NXWidgets: cimage.hxx Source File

NXWidgets 1.19

cimage.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/include/cimage.hxx
3 *
4 * Copyright (C) 2012-2014 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 * Portions of this package derive from Woopsi (http://woopsi.org/) and
37 * portions are original efforts. It is difficult to determine at this
38 * point what parts are original efforts and which parts derive from Woopsi.
39 * However, in any event, the work of Antony Dzeryn will be acknowledged
40 * in all NxWidget files. Thanks Antony!
41 *
42 * Copyright (c) 2007-2011, Antony Dzeryn
43 * All rights reserved.
44 *
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions are met:
47 *
48 * * Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * * Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * * Neither the names "Woopsi", "Simian Zombie" nor the
54 * names of its contributors may be used to endorse or promote products
55 * derived from this software without specific prior written permission.
56 *
57 * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
58 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
59 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
60 * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
61 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
62 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
63 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
64 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
66 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 *
68 ****************************************************************************/
69
70 #ifndef __INCLUDE_CIMAGE_HXX
71 #define __INCLUDE_CIMAGE_HXX
72
73 /****************************************************************************
74 * Included Files
75 ****************************************************************************/
76
77 #include <nuttx/config.h>
78
79 #include <stdint.h>
80 #include <stdbool.h>
81
82 #include <nuttx/nx/nxglib.h>
83
84 #include "cnxwidget.hxx"
85
86 /****************************************************************************
87 * Pre-Processor Definitions
88 ****************************************************************************/
89
90 /****************************************************************************
91 * Implementation Classes
92 ****************************************************************************/
93
94 #if defined(__cplusplus)
95
96 namespace NXWidgets
97 {
98 /**
99 * Forward references
100 */
101
102 class CWidgetControl;
103 class IBitmap;
104
105 /**
106 * Simple image widget for present static images in the widget framework.
107 */
108
109 class CImage : public CNxWidget
110 {
111 protected:
112 FAR IBitmap *m_bitmap; /**< Source bitmap image */
113 struct nxgl_point_s m_origin; /**< Origin for offset image display position */
114 bool m_highlighted; /**< Image is highlighted */
115
116 /**
117 * Draw the area of this widget that falls within the clipping region.
118 * Called by the drawContents(port) and by classes that inherit from
119 * CImage.
120 *
121 * @param port The CGraphicsPort to draw to.
122 * @see redraw()
123 */
124
125 void drawContents(CGraphicsPort *port, bool selected);
126
127 /**
128 * Draw the area of this widget that falls within the clipping region.
129 * Called by the redraw() function to draw all visible regions.
130 *
131 * @param port The CGraphicsPort to draw to.
132 * @see redraw()
133 */
134
135 virtual void drawContents(CGraphicsPort *port);
136
137 /**
138 * Draw the border of this widget. Called by the indirectly via
139 * drawBoard(port) and also by classes that inherit from CImage.
140 *
141 * @param port The CGraphicsPort to draw to.
142 * @see redraw()
143 */
144
145 void drawBorder(CGraphicsPort *port, bool selected);
146
147 /**
148 * Draw the border of this widget. Called by the redraw() function to draw
149 * all visible regions.
150 *
151 * @param port The CGraphicsPort to draw to.
152 * @see redraw()
153 */
154
155 virtual void drawBorder(CGraphicsPort *port);
156
157 /**
158 * Redraws the button.
159 *
160 * @param x The x coordinate of the click.
161 * @param y The y coordinate of the click.
162 */
163
164 virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
165
166 /**
167 * Raises an action.
168 *
169 * @param x The x coordinate of the mouse.
170 * @param y The y coordinate of the mouse.
171 */
172
173 virtual void onPreRelease(nxgl_coord_t x, nxgl_coord_t y);
174
175 /**
176 * Redraws the image.
177 *
178 * @param x The x coordinate of the mouse.
179 * @param y The y coordinate of the mouse.
180 */
181
182 virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y);
183
184 /**
185 * Redraws the image.
186 *
187 * @param x The x coordinate of the mouse.
188 * @param y The y coordinate of the mouse.
189 */
190
191 virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y);
192
193 /**
194 * Copy constructor is protected to prevent usage.
195 */
196
197 inline CImage(const CImage &label) : CNxWidget(label) { };
198
199 public:
200
201 /**
202 * Constructor for an image.
203 *
204 * @param pWidgetControl The controlling widget for the display
205 * @param x The x coordinate of the image box, relative to its parent.
206 * @param y The y coordinate of the image box, relative to its parent.
207 * @param width The width of the textbox.
208 * @param height The height of the textbox.
209 * @param bitmap The source bitmap image.
210 * @param style The style that the widget should use. If this is not
211 * specified, the button will use the global default widget
212 * style.
213 */
214
215 CImage(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
216 nxgl_coord_t width, nxgl_coord_t height, FAR IBitmap *bitmap,
217 CWidgetStyle *style = (CWidgetStyle *)NULL);
218
219 /**
220 * Destructor.
221 *
222 * NOTE: That the contained bitmap image is not destroyed when the image
223 * container is destroyed.
224 */
225
226 virtual inline ~CImage() { }
227
228 /**
229 * Get pointer to the bitmap that this image contains.
230 */
231
232 inline FAR IBitmap *getBitmap() const { return m_bitmap; }
233
234 /**
235 * Set the bitmap that this image contains.
236 */
237
238 inline void setBitmap(FAR IBitmap *bitmap) { m_bitmap = bitmap; }
239
240 /**
241 * Insert the dimensions that this widget wants to have into the rect
242 * passed in as a parameter. All coordinates are relative to the
243 * widget's parent.
244 *
245 * @param rect Reference to a rect to populate with data.
246 */
247
248 void getPreferredDimensions(CRect &rect) const;
249
250 /**
251 * Set the horizontal position of the bitmap. Zero is the left edge
252 * of the bitmap and values >0 will move the bit map to the right.
253 * This method is useful for horizontal scrolling a large bitmap
254 * within a smaller window
255 */
256
257 void setImageLeft(nxgl_coord_t column);
258
259 /**
260 * Align the image at the left of the widget region.
261 *
262 * NOTE: The CImage widget does not support any persistent alignment
263 * attribute (at least not at the moment). As a result, this alignment
264 * can be lost if the image is changed or if the widget is resized.
265 */
266
267 inline void alignHorizontalLeft(void)
268 {
269 setImageLeft(0);
270 }
271
272 /**
273 * Align the image at the left of the widget region.
274 *
275 * NOTE: The CImage widget does not support any persistent alignment
276 * attribute (at least not at the moment). As a result, this alignment
277 * can be lost if the image is changed or if the widget is resized.
278 */
279
280 void alignHorizontalCenter(void);
281
282 /**
283 * Align the image at the left of the widget region.
284 *
285 * NOTE: The CImage widget does not support any persistent alignment
286 * attribute (at least not at the moment). As a result, this alignment
287 * can be lost if the image is changed or if the widget is resized.
288 */
289
290 void alignHorizontalRight(void);
291
292 /**
293 * Set the vertical position of the bitmap. Zero is the top edge
294 * of the bitmap and values >0 will move the bit map down.
295 * This method is useful for vertical scrolling a large bitmap
296 * within a smaller window
297 */
298
299 void setImageTop(nxgl_coord_t row);
300
301 /**
302 * Align the image at the top of the widget region.
303 *
304 * NOTE: The CImage widget does not support any persistent alignment
305 * attribute (at least not at the moment). As a result, this alignment
306 * can be lost if the image is changed or if the widget is resized.
307 */
308
309 inline void alignVerticalTop(void)
310 {
311 setImageTop(0);
312 }
313
314 /**
315 * Align the image at the middle of the widget region.
316 *
317 * NOTE: The CImage widget does not support any persistent alignment
318 * attribute (at least not at the moment). As a result, this alignment
319 * can be lost if the image is changed or if the widget is resized.
320 */
321
322 void alignVerticalCenter(void);
323
324 /**
325 * Align the image at the left of the widget region.
326 *
327 * NOTE: The CImage widget does not support any persistent alignment
328 * attribute (at least not at the moment). As a result, this alignment
329 * can be lost if the image is changed or if the widget is resized.
330 */
331
332 void alignVerticalBottom(void);
333
334 /**
335 * Control the highlight state.
336 *
337 * @param highlightOn True(1), the image will be highlighted
338 */
339
340 void highlight(bool highlightOn);
341 };
342 }
343
344 #endif // __cplusplus
345
346 #endif // __INCLUDE_CIMAGE_HXX
NXWidgets::CImage::setImageLeft
void setImageLeft(nxgl_coord_t column)
Definition: cimage.cxx:484
NXWidgets::CNxWidget
Definition: cnxwidget.hxx:121
NXWidgets::CWidgetStyle
Definition: cwidgetstyle.hxx:125
NXWidgets::CImage::onClick
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y)
Definition: cimage.cxx:434
NXWidgets::CWidgetControl
Definition: cwidgetcontrol.hxx:95
NXWidgets::CImage::~CImage
virtual ~CImage()
Definition: cimage.hxx:226
NXWidgets::CImage::alignHorizontalCenter
void alignHorizontalCenter(void)
Definition: cimage.cxx:505
NXWidgets::CImage::highlight
void highlight(bool highlightOn)
Definition: cimage.cxx:418
NXWidgets::CImage::getPreferredDimensions
void getPreferredDimensions(CRect &rect) const
Definition: cimage.cxx:139
NXWidgets::CImage::drawBorder
void drawBorder(CGraphicsPort *port, bool selected)
Definition: cimage.cxx:367
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CImage::alignHorizontalRight
void alignHorizontalRight(void)
Definition: cimage.cxx:525
NXWidgets::CImage::drawContents
void drawContents(CGraphicsPort *port, bool selected)
Definition: cimage.cxx:175
NXWidgets::CImage::setBitmap
void setBitmap(FAR IBitmap *bitmap)
Definition: cimage.hxx:238
NXWidgets::CImage::setImageTop
void setImageTop(nxgl_coord_t row)
Definition: cimage.cxx:546
NXWidgets::CImage::m_bitmap
FAR IBitmap * m_bitmap
Definition: cimage.hxx:112
NXWidgets::CImage::m_highlighted
bool m_highlighted
Definition: cimage.hxx:114
NXWidgets::CImage::onPreRelease
virtual void onPreRelease(nxgl_coord_t x, nxgl_coord_t y)
Definition: cimage.cxx:446
NXWidgets::CImage::alignVerticalCenter
void alignVerticalCenter(void)
Definition: cimage.cxx:569
NXWidgets::CImage::onReleaseOutside
virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y)
Definition: cimage.cxx:470
NXWidgets::CImage::m_origin
struct nxgl_point_s m_origin
Definition: cimage.hxx:113
NXWidgets::CImage::CImage
CImage(const CImage &label)
Definition: cimage.hxx:197
NXWidgets::CImage::alignVerticalTop
void alignVerticalTop(void)
Definition: cimage.hxx:309
NXWidgets::CRect
Definition: crect.hxx:101
NXWidgets::CImage
Definition: cimage.hxx:109
NXWidgets::CImage::alignHorizontalLeft
void alignHorizontalLeft(void)
Definition: cimage.hxx:267
bitmap
static const NXWidgets::SRlePaletteBitmapEntry bitmap[]
Definition: glyph_mediaplayer24x24.cxx:85
cnxwidget.hxx
NXWidgets::CImage::getBitmap
FAR IBitmap * getBitmap() const
Definition: cimage.hxx:232
NXWidgets::IBitmap
Definition: ibitmap.hxx:103
NXWidgets::CImage::onRelease
virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y)
Definition: cimage.cxx:458
NXWidgets::CImage::alignVerticalBottom
void alignVerticalBottom(void)
Definition: cimage.cxx:589
NXWidgets::CGraphicsPort
Definition: cgraphicsport.hxx:106