NXWidgets: csliderhorizontal.hxx Source File

NXWidgets 1.19

csliderhorizontal.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/include/csliderhorizontal.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 most 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_CSLIDERHORIZONTAL_HXX
71 #define __INCLUDE_CSLIDERHORIZONTAL_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 "cwidgeteventhandler.hxx"
86 #include "islider.hxx"
87
88 /****************************************************************************
89 * Pre-Processor Definitions
90 ****************************************************************************/
91
92 /****************************************************************************
93 * Implementation Classes
94 ****************************************************************************/
95
96 #if defined(__cplusplus)
97
98 namespace NXWidgets
99 {
100 class CSliderHorizontalGrip;
101 class CWidgetControl;
102
103 /**
104 * Widget providing a sliding "grip" that can be moved left and
105 * right in the "gutter". Essentially a scrollbar, but more
106 * generic.
107 */
108
109 class CSliderHorizontal : public ISlider, public CNxWidget, public CWidgetEventHandler
110 {
111 protected:
112 CSliderHorizontalGrip *m_grip; /**< Pointer to the grip. */
113 int m_minimumValue; /**< Minimum value that the grip can represent. */
114 int m_maximumValue; /**< Maximum value that the grip can represent. */
115 int32_t m_value; /**< Current value of the slider. */
116 nxgl_coord_t m_minimumGripWidth; /**< Smallest width that the grip can become */
117 nxgl_coord_t m_pageSize; /**< Value of a page of data, used when clicking
118 the gutter. */
119 int32_t m_gutterWidth; /**< Width of the gutter, taking into account
120 any adjustments made to the width of the grip. */
121 uint32_t m_contentSize; /**< Number of values in the min/max range. */
122
123 /**
124 * Get the maximum possible value that the slider can represent. Useful when
125 * using the slider as a scrollbar, as the height of the grip prevents the full
126 * range of values being accessed (intentionally).
127 * The returned value is shifted left 16 places for more accuracy in fixed-point
128 * calculations.
129 *
130 * @return The maximum possible value that the slider can represent.
131 */
132
133 int32_t getPhysicalMaximumValueWithBitshift(void) const;
134
135 /**
136 * Get the value represented by the top of the grip.
137 * return The value represented by the top of the grip.
138 */
139
140 const int32_t getGripValue(void) const;
141
142 /**
143 * Draw the area of this widget that falls within the clipping region.
144 * Called by the redraw() function to draw all visible regions.
145 *
146 * @param port The CGraphicsPort to draw to.
147 * @see redraw()
148 */
149
150 virtual void drawContents(CGraphicsPort *port);
151
152 /**
153 * Draw the area of this widget that falls within the clipping region.
154 * Called by the redraw() function to draw all visible regions.
155 *
156 * @param port The CGraphicsPort to draw to.
157 * @see redraw()
158 */
159
160 virtual void drawBorder(CGraphicsPort *port);
161
162 /**
163 * Resize the slider to the new dimensions.
164 *
165 * @param width The new width.
166 * @param height The new height.
167 */
168
169 virtual void onResize(nxgl_coord_t width, nxgl_coord_t height);
170
171 /**
172 * Moves the grip towards the mouse.
173 *
174 * @param x The x coordinate of the click.
175 * @param y The y coordinate of the click.
176 */
177
178 virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
179
180 /**
181 * Copy constructor is protected to prevent usage.
182 */
183
184 inline CSliderHorizontal(const CSliderHorizontal& sliderHorizontal)
185 : CNxWidget(sliderHorizontal) { }
186
187 /**
188 * Resize and redraw the grip.
189 */
190
191 void resizeGrip(void);
192
193 public:
194
195 /**
196 * Constructor.
197 *
198 * @param pWidgetControl The widget control instance for the window.
199 * @param x The x coordinate of the slider, relative to its parent.
200 * @param y The y coordinate of the slider, relative to its parent.
201 * @param width The width of the slider.
202 * @param height The height of the slider.
203 */
204
205 CSliderHorizontal(CWidgetControl *pWidgetControl,
206 nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width,
207 nxgl_coord_t height);
208
209 /**
210 * Destructor.
211 */
212
213 virtual inline ~CSliderHorizontal(void) { }
214
215 /**
216 * Get the smallest value that the slider can represent.
217 *
218 * @return The smallest value.
219 */
220
221 inline const int getMinimumValue(void) const
222 {
223 return m_minimumValue;
224 }
225
226 /**
227 * Get the largest value that the slider can represent.
228 *
229 * @return The largest value.
230 */
231
232 inline const int getMaximumValue(void) const
233 {
234 return m_maximumValue;
235 }
236
237 /**
238 * Get the current value of the slider.
239 *
240 * return The current slider value.
241 */
242
243 inline const int getValue(void) const
244 {
245 return m_value >> 16;
246 }
247
248 /**
249 * Get the value represented by the height of the grip.
250 * For sliders, this would typically be 1 (so each new
251 * grip position is worth 1). For scrollbars, this
252 * would be the height of the scrolling widget.
253 *
254 * @return The page size.
255 */
256
257 inline const nxgl_coord_t getPageSize(void) const
258 {
259 return m_pageSize;
260 }
261
262 /**
263 * Set the smallest value that the slider can represent.
264 *
265 * @param value The smallest value.
266 */
267
268 inline void setMinimumValue(const int value)
269 {
270 m_minimumValue = value;
271 m_contentSize = m_maximumValue - m_minimumValue + 1;
272 resizeGrip();
273 };
274
275 /**
276 * Set the largest value that the slider can represent.
277 *
278 * @param value The largest value.
279 */
280
281 inline void setMaximumValue(const int value)
282 {
283 m_maximumValue = value;
284 m_contentSize = m_maximumValue - m_minimumValue + 1;
285 resizeGrip();
286 };
287
288 /**
289 * Set the value that of the slider. This will reposition
290 * and redraw the grip.
291 *
292 * @param value The new value.
293 */
294
295 void setValue(const int value);
296
297 /**
298 * Set the value that of the slider. This will reposition and redraw
299 * the grip. The supplied value should be shifted left 16 places.
300 * This ensures greater accuracy than the standard setValue() method if
301 * the slider is being used as a scrollbar.
302 *
303 * @param value The new value.
304 */
305
306 void setValueWithBitshift(const int32_t value);
307
308 /**
309 * Set the page size represented by the grip.
310 *
311 * @param pageSize The page size.
312 * @see getPageSize().
313 */
314
315 inline void setPageSize(const nxgl_coord_t pageSize)
316 {
317 m_pageSize = pageSize;
318 resizeGrip();
319 };
320
321 /**
322 * Process events fired by the grip.
323 *
324 * @param e The event details.
325 */
326
327 virtual void handleDragEvent(const CWidgetEventArgs &e);
328
329 /**
330 * Get the smallest value that the slider can move through when
331 * dragged.
332 *
333 * @return The smallest value that the slider can move through when
334 * dragged.
335 */
336
337 nxgl_coord_t getMinimumStep(void) const;
338 };
339 }
340
341 #endif // __cplusplus
342
343 #endif // __INCLUDE_CSLIDERHORIZONTAL_HXX
344
NXWidgets::CSliderHorizontal::CSliderHorizontal
CSliderHorizontal(const CSliderHorizontal &sliderHorizontal)
Definition: csliderhorizontal.hxx:184
NXWidgets::CNxWidget
Definition: cnxwidget.hxx:121
NXWidgets::CSliderHorizontal::getGripValue
const int32_t getGripValue(void) const
Definition: csliderhorizontal.cxx:271
NXWidgets::CWidgetEventHandler
Definition: cwidgeteventhandler.hxx:103
NXWidgets::CSliderHorizontal::m_value
int32_t m_value
Definition: csliderhorizontal.hxx:115
NXWidgets::CWidgetControl
Definition: cwidgetcontrol.hxx:95
NXWidgets::CSliderHorizontal::~CSliderHorizontal
virtual ~CSliderHorizontal(void)
Definition: csliderhorizontal.hxx:213
NXWidgets::CSliderHorizontal::getMinimumStep
nxgl_coord_t getMinimumStep(void) const
Definition: csliderhorizontal.cxx:230
NXWidgets::CSliderHorizontal::m_contentSize
uint32_t m_contentSize
Definition: csliderhorizontal.hxx:121
NXWidgets::CSliderHorizontal::setPageSize
void setPageSize(const nxgl_coord_t pageSize)
Definition: csliderhorizontal.hxx:315
NXWidgets::CSliderHorizontal::setMaximumValue
void setMaximumValue(const int value)
Definition: csliderhorizontal.hxx:281
NXWidgets::CSliderHorizontal::m_gutterWidth
int32_t m_gutterWidth
Definition: csliderhorizontal.hxx:119
NXWidgets::CSliderHorizontal::setValue
void setValue(const int value)
Definition: csliderhorizontal.cxx:140
NXWidgets::CSliderHorizontal::setMinimumValue
void setMinimumValue(const int value)
Definition: csliderhorizontal.hxx:268
NXWidgets::CSliderHorizontal
Definition: csliderhorizontal.hxx:109
NXWidgets::CSliderHorizontal::m_minimumValue
int m_minimumValue
Definition: csliderhorizontal.hxx:113
NXWidgets::CSliderHorizontal::getPhysicalMaximumValueWithBitshift
int32_t getPhysicalMaximumValueWithBitshift(void) const
Definition: csliderhorizontal.cxx:257
islider.hxx
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CSliderHorizontal::getMaximumValue
const int getMaximumValue(void) const
Definition: csliderhorizontal.hxx:232
NXWidgets::CSliderHorizontal::m_maximumValue
int m_maximumValue
Definition: csliderhorizontal.hxx:114
NXWidgets::CSliderHorizontalGrip
Definition: csliderhorizontalgrip.hxx:105
NXWidgets::ISlider
Definition: islider.hxx:99
NXWidgets::CSliderHorizontal::handleDragEvent
virtual void handleDragEvent(const CWidgetEventArgs &e)
Definition: csliderhorizontal.cxx:202
NXWidgets::CSliderHorizontal::drawContents
virtual void drawContents(CGraphicsPort *port)
Definition: csliderhorizontal.cxx:293
NXWidgets::CSliderHorizontal::getPageSize
const nxgl_coord_t getPageSize(void) const
Definition: csliderhorizontal.hxx:257
NXWidgets::CSliderHorizontal::m_minimumGripWidth
nxgl_coord_t m_minimumGripWidth
Definition: csliderhorizontal.hxx:116
NXWidgets::CSliderHorizontal::resizeGrip
void resizeGrip(void)
Definition: csliderhorizontal.cxx:379
NXWidgets::CWidgetEventArgs
Definition: cwidgeteventargs.hxx:127
NXWidgets::CSliderHorizontal::drawBorder
virtual void drawBorder(CGraphicsPort *port)
Definition: csliderhorizontal.cxx:311
cnxwidget.hxx
NXWidgets::CSliderHorizontal::m_grip
CSliderHorizontalGrip * m_grip
Definition: csliderhorizontal.hxx:112
NXWidgets::CSliderHorizontal::setValueWithBitshift
void setValueWithBitshift(const int32_t value)
Definition: csliderhorizontal.cxx:154
NXWidgets::CSliderHorizontal::getMinimumValue
const int getMinimumValue(void) const
Definition: csliderhorizontal.hxx:221
NXWidgets::CSliderHorizontal::onClick
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y)
Definition: csliderhorizontal.cxx:357
NXWidgets::CSliderHorizontal::onResize
virtual void onResize(nxgl_coord_t width, nxgl_coord_t height)
Definition: csliderhorizontal.cxx:329
cwidgeteventhandler.hxx
NXWidgets::CSliderHorizontal::getValue
const int getValue(void) const
Definition: csliderhorizontal.hxx:243
NXWidgets::CSliderHorizontal::m_pageSize
nxgl_coord_t m_pageSize
Definition: csliderhorizontal.hxx:117
NXWidgets::CGraphicsPort
Definition: cgraphicsport.hxx:106