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.

122 lines
4.8 KiB

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