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.

677 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(vgui::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. //-----------------------------------------------------------------------------
  364. // Purpose: Re-aligns background image panels so they are touching.
  365. //-----------------------------------------------------------------------------
  366. static void FixupBackgroundPanels( EditablePanel *pWindow, int offsetX, int offsetY )
  367. {
  368. if ( !pWindow )
  369. return;
  370. int screenWide, screenTall;
  371. pWindow->GetSize( screenWide, screenTall );
  372. int inset = GetAlternateProportionalValueFromNormal( 20 );
  373. int cornerSize = GetAlternateProportionalValueFromNormal( 10 );
  374. int titleHeight = GetAlternateProportionalValueFromNormal( 42 );
  375. int mainHeight = GetAlternateProportionalValueFromNormal( 376 );
  376. int logoSize = titleHeight;
  377. int captionInset = GetAlternateProportionalValueFromNormal( 76 );
  378. Panel *pPanel;
  379. // corners --------------------------------------------
  380. pPanel = pWindow->FindChildByName( "TopLeftPanel" );
  381. if ( pPanel )
  382. {
  383. pPanel->SetZPos( -20 );
  384. pPanel->SetBounds( offsetX + inset, offsetY + inset, cornerSize, cornerSize );
  385. }
  386. pPanel = pWindow->FindChildByName( "TopRightPanel" );
  387. if ( pPanel )
  388. {
  389. pPanel->SetZPos( -20 );
  390. pPanel->SetBounds( screenWide - offsetX - inset - cornerSize, offsetY + inset, cornerSize, cornerSize );
  391. }
  392. pPanel = pWindow->FindChildByName( "BottomLeftPanel" );
  393. if ( pPanel )
  394. {
  395. pPanel->SetZPos( -20 );
  396. pPanel->SetBounds( offsetX + inset, screenTall - offsetY - inset - cornerSize, cornerSize, cornerSize );
  397. }
  398. pPanel = pWindow->FindChildByName( "BottomRightPanel" );
  399. if ( pPanel )
  400. {
  401. pPanel->SetZPos( -20 );
  402. pPanel->SetBounds( screenWide - offsetX - inset - cornerSize, screenTall - offsetY - inset - cornerSize, cornerSize, cornerSize );
  403. }
  404. // background -----------------------------------------
  405. pPanel = pWindow->FindChildByName( "TopSolid" );
  406. if ( pPanel )
  407. {
  408. pPanel->SetZPos( -20 );
  409. pPanel->SetBounds( offsetX + inset + cornerSize, offsetY + inset, screenWide - 2*offsetX - 2*inset - 2*cornerSize, cornerSize );
  410. }
  411. pPanel = pWindow->FindChildByName( "UpperMiddleSolid" );
  412. if ( pPanel )
  413. {
  414. pPanel->SetZPos( -20 );
  415. pPanel->SetBounds( offsetX + inset, offsetY + inset + cornerSize, screenWide - 2*offsetX - 2*inset, titleHeight );
  416. }
  417. pPanel = pWindow->FindChildByName( "LowerMiddleSolid" );
  418. if ( pPanel )
  419. {
  420. pPanel->SetZPos( -20 );
  421. pPanel->SetBounds( offsetX + inset + cornerSize, screenTall - offsetY - inset - cornerSize, screenWide - 2*offsetX - 2*inset - 2*cornerSize, cornerSize );
  422. }
  423. pPanel = pWindow->FindChildByName( "BottomSolid" );
  424. if ( pPanel )
  425. {
  426. pPanel->SetZPos( -20 );
  427. pPanel->SetBounds( offsetX + inset, screenTall - offsetY - inset - cornerSize - mainHeight, screenWide - 2*offsetX - 2*inset, mainHeight );
  428. }
  429. // transparent border ---------------------------------
  430. pPanel = pWindow->FindChildByName( "TopClear" );
  431. if ( pPanel )
  432. {
  433. pPanel->SetZPos( -20 );
  434. pPanel->SetBounds( 0, 0, screenWide, offsetY + inset );
  435. }
  436. pPanel = pWindow->FindChildByName( "BottomClear" );
  437. if ( pPanel )
  438. {
  439. pPanel->SetZPos( -20 );
  440. pPanel->SetBounds( 0, screenTall - offsetY - inset, screenWide, offsetY + inset );
  441. }
  442. pPanel = pWindow->FindChildByName( "LeftClear" );
  443. if ( pPanel )
  444. {
  445. pPanel->SetZPos( -20 );
  446. pPanel->SetBounds( 0, offsetY + inset, offsetX + inset, screenTall - 2*offsetY - 2*inset );
  447. }
  448. pPanel = pWindow->FindChildByName( "RightClear" );
  449. if ( pPanel )
  450. {
  451. pPanel->SetZPos( -20 );
  452. pPanel->SetBounds( screenWide - offsetX - inset, offsetY + inset, offsetX + inset, screenTall - 2*offsetY - 2*inset );
  453. }
  454. // Logo -----------------------------------------------
  455. /* int logoInset = (cornerSize + titleHeight - logoSize)/2;
  456. pPanel = pWindow->FindChildByName( "ExclamationPanel" );
  457. if ( pPanel )
  458. {
  459. pPanel->SetZPos( -19 ); // higher than the background
  460. pPanel->SetBounds( offsetX + inset + logoInset, offsetY + inset + logoInset, logoSize, logoSize );
  461. }
  462. */
  463. // Title caption --------------------------------------
  464. pPanel = dynamic_cast< Label * >(pWindow->FindChildByName( "CaptionLabel" ));
  465. if ( pPanel )
  466. {
  467. pPanel->SetZPos( -19 ); // higher than the background
  468. pPanel->SetBounds( offsetX + captionInset/*inset + 2*logoInset + logoSize*/, offsetY + inset /*+ logoInset*/, screenWide, logoSize );
  469. }
  470. }
  471. //-----------------------------------------------------------------------------
  472. // Purpose: Creates background image panels
  473. //-----------------------------------------------------------------------------
  474. void CreateBackground( EditablePanel *pWindow )
  475. {
  476. // corners --------------------------------------------
  477. new CBitmapImagePanel( pWindow, "TopLeftPanel", "gfx/vgui/round_corner_nw" );
  478. new CBitmapImagePanel( pWindow, "TopRightPanel", "gfx/vgui/round_corner_ne" );
  479. new CBitmapImagePanel( pWindow, "BottomLeftPanel", "gfx/vgui/round_corner_sw" );
  480. new CBitmapImagePanel( pWindow, "BottomRightPanel", "gfx/vgui/round_corner_se" );
  481. // background -----------------------------------------
  482. new CBitmapImagePanel( pWindow, "TopSolid", "gfx/vgui/solid_background" );
  483. new CBitmapImagePanel( pWindow, "UpperMiddleSolid", "gfx/vgui/solid_background" );
  484. new CBitmapImagePanel( pWindow, "LowerMiddleSolid", "gfx/vgui/solid_background" );
  485. new CBitmapImagePanel( pWindow, "BottomSolid", "gfx/vgui/solid_background" );
  486. // transparent border ---------------------------------
  487. new CBitmapImagePanel( pWindow, "TopClear", "gfx/vgui/trans_background" );
  488. new CBitmapImagePanel( pWindow, "BottomClear", "gfx/vgui/trans_background" );
  489. new CBitmapImagePanel( pWindow, "LeftClear", "gfx/vgui/trans_background" );
  490. new CBitmapImagePanel( pWindow, "RightClear", "gfx/vgui/trans_background" );
  491. // Logo -----------------------------------------------
  492. // new CBitmapImagePanel( pWindow, "ExclamationPanel", "gfx/vgui/TF_logo" );
  493. // Title caption --------------------------------------
  494. Panel *pPanel = dynamic_cast< Label * >(pWindow->FindChildByName( "CaptionLabel" ));
  495. if ( !pPanel )
  496. new CaptionLabel( pWindow, "CaptionLabel", "" );
  497. }
  498. void ResizeWindowControls( EditablePanel *pWindow, int tall, int wide, int offsetX, int offsetY )
  499. {
  500. if (!pWindow || !pWindow->GetBuildGroup() || !pWindow->GetBuildGroup()->GetPanelList())
  501. return;
  502. CUtlVector<PHandle> *panelList = pWindow->GetBuildGroup()->GetPanelList();
  503. CUtlVector<Panel *> resizedPanels;
  504. CUtlVector<Panel *> movedPanels;
  505. // Resize to account for 1.25 aspect ratio (1280x1024) screens
  506. {
  507. for ( int i = 0; i < panelList->Size(); ++i )
  508. {
  509. PHandle handle = (*panelList)[i];
  510. Panel *panel = handle.Get();
  511. bool found = false;
  512. for ( int j = 0; j < resizedPanels.Size(); ++j )
  513. {
  514. if (panel == resizedPanels[j])
  515. found = true;
  516. }
  517. if (!panel || found)
  518. {
  519. continue;
  520. }
  521. resizedPanels.AddToTail( panel ); // don't move a panel more than once
  522. if ( panel != pWindow )
  523. {
  524. RepositionControl( panel );
  525. }
  526. }
  527. }
  528. // and now re-center them. Woohoo!
  529. for ( int i = 0; i < panelList->Size(); ++i )
  530. {
  531. PHandle handle = (*panelList)[i];
  532. Panel *panel = handle.Get();
  533. bool found = false;
  534. for ( int j = 0; j < movedPanels.Size(); ++j )
  535. {
  536. if (panel == movedPanels[j])
  537. found = true;
  538. }
  539. if (!panel || found)
  540. {
  541. continue;
  542. }
  543. movedPanels.AddToTail( panel ); // don't move a panel more than once
  544. if ( panel != pWindow )
  545. {
  546. int x, y;
  547. panel->GetPos( x, y );
  548. panel->SetPos( x + offsetX, y + offsetY );
  549. #if DEBUG_WINDOW_REPOSITIONING
  550. DevMsg( "Repositioning '%s' from (%d,%d) to (%d,%d) -- a distance of (%d,%d)\n",
  551. panel->GetName(), x, y, x + offsetX, y + offsetY, offsetX, offsetY );
  552. #endif
  553. }
  554. }
  555. }
  556. //-----------------------------------------------------------------------------
  557. // Purpose: Resizes windows to fit completely on-screen (for 1280x1024), and
  558. // centers them on the screen. Sub-controls are also resized and moved.
  559. //-----------------------------------------------------------------------------
  560. void LayoutBackgroundPanel( EditablePanel *pWindow )
  561. {
  562. if ( !pWindow )
  563. return;
  564. int screenW, screenH;
  565. GetHudSize( screenW, screenH );
  566. int wide, tall;
  567. pWindow->GetSize( wide, tall );
  568. int offsetX = 0;
  569. int offsetY = 0;
  570. // Slide everything over to the center
  571. pWindow->SetBounds( 0, 0, screenW, screenH );
  572. if ( wide != screenW || tall != screenH )
  573. {
  574. wide = GetAlternateProportionalValueFromScaled(pWindow->GetScheme(), wide);
  575. tall = GetAlternateProportionalValueFromScaled(pWindow->GetScheme(), tall);
  576. offsetX = (screenW - wide)/2;
  577. offsetY = (screenH - tall)/2;
  578. ResizeWindowControls( pWindow, tall, wide, offsetX, offsetY );
  579. }
  580. // now that the panels are moved/resized, look for some bg panels, and re-align them
  581. FixupBackgroundPanels( pWindow, offsetX, offsetY );
  582. }
  583. //-----------------------------------------------------------------------------