ProcessGui.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. // ProcessGui.H
  21. //
  22. // History:
  23. // 07/03/97 JMI Started.
  24. //
  25. // 07/03/97 JMI Had not implemented the update func to the feature level
  26. // the comments implied. Implemented.
  27. //
  28. // 07/03/97 JMI Ammended miscomment.
  29. //
  30. // 07/03/97 JMI Added Init() and Kill(). Init() is called by the con-
  31. // structor. Kill() is called by the destructor. The de-
  32. // structor used to call Unprepare() but the problem with
  33. // that was that Unprepare() did more than just deallocate
  34. // the dynamic stuff and that stuff shouldn't have been done
  35. // upon destruction. So now Unprepare() and the destructor
  36. // call Kill() to take care of dynamic items.
  37. //
  38. // 09/01/97 JMI Added special behavior flags, m_flags.
  39. //
  40. //////////////////////////////////////////////////////////////////////////////
  41. //
  42. // ProcessGui process modal or non-modal GUI input and renders the GUI using
  43. // dirty rectangles. The update type is customizable via a callback. There
  44. // is also a default implementation for ease of use.
  45. //
  46. //////////////////////////////////////////////////////////////////////////////
  47. #ifndef PROCESSGUI_H
  48. #define PROCESSGUI_H
  49. //////////////////////////////////////////////////////////////////////////////
  50. // C Headers -- Must be included before RSPiX.h b/c RSPiX utilizes SHMalloc.
  51. //////////////////////////////////////////////////////////////////////////////
  52. ///////////////////////////////////////////////////////////////////////////////
  53. // RSPiX Headers.
  54. // If PATHS_IN_INCLUDES macro is defined, we can utilize relative
  55. // paths to a header file. In this case we generally go off of our
  56. // RSPiX root directory. System.h MUST be included before this macro
  57. // is evaluated. System.h is the header that, based on the current
  58. // platform (or more so in this case on the compiler), defines
  59. // PATHS_IN_INCLUDES. Blue.h includes system.h so you can include that
  60. // instead.
  61. ///////////////////////////////////////////////////////////////////////////////
  62. #include "System.h"
  63. #ifdef PATHS_IN_INCLUDES
  64. #include "ORANGE/GUI/guiItem.h"
  65. #include "ORANGE/DirtRect/DirtRect.h"
  66. #else
  67. #include "guiItem.h"
  68. #include "DirtRect.h"
  69. #endif
  70. //////////////////////////////////////////////////////////////////////////////
  71. // Macros.
  72. //////////////////////////////////////////////////////////////////////////////
  73. //////////////////////////////////////////////////////////////////////////////
  74. // Protos.
  75. //////////////////////////////////////////////////////////////////////////////
  76. //////////////////////////////////////////////////////////////////////////////
  77. // Typedefs.
  78. //////////////////////////////////////////////////////////////////////////////
  79. class RProcessGui
  80. {
  81. ///////////////////////////////////////////////////////////////////////////
  82. // Typedefs, enums, etc.
  83. ///////////////////////////////////////////////////////////////////////////
  84. public:
  85. typedef long (*UpdateFunc)( // Returns a non-zero ID to abort or zero
  86. // to continue.
  87. RInputEvent* pie); // Out: Next input event to process.
  88. typedef enum
  89. {
  90. NoCleanScreen = 0x0001 // Don't clean the dest buffer when exiting.
  91. } Flags;
  92. ///////////////////////////////////////////////////////////////////////////
  93. // Con/Destruction.
  94. ///////////////////////////////////////////////////////////////////////////
  95. public:
  96. RProcessGui()
  97. {
  98. Init();
  99. }
  100. ~RProcessGui()
  101. {
  102. Kill();
  103. }
  104. ///////////////////////////////////////////////////////////////////////////
  105. // Methods.
  106. ///////////////////////////////////////////////////////////////////////////
  107. public:
  108. // Prepare to handle a GUI.
  109. // This must be called to setup components before DoModeless() is called.
  110. // (DoModal() does this automatically).
  111. short Prepare( // Returns 0 on success.
  112. RGuiItem* pgui, // In: GUI to be processed.
  113. RGuiItem* pguiOk = NULL, // In: If not NULL, specifies GUI
  114. // activated by ENTER key.
  115. RGuiItem* pguiCancel = NULL); // In: If not NULL, specifies GUI
  116. // activated by ESCAPE key.
  117. // This should be called to clean up components when no more DoModeless()
  118. // calls are to be made on the current GUI.
  119. // (DoModal() does this automatically).
  120. void Unprepare(void); // Returns nothing.
  121. // Setup GUI to notify this class of presses.
  122. void SetGuiToNotify( // Returns nothing.
  123. RGuiItem* pgui); // In: GUI item to setup to notify this class
  124. // of presses.
  125. // Set all unclaimed GUIs' callbacks to go through this class.
  126. void SetGuisToNotify( // Returns nothing.
  127. RGuiItem* pguiRoot); // In: All unclaimed child GUIs'
  128. // callbacks are directed through
  129. // ProcessGui.
  130. // Call this to process a GUI modally. Once this function is called,
  131. // it will not return until a GUI pressed callback occurs on a GUI
  132. // with an ID other than 0 or the update callback, m_fnUpdate, if any,
  133. // returns non-zero.
  134. long DoModal( // Returns ID of pressed GUI that terminated
  135. // modal loop or value returned from
  136. // m_fnUpdate, if any.
  137. RGuiItem* pgui, // In: GUI to be processed or NULL.
  138. RGuiItem* pguiOk = NULL, // In: If not NULL, specifies GUI
  139. // activated by ENTER key.
  140. RGuiItem* pguiCancel = NULL, // In: If not NULL, specifies GUI
  141. // activated by ESCAPE key.
  142. RImage* pimDst = NULL); // Where to draw dialog and rspBlit from.
  143. // If this is NULL, the system buffer is
  144. // used.
  145. // rspBlit is used to update this to the
  146. // screen image unless pimDst is the screen
  147. // image.
  148. // Call this to process a GUI modelessly. This function processes the
  149. // GUI for only one iteration allowing the caller continuous control.
  150. long DoModeless( // Returns ID of pressed GUI or value.
  151. RGuiItem* pgui, // In: GUI to be processed or NULL.
  152. RInputEvent* pie, // In: Input event to process.
  153. RImage* pimDst = NULL); // Where to draw dialog and rspBlit from.
  154. // If this is NULL, the system buffer is
  155. // used.
  156. // rspBlit is used to update this to the
  157. // screen image unless pimDst is the screen
  158. // image.
  159. ///////////////////////////////////////////////////////////////////////////
  160. // Querries.
  161. ///////////////////////////////////////////////////////////////////////////
  162. public:
  163. ///////////////////////////////////////////////////////////////////////////
  164. // Internal functions.
  165. ///////////////////////////////////////////////////////////////////////////
  166. protected:
  167. // Initialize instantiable data members.
  168. void Init(void); // Returns nothing.
  169. // Deallocate any instantiable dynamic members.
  170. void Kill(void); // Returns nothing.
  171. ///////////////////////////////////////////////////////////////////////////
  172. // Internal static functions.
  173. ///////////////////////////////////////////////////////////////////////////
  174. protected:
  175. // Callback for pressed GUIs.
  176. static void PressedCall( // Returns nothing.
  177. RGuiItem* pgui); // In: Pressed GUI.
  178. ///////////////////////////////////////////////////////////////////////////
  179. // Instantiable data.
  180. ///////////////////////////////////////////////////////////////////////////
  181. public:
  182. RDirtyRects m_drl; // List of dirtied areas.
  183. RImage m_imEraser; // Erase image.
  184. RImage* m_pimLastDst; // Last composite buffer (used
  185. // in Unprepare() to clean up display).
  186. RGuiItem* m_pguiOk; // GUI activated by ENTER.
  187. RGuiItem* m_pguiCancel; // GUI activated by ESCAPE.
  188. UpdateFunc m_fnUpdate; // Callback to do updates, if not using
  189. // default handling.
  190. short m_sFlags; // See Flags.
  191. ///////////////////////////////////////////////////////////////////////////
  192. // Static data.
  193. ///////////////////////////////////////////////////////////////////////////
  194. public:
  195. // ID of last item pressed.
  196. static long ms_lPressedId;
  197. };
  198. #endif // PROCESSGUI_H
  199. //////////////////////////////////////////////////////////////////////////////
  200. // EOF
  201. //////////////////////////////////////////////////////////////////////////////