NXWidgets  1.19
cbgwindow.hxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/include/cbgwindow.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_CBGWINDOW_HXX
37 #define __INCLUDE_CBGWINDOW_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 
51 #include "nxconfig.hxx"
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  class INxWindow;
68  struct SBitmap;
69 
70  /**
71  * This class defines operations on a the NX background window.
72  * There are three instances that represent an NX window from the
73  * perspective of NXWidgets.
74  *
75  * - There is one widget control instance per NX window,
76  * - One CCallback instance per window,
77  * - One window instance.
78  *
79  * There a various kinds of of window instances, but each inherits
80  * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
81  * that describes the common window behavior.
82  */
83 
84  class CBgWindow : protected CCallback, public INxWindow
85  {
86  private:
87  NXHANDLE m_hNxServer; /**< Handle to the NX server. */
88  NXWINDOW m_hWindow; /**< Handle to the NX background window */
89  CWidgetControl *m_widgetControl; /**< The controlling widget for the window */
90 
91  public:
92 
93  /**
94  * Constructor. Obtains the background window from server and wraps
95  * the window as CBgWindow. Creates an uninitialized instance of the
96  * CBgWindow object. The open() method must be called to initialize
97  * 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  CBgWindow(NXHANDLE hNxServer, CWidgetControl *widgetControl);
117 
118  /**
119  * Destructor. Returns the background window to the server.
120  */
121 
122  virtual ~CBgWindow(void);
123 
124  /**
125  * Creates a the 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 created.
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). NOTE:
155  * The background window is always positioned at {0,0}
156  *
157  * @return The position.
158  */
159 
160  bool getPosition(FAR struct nxgl_point_s *pPos);
161 
162  /**
163  * Get the size of the window (as reported by the NX callback). NOTE:
164  * The size of the background window is always the entire display.
165  *
166  * @return The size.
167  */
168 
169  bool getSize(FAR struct nxgl_size_s *pSize);
170 
171  /**
172  * Set the position and size of the window.
173  *
174  * @param pPos The new position of the window.
175  * @return True on success, false on any failure.
176  */
177 
178  bool setPosition(FAR const struct nxgl_point_s *pPos);
179 
180  /**
181  * Set the size of the selected window. NOTE: The size of the
182  * background window is always the entire display and cannot be
183  * changed.
184  *
185  * @param pSize The new size of the window.
186  * @return True on success, false on any failure.
187  */
188 
189  bool setSize(FAR const struct nxgl_size_s *pSize);
190 
191  /**
192  * Bring the window to the top of the display. NOTE: The background
193  * window cannot be raised.
194  *
195  * @return True on success, false on any failure.
196  */
197 
198  bool raise(void);
199 
200  /**
201  * Lower the window to the bottom of the display. NOTE: The background
202  * window is always at the bottom of the window hierarchy.
203  *
204  * @return True on success, false on any failure.
205  */
206 
207  bool lower(void);
208 
209  /**
210  * Each window implementation also inherits from CCallback. CCallback,
211  * by default, forwards NX keyboard input to the various widgets residing
212  * in the window. But NxTerm is a different usage model; In this case,
213  * keyboard input needs to be directed to the NxTerm character driver.
214  * This method can be used to enable (or disable) redirection of NX
215  * keyboard input from the window widgets to the NxTerm
216  *
217  * @param handle. The NXTERM handle. If non-NULL, NX keyboard
218  * input will be directed to the NxTerm driver using this
219  * handle; If NULL (the default), NX keyboard input will be
220  * directed to the widgets within the window.
221  */
222 
223 #ifdef CONFIG_NXTERM_NXKBDIN
224  inline void redirectNxTerm(NXTERM handle)
225  {
226  setNxTerm(handle);
227  }
228 #endif
229 
230  /**
231  * Set an individual pixel in the window with the specified color.
232  *
233  * @param pPos The location of the pixel to be filled.
234  * @param color The color to use in the fill.
235  *
236  * @return True on success; false on failure.
237  */
238 
239  bool setPixel(FAR const struct nxgl_point_s *pPos,
240  nxgl_mxpixel_t color);
241 
242  /**
243  * Fill the specified rectangle in the window with the specified color.
244  *
245  * @param pRect The location to be filled.
246  * @param color The color to use in the fill.
247  *
248  * @return True on success; false on failure.
249  */
250 
251  bool fill(FAR const struct nxgl_rect_s *pRect,
252  nxgl_mxpixel_t color);
253 
254  /**
255  * Get the raw contents of graphic memory within a rectangular region. NOTE:
256  * Since raw graphic memory is returned, the returned memory content may be
257  * the memory of windows above this one and may not necessarily belong to
258  * this window unless you assure that this is the top window.
259  *
260  * @param rect The location to be copied
261  * @param dest - The describes the destination bitmap to receive the
262  * graphics data.
263  */
264 
265  void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest);
266 
267  /**
268  * Fill the specified trapezoidal region in the window with the specified
269  * color.
270  *
271  * @param pClip Clipping rectangle relative to window (may be null).
272  * @param pTrap The trapezoidal region to be filled.
273  * @param color The color to use in the fill.
274  *
275  * @return True on success; false on failure.
276  */
277 
278  bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip,
279  FAR const struct nxgl_trapezoid_s *pTrap,
280  nxgl_mxpixel_t color);
281 
282  /**
283  * Fill the specified line in the window with the specified color.
284  *
285  * @param vector - Describes the line to be drawn
286  * @param width - The width of the line
287  * @param color - The color to use to fill the line
288  * @param caps - Draw a circular cap on the ends of the line to support
289  * better line joins
290  *
291  * @return True on success; false on failure.
292  */
293 
294  bool drawLine(FAR struct nxgl_vector_s *vector,
295  nxgl_coord_t width, nxgl_mxpixel_t color,
296  enum ELineCaps caps);
297 
298  /**
299  * Draw a filled circle at the specified position, size, and color.
300  *
301  * @param center The window-relative coordinates of the circle center.
302  * @param radius The radius of the rectangle in pixels.
303  * @param color The color of the rectangle.
304  */
305 
306  bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius,
307  nxgl_mxpixel_t color);
308 
309  /**
310  * Move a rectangular region within the window.
311  *
312  * @param pRect Describes the rectangular region to move.
313  * @param pOffset The offset to move the region.
314  *
315  * @return True on success; false on failure.
316  */
317 
318  bool move(FAR const struct nxgl_rect_s *pRect,
319  FAR const struct nxgl_point_s *pOffset);
320 
321  /**
322  * Copy a rectangular region of a larger image into the rectangle in the
323  * specified window.
324  *
325  * @param pDest Describes the rectangular on the display that will receive
326  * the bitmap.
327  * @param pSrc The start of the source image.
328  * @param pOrigin the pOrigin of the upper, left-most corner of the full
329  * bitmap. Both pDest and pOrigin are in window coordinates, however,
330  * pOrigin may lie outside of the display.
331  * @param stride The width of the full source image in bytes.
332  *
333  * @return True on success; false on failure.
334  */
335 
336  bool bitmap(FAR const struct nxgl_rect_s *pDest,
337  FAR const void *pSrc,
338  FAR const struct nxgl_point_s *pOrigin,
339  unsigned int stride);
340  };
341 }
342 
343 #endif // __cplusplus
344 
345 #endif // __INCLUDE_CBGWINDOW_HXX
346 
bool drawLine(FAR struct nxgl_vector_s *vector, nxgl_coord_t width, nxgl_mxpixel_t color, enum ELineCaps caps)
Definition: cbgwindow.cxx:317
bool requestPosition(void)
Definition: cbgwindow.cxx:138
void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest)
Definition: cbgwindow.cxx:278
bool setPixel(FAR const struct nxgl_point_s *pPos, nxgl_mxpixel_t color)
Definition: cbgwindow.cxx:242
CWidgetControl * m_widgetControl
Definition: cbgwindow.hxx:89
virtual ~CBgWindow(void)
Definition: cbgwindow.cxx:80
bool getSize(FAR struct nxgl_size_s *pSize)
Definition: cbgwindow.cxx:168
bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius, nxgl_mxpixel_t color)
Definition: cbgwindow.cxx:334
bool bitmap(FAR const struct nxgl_rect_s *pDest, FAR const void *pSrc, FAR const struct nxgl_point_s *pOrigin, unsigned int stride)
Definition: cbgwindow.cxx:372
void setNxTerm(NXTERM handle)
Definition: ccallback.hxx:259
bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip, FAR const struct nxgl_trapezoid_s *pTrap, nxgl_mxpixel_t color)
Definition: cbgwindow.cxx:296
bool setPosition(FAR const struct nxgl_point_s *pPos)
Definition: cbgwindow.cxx:182
CBgWindow(NXHANDLE hNxServer, CWidgetControl *widgetControl)
Definition: cbgwindow.cxx:67
bool setSize(FAR const struct nxgl_size_s *pSize)
Definition: cbgwindow.cxx:198
CWidgetControl * getWidgetControl(void) const
Definition: cbgwindow.cxx:124
bool fill(FAR const struct nxgl_rect_s *pRect, nxgl_mxpixel_t color)
Definition: cbgwindow.cxx:259
void redirectNxTerm(NXTERM handle)
Definition: cbgwindow.hxx:224
bool move(FAR const struct nxgl_rect_s *pRect, FAR const struct nxgl_point_s *pOffset)
Definition: cbgwindow.cxx:349
bool getPosition(FAR struct nxgl_point_s *pPos)
Definition: cbgwindow.cxx:152