diff options
Diffstat (limited to 'src/ui/window.c')
-rw-r--r-- | src/ui/window.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/ui/window.c b/src/ui/window.c index f8391ed9..3ac02495 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -443,7 +443,11 @@ void init_Window(iWindow *d, iRect rect) { | |||
443 | if (left_Rect(rect) >= 0 || top_Rect(rect) >= 0) { | 443 | if (left_Rect(rect) >= 0 || top_Rect(rect) >= 0) { |
444 | SDL_SetWindowPosition(d->win, left_Rect(rect), top_Rect(rect)); | 444 | SDL_SetWindowPosition(d->win, left_Rect(rect), top_Rect(rect)); |
445 | } | 445 | } |
446 | #if defined (iPlatformMobile) | ||
447 | const iInt2 minSize = zero_I2(); /* windows aren't independently resizable */ | ||
448 | #else | ||
446 | const iInt2 minSize = init_I2(425, 325); | 449 | const iInt2 minSize = init_I2(425, 325); |
450 | #endif | ||
447 | SDL_SetWindowMinimumSize(d->win, minSize.x, minSize.y); | 451 | SDL_SetWindowMinimumSize(d->win, minSize.x, minSize.y); |
448 | SDL_SetWindowTitle(d->win, "Lagrange"); | 452 | SDL_SetWindowTitle(d->win, "Lagrange"); |
449 | /* Some info. */ { | 453 | /* Some info. */ { |
@@ -712,7 +716,6 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { | |||
712 | } | 716 | } |
713 | } | 717 | } |
714 | #endif /* defined LAGRANGE_ENABLE_CUSTOM_FRAME */ | 718 | #endif /* defined LAGRANGE_ENABLE_CUSTOM_FRAME */ |
715 | //printf("MOVED: %d, %d\n", ev->data1, ev->data2); fflush(stdout); | ||
716 | if (unsnap_Window_(d, &newPos)) { | 719 | if (unsnap_Window_(d, &newPos)) { |
717 | return iTrue; | 720 | return iTrue; |
718 | } | 721 | } |
@@ -753,7 +756,13 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { | |||
753 | case SDL_WINDOWEVENT_MINIMIZED: | 756 | case SDL_WINDOWEVENT_MINIMIZED: |
754 | d->isMinimized = iTrue; | 757 | d->isMinimized = iTrue; |
755 | return iTrue; | 758 | return iTrue; |
756 | #endif /* defined (iPlatformDesktop) */ | 759 | #else /* if defined (!iPlatformDesktop) */ |
760 | case SDL_WINDOWEVENT_RESIZED: | ||
761 | /* On mobile, this occurs when the display is rotated. */ | ||
762 | invalidate_Window(d); | ||
763 | postRefresh_App(); | ||
764 | return iTrue; | ||
765 | #endif | ||
757 | case SDL_WINDOWEVENT_LEAVE: | 766 | case SDL_WINDOWEVENT_LEAVE: |
758 | unhover_Widget(); | 767 | unhover_Widget(); |
759 | d->isMouseInside = iFalse; | 768 | d->isMouseInside = iFalse; |
@@ -763,19 +772,12 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { | |||
763 | d->isMouseInside = iTrue; | 772 | d->isMouseInside = iTrue; |
764 | postCommand_App("window.mouse.entered"); | 773 | postCommand_App("window.mouse.entered"); |
765 | return iTrue; | 774 | return iTrue; |
766 | #if defined (iPlatformMobile) | ||
767 | case SDL_WINDOWEVENT_RESIZED: | ||
768 | /* On mobile, this occurs when the display is rotated. */ | ||
769 | invalidate_Window(d); | ||
770 | postRefresh_App(); | ||
771 | return iTrue; | ||
772 | #endif | ||
773 | case SDL_WINDOWEVENT_FOCUS_GAINED: | 775 | case SDL_WINDOWEVENT_FOCUS_GAINED: |
774 | d->focusGainedAt = SDL_GetTicks(); | 776 | d->focusGainedAt = SDL_GetTicks(); |
775 | setCapsLockDown_Keys(iFalse); | 777 | setCapsLockDown_Keys(iFalse); |
776 | postCommand_App("window.focus.gained"); | 778 | postCommand_App("window.focus.gained"); |
777 | d->isExposed = iTrue; | 779 | d->isExposed = iTrue; |
778 | #if defined (iPlatformMobile) | 780 | #if !defined (iPlatformDesktop) |
779 | /* Returned to foreground, may have lost buffered content. */ | 781 | /* Returned to foreground, may have lost buffered content. */ |
780 | invalidate_Window_(d, iTrue); | 782 | invalidate_Window_(d, iTrue); |
781 | postCommand_App("window.unfreeze"); | 783 | postCommand_App("window.unfreeze"); |
@@ -783,7 +785,7 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { | |||
783 | return iFalse; | 785 | return iFalse; |
784 | case SDL_WINDOWEVENT_FOCUS_LOST: | 786 | case SDL_WINDOWEVENT_FOCUS_LOST: |
785 | postCommand_App("window.focus.lost"); | 787 | postCommand_App("window.focus.lost"); |
786 | #if defined (iPlatformMobile) | 788 | #if !defined (iPlatformDesktop) |
787 | setFreezeDraw_Window(d, iTrue); | 789 | setFreezeDraw_Window(d, iTrue); |
788 | #endif | 790 | #endif |
789 | return iFalse; | 791 | return iFalse; |
@@ -949,6 +951,10 @@ iBool setKeyRoot_Window(iWindow *d, iRoot *root) { | |||
949 | return iFalse; | 951 | return iFalse; |
950 | } | 952 | } |
951 | 953 | ||
954 | iLocalDef iBool isEscapeKeypress_(const SDL_Event *ev) { | ||
955 | return (ev->type == SDL_KEYDOWN || ev->type == SDL_KEYUP) && ev->key.keysym.sym == SDLK_ESCAPE; | ||
956 | } | ||
957 | |||
952 | iBool dispatchEvent_Window(iWindow *d, const SDL_Event *ev) { | 958 | iBool dispatchEvent_Window(iWindow *d, const SDL_Event *ev) { |
953 | if (ev->type == SDL_MOUSEMOTION) { | 959 | if (ev->type == SDL_MOUSEMOTION) { |
954 | /* Hover widget may change. */ | 960 | /* Hover widget may change. */ |
@@ -964,7 +970,11 @@ iBool dispatchEvent_Window(iWindow *d, const SDL_Event *ev) { | |||
964 | } | 970 | } |
965 | if ((ev->type == SDL_KEYDOWN || ev->type == SDL_KEYUP || ev->type == SDL_TEXTINPUT) | 971 | if ((ev->type == SDL_KEYDOWN || ev->type == SDL_KEYUP || ev->type == SDL_TEXTINPUT) |
966 | && d->keyRoot != root) { | 972 | && d->keyRoot != root) { |
967 | continue; /* Key events go only to the root with keyboard focus. */ | 973 | if (!isEscapeKeypress_(ev)) { |
974 | /* Key events go only to the root with keyboard focus, with the exception | ||
975 | of Escape that will also affect the entire window. */ | ||
976 | continue; | ||
977 | } | ||
968 | } | 978 | } |
969 | if (ev->type == SDL_MOUSEWHEEL && !contains_Rect(rect_Root(root), | 979 | if (ev->type == SDL_MOUSEWHEEL && !contains_Rect(rect_Root(root), |
970 | coord_MouseWheelEvent(&ev->wheel))) { | 980 | coord_MouseWheelEvent(&ev->wheel))) { |
@@ -1015,7 +1025,6 @@ void draw_Window(iWindow *d) { | |||
1015 | if (d->isDrawFrozen) { | 1025 | if (d->isDrawFrozen) { |
1016 | return; | 1026 | return; |
1017 | } | 1027 | } |
1018 | //#if defined (iPlatformMobile) | ||
1019 | /* Check if root needs resizing. */ { | 1028 | /* Check if root needs resizing. */ { |
1020 | iInt2 renderSize; | 1029 | iInt2 renderSize; |
1021 | SDL_GetRendererOutputSize(d->render, &renderSize.x, &renderSize.y); | 1030 | SDL_GetRendererOutputSize(d->render, &renderSize.x, &renderSize.y); |
@@ -1024,7 +1033,6 @@ void draw_Window(iWindow *d) { | |||
1024 | processEvents_App(postedEventsOnly_AppEventMode); | 1033 | processEvents_App(postedEventsOnly_AppEventMode); |
1025 | } | 1034 | } |
1026 | } | 1035 | } |
1027 | //#endif | ||
1028 | const int winFlags = SDL_GetWindowFlags(d->win); | 1036 | const int winFlags = SDL_GetWindowFlags(d->win); |
1029 | const iBool gotFocus = (winFlags & SDL_WINDOW_INPUT_FOCUS) != 0; | 1037 | const iBool gotFocus = (winFlags & SDL_WINDOW_INPUT_FOCUS) != 0; |
1030 | iPaint p; | 1038 | iPaint p; |
@@ -1032,7 +1040,7 @@ void draw_Window(iWindow *d) { | |||
1032 | /* Clear the window. The clear color is visible as a border around the window | 1040 | /* Clear the window. The clear color is visible as a border around the window |
1033 | when the custom frame is being used. */ { | 1041 | when the custom frame is being used. */ { |
1034 | setCurrent_Root(d->roots[0]); | 1042 | setCurrent_Root(d->roots[0]); |
1035 | #if defined (iPlatformAppleMobile) | 1043 | #if defined (iPlatformMobile) |
1036 | iColor back = get_Color(uiBackground_ColorId); | 1044 | iColor back = get_Color(uiBackground_ColorId); |
1037 | if (deviceType_App() == phone_AppDeviceType) { | 1045 | if (deviceType_App() == phone_AppDeviceType) { |
1038 | /* Page background extends to safe area, so fill it completely. */ | 1046 | /* Page background extends to safe area, so fill it completely. */ |