diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-04-27 12:56:09 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-04-27 12:56:09 +0300 |
commit | 3846778c99d9efca609b7cb216cb71c675f036b0 (patch) | |
tree | cb126b07588036c24c5922c5c460d30be2204791 /src/ui/window.c | |
parent | 9a7aa34e63132edb5906914ff99b861e64ee9099 (diff) |
Keeping track of current UI root
The current UI root should always be set explicitly before the UI
is accessed.
Diffstat (limited to 'src/ui/window.c')
-rw-r--r-- | src/ui/window.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/ui/window.c b/src/ui/window.c index 627f16b1..1e98b167 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -167,6 +167,7 @@ static void setupUserInterface_Window(iWindow *d) { | |||
167 | #endif | 167 | #endif |
168 | setCurrent_Root(&d->root); | 168 | setCurrent_Root(&d->root); |
169 | createUserInterface_Root(&d->root); | 169 | createUserInterface_Root(&d->root); |
170 | setCurrent_Root(NULL); | ||
170 | } | 171 | } |
171 | 172 | ||
172 | static void updateRootSize_Window_(iWindow *d, iBool notifyAlways) { | 173 | static void updateRootSize_Window_(iWindow *d, iBool notifyAlways) { |
@@ -449,19 +450,21 @@ void init_Window(iWindow *d, iRect rect) { | |||
449 | } | 450 | } |
450 | 451 | ||
451 | void deinit_Window(iWindow *d) { | 452 | void deinit_Window(iWindow *d) { |
453 | setCurrent_Root(&d->root); | ||
452 | iRecycle(); | 454 | iRecycle(); |
453 | if (theWindow_ == d) { | 455 | if (theWindow_ == d) { |
454 | theWindow_ = NULL; | 456 | theWindow_ = NULL; |
455 | } | 457 | } |
458 | deinit_Root(&d->root); | ||
459 | setCurrent_Root(NULL); | ||
460 | deinit_Text(); | ||
461 | SDL_DestroyRenderer(d->render); | ||
462 | SDL_DestroyWindow(d->win); | ||
456 | iForIndices(i, d->cursors) { | 463 | iForIndices(i, d->cursors) { |
457 | if (d->cursors[i]) { | 464 | if (d->cursors[i]) { |
458 | SDL_FreeCursor(d->cursors[i]); | 465 | SDL_FreeCursor(d->cursors[i]); |
459 | } | 466 | } |
460 | } | 467 | } |
461 | deinit_Root(&d->root); | ||
462 | deinit_Text(); | ||
463 | SDL_DestroyRenderer(d->render); | ||
464 | SDL_DestroyWindow(d->win); | ||
465 | } | 468 | } |
466 | 469 | ||
467 | SDL_Renderer *renderer_Window(const iWindow *d) { | 470 | SDL_Renderer *renderer_Window(const iWindow *d) { |
@@ -766,6 +769,7 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) { | |||
766 | event.button.x = pos.x; | 769 | event.button.x = pos.x; |
767 | event.button.y = pos.y; | 770 | event.button.y = pos.y; |
768 | } | 771 | } |
772 | setCurrent_Root(&d->root); | ||
769 | iWidget *widget = d->root.widget; | 773 | iWidget *widget = d->root.widget; |
770 | if (event.type == SDL_MOUSEMOTION || event.type == SDL_MOUSEWHEEL || | 774 | if (event.type == SDL_MOUSEMOTION || event.type == SDL_MOUSEWHEEL || |
771 | event.type == SDL_MOUSEBUTTONUP || event.type == SDL_MOUSEBUTTONDOWN) { | 775 | event.type == SDL_MOUSEBUTTONUP || event.type == SDL_MOUSEBUTTONDOWN) { |
@@ -866,10 +870,11 @@ void draw_Window(iWindow *d) { | |||
866 | /* Draw widgets. */ | 870 | /* Draw widgets. */ |
867 | d->frameTime = SDL_GetTicks(); | 871 | d->frameTime = SDL_GetTicks(); |
868 | if (isExposed_Window(d)) { | 872 | if (isExposed_Window(d)) { |
873 | setCurrent_Root(&d->root); | ||
869 | draw_Widget(d->root.widget); | 874 | draw_Widget(d->root.widget); |
870 | #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) | 875 | #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) |
871 | /* App icon. */ | 876 | /* App icon. */ |
872 | const iWidget *appIcon = findChild_Widget(d->root, "winbar.icon"); | 877 | const iWidget *appIcon = findChild_Widget(d->root.widget, "winbar.icon"); |
873 | if (isVisible_Widget(appIcon)) { | 878 | if (isVisible_Widget(appIcon)) { |
874 | const int size = appIconSize_(); | 879 | const int size = appIconSize_(); |
875 | const iRect rect = bounds_Widget(appIcon); | 880 | const iRect rect = bounds_Widget(appIcon); |
@@ -885,11 +890,11 @@ void draw_Window(iWindow *d) { | |||
885 | &(SDL_Rect){ left_Rect(rect) + gap_UI * 1.25f, mid.y - size / 2, size, size }); | 890 | &(SDL_Rect){ left_Rect(rect) + gap_UI * 1.25f, mid.y - size / 2, size, size }); |
886 | } | 891 | } |
887 | #endif | 892 | #endif |
893 | setCurrent_Root(NULL); | ||
888 | } | 894 | } |
889 | #if 0 | 895 | #if 0 |
890 | /* Text cache debugging. */ { | 896 | /* Text cache debugging. */ { |
891 | SDL_Texture *cache = glyphCache_Text(); | 897 | SDL_Rect rect = { d->root.widget->rect.size.x - 640, 0, 640, 2.5 * 640 }; |
892 | SDL_Rect rect = { d->root->rect.size.x - 640, 0, 640, 2.5 * 640 }; | ||
893 | SDL_SetRenderDrawColor(d->render, 0, 0, 0, 255); | 898 | SDL_SetRenderDrawColor(d->render, 0, 0, 0, 255); |
894 | SDL_RenderFillRect(d->render, &rect); | 899 | SDL_RenderFillRect(d->render, &rect); |
895 | SDL_RenderCopy(d->render, glyphCache_Text(), NULL, &rect); | 900 | SDL_RenderCopy(d->render, glyphCache_Text(), NULL, &rect); |