diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-25 10:59:28 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-25 10:59:28 +0300 |
commit | c80331992585bfee3d65a7ba24f3a4b640c48735 (patch) | |
tree | 5eaa85a0a3a1c46bdca7cccfae0e7349e22f6d13 /src/ui/window.h | |
parent | 562a0d2d38c0621a296e8343270f3f1efc268156 (diff) | |
parent | 242e8231ea61278fe482020658be86c2dec0ae53 (diff) |
Merge branch 'work/v1.7' into dev
Diffstat (limited to 'src/ui/window.h')
-rw-r--r-- | src/ui/window.h | 155 |
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 | ||
32 | enum iWindowType { | ||
33 | main_WindowType, | ||
34 | popup_WindowType, | ||
35 | }; | ||
36 | |||
37 | iDeclareType(MainWindow) | ||
38 | iDeclareType(Text) | ||
32 | iDeclareType(Window) | 39 | iDeclareType(Window) |
33 | iDeclareTypeConstructionArgs(Window, iRect rect) | 40 | |
41 | iDeclareTypeConstructionArgs(Window, enum iWindowType type, iRect rect, uint32_t flags) | ||
42 | iDeclareTypeConstructionArgs(MainWindow, iRect rect) | ||
43 | |||
44 | typedef iAny iAnyWindow; | ||
34 | 45 | ||
35 | enum iWindowSnap { | 46 | enum iWindowSnap { |
36 | none_WindowSnap = 0, | 47 | none_WindowSnap = 0, |
@@ -69,9 +80,8 @@ enum iWindowSplit { | |||
69 | }; | 80 | }; |
70 | 81 | ||
71 | struct Impl_Window { | 82 | struct 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 | ||
110 | struct 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 | |||
121 | iLocalDef enum iWindowType type_Window(const iAnyWindow *d) { | ||
122 | if (d) { | ||
123 | return ((const iWindow *) d)->type; | ||
124 | } | ||
125 | return main_WindowType; | ||
126 | } | ||
127 | |||
128 | uint32_t id_Window (const iWindow *); | ||
129 | iInt2 size_Window (const iWindow *); | ||
130 | iInt2 maxTextureSize_Window (const iWindow *); | ||
131 | float uiScale_Window (const iWindow *); | ||
132 | iInt2 coord_Window (const iWindow *, int x, int y); | ||
133 | iInt2 mouseCoord_Window (const iWindow *, int whichDevice); | ||
134 | iAnyObject * hitChild_Window (const iWindow *, iInt2 coord); | ||
135 | uint32_t frameTime_Window (const iWindow *); | ||
136 | SDL_Renderer * renderer_Window (const iWindow *); | ||
137 | int numRoots_Window (const iWindow *); | ||
138 | iRoot * findRoot_Window (const iWindow *, const iWidget *widget); | ||
139 | iRoot * otherRoot_Window (const iWindow *, iRoot *root); | ||
140 | |||
105 | iBool processEvent_Window (iWindow *, const SDL_Event *); | 141 | iBool processEvent_Window (iWindow *, const SDL_Event *); |
106 | iBool dispatchEvent_Window (iWindow *, const SDL_Event *); | 142 | iBool dispatchEvent_Window (iWindow *, const SDL_Event *); |
107 | void invalidate_Window (iWindow *); /* discard all cached graphics */ | 143 | void invalidate_Window (iAnyWindow *); /* discard all cached graphics */ |
108 | void draw_Window (iWindow *); | 144 | void draw_Window (iWindow *); |
109 | void drawWhileResizing_Window(iWindow *d, int w, int h); /* workaround for SDL bug */ | ||
110 | void resize_Window (iWindow *, int w, int h); | ||
111 | void setTitle_Window (iWindow *, const iString *title); | ||
112 | void setUiScale_Window (iWindow *, float uiScale); | 145 | void setUiScale_Window (iWindow *, float uiScale); |
113 | void setFreezeDraw_Window (iWindow *, iBool freezeDraw); | ||
114 | iBool setKeyRoot_Window (iWindow *, iRoot *root); | ||
115 | void setCursor_Window (iWindow *, int cursor); | 146 | void setCursor_Window (iWindow *, int cursor); |
116 | void setSnap_Window (iWindow *, int snapMode); | 147 | iBool setKeyRoot_Window (iWindow *, iRoot *root); |
117 | void setKeyboardHeight_Window(iWindow *, int height); | ||
118 | void setSplitMode_Window (iWindow *, int splitMode); | ||
119 | void showToolbars_Window (iWindow *, iBool show); | ||
120 | iBool postContextClick_Window (iWindow *, const SDL_MouseButtonEvent *); | 148 | iBool postContextClick_Window (iWindow *, const SDL_MouseButtonEvent *); |
121 | void checkPendingSplit_Window(iWindow *); | ||
122 | void swapRoots_Window (iWindow *); | ||
123 | |||
124 | uint32_t id_Window (const iWindow *); | ||
125 | iInt2 size_Window (const iWindow *); | ||
126 | iInt2 maxTextureSize_Window (const iWindow *); | ||
127 | float uiScale_Window (const iWindow *); | ||
128 | iInt2 coord_Window (const iWindow *, int x, int y); | ||
129 | iInt2 mouseCoord_Window (const iWindow *, int whichDevice); | ||
130 | iAnyObject *hitChild_Window (const iWindow *, iInt2 coord); | ||
131 | uint32_t frameTime_Window (const iWindow *); | ||
132 | SDL_Renderer *renderer_Window (const iWindow *); | ||
133 | int snap_Window (const iWindow *); | ||
134 | iBool isFullscreen_Window (const iWindow *); | ||
135 | int numRoots_Window (const iWindow *); | ||
136 | iRoot * findRoot_Window (const iWindow *, const iWidget *widget); | ||
137 | iRoot * otherRoot_Window (const iWindow *, iRoot *root); | ||
138 | iWindow * get_Window (void); | ||
139 | 149 | ||
150 | iWindow * get_Window (void); | ||
140 | iBool isOpenGLRenderer_Window (void); | 151 | iBool isOpenGLRenderer_Window (void); |
141 | 152 | ||
142 | #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) | 153 | void setCurrent_Window (iAnyWindow *); |
143 | SDL_HitTestResult hitTest_Window(const iWindow *d, iInt2 pos); | ||
144 | #endif | ||
145 | 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; |
149 | } | 158 | } |
159 | |||
160 | iLocalDef iWindow *as_Window(iAnyWindow *d) { | ||
161 | iAssert(type_Window(d) == main_WindowType || type_Window(d) == popup_WindowType); | ||
162 | return (iWindow *) d; | ||
163 | } | ||
164 | |||
165 | iLocalDef 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 | |||
170 | iLocalDef iText *text_Window(const iAnyWindow *d) { | ||
171 | return constAs_Window(d)->text; | ||
172 | } | ||
173 | |||
174 | /*----------------------------------------------------------------------------------------------*/ | ||
175 | |||
176 | iLocalDef iWindow *asWindow_MainWindow(iMainWindow *d) { | ||
177 | iAssert(type_Window(d) == main_WindowType); | ||
178 | return &d->base; | ||
179 | } | ||
180 | |||
181 | void setTitle_MainWindow (iMainWindow *, const iString *title); | ||
182 | void setSnap_MainWindow (iMainWindow *, int snapMode); | ||
183 | void setFreezeDraw_MainWindow (iMainWindow *, iBool freezeDraw); | ||
184 | void setKeyboardHeight_MainWindow (iMainWindow *, int height); | ||
185 | void setSplitMode_MainWindow (iMainWindow *, int splitMode); | ||
186 | void checkPendingSplit_MainWindow (iMainWindow *); | ||
187 | void swapRoots_MainWindow (iMainWindow *); | ||
188 | void showToolbars_MainWindow (iMainWindow *, iBool show); | ||
189 | void resize_MainWindow (iMainWindow *, int w, int h); | ||
190 | |||
191 | iBool processEvent_MainWindow (iMainWindow *, const SDL_Event *); | ||
192 | void draw_MainWindow (iMainWindow *); | ||
193 | void drawWhileResizing_MainWindow (iMainWindow *, int w, int h); /* workaround for SDL bug */ | ||
194 | |||
195 | int snap_MainWindow (const iMainWindow *); | ||
196 | iBool isFullscreen_Window (const iMainWindow *); | ||
197 | |||
198 | #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) | ||
199 | SDL_HitTestResult hitTest_MainWindow(const iMainWindow *d, iInt2 pos); | ||
200 | #endif | ||
201 | |||
202 | iMainWindow * get_MainWindow (void); | ||
203 | |||
204 | iLocalDef iMainWindow *as_MainWindow(iAnyWindow *d) { | ||
205 | iAssert(type_Window(d) == main_WindowType); | ||
206 | return (iMainWindow *) d; | ||
207 | } | ||
208 | |||
209 | iLocalDef const iMainWindow *constAs_MainWindow(const iAnyWindow *d) { | ||
210 | iAssert(type_Window(d) == main_WindowType); | ||
211 | return (const iMainWindow *) d; | ||
212 | } | ||
213 | |||
214 | /*----------------------------------------------------------------------------------------------*/ | ||
215 | |||
216 | iWindow * newPopup_Window (iInt2 screenPos, iWidget *rootWidget); | ||