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.

107 lines
4.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include <mxtk/mx.h>
  9. #include "utlvector.h"
  10. //-----------------------------------------------------------------------------
  11. // Purpose: Helper class that automagically sets up and destroys a memory device-
  12. // context for flicker-free refershes
  13. //-----------------------------------------------------------------------------
  14. class CDrawHelper
  15. {
  16. public:
  17. // Construction/destruction
  18. CDrawHelper( mxWindow *widget);
  19. CDrawHelper( mxWindow *widget, COLORREF bgColor );
  20. CDrawHelper( mxWindow *widget, int x, int y, int w, int h, COLORREF bgColor );
  21. CDrawHelper( mxWindow *widget, RECT& bounds );
  22. CDrawHelper( mxWindow *widget, RECT& bounds, COLORREF bgColor );
  23. virtual ~CDrawHelper( void );
  24. // Allow caller to draw onto the memory dc, too
  25. HDC GrabDC( void );
  26. // Compute text size
  27. static int CalcTextWidth( const char *font, int pointsize, int weight, PRINTF_FORMAT_STRING const char *fmt, ... );
  28. static int CalcTextWidth( HFONT font, PRINTF_FORMAT_STRING const char *fmt, ... );
  29. int CalcTextWidthW( const char *font, int pointsize, int weight, PRINTF_FORMAT_STRING const wchar_t *fmt, ... );
  30. int CalcTextWidthW( HFONT font, PRINTF_FORMAT_STRING const wchar_t *fmt, ... );
  31. void DrawColoredTextW( const char *font, int pointsize, int weight, COLORREF clr, RECT& rcText, PRINTF_FORMAT_STRING const wchar_t *fmt, ... );
  32. void DrawColoredTextW( HFONT font, COLORREF clr, RECT& rcText, PRINTF_FORMAT_STRING const wchar_t *fmt, ... );
  33. void DrawColoredTextCharsetW( const char *font, int pointsize, int weight, DWORD charset, COLORREF clr, RECT& rcText, PRINTF_FORMAT_STRING const wchar_t *fmt, ... );
  34. void CalcTextRect( const char *font, int pointsize, int weight, int maxwidth, RECT& rcText, PRINTF_FORMAT_STRING const char *fmt, ... );
  35. // Draw text
  36. void DrawColoredText( const char *font, int pointsize, int weight, COLORREF clr, RECT& rcText, PRINTF_FORMAT_STRING const char *fmt, ... );
  37. void DrawColoredText( HFONT font, COLORREF clr, RECT& rcText, PRINTF_FORMAT_STRING const char *fmt, ... );
  38. void DrawColoredTextCharset( const char *font, int pointsize, int weight, DWORD charset, COLORREF clr, RECT& rcText, PRINTF_FORMAT_STRING const char *fmt, ... );
  39. void DrawColoredTextMultiline( const char *font, int pointsize, int weight, COLORREF clr, RECT& rcText, PRINTF_FORMAT_STRING const char *fmt, ... );
  40. // Draw a line
  41. void DrawColoredLine( COLORREF clr, int style, int width, int x1, int y1, int x2, int y2 );
  42. void DrawColoredPolyLine( COLORREF clr, int style, int width, CUtlVector< POINT >& points );
  43. // Draw a blending ramp
  44. POINTL DrawColoredRamp( COLORREF clr, int style, int width, int x1, int y1, int x2, int y2, float rate, float sustain );
  45. // Draw a filled rect
  46. void DrawFilledRect( COLORREF clr, int x1, int y1, int x2, int y2 );
  47. // Draw an outlined rect
  48. void DrawOutlinedRect( COLORREF clr, int style, int width, int x1, int y1, int x2, int y2 );
  49. void DrawOutlinedRect( COLORREF clr, int style, int width, RECT& rc );
  50. void DrawFilledRect( HBRUSH br, RECT& rc );
  51. void DrawFilledRect( COLORREF clr, RECT& rc );
  52. void DrawGradientFilledRect( RECT& rc, COLORREF clr1, COLORREF clr2, bool vertical );
  53. void DrawLine( int x1, int y1, int x2, int y2, COLORREF clr, int thickness );
  54. // Draw a triangle
  55. void DrawTriangleMarker( RECT& rc, COLORREF fill, bool inverted = false );
  56. void DrawCircle( COLORREF clr, int x, int y, int radius, bool filled = true );
  57. // Get width/height of draw area
  58. int GetWidth( void );
  59. int GetHeight( void );
  60. // Get client rect for drawing
  61. void GetClientRect( RECT& rc );
  62. void StartClipping( RECT& clipRect );
  63. void StopClipping( void );
  64. // Remap rect if we're using a clipped viewport
  65. void OffsetSubRect( RECT& rc );
  66. private:
  67. // Internal initializer
  68. void Init( mxWindow *widget, int x, int y, int w, int h, COLORREF bgColor);
  69. void ClipToRects( void );
  70. // The window we are drawing on
  71. HWND m_hWnd;
  72. // The final DC
  73. HDC m_dcReal;
  74. // The working DC
  75. HDC m_dcMemory;
  76. // Client area and offsets
  77. RECT m_rcClient;
  78. int m_x, m_y;
  79. int m_w, m_h;
  80. // Bitmap for drawing in the memory DC
  81. HBITMAP m_bmMemory;
  82. HBITMAP m_bmOld;
  83. // Remember the original default color
  84. COLORREF m_clrOld;
  85. CUtlVector < RECT > m_ClipRects;
  86. HRGN m_ClipRegion;
  87. };