Counter Strike : Global Offensive Source Code
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.

1073 lines
27 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "tier0/dbg.h"
  8. #include <stdio.h>
  9. #include "choreoview.h"
  10. #include "choreowidgetdrawhelper.h"
  11. #include "choreoviewcolors.h"
  12. #include "hlfaceposer.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. //-----------------------------------------------------------------------------
  16. // Purpose:
  17. // Input : *widget -
  18. //-----------------------------------------------------------------------------
  19. CChoreoWidgetDrawHelper::CChoreoWidgetDrawHelper( mxWindow *widget )
  20. {
  21. Init( widget, 0, 0, 0, 0, COLOR_CHOREO_BACKGROUND, false );
  22. }
  23. //-----------------------------------------------------------------------------
  24. // Purpose:
  25. // Input : *widget -
  26. //-----------------------------------------------------------------------------
  27. CChoreoWidgetDrawHelper::CChoreoWidgetDrawHelper( mxWindow *widget, const Color& bgColor )
  28. {
  29. Init( widget, 0, 0, 0, 0, bgColor, false );
  30. }
  31. //-----------------------------------------------------------------------------
  32. // Purpose:
  33. // Input : *widget -
  34. // bounds -
  35. //-----------------------------------------------------------------------------
  36. CChoreoWidgetDrawHelper::CChoreoWidgetDrawHelper( mxWindow *widget, RECT& bounds )
  37. {
  38. Init( widget, bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top, COLOR_CHOREO_BACKGROUND, false );
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Purpose:
  42. // Input : *widget -
  43. // bounds -
  44. //-----------------------------------------------------------------------------
  45. CChoreoWidgetDrawHelper::CChoreoWidgetDrawHelper( mxWindow *widget, RECT& bounds, bool noPageFlip )
  46. {
  47. Init( widget, bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top, COLOR_CHOREO_BACKGROUND, noPageFlip );
  48. }
  49. //-----------------------------------------------------------------------------
  50. // Purpose:
  51. // Input : *widget -
  52. // x -
  53. // y -
  54. // w -
  55. // h -
  56. //-----------------------------------------------------------------------------
  57. CChoreoWidgetDrawHelper::CChoreoWidgetDrawHelper( mxWindow *widget, int x, int y, int w, int h, const Color& bgColor )
  58. {
  59. Init( widget, x, y, w, h, bgColor, false );
  60. }
  61. //-----------------------------------------------------------------------------
  62. // Purpose:
  63. // Input : *widget -
  64. // bounds -
  65. // bgColor -
  66. //-----------------------------------------------------------------------------
  67. CChoreoWidgetDrawHelper::CChoreoWidgetDrawHelper( mxWindow *widget, RECT& bounds, const Color& bgColor )
  68. {
  69. Init( widget, bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top, bgColor, false );
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Purpose:
  73. // Input : *widget -
  74. // x -
  75. // y -
  76. // w -
  77. // h -
  78. //-----------------------------------------------------------------------------
  79. void CChoreoWidgetDrawHelper::Init( mxWindow *widget, int x, int y, int w, int h, const Color& bgColor, bool noPageFlip )
  80. {
  81. m_bNoPageFlip = noPageFlip;
  82. m_x = x;
  83. m_y = y;
  84. m_w = w ? w : widget->w2();
  85. m_h = h ? h : widget->h2();
  86. m_hWnd = (HWND)widget->getHandle();
  87. Assert( m_hWnd );
  88. m_dcReal = GetDC( m_hWnd );
  89. m_rcClient.left = m_x;
  90. m_rcClient.top = m_y;
  91. m_rcClient.right = m_x + m_w;
  92. m_rcClient.bottom = m_y + m_h;
  93. if ( !noPageFlip )
  94. {
  95. m_dcMemory = CreateCompatibleDC( m_dcReal );
  96. m_bmMemory = CreateCompatibleBitmap( m_dcReal, m_w, m_h );
  97. m_bmOld = (HBITMAP)SelectObject( m_dcMemory, m_bmMemory );
  98. }
  99. else
  100. {
  101. m_dcMemory = m_dcReal;
  102. m_x = m_y = 0;
  103. }
  104. m_clrOld = RGBToColor( SetBkColor( m_dcMemory, ColorToRGB( bgColor ) ) );
  105. RECT rcFill = m_rcClient;
  106. OffsetRect( &rcFill, -m_rcClient.left, -m_rcClient.top );
  107. if ( !noPageFlip )
  108. {
  109. HBRUSH br = CreateSolidBrush( ColorToRGB( bgColor ) );
  110. FillRect( m_dcMemory, &rcFill, br );
  111. DeleteObject( br );
  112. }
  113. m_ClipRegion = (HRGN)0;
  114. }
  115. //-----------------------------------------------------------------------------
  116. // Purpose: Finish up
  117. //-----------------------------------------------------------------------------
  118. CChoreoWidgetDrawHelper::~CChoreoWidgetDrawHelper( void )
  119. {
  120. SelectClipRgn( m_dcMemory, NULL );
  121. while ( m_ClipRects.Count() > 0 )
  122. {
  123. StopClipping();
  124. }
  125. if ( !m_bNoPageFlip )
  126. {
  127. BitBlt( m_dcReal, m_x, m_y, m_w, m_h, m_dcMemory, 0, 0, SRCCOPY );
  128. SetBkColor( m_dcMemory, ColorToRGB( m_clrOld ) );
  129. SelectObject( m_dcMemory, m_bmOld );
  130. DeleteObject( m_bmMemory );
  131. DeleteObject( m_dcMemory );
  132. }
  133. ReleaseDC( m_hWnd, m_dcReal );
  134. ValidateRect( m_hWnd, &m_rcClient );
  135. }
  136. //-----------------------------------------------------------------------------
  137. // Purpose:
  138. // Output : int
  139. //-----------------------------------------------------------------------------
  140. int CChoreoWidgetDrawHelper::GetWidth( void )
  141. {
  142. return m_w;
  143. }
  144. //-----------------------------------------------------------------------------
  145. // Purpose:
  146. // Output : int
  147. //-----------------------------------------------------------------------------
  148. int CChoreoWidgetDrawHelper::GetHeight( void )
  149. {
  150. return m_h;
  151. }
  152. //-----------------------------------------------------------------------------
  153. // Purpose:
  154. // Input : rc -
  155. //-----------------------------------------------------------------------------
  156. void CChoreoWidgetDrawHelper::GetClientRect( RECT& rc )
  157. {
  158. rc.left = rc.top = 0;
  159. rc.right = m_w;
  160. rc.bottom = m_h;
  161. }
  162. //-----------------------------------------------------------------------------
  163. // Purpose:
  164. // Output : HDC
  165. //-----------------------------------------------------------------------------
  166. HDC CChoreoWidgetDrawHelper::GrabDC( void )
  167. {
  168. return m_dcMemory;
  169. }
  170. //-----------------------------------------------------------------------------
  171. // Purpose:
  172. // Input : *font -
  173. // pointsize -
  174. // weight -
  175. // maxwidth -
  176. // rcText -
  177. // *fmt -
  178. // ... -
  179. //-----------------------------------------------------------------------------
  180. void CChoreoWidgetDrawHelper::CalcTextRect( const char *font, int pointsize, int weight, int maxwidth, RECT& rcText, const char *fmt, ... )
  181. {
  182. va_list args;
  183. static char output[1024];
  184. va_start( args, fmt );
  185. vprintf( fmt, args );
  186. vsprintf( output, fmt, args );
  187. HFONT fnt = CreateFont(
  188. -pointsize,
  189. 0,
  190. 0,
  191. 0,
  192. weight,
  193. FALSE,
  194. FALSE,
  195. FALSE,
  196. ANSI_CHARSET,
  197. OUT_TT_PRECIS,
  198. CLIP_DEFAULT_PRECIS,
  199. ANTIALIASED_QUALITY,
  200. DEFAULT_PITCH,
  201. font );
  202. HFONT oldFont = (HFONT)SelectObject( m_dcMemory, fnt );
  203. DrawText( m_dcMemory, output, -1, &rcText, DT_LEFT | DT_NOPREFIX | DT_VCENTER | DT_WORDBREAK | DT_CALCRECT );
  204. SelectObject( m_dcMemory, oldFont );
  205. DeleteObject( fnt );
  206. }
  207. //-----------------------------------------------------------------------------
  208. // Purpose:
  209. // Input : *font -
  210. // pointsize -
  211. // weight -
  212. // *fmt -
  213. // ... -
  214. // Output : int
  215. //-----------------------------------------------------------------------------
  216. int CChoreoWidgetDrawHelper::CalcTextWidth( const char *font, int pointsize, int weight, const char *fmt, ... )
  217. {
  218. va_list args;
  219. static char output[1024];
  220. va_start( args, fmt );
  221. vprintf( fmt, args );
  222. vsprintf( output, fmt, args );
  223. HFONT fnt = CreateFont(
  224. -pointsize,
  225. 0,
  226. 0,
  227. 0,
  228. weight,
  229. FALSE,
  230. FALSE,
  231. FALSE,
  232. ANSI_CHARSET,
  233. OUT_TT_PRECIS,
  234. CLIP_DEFAULT_PRECIS,
  235. ANTIALIASED_QUALITY,
  236. DEFAULT_PITCH,
  237. font );
  238. HDC screen = GetDC( NULL );
  239. HFONT oldFont = (HFONT)SelectObject( screen, fnt );
  240. RECT rcText;
  241. rcText.left = rcText.top = 0;
  242. rcText.bottom = pointsize + 5;
  243. rcText.right = rcText.left + 2048;
  244. DrawText( screen, output, -1, &rcText, DT_LEFT | DT_NOPREFIX | DT_VCENTER | DT_SINGLELINE | DT_CALCRECT );
  245. SelectObject( screen, oldFont );
  246. DeleteObject( fnt );
  247. ReleaseDC( NULL, screen );
  248. return rcText.right;
  249. }
  250. //-----------------------------------------------------------------------------
  251. // Purpose:
  252. // Input : *font -
  253. // pointsize -
  254. // weight -
  255. // *fmt -
  256. // ... -
  257. // Output : int
  258. //-----------------------------------------------------------------------------
  259. int CChoreoWidgetDrawHelper::CalcTextWidthW( const char *font, int pointsize, int weight, const wchar_t *fmt, ... )
  260. {
  261. va_list args;
  262. static wchar_t output[1024];
  263. va_start( args, fmt );
  264. vwprintf( fmt, args );
  265. vswprintf( output, fmt, args );
  266. HFONT fnt = CreateFont(
  267. -pointsize,
  268. 0,
  269. 0,
  270. 0,
  271. weight,
  272. FALSE,
  273. FALSE,
  274. FALSE,
  275. ANSI_CHARSET,
  276. OUT_TT_PRECIS,
  277. CLIP_DEFAULT_PRECIS,
  278. ANTIALIASED_QUALITY,
  279. DEFAULT_PITCH,
  280. font );
  281. HDC screen = GetDC( NULL );
  282. HFONT oldFont = (HFONT)SelectObject( screen, fnt );
  283. RECT rcText;
  284. rcText.left = rcText.top = 0;
  285. rcText.bottom = pointsize + 5;
  286. rcText.right = rcText.left + 2048;
  287. DrawTextW( screen, output, -1, &rcText, DT_LEFT | DT_NOPREFIX | DT_VCENTER | DT_SINGLELINE | DT_CALCRECT );
  288. SelectObject( screen, oldFont );
  289. DeleteObject( fnt );
  290. ReleaseDC( NULL, screen );
  291. return rcText.right;
  292. }
  293. //-----------------------------------------------------------------------------
  294. // Purpose:
  295. // Input : fnt -
  296. // *fmt -
  297. // ... -
  298. // Output : int
  299. //-----------------------------------------------------------------------------
  300. int CChoreoWidgetDrawHelper::CalcTextWidth( HFONT fnt, const char *fmt, ... )
  301. {
  302. va_list args;
  303. static char output[1024];
  304. va_start( args, fmt );
  305. vprintf( fmt, args );
  306. vsprintf( output, fmt, args );
  307. HDC screen = GetDC( NULL );
  308. HFONT oldFont = (HFONT)SelectObject( screen, fnt );
  309. RECT rcText;
  310. rcText.left = rcText.top = 0;
  311. rcText.bottom = 1000;
  312. rcText.right = rcText.left + 2048;
  313. DrawText( screen, output, -1, &rcText, DT_LEFT | DT_NOPREFIX | DT_VCENTER | DT_SINGLELINE | DT_CALCRECT );
  314. SelectObject( screen, oldFont );
  315. ReleaseDC( NULL, screen );
  316. return rcText.right;
  317. }
  318. int CChoreoWidgetDrawHelper::CalcTextWidthW( HFONT fnt, const wchar_t *fmt, ... )
  319. {
  320. va_list args;
  321. static wchar_t output[1024];
  322. va_start( args, fmt );
  323. vwprintf( fmt, args );
  324. vswprintf( output, fmt, args );
  325. HDC screen = GetDC( NULL );
  326. HFONT oldFont = (HFONT)SelectObject( screen, fnt );
  327. RECT rcText;
  328. rcText.left = rcText.top = 0;
  329. rcText.bottom = 1000;
  330. rcText.right = rcText.left + 2048;
  331. DrawTextW( screen, output, -1, &rcText, DT_LEFT | DT_NOPREFIX | DT_VCENTER | DT_SINGLELINE | DT_CALCRECT );
  332. SelectObject( screen, oldFont );
  333. ReleaseDC( NULL, screen );
  334. return rcText.right;
  335. }
  336. //-----------------------------------------------------------------------------
  337. // Purpose:
  338. // Input : *font -
  339. // pointsize -
  340. // weight -
  341. // clr -
  342. // rcText -
  343. // *fmt -
  344. // ... -
  345. //-----------------------------------------------------------------------------
  346. void CChoreoWidgetDrawHelper::DrawColoredText( const char *font, int pointsize, int weight, const Color& clr, RECT& rcText, const char *fmt, ... )
  347. {
  348. va_list args;
  349. static char output[1024];
  350. va_start( args, fmt );
  351. vsprintf( output, fmt, args );
  352. va_end( args );
  353. DrawColoredTextCharset( font, pointsize, weight, ANSI_CHARSET, clr, rcText, output );
  354. }
  355. //-----------------------------------------------------------------------------
  356. // Purpose:
  357. // Input : *font -
  358. // pointsize -
  359. // weight -
  360. // clr -
  361. // rcText -
  362. // *fmt -
  363. // ... -
  364. //-----------------------------------------------------------------------------
  365. void CChoreoWidgetDrawHelper::DrawColoredTextW( const char *font, int pointsize, int weight, const Color& clr, RECT& rcText, const wchar_t *fmt, ... )
  366. {
  367. va_list args;
  368. static wchar_t output[1024];
  369. va_start( args, fmt );
  370. vswprintf( output, fmt, args );
  371. va_end( args );
  372. DrawColoredTextCharsetW( font, pointsize, weight, ANSI_CHARSET, clr, rcText, output );
  373. }
  374. //-----------------------------------------------------------------------------
  375. // Purpose:
  376. // Input : font -
  377. // clr -
  378. // rcText -
  379. // *fmt -
  380. // ... -
  381. //-----------------------------------------------------------------------------
  382. void CChoreoWidgetDrawHelper::DrawColoredText( HFONT font, const Color& clr, RECT& rcText, const char *fmt, ... )
  383. {
  384. va_list args;
  385. static char output[1024];
  386. va_start( args, fmt );
  387. vsprintf( output, fmt, args );
  388. va_end( args );
  389. HFONT oldFont = (HFONT)SelectObject( m_dcMemory, font );
  390. Color oldColor = RGBToColor( SetTextColor( m_dcMemory, ColorToRGB( clr ) ) );
  391. int oldMode = SetBkMode( m_dcMemory, TRANSPARENT );
  392. RECT rcTextOffset = rcText;
  393. OffsetSubRect( rcTextOffset );
  394. DrawText( m_dcMemory, output, -1, &rcTextOffset, DT_LEFT | DT_NOPREFIX | DT_VCENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS );
  395. SetBkMode( m_dcMemory, oldMode );
  396. SetTextColor( m_dcMemory, ColorToRGB( oldColor ) );
  397. SelectObject( m_dcMemory, oldFont );
  398. }
  399. //-----------------------------------------------------------------------------
  400. // Purpose:
  401. // Input : font -
  402. // clr -
  403. // rcText -
  404. // *fmt -
  405. // ... -
  406. //-----------------------------------------------------------------------------
  407. void CChoreoWidgetDrawHelper::DrawColoredTextW( HFONT font, const Color& clr, RECT& rcText, const wchar_t *fmt, ... )
  408. {
  409. va_list args;
  410. static wchar_t output[1024];
  411. va_start( args, fmt );
  412. vswprintf( output, fmt, args );
  413. va_end( args );
  414. HFONT oldFont = (HFONT)SelectObject( m_dcMemory, font );
  415. Color oldColor = RGBToColor( SetTextColor( m_dcMemory, ColorToRGB( clr ) ) );
  416. int oldMode = SetBkMode( m_dcMemory, TRANSPARENT );
  417. RECT rcTextOffset = rcText;
  418. OffsetSubRect( rcTextOffset );
  419. DrawTextW( m_dcMemory, output, -1, &rcTextOffset, DT_LEFT | DT_NOPREFIX | DT_VCENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS );
  420. SetBkMode( m_dcMemory, oldMode );
  421. SetTextColor( m_dcMemory, ColorToRGB( oldColor ) );
  422. SelectObject( m_dcMemory, oldFont );
  423. }
  424. //-----------------------------------------------------------------------------
  425. // Purpose:
  426. // Input : *font -
  427. // pointsize -
  428. // weight -
  429. // clr -
  430. // rcText -
  431. // *fmt -
  432. // ... -
  433. //-----------------------------------------------------------------------------
  434. void CChoreoWidgetDrawHelper::DrawColoredTextCharset( const char *font, int pointsize, int weight, DWORD charset, const Color& clr, RECT& rcText, const char *fmt, ... )
  435. {
  436. va_list args;
  437. static char output[1024];
  438. va_start( args, fmt );
  439. vsprintf( output, fmt, args );
  440. va_end( args );
  441. HFONT fnt = CreateFont(
  442. -pointsize,
  443. 0,
  444. 0,
  445. 0,
  446. weight,
  447. FALSE,
  448. FALSE,
  449. FALSE,
  450. charset,
  451. OUT_TT_PRECIS,
  452. CLIP_DEFAULT_PRECIS,
  453. ANTIALIASED_QUALITY,
  454. DEFAULT_PITCH,
  455. font );
  456. HFONT oldFont = (HFONT)SelectObject( m_dcMemory, fnt );
  457. Color oldColor = RGBToColor( SetTextColor( m_dcMemory, ColorToRGB( clr ) ) );
  458. int oldMode = SetBkMode( m_dcMemory, TRANSPARENT );
  459. RECT rcTextOffset = rcText;
  460. OffsetSubRect( rcTextOffset );
  461. DrawText( m_dcMemory, output, -1, &rcTextOffset, DT_LEFT | DT_NOPREFIX | DT_VCENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS );
  462. SetBkMode( m_dcMemory, oldMode );
  463. SetTextColor( m_dcMemory, ColorToRGB( oldColor ) );
  464. SelectObject( m_dcMemory, oldFont );
  465. DeleteObject( fnt );
  466. }
  467. void CChoreoWidgetDrawHelper::DrawColoredTextCharsetW( const char *font, int pointsize, int weight, DWORD charset, const Color& clr, RECT& rcText, const wchar_t *fmt, ... )
  468. {
  469. va_list args;
  470. static wchar_t output[1024];
  471. va_start( args, fmt );
  472. vswprintf( output, fmt, args );
  473. va_end( args );
  474. HFONT fnt = CreateFont(
  475. -pointsize,
  476. 0,
  477. 0,
  478. 0,
  479. weight,
  480. FALSE,
  481. FALSE,
  482. FALSE,
  483. charset,
  484. OUT_TT_PRECIS,
  485. CLIP_DEFAULT_PRECIS,
  486. ANTIALIASED_QUALITY,
  487. DEFAULT_PITCH,
  488. font );
  489. HFONT oldFont = (HFONT)SelectObject( m_dcMemory, fnt );
  490. Color oldColor = RGBToColor( SetTextColor( m_dcMemory, ColorToRGB( clr ) ) );
  491. int oldMode = SetBkMode( m_dcMemory, TRANSPARENT );
  492. RECT rcTextOffset = rcText;
  493. OffsetSubRect( rcTextOffset );
  494. DrawTextW( m_dcMemory, output, -1, &rcTextOffset, DT_LEFT | DT_NOPREFIX | DT_VCENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS );
  495. SetBkMode( m_dcMemory, oldMode );
  496. SetTextColor( m_dcMemory, ColorToRGB( oldColor ) );
  497. SelectObject( m_dcMemory, oldFont );
  498. DeleteObject( fnt );
  499. }
  500. //-----------------------------------------------------------------------------
  501. // Purpose:
  502. // Input : *font -
  503. // pointsize -
  504. // weight -
  505. // clr -
  506. // rcText -
  507. // *fmt -
  508. // ... -
  509. //-----------------------------------------------------------------------------
  510. void CChoreoWidgetDrawHelper::DrawColoredTextMultiline( const char *font, int pointsize, int weight, const Color& clr, RECT& rcText, const char *fmt, ... )
  511. {
  512. va_list args;
  513. static char output[1024];
  514. va_start( args, fmt );
  515. vprintf( fmt, args );
  516. vsprintf( output, fmt, args );
  517. HFONT fnt = CreateFont(
  518. -pointsize,
  519. 0,
  520. 0,
  521. 0,
  522. weight,
  523. FALSE,
  524. FALSE,
  525. FALSE,
  526. ANSI_CHARSET,
  527. OUT_TT_PRECIS,
  528. CLIP_DEFAULT_PRECIS,
  529. ANTIALIASED_QUALITY,
  530. DEFAULT_PITCH,
  531. font );
  532. HFONT oldFont = (HFONT)SelectObject( m_dcMemory, fnt );
  533. Color oldColor = RGBToColor( SetTextColor( m_dcMemory, ColorToRGB( clr ) ) );
  534. int oldMode = SetBkMode( m_dcMemory, TRANSPARENT );
  535. RECT rcTextOffset = rcText;
  536. OffsetSubRect( rcTextOffset );
  537. DrawText( m_dcMemory, output, -1, &rcTextOffset, DT_LEFT | DT_NOPREFIX | DT_VCENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS );
  538. SetBkMode( m_dcMemory, oldMode );
  539. SetTextColor( m_dcMemory, ColorToRGB( oldColor ) );
  540. SelectObject( m_dcMemory, oldFont );
  541. DeleteObject( fnt );
  542. }
  543. //-----------------------------------------------------------------------------
  544. // Purpose:
  545. // Input : r -
  546. // g -
  547. // b -
  548. // style -
  549. // width -
  550. // x1 -
  551. // y1 -
  552. // x2 -
  553. // y2 -
  554. //-----------------------------------------------------------------------------
  555. void CChoreoWidgetDrawHelper::DrawColoredLine( const Color& clr, int style, int width, int x1, int y1, int x2, int y2 )
  556. {
  557. HPEN pen = CreatePen( style, width, ColorToRGB( clr ) );
  558. HPEN oldPen = (HPEN)SelectObject( m_dcMemory, pen );
  559. MoveToEx( m_dcMemory, x1-m_x, y1-m_y, NULL );
  560. LineTo( m_dcMemory, x2-m_x, y2-m_y );
  561. SelectObject( m_dcMemory, oldPen );
  562. DeleteObject( pen );
  563. };
  564. //-----------------------------------------------------------------------------
  565. // Purpose:
  566. // Input : clr -
  567. // style -
  568. // width -
  569. // count -
  570. // *pts -
  571. //-----------------------------------------------------------------------------
  572. void CChoreoWidgetDrawHelper::DrawColoredPolyLine( const Color& clr, int style, int width, CUtlVector< POINT >& points )
  573. {
  574. int c = points.Count();
  575. if ( c < 2 )
  576. return;
  577. HPEN pen = CreatePen( style, width, ColorToRGB( clr ) );
  578. HPEN oldPen = (HPEN)SelectObject( m_dcMemory, pen );
  579. POINT *temp = (POINT *)_alloca( c * sizeof( POINT ) );
  580. Assert( temp );
  581. int i;
  582. for ( i = 0; i < c; i++ )
  583. {
  584. POINT *pt = &points[ i ];
  585. temp[ i ].x = pt->x - m_x;
  586. temp[ i ].y = pt->y - m_y;
  587. }
  588. Polyline( m_dcMemory, temp, c );
  589. SelectObject( m_dcMemory, oldPen );
  590. DeleteObject( pen );
  591. }
  592. //-----------------------------------------------------------------------------
  593. // Purpose:
  594. // Input : r -
  595. // g -
  596. // b -
  597. // style -
  598. // width -
  599. // x1 -
  600. // y1 -
  601. // x2 -
  602. // y2 -
  603. //-----------------------------------------------------------------------------
  604. POINTL CChoreoWidgetDrawHelper::DrawColoredRamp( const Color& clr, int style, int width, int x1, int y1, int x2, int y2, float rate, float sustain )
  605. {
  606. HPEN pen = CreatePen( style, width, ColorToRGB( clr ) );
  607. HPEN oldPen = (HPEN)SelectObject( m_dcMemory, pen );
  608. MoveToEx( m_dcMemory, x1-m_x, y1-m_y, NULL );
  609. int dx = x2 - x1;
  610. int dy = y2 - y1;
  611. POINTL p;
  612. p.x = 0L;
  613. p.y = 0L;
  614. for (float i = 0.1f; i <= 1.09f; i += 0.1f)
  615. {
  616. float j = 3.0f * i * i - 2.0f * i * i * i;
  617. p.x = x1+(int)(dx*i*(1.0f-rate))-m_x;
  618. p.y = y1+(int)(dy*sustain*j)-m_y;
  619. LineTo( m_dcMemory, p.x, p.y );
  620. }
  621. SelectObject( m_dcMemory, oldPen );
  622. DeleteObject( pen );
  623. return p;
  624. };
  625. //-----------------------------------------------------------------------------
  626. // Purpose: Draw a filled rect
  627. // Input : clr -
  628. // x1 -
  629. // y1 -
  630. // x2 -
  631. // y2 -
  632. //-----------------------------------------------------------------------------
  633. void CChoreoWidgetDrawHelper::DrawFilledRect( const Color& clr, RECT& rc )
  634. {
  635. RECT rcCopy = rc;
  636. HBRUSH br = CreateSolidBrush( ColorToRGB( clr ) );
  637. OffsetSubRect( rcCopy );
  638. FillRect( m_dcMemory, &rcCopy, br );
  639. DeleteObject( br );
  640. }
  641. //-----------------------------------------------------------------------------
  642. // Purpose: Draw a filled rect
  643. // Input : clr -
  644. // x1 -
  645. // y1 -
  646. // x2 -
  647. // y2 -
  648. //-----------------------------------------------------------------------------
  649. void CChoreoWidgetDrawHelper::DrawFilledRect( const Color& clr, int x1, int y1, int x2, int y2 )
  650. {
  651. HBRUSH br = CreateSolidBrush( ColorToRGB( clr ) );
  652. RECT rc;
  653. rc.left = x1;
  654. rc.right = x2;
  655. rc.top = y1;
  656. rc.bottom = y2;
  657. OffsetSubRect( rc );
  658. FillRect( m_dcMemory, &rc, br );
  659. DeleteObject( br );
  660. }
  661. //-----------------------------------------------------------------------------
  662. // Purpose:
  663. // Input : clr -
  664. // style -
  665. // width -
  666. // rc -
  667. //-----------------------------------------------------------------------------
  668. void CChoreoWidgetDrawHelper::DrawOutlinedRect( const Color& clr, int style, int width, RECT& rc )
  669. {
  670. DrawOutlinedRect( clr, style, width, rc.left, rc.top, rc.right, rc.bottom );
  671. }
  672. //-----------------------------------------------------------------------------
  673. // Purpose: Draw an outlined rect
  674. // Input : clr -
  675. // style -
  676. // width -
  677. // x1 -
  678. // y1 -
  679. // x2 -
  680. // y2 -
  681. //-----------------------------------------------------------------------------
  682. void CChoreoWidgetDrawHelper::DrawOutlinedRect( const Color& clr, int style, int width, int x1, int y1, int x2, int y2 )
  683. {
  684. HPEN oldpen, pen;
  685. HBRUSH oldbrush, brush;
  686. pen = CreatePen( PS_SOLID, width, ColorToRGB( clr ) );
  687. oldpen = (HPEN)SelectObject( m_dcMemory, pen );
  688. brush = (HBRUSH)GetStockObject( NULL_BRUSH );
  689. oldbrush = (HBRUSH)SelectObject( m_dcMemory, brush );
  690. RECT rc;
  691. rc.left = x1;
  692. rc.right = x2;
  693. rc.top = y1;
  694. rc.bottom = y2;
  695. OffsetSubRect( rc);
  696. Rectangle( m_dcMemory, rc.left, rc.top, rc.right, rc.bottom );
  697. SelectObject( m_dcMemory, oldbrush );
  698. DeleteObject( brush );
  699. SelectObject( m_dcMemory, oldpen );
  700. DeleteObject( pen );
  701. }
  702. //-----------------------------------------------------------------------------
  703. // Purpose:
  704. // Input : x1 -
  705. // y1 -
  706. // x2 -
  707. // y2 -
  708. // clr -
  709. // thickness -
  710. //-----------------------------------------------------------------------------
  711. void CChoreoWidgetDrawHelper::DrawLine( int x1, int y1, int x2, int y2, const Color& clr, int thickness )
  712. {
  713. HPEN oldpen, pen;
  714. HBRUSH oldbrush, brush;
  715. pen = CreatePen( PS_SOLID, thickness, ColorToRGB( clr ) );
  716. oldpen = (HPEN)SelectObject( m_dcMemory, pen );
  717. brush = (HBRUSH)GetStockObject( NULL_BRUSH );
  718. oldbrush = (HBRUSH)SelectObject( m_dcMemory, brush );
  719. // Offset
  720. x1 -= m_x;
  721. x2 -= m_x;
  722. y1 -= m_y;
  723. y2 -= m_y;
  724. MoveToEx( m_dcMemory, x1, y1, NULL );
  725. LineTo( m_dcMemory, x2, y2 );
  726. SelectObject( m_dcMemory, oldbrush );
  727. DeleteObject( brush );
  728. SelectObject( m_dcMemory, oldpen );
  729. DeleteObject( pen );
  730. }
  731. //-----------------------------------------------------------------------------
  732. // Purpose:
  733. // Input : rc -
  734. // fillr -
  735. // fillg -
  736. // fillb -
  737. //-----------------------------------------------------------------------------
  738. void CChoreoWidgetDrawHelper::DrawTriangleMarker( RECT& rc, const Color& fill, bool inverted /*= false*/ )
  739. {
  740. POINT region[3];
  741. int cPoints = 3;
  742. if ( !inverted )
  743. {
  744. region[ 0 ].x = rc.left - m_x;
  745. region[ 0 ].y = rc.top - m_y;
  746. region[ 1 ].x = rc.right - m_x;
  747. region[ 1 ].y = rc.top - m_y;
  748. region[ 2 ].x = ( ( rc.left + rc.right ) / 2 ) - m_x;
  749. region[ 2 ].y = rc.bottom - m_y;
  750. }
  751. else
  752. {
  753. region[ 0 ].x = rc.left - m_x;
  754. region[ 0 ].y = rc.bottom - m_y;
  755. region[ 1 ].x = rc.right - m_x;
  756. region[ 1 ].y = rc.bottom - m_y;
  757. region[ 2 ].x = ( ( rc.left + rc.right ) / 2 ) - m_x;
  758. region[ 2 ].y = rc.top - m_y;
  759. }
  760. HRGN rgn = CreatePolygonRgn( region, cPoints, ALTERNATE );
  761. int oldPF = SetPolyFillMode( m_dcMemory, ALTERNATE );
  762. HBRUSH brFace = CreateSolidBrush( ColorToRGB( fill ) );
  763. FillRgn( m_dcMemory, rgn, brFace );
  764. DeleteObject( brFace );
  765. SetPolyFillMode( m_dcMemory, oldPF );
  766. DeleteObject( rgn );
  767. }
  768. void CChoreoWidgetDrawHelper::StartClipping( RECT& clipRect )
  769. {
  770. RECT fixed = clipRect;
  771. OffsetSubRect( fixed );
  772. m_ClipRects.AddToTail( fixed );
  773. ClipToRects();
  774. }
  775. void CChoreoWidgetDrawHelper::StopClipping( void )
  776. {
  777. Assert( m_ClipRects.Count() > 0 );
  778. if ( m_ClipRects.Count() <= 0 )
  779. return;
  780. m_ClipRects.Remove( m_ClipRects.Count() - 1 );
  781. ClipToRects();
  782. }
  783. void CChoreoWidgetDrawHelper::ClipToRects( void )
  784. {
  785. SelectClipRgn( m_dcMemory, NULL );
  786. if ( m_ClipRegion )
  787. {
  788. DeleteObject( m_ClipRegion );
  789. m_ClipRegion = HRGN( 0 );
  790. }
  791. if ( m_ClipRects.Count() > 0 )
  792. {
  793. RECT rc = m_ClipRects[ 0 ];
  794. m_ClipRegion = CreateRectRgn( rc.left, rc.top, rc.right, rc.bottom );
  795. for ( int i = 1; i < m_ClipRects.Count(); i++ )
  796. {
  797. RECT add = m_ClipRects[ i ];
  798. HRGN addIn = CreateRectRgn( add.left, add.top, add.right, add.bottom );
  799. HRGN result = CreateRectRgn( 0, 0, 100, 100 );
  800. CombineRgn( result, m_ClipRegion, addIn, RGN_AND );
  801. DeleteObject( m_ClipRegion );
  802. DeleteObject( addIn );
  803. m_ClipRegion = result;
  804. }
  805. }
  806. SelectClipRgn( m_dcMemory, m_ClipRegion );
  807. }
  808. //-----------------------------------------------------------------------------
  809. // Purpose:
  810. // Input : rc -
  811. //-----------------------------------------------------------------------------
  812. void CChoreoWidgetDrawHelper::OffsetSubRect( RECT& rc )
  813. {
  814. OffsetRect( &rc, -m_x, -m_y );
  815. }
  816. //-----------------------------------------------------------------------------
  817. // Purpose:
  818. // Input : br -
  819. // rc -
  820. //-----------------------------------------------------------------------------
  821. void CChoreoWidgetDrawHelper::DrawFilledRect( HBRUSH br, RECT& rc )
  822. {
  823. RECT rcFill = rc;
  824. OffsetSubRect( rcFill );
  825. FillRect( m_dcMemory, &rcFill, br );
  826. }
  827. void CChoreoWidgetDrawHelper::DrawCircle( const Color& clr, int x, int y, int radius, bool filled /*= true*/ )
  828. {
  829. RECT rc;
  830. int ihalfradius = radius >> 1;
  831. rc.left = x - ihalfradius;
  832. rc.right = rc.left + 2 * ihalfradius;
  833. rc.top = y - ihalfradius;
  834. rc.bottom = y + 2 * ihalfradius - 1;
  835. OffsetSubRect( rc );
  836. HPEN pen = CreatePen( PS_SOLID, 1, ColorToRGB( clr ) );
  837. HBRUSH br = CreateSolidBrush( ColorToRGB( clr ) );
  838. HPEN oldPen = (HPEN)SelectObject( m_dcMemory, pen );
  839. HBRUSH oldBr = (HBRUSH)SelectObject( m_dcMemory, br );
  840. if ( filled )
  841. {
  842. Ellipse( m_dcMemory, rc.left, rc.top, rc.right, rc.bottom );
  843. }
  844. else
  845. {
  846. Arc( m_dcMemory, rc.left, rc.top, rc.right, rc.bottom,
  847. rc.left, rc.top, rc.left, rc.top );
  848. }
  849. SelectObject( m_dcMemory, oldPen );
  850. SelectObject( m_dcMemory, oldBr );
  851. DeleteObject( pen );
  852. DeleteObject( br );
  853. }
  854. //-----------------------------------------------------------------------------
  855. // Purpose:
  856. // Input : rc -
  857. // clr1 -
  858. // clr2 -
  859. // vertical -
  860. //-----------------------------------------------------------------------------
  861. void CChoreoWidgetDrawHelper::DrawGradientFilledRect( RECT& rc, const Color& clr1, const Color& clr2, bool vertical )
  862. {
  863. RECT rcDraw = rc;
  864. OffsetRect( &rcDraw, -m_x, -m_y );
  865. TRIVERTEX vert[2] ;
  866. GRADIENT_RECT gradient_rect;
  867. vert[0].x = rcDraw.left;
  868. vert[0].y = rcDraw.top;
  869. vert[0].Red = clr1.r() << 8;
  870. vert[0].Green = clr1.g() << 8;
  871. vert[0].Blue = clr1.b() << 8;
  872. vert[0].Alpha = 0x0000;
  873. vert[1].x = rcDraw.right;
  874. vert[1].y = rcDraw.bottom;
  875. vert[1].Red = clr2.r() << 8;
  876. vert[1].Green = clr2.g() << 8;
  877. vert[1].Blue = clr2.b() << 8;
  878. vert[1].Alpha = 0x0000;
  879. gradient_rect.UpperLeft = 0;
  880. gradient_rect.LowerRight = 1;
  881. GradientFill(
  882. m_dcMemory,
  883. vert, 2,
  884. &gradient_rect, 1,
  885. vertical ? GRADIENT_FILL_RECT_V : GRADIENT_FILL_RECT_H );
  886. }