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.

1069 lines
27 KiB

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