DrawButton.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. ** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ******************************************************************************
  21. * *
  22. * Project Name : Autorun *
  23. * *
  24. * File Name : AUTORUN.CPP *
  25. * *
  26. * Programmers: Maria del Mar McCready Legg *
  27. * *
  28. * Start Date : September 5, 1997 *
  29. * *
  30. * Last Update : October 2, 2000 [MML] *
  31. * *
  32. *----------------------------------------------------------------------------*
  33. * Functions: *
  34. * DrawButton::DrawButton *
  35. * DrawButton::Is_Mouse_In_Region *
  36. * DrawButton::Return_Bitmap *
  37. * DrawButton::Return_Area *
  38. * DrawButton::Set_Stretched_Width *
  39. * DrawButton::Set_Stretched_Height *
  40. *----------------------------------------------------------------------------*/
  41. #define STRICT
  42. #include <windows.h>
  43. #include <windowsx.h>
  44. #include "autorun.h"
  45. #include "drawbutton.h"
  46. #include "locale_api.h"
  47. #include "wnd_file.h"
  48. #include "leanAndMeanAutorun.h"
  49. #ifndef LEAN_AND_MEAN
  50. ///////GAMEENGINE HEADERS////////////
  51. #include "Common/UnicodeString.h"
  52. #include "Common/SubsystemInterface.h"
  53. #include "GameClient/GameText.h"
  54. #endif
  55. //*****************************************************************************
  56. // DrawButton::DrawButton -- Constructor for custom "Button" type.
  57. //
  58. // This custom button is drawn by the dialog, and uses the WM_MOUSEMOVE,
  59. // WM_LBUTTONUP, and WM_LBUTTONDOWN to trigger actions.
  60. //
  61. // INPUT: int id -- button id handle
  62. // int x -- x position
  63. // int y -- y position
  64. // int w -- width of button
  65. // int h -- height of button
  66. // char *normal -- name of normal button bitmap
  67. // char *pressed -- name of pressed button bitmap
  68. // char *focus -- name of focus button bitmap
  69. //
  70. // OUTPUT: none.
  71. //
  72. // WARNINGS: No keyboard/mouse/paint handling built in. Do manually.
  73. //
  74. // HISTORY:
  75. // 07/15/1996 MML : Created.
  76. //=============================================================================
  77. DrawButton::DrawButton ( int id, RECT button_rect, char *normal, char *focus, char *pressed, const char * string, TTFontClass *fontptr )
  78. {
  79. Id = id;
  80. //--------------------------------------------------------------------------
  81. // Set default rectangle settings.
  82. //--------------------------------------------------------------------------
  83. rect.left = button_rect.left;
  84. rect.top = button_rect.top;
  85. rect.right = button_rect.left + button_rect.right;
  86. rect.bottom = button_rect.top + button_rect.bottom;
  87. MyRect.X = button_rect.left;
  88. MyRect.Y = button_rect.top;
  89. MyRect.Width = rect.right - rect.left;
  90. MyRect.Height = rect.bottom - rect.top;
  91. TextRect.X = button_rect.left;
  92. TextRect.Y = button_rect.top;
  93. TextRect.Width = rect.right - rect.left;
  94. TextRect.Height = rect.bottom - rect.top;
  95. StretchedWidth = rect.right - rect.left;
  96. StretchedHeight = rect.bottom - rect.top;
  97. //--------------------------------------------------------------------------
  98. // Set the string variables.
  99. //--------------------------------------------------------------------------
  100. memset( String, '\0', MAX_PATH );
  101. // if ( string != NULL ) {
  102. // wcscpy( String, Locale_GetString( string_num, String ));
  103. #ifdef LEAN_AND_MEAN
  104. #else
  105. UnicodeString tempString = TheGameText->fetch(string);
  106. wcscpy(String, tempString.str());
  107. #endif
  108. // }
  109. //--------------------------------------------------------------------------
  110. // Set the font pointer.
  111. //--------------------------------------------------------------------------
  112. MyFontPtr = NULL;
  113. if ( fontptr != NULL ) {
  114. MyFontPtr = fontptr;
  115. }
  116. //--------------------------------------------------------------------------
  117. // Set Button Backgrounds.
  118. //--------------------------------------------------------------------------
  119. _tcscpy( NormalBitmap, normal );
  120. _tcscpy( PressedBitmap, pressed );
  121. _tcscpy( FocusBitmap, focus );
  122. if( NormalBitmap[0] != '\0' ) {
  123. UseBitmaps = true; // determines how to draw button.
  124. }
  125. //--------------------------------------------------------------------------
  126. // Start in normal mode.
  127. //--------------------------------------------------------------------------
  128. ButtonState = NORMAL_STATE;
  129. Msg( __LINE__, TEXT(__FILE__), TEXT(" rect = [%d,%d,%d,%d]"), rect.left, rect.top, rect.right, rect.bottom );
  130. Msg( __LINE__, TEXT(__FILE__), TEXT(" MyRect = [%d,%d,%d,%d]"), MyRect.X, MyRect.Y, MyRect.Width, MyRect.Height );
  131. }
  132. DrawButton::DrawButton ( int id, RECT button_rect, char *normal, char *focus, char *pressed, const wchar_t *string, TTFontClass *fontptr )
  133. {
  134. Id = id;
  135. //--------------------------------------------------------------------------
  136. // Set default rectangle settings.
  137. //--------------------------------------------------------------------------
  138. rect.left = button_rect.left;
  139. rect.top = button_rect.top;
  140. rect.right = button_rect.left + button_rect.right;
  141. rect.bottom = button_rect.top + button_rect.bottom;
  142. MyRect.X = button_rect.left;
  143. MyRect.Y = button_rect.top;
  144. MyRect.Width = rect.right - rect.left;
  145. MyRect.Height = rect.bottom - rect.top;
  146. TextRect.X = button_rect.left;
  147. TextRect.Y = button_rect.top;
  148. TextRect.Width = rect.right - rect.left;
  149. TextRect.Height = rect.bottom - rect.top;
  150. StretchedWidth = rect.right - rect.left;
  151. StretchedHeight = rect.bottom - rect.top;
  152. //--------------------------------------------------------------------------
  153. // Set the string variables.
  154. //--------------------------------------------------------------------------
  155. memset( String, '\0', MAX_PATH );
  156. if ( string != NULL ) {
  157. wcscpy( String, string );
  158. }
  159. //--------------------------------------------------------------------------
  160. // Set the font pointer.
  161. //--------------------------------------------------------------------------
  162. MyFontPtr = NULL;
  163. if ( fontptr != NULL ) {
  164. MyFontPtr = fontptr;
  165. }
  166. //--------------------------------------------------------------------------
  167. // Set Button Backgrounds.
  168. //--------------------------------------------------------------------------
  169. _tcscpy( NormalBitmap, normal );
  170. _tcscpy( PressedBitmap, pressed );
  171. _tcscpy( FocusBitmap, focus );
  172. if( NormalBitmap[0] != '\0' ) {
  173. UseBitmaps = true; // determines how to draw button.
  174. }
  175. //--------------------------------------------------------------------------
  176. // Start in normal mode.
  177. //--------------------------------------------------------------------------
  178. ButtonState = NORMAL_STATE;
  179. Msg( __LINE__, TEXT(__FILE__), TEXT(" rect = [%d,%d,%d,%d]"), rect.left, rect.top, rect.right, rect.bottom );
  180. Msg( __LINE__, TEXT(__FILE__), TEXT(" MyRect = [%d,%d,%d,%d]"), MyRect.X, MyRect.Y, MyRect.Width, MyRect.Height );
  181. }
  182. //*****************************************************************************
  183. // DrawButton::Draw_Text -- Check if mouse values are in button area.
  184. //
  185. // INPUT: HDC hDC -- DC to paint to.
  186. //
  187. // OUTPUT: none.
  188. //
  189. // WARNINGS:
  190. //
  191. // HISTORY:
  192. // 01/18/2002 MML : Created.
  193. //=============================================================================
  194. void DrawButton::Draw_Text ( HDC hDC )
  195. {
  196. RECT outline_rect;
  197. Rect rect;
  198. if( hDC == NULL ) {
  199. return;
  200. }
  201. Return_Area( &outline_rect );
  202. Return_Text_Area( &rect );
  203. /*
  204. ** This function was combining the pixel color with the background,
  205. ** so it never looked correct.
  206. */
  207. // SetTextColor( hDC, RGB( 0, 240, 0 ));
  208. // DrawFocusRect( hDC, &dst_rect );
  209. if ( Get_State() == DrawButton::PRESSED_STATE ) {
  210. MyFontPtr->Print(
  211. hDC,
  212. String,
  213. rect,
  214. TEXT_PRESSED_COLOR,
  215. TEXT_PRESSED_SHADOW_COLOR,
  216. TPF_BUTTON,
  217. TPF_SHADOW );
  218. } else if ( Get_State() == DrawButton::FOCUS_STATE ) {
  219. MyFontPtr->Print(
  220. hDC,
  221. String,
  222. rect,
  223. TEXT_FOCUSED_COLOR,
  224. TEXT_FOCUSED_SHADOW_COLOR,
  225. TPF_BUTTON,
  226. TPF_SHADOW );
  227. } else {
  228. MyFontPtr->Print(
  229. hDC,
  230. String,
  231. rect,
  232. TEXT_NORMAL_COLOR,
  233. TEXT_NORMAL_SHADOW_COLOR,
  234. TPF_BUTTON,
  235. TPF_SHADOW );
  236. }
  237. }
  238. //*****************************************************************************
  239. // DrawButton::Is_Mouse_In_Region -- Check if mouse values are in button area.
  240. //
  241. // INPUT: int mouse_x -- mouse x position
  242. // int mouse_y -- mouse y position
  243. //
  244. // OUTPUT: bool -- true of false.
  245. //
  246. // WARNINGS: No keyboard/mouse/paint handling built in. Do manually.
  247. // Note: width is shortened below to accomodate actual bitmap area.
  248. //
  249. // HISTORY:
  250. // 07/15/1996 MML : Created.
  251. //=============================================================================
  252. bool DrawButton::Is_Mouse_In_Region ( int mouse_x, int mouse_y )
  253. {
  254. if ( mouse_x < 0 || mouse_y < 0 ) {
  255. return( false );
  256. }
  257. if (( mouse_x >= rect.left ) &&
  258. ( mouse_y >= rect.top ) &&
  259. ( mouse_x <= rect.left + StretchedWidth ) &&
  260. ( mouse_y <= rect.top + StretchedHeight )) {
  261. return ( TRUE );
  262. }
  263. return ( FALSE );
  264. }
  265. //*****************************************************************************
  266. // DrawButton::Return_Bitmap
  267. //
  268. // Return name of correct bitmap based on state of button.
  269. //
  270. // INPUT: none.
  271. //
  272. // OUTPUT: char *bitmap -- name of bitmap file.
  273. //
  274. // WARNINGS: No keyboard/mouse/paint handling built in. Do manually.
  275. //
  276. // HISTORY:
  277. // 07/15/1996 MML : Created.
  278. //=============================================================================
  279. char *DrawButton::Return_Bitmap ( void )
  280. {
  281. if ( ButtonState == PRESSED_STATE ) {
  282. return ( PressedBitmap );
  283. } else if ( ButtonState == FOCUS_STATE ) {
  284. return ( FocusBitmap );
  285. } else {
  286. return ( NormalBitmap );
  287. }
  288. }
  289. //*****************************************************************************
  290. // DrawButton::Return_Area -- Return x, y and width and height of button.
  291. //
  292. // INPUT: RECT area -- holds the x,y,width,height information.
  293. //
  294. // OUTPUT: none.
  295. //
  296. // WARNINGS: No keyboard/mouse/paint handling built in. Do manually.
  297. //
  298. // HISTORY:
  299. // 07/15/1996 MML : Created.
  300. //=============================================================================
  301. void DrawButton::Return_Area ( RECT *area )
  302. {
  303. area->left = rect.left;
  304. area->top = rect.top;
  305. area->right = rect.left + StretchedWidth;
  306. area->bottom = rect.top + StretchedHeight;
  307. }
  308. void DrawButton::Return_Area ( Rect *area )
  309. {
  310. area->X = MyRect.X;
  311. area->Y = MyRect.Y;
  312. area->Width = MyRect.Width;
  313. area->Height = MyRect.Height;
  314. }
  315. void DrawButton::Return_Text_Area ( Rect *area )
  316. {
  317. area->X = TextRect.X;
  318. area->Y = TextRect.Y;
  319. area->Width = TextRect.Width;
  320. area->Height = TextRect.Height;
  321. }
  322. //*****************************************************************************
  323. // DrawButton::Set_Stretched_Width -- Set draw width of button.
  324. //
  325. // INPUT: int value -- destination width size.
  326. //
  327. //OUTPUT: none.
  328. //
  329. // WARNINGS: none.
  330. //
  331. // HISTORY: 08/12/1996 MML : Created.
  332. //=============================================================================
  333. int DrawButton::Set_Stretched_Width ( int value )
  334. {
  335. int nWidth = StretchedWidth;
  336. StretchedWidth = value;
  337. return ( nWidth );
  338. }
  339. //*****************************************************************************
  340. // DrawButton::Set_Stretched_Height -- Set draw height of button.
  341. //
  342. // INPUT: int value -- destination height size.
  343. //
  344. // OUTPUT: none.
  345. //
  346. // WARNINGS: none.
  347. //
  348. // HISTORY: 08/12/1996 MML : Created.
  349. //=============================================================================
  350. int DrawButton::Set_Stretched_Height ( int value )
  351. {
  352. int nHeight = StretchedHeight;
  353. StretchedHeight = value;
  354. return( nHeight );
  355. }