summaryrefslogtreecommitdiff
path: root/src/ui/window.h
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-09-25 10:59:28 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-09-25 10:59:28 +0300
commitc80331992585bfee3d65a7ba24f3a4b640c48735 (patch)
tree5eaa85a0a3a1c46bdca7cccfae0e7349e22f6d13 /src/ui/window.h
parent562a0d2d38c0621a296e8343270f3f1efc268156 (diff)
parent242e8231ea61278fe482020658be86c2dec0ae53 (diff)
Merge branch 'work/v1.7' into dev
Diffstat (limited to 'src/ui/window.h')
-rw-r--r--src/ui/window.h155
1 files changed, 111 insertions, 44 deletions
diff --git a/src/ui/window.h b/src/ui/window.h
index 63f7e5f2..f1827931 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -29,8 +29,19 @@ 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
37iDeclareType(MainWindow)
38iDeclareType(Text)
32iDeclareType(Window) 39iDeclareType(Window)
33iDeclareTypeConstructionArgs(Window, iRect rect) 40
41iDeclareTypeConstructionArgs(Window, enum iWindowType type, iRect rect, uint32_t flags)
42iDeclareTypeConstructionArgs(MainWindow, iRect rect)
43
44typedef iAny iAnyWindow;
34 45
35enum iWindowSnap { 46enum iWindowSnap {
36 none_WindowSnap = 0, 47 none_WindowSnap = 0,
@@ -69,9 +80,8 @@ enum iWindowSplit {
69}; 80};
70 81
71struct Impl_Window { 82struct Impl_Window {
83 enum iWindowType type;
72 SDL_Window * win; 84 SDL_Window * win;
73 iWindowPlacement place;
74 iBool isDrawFrozen; /* avoids premature draws while restoring window state */
75 iBool isExposed; 85 iBool isExposed;
76 iBool isMinimized; 86 iBool isMinimized;
77 iBool isMouseInside; 87 iBool isMouseInside;
@@ -80,12 +90,8 @@ struct Impl_Window {
80 uint32_t focusGainedAt; 90 uint32_t focusGainedAt;
81 SDL_Renderer *render; 91 SDL_Renderer *render;
82 iInt2 size; 92 iInt2 size;
83 int splitMode;
84 int pendingSplitMode;
85 iString * pendingSplitUrl; /* URL to open in a newly opened split */
86 iRoot * roots[2]; /* root widget and UI state; second one is for split mode */
87 iRoot * keyRoot; /* root that has the current keyboard input focus */
88 iWidget * hover; 93 iWidget * hover;
94 iWidget * lastHover; /* cleared if deleted */
89 iWidget * mouseGrab; 95 iWidget * mouseGrab;
90 iWidget * focus; 96 iWidget * focus;
91 float pixelRatio; /* conversion between points and pixels, e.g., coords, window size */ 97 float pixelRatio; /* conversion between points and pixels, e.g., coords, window size */
@@ -93,57 +99,118 @@ struct Impl_Window {
93 float uiScale; 99 float uiScale;
94 uint32_t frameTime; 100 uint32_t frameTime;
95 double presentTime; 101 double presentTime;
96 SDL_Texture * appIcon;
97 SDL_Texture * borderShadow;
98 SDL_Cursor * cursors[SDL_NUM_SYSTEM_CURSORS]; 102 SDL_Cursor * cursors[SDL_NUM_SYSTEM_CURSORS];
99 SDL_Cursor * pendingCursor; 103 SDL_Cursor * pendingCursor;
100 int loadAnimTimer; 104 iRoot * roots[2]; /* root widget and UI state; second one is for split mode */
101 iAnim rootOffset; 105 iRoot * keyRoot; /* root that has the current keyboard input focus */
102 int keyboardHeight; /* mobile software keyboards */ 106 SDL_Texture * borderShadow;
107 iText * text;
103}; 108};
104 109
110struct Impl_MainWindow {
111 iWindow base;
112 iWindowPlacement place;
113 iBool isDrawFrozen; /* avoids premature draws while restoring window state */
114 int splitMode;
115 int pendingSplitMode;
116 iString * pendingSplitUrl; /* URL to open in a newly opened split */
117 SDL_Texture * appIcon;
118 int keyboardHeight; /* mobile software keyboards */
119};
120
121iLocalDef enum iWindowType type_Window(const iAnyWindow *d) {
122 if (d) {
123 return ((const iWindow *) d)->type;
124 }
125 return main_WindowType;
126}
127
128uint32_t id_Window (const iWindow *);
129iInt2 size_Window (const iWindow *);
130iInt2 maxTextureSize_Window (const iWindow *);
131float uiScale_Window (const iWindow *);
132iInt2 coord_Window (const iWindow *, int x, int y);
133iInt2 mouseCoord_Window (const iWindow *, int whichDevice);
134iAnyObject * hitChild_Window (const iWindow *, iInt2 coord);
135uint32_t frameTime_Window (const iWindow *);
136SDL_Renderer * renderer_Window (const iWindow *);
137int numRoots_Window (const iWindow *);
138iRoot * findRoot_Window (const iWindow *, const iWidget *widget);
139iRoot * otherRoot_Window (const iWindow *, iRoot *root);
140
105iBool processEvent_Window (iWindow *, const SDL_Event *); 141iBool processEvent_Window (iWindow *, const SDL_Event *);
106iBool dispatchEvent_Window (iWindow *, const SDL_Event *); 142iBool dispatchEvent_Window (iWindow *, const SDL_Event *);
107void invalidate_Window (iWindow *); /* discard all cached graphics */ 143void invalidate_Window (iAnyWindow *); /* discard all cached graphics */
108void draw_Window (iWindow *); 144void draw_Window (iWindow *);
109void drawWhileResizing_Window(iWindow *d, int w, int h); /* workaround for SDL bug */
110void resize_Window (iWindow *, int w, int h);
111void setTitle_Window (iWindow *, const iString *title);
112void setUiScale_Window (iWindow *, float uiScale); 145void setUiScale_Window (iWindow *, float uiScale);
113void setFreezeDraw_Window (iWindow *, iBool freezeDraw);
114iBool setKeyRoot_Window (iWindow *, iRoot *root);
115void setCursor_Window (iWindow *, int cursor); 146void setCursor_Window (iWindow *, int cursor);
116void setSnap_Window (iWindow *, int snapMode); 147iBool setKeyRoot_Window (iWindow *, iRoot *root);
117void setKeyboardHeight_Window(iWindow *, int height);
118void setSplitMode_Window (iWindow *, int splitMode);
119void showToolbars_Window (iWindow *, iBool show);
120iBool postContextClick_Window (iWindow *, const SDL_MouseButtonEvent *); 148iBool postContextClick_Window (iWindow *, const SDL_MouseButtonEvent *);
121void checkPendingSplit_Window(iWindow *);
122void swapRoots_Window (iWindow *);
123
124uint32_t id_Window (const iWindow *);
125iInt2 size_Window (const iWindow *);
126iInt2 maxTextureSize_Window (const iWindow *);
127float uiScale_Window (const iWindow *);
128iInt2 coord_Window (const iWindow *, int x, int y);
129iInt2 mouseCoord_Window (const iWindow *, int whichDevice);
130iAnyObject *hitChild_Window (const iWindow *, iInt2 coord);
131uint32_t frameTime_Window (const iWindow *);
132SDL_Renderer *renderer_Window (const iWindow *);
133int snap_Window (const iWindow *);
134iBool isFullscreen_Window (const iWindow *);
135int numRoots_Window (const iWindow *);
136iRoot * findRoot_Window (const iWindow *, const iWidget *widget);
137iRoot * otherRoot_Window (const iWindow *, iRoot *root);
138iWindow * get_Window (void);
139 149
150iWindow * get_Window (void);
140iBool isOpenGLRenderer_Window (void); 151iBool isOpenGLRenderer_Window (void);
141 152
142#if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) 153void setCurrent_Window (iAnyWindow *);
143SDL_HitTestResult hitTest_Window(const iWindow *d, iInt2 pos);
144#endif
145 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;
149} 158}
159
160iLocalDef iWindow *as_Window(iAnyWindow *d) {
161 iAssert(type_Window(d) == main_WindowType || type_Window(d) == popup_WindowType);
162 return (iWindow *) d;
163}
164
165iLocalDef const iWindow *constAs_Window(const iAnyWindow *d) {
166 iAssert(type_Window(d) == main_WindowType || type_Window(d) == popup_WindowType);
167 return (const iWindow *) d;
168}
169
170iLocalDef iText *text_Window(const iAnyWindow *d) {
171 return constAs_Window(d)->text;
172}
173
174/*----------------------------------------------------------------------------------------------*/
175
176iLocalDef iWindow *asWindow_MainWindow(iMainWindow *d) {
177 iAssert(type_Window(d) == main_WindowType);
178 return &d->base;
179}
180
181void setTitle_MainWindow (iMainWindow *, const iString *title);
182void setSnap_MainWindow (iMainWindow *, int snapMode);
183void setFreezeDraw_MainWindow (iMainWindow *, iBool freezeDraw);
184void setKeyboardHeight_MainWindow (iMainWindow *, int height);
185void setSplitMode_MainWindow (iMainWindow *, int splitMode);
186void checkPendingSplit_MainWindow (iMainWindow *);
187void swapRoots_MainWindow (iMainWindow *);
188void showToolbars_MainWindow (iMainWindow *, iBool show);
189void resize_MainWindow (iMainWindow *, int w, int h);
190
191iBool processEvent_MainWindow (iMainWindow *, const SDL_Event *);
192void draw_MainWindow (iMainWindow *);
193void drawWhileResizing_MainWindow (iMainWindow *, int w, int h); /* workaround for SDL bug */
194
195int snap_MainWindow (const iMainWindow *);
196iBool isFullscreen_Window (const iMainWindow *);
197
198#if defined (LAGRANGE_ENABLE_CUSTOM_FRAME)
199SDL_HitTestResult hitTest_MainWindow(const iMainWindow *d, iInt2 pos);
200#endif
201
202iMainWindow * get_MainWindow (void);
203
204iLocalDef iMainWindow *as_MainWindow(iAnyWindow *d) {
205 iAssert(type_Window(d) == main_WindowType);
206 return (iMainWindow *) d;
207}
208
209iLocalDef const iMainWindow *constAs_MainWindow(const iAnyWindow *d) {
210 iAssert(type_Window(d) == main_WindowType);
211 return (const iMainWindow *) d;
212}
213
214/*----------------------------------------------------------------------------------------------*/
215
216iWindow * newPopup_Window (iInt2 screenPos, iWidget *rootWidget);