TexEdit.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. // TexEdit.h
  19. //
  20. // History:
  21. // 10/03/99 JMI Started.
  22. //
  23. // 10/06/99 JMI Now DoModal() accepts two lights to use.
  24. //
  25. // 10/07/99 JMI Replaced m_fAlt and m_fAzi with a transform so rotations
  26. // can always be relative to the current orientation.
  27. //
  28. //////////////////////////////////////////////////////////////////////////////
  29. //
  30. // Implements a cheezy texture editor.
  31. //
  32. //////////////////////////////////////////////////////////////////////////////
  33. #if !defined(CTEXEDIT_H)
  34. #define CTEXEDIT_H
  35. //------------------------------------------------------------------------------
  36. // Includes.
  37. //------------------------------------------------------------------------------
  38. #include "scene.h"
  39. //------------------------------------------------------------------------------
  40. // Macros.
  41. //------------------------------------------------------------------------------
  42. #define DECL_BTN_CALL(Name) \
  43. void Name(RGuiItem* pgui); \
  44. static void Name##_Static(RGuiItem* pgui) \
  45. { \
  46. ASSERT(pgui->m_ulUserInstance); \
  47. CTexEdit* pte = (CTexEdit*)pgui->m_ulUserInstance; \
  48. pte->Name(pgui); \
  49. }
  50. #define DECL_EVENT_CALL(Name) \
  51. void Name(RGuiItem* pgui, RInputEvent* pie); \
  52. static void Name##_Static(RGuiItem* pgui, RInputEvent* pie) \
  53. { \
  54. ASSERT(pgui->m_ulUserInstance); \
  55. CTexEdit* pte = (CTexEdit*)pgui->m_ulUserInstance; \
  56. pte->Name(pgui, pie); \
  57. }
  58. #define DECL_SB_CALL(Name) \
  59. void Name(RScrollBar* psb); \
  60. static void Name##_Static(RScrollBar* psb) \
  61. { \
  62. ASSERT(psb->m_ulUserInstance); \
  63. CTexEdit* pte = (CTexEdit*)psb->m_ulUserInstance; \
  64. pte->Name(psb); \
  65. }
  66. //------------------------------------------------------------------------------
  67. // Typedefs.
  68. //------------------------------------------------------------------------------
  69. // References ////////////////////////////////////////////////////////////////
  70. class CAnim3D;
  71. // Classes ///////////////////////////////////////////////////////////////////
  72. class CTexEdit
  73. {
  74. //------------------------------------------------------------------------------
  75. // Typedefs.
  76. //------------------------------------------------------------------------------
  77. public:
  78. typedef enum
  79. {
  80. Trans,
  81. Scale,
  82. Rot,
  83. Paint
  84. } Manip;
  85. typedef enum
  86. {
  87. MaxCmds = 10
  88. } Macros;
  89. typedef struct
  90. {
  91. long lTriIndex; // Triangle affected.
  92. U8 u8Color; // Color applied.
  93. U8 u8PrevColor; // Prev color.
  94. } Cmd;
  95. //------------------------------------------------------------------------------
  96. // Data.
  97. //------------------------------------------------------------------------------
  98. public:
  99. RGuiItem* m_pguiRoot; // Main dialog frame.
  100. RGuiItem* m_pguiAnim; // Anim frame.
  101. RGuiItem* m_pguiCurColor; // Current color frame.
  102. RGuiItem* m_pguiPal; // Color palette frame.
  103. CScene m_scene; // Scene for rendering.
  104. Manip m_manip; // Current manipulation type.
  105. bool m_bDragging; // true if in drag manipulation.
  106. short m_sCursorResetX; // Used by ProcessManip() to process drags.
  107. short m_sCursorResetY; // Used by ProcessManip() to process drags.
  108. float m_fScale; // Scaling.
  109. RTransform m_transRot; // Rotation.
  110. float m_fX; // Translation.
  111. float m_fY; // Translation.
  112. bool m_bQuit; // true when done.
  113. U8 m_u8Color; // Current color.
  114. long m_lTriIndex; // Index of tri selected or < 0, if none.
  115. RTexture m_texWork; // Work texture.
  116. RTexture* m_ptexSrc; // The real thing.
  117. ChanTexture* m_ptexchanSrc; // Animation being edited.
  118. bool m_bModified; // true if texture has been modified since last
  119. // synch (revert or apply).
  120. RString m_strFileName; // Filename to save textures as.
  121. bool m_bSpotLight; // true for spotlight; false for ambient.
  122. short m_sBrightness; // Brightness for sprite.
  123. //------------------------------------------------------------------------------
  124. // Construction.
  125. //------------------------------------------------------------------------------
  126. public:
  127. //////////////////////////////////////////////////////////////////////////////
  128. // Default constructor.
  129. //////////////////////////////////////////////////////////////////////////////
  130. CTexEdit(void)
  131. ;
  132. //////////////////////////////////////////////////////////////////////////////
  133. // Destructor.
  134. //////////////////////////////////////////////////////////////////////////////
  135. ~CTexEdit(void)
  136. ;
  137. //------------------------------------------------------------------------------
  138. // Methods.
  139. //------------------------------------------------------------------------------
  140. public:
  141. //////////////////////////////////////////////////////////////////////////////
  142. // Edit the texture of the specified 3D animation in a modal dialog.
  143. //////////////////////////////////////////////////////////////////////////////
  144. void
  145. DoModal(
  146. CAnim3D* panim, // In: 3D animation to paint on.
  147. RAlpha* pltAmbient, // In: Ambient light.
  148. RAlpha* pltSpot, // In: Spot light.
  149. const RString& strFile) // In: Filename to save modified texture as.
  150. ;
  151. //////////////////////////////////////////////////////////////////////////////
  152. // Render the 3D animation at the specified time.
  153. //////////////////////////////////////////////////////////////////////////////
  154. void
  155. DoOutput(
  156. CSprite3* psprite, // In: 3D data to render.
  157. RSop* psopView, // In: View space SOP.
  158. RTransform& trans, // In: Transformation.
  159. RAlpha* palphaLight, // In: Light.
  160. RImage* pimDst, // In: Destination for result.
  161. short sOffsetX, // In: X offset.
  162. short sOffsetY, // In: Y offset.
  163. RRect& rcClip) // In: Dst clip rect.
  164. ;
  165. ////////////////////////////////////////////////////////////////////////////////
  166. // Processes drags and keys into transform stuff.
  167. ////////////////////////////////////////////////////////////////////////////////
  168. void
  169. ProcessManip(
  170. bool bButtonDown, // In: true if mouse button down.
  171. RInputEvent* pie, // In: Current input event.
  172. CSprite3* psprite, // In: 3D data to process.
  173. RSop* psopView) // In: View space SOP.
  174. ;
  175. //------------------------------------------------------------------------------
  176. // Querries.
  177. //------------------------------------------------------------------------------
  178. public:
  179. //////////////////////////////////////////////////////////////////////////////
  180. //////////////////////////////////////////////////////////////////////////////
  181. //------------------------------------------------------------------------------
  182. // Internal functions.
  183. //------------------------------------------------------------------------------
  184. protected:
  185. //////////////////////////////////////////////////////////////////////////////
  186. // Apply work colors to real thing.
  187. //////////////////////////////////////////////////////////////////////////////
  188. void
  189. Apply(void)
  190. ;
  191. //////////////////////////////////////////////////////////////////////////////
  192. // Revert work colors to real thing.
  193. //////////////////////////////////////////////////////////////////////////////
  194. void
  195. Revert(void)
  196. ;
  197. //////////////////////////////////////////////////////////////////////////////
  198. // Save work colors to real thing.
  199. //////////////////////////////////////////////////////////////////////////////
  200. void
  201. Save(void)
  202. ;
  203. //////////////////////////////////////////////////////////////////////////////
  204. // Set the current manipulation type.
  205. //////////////////////////////////////////////////////////////////////////////
  206. void
  207. SetManip(
  208. Manip manip) // In: New manipulation type.
  209. ;
  210. //////////////////////////////////////////////////////////////////////////////
  211. // Set the current palette color.
  212. //////////////////////////////////////////////////////////////////////////////
  213. void
  214. SetColor(
  215. U8 u8Color) // In: New color index.
  216. ;
  217. //////////////////////////////////////////////////////////////////////////////
  218. // Set the specified button to notify.
  219. //////////////////////////////////////////////////////////////////////////////
  220. void
  221. SetToNotify(
  222. long lBtnId, // In: ID of btn whose callback will be set.
  223. RGuiItem::BtnUpCall pfn) // In: Function to notify.
  224. ;
  225. //////////////////////////////////////////////////////////////////////////////
  226. // Set the specified gui to notify.
  227. //////////////////////////////////////////////////////////////////////////////
  228. void
  229. SetToNotify(
  230. long lId, // In: ID of gui whose callback will be set.
  231. RGuiItem::InputEventCall pfn) // In: Function to notify.
  232. ;
  233. //////////////////////////////////////////////////////////////////////////////
  234. // Set the specified scrollbar to notify.
  235. //////////////////////////////////////////////////////////////////////////////
  236. void
  237. SetToNotify(
  238. long lId, // In: ID of scrollbar whose callback will be set.
  239. RScrollBar::UpdatePosCall pfn) // In: Function to notify.
  240. ;
  241. //////////////////////////////////////////////////////////////////////////////
  242. // Reset transformation members.
  243. //////////////////////////////////////////////////////////////////////////////
  244. void
  245. ResetTransformation(void)
  246. {
  247. m_fScale = 0.5f;
  248. m_transRot.Make1();
  249. m_fX = 0;
  250. m_fY = 0;
  251. }
  252. //////////////////////////////////////////////////////////////////////////////
  253. // Set the status text field to that specified.
  254. //////////////////////////////////////////////////////////////////////////////
  255. void
  256. SetStatusText(
  257. const char* pszFrmt, // In: Format specifier ala sprintf.
  258. ...) // In: Arguments as specified by format.
  259. ;
  260. //////////////////////////////////////////////////////////////////////////////
  261. // Compose tarnsformations in the specified transform. Init transform before
  262. // calling as necessary.
  263. //////////////////////////////////////////////////////////////////////////////
  264. void
  265. ComposeTransform(
  266. RTransform& trans) // In: Transform to compose in.
  267. ;
  268. //------------------------------------------------------------------------------
  269. // Callbacks.
  270. //------------------------------------------------------------------------------
  271. protected:
  272. DECL_BTN_CALL(QuitCall)
  273. DECL_BTN_CALL(ManipCall)
  274. DECL_EVENT_CALL(ColorCall)
  275. DECL_BTN_CALL(ApplyCall)
  276. DECL_BTN_CALL(SaveCall)
  277. DECL_BTN_CALL(RevertCall)
  278. DECL_BTN_CALL(SpotCall)
  279. DECL_SB_CALL(BrightnessCall)
  280. DECL_BTN_CALL(AdjustCall)
  281. DECL_EVENT_CALL(AnimCall)
  282. };
  283. #endif // CTEXEDIT_H
  284. //////////////////////////////////////////////////////////////////////////////
  285. // EOF
  286. //////////////////////////////////////////////////////////////////////////////