NXWidgets  1.19
cnxtoolbar.cxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/src/cnxtoolbar.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 "cnxtoolbar.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.
61  *
62  * @param pNxTkWindow Parent framed window instance
63  * @param hNxTkWindow Parent framed window NX handler
64  * @param widgetControl Controlling widget for this toolbar.
65  * @param height The height of the toolbar.
66  */
67 
68 CNxToolbar::CNxToolbar(CNxTkWindow *pNxTkWindow, NXTKWINDOW hNxTkWindow,
69  CWidgetControl *pWidgetControl, nxgl_coord_t height)
70  : CCallback(pWidgetControl)
71 {
72  // Initialize toolbar state data
73 
74  m_nxTkWindow = pNxTkWindow;
75  m_hNxTkWindow = hNxTkWindow;
76  m_widgetControl = pWidgetControl;
77  m_height = height;
78 
79  // Create the CGraphicsPort instance for this window
80 
81  m_widgetControl->createGraphicsPort(static_cast<INxWindow*>(this));
82 }
83 
84 /**
85  * Destructor.
86  */
87 
89 {
90  // Inform the parent window instance that the toolbar is gone
91 
93 
94  // Release the widget control instance. Normally the lifetime
95  // of the widget control instance is managed by logic outside
96  // of the window instance. But here, as in the real world,
97  // our parent expects us to clean up after ourselves.
98 
99  delete m_widgetControl;
100 
101  // Release the toolbar.
102 
103  (void)nxtk_closetoolbar(m_hNxTkWindow);
104 }
105 
106 /**
107  * Creates a new toolbar. Toolbar creation is separate from
108  * object instantiation so that failures can be reported.
109  *
110  * @return True if the toolbar was successfully created.
111  */
112 
114 {
115  // Get the C-callable callback vtable
116 
117  FAR struct nx_callback_s *vtable = getCallbackVTable();
118 
119  // Create the toolbar
120 
121  int ret = nxtk_opentoolbar(m_hNxTkWindow, m_height, vtable,
122  (FAR void *)static_cast<CCallback*>(this));
123  return ret == OK;
124 }
125 
126 /**
127  * Each implementation of INxWindow must provide a method to recover
128  * the contained CWidgetControl instance.
129  *
130  * @return The contained CWidgetControl instance
131  */
132 
134 {
135  return m_widgetControl;
136 }
137 
138 /**
139  * Request the position and size information of the toolbar. The values
140  * will be returned asynchronously through the client callback method.
141  * The GetPosition() method may than be called to obtain the positional
142  * data as provided by the callback.
143  *
144  * @return True on success, false on any failure.
145  */
146 
148 {
149  // Request the position of the entire framed window containing the
150  // toolbar. The NXTK callback will route toolbar specific
151  // information back to us.
152 
153  nxtk_getposition(m_hNxTkWindow);
154  return false;
155 }
156 
157 /**
158  * Get the position of the toolbar in the physical display coordinates
159  * (as reported by the NX callback).
160  *
161  * @return The position.
162  */
163 
164 bool CNxToolbar::getPosition(FAR struct nxgl_point_s *pPos)
165 {
166  return m_widgetControl->getWindowPosition(pPos);
167 }
168 
169 /**
170  * Get the size of the toolbar (as reported by the NX callback).
171  *
172  * @return The size.
173  */
174 
175 bool CNxToolbar::getSize(FAR struct nxgl_size_s *pSize)
176 {
177  return m_widgetControl->getWindowSize(pSize);
178 }
179 
180 /**
181  * Set the position and size of the toolbar. The position of
182  * the toolbar is fixed at the top of the parent framed window.
183  *
184  * @param pPos The new position of the toolbar.
185  * @return Always returns false.
186  */
187 
188 bool CNxToolbar::setPosition(FAR const struct nxgl_point_s *pPos)
189 {
190  return false;
191 }
192 
193 /**
194  * Set the size of the selected toolbar. The only variable dimension
195  * is the height of the toolbar, but that cannot be changed once
196  * it is created.
197  *
198  * @param pSize The new size of the toolbar.
199  * @return Always returns false.
200  */
201 
202 bool CNxToolbar::setSize(FAR const struct nxgl_size_s *pSize)
203 {
204  return false;
205 }
206 
207 /**
208  * Bring the toolbar to the top of the display. The toolbar is
209  * a component of the containing, parent, framed window. It
210  * cannot be raised separately.
211  *
212  * @return Always returns false.
213  */
214 
216 {
217  return false;
218 }
219 
220 /**
221  * Lower the toolbar to the bottom of the display. The toolbar is
222  * a component of the containing, parent, framed window. It
223  * cannot be raised separately.
224  *
225  * @return Always returns false.
226  */
227 
229 {
230  return false;
231 }
232 
233 /**
234  * Set an individual pixel in the toolbar 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 CNxToolbar::setPixel(FAR const struct nxgl_point_s *pPos,
243  nxgl_mxpixel_t color)
244 {
245 #if 0
246  // Set an individual pixel to the specified color
247 
248  return nxtk_setpixel(m_hNxTkWindow, pPos, &color) == OK;
249 #else
250 # warning "Revisit"
251  return false;
252 #endif
253 }
254 
255 /**
256  * Fill the specified rectangle in the toolbar with the specified color.
257  *
258  * @param pRect The location to be filled.
259  * @param color The color to use in the fill.
260  *
261  * @return True on success; false on failure.
262  */
263 
264 bool CNxToolbar::fill(FAR const struct nxgl_rect_s *pRect,
265  nxgl_mxpixel_t color)
266 {
267  // Fill a rectangular region with a solid color
268 
269  return nxtk_filltoolbar(m_hNxTkWindow, pRect, &color) == OK;
270 }
271 
272 /**
273  * Get the raw contents of graphic memory within a rectangular region. NOTE:
274  * Since raw graphic memory is returned, the returned memory content may be
275  * the memory of windows above this one and may not necessarily belong to
276  * this window unless you assure that this is the top window.
277  *
278  * @param rect The location to be copied
279  * @param dest - The describes the destination bitmap to receive the
280  * graphics data.
281  */
282 
283 void CNxToolbar::getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest)
284 {
285  // Get a rectangule region from the toolbar
286 
287  (void)nxtk_gettoolbar(m_hNxTkWindow, rect, 0, (FAR uint8_t*)dest->data, dest->stride);
288 }
289 
290 /**
291  * Fill the specified trapezoidal region in the toolbar with the specified
292  * color.
293  *
294  * @param pClip Clipping rectangle relative to toolbar (may be null).
295  * @param pTrap The trapezoidal region to be filled.
296  * @param color The color to use in the fill.
297  *
298  * @return True on success; false on failure.
299  */
300 
301 bool CNxToolbar::fillTrapezoid(FAR const struct nxgl_rect_s *pClip,
302  FAR const struct nxgl_trapezoid_s *pTrap,
303  nxgl_mxpixel_t color)
304 {
305  // Fill a trapezoidal region with a solid color
306 
307  return nxtk_filltraptoolbar(m_hNxTkWindow, pTrap, &color) == OK;
308 }
309 
310 /**
311  * Fill the specified line in the toolbar with the specified color.
312  *
313  * @param vector - Describes the line to be drawn
314  * @param width - The width of the line
315  * @param color - The color to use to fill the line
316  * @param caps - Draw a circular cap on the ends of the line to support
317  * better line joins
318  *
319  * @return True on success; false on failure.
320  */
321 
322 bool CNxToolbar::drawLine(FAR struct nxgl_vector_s *vector,
323  nxgl_coord_t width, nxgl_mxpixel_t color,
324  enum ELineCaps caps)
325 {
326  // Draw a line with the specified color
327 
328  return nxtk_drawlinetoolbar(m_hNxTkWindow, vector, width, &color, (uint8_t)caps) == OK;
329 }
330 
331 /**
332  * Draw a filled circle at the specified position, size, and color.
333  *
334  * @param center The window-relative coordinates of the circle center.
335  * @param radius The radius of the rectangle in pixels.
336  * @param color The color of the rectangle.
337  */
338 
339 bool CNxToolbar::drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius,
340  nxgl_mxpixel_t color)
341 {
342  return nxtk_fillcircletoolbar(m_hNxTkWindow, center, radius, &color) == OK;
343 }
344 
345 /**
346  * Move a rectangular region within the toolbar.
347  *
348  * @param pRect Describes the rectangular region to move.
349  * @param pOffset The offset to move the region.
350  *
351  * @return True on success; false on failure.
352  */
353 
354 bool CNxToolbar::move(FAR const struct nxgl_rect_s *pRect,
355  FAR const struct nxgl_point_s *pOffset)
356 {
357  // Move a rectangular region of the display
358 
359  return nxtk_movetoolbar(m_hNxTkWindow, pRect, pOffset) == OK;
360 }
361 
362 /**
363  * Copy a rectangular region of a larger image into the rectangle in the
364  * specified toolbar. The source image is treated as an opaque image.
365  *
366  * @param pDest Describes the rectangular on the display that will receive
367  * the bitmap.
368  * @param pSrc The start of the source image.
369  * @param pOrigin the pOrigin of the upper, left-most corner of the full
370  * bitmap. Both pDest and pOrigin are in toolbar coordinates, however,
371  * pOrigin may lie outside of the display.
372  * @param stride The width of the full source image in bytes.
373  *
374  * @return True on success; false on failure.
375  */
376 
377 bool CNxToolbar::bitmap(FAR const struct nxgl_rect_s *pDest,
378  FAR const void *pSrc,
379  FAR const struct nxgl_point_s *pOrigin,
380  unsigned int stride)
381 {
382  // Copy a rectangular bitmap image in a region on the display
383 
384  return nxtk_bitmaptoolbar(m_hNxTkWindow, pDest, &pSrc, pOrigin, stride) == OK;
385 }
bool createGraphicsPort(INxWindow *window)
bool setPixel(FAR const struct nxgl_point_s *pPos, nxgl_mxpixel_t color)
Definition: cnxtoolbar.cxx:242
bool setSize(FAR const struct nxgl_size_s *pSize)
Definition: cnxtoolbar.cxx:202
CWidgetControl * getWidgetControl(void) const
Definition: cnxtoolbar.cxx:133
bool getWindowPosition(FAR struct nxgl_point_s *pos)
bool fill(FAR const struct nxgl_rect_s *pRect, nxgl_mxpixel_t color)
Definition: cnxtoolbar.cxx:264
bool setPosition(FAR const struct nxgl_point_s *pPos)
Definition: cnxtoolbar.cxx:188
bool getSize(FAR struct nxgl_size_s *pSize)
Definition: cnxtoolbar.cxx:175
bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip, FAR const struct nxgl_trapezoid_s *pTrap, nxgl_mxpixel_t color)
Definition: cnxtoolbar.cxx:301
FAR const void * data
Definition: cbitmap.hxx:110
bool requestPosition(void)
Definition: cnxtoolbar.cxx:147
CNxToolbar(CNxTkWindow *pNxTkWindow, NXTKWINDOW hNxTkWindow, CWidgetControl *pWidgetControl, nxgl_coord_t height)
Definition: cnxtoolbar.cxx:68
void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest)
Definition: cnxtoolbar.cxx:283
CWidgetControl * m_widgetControl
Definition: cnxtoolbar.hxx:90
bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius, nxgl_mxpixel_t color)
Definition: cnxtoolbar.cxx:339
bool move(FAR const struct nxgl_rect_s *pRect, FAR const struct nxgl_point_s *pOffset)
Definition: cnxtoolbar.cxx:354
bool bitmap(FAR const struct nxgl_rect_s *pDest, FAR const void *pSrc, FAR const struct nxgl_point_s *pOrigin, unsigned int stride)
Definition: cnxtoolbar.cxx:377
bool getPosition(FAR struct nxgl_point_s *pPos)
Definition: cnxtoolbar.cxx:164
bool getWindowSize(FAR struct nxgl_size_s *size)
FAR struct nx_callback_s * getCallbackVTable(void)
Definition: ccallback.hxx:239
bool drawLine(FAR struct nxgl_vector_s *vector, nxgl_coord_t width, nxgl_mxpixel_t color, enum ELineCaps caps)
Definition: cnxtoolbar.cxx:322
CNxTkWindow * m_nxTkWindow
Definition: cnxtoolbar.hxx:88
nxgl_coord_t m_height
Definition: cnxtoolbar.hxx:91
NXTKWINDOW m_hNxTkWindow
Definition: cnxtoolbar.hxx:89