NXWidgets  1.19
cglyphbutton.hxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/include/cbutton.hxx
3  *
4  * Copyright (C) 2012 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_CGLYPHBUTTON_HXX
71 #define __INCLUDE_CGLYPHBUTTON_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 #include "cwidgetstyle.hxx"
86 
87 /****************************************************************************
88  * Pre-Processor Definitions
89  ****************************************************************************/
90 
91 /****************************************************************************
92  * Implementation Classes
93  ****************************************************************************/
94 
95 #if defined(__cplusplus)
96 
97 namespace NXWidgets
98 {
99  /**
100  * Forward references
101  */
102 
103  class CWidgetControl;
104  struct SBitmap;
105 
106  /**
107  * Class representing a button that will display a glyph.
108  * Class representing a clickable button that contains a bitmap image
109  * instead of text. Displays two bitmaps, one when the button is clicked,
110  * and one when it isn't. The bitmaps should be the same size.
111  */
112 
113  class CGlyphButton : public CNxWidget
114  {
115  protected:
116 
117  FAR const struct SBitmap *m_bitmapNormal; /**< Bitmap when button is not clicked */
118  FAR const struct SBitmap *m_bitmapClicked; /**< Bitmap when button is clicked */
119  nxgl_coord_t m_bitmapX; /**< X coordinate of the bitmaps */
120  nxgl_coord_t m_bitmapY; /**< Y coordinate of the bitmaps */
121 
122  /**
123  * Draw the area of this widget that falls within the clipping region.
124  * Called by the redraw() function to draw all visible regions.
125  *
126  * @param port The CGraphicsPort to draw to.
127  * @see redraw()
128  */
129 
130  virtual void drawContents(CGraphicsPort *port);
131 
132  /**
133  * Draw the area of this widget that falls within the clipping region.
134  * Called by the redraw() function to draw all visible regions.
135  *
136  * @param port The CGraphicsPort to draw to.
137  * @see redraw()
138  */
139 
140  virtual void drawBorder(CGraphicsPort *port);
141 
142  /**
143  *
144  * @param port Graphics port to draw to.
145  */
146 
147  virtual void drawOutline(CGraphicsPort *port);
148 
149  /**
150  * Redraws the button.
151  *
152  * @param x The x coordinate of the click.
153  * @param y The y coordinate of the click.
154  */
155 
156  virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
157 
158  /**
159  * Raises an action event.
160  *
161  * @param x The x coordinate of the mouse.
162  * @param y The y coordinate of the mouse.
163  */
164 
165  virtual void onPreRelease(nxgl_coord_t x, nxgl_coord_t y);
166 
167  /**
168  * Raises a release event and redraws the button.
169  *
170  * @param x The x coordinate of the mouse.
171  * @param y The y coordinate of the mouse.
172  */
173 
174  virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y);
175 
176  /**
177  * Redraws the button.
178  *
179  * @param x The x coordinate of the mouse.
180  * @param y The y coordinate of the mouse.
181  */
182 
183  virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y);
184 
185  /**
186  * Copy constructor is protected to prevent usage.
187  */
188 
189  inline CGlyphButton(const CGlyphButton &button) : CNxWidget(button) { }
190 
191  public:
192 
193  /**
194  * Constructor.
195  *
196  * @param pWidgetControl The widget control for the display.
197  * @param x The x coordinate of the button.
198  * @param y The y coordinate of the button.
199  * @param width The width of the button.
200  * @param height The height of the button.
201  * @param normalGlyph Glyph to display when unclicked.
202  * @param clickedGlyph Glyph to display when clicked.
203  * @param bitmapX The x coordinate at which the bitmaps will be drawn.
204  * @param bitmapY The y coordinate at which the bitmaps will be drawn.
205  * @param style The style that the button should use. If this is not
206  * specified, the button will use the values stored in the global
207  * g_defaultWidgetStyle object. The button will copy the properties of
208  * the style into its own internal style object.
209  */
210 
211  CGlyphButton(CWidgetControl *pWidgetControl,
212  nxgl_coord_t x, nxgl_coord_t y,
213  nxgl_coord_t width, nxgl_coord_t height,
214  nxgl_coord_t bitmapX, nxgl_coord_t bitmapY,
215  FAR const struct SBitmap *normalGlyph,
216  FAR const struct SBitmap *clickedGlyph,
217  CWidgetStyle *style = (CWidgetStyle *)NULL);
218 
219  /**
220  * Destructor.
221  */
222 
223  virtual inline ~CGlyphButton(void) { }
224 
225  /**
226  * Insert the dimensions that this widget wants to have into the rect
227  * passed in as a parameter. All coordinates are relative to the widget's
228  * parent.
229  * @param rect Reference to a rect to populate with data.
230  */
231 
232  virtual void getPreferredDimensions(CRect &rect) const;
233  };
234 }
235 
236 #endif // __cplusplus
237 
238 #endif // __INCLUDE_CGLYPHBUTTON_HXX
CGlyphButton(const CGlyphButton &button)
virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y)
FAR const struct SBitmap * m_bitmapNormal
virtual void drawBorder(CGraphicsPort *port)
virtual void onPreRelease(nxgl_coord_t x, nxgl_coord_t y)
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y)
virtual void getPreferredDimensions(CRect &rect) const
virtual void drawOutline(CGraphicsPort *port)
virtual void drawContents(CGraphicsPort *port)
virtual ~CGlyphButton(void)
FAR const struct SBitmap * m_bitmapClicked
virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y)