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.

123 lines
4.6 KiB

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