ReactOS 0.4.16-dev-306-g647d351
mouse.cpp File Reference
#include "precomp.h"
#include <atlalloc.h>
Include dependency graph for mouse.cpp:

Go to the source code of this file.

Classes

struct  TwoPointDrawTool
 
struct  SmoothDrawTool
 
struct  SelectionBaseTool
 
struct  FreeSelTool
 
struct  RectSelTool
 
struct  RubberTool
 
struct  FillTool
 
struct  ColorTool
 
struct  ZoomTool
 
struct  PenTool
 
struct  BrushTool
 
struct  AirBrushTool
 
struct  TextTool
 
struct  LineTool
 
struct  BezierTool
 
struct  RectTool
 
struct  ShapeTool
 
struct  EllipseTool
 
struct  RRectTool
 

Macros

#define THRESHOULD_DEG   15
 

Typedefs

typedef enum DIRECTION DIRECTION
 

Enumerations

enum  DIRECTION {
  NO_DIRECTION = -1 , DIRECTION_HORIZONTAL , DIRECTION_VERTICAL , DIRECTION_DIAGONAL_RIGHT_DOWN ,
  DIRECTION_DIAGONAL_RIGHT_UP
}
 

Functions

void regularize (LONG x0, LONG y0, LONG &x1, LONG &y1)
 
void roundTo8Directions (LONG x0, LONG y0, LONG &x1, LONG &y1)
 
BOOL nearlyEqualPoints (INT x0, INT y0, INT x1, INT y1)
 
void getBoundaryOfPoints (RECT &rcBoundary, SIZE_T cPoints, const POINT *pPoints)
 
void ShiftPoints (INT dx, INT dy)
 
void BuildMaskFromPoints ()
 
static void pushToPoints (LONG x, LONG y)
 
static DIRECTION GetDirection (LONG x0, LONG y0, LONG x1, LONG y1)
 
static void RestrictDrawDirection (DIRECTION dir, LONG x0, LONG y0, LONG &x1, LONG &y1)
 

Variables

static SIZE_T s_cPoints = 0
 
static CHeapPtr< POINT, CLocalAllocators_dynamicPoints
 
static POINT s_staticPoints [512]
 
static SIZE_T s_maxPoints = _countof(s_staticPoints)
 
static LPPOINT s_pPoints = s_staticPoints
 
static POINT g_ptStart
 
static POINT g_ptEnd
 

Macro Definition Documentation

◆ THRESHOULD_DEG

#define THRESHOULD_DEG   15

Definition at line 220 of file mouse.cpp.

Typedef Documentation

◆ DIRECTION

Enumeration Type Documentation

◆ DIRECTION

Enumerator
NO_DIRECTION 
DIRECTION_HORIZONTAL 
DIRECTION_VERTICAL 
DIRECTION_DIAGONAL_RIGHT_DOWN 
DIRECTION_DIAGONAL_RIGHT_UP 

Definition at line 211 of file mouse.cpp.

212{
213 NO_DIRECTION = -1,
218} DIRECTION;
DIRECTION
Definition: mouse.cpp:212
@ NO_DIRECTION
Definition: mouse.cpp:213
@ DIRECTION_DIAGONAL_RIGHT_UP
Definition: mouse.cpp:217
@ DIRECTION_HORIZONTAL
Definition: mouse.cpp:214
@ DIRECTION_VERTICAL
Definition: mouse.cpp:215
@ DIRECTION_DIAGONAL_RIGHT_DOWN
Definition: mouse.cpp:216

Function Documentation

◆ BuildMaskFromPoints()

void BuildMaskFromPoints ( )

Definition at line 84 of file mouse.cpp.

85{
86 CRect rc;
88
89 ShiftPoints(-rc.left, -rc.top);
90
92 HBITMAP hbmMask = ::CreateBitmap(rc.Width(), rc.Height(), 1, 1, NULL);
93 HGDIOBJ hbmOld = ::SelectObject(hdcMem, hbmMask);
98 ::SelectObject(hdcMem, hbrOld);
99 ::SelectObject(hdcMem, hPenOld);
100 ::SelectObject(hdcMem, hbmOld);
102
103 selectionModel.setMask(rc, hbmMask);
104}
static LPPOINT s_pPoints
Definition: mouse.cpp:16
void ShiftPoints(INT dx, INT dy)
Definition: mouse.cpp:74
void getBoundaryOfPoints(RECT &rcBoundary, SIZE_T cPoints, const POINT *pPoints)
Definition: mouse.cpp:56
static SIZE_T s_cPoints
Definition: mouse.cpp:12
SelectionModel selectionModel
int Width() const noexcept
Definition: atltypes.h:461
int Height() const noexcept
Definition: atltypes.h:318
void setMask(const CRect &rc, HBITMAP hbmMask)
#define NULL
Definition: types.h:112
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
BOOL Polygon(CONST PPOINT UnsafePoints, int Count, int polyFillMode)
Definition: polytest.cpp:730
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
int32_t INT
Definition: typedefs.h:58
HDC hdcMem
Definition: welcome.c:104
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
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define WHITE_BRUSH
Definition: wingdi.h:902
#define NULL_PEN
Definition: wingdi.h:904
#define BLACK_BRUSH
Definition: wingdi.h:896
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
BOOL WINAPI DeleteDC(_In_ HDC)

Referenced by SelectionBaseTool::OnButtonUp().

◆ getBoundaryOfPoints()

void getBoundaryOfPoints ( RECT rcBoundary,
SIZE_T  cPoints,
const POINT pPoints 
)

Definition at line 56 of file mouse.cpp.

57{
58 POINT ptMin = { MAXLONG, MAXLONG }, ptMax = { (LONG)MINLONG, (LONG)MINLONG };
59 while (cPoints-- > 0)
60 {
61 LONG x = pPoints->x, y = pPoints->y;
62 ptMin = { min(x, ptMin.x), min(y, ptMin.y) };
63 ptMax = { max(x, ptMax.x), max(y, ptMax.y) };
64 ++pPoints;
65 }
66
67 ptMax.x += 1;
68 ptMax.y += 1;
69
70 CRect rc(ptMin, ptMax);
71 rcBoundary = rc;
72}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define min(a, b)
Definition: monoChain.cc:55
long LONG
Definition: pedump.c:60
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
#define max(a, b)
Definition: svc.c:63
#define MAXLONG
Definition: umtypes.h:116
#define MINLONG
Definition: umtypes.h:115

Referenced by BuildMaskFromPoints(), SmoothDrawTool::OnButtonUp(), and ShapeTool::OnEndDraw().

◆ GetDirection()

static DIRECTION GetDirection ( LONG  x0,
LONG  y0,
LONG  x1,
LONG  y1 
)
static

Definition at line 223 of file mouse.cpp.

224{
225 LONG dx = x1 - x0, dy = y1 - y0;
226
227 if (labs(dx) <= 8 && labs(dy) <= 8)
228 return NO_DIRECTION;
229
230 double radian = atan2((double)dy, (double)dx);
231 if (radian < DEG2RAD(-180 + THRESHOULD_DEG))
232 {
233 ATLTRACE("DIRECTION_HORIZONTAL: %ld\n", RAD2DEG(radian));
235 }
236 if (radian < DEG2RAD(-90 - THRESHOULD_DEG))
237 {
238 ATLTRACE("DIRECTION_DIAGONAL_RIGHT_DOWN: %ld\n", RAD2DEG(radian));
240 }
241 if (radian < DEG2RAD(-90 + THRESHOULD_DEG))
242 {
243 ATLTRACE("DIRECTION_VERTICAL: %ld\n", RAD2DEG(radian));
244 return DIRECTION_VERTICAL;
245 }
246 if (radian < DEG2RAD(-THRESHOULD_DEG))
247 {
248 ATLTRACE("DIRECTION_DIAGONAL_RIGHT_UP: %ld\n", RAD2DEG(radian));
250 }
251 if (radian < DEG2RAD(+THRESHOULD_DEG))
252 {
253 ATLTRACE("DIRECTION_HORIZONTAL: %ld\n", RAD2DEG(radian));
255 }
256 if (radian < DEG2RAD(+90 - THRESHOULD_DEG))
257 {
258 ATLTRACE("DIRECTION_DIAGONAL_RIGHT_DOWN: %ld\n", RAD2DEG(radian));
260 }
261 if (radian < DEG2RAD(+90 + THRESHOULD_DEG))
262 {
263 ATLTRACE("DIRECTION_VERTICAL: %ld\n", RAD2DEG(radian));
264 return DIRECTION_VERTICAL;
265 }
266 if (radian < DEG2RAD(+180 - THRESHOULD_DEG))
267 {
268 ATLTRACE("DIRECTION_DIAGONAL_RIGHT_UP: %ld\n", RAD2DEG(radian));
270 }
271 ATLTRACE("DIRECTION_HORIZONTAL: %ld\n", RAD2DEG(radian));
273}
valarray< _Tp > atan2(const valarray< _Tp > &__x, const valarray< _Tp > &__y)
Definition: _valarray.h:928
#define ATLTRACE(format,...)
Definition: atltrace.h:269
#define THRESHOULD_DEG
Definition: mouse.cpp:220
#define RAD2DEG(radian)
Definition: precomp.h:77
#define DEG2RAD(degree)
Definition: precomp.h:76
_Check_return_ long __cdecl labs(_In_ long x)
GLint dy
Definition: linetemp.h:97
GLint y0
Definition: linetemp.h:96
GLint x0
Definition: linetemp.h:95
GLint dx
Definition: linetemp.h:97
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG y1
Definition: winddi.h:3709
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3708

Referenced by SmoothDrawTool::OnMouseMove().

◆ nearlyEqualPoints()

BOOL nearlyEqualPoints ( INT  x0,
INT  y0,
INT  x1,
INT  y1 
)

Definition at line 49 of file mouse.cpp.

50{
53 return (abs(x1 - x0) <= cxThreshold) && (abs(y1 - y0) <= cyThreshold);
54}
ToolsModel toolsModel
Definition: toolsmodel.cpp:10
int GetLineWidth() const
Definition: toolsmodel.cpp:46
#define abs(i)
Definition: fconv.c:206
static int UnZoomed(int xy)
Definition: toolsmodel.h:155
#define SM_CXDRAG
Definition: winuser.h:1031
#define SM_CYDRAG
Definition: winuser.h:1032
int WINAPI GetSystemMetrics(_In_ int)

Referenced by ShapeTool::OnButtonUp().

◆ pushToPoints()

static void pushToPoints ( LONG  x,
LONG  y 
)
static

Definition at line 143 of file mouse.cpp.

144{
145 if (s_cPoints + 1 >= s_maxPoints)
146 {
147 SIZE_T newMax = s_maxPoints + 512;
148 SIZE_T cbNew = newMax * sizeof(POINT);
149 if (!s_dynamicPoints.ReallocateBytes(cbNew))
150 {
151 ATLTRACE("%d, %d, %d\n", (INT)s_cPoints, (INT)s_maxPoints, (INT)cbNew);
152 return;
153 }
154
157
159 s_maxPoints = newMax;
160 }
161
162 s_pPoints[s_cPoints++] = { x, y };
163}
static SIZE_T s_maxPoints
Definition: mouse.cpp:15
static POINT s_staticPoints[512]
Definition: mouse.cpp:14
static CHeapPtr< POINT, CLocalAllocator > s_dynamicPoints
Definition: mouse.cpp:13
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define POINT
Definition: precomp.h:30
#define CopyMemory
Definition: winbase.h:1735

Referenced by SmoothDrawTool::OnButtonDown(), SelectionBaseTool::OnButtonDown(), BezierTool::OnButtonDown(), ShapeTool::OnButtonDown(), SmoothDrawTool::OnButtonUp(), BezierTool::OnButtonUp(), ShapeTool::OnButtonUp(), SmoothDrawTool::OnMouseMove(), and SelectionBaseTool::OnMouseMove().

◆ regularize()

void regularize ( LONG  x0,
LONG  y0,
LONG x1,
LONG y1 
)

Definition at line 22 of file mouse.cpp.

23{
24 if (labs(x1 - x0) >= labs(y1 - y0))
25 y1 = y0 + (y1 > y0 ? labs(x1 - x0) : -labs(x1 - x0));
26 else
27 x1 = x0 + (x1 > x0 ? labs(y1 - y0) : -labs(y1 - y0));
28}

Referenced by SelectionBaseTool::OnButtonUp(), RectTool::OnDrawOverlayOnImage(), EllipseTool::OnDrawOverlayOnImage(), RRectTool::OnDrawOverlayOnImage(), and SelectionBaseTool::OnMouseMove().

◆ RestrictDrawDirection()

static void RestrictDrawDirection ( DIRECTION  dir,
LONG  x0,
LONG  y0,
LONG x1,
LONG y1 
)
static

Definition at line 276 of file mouse.cpp.

277{
278 switch (dir)
279 {
280 case NO_DIRECTION:
281 default:
282 return;
283
285 y1 = y0;
286 break;
287
289 x1 = x0;
290 break;
291
293 y1 = y0 + (x1 - x0);
294 break;
295
297 x1 = x0 - (y1 - y0);
298 break;
299 }
300}
unsigned int dir
Definition: maze.c:112

Referenced by SmoothDrawTool::OnButtonUp(), and SmoothDrawTool::OnMouseMove().

◆ roundTo8Directions()

void roundTo8Directions ( LONG  x0,
LONG  y0,
LONG x1,
LONG y1 
)

Definition at line 31 of file mouse.cpp.

32{
33 if (labs(x1 - x0) >= labs(y1 - y0))
34 {
35 if (labs(y1 - y0) * 5 < labs(x1 - x0) * 2)
36 y1 = y0;
37 else
38 y1 = y0 + (y1 > y0 ? labs(x1 - x0) : -labs(x1 - x0));
39 }
40 else
41 {
42 if (labs(x1 - x0) * 5 < labs(y1 - y0) * 2)
43 x1 = x0;
44 else
45 x1 = x0 + (x1 > x0 ? labs(y1 - y0) : -labs(y1 - y0));
46 }
47}

Referenced by ShapeTool::OnButtonDown(), ShapeTool::OnButtonUp(), LineTool::OnDrawOverlayOnImage(), and ShapeTool::OnMouseMove().

◆ ShiftPoints()

void ShiftPoints ( INT  dx,
INT  dy 
)

Definition at line 74 of file mouse.cpp.

75{
76 for (SIZE_T i = 0; i < s_cPoints; ++i)
77 {
78 POINT& pt = s_pPoints[i];
79 pt.x += dx;
80 pt.y += dy;
81 }
82}
#define pt(x, y)
Definition: drawing.c:79
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by BuildMaskFromPoints().

Variable Documentation

◆ g_ptEnd

◆ g_ptStart

◆ s_cPoints

◆ s_dynamicPoints

CHeapPtr<POINT, CLocalAllocator> s_dynamicPoints
static

Definition at line 13 of file mouse.cpp.

Referenced by pushToPoints(), and ToolBase::reset().

◆ s_maxPoints

SIZE_T s_maxPoints = _countof(s_staticPoints)
static

Definition at line 15 of file mouse.cpp.

Referenced by pushToPoints(), and ToolBase::reset().

◆ s_pPoints

◆ s_staticPoints

POINT s_staticPoints[512]
static

Definition at line 14 of file mouse.cpp.

Referenced by pushToPoints(), and ToolBase::reset().