ReactOS 0.4.17-dev-357-ga8f14ff
CStyledCursor Class Reference

#include <canvas.h>

Public Member Functions

 ~CStyledCursor ()
 
void SetStyle (BrushStyle style, INT zoom, INT radius, COLORREF color, BOOL is_rubber)
 
void SetCursor ()
 
 operator HCURSOR () const
 

Static Protected Member Functions

static HCURSOR CreateStyledCursor (BrushStyle style, INT zoom, INT radius, COLORREF color, BOOL is_rubber)
 

Protected Attributes

HCURSOR m_hCursor = NULL
 
BrushStyle m_style
 
INT m_zoom = -1
 
INT m_radius = -1
 
COLORREF m_color = CLR_INVALID
 
BOOL m_is_rubber = FALSE
 

Detailed Description

Definition at line 13 of file canvas.h.

Constructor & Destructor Documentation

◆ ~CStyledCursor()

CStyledCursor::~CStyledCursor ( )
inline

Definition at line 16 of file canvas.h.

17 {
18 if (m_hCursor)
20 }
HCURSOR m_hCursor
Definition: canvas.h:33
BOOL WINAPI DestroyCursor(_In_ HCURSOR)
Definition: cursoricon.c:3083

Member Function Documentation

◆ CreateStyledCursor()

HCURSOR CStyledCursor::CreateStyledCursor ( BrushStyle  style,
INT  zoom,
INT  radius,
COLORREF  color,
BOOL  is_rubber 
)
staticprotected

Definition at line 16 of file canvas.cpp.

17{
18 const INT diameter = 2 * radius;
19 if (diameter * zoom / DEFAULT_ZOOM <= 2)
20 {
22 return hCursor ? CopyCursor(hCursor) : NULL;
23 }
24
25 const INT crosshair1 = 6, crosshair2 = crosshair1 - 2;
26 const INT width = diameter + 2 * crosshair1, height = diameter + 2 * crosshair1;
27 DWORD hotX = width / 2, hotY = height / 2;
28
29 HDC hdcScreen = ::GetDC(NULL);
30 if (!hdcScreen)
31 return NULL;
32 HDC hdcMem = ::CreateCompatibleDC(hdcScreen);
33 if (!hdcMem)
34 {
35 ::ReleaseDC(NULL, hdcScreen);
36 return NULL;
37 }
38
39 RECT rc = { 0, 0, width, height };
40
41 // Create the AND mask bitmap. This must be monochrome (1bpp):
42 // white bits are transparent, black bits are opaque.
43 HBITMAP hbmMask = ::CreateBitmap(width, height, 1, 1, NULL);
44 if (hbmMask)
45 {
46 HBITMAP hbmOld = (HBITMAP)::SelectObject(hdcMem, hbmMask);
47
48 // Fill with white brush
50
51 if (!is_rubber)
52 {
53 // Draw crosshair with white pen
55 ::MoveToEx(hdcMem, 0, hotY, NULL);
56 ::LineTo(hdcMem, crosshair2, hotY);
57 ::MoveToEx(hdcMem, width - crosshair2, hotY, NULL);
58 ::LineTo(hdcMem, width, hotY);
59 ::MoveToEx(hdcMem, hotX, 0, NULL);
60 ::LineTo(hdcMem, hotX, crosshair2);
61 ::MoveToEx(hdcMem, hotX, height - crosshair2, NULL);
62 ::LineTo(hdcMem, hotX, height);
63 }
64
65 // Draw brush or erase with black color
66 if (is_rubber)
67 Erase(hdcMem, hotX, hotY, hotX, hotY, RGB(0, 0, 0), radius + 1);
68 else
69 Brush(hdcMem, hotX, hotY, hotX, hotY, RGB(0, 0, 0), style, diameter);
70
71 if (is_rubber)
72 InflateRect(&rc, -1, -1);
73
74 ::SelectObject(hdcMem, hbmOld);
75 }
76
77 // Create the color (XOR) bitmap
78 HBITMAP hbmColor = ::CreateCompatibleBitmap(hdcScreen, width, height);
79 if (hbmColor)
80 {
81 HBITMAP hbmOld = (HBITMAP)::SelectObject(hdcMem, hbmColor);
82
83 // Fill with black brush
85
86 if (is_rubber)
87 {
88 // Draw for rubber border
89 INT avg = (GetRValue(color) + GetGValue(color) + GetBValue(color)) / 3;
90 COLORREF color2 = (avg > 255 / 2) ? RGB(0, 0, 0) : RGB(255, 255, 255);
91 Erase(hdcMem, hotX, hotY, hotX, hotY, color2, radius + 1);
92 }
93 else
94 {
95 // Draw crosshair with white pen
97 ::MoveToEx(hdcMem, 0, hotY, NULL);
98 ::LineTo(hdcMem, crosshair2, hotY);
99 ::MoveToEx(hdcMem, width - crosshair2, hotY, NULL);
100 ::LineTo(hdcMem, width, hotY);
101 ::MoveToEx(hdcMem, hotX, 0, NULL);
102 ::LineTo(hdcMem, hotX, crosshair2);
103 ::MoveToEx(hdcMem, hotX, height - crosshair2, NULL);
104 ::LineTo(hdcMem, hotX, height);
105 }
106
107 // Draw brush or erase with color
108 if (is_rubber)
109 Erase(hdcMem, hotX, hotY, hotX, hotY, color, radius);
110 else
111 Brush(hdcMem, hotX, hotY, hotX, hotY, color, style, diameter);
112
113 ::SelectObject(hdcMem, hbmOld);
114 }
115
116 ::ReleaseDC(NULL, hdcScreen);
118
119 if (zoom != DEFAULT_ZOOM)
120 {
121 INT newWidth = width * zoom / DEFAULT_ZOOM;
122 INT newHeight = height * zoom / DEFAULT_ZOOM;
123 HBITMAP hbmMaskNew = CopyMonoImage(hbmMask, newWidth, newHeight, STRETCH_DELETESCANS);
124 HBITMAP hbmColorNew = CopyDIBImage(hbmColor, newWidth, newHeight, STRETCH_DELETESCANS);
125 ::DeleteObject(hbmMask);
126 ::DeleteObject(hbmColor);
127 hbmMask = hbmMaskNew;
128 hbmColor = hbmColorNew;
129 hotX = width * zoom / (2 * DEFAULT_ZOOM);
130 hotY = height * zoom / (2 * DEFAULT_ZOOM);
131 }
132
133 ICONINFO ii = { FALSE, hotX, hotY, hbmMask, hbmColor };
134 HCURSOR hCursor = (HCURSOR)::CreateIconIndirect(&ii);
135
136 ::DeleteObject(hbmMask);
137 ::DeleteObject(hbmColor);
138
139 return hCursor;
140}
Arabic default style
Definition: afstyles.h:94
#define DEFAULT_ZOOM
Definition: precomp.h:46
HBITMAP CopyMonoImage(HBITMAP hbm, INT cx, INT cy, INT stretchMode)
Definition: dib.cpp:87
HBITMAP CopyDIBImage(HBITMAP hbm, INT cx, INT cy, INT stretchMode)
Definition: dib.cpp:113
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
void Erase(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color, LONG radius)
Definition: drawing.cpp:115
#define RGB(r, g, b)
Definition: precomp.h:67
#define GetBValue(quad)
Definition: precomp.h:71
#define GetGValue(quad)
Definition: precomp.h:70
#define GetRValue(quad)
Definition: precomp.h:69
unsigned long DWORD
Definition: ntddk_ex.h:95
pKey DeleteObject()
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
GLuint color
Definition: glext.h:6243
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
int32_t INT
Definition: typedefs.h:58
HDC hdcMem
Definition: welcome.c:104
DWORD COLORREF
Definition: windef.h:100
HICON HCURSOR
Definition: windef.h:99
HGDIOBJ WINAPI GetStockObject(_In_ int)
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
BOOL WINAPI MoveToEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define WHITE_PEN
Definition: wingdi.h:905
#define WHITE_BRUSH
Definition: wingdi.h:902
#define BLACK_BRUSH
Definition: wingdi.h:896
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
BOOL WINAPI DeleteDC(_In_ HDC)
BOOL WINAPI LineTo(_In_ HDC, _In_ int, _In_ int)
#define STRETCH_DELETESCANS
Definition: wingdi.h:958
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HICON WINAPI CreateIconIndirect(_In_ PICONINFO)
Definition: cursoricon.c:2975
#define CopyCursor(c)
Definition: winuser.h:4389
#define IDC_CROSS
Definition: winuser.h:698
#define LoadCursor
Definition: winuser.h:5978
HDC WINAPI GetDC(_In_opt_ HWND)
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)

Referenced by SetStyle().

◆ operator HCURSOR()

CStyledCursor::operator HCURSOR ( ) const
inline

Definition at line 30 of file canvas.h.

30{ return m_hCursor; }

◆ SetCursor()

void CStyledCursor::SetCursor ( )
inline

Definition at line 24 of file canvas.h.

25 {
26 if (m_hCursor)
28 }
void SetCursor()
Definition: canvas.h:24

Referenced by CCanvasWindow::OnSetCursor(), and SetCursor().

◆ SetStyle()

void CStyledCursor::SetStyle ( BrushStyle  style,
INT  zoom,
INT  radius,
COLORREF  color,
BOOL  is_rubber 
)

Definition at line 142 of file canvas.cpp.

143{
144 if (m_hCursor &&
145 m_style == style &&
146 m_zoom == zoom &&
147 m_radius == radius &&
148 m_color == color &&
149 m_is_rubber == is_rubber)
150 {
151 return;
152 }
153
154 if (m_hCursor)
156
157 m_hCursor = CreateStyledCursor(style, zoom, radius, color, is_rubber);
158 m_style = style;
159 m_zoom = zoom;
160 m_radius = radius;
161 m_color = color;
162 m_is_rubber = is_rubber;
163}
COLORREF m_color
Definition: canvas.h:37
BOOL m_is_rubber
Definition: canvas.h:38
BrushStyle m_style
Definition: canvas.h:34
static HCURSOR CreateStyledCursor(BrushStyle style, INT zoom, INT radius, COLORREF color, BOOL is_rubber)
Definition: canvas.cpp:16
INT m_zoom
Definition: canvas.h:35
INT m_radius
Definition: canvas.h:36

Referenced by CCanvasWindow::OnSetCursor().

Member Data Documentation

◆ m_color

COLORREF CStyledCursor::m_color = CLR_INVALID
protected

Definition at line 37 of file canvas.h.

Referenced by SetStyle().

◆ m_hCursor

HCURSOR CStyledCursor::m_hCursor = NULL
protected

Definition at line 33 of file canvas.h.

Referenced by operator HCURSOR(), SetCursor(), SetStyle(), and ~CStyledCursor().

◆ m_is_rubber

BOOL CStyledCursor::m_is_rubber = FALSE
protected

Definition at line 38 of file canvas.h.

Referenced by SetStyle().

◆ m_radius

INT CStyledCursor::m_radius = -1
protected

Definition at line 36 of file canvas.h.

Referenced by SetStyle().

◆ m_style

BrushStyle CStyledCursor::m_style
protected

Definition at line 34 of file canvas.h.

Referenced by SetStyle().

◆ m_zoom

INT CStyledCursor::m_zoom = -1
protected

Definition at line 35 of file canvas.h.

Referenced by SetStyle().


The documentation for this class was generated from the following files: