diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-20 11:37:23 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-20 11:37:23 +0300 |
commit | 2d81addf78d6a8b0fb2f2959b04a385c4adffdf2 (patch) | |
tree | 5e0f45b9c945499bc6a6669563de13c5203981a6 /src/ui/window.h | |
parent | 201021092d204680b353c82ce9e9beb76f3044e8 (diff) |
Experimenting with independent popup windows
Toe dipping into multiple window support by allowing popup menu widgets to be displayed in independent windows.
This is not a 100% replacement for native menus, but it gets pretty close.
Diffstat (limited to 'src/ui/window.h')
-rw-r--r-- | src/ui/window.h | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/src/ui/window.h b/src/ui/window.h index 73e92391..f1827931 100644 --- a/src/ui/window.h +++ b/src/ui/window.h | |||
@@ -29,8 +29,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
29 | #include <SDL_render.h> | 29 | #include <SDL_render.h> |
30 | #include <SDL_video.h> | 30 | #include <SDL_video.h> |
31 | 31 | ||
32 | enum iWindowType { | ||
33 | main_WindowType, | ||
34 | popup_WindowType, | ||
35 | }; | ||
36 | |||
32 | iDeclareType(MainWindow) | 37 | iDeclareType(MainWindow) |
38 | iDeclareType(Text) | ||
33 | iDeclareType(Window) | 39 | iDeclareType(Window) |
40 | |||
41 | iDeclareTypeConstructionArgs(Window, enum iWindowType type, iRect rect, uint32_t flags) | ||
34 | iDeclareTypeConstructionArgs(MainWindow, iRect rect) | 42 | iDeclareTypeConstructionArgs(MainWindow, iRect rect) |
35 | 43 | ||
36 | typedef iAny iAnyWindow; | 44 | typedef iAny iAnyWindow; |
@@ -71,15 +79,9 @@ enum iWindowSplit { | |||
71 | noEvents_WindowSplit = iBit(11), | 79 | noEvents_WindowSplit = iBit(11), |
72 | }; | 80 | }; |
73 | 81 | ||
74 | enum iWindowType { | ||
75 | main_WindowType, | ||
76 | popup_WindowType, | ||
77 | }; | ||
78 | |||
79 | struct Impl_Window { | 82 | struct Impl_Window { |
80 | enum iWindowType type; | 83 | enum iWindowType type; |
81 | SDL_Window * win; | 84 | SDL_Window * win; |
82 | iBool isDrawFrozen; /* avoids premature draws while restoring window state */ | ||
83 | iBool isExposed; | 85 | iBool isExposed; |
84 | iBool isMinimized; | 86 | iBool isMinimized; |
85 | iBool isMouseInside; | 87 | iBool isMouseInside; |
@@ -102,11 +104,13 @@ struct Impl_Window { | |||
102 | iRoot * roots[2]; /* root widget and UI state; second one is for split mode */ | 104 | iRoot * roots[2]; /* root widget and UI state; second one is for split mode */ |
103 | iRoot * keyRoot; /* root that has the current keyboard input focus */ | 105 | iRoot * keyRoot; /* root that has the current keyboard input focus */ |
104 | SDL_Texture * borderShadow; | 106 | SDL_Texture * borderShadow; |
107 | iText * text; | ||
105 | }; | 108 | }; |
106 | 109 | ||
107 | struct Impl_MainWindow { | 110 | struct Impl_MainWindow { |
108 | iWindow base; | 111 | iWindow base; |
109 | iWindowPlacement place; | 112 | iWindowPlacement place; |
113 | iBool isDrawFrozen; /* avoids premature draws while restoring window state */ | ||
110 | int splitMode; | 114 | int splitMode; |
111 | int pendingSplitMode; | 115 | int pendingSplitMode; |
112 | iString * pendingSplitUrl; /* URL to open in a newly opened split */ | 116 | iString * pendingSplitUrl; /* URL to open in a newly opened split */ |
@@ -115,7 +119,10 @@ struct Impl_MainWindow { | |||
115 | }; | 119 | }; |
116 | 120 | ||
117 | iLocalDef enum iWindowType type_Window(const iAnyWindow *d) { | 121 | iLocalDef enum iWindowType type_Window(const iAnyWindow *d) { |
118 | return ((const iWindow *) d)->type; | 122 | if (d) { |
123 | return ((const iWindow *) d)->type; | ||
124 | } | ||
125 | return main_WindowType; | ||
119 | } | 126 | } |
120 | 127 | ||
121 | uint32_t id_Window (const iWindow *); | 128 | uint32_t id_Window (const iWindow *); |
@@ -131,11 +138,11 @@ int numRoots_Window (const iWindow *); | |||
131 | iRoot * findRoot_Window (const iWindow *, const iWidget *widget); | 138 | iRoot * findRoot_Window (const iWindow *, const iWidget *widget); |
132 | iRoot * otherRoot_Window (const iWindow *, iRoot *root); | 139 | iRoot * otherRoot_Window (const iWindow *, iRoot *root); |
133 | 140 | ||
141 | iBool processEvent_Window (iWindow *, const SDL_Event *); | ||
134 | iBool dispatchEvent_Window (iWindow *, const SDL_Event *); | 142 | iBool dispatchEvent_Window (iWindow *, const SDL_Event *); |
135 | void invalidate_Window (iAnyWindow *); /* discard all cached graphics */ | 143 | void invalidate_Window (iAnyWindow *); /* discard all cached graphics */ |
136 | void draw_Window (iWindow *); | 144 | void draw_Window (iWindow *); |
137 | void setUiScale_Window (iWindow *, float uiScale); | 145 | void setUiScale_Window (iWindow *, float uiScale); |
138 | void setFreezeDraw_Window (iWindow *, iBool freezeDraw); | ||
139 | void setCursor_Window (iWindow *, int cursor); | 146 | void setCursor_Window (iWindow *, int cursor); |
140 | iBool setKeyRoot_Window (iWindow *, iRoot *root); | 147 | iBool setKeyRoot_Window (iWindow *, iRoot *root); |
141 | iBool postContextClick_Window (iWindow *, const SDL_MouseButtonEvent *); | 148 | iBool postContextClick_Window (iWindow *, const SDL_MouseButtonEvent *); |
@@ -143,6 +150,8 @@ iBool postContextClick_Window (iWindow *, const SDL_MouseButtonEvent *); | |||
143 | iWindow * get_Window (void); | 150 | iWindow * get_Window (void); |
144 | iBool isOpenGLRenderer_Window (void); | 151 | iBool isOpenGLRenderer_Window (void); |
145 | 152 | ||
153 | void setCurrent_Window (iAnyWindow *); | ||
154 | |||
146 | iLocalDef iBool isExposed_Window(const iWindow *d) { | 155 | iLocalDef iBool isExposed_Window(const iWindow *d) { |
147 | iAssert(d); | 156 | iAssert(d); |
148 | return d->isExposed; | 157 | return d->isExposed; |
@@ -158,6 +167,10 @@ iLocalDef const iWindow *constAs_Window(const iAnyWindow *d) { | |||
158 | return (const iWindow *) d; | 167 | return (const iWindow *) d; |
159 | } | 168 | } |
160 | 169 | ||
170 | iLocalDef iText *text_Window(const iAnyWindow *d) { | ||
171 | return constAs_Window(d)->text; | ||
172 | } | ||
173 | |||
161 | /*----------------------------------------------------------------------------------------------*/ | 174 | /*----------------------------------------------------------------------------------------------*/ |
162 | 175 | ||
163 | iLocalDef iWindow *asWindow_MainWindow(iMainWindow *d) { | 176 | iLocalDef iWindow *asWindow_MainWindow(iMainWindow *d) { |
@@ -167,6 +180,7 @@ iLocalDef iWindow *asWindow_MainWindow(iMainWindow *d) { | |||
167 | 180 | ||
168 | void setTitle_MainWindow (iMainWindow *, const iString *title); | 181 | void setTitle_MainWindow (iMainWindow *, const iString *title); |
169 | void setSnap_MainWindow (iMainWindow *, int snapMode); | 182 | void setSnap_MainWindow (iMainWindow *, int snapMode); |
183 | void setFreezeDraw_MainWindow (iMainWindow *, iBool freezeDraw); | ||
170 | void setKeyboardHeight_MainWindow (iMainWindow *, int height); | 184 | void setKeyboardHeight_MainWindow (iMainWindow *, int height); |
171 | void setSplitMode_MainWindow (iMainWindow *, int splitMode); | 185 | void setSplitMode_MainWindow (iMainWindow *, int splitMode); |
172 | void checkPendingSplit_MainWindow (iMainWindow *); | 186 | void checkPendingSplit_MainWindow (iMainWindow *); |
@@ -196,3 +210,7 @@ iLocalDef const iMainWindow *constAs_MainWindow(const iAnyWindow *d) { | |||
196 | iAssert(type_Window(d) == main_WindowType); | 210 | iAssert(type_Window(d) == main_WindowType); |
197 | return (const iMainWindow *) d; | 211 | return (const iMainWindow *) d; |
198 | } | 212 | } |
213 | |||
214 | /*----------------------------------------------------------------------------------------------*/ | ||
215 | |||
216 | iWindow * newPopup_Window (iInt2 screenPos, iWidget *rootWidget); | ||