cimage.hxx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/cimage.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 all 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_CIMAGE_HXX
  56. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CIMAGE_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. /****************************************************************************
  66. * Pre-Processor Definitions
  67. ****************************************************************************/
  68. /****************************************************************************
  69. * Implementation Classes
  70. ****************************************************************************/
  71. #if defined(__cplusplus)
  72. namespace NXWidgets
  73. {
  74. /**
  75. * Forward references
  76. */
  77. class CWidgetControl;
  78. class IBitmap;
  79. /**
  80. * Simple image widget for present static images in the widget framework.
  81. */
  82. class CImage : public CNxWidget
  83. {
  84. protected:
  85. FAR IBitmap *m_bitmap; /**< Source bitmap image */
  86. struct nxgl_point_s m_origin; /**< Origin for offset image display position */
  87. bool m_highlighted; /**< Image is highlighted */
  88. /**
  89. * Draw the area of this widget that falls within the clipping region.
  90. * Called by the drawContents(port) and by classes that inherit from
  91. * CImage.
  92. *
  93. * @param port The CGraphicsPort to draw to.
  94. * @see redraw()
  95. */
  96. void drawContents(CGraphicsPort *port, bool selected);
  97. /**
  98. * Draw the area of this widget that falls within the clipping region.
  99. * Called by the redraw() function to draw all visible regions.
  100. *
  101. * @param port The CGraphicsPort to draw to.
  102. * @see redraw()
  103. */
  104. virtual void drawContents(CGraphicsPort *port);
  105. /**
  106. * Draw the border of this widget. Called by the indirectly via
  107. * drawBoard(port) and also by classes that inherit from CImage.
  108. *
  109. * @param port The CGraphicsPort to draw to.
  110. * @see redraw()
  111. */
  112. void drawBorder(CGraphicsPort *port, bool selected);
  113. /**
  114. * Draw the border of this widget. Called by the redraw() function to draw
  115. * all visible regions.
  116. *
  117. * @param port The CGraphicsPort to draw to.
  118. * @see redraw()
  119. */
  120. virtual void drawBorder(CGraphicsPort *port);
  121. /**
  122. * Redraws the button.
  123. *
  124. * @param x The x coordinate of the click.
  125. * @param y The y coordinate of the click.
  126. */
  127. virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
  128. /**
  129. * Raises an action.
  130. *
  131. * @param x The x coordinate of the mouse.
  132. * @param y The y coordinate of the mouse.
  133. */
  134. virtual void onPreRelease(nxgl_coord_t x, nxgl_coord_t y);
  135. /**
  136. * Redraws the image.
  137. *
  138. * @param x The x coordinate of the mouse.
  139. * @param y The y coordinate of the mouse.
  140. */
  141. virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y);
  142. /**
  143. * Redraws the image.
  144. *
  145. * @param x The x coordinate of the mouse.
  146. * @param y The y coordinate of the mouse.
  147. */
  148. virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y);
  149. /**
  150. * Copy constructor is protected to prevent usage.
  151. */
  152. inline CImage(const CImage &label) : CNxWidget(label) { };
  153. public:
  154. /**
  155. * Constructor for an image.
  156. *
  157. * @param pWidgetControl The controlling widget for the display
  158. * @param x The x coordinate of the image box, relative to its parent.
  159. * @param y The y coordinate of the image box, relative to its parent.
  160. * @param width The width of the textbox.
  161. * @param height The height of the textbox.
  162. * @param bitmap The source bitmap image.
  163. * @param style The style that the widget should use. If this is not
  164. * specified, the button will use the global default widget
  165. * style.
  166. */
  167. CImage(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
  168. nxgl_coord_t width, nxgl_coord_t height, FAR IBitmap *bitmap,
  169. CWidgetStyle *style = (CWidgetStyle *)NULL);
  170. /**
  171. * Destructor.
  172. *
  173. * NOTE: That the contained bitmap image is not destroyed when the image
  174. * container is destroyed.
  175. */
  176. virtual inline ~CImage() { }
  177. /**
  178. * Get pointer to the bitmap that this image contains.
  179. */
  180. inline FAR IBitmap *getBitmap() const { return m_bitmap; }
  181. /**
  182. * Set the bitmap that this image contains.
  183. */
  184. inline void setBitmap(FAR IBitmap *bitmap) { m_bitmap = bitmap; }
  185. /**
  186. * Insert the dimensions that this widget wants to have into the rect
  187. * passed in as a parameter. All coordinates are relative to the
  188. * widget's parent.
  189. *
  190. * @param rect Reference to a rect to populate with data.
  191. */
  192. void getPreferredDimensions(CRect &rect) const;
  193. /**
  194. * Set the horizontal position of the bitmap. Zero is the left edge
  195. * of the bitmap and values >0 will move the bit map to the right.
  196. * This method is useful for horizontal scrolling a large bitmap
  197. * within a smaller window
  198. */
  199. void setImageLeft(nxgl_coord_t column);
  200. /**
  201. * Align the image at the left of the widget region.
  202. *
  203. * NOTE: The CImage widget does not support any persistent alignment
  204. * attribute (at least not at the moment). As a result, this alignment
  205. * can be lost if the image is changed or if the widget is resized.
  206. */
  207. inline void alignHorizontalLeft(void)
  208. {
  209. setImageLeft(0);
  210. }
  211. /**
  212. * Align the image at the left of the widget region.
  213. *
  214. * NOTE: The CImage widget does not support any persistent alignment
  215. * attribute (at least not at the moment). As a result, this alignment
  216. * can be lost if the image is changed or if the widget is resized.
  217. */
  218. void alignHorizontalCenter(void);
  219. /**
  220. * Align the image at the left of the widget region.
  221. *
  222. * NOTE: The CImage widget does not support any persistent alignment
  223. * attribute (at least not at the moment). As a result, this alignment
  224. * can be lost if the image is changed or if the widget is resized.
  225. */
  226. void alignHorizontalRight(void);
  227. /**
  228. * Set the vertical position of the bitmap. Zero is the top edge
  229. * of the bitmap and values >0 will move the bit map down.
  230. * This method is useful for vertical scrolling a large bitmap
  231. * within a smaller window
  232. */
  233. void setImageTop(nxgl_coord_t row);
  234. /**
  235. * Align the image at the top of the widget region.
  236. *
  237. * NOTE: The CImage widget does not support any persistent alignment
  238. * attribute (at least not at the moment). As a result, this alignment
  239. * can be lost if the image is changed or if the widget is resized.
  240. */
  241. inline void alignVerticalTop(void)
  242. {
  243. setImageTop(0);
  244. }
  245. /**
  246. * Align the image at the middle of the widget region.
  247. *
  248. * NOTE: The CImage widget does not support any persistent alignment
  249. * attribute (at least not at the moment). As a result, this alignment
  250. * can be lost if the image is changed or if the widget is resized.
  251. */
  252. void alignVerticalCenter(void);
  253. /**
  254. * Align the image at the left of the widget region.
  255. *
  256. * NOTE: The CImage widget does not support any persistent alignment
  257. * attribute (at least not at the moment). As a result, this alignment
  258. * can be lost if the image is changed or if the widget is resized.
  259. */
  260. void alignVerticalBottom(void);
  261. /**
  262. * Control the highlight state.
  263. *
  264. * @param highlightOn True(1), the image will be highlighted
  265. */
  266. void highlight(bool highlightOn);
  267. };
  268. }
  269. #endif // __cplusplus
  270. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CIMAGE_HXX