NXWidgets: inxwindow.hxx Source File

NXWidgets 1.19

inxwindow.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/include/inxwindow.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_INXWINDOW_HXX
37 #define __INCLUDE_INXWINDOW_HXX
38
39 /****************************************************************************
40 * Included Files
41 ****************************************************************************/
42
43 #include <nuttx/config.h>
44
45 #include <nuttx/nx/nxglib.h>
46
47 #include <stdint.h>
48 #include <stdbool.h>
49
50 #ifdef CONFIG_NXTERM_NXKBDIN
51 # include <nuttx/nx/nxterm.h>
52 #endif
53
54 /****************************************************************************
55 * Pre-Processor Definitions
56 ****************************************************************************/
57
58 /****************************************************************************
59 * Pure Virtual Classes
60 ****************************************************************************/
61
62 #if defined(__cplusplus)
63
64 namespace NXWidgets
65 {
66 struct SBitmap;
67 class CWidgetControl;
68
69 /**
70 * This class defines common operations on a any NX window.
71 * There are three instances that represent an NX window from the
72 * perspective of NXWidgets.
73 *
74 * - There is one widget control instance per NX window,
75 * - One CCallback instance per window,
76 * - One window instance.
77 *
78 * There a various kinds of of window instances, but each inherits
79 * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
80 * that describes the common window behavior.
81 */
82
83 class INxWindow
84 {
85 public:
86 enum ELineCaps
87 {
88 LINECAP_NONE = NX_LINECAP_NONE, // No line caps
89 LINECAP_PT1 = NX_LINECAP_PT1, // Line cap on pt1 of the vector only
90 LINECAP_PT2 = NX_LINECAP_PT2, // Line cap on pt2 of the vector only
91 LINECAP_BOTH = NX_LINECAP_BOTH // Line cap on both ends of the vector only
92 };
93
94 /**
95 * A virtual destructor is required in order to override the INxWindow
96 * destructor. We do this because if we delete INxWindow, we want the
97 * destructor of the class that inherits from INxWindow to run, not this
98 * one.
99 */
100
101 virtual ~INxWindow(void) { }
102
103 /**
104 * Creates a new window. Window creation is separate from
105 * object instantiation so that window creation failures can
106 * be properly reported.
107 *
108 * @return True if the window was successfully created.
109 */
110
111 virtual bool open(void) = 0;
112
113 /**
114 * Each implementation of INxWindow must provide a method to recover
115 * the contained CWidgetControl instance.
116 *
117 * @return The contained CWidgetControl instance
118 */
119
120 virtual CWidgetControl *getWidgetControl(void) const = 0;
121
122 /**
123 * Request the position and size information of the window. The values
124 * will be returned asynchronously through the client callback method.
125 * The GetPosition() method may than be called to obtain the positional
126 * data as provided by the callback.
127 *
128 * @return OK on success; ERROR on failure with errno set appropriately.
129 */
130
131 virtual bool requestPosition(void) = 0;
132
133 /**
134 * Get the position of the window (as reported by the NX callback).
135 *
136 * @return The position.
137 */
138
139 virtual bool getPosition(FAR struct nxgl_point_s *pPos) = 0;
140
141 /**
142 * Get the size of the window (as reported by the NX callback).
143 *
144 * @return The size.
145 */
146
147 virtual bool getSize(FAR struct nxgl_size_s *pSize) = 0;
148
149 /**
150 * Set the position and size of the window.
151 *
152 * @param pPos The new position of the window.
153 * @return True on success, false on failure.
154 */
155
156 virtual bool setPosition(FAR const struct nxgl_point_s *pPos) = 0;
157
158 /**
159 * Set the size of the selected window.
160 *
161 * @param pSize The new size of the window.
162 * @return OK on success; ERROR on failure with errno set appropriately.
163 */
164
165 virtual bool setSize(FAR const struct nxgl_size_s *pSize) = 0;
166
167 /**
168 * Bring the window to the top of the display.
169 *
170 * @return OK on success; ERROR on failure with errno set appropriately.
171 */
172
173 virtual bool raise(void) = 0;
174
175 /**
176 * Lower the window to the bottom of the display.
177 *
178 * @return OK on success; ERROR on failure with errno set appropriately.
179 */
180
181 virtual bool lower(void) = 0;
182
183 /**
184 * Each window implementation also inherits from CCallback. CCallback,
185 * by default, forwards NX keyboard input to the various widgets residing
186 * in the window. But NxTerm is a different usage model; In this case,
187 * keyboard input needs to be directed to the NxTerm character driver.
188 * This method can be used to enable (or disable) redirection of NX
189 * keyboard input from the window widgets to the NxTerm
190 *
191 * @param handle. The NXTERM handle. If non-NULL, NX keyboard
192 * input will be directed to the NxTerm driver using this
193 * handle; If NULL (the default), NX keyboard input will be
194 * directed to the widgets within the window.
195 */
196
197 #ifdef CONFIG_NXTERM_NXKBDIN
198 virtual void redirectNxTerm(NXTERM handle) = 0;
199 #endif
200
201 /**
202 * Set an individual pixel in the window with the specified color.
203 *
204 * @param pPos The location of the pixel to be filled.
205 * @param color The color to use in the fill.
206 *
207 * @return True on success; false on failure.
208 */
209
210 virtual bool setPixel(FAR const struct nxgl_point_s *pPos,
211 nxgl_mxpixel_t color) = 0;
212
213 /**
214 * Fill the specified rectangle in the window with the specified color.
215 *
216 * @param pRect The location to be filled.
217 * @param color The color to use in the fill.
218 *
219 * @return True on success; false on failure.
220 */
221
222 virtual bool fill(FAR const struct nxgl_rect_s *pRect,
223 nxgl_mxpixel_t color) = 0;
224
225 /**
226 * Get the raw contents of graphic memory within a rectangular region. NOTE:
227 * Since raw graphic memory is returned, the returned memory content may be
228 * the memory of windows above this one and may not necessarily belong to
229 * this window unless you assure that this is the top window.
230 *
231 * @param rect The location to be copied
232 * @param dest - The describes the destination bitmap to receive the
233 * graphics data.
234 */
235
236 virtual void getRectangle(FAR const struct nxgl_rect_s *rect,
237 struct SBitmap *dest) = 0;
238
239 /**
240 * Fill the specified trapezoidal region in the window with the specified
241 * color.
242 *
243 * @param pClip Clipping rectangle relative to window (may be null).
244 * @param pTrap The trapezoidal region to be filled.
245 * @param color The color to use in the fill.
246 *
247 * @return True on success; false on failure.
248 */
249
250 virtual bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip,
251 FAR const struct nxgl_trapezoid_s *pTrap,
252 nxgl_mxpixel_t color) = 0;
253
254 /**
255 * Fill the specified line in the window with the specified color.
256 *
257 * @param vector - Describes the line to be drawn
258 * @param width - The width of the line
259 * @param color - The color to use to fill the line
260 * @param caps - Draw a circular cap on the ends of the line to support
261 * better line joins
262 *
263 * @return True on success; false on failure.
264 */
265
266 virtual bool drawLine(FAR struct nxgl_vector_s *vector,
267 nxgl_coord_t width, nxgl_mxpixel_t color,
268 enum ELineCaps caps) = 0;
269
270 /**
271 * Draw a filled circle at the specified position, size, and color.
272 *
273 * @param center The window-relative coordinates of the circle center.
274 * @param radius The radius of the rectangle in pixels.
275 * @param color The color of the rectangle.
276 */
277
278 virtual bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius,
279 nxgl_mxpixel_t color) = 0;
280
281 /**
282 * Move a rectangular region within the window.
283 *
284 * @param pRect Describes the rectangular region to move.
285 * @param pOffset The offset to move the region.
286 *
287 * @return True on success; false on failure.
288 */
289
290 virtual bool move(FAR const struct nxgl_rect_s *pRect,
291 FAR const struct nxgl_point_s *pOffset) = 0;
292
293 /**
294 * Copy a rectangular region of a larger image into the rectangle in the
295 * specified window. The source image is treated as an opaque image.
296 *
297 * @param pDest Describes the rectangular on the display that will receive
298 * the bitmap.
299 * @param pSrc The start of the source image.
300 * @param pOrigin the pOrigin of the upper, left-most corner of the full
301 * bitmap. Both pDest and pOrigin are in window coordinates, however,
302 * pOrigin may lie outside of the display.
303 * @param stride The width of the full source image in bytes.
304 *
305 * @return True on success; false on failure.
306 */
307
308 virtual bool bitmap(FAR const struct nxgl_rect_s *pDest,
309 FAR const void *pSrc,
310 FAR const struct nxgl_point_s *pOrigin,
311 unsigned int stride) = 0;
312 };
313 }
314
315 #endif // __cplusplus
316
317 #endif // __INCLUDE_INXWINDOW_HXX
318
NXWidgets::INxWindow::bitmap
virtual bool bitmap(FAR const struct nxgl_rect_s *pDest, FAR const void *pSrc, FAR const struct nxgl_point_s *pOrigin, unsigned int stride)=0
NXWidgets::INxWindow::LINECAP_BOTH
Definition: inxwindow.hxx:91
NXWidgets::CWidgetControl
Definition: cwidgetcontrol.hxx:95
NXWidgets::INxWindow::~INxWindow
virtual ~INxWindow(void)
Definition: inxwindow.hxx:101
NXWidgets::INxWindow::move
virtual bool move(FAR const struct nxgl_rect_s *pRect, FAR const struct nxgl_point_s *pOffset)=0
NXWidgets::INxWindow::getRectangle
virtual void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest)=0
NXWidgets::INxWindow::redirectNxTerm
virtual void redirectNxTerm(NXTERM handle)=0
NXWidgets::INxWindow::fillTrapezoid
virtual bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip, FAR const struct nxgl_trapezoid_s *pTrap, nxgl_mxpixel_t color)=0
NXWidgets::INxWindow::open
virtual bool open(void)=0
NXWidgets::INxWindow::LINECAP_PT1
Definition: inxwindow.hxx:89
NXWidgets::INxWindow::setPixel
virtual bool setPixel(FAR const struct nxgl_point_s *pPos, nxgl_mxpixel_t color)=0
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::INxWindow::getSize
virtual bool getSize(FAR struct nxgl_size_s *pSize)=0
NXWidgets::INxWindow::requestPosition
virtual bool requestPosition(void)=0
NXWidgets::INxWindow::ELineCaps
ELineCaps
Definition: inxwindow.hxx:86
NXWidgets::INxWindow::LINECAP_NONE
Definition: inxwindow.hxx:88
NXWidgets::INxWindow::drawLine
virtual bool drawLine(FAR struct nxgl_vector_s *vector, nxgl_coord_t width, nxgl_mxpixel_t color, enum ELineCaps caps)=0
NXWidgets::INxWindow::LINECAP_PT2
Definition: inxwindow.hxx:90
NXWidgets::INxWindow::getPosition
virtual bool getPosition(FAR struct nxgl_point_s *pPos)=0
NXWidgets::INxWindow::lower
virtual bool lower(void)=0
NXWidgets::INxWindow::setPosition
virtual bool setPosition(FAR const struct nxgl_point_s *pPos)=0
NXWidgets::INxWindow::setSize
virtual bool setSize(FAR const struct nxgl_size_s *pSize)=0
NXWidgets::INxWindow::fill
virtual bool fill(FAR const struct nxgl_rect_s *pRect, nxgl_mxpixel_t color)=0
NXWidgets::SBitmap
Definition: cbitmap.hxx:103
NXWidgets::INxWindow::getWidgetControl
virtual CWidgetControl * getWidgetControl(void) const =0
NXWidgets::INxWindow::drawFilledCircle
virtual bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius, nxgl_mxpixel_t color)=0
NXWidgets::INxWindow
Definition: inxwindow.hxx:83