ReactOS 0.4.17-dev-243-g1369312
CStyledCursor Class Reference

#include <canvas.h>

Public Member Functions

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

Static Protected Member Functions

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

Protected Attributes

HCURSOR m_hCursor = NULL
 
BrushStyle m_style
 
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  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 <= 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 const 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 ICONINFO ii = { FALSE, hotX, hotY, hbmMask, hbmColor };
120 HCURSOR hCursor = (HCURSOR)::CreateIconIndirect(&ii);
121
122 ::DeleteObject(hbmMask);
123 ::DeleteObject(hbmColor);
124
125 return hCursor;
126}
Arabic default style
Definition: afstyles.h:94
#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)
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  radius,
COLORREF  color,
BOOL  is_rubber 
)

Definition at line 128 of file canvas.cpp.

129{
130 if (m_hCursor && m_style == style && m_radius == radius && m_color == color &&
131 m_is_rubber == is_rubber)
132 {
133 return;
134 }
135
136 if (m_hCursor)
138
139 m_hCursor = CreateStyledCursor(style, radius, color, is_rubber);
140 m_style = style;
141 m_radius = radius;
142 m_color = color;
143 m_is_rubber = is_rubber;
144}
COLORREF m_color
Definition: canvas.h:36
static HCURSOR CreateStyledCursor(BrushStyle style, INT radius, COLORREF color, BOOL is_rubber)
Definition: canvas.cpp:16
BOOL m_is_rubber
Definition: canvas.h:37
BrushStyle m_style
Definition: canvas.h:34
INT m_radius
Definition: canvas.h:35

Referenced by CCanvasWindow::OnSetCursor().

Member Data Documentation

◆ m_color

COLORREF CStyledCursor::m_color = CLR_INVALID
protected

Definition at line 36 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 37 of file canvas.h.

Referenced by SetStyle().

◆ m_radius

INT CStyledCursor::m_radius = -1
protected

Definition at line 35 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().


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