NXWidgets: cnxwindow.hxx Source File

NXWidgets 1.19

cnxwindow.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/include/cnxwindow.hxx
3 *
4 * Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved.
5 * Author: Gregory Nutt <gnutt@nuttx.org>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
18 * me be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************/
35
36 #ifndef __INCLUDE_CNXWINDOW_HXX
37 #define __INCLUDE_CNXWINDOW_HXX
38
39 /****************************************************************************
40 * Included Files
41 ****************************************************************************/
42
43 #include <nuttx/config.h>
44
45 #include <stdint.h>
46 #include <stdbool.h>
47
48 #include <nuttx/nx/nxglib.h>
49 #include <nuttx/nx/nx.h>
50 #include <nuttx/nx/nxtk.h>
51
52 #include "ccallback.hxx"
53 #include "inxwindow.hxx"
54
55 /****************************************************************************
56 * Pre-Processor Definitions
57 ****************************************************************************/
58
59 /****************************************************************************
60 * Implementation Classes
61 ****************************************************************************/
62
63 #if defined(__cplusplus)
64
65 namespace NXWidgets
66 {
67 struct SBitmap;
68
69 /**
70 * This class defines operations on a basic "raw" NX window. These windows
71 * are "raw" in the since that they are simply rectangular regions with
72 * no framing or decoration of any kind
73 *
74 * There are three instances that represent an NX window from the
75 * perspective of NXWidgets.
76 *
77 * - There is one widget control instance per NX window,
78 * - One CCallback instance per window,
79 * - One window instance.
80 *
81 * There a various kinds of of window instances, but each inherits
82 * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
83 * that describes the common window behavior.
84 */
85
86 class CNxWindow : protected CCallback, public INxWindow
87 {
88 private:
89 NXHANDLE m_hNxServer; /**< Handle to the NX server. */
90 NXWINDOW m_hNxWindow; /**< Handle to the NX raw window */
91 CWidgetControl *m_widgetControl; /**< The controlling widget for the window */
92
93 public:
94
95 /**
96 * Constructor. Creates an uninitialized instance of the CNxWindow
97 * object. The open() method must be called to initialize the instance.
98 *
99 * The general steps to create any window include:
100 * 1) Create a dumb CWigetControl instance
101 * 2) Pass the dumb CWidgetControl instance to the window constructor
102 * that inherits from INxWindow.
103 * 3) The window constructor call CWidgetControl methods to "smarten"
104 * the CWidgetControl instance with window-specific knowledge.
105 * 4) Call the open() method on the window to display the window.
106 * 5) After that, the fully smartend CWidgetControl instance can
107 * be used to generate additional widgets.
108 * 6) After that, the fully smartened CWidgetControl instance can
109 * be used to generate additional widgets by passing it to the
110 * widget constructor
111 *
112 * @param hNxServer Handle to the NX server.
113 * @param widgetControl Controlling widget for this window.
114 */
115
116 CNxWindow(NXHANDLE hNxServer, CWidgetControl *pWidgetControl);
117
118 /**
119 * Destructor.
120 */
121
122 ~CNxWindow(void);
123
124 /**
125 * Creates a new window. Window creation is separate from
126 * object instantiation so that failures can be reported.
127 *
128 * @return True if the window was successfully opened.
129 */
130
131 bool open(void);
132
133 /**
134 * Each implementation of INxWindow must provide a method to recover
135 * the contained CWidgetControl instance.
136 *
137 * @return The contained CWidgetControl instance
138 */
139
140 CWidgetControl *getWidgetControl(void) const;
141
142 /**
143 * Request the position and size information of the window. The values
144 * will be returned asynchronously through the client callback method.
145 * The GetPosition() method may than be called to obtain the positional
146 * data as provided by the callback.
147 *
148 * @return True on success, false on any failure.
149 */
150
151 bool requestPosition(void);
152
153 /**
154 * Get the position of the window (as reported by the NX callback).
155 *
156 * @return The position.
157 */
158
159 bool getPosition(FAR struct nxgl_point_s *pPos);
160
161 /**
162 * Get the size of the window (as reported by the NX callback).
163 *
164 * @return The size.
165 */
166
167 bool getSize(FAR struct nxgl_size_s *pSize);
168
169 /**
170 * Set the position and size of the window.
171 *
172 * @param pPos The new position of the window.
173 * @return True on success, false on any failure.
174 */
175
176 bool setPosition(FAR const struct nxgl_point_s *pPos);
177
178 /**
179 * Set the size of the selected window.
180 *
181 * @param pSize The new size of the window.
182 * @return True on success, false on any failure.
183 */
184
185 bool setSize(FAR const struct nxgl_size_s *pSize);
186
187 /**
188 * Bring the window to the top of the display.
189 *
190 * @return True on success, false on any failure.
191 */
192
193 bool raise(void);
194
195 /**
196 * Lower the window to the bottom of the display.
197 *
198 * @return True on success, false on any failure.
199 */
200
201 bool lower(void);
202
203 /**
204 * Each window implementation also inherits from CCallback. CCallback,
205 * by default, forwards NX keyboard input to the various widgets residing
206 * in the window. But NxTerm is a different usage model; In this case,
207 * keyboard input needs to be directed to the NxTerm character driver.
208 * This method can be used to enable (or disable) redirection of NX
209 * keyboard input from the window widgets to the NxTerm
210 *
211 * @param handle. The NXTERM handle. If non-NULL, NX keyboard
212 * input will be directed to the NxTerm driver using this
213 * handle; If NULL (the default), NX keyboard input will be
214 * directed to the widgets within the window.
215 */
216
217 #ifdef CONFIG_NXTERM_NXKBDIN
218 inline void redirectNxTerm(NXTERM handle)
219 {
220 setNxTerm(handle);
221 }
222 #endif
223
224 /**
225 * Set an individual pixel in the window with the specified color.
226 *
227 * @param pPos The location of the pixel to be filled.
228 * @param color The color to use in the fill.
229 *
230 * @return True on success; false on failure.
231 */
232
233 bool setPixel(FAR const struct nxgl_point_s *pPos,
234 nxgl_mxpixel_t color);
235
236 /**
237 * Fill the specified rectangle in the window with the specified color.
238 *
239 * @param pRect The location to be filled.
240 * @param color The color to use in the fill.
241 *
242 * @return True on success; false on failure.
243 */
244
245 bool fill(FAR const struct nxgl_rect_s *pRect,
246 nxgl_mxpixel_t color);
247
248 /**
249 * Get the raw contents of graphic memory within a rectangular region. NOTE:
250 * Since raw graphic memory is returned, the returned memory content may be
251 * the memory of windows above this one and may not necessarily belong to
252 * this window unless you assure that this is the top window.
253 *
254 * @param rect The location to be copied
255 * @param dest - The describes the destination bitmap to receive the
256 * graphics data.
257 */
258
259 void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest);
260
261 /**
262 * Fill the specified trapezoidal region in the window with the specified
263 * color.
264 *
265 * @param pClip Clipping rectangle relative to window (may be null).
266 * @param pTrap The trapezoidal region to be filled.
267 * @param color The color to use in the fill.
268 *
269 * @return True on success; false on failure.
270 */
271
272 bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip,
273 FAR const struct nxgl_trapezoid_s *pTrap,
274 nxgl_mxpixel_t color);
275
276 /**
277 * Fill the specified line in the window with the specified color.
278 *
279 * @param vector - Describes the line to be drawn
280 * @param width - The width of the line
281 * @param color - The color to use to fill the line
282 * @param caps - Draw a circular cap on the ends of the line to support
283 * better line joins
284 *
285 * @return True on success; false on failure.
286 */
287
288 bool drawLine(FAR struct nxgl_vector_s *vector,
289 nxgl_coord_t width, nxgl_mxpixel_t color,
290 enum ELineCaps caps);
291
292 /**
293 * Draw a filled circle at the specified position, size, and color.
294 *
295 * @param center The window-relative coordinates of the circle center.
296 * @param radius The radius of the rectangle in pixels.
297 * @param color The color of the rectangle.
298 */
299
300 bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius,
301 nxgl_mxpixel_t color);
302
303 /**
304 * Move a rectangular region within the window.
305 *
306 * @param pRect Describes the rectangular region to move.
307 * @param pOffset The offset to move the region.
308 *
309 * @return True on success; false on failure.
310 */
311
312 bool move(FAR const struct nxgl_rect_s *pRect,
313 FAR const struct nxgl_point_s *pOffset);
314
315 /**
316 * Copy a rectangular region of a larger image into the rectangle in the
317 * specified window.
318 *
319 * @param pDest Describes the rectangular on the display that will receive
320 * the bitmap.
321 * @param pSrc The start of the source image.
322 * @param pOrigin the pOrigin of the upper, left-most corner of the full
323 * bitmap. Both pDest and pOrigin are in window coordinates, however,
324 * pOrigin may lie outside of the display.
325 * @param stride The width of the full source image in bytes.
326 *
327 * @return True on success; false on failure.
328 */
329
330 bool bitmap(FAR const struct nxgl_rect_s *pDest,
331 FAR const void *pSrc,
332 FAR const struct nxgl_point_s *pOrigin,
333 unsigned int stride);
334 };
335 }
336
337 #endif // __cplusplus
338
339 #endif // __INCLUDE_CNXWINDOW_HXX
340
NXWidgets::CNxWindow::getSize
bool getSize(FAR struct nxgl_size_s *pSize)
Definition: cnxwindow.cxx:159
NXWidgets::CCallback
Definition: ccallback.hxx:91
NXWidgets::CNxWindow::drawLine
bool drawLine(FAR struct nxgl_vector_s *vector, nxgl_coord_t width, nxgl_mxpixel_t color, enum ELineCaps caps)
Definition: cnxwindow.cxx:301
NXWidgets::CWidgetControl
Definition: cwidgetcontrol.hxx:95
NXWidgets::CNxWindow::fill
bool fill(FAR const struct nxgl_rect_s *pRect, nxgl_mxpixel_t color)
Definition: cnxwindow.cxx:244
NXWidgets::CNxWindow::lower
bool lower(void)
Definition: cnxwindow.cxx:211
NXWidgets::CNxWindow::~CNxWindow
~CNxWindow(void)
Definition: cnxwindow.cxx:78
NXWidgets::CNxWindow::redirectNxTerm
void redirectNxTerm(NXTERM handle)
Definition: cnxwindow.hxx:218
NXWidgets::CNxWindow::setPosition
bool setPosition(FAR const struct nxgl_point_s *pPos)
Definition: cnxwindow.cxx:171
NXWidgets::CNxWindow::move
bool move(FAR const struct nxgl_rect_s *pRect, FAR const struct nxgl_point_s *pOffset)
Definition: cnxwindow.cxx:333
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CNxWindow::m_hNxWindow
NXWINDOW m_hNxWindow
Definition: cnxwindow.hxx:90
NXWidgets::CNxWindow::requestPosition
bool requestPosition(void)
Definition: cnxwindow.cxx:134
NXWidgets::CNxWindow::CNxWindow
CNxWindow(NXHANDLE hNxServer, CWidgetControl *pWidgetControl)
Definition: cnxwindow.cxx:65
NXWidgets::CNxWindow::setSize
bool setSize(FAR const struct nxgl_size_s *pSize)
Definition: cnxwindow.cxx:185
NXWidgets::INxWindow::ELineCaps
ELineCaps
Definition: inxwindow.hxx:86
NXWidgets::CCallback::setNxTerm
void setNxTerm(NXTERM handle)
Definition: ccallback.hxx:259
inxwindow.hxx
NXWidgets::CNxWindow::m_hNxServer
NXHANDLE m_hNxServer
Definition: cnxwindow.hxx:89
ccallback.hxx
NXWidgets::CNxWindow::fillTrapezoid
bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip, FAR const struct nxgl_trapezoid_s *pTrap, nxgl_mxpixel_t color)
Definition: cnxwindow.cxx:280
NXWidgets::CNxWindow::setPixel
bool setPixel(FAR const struct nxgl_point_s *pPos, nxgl_mxpixel_t color)
Definition: cnxwindow.cxx:227
NXWidgets::CNxWindow::m_widgetControl
CWidgetControl * m_widgetControl
Definition: cnxwindow.hxx:91
NXWidgets::CNxWindow::getRectangle
void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest)
Definition: cnxwindow.cxx:263
NXWidgets::SBitmap
Definition: cbitmap.hxx:103
NXWidgets::CNxWindow::drawFilledCircle
bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius, nxgl_mxpixel_t color)
Definition: cnxwindow.cxx:318
NXWidgets::CNxWindow::getWidgetControl
CWidgetControl * getWidgetControl(void) const
Definition: cnxwindow.cxx:120
NXWidgets::INxWindow
Definition: inxwindow.hxx:83
NXWidgets::CNxWindow::getPosition
bool getPosition(FAR struct nxgl_point_s *pPos)
Definition: cnxwindow.cxx:148
NXWidgets::CNxWindow::open
bool open(void)
Definition: cnxwindow.cxx:100
NXWidgets::CNxWindow::bitmap
bool bitmap(FAR const struct nxgl_rect_s *pDest, FAR const void *pSrc, FAR const struct nxgl_point_s *pOrigin, unsigned int stride)
Definition: cnxwindow.cxx:356
NXWidgets::CNxWindow
Definition: cnxwindow.hxx:86