NXWidgets: cbgwindow.cxx Source File

NXWidgets 1.19

cbgwindow.cxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/src/cbgwindow.cxx
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 /****************************************************************************
37 * Included Files
38 ****************************************************************************/
39
40 #include <nuttx/config.h>
41
42 #include <stdint.h>
43 #include <stdbool.h>
44
45 #include "cwidgetcontrol.hxx"
46 #include "cbgwindow.hxx"
47 #include "cbitmap.hxx"
48
49 /****************************************************************************
50 * Pre-Processor Definitions
51 ****************************************************************************/
52
53 /****************************************************************************
54 * Method Implementations
55 ****************************************************************************/
56
57 using namespace NXWidgets;
58
59 /**
60 * Constructor. Obtains the background window from server and wraps
61 * the window as CBgWindow.
62 *
63 * @param hNxServer Handle to the NX server.
64 * @param widgetControl Controlling widget for this window.
65 */
66
67 CBgWindow::CBgWindow(NXHANDLE hNxServer, CWidgetControl *pWidgetControl)
68 : CCallback(pWidgetControl), m_hNxServer(hNxServer), m_hWindow(0),
69 m_widgetControl(pWidgetControl)
70 {
71 // Create the CGraphicsPort instance for this window
72
73 m_widgetControl->createGraphicsPort(static_cast<INxWindow*>(this));
74 }
75
76 /**
77 * Destructor. Returns the background window to the server.
78 */
79
80 CBgWindow::~CBgWindow(void)
81 {
82 // Release the background. We do not release the widget control
83 // instance. The lifetime of that instance is owned by he-who-
84 // constructed-us.
85
86 (void)nx_releasebkgd(m_hWindow);
87 }
88
89 /**
90 * Creates a new window. Window creation is separate from
91 * object instantiation so that failures can be reported.
92 *
93 * @return True if the window was successfully opened.
94 */
95
96 bool CBgWindow::open(void)
97 {
98 // Get the C-callable callback vtable
99
100 FAR struct nx_callback_s *vtable = getCallbackVTable();
101
102 // Request the background the window
103
104 int ret = nx_requestbkgd(m_hNxServer, vtable,
105 (FAR void *)static_cast<CCallback*>(this));
106 if (ret < 0)
107 {
108 return false;
109 }
110
111 // Window handle (picked off by the callback logic)
112
113 m_hWindow = m_widgetControl->getWindowHandle();
114 return true;
115 }
116
117 /**
118 * Each implementation of INxWindow must provide a method to recover
119 * the contained CWidgetControl instance.
120 *
121 * @return The contained CWidgetControl instance
122 */
123
124 CWidgetControl *CBgWindow::getWidgetControl(void) const
125 {
126 return m_widgetControl;
127 }
128
129 /**
130 * Request the position and size information of the window. The values
131 * will be returned asynchronously through the client callback method.
132 * The GetPosition() method may than be called to obtain the positional
133 * data as provided by the callback.
134 *
135 * @return Always returns true.
136 */
137
138 bool CBgWindow::requestPosition(void)
139 {
140 // The background window is always at {0,0} and the size never changes.
141
142 return true;
143 }
144
145 /**
146 * Get the position of the window (as reported by the NX callback). NOTE:
147 * The background window is always positioned at {0,0}
148 *
149 * @return The position.
150 */
151
152 bool CBgWindow::getPosition(FAR struct nxgl_point_s *pPos)
153 {
154 // The background window is always at {0,0}
155
156 pPos->x = 0;
157 pPos->y = 0;
158 return true;
159 }
160
161 /**
162 * Get the size of the window (as reported by the NX callback). NOTE:
163 * The size of the background window is always the entire display.
164 *
165 * @return The size.
166 */
167
168 bool CBgWindow::getSize(FAR struct nxgl_size_s *pSize)
169 {
170 // The size is always the full size of the display
171
172 return m_widgetControl->getWindowSize(pSize);
173 }
174
175 /**
176 * Set the position and size of the window.
177 *
178 * @param pPos The new position of the window.
179 * @return Always returns false.
180 */
181
182 bool CBgWindow::setPosition(FAR const struct nxgl_point_s *pPos)
183 {
184 // The position of the background cannot be changed
185
186 return false;
187 }
188
189 /**
190 * Set the size of the selected window. NOTE: The size of the
191 * background window is always the entire display and cannot be
192 * changed.
193 *
194 * @param pSize The new size of the window.
195 * @return Always returns false.
196 */
197
198 bool CBgWindow::setSize(FAR const struct nxgl_size_s *pSize)
199 {
200 // The position of the background cannot be changed
201
202 return false;
203 }
204
205 /**
206 * Bring the window to the top of the display. NOTE: The background
207 * window cannot be raised.
208 *
209 * @return Always returns false.
210 */
211
212 bool CBgWindow::raise(void)
213 {
214 // The background cannot be raised
215
216 return false;
217 }
218
219 /**
220 * Lower the window to the bottom of the display. NOTE: The background
221 * window is always at the bottom of the window hierarchy.
222 *
223 * @return Always returns false.
224 */
225
226 bool CBgWindow::lower(void)
227 {
228 // The background cannot be lowered
229
230 return false;
231 }
232
233 /**
234 * Set an individual pixel in the window with the specified color.
235 *
236 * @param pPos The location of the pixel to be filled.
237 * @param color The color to use in the fill.
238 *
239 * @return True on success; false on failure.
240 */
241
242 bool CBgWindow::setPixel(FAR const struct nxgl_point_s *pPos,
243 nxgl_mxpixel_t color)
244 {
245 // Set an individual pixel to the specified color
246
247 return nx_setpixel(m_hWindow, pPos, &color) == OK;
248 }
249
250 /**
251 * Fill the specified rectangle in the window with the specified color.
252 *
253 * @param pRect The location to be filled.
254 * @param color The color to use in the fill.
255 *
256 * @return True on success; false on failure.
257 */
258
259 bool CBgWindow::fill(FAR const struct nxgl_rect_s *pRect,
260 nxgl_mxpixel_t color)
261 {
262 // Fill a rectangular region with a solid color
263
264 return nx_fill(m_hWindow, pRect, &color) == OK;
265 }
266
267 /**
268 * Get the raw contents of graphic memory within a rectangular region. NOTE:
269 * Since raw graphic memory is returned, the returned memory content may be
270 * the memory of windows above this one and may not necessarily belong to
271 * this window unless you assure that this is the top window.
272 *
273 * @param rect The location to be copied
274 * @param dest - The describes the destination bitmap to receive the
275 * graphics data.
276 */
277
278 void CBgWindow::getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest)
279 {
280 // Get a rectangule region from the window
281
282 (void)nx_getrectangle(m_hWindow, rect, 0, (FAR uint8_t*)dest->data, dest->stride);
283 }
284
285 /**
286 * Fill the specified trapezoidal region in the window with the specified
287 * color.
288 *
289 * @param pClip Clipping rectangle relative to window (may be null).
290 * @param pTrap The trapezoidal region to be filled.
291 * @param color The color to use in the fill.
292 *
293 * @return True on success; false on failure.
294 */
295
296 bool CBgWindow::fillTrapezoid(FAR const struct nxgl_rect_s *pClip,
297 FAR const struct nxgl_trapezoid_s *pTrap,
298 nxgl_mxpixel_t color)
299 {
300 // Fill a trapezoidal region with a solid color
301
302 return nx_filltrapezoid(m_hWindow, pClip, pTrap, &color) == OK;
303 }
304
305 /**
306 * Fill the specified line in the window with the specified color.
307 *
308 * @param vector - Describes the line to be drawn
309 * @param width - The width of the line
310 * @param color - The color to use to fill the line
311 * @param caps - Draw a circular cap on the ends of the line to support
312 * better line joins
313 *
314 * @return True on success; false on failure.
315 */
316
317 bool CBgWindow::drawLine(FAR struct nxgl_vector_s *vector,
318 nxgl_coord_t width, nxgl_mxpixel_t color,
319 enum ELineCaps caps)
320 {
321 // Draw a line with the specified color
322
323 return nx_drawline(m_hWindow, vector, width, &color, (uint8_t)caps) == OK;
324 }
325
326 /**
327 * Draw a filled circle at the specified position, size, and color.
328 *
329 * @param center The window-relative coordinates of the circle center.
330 * @param radius The radius of the rectangle in pixels.
331 * @param color The color of the rectangle.
332 */
333
334 bool CBgWindow::drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius,
335 nxgl_mxpixel_t color)
336 {
337 return nx_fillcircle(m_hWindow, center, radius, &color) == OK;
338 }
339
340 /**
341 * Move a rectangular region within the window.
342 *
343 * @param pRect Describes the rectangular region to move.
344 * @param pOffset The offset to move the region.
345 *
346 * @return True on success; false on failure.
347 */
348
349 bool CBgWindow::move(FAR const struct nxgl_rect_s *pRect,
350 FAR const struct nxgl_point_s *pOffset)
351 {
352 // Move a rectangular region of the display
353
354 return nx_move(m_hWindow, pRect, pOffset) == OK;
355 }
356
357 /**
358 * Copy a rectangular region of a larger image into the rectangle in the
359 * specified window. The source image is treated as an opaque image.
360 *
361 * @param pDest Describes the rectangular on the display that will receive
362 * the bitmap.
363 * @param pSrc The start of the source image.
364 * @param pOrigin the pOrigin of the upper, left-most corner of the full
365 * bitmap. Both pDest and pOrigin are in window coordinates, however,
366 * pOrigin may lie outside of the display.
367 * @param stride The width of the full source image in bytes.
368 *
369 * @return True on success; false on failure.
370 */
371
372 bool CBgWindow::bitmap(FAR const struct nxgl_rect_s *pDest,
373 FAR const void *pSrc,
374 FAR const struct nxgl_point_s *pOrigin,
375 unsigned int stride)
376 {
377 // Copy a rectangular bitmap image in a region on the display
378
379 return nx_bitmap(m_hWindow, pDest, &pSrc, pOrigin, stride) == OK;
380 }
NXWidgets::CCallback
Definition: ccallback.hxx:91
NXWidgets::CWidgetControl::createGraphicsPort
bool createGraphicsPort(INxWindow *window)
Definition: cwidgetcontrol.cxx:656
NXWidgets::CBgWindow::drawLine
bool drawLine(FAR struct nxgl_vector_s *vector, nxgl_coord_t width, nxgl_mxpixel_t color, enum ELineCaps caps)
Definition: cbgwindow.cxx:317
NXWidgets::CBgWindow::requestPosition
bool requestPosition(void)
Definition: cbgwindow.cxx:138
NXWidgets::CWidgetControl
Definition: cwidgetcontrol.hxx:95
NXWidgets::CBgWindow::getRectangle
void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest)
Definition: cbgwindow.cxx:278
NXWidgets::CBgWindow::setPixel
bool setPixel(FAR const struct nxgl_point_s *pPos, nxgl_mxpixel_t color)
Definition: cbgwindow.cxx:242
NXWidgets::CBgWindow::m_widgetControl
CWidgetControl * m_widgetControl
Definition: cbgwindow.hxx:89
NXWidgets::CBgWindow::~CBgWindow
virtual ~CBgWindow(void)
Definition: cbgwindow.cxx:80
NXWidgets::CBgWindow::m_hNxServer
NXHANDLE m_hNxServer
Definition: cbgwindow.hxx:87
cwidgetcontrol.hxx
NXWidgets::CBgWindow::getSize
bool getSize(FAR struct nxgl_size_s *pSize)
Definition: cbgwindow.cxx:168
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::INxWindow::ELineCaps
ELineCaps
Definition: inxwindow.hxx:86
NXWidgets::CBgWindow::drawFilledCircle
bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius, nxgl_mxpixel_t color)
Definition: cbgwindow.cxx:334
NXWidgets::CBgWindow::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: cbgwindow.cxx:372
cbgwindow.hxx
NXWidgets::CBgWindow::fillTrapezoid
bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip, FAR const struct nxgl_trapezoid_s *pTrap, nxgl_mxpixel_t color)
Definition: cbgwindow.cxx:296
NXWidgets::CBgWindow::setPosition
bool setPosition(FAR const struct nxgl_point_s *pPos)
Definition: cbgwindow.cxx:182
NXWidgets::SBitmap::data
FAR const void * data
Definition: cbitmap.hxx:110
NXWidgets::CBgWindow::lower
bool lower(void)
Definition: cbgwindow.cxx:226
NXWidgets::CBgWindow::CBgWindow
CBgWindow(NXHANDLE hNxServer, CWidgetControl *widgetControl)
Definition: cbgwindow.cxx:67
cbitmap.hxx
NXWidgets::CBgWindow::open
bool open(void)
Definition: cbgwindow.cxx:96
NXWidgets::SBitmap
Definition: cbitmap.hxx:103
NXWidgets::CBgWindow::setSize
bool setSize(FAR const struct nxgl_size_s *pSize)
Definition: cbgwindow.cxx:198
NXWidgets::CBgWindow::getWidgetControl
CWidgetControl * getWidgetControl(void) const
Definition: cbgwindow.cxx:124
NXWidgets::CWidgetControl::getWindowSize
bool getWindowSize(FAR struct nxgl_size_s *size)
Definition: cwidgetcontrol.hxx:714
NXWidgets::CBgWindow::m_hWindow
NXWINDOW m_hWindow
Definition: cbgwindow.hxx:88
NXWidgets::CCallback::getCallbackVTable
FAR struct nx_callback_s * getCallbackVTable(void)
Definition: ccallback.hxx:239
NXWidgets::CBgWindow::fill
bool fill(FAR const struct nxgl_rect_s *pRect, nxgl_mxpixel_t color)
Definition: cbgwindow.cxx:259
NXWidgets::SBitmap::stride
uint16_t stride
Definition: cbitmap.hxx:109
NXWidgets::CBgWindow::move
bool move(FAR const struct nxgl_rect_s *pRect, FAR const struct nxgl_point_s *pOffset)
Definition: cbgwindow.cxx:349
NXWidgets::CWidgetControl::getWindowHandle
NXHANDLE getWindowHandle(void)
Definition: cwidgetcontrol.hxx:668
NXWidgets::CBgWindow::getPosition
bool getPosition(FAR struct nxgl_point_s *pPos)
Definition: cbgwindow.cxx:152
NXWidgets::CBgWindow::raise
bool raise(void)
Definition: cbgwindow.cxx:212