NXWidgets  1.19
cstickyimage.hxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/include/cstickyimage.hxx
3  *
4  * Copyright (C) 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 #ifndef __INCLUDE_CSTICKIMAGE_HXX
37 #define __INCLUDE_CSTICKIMAGE_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 
50 #include "cimage.hxx"
51 #include "cwidgetstyle.hxx"
52 
53 /****************************************************************************
54  * Pre-Processor Definitions
55  ****************************************************************************/
56 
57 /****************************************************************************
58  * Implementation Classes
59  ****************************************************************************/
60 
61 #if defined(__cplusplus)
62 
63 namespace NXWidgets
64 {
65  class CWidgetControl;
66 
67  /**
68  * CImage that sticks in the selected selected state when clicked.
69  */
70 
71  class CStickyImage : public CImage
72  {
73  protected:
74  bool m_stuckSelection; /**< True if the image is stuck in the selected */
75 
76  /**
77  * Draw the area of this widget that falls within the clipping region.
78  * Called by the redraw() function to draw all visible regions.
79  *
80  * @param port The CGraphicsPort to draw to.
81  * @see redraw()
82  */
83 
84  virtual void drawContents(CGraphicsPort *port);
85 
86  /**
87  * Draw the area of this widget that falls within the clipping region.
88  * Called by the redraw() function to draw all visible regions.
89  *
90  * @param port The CGraphicsPort to draw to.
91  * @see redraw()
92  */
93 
94  virtual void drawBorder(CGraphicsPort *port);
95 
96  /**
97  * Don't redraw on click events. The image state is completely controlled
98  * by the m_stuckSelection state.
99  *
100  * @param x The x coordinate of the click.
101  * @param y The y coordinate of the click.
102  */
103 
104  virtual void onClick(nxgl_coord_t x, nxgl_coord_t y) {}
105 
106  /**
107  * Don't redraw on release events. The image state is completely controlled
108  * by the m_stuckSelection state.
109  *
110  * @param x The x coordinate of the mouse.
111  * @param y The y coordinate of the mouse.
112  */
113 
114  virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y) { }
115 
116  /**
117  * Don't redraw on release events. The image state is completely controlled
118  * by the m_stuckSelection state.
119  *
120  * @param x The x coordinate of the mouse.
121  * @param y The y coordinate of the mouse.
122  */
123 
124  virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y) { }
125 
126  /**
127  * Copy constructor is protected to prevent usage.
128  */
129 
130  inline CStickyImage(const CStickyImage &image) : CImage(image) { }
131 
132  public:
133 
134  /**
135  * Constructor for an image.
136  *
137  * @param pWidgetControl The controlling widget for the display
138  * @param x The x coordinate of the image box, relative to its parent.
139  * @param y The y coordinate of the image box, relative to its parent.
140  * @param width The width of the image box.
141  * @param height The height of the image box.
142  * @param bitmap The source bitmap image.
143  * @param style The style that the widget should use. If this is not
144  * specified, the image will use the global default widget
145  * style.
146  */
147 
148  CStickyImage(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
149  nxgl_coord_t width, nxgl_coord_t height, FAR IBitmap *bitmap,
150  CWidgetStyle *style = (CWidgetStyle *)NULL);
151 
152  /**
153  * Destructor.
154  */
155 
156  virtual inline ~CStickyImage(void) { }
157 
158  /**
159  * Sets the image's stuck selection state.
160  *
161  * @param selection The new stuck selection state.
162  */
163 
164  void setStuckSelection(bool selection);
165 
166  /**
167  * Toggles the images stuck selection state.
168  */
169 
170  inline void toggleStuckSelection(void)
171  {
172  setStuckSelection(!m_stuckSelection);
173  }
174 
175  /**
176  * Returns the stuck selection state.
177  *
178  * @return True if the image is in the stuck selection state.
179  */
180 
181  inline const bool isStuckSelection(void) const
182  {
183  return m_stuckSelection;
184  }
185  };
186 }
187 
188 #endif // __cplusplus
189 
190 #endif // __INCLUDE_CSTICKIMAGE_HXX
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y)
virtual ~CStickyImage(void)
virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y)
void setStuckSelection(bool selection)
virtual void drawBorder(CGraphicsPort *port)
CStickyImage(const CStickyImage &image)
const bool isStuckSelection(void) const
virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y)
static const NXWidgets::SRlePaletteBitmapEntry bitmap[]
virtual void drawContents(CGraphicsPort *port)