@@ -22,8 +22,8 @@ GUI_Screen::GUI_Screen(const char *aname, SDL_Surface *surface)
2222 background = 0 ;
2323 contents = 0 ;
2424 focus_widget = 0 ;
25+ modal_widget = 0 ;
2526 background_color = 0 ;
26- // mouse = 0;
2727 joysel = new GUI_Widget *[64 ];
2828 joysel_size = 0 ;
2929 joysel_cur = 0 ;
@@ -34,6 +34,7 @@ GUI_Screen::~GUI_Screen(void)
3434{
3535 if (background) background->DecRef ();
3636 if (focus_widget) focus_widget->DecRef ();
37+ if (modal_widget) modal_widget->DecRef ();
3738 if (contents) contents->DecRef ();
3839 if (screen_surface) screen_surface->DecRef ();
3940}
@@ -283,6 +284,7 @@ int GUI_Screen::Event(const SDL_Event *event, int xoffset, int yoffset)
283284 if (joysel_enabled) {
284285
285286 SDL_Event evt;
287+ GUI_Container *container = modal_widget ? (GUI_Container *)modal_widget : (GUI_Container *)contents;
286288
287289 switch (event->type ) {
288290 case SDL_JOYHATMOTION:
@@ -291,7 +293,7 @@ int GUI_Screen::Event(const SDL_Event *event, int xoffset, int yoffset)
291293 break ;
292294 }
293295
294- if (contents ) {
296+ if (container ) {
295297 switch (event->jhat .value ) {
296298 case SDL_HAT_UP: // UP
297299 case SDL_HAT_DOWN: // DOWN
@@ -303,7 +305,7 @@ int GUI_Screen::Event(const SDL_Event *event, int xoffset, int yoffset)
303305 }
304306
305307 joysel_size = 0 ;
306- find_widget_rec ((GUI_Container *)contents );
308+ find_widget_rec (container );
307309
308310 if (joysel_size) {
309311
@@ -334,7 +336,7 @@ int GUI_Screen::Event(const SDL_Event *event, int xoffset, int yoffset)
334336 joysel[i] = NULL ;
335337 }
336338 joysel_size = 0 ;
337- find_widget_rec ((GUI_Container *)contents );
339+ find_widget_rec (container );
338340 joysel_cur = event->jhat .value == SDL_HAT_LEFT ? 0 : joysel_size - 1 ;
339341
340342 if (joysel_size && joysel[joysel_cur]) {
@@ -354,7 +356,7 @@ int GUI_Screen::Event(const SDL_Event *event, int xoffset, int yoffset)
354356
355357 case SDL_KEYDOWN:
356358 {
357- if (contents ) {
359+ if (container ) {
358360 switch (event->key .keysym .sym ) {
359361 default :
360362 break ;
@@ -369,7 +371,7 @@ int GUI_Screen::Event(const SDL_Event *event, int xoffset, int yoffset)
369371 }
370372
371373 joysel_size = 0 ;
372- find_widget_rec ((GUI_Container *)contents );
374+ find_widget_rec (container );
373375
374376 if (joysel_size) {
375377
@@ -399,7 +401,7 @@ int GUI_Screen::Event(const SDL_Event *event, int xoffset, int yoffset)
399401 joysel[i] = NULL ;
400402 }
401403 joysel_size = 0 ;
402- find_widget_rec ((GUI_Container *)contents );
404+ find_widget_rec (container );
403405 joysel_cur = event->key .keysym .sym == SDLK_LEFT ? 0 : joysel_size - 1 ;
404406
405407 if (joysel_size && joysel[joysel_cur]) {
@@ -419,9 +421,16 @@ int GUI_Screen::Event(const SDL_Event *event, int xoffset, int yoffset)
419421 }
420422 }
421423
422- if (contents)
423- if (contents->Event (event, xoffset, yoffset))
424+ if (modal_widget)
425+ {
426+ if (modal_widget->Event (event, xoffset, yoffset))
427+ return 1 ;
428+ }
429+ else if (contents)
430+ {
431+ if (contents->Event (event, xoffset, yoffset))
424432 return 1 ;
433+ }
425434 return GUI_Drawable::Event (event, xoffset, yoffset);
426435}
427436
@@ -433,7 +442,8 @@ void GUI_Screen::RemoveWidget(GUI_Widget *widget)
433442
434443void GUI_Screen::SetContents (GUI_Widget *widget)
435444{
436-
445+ SetFocusWidget (NULL );
446+ SetModalWidget (NULL );
437447 Keep (&contents, widget);
438448
439449 joysel_size = 0 ;
@@ -448,6 +458,21 @@ void GUI_Screen::SetContents(GUI_Widget *widget)
448458 MarkChanged ();
449459}
450460
461+ GUI_Widget *GUI_Screen::GetContents (void )
462+ {
463+ return contents;
464+ }
465+
466+ void GUI_Screen::SetModalWidget (GUI_Widget *widget)
467+ {
468+ if (GUI_ObjectKeep ((GUI_Object **) &modal_widget, widget))
469+ {
470+ MarkChanged ();
471+ joysel_size = 0 ;
472+ joysel_cur = -1 ;
473+ }
474+ }
475+
451476void GUI_Screen::SetBackground (GUI_Surface *image)
452477{
453478 if (GUI_ObjectKeep ((GUI_Object **) &background, image))
@@ -468,31 +493,33 @@ void GUI_Screen::SetBackgroundColor(SDL_Color c)
468493
469494void GUI_Screen::SetFocusWidget (GUI_Widget *widget)
470495{
471- // assert(widget != NULL);
472-
473- if (widget != NULL && focus_widget != widget)
474- {
475- ClearFocusWidget ();
476- widget->SetFlags (WIDGET_HAS_FOCUS);
477- widget->IncRef ();
478- focus_widget = widget;
479- }
480- }
496+ if (focus_widget == widget)
497+ return ;
481498
482- void GUI_Screen::ClearFocusWidget ()
483- {
484499 if (focus_widget)
485500 {
486501 focus_widget->ClearFlags (WIDGET_HAS_FOCUS);
487502 focus_widget->DecRef ();
488503 focus_widget = 0 ;
489504 }
505+
506+ if (widget)
507+ {
508+ focus_widget = widget;
509+ focus_widget->IncRef ();
510+ focus_widget->SetFlags (WIDGET_HAS_FOCUS);
511+ }
490512}
491513
492514GUI_Widget *GUI_Screen::GetFocusWidget ()
493515{
494516 return focus_widget;
495517}
518+
519+ GUI_Widget *GUI_Screen::GetModalWidget ()
520+ {
521+ return modal_widget;
522+ }
496523/*
497524void GUI_Screen::SetMouse(GUI_Mouse *m)
498525{
@@ -522,6 +549,11 @@ void GUI_ScreenSetContents(GUI_Screen *screen, GUI_Widget *widget)
522549 screen->SetContents (widget);
523550}
524551
552+ GUI_Widget *GUI_ScreenGetContents (GUI_Screen *screen)
553+ {
554+ return screen->GetContents ();
555+ }
556+
525557void GUI_ScreenSetBackground (GUI_Screen *screen, GUI_Surface *image)
526558{
527559 screen->SetBackground (image);
@@ -532,9 +564,14 @@ void GUI_ScreenSetFocusWidget(GUI_Screen *screen, GUI_Widget *widget)
532564 screen->SetFocusWidget (widget);
533565}
534566
535- void GUI_ScreenClearFocusWidget (GUI_Screen *screen)
567+ void GUI_ScreenSetModalWidget (GUI_Screen *screen, GUI_Widget *widget)
568+ {
569+ screen->SetModalWidget (widget);
570+ }
571+
572+ GUI_Widget *GUI_ScreenGetModalWidget (GUI_Screen *screen)
536573{
537- screen->ClearFocusWidget ();
574+ return screen->GetModalWidget ();
538575}
539576
540577void GUI_ScreenSetBackgroundColor (GUI_Screen *screen, SDL_Color c)
0 commit comments