4 #define PUSTACK_MAX 100
6 static int currLiveInterface = -1 ;
7 static puInterface *liveInterfaceStack [ PUSTACK_MAX ] ;
8 static int currInterface = -1 ;
9 static puInterface *interfaceStack [ PUSTACK_MAX ] ;
11 void puPushLiveInterface ( puInterface *in )
13 if ( currLiveInterface < PUSTACK_MAX )
14 liveInterfaceStack [ ++currLiveInterface ] = in ;
16 fprintf ( stderr, "PUI: Too many live puInterfaces open at once!\n" ) ;
19 void puPushInterface ( puInterface *in )
21 if ( currInterface < PUSTACK_MAX )
22 interfaceStack [ ++currInterface ] = in ;
24 fprintf ( stderr, "PUI: Too many puInterfaces open at once!\n" ) ;
27 void puPopLiveInterface ( void )
29 if ( currLiveInterface > 0 )
32 fprintf ( stderr, "PUI: Live puInterface stack is empty!\n" ) ;
35 void puPopInterface ( void )
37 if ( currInterface > 0 )
40 fprintf ( stderr, "PUI: puInterface stack is empty!\n" ) ;
43 int puNoLiveInterface ( void )
45 return currLiveInterface < 0 ;
48 int puNoInterface ( void )
50 return currInterface < 0 ;
53 puInterface *puGetUltimateLiveInterface ( void )
55 if ( currLiveInterface < 0 )
57 fprintf ( stderr, "PUI: No Live Interface!\n" ) ;
61 return liveInterfaceStack [ 0 ] ;
65 puInterface *puGetBaseLiveInterface ( void )
67 if ( currLiveInterface < 0 )
69 fprintf ( stderr, "PUI: No Live Interface!\n" ) ;
74 Work down the interface stack until you
75 either get to the bottom or find a block
76 in the form of a puDialogBox.
79 for ( int i = currLiveInterface ; i > 0 ; i-- )
80 if ( liveInterfaceStack [ i ] -> getType () & PUCLASS_DIALOGBOX )
81 return liveInterfaceStack [ i ] ;
83 return liveInterfaceStack [ 0 ] ;
86 puInterface *puGetCurrInterface ( void )
88 if ( currInterface < 0 )
90 fprintf ( stderr, "PUI: No Interface!\n" ) ;
94 return interfaceStack [ currInterface ] ;
97 void puInterface::remove ( puObject *obj )
102 /* Are we the first object in the list */
104 if ( obj -> prev == NULL )
105 dlist = obj -> next ;
107 obj -> prev -> next = obj -> next ;
109 /* Are we the last object in the list */
111 if ( obj -> next != NULL )
112 obj -> next -> prev = obj -> prev ;
121 void puInterface::add ( puObject *new_obj )
126 new_obj -> next = NULL ;
127 new_obj -> prev = NULL ;
133 for ( last = dlist ; last->next != NULL ; last = last->next )
134 /* Search for end of list. */ ;
136 last -> next = new_obj ;
137 new_obj -> prev = last ;
138 new_obj -> next = NULL ;
145 int puInterface::checkKey ( int key, int updown )
147 if ( dlist == NULL || ! isVisible () || ! isActive () )
153 We have to walk the list backwards to ensure that
154 the click order is the same as the DRAW order.
157 for ( bo = dlist ; bo->next != NULL ; bo = bo->next )
158 /* Find the last object in our list. */ ;
160 for ( ; bo != NULL ; bo = bo->prev )
161 if ( bo -> checkKey ( key, updown ) )
167 int puInterface::checkHit ( int button, int updown, int x, int y )
169 if ( dlist == NULL || ! isVisible () || ! isActive () )
173 This might be a bit redundant - but it's too hard to keep
174 track of changing abox sizes when daughter objects are
186 We have to walk the list backwards to ensure that
187 the click order is the same as the DRAW order.
190 for ( bo = dlist ; bo->next != NULL ; bo = bo->next )
191 /* Find the last object in our list. */ ;
193 for ( ; bo != NULL ; bo = bo->prev )
194 if ( bo -> checkHit ( button, updown, x, y ) )
201 void puInterface::draw ( int dx, int dy )
203 if ( ! isVisible () )
206 for ( puObject *bo = dlist ; bo != NULL ; bo = bo->next )
208 /* June 16th, 98, Shammi :
209 * The next if statement checks if the object is
210 * a menu bar and makes sure it is repositioned
214 if ( bo->getType() & PUCLASS_MENUBAR )
216 int obWidth, obHeight ;
217 bo -> getSize ( &obWidth, &obHeight ) ;
218 bo -> setPosition ( 0, puGetWindowHeight() - obHeight ) ;
221 bo -> draw ( dx + abox.min[0], dy + abox.min[1] ) ;
226 void puInterface::recalc_bbox ( void )
229 contents . empty () ;
231 for ( puObject *bo = dlist ; bo != NULL ; bo = bo->next )
232 contents . extend ( bo -> getBBox() ) ;
234 if ( contents . isEmpty () )
236 abox . max[0] = abox . min[0] ;
237 abox . max[1] = abox . min[1] ;
241 abox . max[0] = abox . min[0] + contents . max[0] ;
242 abox . max[1] = abox . min[1] + contents . max[1] ;
245 puObject::recalc_bbox () ;
249 void puInterface::doHit ( int, int, int, int )
254 puInterface::~puInterface ()
256 puPopLiveInterface () ;
258 puObject *bo = dlist ;
260 while ( bo != NULL ) {
261 puObject *tmp_bo = bo->next ;