The ZX Ecosystem v5.1.0;_GUI_v3.1.0
Loading...
Searching...
No Matches
ZXWidgetCanvas.h
Go to the documentation of this file.
1
2/* **************************************************************************/
19#ifndef ZXWIDGET_CANVAS
20#define ZXWIDGET_CANVAS
21
22#include <functional>
25
26
27namespace zxeco
28{
29
30namespace gui
31{
32
33/*******************************************************************************
34*
35* Class: CanvasWidget
36*
37*******************************************************************************/
38
40
45{
46 public:
47
48 using DrawCallback = std::function< void(CanvasWidget &) >;
50
51
52 CanvasWidget(ID id, const std::string & name,
53 const CharArea & totdims, const CharArea & viewportdims,
54 const DrawCallback & drawcallback,
55 bool movekeys = false, CharDist inchor = 1, CharDist incver =1,
56 const std::string & tooltiptext = "",
57 HorAlign hal = HorAlign::LEFT,
58 VertAlign val = VertAlign::TOP);
60
84 void changeDrawCallback(const DrawCallback & newcbk)
85
86 { viewportshiftcallback_ = newcbk; }
87
88 Screen & canvas(void);
90
97 CharRect viewport(void) const;
99
101 void moveViewport(const CharCursor & corner);
103
109
114 bool eventProcessedByViewport(const CallbackParms & cbp) const noexcept
116
120 { return((cbp.moment == 'A') &&
121 (cbp.whoprocessed != nullptr) &&
122 (cbp.whoprocessed == canvas_)); }
123
125 CharCursor & relpos) const;
127
132 const char * className(void) const noexcept { return("CanvasWidget"); }
133 void setTooltip(const std::string & ttt) override
134 { canvas_->setTooltip(ttt); }
135 const AreaFitting & calcFittingNeeds(const CharArea & area);
137
138
139 private:
140
141 enum Subwidgs {
142 FIRSTCONT = 0,
143 CANVAS,
144 VERTSCROLL,
145 HORIZSCROLL,
146 NUMSUBWIDGETS
147 };
148
149 static const ID kIDsSubs[NUMSUBWIDGETS];
150
151
152 const bool movekeys_;
153 CharArea totdims_;
154 DrawCallback viewportshiftcallback_;
155 CharCursor cornerviewport_;
156 ContainerWidget * firstcont_;
157 Widget * canvas_;
158 SlideWidget * pvertscroll_;
159 SlideWidget * phorizscroll_;
160 double oldvalh_,oldvalv_;
161
162 std::string scrollStatesInfo(void) const;
163 const CharArea areaNeededFor(const CharArea & avail,
164 bool & vscr, bool & hscr) const;
165 void drawRaw(void);
166 int processEvent(const EventData & evdata, Widget * who) override;
167};
168
169
170
171} // end namespace gui
172} // end namespace zxeco
173
174#endif
175 // ZXWidgetCanvas
177
178
179
HorAlign
Horizontal alignment of widgets within the areas of their containers.
VertAlign
Vertical alignment of widgets within the areas of their containers.
virtual void setTooltip(const std::string &ttt)
Must return a text with the name of the class.
A container of other widgets.
All widgets must inherit from this.
Definition: ZXWidgetsBase.h:56
int ID
A numeric ID associated to the widget.
Definition: ZXWidgetsBase.h:67
Information about the fitting of widgets drawings into rectangular areas.
A class to contain the parameters received by a callback routine.
void setTooltip(const std::string &ttt) override
Must return a text with the name of the class.
bool mouseCharPosInViewport(const PointingStatus &mouse, CharCursor &relpos) const
Calculate the char-relative position of MOUSE into the canvas.
bool eventProcessedByViewport(const CallbackParms &cbp) const noexcept
< Return TRUE if the event has processed within viewport and not scrolls.
void moveViewport(const CharCursor &corner)
Set the new viewport to the given one.
Screen & canvas(void)
Return the portion of screen where to write/draw; size of the viewport.
void changeDrawCallback(const DrawCallback &newcbk)
const AreaFitting & calcFittingNeeds(const CharArea &area)
Must calculate the widget fitting within the dimensions of AREA.
std::function< void(CanvasWidget &) > DrawCallback
Callback called every time the viewport is moved or the canvas drawn.
CharCursor maxViewportPos(void) const
Return the maximum coordinates that the viewport corner may have.
Widget * setDrawingZone(const CharRect &zone)
Set the final drawing zone for the widget and the aligned one.
CharRect viewport(void) const
Return the current location of the viewport within underlying canvas.
const char * className(void) const noexcept
Must return a text with the name of the class.
CanvasWidget(ID id, const std::string &name, const CharArea &totdims, const CharArea &viewportdims, const DrawCallback &drawcallback, bool movekeys=false, CharDist inchor=1, CharDist incver=1, const std::string &tooltiptext="", HorAlign hal=HorAlign::LEFT, VertAlign val=VertAlign::TOP)
Constructor. The underlying canvas is also constructed and owned here.
A possibly scrollable canvas where to write/draw things.
A slide, either horizontal or vertical, e.g., to serve as scroll bar.
Definition: ZXWidgetSlide.h:39
uint16_t CharDist
A distance meadured in screen chars.
Definition: ZXGraphics.h:97
Status of the pointing device.
Definition: ZXPointing.h:39
The class that provides the main support for managing the ZX screen.
Definition: ZXScreen.h:89
The main namespace of the library, that spans across all the zx modules.
Definition: ZXChars.h:31