NXWidgets  1.19
cscrollingpanel.hxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/include/cscrollingpanel.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_CSCROLLINGPANEL_HXX
71 #define __INCLUDE_CSCROLLINGPANEL_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 "iscrollable.hxx"
86 #include "cwidgetstyle.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  /**
101  * Class containing a scrollable region. Responds to mouse movement. Can
102  * contain sub-widgets which will also be scrolled.
103  */
104 
105  class CScrollingPanel : public CNxWidget, public IScrollable
106  {
107  protected:
108  CWidgetControl *m_widgetControl; /**< Widget control instance */
109  int32_t m_canvasX; /**< X coordinate of the virtual
110  canvas. */
111  int32_t m_canvasY; /**< Y coordinate of the virtual
112  canvas. */
113  int32_t m_canvasWidth; /**< Width of the virtual canvas. */
114  int32_t m_canvasHeight; /**< Height of the virtual canvas. */
115  bool m_allowVerticalScroll; /**< True if vertical scrolling is
116  allowed. */
117  bool m_allowHorizontalScroll; /**< True if horizontal scrolling is
118  allowed. */
119  bool m_isContentScrolled; /**< True if the content drawn to the
120  panel is scrolled(ie. everything
121  drawn in the draw() method);
122  false if just child objects are scrolled. */
123 
124  /**
125  * Draw the area of this widget that falls within the clipping region.
126  * Called by the redraw() function to draw all visible regions.
127  *
128  * @param port The CGraphicsPort to draw to.
129  * @see redraw()
130  */
131 
132  virtual void drawContents(CGraphicsPort *port);
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 drawBorder(CGraphicsPort *port);
143 
144  /**
145  * Scrolls the panel to match the drag.
146  *
147  * @param x The x coordinate of the mouse.
148  * @param y The y coordinate of the mouse.
149  * @param vX The horizontal drag distance.
150  * @param vY The vertical drag distance.
151  */
152 
153  virtual void onDrag(nxgl_coord_t x, nxgl_coord_t y,
154  nxgl_coord_t vX, nxgl_coord_t vY);
155 
156  /**
157  * Starts the dragging system.
158  *
159  * @param x The x coordinate of the click.
160  * @param y The y coordinate of the click.
161  */
162 
163  virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
164 
165  /**
166  * Scroll all child widgets by the specified amounts. Actually uses
167  * the widget's moveTo() function to reposition them.
168  *
169  * @param dx The horizontal distance to scroll.
170  * @param dy The vertical distance to scroll.
171  * @param do_redraw Redraw widgets after moving.
172  */
173 
174  void scrollChildren(int32_t dx, int32_t dy, bool do_redraw);
175 
176  /**
177  * Destructor.
178  */
179 
180  virtual ~CScrollingPanel(void) { }
181 
182  /**
183  * Copy constructor is protected to prevent usage.
184  */
185 
186  inline CScrollingPanel(const CScrollingPanel &scrollingPanel)
187  : CNxWidget(scrollingPanel) { }
188 
189  public:
190 
191  /**
192  * Constructor.
193  *
194  * @param pWidgetControl The widget control for the display.
195  * @param x The x coordinate of the widget.
196  * @param y The y coordinate of the widget.
197  * @param width The width of the widget.
198  * @param height The height of the widget.
199  * @param flags The usual widget flags.
200  * @param style The style that the widget should use. If this is not
201  * specified, the widget will use the values stored in the global
202  * g_defaultWidgetStyle object. The widget will copy the properties of
203  * the style into its own internal style object.
204  */
205 
206  CScrollingPanel(CWidgetControl *pWidgetControl,
207  nxgl_coord_t x, nxgl_coord_t y,
208  nxgl_coord_t width, nxgl_coord_t height,
209  uint32_t flags,
210  CWidgetStyle *style = (CWidgetStyle *)NULL);
211 
212  /**
213  * Scroll the panel by the specified amounts.
214  *
215  * @param dx The horizontal distance to scroll.
216  * @param dy The vertical distance to scroll.
217  */
218 
219  virtual void scroll(int32_t dx, int32_t dy);
220 
221  /**
222  * Reposition the panel's scrolling region to the specified coordinates.
223  *
224  * @param x The new x coordinate of the scrolling region.
225  * @param y The new y coordinate of the scrolling region.
226  */
227 
228  virtual void jump(int32_t x, int32_t y);
229 
230  /**
231  * Returns true if vertical scrolling is allowed.
232  *
233  * @return True if vertical scrolling is allowed.
234  */
235 
236  inline bool allowsVerticalScroll(void) const
237  {
238  return m_allowVerticalScroll;
239  }
240 
241  /**
242  * Returns true if horizontal scrolling is allowed.
243  *
244  * @return True if horizontal scrolling is allowed.
245  */
246 
247  inline bool allowsHorizontalScroll(void) const
248  {
250  }
251 
252  /**
253  * Gets the x coordinate of the virtual canvas.
254  *
255  * @return The x coordinate of the virtual canvas.
256  */
257 
258  virtual inline const int32_t getCanvasX(void) const
259  {
260  return m_canvasX;
261  }
262 
263  /**
264  * Gets the y coordinate of the virtual canvas.
265  *
266  * @return The y coordinate of the virtual canvas.
267  */
268 
269  virtual inline const int32_t getCanvasY(void) const
270  {
271  return m_canvasY;
272  }
273 
274  /**
275  * Gets the width of the virtual canvas.
276  *
277  * @return The width of the virtual canvas.
278  */
279 
280  virtual inline const int32_t getCanvasWidth(void) const
281  {
282  return m_canvasWidth;
283  }
284 
285  /**
286  * Gets the height of the virtual canvas.
287  *
288  * @return The height of the virtual canvas.
289  */
290 
291  virtual inline const int32_t getCanvasHeight(void) const
292  {
293  return m_canvasHeight;
294  }
295 
296  /**
297  * Set whether or not horizontal scrolling is allowed.
298  *
299  * @param allow True to allow horizontal scrolling; false to deny it.
300  */
301 
302  inline void setAllowsVerticalScroll(bool allow)
303  {
304  m_allowVerticalScroll = allow;
305  }
306 
307  /**
308  * Set whether or not horizontal scrolling is allowed.
309  *
310  * @param allow True to allow horizontal scrolling; false to deny it.
311  */
312 
313  inline void setAllowsHorizontalScroll(bool allow)
314  {
315  m_allowHorizontalScroll = allow;
316  }
317 
318  /**
319  * Set whether or not the content of the panel is scrolled.
320  * Content is anything drawn to the panel in the draw() method.
321  * This property is disabled by default, which will result in
322  * faster scrolling of child objects.
323  * If the panel contains no child objects, just draw() method
324  * content, consider using a SuperBitmap class instead.
325  *
326  * @param scrolled True to enable content scrolling; false to disable it.
327  */
328 
329  inline void setContentScrolled(bool scrolled)
330  {
331  m_isContentScrolled = scrolled;
332  }
333 
334  /**
335  * Check if the content of the panel, drawn via the draw() method,
336  * is scrolled.
337  *
338  * @return True if the content is scrolled; false if not.
339  */
340 
341  inline bool IsContentScrolled(void)
342  {
343  return m_isContentScrolled;
344  }
345 
346  /**
347  * Sets the width of the virtual canvas.
348  *
349  * @param width The width of the virtual canvas.
350  */
351 
352  virtual inline void setCanvasWidth(const int32_t width)
353  {
354  m_canvasWidth = width;
355  }
356 
357  /**
358  * Sets the height of the virtual canvas.
359  *
360  * @param height The height of the virtual canvas.
361  */
362 
363  virtual inline void setCanvasHeight(const int32_t height)
364  {
365  m_canvasHeight = height;
366  }
367  };
368 }
369 
370 #endif // __cplusplus
371 
372 #endif // __INCLUDE_CSCROLLINGPANEL_HXX
373 
bool allowsVerticalScroll(void) const
virtual void drawBorder(CGraphicsPort *port)
virtual void setCanvasHeight(const int32_t height)
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y)
void setContentScrolled(bool scrolled)
CWidgetControl * m_widgetControl
virtual const int32_t getCanvasWidth(void) const
bool allowsHorizontalScroll(void) const
CScrollingPanel(const CScrollingPanel &scrollingPanel)
virtual void drawContents(CGraphicsPort *port)
virtual const int32_t getCanvasHeight(void) const
void setAllowsHorizontalScroll(bool allow)
void scrollChildren(int32_t dx, int32_t dy, bool do_redraw)
virtual const int32_t getCanvasX(void) const
virtual const int32_t getCanvasY(void) const
virtual void scroll(int32_t dx, int32_t dy)
void setAllowsVerticalScroll(bool allow)
virtual void setCanvasWidth(const int32_t width)
virtual void jump(int32_t x, int32_t y)
virtual void onDrag(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t vX, nxgl_coord_t vY)