cstickyimage.hxx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/cstickyimage.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. #ifndef __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CSTICKIMAGE_HXX
  21. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CSTICKIMAGE_HXX
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <stdint.h>
  27. #include <stdbool.h>
  28. #include <nuttx/nx/nxglib.h>
  29. #include "graphics/nxwidgets/cimage.hxx"
  30. #include "graphics/nxwidgets/cwidgetstyle.hxx"
  31. /****************************************************************************
  32. * Pre-Processor Definitions
  33. ****************************************************************************/
  34. /****************************************************************************
  35. * Implementation Classes
  36. ****************************************************************************/
  37. #if defined(__cplusplus)
  38. namespace NXWidgets
  39. {
  40. class CWidgetControl;
  41. /**
  42. * CImage that sticks in the selected selected state when clicked.
  43. */
  44. class CStickyImage : public CImage
  45. {
  46. protected:
  47. bool m_stuckSelection; /**< True if the image is stuck in the selected */
  48. /**
  49. * Draw the area of this widget that falls within the clipping region.
  50. * Called by the redraw() function to draw all visible regions.
  51. *
  52. * @param port The CGraphicsPort to draw to.
  53. * @see redraw()
  54. */
  55. virtual void drawContents(CGraphicsPort *port);
  56. /**
  57. * Draw the area of this widget that falls within the clipping region.
  58. * Called by the redraw() function to draw all visible regions.
  59. *
  60. * @param port The CGraphicsPort to draw to.
  61. * @see redraw()
  62. */
  63. virtual void drawBorder(CGraphicsPort *port);
  64. /**
  65. * Don't redraw on click events. The image state is completely controlled
  66. * by the m_stuckSelection state.
  67. *
  68. * @param x The x coordinate of the click.
  69. * @param y The y coordinate of the click.
  70. */
  71. virtual void onClick(nxgl_coord_t x, nxgl_coord_t y) {}
  72. /**
  73. * Don't redraw on release events. The image state is completely controlled
  74. * by the m_stuckSelection state.
  75. *
  76. * @param x The x coordinate of the mouse.
  77. * @param y The y coordinate of the mouse.
  78. */
  79. virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y) { }
  80. /**
  81. * Don't redraw on release events. The image state is completely controlled
  82. * by the m_stuckSelection state.
  83. *
  84. * @param x The x coordinate of the mouse.
  85. * @param y The y coordinate of the mouse.
  86. */
  87. virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y) { }
  88. /**
  89. * Copy constructor is protected to prevent usage.
  90. */
  91. inline CStickyImage(const CStickyImage &image) : CImage(image) { }
  92. public:
  93. /**
  94. * Constructor for an image.
  95. *
  96. * @param pWidgetControl The controlling widget for the display
  97. * @param x The x coordinate of the image box, relative to its parent.
  98. * @param y The y coordinate of the image box, relative to its parent.
  99. * @param width The width of the image box.
  100. * @param height The height of the image box.
  101. * @param bitmap The source bitmap image.
  102. * @param style The style that the widget should use. If this is not
  103. * specified, the image will use the global default widget
  104. * style.
  105. */
  106. CStickyImage(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
  107. nxgl_coord_t width, nxgl_coord_t height, FAR IBitmap *bitmap,
  108. CWidgetStyle *style = (CWidgetStyle *)NULL);
  109. /**
  110. * Destructor.
  111. */
  112. virtual inline ~CStickyImage(void) { }
  113. /**
  114. * Sets the image's stuck selection state.
  115. *
  116. * @param selection The new stuck selection state.
  117. */
  118. void setStuckSelection(bool selection);
  119. /**
  120. * Toggles the images stuck selection state.
  121. */
  122. inline void toggleStuckSelection(void)
  123. {
  124. setStuckSelection(!m_stuckSelection);
  125. }
  126. /**
  127. * Returns the stuck selection state.
  128. *
  129. * @return True if the image is in the stuck selection state.
  130. */
  131. inline const bool isStuckSelection(void) const
  132. {
  133. return m_stuckSelection;
  134. }
  135. };
  136. }
  137. #endif // __cplusplus
  138. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CSTICKIMAGE_HXX