summaryrefslogtreecommitdiff
path: root/src/ui/window.h
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-09-20 11:37:23 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-09-20 11:37:23 +0300
commit2d81addf78d6a8b0fb2f2959b04a385c4adffdf2 (patch)
tree5e0f45b9c945499bc6a6669563de13c5203981a6 /src/ui/window.h
parent201021092d204680b353c82ce9e9beb76f3044e8 (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.h34
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
32enum iWindowType {
33 main_WindowType,
34 popup_WindowType,
35};
36
32iDeclareType(MainWindow) 37iDeclareType(MainWindow)
38iDeclareType(Text)
33iDeclareType(Window) 39iDeclareType(Window)
40
41iDeclareTypeConstructionArgs(Window, enum iWindowType type, iRect rect, uint32_t flags)
34iDeclareTypeConstructionArgs(MainWindow, iRect rect) 42iDeclareTypeConstructionArgs(MainWindow, iRect rect)
35 43
36typedef iAny iAnyWindow; 44typedef iAny iAnyWindow;
@@ -71,15 +79,9 @@ enum iWindowSplit {
71 noEvents_WindowSplit = iBit(11), 79 noEvents_WindowSplit = iBit(11),
72}; 80};
73 81
74enum iWindowType {
75 main_WindowType,
76 popup_WindowType,
77};
78
79struct Impl_Window { 82struct 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
107struct Impl_MainWindow { 110struct 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
117iLocalDef enum iWindowType type_Window(const iAnyWindow *d) { 121iLocalDef 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
121uint32_t id_Window (const iWindow *); 128uint32_t id_Window (const iWindow *);
@@ -131,11 +138,11 @@ int numRoots_Window (const iWindow *);
131iRoot * findRoot_Window (const iWindow *, const iWidget *widget); 138iRoot * findRoot_Window (const iWindow *, const iWidget *widget);
132iRoot * otherRoot_Window (const iWindow *, iRoot *root); 139iRoot * otherRoot_Window (const iWindow *, iRoot *root);
133 140
141iBool processEvent_Window (iWindow *, const SDL_Event *);
134iBool dispatchEvent_Window (iWindow *, const SDL_Event *); 142iBool dispatchEvent_Window (iWindow *, const SDL_Event *);
135void invalidate_Window (iAnyWindow *); /* discard all cached graphics */ 143void invalidate_Window (iAnyWindow *); /* discard all cached graphics */
136void draw_Window (iWindow *); 144void draw_Window (iWindow *);
137void setUiScale_Window (iWindow *, float uiScale); 145void setUiScale_Window (iWindow *, float uiScale);
138void setFreezeDraw_Window (iWindow *, iBool freezeDraw);
139void setCursor_Window (iWindow *, int cursor); 146void setCursor_Window (iWindow *, int cursor);
140iBool setKeyRoot_Window (iWindow *, iRoot *root); 147iBool setKeyRoot_Window (iWindow *, iRoot *root);
141iBool postContextClick_Window (iWindow *, const SDL_MouseButtonEvent *); 148iBool postContextClick_Window (iWindow *, const SDL_MouseButtonEvent *);
@@ -143,6 +150,8 @@ iBool postContextClick_Window (iWindow *, const SDL_MouseButtonEvent *);
143iWindow * get_Window (void); 150iWindow * get_Window (void);
144iBool isOpenGLRenderer_Window (void); 151iBool isOpenGLRenderer_Window (void);
145 152
153void setCurrent_Window (iAnyWindow *);
154
146iLocalDef iBool isExposed_Window(const iWindow *d) { 155iLocalDef 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
170iLocalDef iText *text_Window(const iAnyWindow *d) {
171 return constAs_Window(d)->text;
172}
173
161/*----------------------------------------------------------------------------------------------*/ 174/*----------------------------------------------------------------------------------------------*/
162 175
163iLocalDef iWindow *asWindow_MainWindow(iMainWindow *d) { 176iLocalDef iWindow *asWindow_MainWindow(iMainWindow *d) {
@@ -167,6 +180,7 @@ iLocalDef iWindow *asWindow_MainWindow(iMainWindow *d) {
167 180
168void setTitle_MainWindow (iMainWindow *, const iString *title); 181void setTitle_MainWindow (iMainWindow *, const iString *title);
169void setSnap_MainWindow (iMainWindow *, int snapMode); 182void setSnap_MainWindow (iMainWindow *, int snapMode);
183void setFreezeDraw_MainWindow (iMainWindow *, iBool freezeDraw);
170void setKeyboardHeight_MainWindow (iMainWindow *, int height); 184void setKeyboardHeight_MainWindow (iMainWindow *, int height);
171void setSplitMode_MainWindow (iMainWindow *, int splitMode); 185void setSplitMode_MainWindow (iMainWindow *, int splitMode);
172void checkPendingSplit_MainWindow (iMainWindow *); 186void 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
216iWindow * newPopup_Window (iInt2 screenPos, iWidget *rootWidget);