Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

676 lines
20 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "backgroundpanel.h"
  9. #include <vgui/IVGui.h>
  10. #include <vgui/IScheme.h>
  11. #include <vgui/ISurface.h>
  12. #include <vgui_controls/Label.h>
  13. #include <vgui/ILocalize.h>
  14. #include "vgui_controls/BuildGroup.h"
  15. #include "vgui_controls/BitmapImagePanel.h"
  16. using namespace vgui;
  17. #define DEBUG_WINDOW_RESIZING 0
  18. #define DEBUG_WINDOW_REPOSITIONING 0
  19. //-----------------------------------------------------------------------------
  20. const int NumSegments = 7;
  21. static int coord[NumSegments+1] = {
  22. 0,
  23. 1,
  24. 2,
  25. 3,
  26. 4,
  27. 6,
  28. 9,
  29. 10
  30. };
  31. //-----------------------------------------------------------------------------
  32. void DrawRoundedBackground( Color bgColor, int wide, int tall )
  33. {
  34. int x1, x2, y1, y2;
  35. surface()->DrawSetColor(bgColor);
  36. surface()->DrawSetTextColor(bgColor);
  37. int i;
  38. // top-left corner --------------------------------------------------------
  39. int xDir = 1;
  40. int yDir = -1;
  41. int xIndex = 0;
  42. int yIndex = NumSegments - 1;
  43. int xMult = 1;
  44. int yMult = 1;
  45. int x = 0;
  46. int y = 0;
  47. for ( i=0; i<NumSegments; ++i )
  48. {
  49. x1 = MIN( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  50. x2 = MAX( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  51. y1 = MAX( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  52. y2 = y + coord[NumSegments];
  53. surface()->DrawFilledRect( x1, y1, x2, y2 );
  54. xIndex += xDir;
  55. yIndex += yDir;
  56. }
  57. // top-right corner -------------------------------------------------------
  58. xDir = 1;
  59. yDir = -1;
  60. xIndex = 0;
  61. yIndex = NumSegments - 1;
  62. x = wide;
  63. y = 0;
  64. xMult = -1;
  65. yMult = 1;
  66. for ( i=0; i<NumSegments; ++i )
  67. {
  68. x1 = MIN( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  69. x2 = MAX( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  70. y1 = MAX( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  71. y2 = y + coord[NumSegments];
  72. surface()->DrawFilledRect( x1, y1, x2, y2 );
  73. xIndex += xDir;
  74. yIndex += yDir;
  75. }
  76. // bottom-right corner ----------------------------------------------------
  77. xDir = 1;
  78. yDir = -1;
  79. xIndex = 0;
  80. yIndex = NumSegments - 1;
  81. x = wide;
  82. y = tall;
  83. xMult = -1;
  84. yMult = -1;
  85. for ( i=0; i<NumSegments; ++i )
  86. {
  87. x1 = MIN( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  88. x2 = MAX( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  89. y1 = y - coord[NumSegments];
  90. y2 = MIN( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  91. surface()->DrawFilledRect( x1, y1, x2, y2 );
  92. xIndex += xDir;
  93. yIndex += yDir;
  94. }
  95. // bottom-left corner -----------------------------------------------------
  96. xDir = 1;
  97. yDir = -1;
  98. xIndex = 0;
  99. yIndex = NumSegments - 1;
  100. x = 0;
  101. y = tall;
  102. xMult = 1;
  103. yMult = -1;
  104. for ( i=0; i<NumSegments; ++i )
  105. {
  106. x1 = MIN( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  107. x2 = MAX( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  108. y1 = y - coord[NumSegments];
  109. y2 = MIN( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  110. surface()->DrawFilledRect( x1, y1, x2, y2 );
  111. xIndex += xDir;
  112. yIndex += yDir;
  113. }
  114. // paint between top left and bottom left ---------------------------------
  115. x1 = 0;
  116. x2 = coord[NumSegments];
  117. y1 = coord[NumSegments];
  118. y2 = tall - coord[NumSegments];
  119. surface()->DrawFilledRect( x1, y1, x2, y2 );
  120. // paint between left and right -------------------------------------------
  121. x1 = coord[NumSegments];
  122. x2 = wide - coord[NumSegments];
  123. y1 = 0;
  124. y2 = tall;
  125. surface()->DrawFilledRect( x1, y1, x2, y2 );
  126. // paint between top right and bottom right -------------------------------
  127. x1 = wide - coord[NumSegments];
  128. x2 = wide;
  129. y1 = coord[NumSegments];
  130. y2 = tall - coord[NumSegments];
  131. surface()->DrawFilledRect( x1, y1, x2, y2 );
  132. }
  133. //-----------------------------------------------------------------------------
  134. void DrawRoundedBorder( Color borderColor, int wide, int tall )
  135. {
  136. int x1, x2, y1, y2;
  137. surface()->DrawSetColor(borderColor);
  138. surface()->DrawSetTextColor(borderColor);
  139. int i;
  140. // top-left corner --------------------------------------------------------
  141. int xDir = 1;
  142. int yDir = -1;
  143. int xIndex = 0;
  144. int yIndex = NumSegments - 1;
  145. int xMult = 1;
  146. int yMult = 1;
  147. int x = 0;
  148. int y = 0;
  149. for ( i=0; i<NumSegments; ++i )
  150. {
  151. x1 = MIN( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  152. x2 = MAX( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  153. y1 = MIN( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  154. y2 = MAX( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  155. surface()->DrawFilledRect( x1, y1, x2, y2 );
  156. xIndex += xDir;
  157. yIndex += yDir;
  158. }
  159. // top-right corner -------------------------------------------------------
  160. xDir = 1;
  161. yDir = -1;
  162. xIndex = 0;
  163. yIndex = NumSegments - 1;
  164. x = wide;
  165. y = 0;
  166. xMult = -1;
  167. yMult = 1;
  168. for ( i=0; i<NumSegments; ++i )
  169. {
  170. x1 = MIN( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  171. x2 = MAX( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  172. y1 = MIN( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  173. y2 = MAX( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  174. surface()->DrawFilledRect( x1, y1, x2, y2 );
  175. xIndex += xDir;
  176. yIndex += yDir;
  177. }
  178. // bottom-right corner ----------------------------------------------------
  179. xDir = 1;
  180. yDir = -1;
  181. xIndex = 0;
  182. yIndex = NumSegments - 1;
  183. x = wide;
  184. y = tall;
  185. xMult = -1;
  186. yMult = -1;
  187. for ( i=0; i<NumSegments; ++i )
  188. {
  189. x1 = MIN( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  190. x2 = MAX( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  191. y1 = MIN( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  192. y2 = MAX( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  193. surface()->DrawFilledRect( x1, y1, x2, y2 );
  194. xIndex += xDir;
  195. yIndex += yDir;
  196. }
  197. // bottom-left corner -----------------------------------------------------
  198. xDir = 1;
  199. yDir = -1;
  200. xIndex = 0;
  201. yIndex = NumSegments - 1;
  202. x = 0;
  203. y = tall;
  204. xMult = 1;
  205. yMult = -1;
  206. for ( i=0; i<NumSegments; ++i )
  207. {
  208. x1 = MIN( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  209. x2 = MAX( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  210. y1 = MIN( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  211. y2 = MAX( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  212. surface()->DrawFilledRect( x1, y1, x2, y2 );
  213. xIndex += xDir;
  214. yIndex += yDir;
  215. }
  216. // top --------------------------------------------------------------------
  217. x1 = coord[NumSegments];
  218. x2 = wide - coord[NumSegments];
  219. y1 = 0;
  220. y2 = 1;
  221. surface()->DrawFilledRect( x1, y1, x2, y2 );
  222. // bottom -----------------------------------------------------------------
  223. x1 = coord[NumSegments];
  224. x2 = wide - coord[NumSegments];
  225. y1 = tall - 1;
  226. y2 = tall;
  227. surface()->DrawFilledRect( x1, y1, x2, y2 );
  228. // left -------------------------------------------------------------------
  229. x1 = 0;
  230. x2 = 1;
  231. y1 = coord[NumSegments];
  232. y2 = tall - coord[NumSegments];
  233. surface()->DrawFilledRect( x1, y1, x2, y2 );
  234. // right ------------------------------------------------------------------
  235. x1 = wide - 1;
  236. x2 = wide;
  237. y1 = coord[NumSegments];
  238. y2 = tall - coord[NumSegments];
  239. surface()->DrawFilledRect( x1, y1, x2, y2 );
  240. }
  241. //-----------------------------------------------------------------------------
  242. class CaptionLabel : public Label
  243. {
  244. public:
  245. CaptionLabel(Panel *parent, const char *panelName, const char *text) : Label(parent, panelName, text)
  246. {
  247. }
  248. virtual void ApplySchemeSettings( vgui::IScheme *pScheme )
  249. {
  250. Label::ApplySchemeSettings( pScheme );
  251. SetFont( pScheme->GetFont( "MenuTitle", IsProportional() ) );
  252. }
  253. };
  254. //-----------------------------------------------------------------------------
  255. // Purpose: transform a normalized value into one that is scaled based the minimum
  256. // of the horizontal and vertical ratios
  257. //-----------------------------------------------------------------------------
  258. static int GetAlternateProportionalValueFromNormal(int normalizedValue)
  259. {
  260. int wide, tall;
  261. GetHudSize( wide, tall );
  262. int proH, proW;
  263. surface()->GetProportionalBase( proW, proH );
  264. double scaleH = (double)tall / (double)proH;
  265. double scaleW = (double)wide / (double)proW;
  266. double scale = (scaleW < scaleH) ? scaleW : scaleH;
  267. return (int)( normalizedValue * scale );
  268. }
  269. //-----------------------------------------------------------------------------
  270. // Purpose: transform a standard scaled value into one that is scaled based the minimum
  271. // of the horizontal and vertical ratios
  272. //-----------------------------------------------------------------------------
  273. int GetAlternateProportionalValueFromScaled( HScheme hScheme, int scaledValue)
  274. {
  275. return GetAlternateProportionalValueFromNormal( scheme()->GetProportionalNormalizedValueEx( hScheme, scaledValue ) );
  276. }
  277. //-----------------------------------------------------------------------------
  278. // Purpose: moves and resizes a single control
  279. //-----------------------------------------------------------------------------
  280. static void RepositionControl( Panel *pPanel )
  281. {
  282. int x, y, w, h;
  283. pPanel->GetBounds(x, y, w, h);
  284. #if DEBUG_WINDOW_RESIZING
  285. int x1, y1, w1, h1;
  286. pPanel->GetBounds(x1, y1, w1, h1);
  287. int x2, y2, w2, h2;
  288. x2 = scheme()->GetProportionalNormalizedValueEx( pPanel->GetScheme(), x1 );
  289. y2 = scheme()->GetProportionalNormalizedValueEx( pPanel->GetScheme(), y1 );
  290. w2 = scheme()->GetProportionalNormalizedValueEx( pPanel->GetScheme(), w1 );
  291. h2 = scheme()->GetProportionalNormalizedValueEx( pPanel->GetScheme(), h1 );
  292. #endif
  293. x = GetAlternateProportionalValueFromScaled( pPanel->GetScheme(), x );
  294. y = GetAlternateProportionalValueFromScaled( pPanel->GetScheme(), y );
  295. w = GetAlternateProportionalValueFromScaled( pPanel->GetScheme(), w );
  296. h = GetAlternateProportionalValueFromScaled( pPanel->GetScheme(), h );
  297. pPanel->SetBounds(x, y, w, h);
  298. #if DEBUG_WINDOW_RESIZING
  299. DevMsg( "Resizing '%s' from (%d,%d) %dx%d to (%d,%d) %dx%d -- initially was (%d,%d) %dx%d\n",
  300. pPanel->GetName(), x1, y1, w1, h1, x, y, w, h, x2, y2, w2, h2 );
  301. #endif
  302. }
  303. //-----------------------------------------------------------------------------
  304. // Purpose: Sets colors etc for background image panels
  305. //-----------------------------------------------------------------------------
  306. void ApplyBackgroundSchemeSettings( EditablePanel *pWindow, vgui::IScheme *pScheme )
  307. {
  308. Color bgColor = Color( 255, 255, 255, pScheme->GetColor( "BgColor", Color( 0, 0, 0, 0 ) )[3] );
  309. Color fgColor = pScheme->GetColor( "FgColor", Color( 0, 0, 0, 0 ) );
  310. if ( !pWindow )
  311. return;
  312. CBitmapImagePanel *pBitmapPanel;
  313. // corners --------------------------------------------
  314. pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "TopLeftPanel" ));
  315. if ( pBitmapPanel )
  316. {
  317. pBitmapPanel->setImageColor( bgColor );
  318. }
  319. pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "TopRightPanel" ));
  320. if ( pBitmapPanel )
  321. {
  322. pBitmapPanel->setImageColor( bgColor );
  323. }
  324. pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "BottomLeftPanel" ));
  325. if ( pBitmapPanel )
  326. {
  327. pBitmapPanel->setImageColor( bgColor );
  328. }
  329. pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "BottomRightPanel" ));
  330. if ( pBitmapPanel )
  331. {
  332. pBitmapPanel->setImageColor( bgColor );
  333. }
  334. // background -----------------------------------------
  335. pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "TopSolid" ));
  336. if ( pBitmapPanel )
  337. {
  338. pBitmapPanel->setImageColor( bgColor );
  339. }
  340. pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "UpperMiddleSolid" ));
  341. if ( pBitmapPanel )
  342. {
  343. pBitmapPanel->setImageColor( bgColor );
  344. }
  345. pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "LowerMiddleSolid" ));
  346. if ( pBitmapPanel )
  347. {
  348. pBitmapPanel->setImageColor( bgColor );
  349. }
  350. pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "BottomSolid" ));
  351. if ( pBitmapPanel )
  352. {
  353. pBitmapPanel->setImageColor( bgColor );
  354. }
  355. // Logo -----------------------------------------------
  356. pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "ExclamationPanel" ));
  357. if ( pBitmapPanel )
  358. {
  359. pBitmapPanel->setImageColor( fgColor );
  360. }
  361. }
  362. //-----------------------------------------------------------------------------
  363. // Purpose: Re-aligns background image panels so they are touching.
  364. //-----------------------------------------------------------------------------
  365. static void FixupBackgroundPanels( EditablePanel *pWindow, int offsetX, int offsetY )
  366. {
  367. if ( !pWindow )
  368. return;
  369. int screenWide, screenTall;
  370. pWindow->GetSize( screenWide, screenTall );
  371. int inset = GetAlternateProportionalValueFromNormal( 20 );
  372. int cornerSize = GetAlternateProportionalValueFromNormal( 10 );
  373. int titleHeight = GetAlternateProportionalValueFromNormal( 42 );
  374. int mainHeight = GetAlternateProportionalValueFromNormal( 376 );
  375. int logoSize = titleHeight;
  376. int captionInset = GetAlternateProportionalValueFromNormal( 76 );
  377. Panel *pPanel;
  378. // corners --------------------------------------------
  379. pPanel = pWindow->FindChildByName( "TopLeftPanel" );
  380. if ( pPanel )
  381. {
  382. pPanel->SetZPos( -20 );
  383. pPanel->SetBounds( offsetX + inset, offsetY + inset, cornerSize, cornerSize );
  384. }
  385. pPanel = pWindow->FindChildByName( "TopRightPanel" );
  386. if ( pPanel )
  387. {
  388. pPanel->SetZPos( -20 );
  389. pPanel->SetBounds( screenWide - offsetX - inset - cornerSize, offsetY + inset, cornerSize, cornerSize );
  390. }
  391. pPanel = pWindow->FindChildByName( "BottomLeftPanel" );
  392. if ( pPanel )
  393. {
  394. pPanel->SetZPos( -20 );
  395. pPanel->SetBounds( offsetX + inset, screenTall - offsetY - inset - cornerSize, cornerSize, cornerSize );
  396. }
  397. pPanel = pWindow->FindChildByName( "BottomRightPanel" );
  398. if ( pPanel )
  399. {
  400. pPanel->SetZPos( -20 );
  401. pPanel->SetBounds( screenWide - offsetX - inset - cornerSize, screenTall - offsetY - inset - cornerSize, cornerSize, cornerSize );
  402. }
  403. // background -----------------------------------------
  404. pPanel = pWindow->FindChildByName( "TopSolid" );
  405. if ( pPanel )
  406. {
  407. pPanel->SetZPos( -20 );
  408. pPanel->SetBounds( offsetX + inset + cornerSize, offsetY + inset, screenWide - 2*offsetX - 2*inset - 2*cornerSize, cornerSize );
  409. }
  410. pPanel = pWindow->FindChildByName( "UpperMiddleSolid" );
  411. if ( pPanel )
  412. {
  413. pPanel->SetZPos( -20 );
  414. pPanel->SetBounds( offsetX + inset, offsetY + inset + cornerSize, screenWide - 2*offsetX - 2*inset, titleHeight );
  415. }
  416. pPanel = pWindow->FindChildByName( "LowerMiddleSolid" );
  417. if ( pPanel )
  418. {
  419. pPanel->SetZPos( -20 );
  420. pPanel->SetBounds( offsetX + inset + cornerSize, screenTall - offsetY - inset - cornerSize, screenWide - 2*offsetX - 2*inset - 2*cornerSize, cornerSize );
  421. }
  422. pPanel = pWindow->FindChildByName( "BottomSolid" );
  423. if ( pPanel )
  424. {
  425. pPanel->SetZPos( -20 );
  426. pPanel->SetBounds( offsetX + inset, screenTall - offsetY - inset - cornerSize - mainHeight, screenWide - 2*offsetX - 2*inset, mainHeight );
  427. }
  428. // transparent border ---------------------------------
  429. pPanel = pWindow->FindChildByName( "TopClear" );
  430. if ( pPanel )
  431. {
  432. pPanel->SetZPos( -20 );
  433. pPanel->SetBounds( 0, 0, screenWide, offsetY + inset );
  434. }
  435. pPanel = pWindow->FindChildByName( "BottomClear" );
  436. if ( pPanel )
  437. {
  438. pPanel->SetZPos( -20 );
  439. pPanel->SetBounds( 0, screenTall - offsetY - inset, screenWide, offsetY + inset );
  440. }
  441. pPanel = pWindow->FindChildByName( "LeftClear" );
  442. if ( pPanel )
  443. {
  444. pPanel->SetZPos( -20 );
  445. pPanel->SetBounds( 0, offsetY + inset, offsetX + inset, screenTall - 2*offsetY - 2*inset );
  446. }
  447. pPanel = pWindow->FindChildByName( "RightClear" );
  448. if ( pPanel )
  449. {
  450. pPanel->SetZPos( -20 );
  451. pPanel->SetBounds( screenWide - offsetX - inset, offsetY + inset, offsetX + inset, screenTall - 2*offsetY - 2*inset );
  452. }
  453. // Logo -----------------------------------------------
  454. int logoInset = (cornerSize + titleHeight - logoSize)/2;
  455. pPanel = pWindow->FindChildByName( "ExclamationPanel" );
  456. if ( pPanel )
  457. {
  458. pPanel->SetZPos( -19 ); // higher than the background
  459. pPanel->SetBounds( offsetX + inset + logoInset, offsetY + inset + logoInset, logoSize, logoSize );
  460. }
  461. // Title caption --------------------------------------
  462. pPanel = dynamic_cast< Label * >(pWindow->FindChildByName( "CaptionLabel" ));
  463. if ( pPanel )
  464. {
  465. pPanel->SetZPos( -19 ); // higher than the background
  466. pPanel->SetBounds( offsetX + captionInset/*inset + 2*logoInset + logoSize*/, offsetY + inset + logoInset, screenWide, logoSize );
  467. }
  468. }
  469. //-----------------------------------------------------------------------------
  470. // Purpose: Creates background image panels
  471. //-----------------------------------------------------------------------------
  472. void CreateBackground( EditablePanel *pWindow )
  473. {
  474. // corners --------------------------------------------
  475. new CBitmapImagePanel( pWindow, "TopLeftPanel", "gfx/vgui/round_corner_nw" );
  476. new CBitmapImagePanel( pWindow, "TopRightPanel", "gfx/vgui/round_corner_ne" );
  477. new CBitmapImagePanel( pWindow, "BottomLeftPanel", "gfx/vgui/round_corner_sw" );
  478. new CBitmapImagePanel( pWindow, "BottomRightPanel", "gfx/vgui/round_corner_se" );
  479. // background -----------------------------------------
  480. new CBitmapImagePanel( pWindow, "TopSolid", "gfx/vgui/solid_background" );
  481. new CBitmapImagePanel( pWindow, "UpperMiddleSolid", "gfx/vgui/solid_background" );
  482. new CBitmapImagePanel( pWindow, "LowerMiddleSolid", "gfx/vgui/solid_background" );
  483. new CBitmapImagePanel( pWindow, "BottomSolid", "gfx/vgui/solid_background" );
  484. // transparent border ---------------------------------
  485. new CBitmapImagePanel( pWindow, "TopClear", "gfx/vgui/trans_background" );
  486. new CBitmapImagePanel( pWindow, "BottomClear", "gfx/vgui/trans_background" );
  487. new CBitmapImagePanel( pWindow, "LeftClear", "gfx/vgui/trans_background" );
  488. new CBitmapImagePanel( pWindow, "RightClear", "gfx/vgui/trans_background" );
  489. // Logo -----------------------------------------------
  490. new CBitmapImagePanel( pWindow, "ExclamationPanel", "gfx/vgui/CS_logo" );
  491. // Title caption --------------------------------------
  492. Panel *pPanel = dynamic_cast< Label * >(pWindow->FindChildByName( "CaptionLabel" ));
  493. if ( !pPanel )
  494. new CaptionLabel( pWindow, "CaptionLabel", "" );
  495. }
  496. void ResizeWindowControls( EditablePanel *pWindow, int tall, int wide, int offsetX, int offsetY )
  497. {
  498. if (!pWindow || !pWindow->GetBuildGroup() || !pWindow->GetBuildGroup()->GetPanelList())
  499. return;
  500. CUtlVector<PHandle> *panelList = pWindow->GetBuildGroup()->GetPanelList();
  501. CUtlVector<Panel *> resizedPanels;
  502. CUtlVector<Panel *> movedPanels;
  503. // Resize to account for 1.25 aspect ratio (1280x1024) screens
  504. {
  505. for ( int i = 0; i < panelList->Size(); ++i )
  506. {
  507. PHandle handle = (*panelList)[i];
  508. Panel *panel = handle.Get();
  509. bool found = false;
  510. for ( int j = 0; j < resizedPanels.Size(); ++j )
  511. {
  512. if (panel == resizedPanels[j])
  513. found = true;
  514. }
  515. if (!panel || found)
  516. {
  517. continue;
  518. }
  519. resizedPanels.AddToTail( panel ); // don't move a panel more than once
  520. if ( panel != pWindow )
  521. {
  522. RepositionControl( panel );
  523. }
  524. }
  525. }
  526. // and now re-center them. Woohoo!
  527. for ( int i = 0; i < panelList->Size(); ++i )
  528. {
  529. PHandle handle = (*panelList)[i];
  530. Panel *panel = handle.Get();
  531. bool found = false;
  532. for ( int j = 0; j < movedPanels.Size(); ++j )
  533. {
  534. if (panel == movedPanels[j])
  535. found = true;
  536. }
  537. if (!panel || found)
  538. {
  539. continue;
  540. }
  541. movedPanels.AddToTail( panel ); // don't move a panel more than once
  542. if ( panel != pWindow )
  543. {
  544. int x, y;
  545. panel->GetPos( x, y );
  546. panel->SetPos( x + offsetX, y + offsetY );
  547. #if DEBUG_WINDOW_REPOSITIONING
  548. DevMsg( "Repositioning '%s' from (%d,%d) to (%d,%d) -- a distance of (%d,%d)\n",
  549. panel->GetName(), x, y, x + offsetX, y + offsetY, offsetX, offsetY );
  550. #endif
  551. }
  552. }
  553. }
  554. //-----------------------------------------------------------------------------
  555. // Purpose: Resizes windows to fit completely on-screen (for 1280x1024), and
  556. // centers them on the screen. Sub-controls are also resized and moved.
  557. //-----------------------------------------------------------------------------
  558. void LayoutBackgroundPanel( EditablePanel *pWindow )
  559. {
  560. if ( !pWindow )
  561. return;
  562. int screenW, screenH;
  563. GetHudSize( screenW, screenH );
  564. int wide, tall;
  565. pWindow->GetSize( wide, tall );
  566. int offsetX = 0;
  567. int offsetY = 0;
  568. // Slide everything over to the center
  569. pWindow->SetBounds( 0, 0, screenW, screenH );
  570. if ( wide != screenW || tall != screenH )
  571. {
  572. wide = GetAlternateProportionalValueFromScaled( pWindow->GetScheme(), wide);
  573. tall = GetAlternateProportionalValueFromScaled( pWindow->GetScheme(), tall);
  574. offsetX = (screenW - wide)/2;
  575. offsetY = (screenH - tall)/2;
  576. ResizeWindowControls( pWindow, tall, wide, offsetX, offsetY );
  577. }
  578. // now that the panels are moved/resized, look for some bg panels, and re-align them
  579. FixupBackgroundPanels( pWindow, offsetX, offsetY );
  580. }
  581. //-----------------------------------------------------------------------------