cbgwindow.hxx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/cbgwindow.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_CBGWINDOW_HXX
  21. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CBGWINDOW_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 <nuttx/nx/nx.h>
  30. #include "graphics/nxwidgets/nxconfig.hxx"
  31. #include "graphics/nxwidgets/ccallback.hxx"
  32. #include "graphics/nxwidgets/inxwindow.hxx"
  33. /****************************************************************************
  34. * Pre-Processor Definitions
  35. ****************************************************************************/
  36. /****************************************************************************
  37. * Implementation Classes
  38. ****************************************************************************/
  39. #if defined(__cplusplus)
  40. namespace NXWidgets
  41. {
  42. class INxWindow;
  43. struct SBitmap;
  44. /**
  45. * This class defines operations on a the NX background window.
  46. * There are three instances that represent an NX window from the
  47. * perspective of NXWidgets.
  48. *
  49. * - There is one widget control instance per NX window,
  50. * - One CCallback instance per window,
  51. * - One window instance.
  52. *
  53. * There a various kinds of of window instances, but each inherits
  54. * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
  55. * that describes the common window behavior.
  56. */
  57. class CBgWindow : protected CCallback, public INxWindow
  58. {
  59. private:
  60. NXHANDLE m_hNxServer; /**< Handle to the NX server. */
  61. NXWINDOW m_hWindow; /**< Handle to the NX background window */
  62. CWidgetControl *m_widgetControl; /**< The controlling widget for the window */
  63. public:
  64. /**
  65. * Constructor. Obtains the background window from server and wraps
  66. * the window as CBgWindow. Creates an uninitialized instance of the
  67. * CBgWindow object. The open() method must be called to initialize
  68. * the instance.
  69. *
  70. * The general steps to create any window include:
  71. * 1) Create a dumb CWigetControl instance
  72. * 2) Pass the dumb CWidgetControl instance to the window constructor
  73. * that inherits from INxWindow.
  74. * 3) The window constructor call CWidgetControl methods to "smarten"
  75. * the CWidgetControl instance with window-specific knowledge.
  76. * 4) Call the open() method on the window to display the window.
  77. * 5) After that, the fully smartend CWidgetControl instance can
  78. * be used to generate additional widgets.
  79. * 6) After that, the fully smartened CWidgetControl instance can
  80. * be used to generate additional widgets by passing it to the
  81. * widget constructor
  82. *
  83. * @param hNxServer Handle to the NX server.
  84. * @param widgetControl Controlling widget for this window.
  85. */
  86. CBgWindow(NXHANDLE hNxServer, CWidgetControl *widgetControl);
  87. /**
  88. * Destructor. Returns the background window to the server.
  89. */
  90. virtual ~CBgWindow(void);
  91. /**
  92. * Creates the new window. Window creation is separate from
  93. * object instantiation so that failures can be reported.
  94. *
  95. * @return True if the window was successfully created.
  96. */
  97. bool open(void);
  98. /**
  99. * Each implementation of INxWindow must provide a method to recover
  100. * the contained CWidgetControl instance.
  101. *
  102. * @return The contained CWidgetControl instance
  103. */
  104. CWidgetControl *getWidgetControl(void) const;
  105. /**
  106. * Synchronize the window with the NX server. This function will delay
  107. * until the the NX server has caught up with all of the queued requests.
  108. * When this function returns, the state of the NX server will be the
  109. * same as the state of the application.
  110. */
  111. inline void synchronize(void)
  112. {
  113. CCallback::synchronize(m_hWindow, CCallback::NX_RAWWINDOW);
  114. }
  115. /**
  116. * Request the position and size information of the window. The values
  117. * will be returned asynchronously through the client callback method.
  118. * The GetPosition() method may than be called to obtain the positional
  119. * data as provided by the callback.
  120. *
  121. * @return True on success, false on any failure.
  122. */
  123. bool requestPosition(void);
  124. /**
  125. * Get the position of the window (as reported by the NX callback). NOTE:
  126. * The background window is always positioned at {0,0}
  127. *
  128. * @return The position.
  129. */
  130. bool getPosition(FAR struct nxgl_point_s *pPos);
  131. /**
  132. * Get the size of the window (as reported by the NX callback). NOTE:
  133. * The size of the background window is always the entire display.
  134. *
  135. * @return The size.
  136. */
  137. bool getSize(FAR struct nxgl_size_s *pSize);
  138. /**
  139. * Set the position and size of the window.
  140. *
  141. * @param pPos The new position of the window.
  142. * @return True on success, false on any failure.
  143. */
  144. bool setPosition(FAR const struct nxgl_point_s *pPos);
  145. /**
  146. * Set the size of the selected window. NOTE: The size of the
  147. * background window is always the entire display and cannot be
  148. * changed.
  149. *
  150. * @param pSize The new size of the window.
  151. * @return True on success, false on any failure.
  152. */
  153. bool setSize(FAR const struct nxgl_size_s *pSize);
  154. /**
  155. * Bring the window to the top of the display. NOTE: The background
  156. * window cannot be raised.
  157. *
  158. * @return Always returns false.
  159. */
  160. inline bool raise(void)
  161. {
  162. // The background cannot be raised
  163. return false;
  164. }
  165. /**
  166. * Lower the window to the bottom of the display. NOTE: The background
  167. * window is always at the bottom of the window hierarchy.
  168. *
  169. * @return Always returns false.
  170. */
  171. inline bool lower(void)
  172. {
  173. // The background cannot be lowered
  174. return false;
  175. }
  176. /**
  177. * Return true if the window is currently being displayed
  178. *
  179. * @return Always returns true.
  180. */
  181. inline bool isVisible(void)
  182. {
  183. // The background is always visible (although perhaps obscured)
  184. return true;
  185. }
  186. /**
  187. * Show a hidden window
  188. *
  189. * @return Always returns false.
  190. */
  191. inline bool show(void)
  192. {
  193. // The background is always visible (although perhaps obscured)
  194. return false;
  195. }
  196. /**
  197. * Hide a visible window
  198. *
  199. * @return Always returns false.
  200. */
  201. inline bool hide(void)
  202. {
  203. // The background cannot be hidden
  204. return false;
  205. }
  206. /**
  207. * May be used to either (1) raise a window to the top of the display and
  208. * select modal behavior, or (2) disable modal behavior. NOTE: The
  209. * background cannot be a modal window.
  210. *
  211. * @param enable True: enter modal state; False: leave modal state
  212. * @return Always returns false.
  213. */
  214. inline bool modal(bool enable)
  215. {
  216. // The background cannot a modal window
  217. return false;
  218. }
  219. #ifdef CONFIG_NXTERM_NXKBDIN
  220. /**
  221. * Each window implementation also inherits from CCallback. CCallback,
  222. * by default, forwards NX keyboard input to the various widgets residing
  223. * in the window. But NxTerm is a different usage model; In this case,
  224. * keyboard input needs to be directed to the NxTerm character driver.
  225. * This method can be used to enable (or disable) redirection of NX
  226. * keyboard input from the window widgets to the NxTerm
  227. *
  228. * @param handle. The NXTERM handle. If non-NULL, NX keyboard
  229. * input will be directed to the NxTerm driver using this
  230. * handle; If NULL (the default), NX keyboard input will be
  231. * directed to the widgets within the window.
  232. */
  233. inline void redirectNxTerm(NXTERM handle)
  234. {
  235. setNxTerm(handle);
  236. }
  237. #endif
  238. /**
  239. * Set an individual pixel in the window with the specified color.
  240. *
  241. * @param pPos The location of the pixel to be filled.
  242. * @param color The color to use in the fill.
  243. *
  244. * @return True on success; false on failure.
  245. */
  246. bool setPixel(FAR const struct nxgl_point_s *pPos,
  247. nxgl_mxpixel_t color);
  248. /**
  249. * Fill the specified rectangle in the window with the specified color.
  250. *
  251. * @param pRect The location to be filled.
  252. * @param color The color to use in the fill.
  253. *
  254. * @return True on success; false on failure.
  255. */
  256. bool fill(FAR const struct nxgl_rect_s *pRect,
  257. nxgl_mxpixel_t color);
  258. /**
  259. * Get the raw contents of graphic memory within a rectangular region. NOTE:
  260. * Since raw graphic memory is returned, the returned memory content may be
  261. * the memory of windows above this one and may not necessarily belong to
  262. * this window unless you assure that this is the top window.
  263. *
  264. * @param rect The location to be copied
  265. * @param dest - The describes the destination bitmap to receive the
  266. * graphics data.
  267. */
  268. void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest);
  269. /**
  270. * Fill the specified trapezoidal region in the window with the specified
  271. * color.
  272. *
  273. * @param pClip Clipping rectangle relative to window (may be null).
  274. * @param pTrap The trapezoidal region to be filled.
  275. * @param color The color to use in the fill.
  276. *
  277. * @return True on success; false on failure.
  278. */
  279. bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip,
  280. FAR const struct nxgl_trapezoid_s *pTrap,
  281. nxgl_mxpixel_t color);
  282. /**
  283. * Fill the specified line in the window with the specified color.
  284. *
  285. * @param vector - Describes the line to be drawn
  286. * @param width - The width of the line
  287. * @param color - The color to use to fill the line
  288. * @param caps - Draw a circular cap on the ends of the line to support
  289. * better line joins
  290. *
  291. * @return True on success; false on failure.
  292. */
  293. bool drawLine(FAR struct nxgl_vector_s *vector,
  294. nxgl_coord_t width, nxgl_mxpixel_t color,
  295. enum ELineCaps caps);
  296. /**
  297. * Draw a filled circle at the specified position, size, and color.
  298. *
  299. * @param center The window-relative coordinates of the circle center.
  300. * @param radius The radius of the rectangle in pixels.
  301. * @param color The color of the rectangle.
  302. */
  303. bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius,
  304. nxgl_mxpixel_t color);
  305. /**
  306. * Move a rectangular region within the window.
  307. *
  308. * @param pRect Describes the rectangular region to move.
  309. * @param pOffset The offset to move the region.
  310. *
  311. * @return True on success; false on failure.
  312. */
  313. bool move(FAR const struct nxgl_rect_s *pRect,
  314. FAR const struct nxgl_point_s *pOffset);
  315. /**
  316. * Copy a rectangular region of a larger image into the rectangle in the
  317. * specified window.
  318. *
  319. * @param pDest Describes the rectangular on the display that will receive
  320. * the bitmap.
  321. * @param pSrc The start of the source image.
  322. * @param pOrigin the pOrigin of the upper, left-most corner of the full
  323. * bitmap. Both pDest and pOrigin are in window coordinates, however,
  324. * pOrigin may lie outside of the display.
  325. * @param stride The width of the full source image in bytes.
  326. *
  327. * @return True on success; false on failure.
  328. */
  329. bool bitmap(FAR const struct nxgl_rect_s *pDest,
  330. FAR const void *pSrc,
  331. FAR const struct nxgl_point_s *pOrigin,
  332. unsigned int stride);
  333. };
  334. }
  335. #endif // __cplusplus
  336. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CBGWINDOW_HXX