NXWidgets: cglyphsliderhorizontal.hxx Source File

NXWidgets 1.19

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