EditWindow.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: EditWindow.h /////////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: RTS3
  34. //
  35. // File name: EditWindow.h
  36. //
  37. // Created: Colin Day, July 2001
  38. //
  39. // Desc: Main edit window for the GUI editing tool
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. #pragma once
  44. #ifndef __EDITWINDOW_H_
  45. #define __EDITWINDOW_H_
  46. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  47. #include <stdlib.h>
  48. #include <windows.h>
  49. // USER INCLUDES //////////////////////////////////////////////////////////////
  50. #include "GUIEditColor.h"
  51. #include "Lib/BaseType.h"
  52. #include "GameClient/Image.h"
  53. #include "GameClient/GameWindow.h"
  54. #include "WW3D2/AssetMgr.h"
  55. #include "WW3D2/Render2D.h"
  56. // FORWARD REFERENCES /////////////////////////////////////////////////////////
  57. ///////////////////////////////////////////////////////////////////////////////
  58. // TYPE DEFINES ///////////////////////////////////////////////////////////////
  59. ///////////////////////////////////////////////////////////////////////////////
  60. // EditWindow -----------------------------------------------------------------
  61. /** The edit window singleton definition, this is where we create and
  62. * interact with GUI controls for this tool */
  63. //-----------------------------------------------------------------------------
  64. class EditWindow
  65. {
  66. public:
  67. EditWindow( void );
  68. ~EditWindow( void );
  69. /// initialize the edit window singleton
  70. void init( UnsignedInt clientWidth, UnsignedInt clientHeight );
  71. void shutdown( void ); ///< free all data
  72. void draw( void ); ///< draw the edit window
  73. void updatePulse( void ); ///< pulse message from timer
  74. HWND getWindowHandle( void ); ///< get window handle
  75. void setSize( ICoord2D *size ); ///< set width and height for edit window
  76. void getSize( ICoord2D *size ); ///< get width and height for edit window
  77. RGBColorReal getBackgroundColor( void ); ///< return the background color
  78. void setBackgroundColor( RGBColorReal color ); ///< set background color
  79. void setDragMoveOrigin( ICoord2D *pos ); ///< for drag moving
  80. void setDragMoveDest( ICoord2D *pos ); ///< for drag moving
  81. ICoord2D getDragMoveOrigin( void ); ///< for keybord moving
  82. ICoord2D getDragMoveDest( void ); ///< for keyboard moving
  83. void notifyWindowDeleted( GameWindow *window ); ///< window has been deleted
  84. /// mouse event has occurred, button up/down, move etc.
  85. void mouseEvent( UnsignedInt windowsMessage, WPARAM wParam, LPARAM lParam );
  86. void getPopupMenuClickPos( ICoord2D *pos ); ///< get popup menu click loc
  87. void openPopupMenu( Int x, Int y ); ///< open floating popup right click menu
  88. // **************************************************************************
  89. /// draw a line on the display in screen coordinates
  90. void drawLine( Int startX, Int startY, Int endX, Int endY,
  91. Real lineWidth, UnsignedInt lineColor );
  92. /// draw a rect border on the display in pixel coordinates with the specified color
  93. void drawOpenRect( Int startX, Int startY, Int width, Int height,
  94. Real lineWidth, UnsignedInt lineColor );
  95. /// draw a filled rect on the display in pixel coords with the specified color
  96. void drawFillRect( Int startX, Int startY, Int width, Int height,
  97. UnsignedInt color );
  98. /// draw an image fit within the screen coordinates
  99. void drawImage( const Image *image, Int startX, Int startY,
  100. Int endX, Int endY, Color color = 0xFFFFFFFF );
  101. /// image clipping support
  102. void setClipRegion( IRegion2D *region ) {m_clipRegion = *region; m_isClippedEnabled = TRUE;}
  103. Bool isClippingEnabled( void ) { return m_isClippedEnabled; }
  104. void enableClipping( Bool onoff ) { m_isClippedEnabled = onoff; }
  105. protected:
  106. void registerEditWindowClass( void ); ///< register class with OS
  107. /// callback from windows, NOTE that it's static and has no this pointer
  108. static LRESULT CALLBACK editProc( HWND hWnd, UINT message,
  109. WPARAM wParam, LPARAM lParam );
  110. void drawGrid( void ); ///< draw the grid
  111. void drawSeeThruOutlines( GameWindow *windowList, Color c );
  112. void drawHiddenOutlines( GameWindow *windowList, Color c );
  113. void drawUIFeedback( void ); ///< draw UI visual feedback
  114. /// if mouse is close to selected window allow resize
  115. void handleResizeAvailable( Int mouseX, Int mouseY );
  116. //
  117. // these methods check to see if the mouse is close enough to the
  118. // given geometry region (usually for resizing controls)
  119. //
  120. Bool inCornerTolerance( ICoord2D *dest, ICoord2D *source, Int tolerance );
  121. Bool inLineTolerance( ICoord2D *dest, ICoord2D *lineStart, ICoord2D *lineEnd,
  122. Int tolerance );
  123. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  124. static Bool m_classRegistered; ///< TRUE when we've register with OS
  125. static char *m_className; ///< name for windows class
  126. ICoord2D m_size; ///< width and height of edit window
  127. UnsignedByte m_bitDepth; ///< bit depth for edit window
  128. HWND m_editWindowHWnd; ///< edit window handle
  129. Int m_pulse; ///< for visual feedback that looks cool!
  130. RGBColorReal m_backgroundColor; ///< the background color
  131. Bool m_w3dInitialized; ///< TRUE once W3D is up
  132. WW3DAssetManager *m_assetManager; ///< asset manager for WW3D
  133. Render2DClass *m_2DRender; ///< our 2D renderer
  134. ICoord2D m_popupMenuClickPos; ///< position where popup menu was created at
  135. GameWindow *m_pickedWindow; ///< picked window from mouse click editing
  136. ICoord2D m_dragMoveOrigin; ///< mouse click position to start drag move
  137. ICoord2D m_dragMoveDest; ///< destination for drag move
  138. Bool m_dragSelecting; ///< TRUE when drawing a selection box
  139. IRegion2D m_selectRegion; ///< region for selection box
  140. Bool m_resizingWindow; ///< TRUE when drag resizing a window
  141. GameWindow *m_windowToResize; ///< the window to resize
  142. ICoord2D m_resizeOrigin; ///< mouse clicked down here to drag resize
  143. ICoord2D m_resizeDest; ///< mouse pos when dragging around to resize
  144. IRegion2D m_clipRegion; ///< the clipping region for images
  145. Bool m_isClippedEnabled; ///<used by 2D drawing operations to define clip re
  146. }; // end EditWindow
  147. ///////////////////////////////////////////////////////////////////////////////
  148. // INLINING ///////////////////////////////////////////////////////////////////
  149. ///////////////////////////////////////////////////////////////////////////////
  150. inline HWND EditWindow::getWindowHandle( void ) { return m_editWindowHWnd; }
  151. inline void EditWindow::getSize( ICoord2D *size ) { *size = m_size; }
  152. inline void EditWindow::getPopupMenuClickPos( ICoord2D *pos ) { *pos = m_popupMenuClickPos; }
  153. inline void EditWindow::setDragMoveDest( ICoord2D *pos ) { if( pos ) m_dragMoveDest = *pos; }
  154. inline void EditWindow::setDragMoveOrigin( ICoord2D *pos ) { if( pos ) m_dragMoveOrigin = *pos; }
  155. inline ICoord2D EditWindow::getDragMoveDest( void ) { return m_dragMoveDest; }
  156. inline ICoord2D EditWindow::getDragMoveOrigin( void ) { return m_dragMoveOrigin; }
  157. ///////////////////////////////////////////////////////////////////////////////
  158. // EXTERNALS //////////////////////////////////////////////////////////////////
  159. ///////////////////////////////////////////////////////////////////////////////
  160. extern EditWindow *TheEditWindow; ///< edit window singleton extern
  161. #endif // __EDITWINDOW_H_