cglyphsliderhorizontal.hxx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/cglyphsliderhorizontal.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_CGLYPHSLIDERHORIZONTAL_HXX
  56. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CGLYPHSLIDERHORIZONTAL_HXX
  57. /****************************************************************************
  58. * Included Files
  59. ****************************************************************************/
  60. #include "graphics/nxwidgets/csliderhorizontal.hxx"
  61. #include "graphics/nxwidgets/cglyphsliderhorizontalgrip.hxx"
  62. /****************************************************************************
  63. * Pre-Processor Definitions
  64. ****************************************************************************/
  65. /****************************************************************************
  66. * Implementation Classes
  67. ****************************************************************************/
  68. #if defined(__cplusplus)
  69. namespace NXWidgets
  70. {
  71. /**
  72. * Widget providing a sliding "grip" that can be moved left and
  73. * right in the "gutter". Essentially a scrollbar, but more
  74. * generic.
  75. */
  76. class CGlyphSliderHorizontal : public ISlider, public CNxWidget, public CWidgetEventHandler
  77. {
  78. protected:
  79. CGlyphSliderHorizontalGrip *m_grip; /**< Pointer to the grip. */
  80. int m_minimumValue; /**< Minimum value that the grip can represent. */
  81. int m_maximumValue; /**< Maximum value that the grip can represent. */
  82. int32_t m_value; /**< Current value of the slider. */
  83. nxgl_coord_t m_minimumGripWidth; /**< Smallest width that the grip can become */
  84. nxgl_coord_t m_pageSize; /**< Value of a page of data, used when clicking
  85. the gutter. */
  86. int32_t m_gutterWidth; /**< Width of the gutter, taking into account
  87. any adjustments made to the width of the grip. */
  88. uint32_t m_contentSize; /**< Number of values in the min/max range. */
  89. nxwidget_pixel_t m_fillColor; /**< Fill color for left side of "fuel gague" */
  90. bool m_fill; /**< Set true if fill is active */
  91. uint32_t m_barThickness; /**< Thickness (in pixels) of the bar */
  92. /**
  93. * Get the maximum possible value that the slider can represent. Useful when
  94. * using the slider as a scrollbar, as the height of the grip prevents the full
  95. * range of values being accessed (intentionally).
  96. * The returned value is shifted left 16 places for more accuracy in fixed-point
  97. * calculations.
  98. *
  99. * @return The maximum possible value that the slider can represent.
  100. */
  101. int32_t getPhysicalMaximumValueWithBitshift(void) const;
  102. /**
  103. * Get the value represented by the top of the grip.
  104. * return The value represented by the top of the grip.
  105. */
  106. const int32_t getGripValue(void) const;
  107. /**
  108. * Draw the area of this widget that falls within the clipping region.
  109. * Called by the redraw() function to draw all visible regions.
  110. *
  111. * @param port The CGraphicsPort to draw to.
  112. * @see redraw()
  113. */
  114. virtual void drawContents(CGraphicsPort *port);
  115. /**
  116. * Draw the area of this widget that falls within the clipping region.
  117. * Called by the redraw() function to draw all visible regions.
  118. *
  119. * @param port The CGraphicsPort to draw to.
  120. * @see redraw()
  121. */
  122. virtual void drawBorder(CGraphicsPort *port);
  123. /**
  124. * Resize the slider to the new dimensions.
  125. *
  126. * @param width The new width.
  127. * @param height The new height.
  128. */
  129. virtual void onResize(nxgl_coord_t width, nxgl_coord_t height);
  130. /**
  131. * Moves the grip towards the mouse.
  132. *
  133. * @param x The x coordinate of the click.
  134. * @param y The y coordinate of the click.
  135. */
  136. virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
  137. public:
  138. /**
  139. * Constructor.
  140. *
  141. * @param control The widget control instance for the window.
  142. * @param x The x coordinate of the slider, relative to its parent.
  143. * @param y The y coordinate of the slider, relative to its parent.
  144. * @param width The width of the slider.
  145. * @param thickness The thickness of the slider.
  146. * @param gripBitmap The slider grip image
  147. * @param fillColor The color to use when filling the grip
  148. * @param fill True: The grip will be filled with fillColor
  149. */
  150. CGlyphSliderHorizontal(CWidgetControl *control,
  151. nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width,
  152. nxgl_coord_t thickness, IBitmap *gripBitmap,
  153. nxwidget_pixel_t fillColor, bool fill = true);
  154. /**
  155. * Destructor.
  156. *
  157. * NOTE: That the contained bitmap image is not destroyed when the image
  158. * container is destroyed.
  159. */
  160. virtual inline ~CGlyphSliderHorizontal(void) { }
  161. /**
  162. * Get the smallest value that the slider can represent.
  163. *
  164. * @return The smallest value.
  165. */
  166. inline const int getMinimumValue(void) const
  167. {
  168. return m_minimumValue;
  169. }
  170. /**
  171. * Get the largest value that the slider can represent.
  172. *
  173. * @return The largest value.
  174. */
  175. inline const int getMaximumValue(void) const
  176. {
  177. return m_maximumValue;
  178. }
  179. /**
  180. * Get the current value of the slider.
  181. *
  182. * return The current slider value.
  183. */
  184. inline const int getValue(void) const
  185. {
  186. return (int)(m_value >> 16);
  187. }
  188. /**
  189. * Get the value represented by the height of the grip. For sliders,
  190. * this would typically be 1 (so each new grip position is worth 1).
  191. * For scrollbars, this would be the height of the scrolling widget.
  192. *
  193. * @return The page size.
  194. */
  195. inline const nxgl_coord_t getPageSize(void) const
  196. {
  197. return m_pageSize;
  198. }
  199. /**
  200. * Set the smallest value that the slider can represent.
  201. *
  202. * @param value The smallest value.
  203. */
  204. inline void setMinimumValue(const int value)
  205. {
  206. m_minimumValue = value;
  207. m_contentSize = m_maximumValue - m_minimumValue + 1;
  208. //resizeGrip();
  209. };
  210. /**
  211. * Set the largest value that the slider can represent.
  212. *
  213. * @param value The largest value.
  214. */
  215. inline void setMaximumValue(const int value)
  216. {
  217. m_maximumValue = value;
  218. m_contentSize = m_maximumValue - m_minimumValue + 1;
  219. //resizeGrip();
  220. };
  221. /**
  222. * Set the value that of the slider. This will reposition
  223. * and redraw the grip.
  224. *
  225. * @param value The new value.
  226. */
  227. void setValue(const int value);
  228. /**
  229. * Set the value that of the slider. This will reposition and redraw
  230. * the grip. The supplied value should be shifted left 16 places.
  231. * This ensures greater accuracy than the standard setValue() method if
  232. * the slider is being used as a scrollbar.
  233. *
  234. * @param value The new value.
  235. */
  236. void setValueWithBitshift(const int32_t value);
  237. /**
  238. * Set the page size represented by the grip.
  239. *
  240. * @param pageSize The page size.
  241. * @see getPageSize().
  242. */
  243. inline void setPageSize(const nxgl_coord_t pageSize)
  244. {
  245. m_pageSize = pageSize;
  246. //resizeGrip();
  247. };
  248. /**
  249. * Set the thickness of the slider bar
  250. *
  251. * @param thickness The slider bar thickness in pixels
  252. */
  253. inline void setBarThickness(const nxgl_coord_t thickness)
  254. {
  255. m_barThickness = thickness;
  256. redraw();
  257. };
  258. /**
  259. * Process events fired by the grip.
  260. *
  261. * @param e The event details.
  262. */
  263. virtual void handleDragEvent(const CWidgetEventArgs &e);
  264. /**
  265. * Get the smallest value that the slider can move through when
  266. * dragged.
  267. *
  268. * @return The smallest value that the slider can move through when
  269. * dragged.
  270. */
  271. nxgl_coord_t getMinimumStep(void) const;
  272. };
  273. }
  274. #endif // __cplusplus
  275. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CGLYPHSLIDERHORIZONTAL_HXX