Frame.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. //
  20. // Frame.H
  21. //
  22. // History:
  23. // 01/13/97 JMI Started.
  24. //
  25. // 08/22/97 JMI Now uses rspGeneralLock/Unlock() to make sure the
  26. // destination buffer to Draw() is properly locked, if
  27. // necessary.
  28. //
  29. //////////////////////////////////////////////////////////////////////////////
  30. //
  31. // This is a very simple class designed to be used as a container. It does
  32. // not allocate any memory for its image and it does not draw its image. It
  33. // just draws its children. It's a way of making many child items relative
  34. // to one particular item that has no 'mass'.
  35. // Very useful and efficient for grouping large areas of object with
  36. // practically no memory overhead.
  37. //
  38. //////////////////////////////////////////////////////////////////////////////
  39. #ifndef FRAME_H
  40. #define FRAME_H
  41. //////////////////////////////////////////////////////////////////////////////
  42. // Please see the CPP file for an explanation of this API.
  43. //////////////////////////////////////////////////////////////////////////////
  44. //////////////////////////////////////////////////////////////////////////////
  45. // Headers.
  46. //////////////////////////////////////////////////////////////////////////////
  47. #include "System.h"
  48. // If PATHS_IN_INCLUDES macro is defined, we can utilized relative
  49. // paths to a header file. In this case we generally go off of our
  50. // RSPiX root directory. System.h MUST be included before this macro
  51. // is evaluated. System.h is the header that, based on the current
  52. // platform (or more so in this case on the compiler), defines
  53. // PATHS_IN_INCLUDES. Blue.h includes system.h so you can include that
  54. // instead.
  55. #ifdef PATHS_IN_INCLUDES
  56. #include "ORANGE/GUI/guiItem.h"
  57. #else
  58. #include "GuiItem.h"
  59. #endif // PATHS_IN_INCLUDES
  60. //////////////////////////////////////////////////////////////////////////////
  61. // Macros.
  62. //////////////////////////////////////////////////////////////////////////////
  63. //////////////////////////////////////////////////////////////////////////////
  64. // Typedefs.
  65. //////////////////////////////////////////////////////////////////////////////
  66. //////////////////////////////////////////////////////////////////////////////
  67. class RFrame : public RGuiItem
  68. {
  69. public: // Construction/Destruction.
  70. // Default constructor.
  71. RFrame(void)
  72. {
  73. // No border.
  74. m_sBorderThickness = 0;
  75. // Don't show focus.
  76. m_sShowFocus = FALSE;
  77. }
  78. // Destructor.
  79. ~RFrame(void)
  80. {
  81. }
  82. //////////////////////////////////////////////////////////////////////////////
  83. public: // Methods.
  84. ////////////////////////////////////////////////////////////////////////
  85. // Methods.
  86. ////////////////////////////////////////////////////////////////////////
  87. // Compose item.
  88. virtual // If you override this, call this base if possible.
  89. void Compose( // Returns nothing.
  90. RImage* pim = NULL) // Dest image, uses m_im if NULL.
  91. {
  92. // Set hot area.
  93. SetHotArea();
  94. // Set event area.
  95. SetEventArea();
  96. }
  97. // Creates a displayable Gui. Call SetFont and SetText before calling
  98. // this as it calls Compose.
  99. virtual // If you override this, call this base if possible.
  100. short Create( // Returns 0 on success.
  101. short sX, // X position relative to "parent" item.
  102. short sY, // Y position relative to "parent" item.
  103. short sW, // Width.
  104. short sH, // Height.
  105. short sDepth) // Color depth.
  106. {
  107. m_sX = sX;
  108. m_sY = sY;
  109. m_im.m_sWidth = sW;
  110. m_im.m_sHeight = sH;
  111. Compose();
  112. // Nothing to allocate.
  113. return 0;
  114. }
  115. // Draw this item and all its subitems into the provided RImage.
  116. virtual // If you override this, call this base if possible.
  117. short Draw( // Returns 0 on success.
  118. RImage* pimDst, // Destination image.
  119. short sDstX = 0, // X position in destination.
  120. short sDstY = 0, // Y position in destination.
  121. short sSrcX = 0, // X position in source.
  122. short sSrcY = 0, // Y position in source.
  123. short sW = 0, // Amount to draw.
  124. short sH = 0, // Amount to draw.
  125. RRect* prc = NULL) // Clip to.
  126. {
  127. short sRes = 0; // Assume success.
  128. // If visible . . .
  129. if (m_sVisible != FALSE)
  130. {
  131. sDstX += m_sX;
  132. sDstY += m_sY;
  133. // An original clippage should be passed to all these children.
  134. // Set up default clip rect.
  135. RRect rc;
  136. // Get client.
  137. GetClient(&rc.sX, &rc.sY, &rc.sW, &rc.sH);
  138. // Affect by draw position.
  139. rc.sX += sDstX;
  140. rc.sY += sDstY;
  141. // Clip to destination.
  142. RRect rcDst;
  143. // If no rect . . .
  144. if (prc == NULL)
  145. {
  146. // Provide one using destination image.
  147. rcDst.sX = 0;
  148. rcDst.sY = 0;
  149. rcDst.sW = pimDst->m_sWidth;
  150. rcDst.sH = pimDst->m_sHeight;
  151. prc = &rcDst;
  152. }
  153. // Clip default clipper to provided or destination.
  154. rc.ClipTo(prc);
  155. // Draw back to front!
  156. // Note that we lock this here and don't unlock it until after we
  157. // have processed our children. Although and because Draw()
  158. // is recursive, this is the most efficient way to do this lock.
  159. // Since rspGeneralLock() (or, at least, the functions it calls)
  160. // do not do anything if the buffer is already locked, there is
  161. // little efficiency lost in calling this multiple times but plenty
  162. // gained by not locking/unlocking and locking/unlocking again and
  163. // again (the exception being the flip page).
  164. rspGeneralLock(pimDst);
  165. RGuiItem* pgui = m_listguiChildren.GetTail();
  166. while (sRes == 0 && pgui != NULL)
  167. {
  168. // Draw subitem and all its subitems.
  169. sRes = pgui->Draw(pimDst, sDstX, sDstY, 0, 0, 0, 0, &rc);
  170. pgui = m_listguiChildren.GetPrev();
  171. }
  172. // If this item has the focus . . .
  173. if (ms_pguiFocus == this)
  174. {
  175. // Draw focus feedback, if this item shows the focus.
  176. DrawFocus(pimDst, sDstX, sDstY, &rc);
  177. }
  178. // Unlock the destination buffer.
  179. rspGeneralUnlock(pimDst);
  180. }
  181. return sRes;
  182. }
  183. ////////////////////////////////////////////////////////////////////////
  184. // Querries.
  185. ////////////////////////////////////////////////////////////////////////
  186. //////////////////////////////////////////////////////////////////////////////
  187. public: // Static
  188. //////////////////////////////////////////////////////////////////////////////
  189. public: // Querries.
  190. //////////////////////////////////////////////////////////////////////////////
  191. protected: // Internal functions.
  192. //////////////////////////////////////////////////////////////////////////////
  193. public: // Member variables.
  194. protected: // Internal typedefs.
  195. protected: // Protected member variables.
  196. };
  197. #endif // FRAME_H
  198. //////////////////////////////////////////////////////////////////////////////
  199. // EOF
  200. //////////////////////////////////////////////////////////////////////////////