diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-23 22:39:22 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-23 22:39:22 +0300 |
commit | 91167bd9d49ac52587da382351a009e2465c3bdd (patch) | |
tree | 6836d85b04aacfdbb78d155494f8312f67e0dcd9 | |
parent | 9a419d89fac606f309dab09c80ef398f98118107 (diff) |
Widget: Keep-on-top widgets have an order
-rw-r--r-- | src/ui/widget.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/ui/widget.c b/src/ui/widget.c index 8277b921..f187bb82 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c | |||
@@ -28,6 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
28 | #include "util.h" | 28 | #include "util.h" |
29 | #include "window.h" | 29 | #include "window.h" |
30 | 30 | ||
31 | #include <the_Foundation/ptrarray.h> | ||
31 | #include <the_Foundation/ptrset.h> | 32 | #include <the_Foundation/ptrset.h> |
32 | #include <SDL_mouse.h> | 33 | #include <SDL_mouse.h> |
33 | #include <stdarg.h> | 34 | #include <stdarg.h> |
@@ -38,15 +39,15 @@ struct Impl_RootData { | |||
38 | iWidget *hover; | 39 | iWidget *hover; |
39 | iWidget *mouseGrab; | 40 | iWidget *mouseGrab; |
40 | iWidget *focus; | 41 | iWidget *focus; |
41 | iPtrSet *onTop; | 42 | iPtrArray *onTop; /* order is important; last one is topmost */ |
42 | iPtrSet *pendingDestruction; | 43 | iPtrSet *pendingDestruction; |
43 | }; | 44 | }; |
44 | 45 | ||
45 | static iRootData rootData_; | 46 | static iRootData rootData_; |
46 | 47 | ||
47 | iPtrSet *onTop_RootData_(void) { | 48 | iPtrArray *onTop_RootData_(void) { |
48 | if (!rootData_.onTop) { | 49 | if (!rootData_.onTop) { |
49 | rootData_.onTop = new_PtrSet(); | 50 | rootData_.onTop = new_PtrArray(); |
50 | } | 51 | } |
51 | return rootData_.onTop; | 52 | return rootData_.onTop; |
52 | } | 53 | } |
@@ -54,7 +55,7 @@ iPtrSet *onTop_RootData_(void) { | |||
54 | void destroyPending_Widget(void) { | 55 | void destroyPending_Widget(void) { |
55 | iForEach(PtrSet, i, rootData_.pendingDestruction) { | 56 | iForEach(PtrSet, i, rootData_.pendingDestruction) { |
56 | iWidget *widget = *i.value; | 57 | iWidget *widget = *i.value; |
57 | remove_PtrSet(onTop_RootData_(), widget); | 58 | removeOne_PtrArray(onTop_RootData_(), widget); |
58 | if (widget->parent) { | 59 | if (widget->parent) { |
59 | iRelease(removeChild_Widget(widget->parent, widget)); | 60 | iRelease(removeChild_Widget(widget->parent, widget)); |
60 | } | 61 | } |
@@ -126,10 +127,10 @@ void setFlags_Widget(iWidget *d, int flags, iBool set) { | |||
126 | iChangeFlags(d->flags, flags, set); | 127 | iChangeFlags(d->flags, flags, set); |
127 | if (flags & keepOnTop_WidgetFlag) { | 128 | if (flags & keepOnTop_WidgetFlag) { |
128 | if (set) { | 129 | if (set) { |
129 | insert_PtrSet(onTop_RootData_(), d); | 130 | pushBack_PtrArray(onTop_RootData_(), d); |
130 | } | 131 | } |
131 | else { | 132 | else { |
132 | remove_PtrSet(onTop_RootData_(), d); | 133 | removeOne_PtrArray(onTop_RootData_(), d); |
133 | } | 134 | } |
134 | } | 135 | } |
135 | } | 136 | } |
@@ -422,7 +423,7 @@ iBool dispatchEvent_Widget(iWidget *d, const SDL_Event *ev) { | |||
422 | } | 423 | } |
423 | } | 424 | } |
424 | /* Root offers events first to widgets on top. */ | 425 | /* Root offers events first to widgets on top. */ |
425 | iForEach(PtrSet, i, rootData_.onTop) { | 426 | iReverseForEach(PtrArray, i, rootData_.onTop) { |
426 | iWidget *widget = *i.value; | 427 | iWidget *widget = *i.value; |
427 | if (isVisible_Widget(widget) && dispatchEvent_Widget(widget, ev)) { | 428 | if (isVisible_Widget(widget) && dispatchEvent_Widget(widget, ev)) { |
428 | return iTrue; | 429 | return iTrue; |
@@ -522,7 +523,7 @@ void draw_Widget(const iWidget *d) { | |||
522 | } | 523 | } |
523 | /* Root draws the on-top widgets on top of everything else. */ | 524 | /* Root draws the on-top widgets on top of everything else. */ |
524 | if (!d->parent) { | 525 | if (!d->parent) { |
525 | iConstForEach(PtrSet, i, onTop_RootData_()) { | 526 | iConstForEach(PtrArray, i, onTop_RootData_()) { |
526 | draw_Widget(*i.value); | 527 | draw_Widget(*i.value); |
527 | } | 528 | } |
528 | } | 529 | } |