615 /* |
597 /* |
616 * Process a dialog. Returns the button number that has been pressed |
598 * Process a dialog. Returns the button number that has been pressed |
617 */ |
599 */ |
618 int SDLGui_DoDialogLoop(SGOBJ *dlg) |
600 int SDLGui_DoDialogLoop(SGOBJ *dlg) |
619 { |
601 { |
620 int obj = 0, oldbutton = 0, retbutton = 0, b, i, j; |
602 int obj = 0, retbutton = 0; |
621 SDL_Event sdlEvent; |
603 SDL_Event sdlEvent; |
622 |
|
623 /* |
|
624 * Is the left mouse button still pressed? Yes -> Handle TOUCHEXIT objects here |
|
625 */ |
|
626 SDL_PumpEvents(); |
|
627 b = SDL_GetMouseState(&i, &j); |
|
628 obj = SDLGui_FindObj(dlg, i, j); |
|
629 if (obj > 0 && (dlg[obj].flags & SG_TOUCHEXIT) ) { |
|
630 oldbutton = obj; |
|
631 if (b & SDL_BUTTON(1)) { |
|
632 dlg[obj].state |= SG_SELECTED; |
|
633 retbutton = obj; |
|
634 } |
|
635 } |
|
636 |
604 |
637 /* The main loop */ |
605 /* The main loop */ |
638 while (retbutton == 0 && !my_shutdown) { |
606 while (retbutton == 0 && !my_shutdown) { |
639 |
607 |
|
608 /* |
|
609 * Poll network for data |
|
610 */ |
640 socket_recv(); |
611 socket_recv(); |
641 |
612 |
642 if (SDL_PollEvent(&sdlEvent) == 1) { /* Wait for events */ |
613 if (SDL_PollEvent(&sdlEvent) == 1) { /* Wait for events */ |
643 switch (sdlEvent.type) { |
614 switch (sdlEvent.type) { |
644 case SDL_QUIT: |
615 case SDL_QUIT: |
655 if (obj > 0) { |
626 if (obj > 0) { |
656 if (dlg[obj].type == SGBUTTON) { |
627 if (dlg[obj].type == SGBUTTON) { |
657 dlg[obj].state |= SG_SELECTED; |
628 dlg[obj].state |= SG_SELECTED; |
658 SDLGui_DrawButton(dlg, obj); |
629 SDLGui_DrawButton(dlg, obj); |
659 SDL_UpdateRect(pSdlGuiScrn, dlg[0].x + dlg[obj].x - 2, dlg[0].y + dlg[obj].y - 2, dlg[obj].w + 4, dlg[obj].h + 4); |
630 SDL_UpdateRect(pSdlGuiScrn, dlg[0].x + dlg[obj].x - 2, dlg[0].y + dlg[obj].y - 2, dlg[obj].w + 4, dlg[obj].h + 4); |
660 oldbutton=obj; |
631 retbutton = obj + 1000; |
661 } |
|
662 if ( dlg[obj].flags & SG_TOUCHEXIT ) { |
|
663 dlg[obj].state |= SG_SELECTED; |
|
664 retbutton = obj; |
|
665 } |
632 } |
666 } |
633 } |
667 break; |
634 break; |
668 |
635 |
669 case SDL_MOUSEBUTTONUP: |
636 case SDL_MOUSEBUTTONUP: |
672 break; |
639 break; |
673 } |
640 } |
674 /* It was the left button: Find the object under the mouse cursor */ |
641 /* It was the left button: Find the object under the mouse cursor */ |
675 obj = SDLGui_FindObj(dlg, sdlEvent.button.x, sdlEvent.button.y); |
642 obj = SDLGui_FindObj(dlg, sdlEvent.button.x, sdlEvent.button.y); |
676 if (obj > 0) { |
643 if (obj > 0) { |
677 switch (dlg[obj].type) { |
644 if (dlg[obj].type == SGBUTTON) { |
678 case SGBUTTON: |
645 dlg[obj].state &= ~SG_SELECTED; |
679 if (oldbutton==obj) |
646 SDLGui_DrawButton(dlg, obj); |
680 retbutton=obj; |
647 SDL_UpdateRect(pSdlGuiScrn, dlg[0].x + dlg[obj].x - 2, dlg[0].y + dlg[obj].y - 2, dlg[obj].w + 4, dlg[obj].h + 4); |
681 break; |
648 retbutton = obj; |
682 } |
649 } |
683 } |
650 } |
684 if (oldbutton > 0) { |
|
685 dlg[oldbutton].state &= ~SG_SELECTED; |
|
686 SDLGui_DrawButton(dlg, oldbutton); |
|
687 SDL_UpdateRect(pSdlGuiScrn, dlg[0].x+dlg[oldbutton].x-2, dlg[0].y+dlg[oldbutton].y-2, dlg[oldbutton].w+4, dlg[oldbutton].h+4); |
|
688 oldbutton = 0; |
|
689 } |
|
690 if (obj >= 0 && (dlg[obj].flags & SG_EXIT)) { |
|
691 retbutton = obj; |
|
692 } |
|
693 break; |
651 break; |
694 |
652 |
695 case SDL_MOUSEMOTION: |
653 case SDL_MOUSEMOTION: |
696 break; |
654 break; |
697 |
655 |
698 case SDL_KEYDOWN: /* Key pressed */ |
656 case SDL_KEYDOWN: /* Key pressed */ |
699 if (sdlEvent.key.keysym.sym == SDLK_RETURN || sdlEvent.key.keysym.sym == SDLK_KP_ENTER) { |
|
700 retbutton = SDLGui_SearchFlaggedButton(dlg, SG_DEFAULT); |
|
701 } else if (sdlEvent.key.keysym.sym == SDLK_ESCAPE) { |
|
702 retbutton = SDLGui_SearchFlaggedButton(dlg, SG_CANCEL); |
|
703 } |
|
704 break; |
657 break; |
705 } |
658 } |
706 } else { |
659 } else { |
707 SDL_Delay(1); |
660 SDL_Delay(1); |
708 } |
661 } |