diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-13 13:35:39 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-13 13:35:39 +0200 |
commit | 95df7abfb8ff46fba1bda1e696184682a5766fda (patch) | |
tree | 2f975446d82b84ad281e6ea6b4462d8a19d6e572 /src/ui/window.c | |
parent | 9eba54d16f19fc976b64a678c151a6f03883658c (diff) |
Windows: Further custom frame improvements
Saving the window rectangle and snap mode. Frame title alignment.
Diffstat (limited to 'src/ui/window.c')
-rw-r--r-- | src/ui/window.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/ui/window.c b/src/ui/window.c index 65386e14..a59aa135 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -93,6 +93,19 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) { | |||
93 | setTextColor_LabelWidget(findWidget_App("winbar.title"), uiTextStrong_ColorId); | 93 | setTextColor_LabelWidget(findWidget_App("winbar.title"), uiTextStrong_ColorId); |
94 | return iFalse; | 94 | return iFalse; |
95 | } | 95 | } |
96 | else if (equal_Command(cmd, "window.setrect")) { | ||
97 | const int snap = argLabel_Command(cmd, "snap"); | ||
98 | if (snap) { | ||
99 | iWindow *window = get_Window(); | ||
100 | iInt2 coord = coord_Command(cmd); | ||
101 | iInt2 size = init_I2(argLabel_Command(cmd, "width"), | ||
102 | argLabel_Command(cmd, "height")); | ||
103 | SDL_SetWindowPosition(window->win, coord.x, coord.y); | ||
104 | SDL_SetWindowSize(window->win, size.x, size.y); | ||
105 | window->place.snap = snap; | ||
106 | return iTrue; | ||
107 | } | ||
108 | } | ||
96 | else if (equal_Command(cmd, "window.restore")) { | 109 | else if (equal_Command(cmd, "window.restore")) { |
97 | setSnap_Window(get_Window(), none_WindowSnap); | 110 | setSnap_Window(get_Window(), none_WindowSnap); |
98 | return iTrue; | 111 | return iTrue; |
@@ -542,6 +555,7 @@ static void setupUserInterface_Window(iWindow *d) { | |||
542 | const int border = gap_UI / 4; | 555 | const int border = gap_UI / 4; |
543 | setPadding1_Widget(div, border); /* draggable edges */ | 556 | setPadding1_Widget(div, border); /* draggable edges */ |
544 | iWidget *winBar = new_Widget(); | 557 | iWidget *winBar = new_Widget(); |
558 | setPadding_Widget(winBar, 0, gap_UI / 3, 0, 0); | ||
545 | setId_Widget(winBar, "winbar"); | 559 | setId_Widget(winBar, "winbar"); |
546 | setFlags_Widget(winBar, | 560 | setFlags_Widget(winBar, |
547 | arrangeHeight_WidgetFlag | resizeChildren_WidgetFlag | | 561 | arrangeHeight_WidgetFlag | resizeChildren_WidgetFlag | |
@@ -792,13 +806,14 @@ static SDL_HitTestResult hitTest_Window_(SDL_Window *win, const SDL_Point *pos, | |||
792 | if (SDL_GetWindowFlags(d->win) & (SDL_WINDOW_MOUSE_CAPTURE | SDL_WINDOW_FULLSCREEN_DESKTOP)) { | 806 | if (SDL_GetWindowFlags(d->win) & (SDL_WINDOW_MOUSE_CAPTURE | SDL_WINDOW_FULLSCREEN_DESKTOP)) { |
793 | return SDL_HITTEST_NORMAL; | 807 | return SDL_HITTEST_NORMAL; |
794 | } | 808 | } |
809 | const int snap = snap_Window(d); | ||
795 | int w, h; | 810 | int w, h; |
796 | SDL_GetWindowSize(win, &w, &h); | 811 | SDL_GetWindowSize(win, &w, &h); |
797 | /* TODO: Check if inside the caption label widget. */ | 812 | /* TODO: Check if inside the caption label widget. */ |
798 | const iBool isLeft = pos->x < gap_UI; | 813 | const iBool isLeft = pos->x < gap_UI; |
799 | const iBool isRight = pos->x >= w - gap_UI; | 814 | const iBool isRight = pos->x >= w - gap_UI; |
800 | const iBool isTop = pos->y < gap_UI; | 815 | const iBool isTop = pos->y < gap_UI && snap != yMaximized_WindowSnap; |
801 | const iBool isBottom = pos->y >= h - gap_UI; | 816 | const iBool isBottom = pos->y >= h - gap_UI && snap != yMaximized_WindowSnap; |
802 | const int captionHeight = lineHeight_Text(uiContent_FontId) + gap_UI * 2; | 817 | const int captionHeight = lineHeight_Text(uiContent_FontId) + gap_UI * 2; |
803 | const int rightEdge = left_Rect(bounds_Widget(findChild_Widget(d->root, "winbar.min"))); | 818 | const int rightEdge = left_Rect(bounds_Widget(findChild_Widget(d->root, "winbar.min"))); |
804 | d->place.lastHit = SDL_HITTEST_NORMAL; | 819 | d->place.lastHit = SDL_HITTEST_NORMAL; |
@@ -862,6 +877,7 @@ void init_Window(iWindow *d, iRect rect) { | |||
862 | d->isExposed = iFalse; | 877 | d->isExposed = iFalse; |
863 | d->isMinimized = iFalse; | 878 | d->isMinimized = iFalse; |
864 | d->isMouseInside = iTrue; | 879 | d->isMouseInside = iTrue; |
880 | d->ignoreClick = iFalse; | ||
865 | d->focusGainedAt = 0; | 881 | d->focusGainedAt = 0; |
866 | uint32_t flags = 0; | 882 | uint32_t flags = 0; |
867 | #if defined (iPlatformAppleDesktop) | 883 | #if defined (iPlatformAppleDesktop) |
@@ -1180,21 +1196,10 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) { | |||
1180 | As a workaround, ignore these events. */ | 1196 | As a workaround, ignore these events. */ |
1181 | return iTrue; /* won't go to bindings, either */ | 1197 | return iTrue; /* won't go to bindings, either */ |
1182 | } | 1198 | } |
1183 | #if 0 //defined (LAGRANGE_CUSTOM_FRAME) | 1199 | if (event.type == SDL_MOUSEBUTTONDOWN && d->ignoreClick) { |
1184 | if (event.type == SDL_KEYDOWN) { | 1200 | d->ignoreClick = iFalse; |
1185 | if (keyMods_Sym(event.key.keysym.mod) == KMOD_PRIMARY) { | 1201 | return iTrue; |
1186 | printf("got! %x\n", event.key.keysym.sym); fflush(stdout); | ||
1187 | /* Emulate window snapping keys. */ | ||
1188 | switch (event.key.keysym.sym) { | ||
1189 | default: | ||
1190 | break; | ||
1191 | case SDLK_LEFT: | ||
1192 | setSnap_Window(d, left_WindowSnap); | ||
1193 | return iTrue; | ||
1194 | } | ||
1195 | } | ||
1196 | } | 1202 | } |
1197 | #endif | ||
1198 | /* Map mouse pointer coordinate to our coordinate system. */ | 1203 | /* Map mouse pointer coordinate to our coordinate system. */ |
1199 | if (event.type == SDL_MOUSEMOTION) { | 1204 | if (event.type == SDL_MOUSEMOTION) { |
1200 | setCursor_Window(d, SDL_SYSTEM_CURSOR_ARROW); /* default cursor */ | 1205 | setCursor_Window(d, SDL_SYSTEM_CURSOR_ARROW); /* default cursor */ |