cscrollingpanel.hxx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/cscrollingpanel.hxx
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /****************************************************************************
  21. *
  22. * Portions of this package derive from Woopsi (http://woopsi.org/) and
  23. * portions are original efforts. It is difficult to determine at this
  24. * point what parts are original efforts and which parts derive from Woopsi.
  25. * However, in any event, the work of Antony Dzeryn will be acknowledged
  26. * in most NxWidget files. Thanks Antony!
  27. *
  28. * Copyright (c) 2007-2011, Antony Dzeryn
  29. * All rights reserved.
  30. *
  31. * Redistribution and use in source and binary forms, with or without
  32. * modification, are permitted provided that the following conditions are met:
  33. *
  34. * * Redistributions of source code must retain the above copyright
  35. * notice, this list of conditions and the following disclaimer.
  36. * * Redistributions in binary form must reproduce the above copyright
  37. * notice, this list of conditions and the following disclaimer in the
  38. * documentation and/or other materials provided with the distribution.
  39. * * Neither the names "Woopsi", "Simian Zombie" nor the
  40. * names of its contributors may be used to endorse or promote products
  41. * derived from this software without specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
  44. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  45. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  46. * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
  47. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  48. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  49. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  50. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  51. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  52. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  53. *
  54. ****************************************************************************/
  55. #ifndef __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CSCROLLINGPANEL_HXX
  56. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CSCROLLINGPANEL_HXX
  57. /****************************************************************************
  58. * Included Files
  59. ****************************************************************************/
  60. #include <nuttx/config.h>
  61. #include <stdint.h>
  62. #include <stdbool.h>
  63. #include <nuttx/nx/nxglib.h>
  64. #include "graphics/nxwidgets/cnxwidget.hxx"
  65. #include "graphics/nxwidgets/iscrollable.hxx"
  66. #include "graphics/nxwidgets/cwidgetstyle.hxx"
  67. /****************************************************************************
  68. * Pre-Processor Definitions
  69. ****************************************************************************/
  70. /****************************************************************************
  71. * Implementation Classes
  72. ****************************************************************************/
  73. #if defined(__cplusplus)
  74. namespace NXWidgets
  75. {
  76. /**
  77. * Class containing a scrollable region. Responds to mouse movement. Can
  78. * contain sub-widgets which will also be scrolled.
  79. */
  80. class CScrollingPanel : public CNxWidget, public IScrollable
  81. {
  82. protected:
  83. CWidgetControl *m_widgetControl; /**< Widget control instance */
  84. int32_t m_canvasX; /**< X coordinate of the virtual
  85. canvas. */
  86. int32_t m_canvasY; /**< Y coordinate of the virtual
  87. canvas. */
  88. int32_t m_canvasWidth; /**< Width of the virtual canvas. */
  89. int32_t m_canvasHeight; /**< Height of the virtual canvas. */
  90. bool m_allowVerticalScroll; /**< True if vertical scrolling is
  91. allowed. */
  92. bool m_allowHorizontalScroll; /**< True if horizontal scrolling is
  93. allowed. */
  94. bool m_isContentScrolled; /**< True if the content drawn to the
  95. panel is scrolled(ie. everything
  96. drawn in the draw() method);
  97. false if just child objects are scrolled. */
  98. /**
  99. * Draw the area of this widget that falls within the clipping region.
  100. * Called by the redraw() function to draw all visible regions.
  101. *
  102. * @param port The CGraphicsPort to draw to.
  103. * @see redraw()
  104. */
  105. virtual void drawContents(CGraphicsPort *port);
  106. /**
  107. * Draw the area of this widget that falls within the clipping region.
  108. * Called by the redraw() function to draw all visible regions.
  109. *
  110. * @param port The CGraphicsPort to draw to.
  111. * @see redraw()
  112. */
  113. virtual void drawBorder(CGraphicsPort *port);
  114. /**
  115. * Scrolls the panel to match the drag.
  116. *
  117. * @param x The x coordinate of the mouse.
  118. * @param y The y coordinate of the mouse.
  119. * @param vX The horizontal drag distance.
  120. * @param vY The vertical drag distance.
  121. */
  122. virtual void onDrag(nxgl_coord_t x, nxgl_coord_t y,
  123. nxgl_coord_t vX, nxgl_coord_t vY);
  124. /**
  125. * Starts the dragging system.
  126. *
  127. * @param x The x coordinate of the click.
  128. * @param y The y coordinate of the click.
  129. */
  130. virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
  131. /**
  132. * Scroll all child widgets by the specified amounts. Actually uses
  133. * the widget's moveTo() function to reposition them.
  134. *
  135. * @param dx The horizontal distance to scroll.
  136. * @param dy The vertical distance to scroll.
  137. * @param do_redraw Redraw widgets after moving.
  138. */
  139. void scrollChildren(int32_t dx, int32_t dy, bool do_redraw);
  140. /**
  141. * Destructor.
  142. */
  143. virtual ~CScrollingPanel(void) { }
  144. /**
  145. * Copy constructor is protected to prevent usage.
  146. */
  147. inline CScrollingPanel(const CScrollingPanel &scrollingPanel)
  148. : CNxWidget(scrollingPanel) { }
  149. public:
  150. /**
  151. * Constructor.
  152. *
  153. * @param pWidgetControl The widget control for the display.
  154. * @param x The x coordinate of the widget.
  155. * @param y The y coordinate of the widget.
  156. * @param width The width of the widget.
  157. * @param height The height of the widget.
  158. * @param flags The usual widget flags.
  159. * @param style The style that the widget should use. If this is not
  160. * specified, the widget will use the values stored in the global
  161. * g_defaultWidgetStyle object. The widget will copy the properties of
  162. * the style into its own internal style object.
  163. */
  164. CScrollingPanel(CWidgetControl *pWidgetControl,
  165. nxgl_coord_t x, nxgl_coord_t y,
  166. nxgl_coord_t width, nxgl_coord_t height,
  167. uint32_t flags,
  168. CWidgetStyle *style = (CWidgetStyle *)NULL);
  169. /**
  170. * Scroll the panel by the specified amounts.
  171. *
  172. * @param dx The horizontal distance to scroll.
  173. * @param dy The vertical distance to scroll.
  174. */
  175. virtual void scroll(int32_t dx, int32_t dy);
  176. /**
  177. * Reposition the panel's scrolling region to the specified coordinates.
  178. *
  179. * @param x The new x coordinate of the scrolling region.
  180. * @param y The new y coordinate of the scrolling region.
  181. */
  182. virtual void jump(int32_t x, int32_t y);
  183. /**
  184. * Returns true if vertical scrolling is allowed.
  185. *
  186. * @return True if vertical scrolling is allowed.
  187. */
  188. inline bool allowsVerticalScroll(void) const
  189. {
  190. return m_allowVerticalScroll;
  191. }
  192. /**
  193. * Returns true if horizontal scrolling is allowed.
  194. *
  195. * @return True if horizontal scrolling is allowed.
  196. */
  197. inline bool allowsHorizontalScroll(void) const
  198. {
  199. return m_allowHorizontalScroll;
  200. }
  201. /**
  202. * Gets the x coordinate of the virtual canvas.
  203. *
  204. * @return The x coordinate of the virtual canvas.
  205. */
  206. virtual inline const int32_t getCanvasX(void) const
  207. {
  208. return m_canvasX;
  209. }
  210. /**
  211. * Gets the y coordinate of the virtual canvas.
  212. *
  213. * @return The y coordinate of the virtual canvas.
  214. */
  215. virtual inline const int32_t getCanvasY(void) const
  216. {
  217. return m_canvasY;
  218. }
  219. /**
  220. * Gets the width of the virtual canvas.
  221. *
  222. * @return The width of the virtual canvas.
  223. */
  224. virtual inline const int32_t getCanvasWidth(void) const
  225. {
  226. return m_canvasWidth;
  227. }
  228. /**
  229. * Gets the height of the virtual canvas.
  230. *
  231. * @return The height of the virtual canvas.
  232. */
  233. virtual inline const int32_t getCanvasHeight(void) const
  234. {
  235. return m_canvasHeight;
  236. }
  237. /**
  238. * Set whether or not horizontal scrolling is allowed.
  239. *
  240. * @param allow True to allow horizontal scrolling; false to deny it.
  241. */
  242. inline void setAllowsVerticalScroll(bool allow)
  243. {
  244. m_allowVerticalScroll = allow;
  245. }
  246. /**
  247. * Set whether or not horizontal scrolling is allowed.
  248. *
  249. * @param allow True to allow horizontal scrolling; false to deny it.
  250. */
  251. inline void setAllowsHorizontalScroll(bool allow)
  252. {
  253. m_allowHorizontalScroll = allow;
  254. }
  255. /**
  256. * Set whether or not the content of the panel is scrolled.
  257. * Content is anything drawn to the panel in the draw() method.
  258. * This property is disabled by default, which will result in
  259. * faster scrolling of child objects.
  260. * If the panel contains no child objects, just draw() method
  261. * content, consider using a SuperBitmap class instead.
  262. *
  263. * @param scrolled True to enable content scrolling; false to disable it.
  264. */
  265. inline void setContentScrolled(bool scrolled)
  266. {
  267. m_isContentScrolled = scrolled;
  268. }
  269. /**
  270. * Check if the content of the panel, drawn via the draw() method,
  271. * is scrolled.
  272. *
  273. * @return True if the content is scrolled; false if not.
  274. */
  275. inline bool IsContentScrolled(void)
  276. {
  277. return m_isContentScrolled;
  278. }
  279. /**
  280. * Sets the width of the virtual canvas.
  281. *
  282. * @param width The width of the virtual canvas.
  283. */
  284. virtual inline void setCanvasWidth(const int32_t width)
  285. {
  286. m_canvasWidth = width;
  287. }
  288. /**
  289. * Sets the height of the virtual canvas.
  290. *
  291. * @param height The height of the virtual canvas.
  292. */
  293. virtual inline void setCanvasHeight(const int32_t height)
  294. {
  295. m_canvasHeight = height;
  296. }
  297. };
  298. }
  299. #endif // __cplusplus
  300. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CSCROLLINGPANEL_HXX