NXWidgets: cprogressbar.hxx Source File

NXWidgets 1.19

cprogressbar.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/include/cprogressbar.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 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_CPROGRESSBAR_HXX
71 #define __INCLUDE_CPROGRESSBAR_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
104 /**
105 * Widget providing a horizontal progress bar.
106 */
107
108 class CProgressBar : public CNxWidget
109 {
110 protected:
111 int16_t m_minimumValue; /**< Minimum value that the grip can represent. */
112 int16_t m_maximumValue; /**< Maximum value that the grip can represent. */
113 int16_t m_value; /**< Value of the progress bar. */
114 bool m_showPercentageText; /**< If true, completion percentage is drawn
115 over the bar. */
116
117 /**
118 * Draw the area of this widget that falls within the clipping region.
119 * Called by the redraw() function to draw all visible regions.
120 *
121 * @param port The CGraphicsPort to draw to.
122 * @see redraw()
123 */
124
125 virtual void drawContents(CGraphicsPort *port);
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 drawBorder(CGraphicsPort *port);
136
137 /**
138 * Copy constructor is protected to prevent usage.
139 */
140
141 inline CProgressBar(const CProgressBar &progressBar) : CNxWidget(progressBar) { }
142
143 public:
144
145 /**
146 * Constructor.
147 *
148 * @param pWidgetControl The widget control for the display.
149 * @param x The x coordinate of the progress bar, relative to its parent.
150 * @param y The y coordinate of the progress bar, relative to its parent.
151 * @param width The width of the progress bar.
152 * @param height The height of the progress bar.
153 */
154
155 CProgressBar(CWidgetControl *pWidgetControl,
156 nxgl_coord_t x, nxgl_coord_t y,
157 nxgl_coord_t width, nxgl_coord_t height);
158
159 /**
160 * Destructor.
161 */
162
163 virtual inline ~CProgressBar(void) { }
164
165 /**
166 * Get the smallest value that the progress bar can represent.
167 *
168 * @return The smallest value.
169 */
170
171 inline const int16_t getMinimumValue(void) const
172 {
173 return m_minimumValue;
174 }
175
176 /**
177 * Get the largest value that the progress bar can represent.
178 *
179 * @return The largest value.
180 */
181
182 inline const int16_t getMaximumValue(void) const
183 {
184 return m_maximumValue;
185 }
186
187 /**
188 * Get the current value of the progress bar.
189 * return The current progress bar value.
190 */
191
192 inline const int16_t getValue(void) const
193 {
194 return m_value;
195 }
196
197 /**
198 * Set the smallest value that the progress bar can represent.
199 *
200 * @param value The smallest value.
201 */
202
203 inline void setMinimumValue(const int16_t value)
204 {
205 m_minimumValue = value;
206 }
207
208 /**
209 * Set the largest value that the progress bar can represent.
210 *
211 * @param value The largest value.
212 */
213
214 inline void setMaximumValue(const int16_t value)
215 {
216 m_maximumValue = value;
217 }
218
219 /**
220 * Set the value that of the progress bar.
221 *
222 * @param value The new value.
223 */
224
225 void setValue(const int16_t value);
226
227 /**
228 * Shows the percentage text over the bar.
229 */
230
231 inline void showPercentageText(void)
232 {
233 m_showPercentageText = true;
234 redraw();
235 }
236
237 /**
238 * Hides the percentage text over the bar.
239 */
240
241 inline void hidePercentageText(void)
242 {
243 m_showPercentageText = false;
244 redraw();
245 }
246 };
247 }
248
249 #endif // __cplusplus
250
251 #endif // __INCLUDE_CPROGRESSBAR_HXX
NXWidgets::CProgressBar::CProgressBar
CProgressBar(const CProgressBar &progressBar)
Definition: cprogressbar.hxx:141
NXWidgets::CNxWidget
Definition: cnxwidget.hxx:121
NXWidgets::CProgressBar::getMaximumValue
const int16_t getMaximumValue(void) const
Definition: cprogressbar.hxx:182
NXWidgets::CProgressBar::showPercentageText
void showPercentageText(void)
Definition: cprogressbar.hxx:231
NXWidgets::CWidgetControl
Definition: cwidgetcontrol.hxx:95
NXWidgets::CProgressBar::m_minimumValue
int16_t m_minimumValue
Definition: cprogressbar.hxx:111
NXWidgets::CNxWidget::redraw
void redraw(void)
Definition: cnxwidget.cxx:483
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CProgressBar::~CProgressBar
virtual ~CProgressBar(void)
Definition: cprogressbar.hxx:163
NXWidgets::CProgressBar::hidePercentageText
void hidePercentageText(void)
Definition: cprogressbar.hxx:241
NXWidgets::CProgressBar::setValue
void setValue(const int16_t value)
Definition: cprogressbar.cxx:125
NXWidgets::CProgressBar::drawContents
virtual void drawContents(CGraphicsPort *port)
Definition: cprogressbar.cxx:152
NXWidgets::CProgressBar::setMinimumValue
void setMinimumValue(const int16_t value)
Definition: cprogressbar.hxx:203
NXWidgets::CProgressBar::setMaximumValue
void setMaximumValue(const int16_t value)
Definition: cprogressbar.hxx:214
NXWidgets::CProgressBar::getValue
const int16_t getValue(void) const
Definition: cprogressbar.hxx:192
NXWidgets::CProgressBar::m_maximumValue
int16_t m_maximumValue
Definition: cprogressbar.hxx:112
NXWidgets::CProgressBar::getMinimumValue
const int16_t getMinimumValue(void) const
Definition: cprogressbar.hxx:171
NXWidgets::CProgressBar::drawBorder
virtual void drawBorder(CGraphicsPort *port)
Definition: cprogressbar.cxx:221
NXWidgets::CProgressBar
Definition: cprogressbar.hxx:108
NXWidgets::CProgressBar::m_value
int16_t m_value
Definition: cprogressbar.hxx:113
NXWidgets::CProgressBar::m_showPercentageText
bool m_showPercentageText
Definition: cprogressbar.hxx:114
cnxwidget.hxx
NXWidgets::CGraphicsPort
Definition: cgraphicsport.hxx:106