NXWidgets  1.19
csliderverticalgrip.cxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/src/cslidervertical.cxx
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 /****************************************************************************
71  * Included Files
72  ****************************************************************************/
73 
74 #include <nuttx/config.h>
75 
76 #include <stdint.h>
77 #include <stdbool.h>
78 
79 #include "nxconfig.hxx"
80 #include "cwidgetcontrol.hxx"
81 #include "csliderverticalgrip.hxx"
82 #include "cgraphicsport.hxx"
83 
84 /****************************************************************************
85  * Pre-Processor Definitions
86  ****************************************************************************/
87 
88 /****************************************************************************
89  * Method Implementations
90  ****************************************************************************/
91 
92 using namespace NXWidgets;
93 /**
94  * Constructor.
95  *
96  * @param pWidgetControl The controlling widget for the display
97  * @param x The x coordinate of the grip, relative to its parent.
98  * @param y The y coordinate of the grip, relative to its parent.
99  * @param width The width of the grip.
100  * @param height The height of the grip.
101  */
102 
104  nxgl_coord_t x, nxgl_coord_t y,
105  nxgl_coord_t width, nxgl_coord_t height)
106 : CNxWidget(pWidgetControl, x, y, width, height, WIDGET_DRAGGABLE)
107 {
108 }
109 
110 /**
111  * Draw the area of this widget that falls within the clipping region.
112  * Called by the redraw() function to draw all visible regions.
113  *
114  * @param port The CGraphicsPort to draw to.
115  * @see redraw()
116  */
117 
119 {
120  CRect rect;
121  getRect(rect);
122 
123  nxwidget_pixel_t color;
124  if (!m_flags.clicked)
125  {
126  color = getSelectedBackgroundColor();
127  }
128  else
129  {
130  color = getHighlightColor();
131  }
132 
133  port->drawFilledRect(rect.getX(), rect.getY(),
134  rect.getWidth(), rect.getHeight(),
135  color);
136 }
137 
138 /**
139  * Draw the area of this widget that falls within the clipping region.
140  * Called by the redraw() function to draw all visible regions.
141  *
142  * @param port The CGraphicsPort to draw to.
143  * @see redraw()
144  */
145 
147 {
148  // Stop drawing if the widget indicates it should not have an outline
149 
150  if (!isBorderless())
151  {
152  if (isClicked())
153  {
154  port->drawBevelledRect(getX(), getY(), getWidth(), getHeight(),
156  }
157  else
158  {
159  port->drawBevelledRect(getX(), getY(), getWidth(), getHeight(),
161  }
162  }
163 }
164 
165 /**
166  * Starts dragging the grip and redraws it.
167  *
168  * @param x The x coordinate of the click.
169  * @param y The y coordinate of the click.
170  */
171 
172 void CSliderVerticalGrip::onClick(nxgl_coord_t x, nxgl_coord_t y)
173 {
174  startDragging(x, y);
175  redraw();
176 }
177 
178 /**
179  * Redraws the grip.
180  *
181  * @param x The x coordinate of the mouse.
182  * @param y The y coordinate of the mouse.
183  */
184 
185 void CSliderVerticalGrip::onRelease(nxgl_coord_t x, nxgl_coord_t y)
186 {
187  redraw();
188 }
189 
190 /**
191  * Redraws the grip.
192  *
193  * @param x The x coordinate of the mouse.
194  * @param y The y coordinate of the mouse.
195  */
196 
197 void CSliderVerticalGrip::onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y)
198 {
199  redraw();
200 }
201 
202 /**
203  * Moves the grip to follow the mouse.
204  *
205  * @param x The x coordinate of the mouse.
206  * @param y The y coordinate of the mouse.
207  * @param vX The horizontal distance of the drag.
208  * @param vY The vertical distance of the drag.
209  */
210 
211 void CSliderVerticalGrip::onDrag(nxgl_coord_t x, nxgl_coord_t y,
212  nxgl_coord_t vX, nxgl_coord_t vY)
213 {
214  // Work out where we're moving to
215 
216  nxgl_coord_t destY = y - m_grabPointY - m_parent->getY();
217 
218  // Do we need to move?
219 
220  if (destY != m_rect.getY())
221  {
222  // Get parent rect
223 
224  CRect rect;
225  m_parent->getClientRect(rect);
226 
227  // Prevent grip from moving outside parent
228 
229  if (destY < rect.getY())
230  {
231  destY = rect.getY();
232  }
233  else
234  {
235  if (destY + getHeight() > rect.getHeight() + rect.getY())
236  {
237  destY = (rect.getHeight() + rect.getY()) - getHeight();
238  }
239  }
240 
241  // Move to new location
242 
243  moveTo(rect.getX(), destY);
244  }
245 }
bool isClicked(void) const
Definition: cnxwidget.hxx:560
bool isBorderless(void) const
Definition: cnxwidget.hxx:549
nxgl_mxpixel_t getShadowEdgeColor(void) const
Definition: cnxwidget.hxx:749
nxgl_coord_t getHeight(void) const
Definition: crect.hxx:204
bool moveTo(nxgl_coord_t x, nxgl_coord_t y)
Definition: cnxwidget.cxx:990
nxgl_coord_t m_grabPointY
Definition: cnxwidget.hxx:177
void getRect(CRect &rect) const
Definition: cnxwidget.cxx:448
nxgl_coord_t getWidth(void) const
Definition: crect.hxx:181
void drawBevelledRect(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, nxgl_mxpixel_t shineColor, nxgl_mxpixel_t shadowColor)
nxgl_coord_t getX(void) const
Definition: crect.hxx:160
virtual void drawBorder(CGraphicsPort *port)
CSliderVerticalGrip(const CSliderVerticalGrip &sliderVerticalGrip)
virtual void onDrag(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t vX, nxgl_coord_t vY)
uint8_t nxwidget_pixel_t
Definition: nxconfig.hxx:442
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y)
nxgl_coord_t getHeight(void) const
Definition: cnxwidget.hxx:593
void getClientRect(CRect &rect) const
Definition: cnxwidget.cxx:421
virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y)
virtual void drawContents(CGraphicsPort *port)
nxgl_mxpixel_t getSelectedBackgroundColor(void) const
Definition: cnxwidget.hxx:727
void drawFilledRect(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, nxgl_mxpixel_t color)
nxgl_mxpixel_t getShineEdgeColor(void) const
Definition: cnxwidget.hxx:738
nxgl_mxpixel_t getHighlightColor(void) const
Definition: cnxwidget.hxx:760
nxgl_coord_t getY(void) const
Definition: cnxwidget.cxx:261
nxgl_coord_t getWidth(void) const
Definition: cnxwidget.hxx:582
nxgl_coord_t getX(void) const
Definition: cnxwidget.cxx:245
nxgl_coord_t getY(void) const
Definition: crect.hxx:170
virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y)
void startDragging(nxgl_coord_t x, nxgl_coord_t y)
Definition: cnxwidget.cxx:1542
CNxWidget * m_parent
Definition: cnxwidget.hxx:202