ControlBarResizer.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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: ControlBarResizer.cpp /////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // created: Sep 2002
  34. //
  35. // Filename: ControlBarResizer.cpp
  36. //
  37. // author: Chris Huybregts
  38. //
  39. // purpose: We want a "squished" control bar, this is the methods that will do it
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. //-----------------------------------------------------------------------------
  44. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  45. //-----------------------------------------------------------------------------
  46. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  47. //-----------------------------------------------------------------------------
  48. // USER INCLUDES //////////////////////////////////////////////////////////////
  49. //-----------------------------------------------------------------------------
  50. #include "GameClient/ControlBar.h"
  51. #include "GameClient/ControlBarResizer.h"
  52. #include "GameClient/GameWindow.h"
  53. #include "GameClient/GameWindowManager.h"
  54. #include "GameClient/Display.h"
  55. //-----------------------------------------------------------------------------
  56. // DEFINES ////////////////////////////////////////////////////////////////////
  57. //-----------------------------------------------------------------------------
  58. const FieldParse ControlBarResizer::m_controlBarResizerParseTable[] =
  59. {
  60. { "AltPosition", INI::parseICoord2D, NULL, offsetof( ResizerWindow, m_altPos ) },
  61. { "AltSize", INI::parseICoord2D, NULL, offsetof( ResizerWindow, m_altSize ) },
  62. { NULL, NULL, NULL, 0 } // keep this last
  63. };
  64. //-----------------------------------------------------------------------------
  65. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  66. //-----------------------------------------------------------------------------
  67. ResizerWindow::ResizerWindow(void)
  68. {
  69. m_defaultPos.x = m_defaultPos.y = 0;
  70. m_defaultSize.x = m_defaultSize.y = 0;
  71. m_altSize.x = m_altSize.y = 0;
  72. m_altPos.x = m_altPos.y = 0;
  73. }
  74. ControlBarResizer::ControlBarResizer( void )
  75. {
  76. }
  77. ControlBarResizer::~ControlBarResizer( void )
  78. {
  79. ResizerWindowList::iterator it = m_resizerWindowsList.begin();
  80. while (it != m_resizerWindowsList.end())
  81. {
  82. ResizerWindow *rWin = *it;
  83. if( !rWin )
  84. {
  85. it = m_resizerWindowsList.erase(it);
  86. continue;
  87. }
  88. delete rWin;
  89. it = m_resizerWindowsList.erase(it);
  90. }
  91. m_resizerWindowsList.clear();
  92. }
  93. void ControlBarResizer::init( void )
  94. {
  95. INI ini;
  96. // Read from INI all the ControlBarSchemes
  97. ini.load( AsciiString( "Data\\INI\\ControlBarResizer.ini" ), INI_LOAD_OVERWRITE, NULL );
  98. }
  99. ResizerWindow *ControlBarResizer::findResizerWindow( AsciiString name )
  100. {
  101. ResizerWindowList::iterator it = m_resizerWindowsList.begin();
  102. while (it != m_resizerWindowsList.end())
  103. {
  104. ResizerWindow *rWin = *it;
  105. if( !rWin )
  106. {
  107. DEBUG_ASSERTCRASH(FALSE,("There's no resizerWindow in ControlBarResizer::findResizerWindow"));
  108. it++;
  109. continue;
  110. }
  111. // find the scheme that best matches our resolution
  112. if(rWin->m_name.compare(name) == 0)
  113. {
  114. return rWin;
  115. }
  116. it ++;
  117. }
  118. return NULL;
  119. }
  120. ResizerWindow *ControlBarResizer::newResizerWindow( AsciiString name )
  121. {
  122. ResizerWindow *newRwin = NEW ResizerWindow;
  123. if(!newRwin)
  124. return NULL;
  125. newRwin->m_name = name;
  126. GameWindow *win = NULL;
  127. win = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey(name));
  128. if( !win )
  129. {
  130. DEBUG_ASSERTCRASH(win,("ControlBarResizer::newResizerWindow could not find window %s Are you sure that window is loaded yet?", name.str()) );
  131. delete newRwin;
  132. return NULL;
  133. }
  134. win->winGetPosition(&newRwin->m_defaultPos.x,&newRwin->m_defaultPos.y);
  135. win->winGetSize(&newRwin->m_defaultSize.x,&newRwin->m_defaultSize.y);
  136. m_resizerWindowsList.push_back(newRwin);
  137. return newRwin;
  138. }
  139. void ControlBarResizer::sizeWindowsDefault( void )
  140. {
  141. ResizerWindowList::iterator it = m_resizerWindowsList.begin();
  142. GameWindow *win = NULL;
  143. while (it != m_resizerWindowsList.end())
  144. {
  145. ResizerWindow *rWin = *it;
  146. if( !rWin )
  147. {
  148. DEBUG_ASSERTCRASH(FALSE,("There's no resizerWindow in ControlBarResizer::sizeWindowsDefault"));
  149. it++;
  150. continue;
  151. }
  152. win = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey(rWin->m_name));
  153. if(!win)
  154. {
  155. it++;
  156. continue;
  157. }
  158. win->winSetPosition(rWin->m_defaultPos.x, rWin->m_defaultPos.y);
  159. win->winSetSize(rWin->m_defaultSize.x, rWin->m_defaultSize.y);
  160. DEBUG_LOG(("sizeWindowsDefault:%s pos X:%d pos Y: %d size X:%d sizeY: %d",rWin->m_name.str(),rWin->m_defaultPos.x, rWin->m_defaultPos.y,rWin->m_defaultSize.x, rWin->m_defaultSize.y ));
  161. it ++;
  162. }
  163. }
  164. void ControlBarResizer::sizeWindowsAlt( void )
  165. {
  166. ResizerWindowList::iterator it = m_resizerWindowsList.begin();
  167. GameWindow *win = NULL;
  168. Real x = (Real)TheDisplay->getWidth() / 800;
  169. Real y = (Real)TheDisplay->getHeight() / 600;
  170. while (it != m_resizerWindowsList.end())
  171. {
  172. ResizerWindow *rWin = *it;
  173. if( !rWin )
  174. {
  175. DEBUG_ASSERTCRASH(FALSE,("There's no resizerWindow in ControlBarResizer::sizeWindowsDefault"));
  176. it++;
  177. continue;
  178. }
  179. win = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey(rWin->m_name));
  180. if(!win)
  181. {
  182. it++;
  183. continue;
  184. }
  185. win->winSetPosition(rWin->m_altPos.x * x, rWin->m_altPos.y * y);
  186. if(rWin->m_altSize.x >0 || rWin->m_altSize.y > 0)
  187. win->winSetSize(rWin->m_altSize.x *x, rWin->m_altSize.y *y);
  188. DEBUG_LOG(("sizeWindowsAlt:%s pos X:%d pos Y: %d size X:%d sizeY: %d",rWin->m_name.str(), rWin->m_altPos.x*x, rWin->m_altPos.y*y,rWin->m_altSize.x*x, rWin->m_altSize.y *y));
  189. it ++;
  190. }
  191. }
  192. void INI::parseControlBarResizerDefinition( INI* ini )
  193. {
  194. // AsciiString name;
  195. // ResizerWindow *rWin = NULL;
  196. //
  197. // // read the name
  198. // const char* c = ini->getNextToken();
  199. // name.set( c );
  200. //
  201. //// ControlBarResizer *resizer = TheControlBar->getControlBarResizer();
  202. // if( !resizer )
  203. // {
  204. // //We don't need it if we're in the builder... which doesn't have this.
  205. // return;
  206. // }
  207. // rWin = resizer->findResizerWindow( name );
  208. // if( rWin == NULL )
  209. // {
  210. //
  211. // // image not found, create a new one
  212. // rWin = resizer->newResizerWindow(name);
  213. // DEBUG_ASSERTCRASH( rWin, ("parseControlBarResizerDefinition: unable to allocate ResizerWindow for '%s'\n",
  214. // name.str()) );
  215. //
  216. // } // end if
  217. //
  218. // // parse the ini definition
  219. // ini->initFromINI( rWin, resizer->getFieldParse());
  220. //
  221. } // end parseMappedImage
  222. //-----------------------------------------------------------------------------
  223. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  224. //-----------------------------------------------------------------------------