6 void() Menu_Process_Setup =
10 Menu_Clip_Position = '0 0 0';
11 Menu_Clip_Size = '0 0 0';
16 void( vector pOrigin ) _Menu_Origin_Push =
18 Menu_Origin = Menu_OrgToMen( pOrigin );
20 if( _menu_process_filtered ) {
21 print( "MGFX Pushed origin: ", vtos( pOrigin ), " Absolute ", vtos( Menu_Origin ), "\n" );
22 //print( "MGFX Pushed origin: ", vtos( pOrigin ), " Absolute " );
23 //print( vtos( Menu_Origin ), "\n" );
26 Menu_Cursor_Position = Cursor_Position - Menu_Origin;
29 void( vector pOldOrigin ) _Menu_Origin_Pop =
31 Menu_Origin = pOldOrigin;
33 if( _menu_process_filtered )
34 print( "MGFX Popped origin for origin: ", vtos( Menu_Origin ), "\n" );
36 Menu_Cursor_Position = Cursor_Position - Menu_Origin;
39 void( vector pPos, vector pSize ) _Menu_Clip_Push =
43 if( pPos != '0 0 0' || pSize != '0 0 0' ) {
44 if( (Menu_Clip_Position != '0 0 0' || Menu_Clip_Size != '0 0 0') ) {
45 pPos = Menu_OrgToMen( pPos );
46 lDelta = Util_GetClipDelta( pPos, Menu_Clip_Position, Menu_Clip_Size );
48 pSize = Util_ClipRect( pPos, pSize - lDelta, Menu_Clip_Position, Menu_Clip_Size );
51 Menu_Clip_Position = pPos;
52 Menu_Clip_Size = pSize;
53 Gfx_SetClipArea( Menu_Clip_Position_x, Menu_Clip_Position_y, Menu_Clip_Size_x, Menu_Clip_Size_y );
56 if( _menu_process_filtered ) {
57 print( "MGFX Pushed clipper: ", vtos( pPos ), " " );
58 print( vtos( pSize ) );
59 print( " Clipped to: ", vtos( Menu_Clip_Position ), " " );
60 print( vtos( Menu_Clip_Size),"\n" );
64 void( vector pOldPos, vector pOldSize ) _Menu_Clip_Pop =
66 Menu_Clip_Position = pOldPos;
67 Menu_Clip_Size = pOldSize;
69 if( sys_debug_mgfx ) {
70 print( "MGFX Popped clipper for clip area: ", vtos( Menu_Clip_Position ), " " );
71 print( vtos( Menu_Clip_Size ), "\n" );
74 if( Menu_Clip_Position == '0 0 0' && Menu_Clip_Size == '0 0 0' )
77 Gfx_SetClipArea( Menu_Clip_Position_x, Menu_Clip_Position_y, Menu_Clip_Size_x, Menu_Clip_Size_y );
80 // debug process functions
81 bool _menu_process_filtered;
82 void( float pMode, float pSelectState ) _Menu_Process_Debug_Filter =
84 if( !sys_debug_process )
85 _menu_process_filtered = false;
86 else if( sys_debug_process_filter )
87 _menu_process_filtered = (pMode & sys_debug_process_filter);
89 _menu_process_filtered = true;
90 if( _menu_process_filtered == MENU_PROCESS_MOUSE && pSelectState == MENU_SELECT_NEVER )
91 _menu_process_filtered = false;
94 void( string pText ) _Menu_Process_Debug_Print =
96 if( _menu_process_filtered )
100 void( entity pItem, float pMode, float pSelectState, float pKey, float pAscii ) _Menu_Process_Debug_Header =
102 if( sys_debug_process && _menu_process_filtered ) {
104 case MENU_PROCESS_RUNFLAG:
107 case MENU_PROCESS_UPDATE:
110 case MENU_PROCESS_DRAW:
113 case MENU_PROCESS_MOUSE:
115 switch( pSelectState ) {
116 case MENU_SELECT_SELECTABLE:
119 case MENU_SELECT_ALWAYS:
122 case MENU_SELECT_NEVER:
127 case MENU_PROCESS_KEY:
129 print( ftos( pKey ), " " );
134 print( pItem.name, " " );
138 void( float pRetValue ) _Menu_Process_Debug_Return =
140 if( sys_debug_process && _menu_process_filtered )
141 switch( pRetValue ) {
142 case MENU_EVENT_NORMAL:
143 case MENU_EVENT_CONTINUE:
144 print( "MENU_EVENT_CONTINUE\n" );
146 case MENU_EVENT_RAISEPARENT:
147 print( "MENU_EVENT_RAISEPARENT\n" );
149 case MENU_EVENT_PROCESSED:
150 print( "MENU_EVENT_PROCESSED\n" );
155 // main process functions
156 float( entity pItem, float pMode, float pSelectState, float pKey, float pAscii ) Menu_Process =
159 local bool lContinue;
161 // the new clip and origin stack
162 local vector lOldOrigin, lOldClipPos, lOldClipSize;
164 // set the debug filter
165 _Menu_Process_Debug_Filter( pMode, pSelectState );
167 _Menu_Process_Debug_Header( pItem, pMode, pSelectState, pKey, pAscii );
169 // adjust the clip area
170 lOldClipPos = Menu_Clip_Position;
171 lOldClipSize = Menu_Clip_Size;
172 _Menu_Clip_Push( pItem.pos, pItem.size );
174 // test if its necessary to do anything
176 lResult = MENU_EVENT_NORMAL;
178 case MENU_PROCESS_RUNFLAG:
181 case MENU_PROCESS_MOUSE:
182 if( !Menu_IsVisible( pItem ) )
186 case MENU_PROCESS_DRAW:
187 if( !Menu_IsVisible( pItem ) )
191 case MENU_PROCESS_UPDATE:
192 if( Menu_HasRunFlag( pItem, RUNFLAG_CHILDDRAWONLY ) )
196 case MENU_PROCESS_KEY:
197 if( !Menu_HasEvents( pItem ) )
202 error( "Bad pMode in Menu_Processs!" );
206 _Menu_Process_Debug_Print( "Condition failed\n" );
207 _Menu_Clip_Pop( lOldClipPos, lOldClipSize );
211 // process the events for this item
214 case MENU_PROCESS_RUNFLAG:
215 Menu_SetRunFlag( pItem );
217 case MENU_PROCESS_UPDATE:
218 Raise_Update( pItem );
219 if( Menu_HasRunFlag( pItem, RUNFLAG_HIDDEN ) )
222 case MENU_PROCESS_DRAW:
225 case MENU_PROCESS_MOUSE:
226 // check if the mouse is even in the clip area
227 if( Util_InRect( Cursor_Position, Menu_Clip_Position, Menu_Clip_Size ) ||
228 ( Menu_Clip_Position == '0 0 0' && Menu_Clip_Size == '0 0 0' ) ) {
229 pItem._runFlag = pItem._runFlag | RUNFLAG_MOUSEINAREA;
231 if( !Menu_HasRunFlag( pItem, RUNFLAG_HADMOUSE ) && Menu_HasEvents( pItem ) )
232 Raise_MouseEnter( pItem );
233 if( pSelectState != MENU_SELECT_NEVER && Menu_HasFlag( pItem, FLAG_SEALOFFMOUSE ) )
234 Menu_ActiveItem = null_entity;
235 if( ( pSelectState == MENU_SELECT_ALWAYS ) ||
236 ( Menu_IsSelectable( pItem ) && pSelectState == MENU_SELECT_SELECTABLE ) )
237 Menu_ActiveItem = pItem;
238 } else if( Menu_HasRunFlag( pItem, RUNFLAG_HADMOUSE ) && Menu_HasEvents( pItem ) )
239 Raise_MouseLeave( pItem );
241 case MENU_PROCESS_KEY:
242 if( Menu_ActiveItem == pItem ) {
244 if( Raise_Key( pItem, pKey, pAscii ) )
245 lResult = MENU_EVENT_PROCESSED;
247 lResult = MENU_EVENT_RAISEPARENT;
249 _Menu_Process_Debug_Return( lResult );
254 _Menu_Process_Debug_Print( "Early\n" );
255 _Menu_Clip_Pop( lOldClipPos, lOldClipSize );
259 // we adjust the origin for the children
260 lOldOrigin = Menu_Origin;
261 _Menu_Origin_Push( pItem.pos + pItem.origin );
263 _Menu_Process_Debug_Print( "\n" );
266 case MENU_PROCESS_RUNFLAG:
267 for( lChild = pItem._child ; lChild ; lChild = lChild._next ) {
268 Menu_InheritRunFlag( pItem, lChild );
269 Menu_ProcessRunFlag( lChild );
272 case MENU_PROCESS_DRAW:
273 for( lChild = pItem._child ; lChild ; lChild = lChild._next )
274 Menu_ProcessDraw( lChild );
276 case MENU_PROCESS_UPDATE:
277 for( lChild = pItem._child ; lChild ; lChild = lChild._next )
278 Menu_ProcessUpdate( lChild );
280 case MENU_PROCESS_MOUSE:
281 for( lChild = pItem._child ; lChild ; lChild = lChild._next )
282 if( Menu_HasEvents( pItem ) )
283 Menu_ProcessMouse( lChild, pSelectState );
285 Menu_ProcessMouse( lChild, MENU_SELECT_NEVER );
287 case MENU_PROCESS_KEY:
288 for( lChild = pItem._child ; lContinue && lChild ; lChild = lChild._next ) {
291 lRet = Menu_ProcessKey( lChild, pKey, pAscii );
294 case MENU_EVENT_RAISEPARENT:
296 if( Raise_Key( pItem, pKey, pAscii ) )
297 lResult = MENU_EVENT_PROCESSED;
299 lResult = MENU_EVENT_RAISEPARENT;
301 case MENU_EVENT_PROCESSED:
305 case MENU_EVENT_CONTINUE:
310 _Menu_Process_Debug_Return( lResult );
314 _Menu_Origin_Pop( lOldOrigin );
316 _Menu_Clip_Pop( lOldClipPos, lOldClipSize );
324 Menu_UpdateRunFlags();
325 // process the update event
326 Menu_Process_Setup();
327 Menu_ProcessUpdate( Menu_ActiveWindow, MENU_PROCESS_UPDATE );
329 Menu_Process_Setup();
330 // if mouse was moved, select an item
331 if( Cursor_Relative != '0 0 0' ) {
334 lOld = Menu_ActiveItem;
335 Menu_ProcessMouse( Menu_ActiveWindow, MENU_SELECT_SELECTABLE );
337 if( !Menu_ActiveItem )
338 Menu_ActiveItem = lOld;
339 else if( lOld != Menu_ActiveItem ) {
340 Raise_Select( lOld, false, true );
341 Raise_Select( Menu_ActiveItem, true, true );
343 } else // just update mouseinarea
344 Menu_ProcessMouse( Menu_ActiveWindow, MENU_SELECT_NEVER );
346 Menu_CollectGarbage( false );
351 // if Menu_ActiveWindow is visible loop though it
352 if( Menu_IsVisible( Menu_ActiveWindow ) )
354 Menu_Process_Setup();
355 Menu_ProcessDraw( Menu_ActiveWindow );
361 void( float pKey, float pAscii) Menu_Key =
363 // is a keyhook set ?
364 if( Menu_KeyHook != Util_NullFunction ) {
366 Menu_KeyHook( pKey, pAscii );
369 // before calling the current keydown functions, process the mouse again
370 // to make sure the correct item is called
371 // (except mouse wheel up and down)
372 // if the mouse doesnt point to an item, there wont be a reaction on the clicking
373 if(K_MOUSE1 <= pKey && pKey <= K_MOUSE10) {
376 lOld = Menu_ActiveItem;
377 Menu_ActiveItem = null_entity;
378 Menu_ProcessMouse( Menu_ActiveWindow, MENU_SELECT_SELECTABLE );
380 if( !Menu_ActiveItem ) {
381 Menu_ActiveItem = lOld;
383 } else if( lOld != Menu_ActiveItem ) {
384 Raise_Select( lOld, false, true );
385 Raise_Select( Menu_ActiveItem, true, true );
389 // call current selected keydown function
390 // if nothing is selected -> window has no items -> call window key
391 if(Menu_ActiveItem == null_entity)
392 Menu_Reselect( false );
394 if( ( !Menu_IsSelectable( Menu_ActiveItem ) && Menu_ActiveItem != Menu_ActiveWindow ) ||
395 Menu_ProcessKey( Menu_ActiveWindow, pKey, pAscii ) != MENU_EVENT_PROCESSED )
396 // If it goes really wrong:
397 if( pKey == K_ESCAPE )
398 if( gamestatus & GAME_DEVELOPER )
399 error( " K_ESCAPE wasnt processed!\n" );
402 cmd( "menu_restart\n" );
404 else if( gamestatus & GAME_DEVELOPER ) {
405 print( " Key ", ftos( pKey ), " ('" );
406 print( chr( pAscii ), "') wasn't processed!\n" );
412 // only let the qc toggle the menu if we are ingame or a developer
413 if( gamestatus & GAME_CONNECTED || gamestatus & GAME_DEVELOPER ) {
414 // then allow toggling