The ZX Ecosystem v5.1.0;_GUI_v3.1.0
Loading...
Searching...
No Matches
ZXWindows.h
Go to the documentation of this file.
1
2/* **************************************************************************/
20#ifndef ZXWINDOWS
21#define ZXWINDOWS
22
23#include <string>
24#include <stack>
25#include <memory>
31
32
33namespace zxeco
34{
35
36namespace gui
37{
38
39
40/*****************************************************************************
41*
42* Class: Window
43*
44*******************************************************************************/
45
47
49class Window
50{
51 public:
52
53 /* -------------- Types, consts, etc. -------------- */
57 using Ptr = std::unique_ptr<Window>;
58
61 {
62 public:
63
65
69 DepthFirstInserter(bool autoid = false):autoid_{autoid} {}
70
71
72 void changeAutoID(bool autoid) { autoid_ = autoid; }
74
75 bool autoIDMode(void) const noexcept { return(autoid_); }
77
78 void checkAutoIDMode(void) const;
80
81 Widget & add(const Widget::Ptr & wp);
83
91 void closeContainer(void) { if (!conts_.empty()) conts_.pop(); }
93
97 Widget * root(void) const noexcept {return(root_?root_.get():nullptr);}
100 void setInWindow(Window & w);
102
105 private:
106
107 bool autoid_;
108 Widget::Ptr root_;
109 std::stack<Widget::Ptr> conts_;
110 };
111
112
114 enum class MngResult {
117 OUT_CLICK
118 };
119
121 static constexpr CharDist kLengthBars = 7;
126 /* -------------- Constructors -------------- */
129 Window(ZXEco & zxe, const CharRect & placem,
130 const std::string & title,
131 bool withborder = true, bool withzxbands = true,
132 const WinColors & wincols = WinColors::kLight,
133 bool preserveback = true);
135
153 Window(const Window & ) = delete;
154 Window(Window && ) = delete;
155 Window & operator=(const Window & ) = delete;
156 Window & operator=(Window && ) = delete;
157
158 virtual ~Window(void);
160
167 /* -------------- Getters -------------- */
170 ZXEco & zxEco(void) noexcept { return(*pzxeco_); }
172
173 const DoubleRect & placement(void) const noexcept { return(winabsrect_); }
175
176 const CharRect & bodyRelRect(void) const noexcept { return(bodyrelrect_); }
178
181 const WinColors & winColors(void) const noexcept { return(wincols_); }
183 bool hasBorder(void) const noexcept { return(withborder_); }
185
189 /* -------------- Widgets -------------- */
192 Widget * rootWidget(void);
194
199 /* -------------- Use -------------- */
202 MngResult manage(unsigned permill = 10);
204
215 void show(void);
217
224 void hide(bool preservcontent = true);
226
231 void clearBody(void) { drawBlank(); }
233
237 /* -------------- Others -------------- */
240 std::string to_string(void) const;
242
246 private:
247
249 enum class State {
250 UNDRAWN,
251 VISIBLE_PRES,
252 VISIBLE_UNPRES,
253 HIDDEN_PRES,
254 HIDDEN_UNPRES
255 };
256
257 static bool constexpr visibleState(State s) noexcept
259 { return((s == State::VISIBLE_PRES) || (s == State::VISIBLE_UNPRES)); }
260
261 static const std::string & nameOfState(State s);
263
264
265 const Bitmap zxbandchar_;
266
267 ZXEco * pzxeco_;
268 DoubleRect winabsrect_;
269 const CharRect titlerelrect_;
270 const CharRect bodyrelrect_;
271 const std::string title_;
272 const bool withborder_;
273 const bool withzxbands_;
274 const bool preserveback_;
275 WinColors wincols_;
276
277 DoubleGraphic blankmap_;
278 DoubleGraphic preservedbackgroundorcontent_;
279 State st_;
280 Widget::Ptr rootwidget_;
281
282
283 void preserve(DoubleGraphic & dest);
284 void restorePreserved(const DoubleGraphic & orig);
285 void drawBlank(void);
286 void drawContent(void);
287 bool mousePos(unsigned xm, unsigned ym, PixCursor & pc) const;
288 bool convertEvent(const PalettizedWindow::Event & de,
289 Widget::EventData & evd,
290 PointingStatus & m,
291 bool & mouseindrawable) const;
292};
293
294
295
296} // end namespace gui
297} // end namespace zxeco
298
299#endif
300 // ZXWindows
302
Events that the window can receive from its desktop environment.
static const WinColors kLight
Colors for light background, with bright.
Definition: ZXGUIGeneral.h:55
Colors used in a GUI window.
Definition: ZXGUIGeneral.h:53
All widgets must inherit from this.
Definition: ZXWidgetsBase.h:56
std::shared_ptr< Widget > Ptr
A polymorphic ptr to a widget.
Definition: ZXWidgetsBase.h:74
Window(const Window &)=delete
A window with the given parameters.
DepthFirstInserter(bool autoid=false)
Default constructor.
Definition: ZXWindows.h:69
Window(ZXEco &zxe, const CharRect &placem, const std::string &title, bool withborder=true, bool withzxbands=true, const WinColors &wincols=WinColors::kLight, bool preserveback=true)
A window with the given parameters.
std::string to_string(void) const
Return a text explaining the window.
Window & operator=(Window &&)=delete
A window with the given parameters.
Widget * root(void) const noexcept
Return a pointer to the root widget, if any, or nullptr otherwise.
Definition: ZXWindows.h:96
MngResult manage(unsigned permill=10)
Show the window and interact with the user in the given ecosystem.
bool hasBorder(void) const noexcept
Return TRUE if the window has a border.
Definition: ZXWindows.h:182
virtual ~Window(void)
Destructor.
Window & operator=(const Window &)=delete
A window with the given parameters.
void changeAutoID(bool autoid)
Change the current auto-ID mode to AUTOID (see the constructor).
Definition: ZXWindows.h:72
const DoubleRect & placement(void) const noexcept
Return a reference to the absolute placement of the window.
Definition: ZXWindows.h:173
Widget * rootWidget(void)
Return the root widget or nullptr if none.
bool autoIDMode(void) const noexcept
Return the current auto-ID mode (see the constructor).
Definition: ZXWindows.h:75
void checkAutoIDMode(void) const
If the inserter is not in auto-ID mode, throw (see the constructor)
const WinColors & winColors(void) const noexcept
Return the ecosystem where the window is working.
Definition: ZXWindows.h:180
void clearBody(void)
Clear the body area. Do nothing if the current state is not visible.
Definition: ZXWindows.h:230
Window(Window &&)=delete
A window with the given parameters.
void show(void)
Show the window space preserving previous background if desired.
const CharRect & bodyRelRect(void) const noexcept
Return a reference to the body rectangle of the window w.r.t. its orig.
Definition: ZXWindows.h:176
void closeContainer(void)
Close additions of widgets to the current container.
Definition: ZXWindows.h:91
ZXEco & zxEco(void) noexcept
Return the ecosystem where the window is working.
Definition: ZXWindows.h:170
Widget & add(const Widget::Ptr &wp)
Add a new widget as child of the current parent.
void setInWindow(Window &w)
Set the root widget of W to the root widget of this inserter.
void hide(bool preservcontent=true)
Hide the window, preserving the window contents if desired.
A window on the screen.
Definition: ZXWindows.h:50
To insert widgets in a window in a depth-first fashion.
Definition: ZXWindows.h:61
MngResult
Possible results of calling the manage() method.
Definition: ZXWindows.h:114
static constexpr CharDist kLengthBars
Number of chars printed in the title ZX when there are bars.
Definition: ZXWindows.h:121
std::unique_ptr< Window > Ptr
Safe pointer to a window.
Definition: ZXWindows.h:57
@ OUT_CLICK
A click/unclick out of win.
@ FINISHING_CALLBACK
A callback tells to finish.
@ DESKCLOSE_EVENT
A close of desktop received.
Cursor< PixelCoordT, PixelCoordT > PixCursor
Shortcut for this kind of cursor.
Definition: ZXGraphics.h:471
Rect< CharDistT, CharDistT > CharRect
Shortcut for this kind of rectangle.
Definition: ZXGraphics.h:735
uint16_t CharDist
A distance meadured in screen chars.
Definition: ZXGraphics.h:97
Class that provides access to the entire ecosystem: graphics, keyboard, etc.
Definition: ZXEcosystem.h:59
A rectangle with both char and pixel resolutions, possibly synchronized.
Definition: ZXGraphics.h:799
The main namespace of the library, that spans across all the zx modules.
Definition: ZXChars.h:31