ReactOS 0.4.15-dev-7674-gc0b4db1
CCanvasWindow Class Reference

#include <canvas.h>

Inheritance diagram for CCanvasWindow:
Collaboration diagram for CCanvasWindow:

Public Member Functions

 DECLARE_WND_CLASS_EX (L"ReactOSPaintCanvas", CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW, COLOR_APPWORKSPACE) CCanvasWindow()
 
virtual ~CCanvasWindow ()
 
VOID OnEndDraw (BOOL bCancel)
 
VOID updateScrollRange ()
 
VOID updateScrollPos (INT x=0, INT y=0)
 
VOID ImageToCanvas (POINT &pt)
 
VOID ImageToCanvas (RECT &rc)
 
VOID CanvasToImage (POINT &pt)
 
VOID CanvasToImage (RECT &rc)
 
VOID GetImageRect (RECT &rc)
 
VOID getNewZoomRect (CRect &rcView, INT newZoom, CPoint ptTarget)
 
VOID zoomTo (INT newZoom, LONG left=0, LONG top=0)
 

Public Attributes

BOOL m_drawing
 

Protected Member Functions

HITTEST CanvasHitTest (POINT pt)
 
RECT GetBaseRect ()
 
VOID DoDraw (HDC hDC, RECT &rcClient, RECT &rcPaint)
 
VOID OnHVScroll (WPARAM wParam, INT fnBar)
 
LRESULT OnSize (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnHScroll (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnVScroll (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnEraseBkgnd (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnPaint (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnMouseMove (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnKeyDown (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnSetCursor (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnMouseWheel (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnCancelMode (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnCaptureChanged (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnCtlColorEdit (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnPaletteModelColorChanged (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnButtonDown (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnButtonDblClk (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnButtonUp (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 

Protected Attributes

HITTEST m_hitCanvasSizeBox
 
POINT m_ptOrig
 
HBITMAP m_ahbmCached [2]
 
CRect m_rcResizing
 
UINT m_nMouseDownMsg = 0
 

Detailed Description

Definition at line 10 of file canvas.h.

Constructor & Destructor Documentation

◆ ~CCanvasWindow()

CCanvasWindow::~CCanvasWindow ( )
virtual

Definition at line 23 of file canvas.cpp.

24{
25 if (m_ahbmCached[0])
27 if (m_ahbmCached[1])
29}
HBITMAP m_ahbmCached[2]
Definition: canvas.h:60
pKey DeleteObject()

Member Function Documentation

◆ CanvasHitTest()

HITTEST CCanvasWindow::CanvasHitTest ( POINT  pt)
protected

Definition at line 71 of file canvas.cpp.

72{
74 return HIT_INNER;
75 RECT rcBase = GetBaseRect();
76 return getSizeBoxHitTest(pt, &rcBase);
77}
SelectionModel selectionModel
@ HIT_INNER
Definition: precomp.h:66
CTextEditWindow textEditWindow
Definition: textedit.cpp:12
RECT GetBaseRect()
Definition: canvas.cpp:31
#define pt(x, y)
Definition: drawing.c:79
HITTEST getSizeBoxHitTest(POINT pt, LPCRECT prcBase)
Definition: sizebox.cpp:80
BOOL WINAPI IsWindowVisible(_In_ HWND)

Referenced by OnButtonDown(), and OnSetCursor().

◆ CanvasToImage() [1/2]

VOID CCanvasWindow::CanvasToImage ( POINT pt)

Definition at line 53 of file canvas.cpp.

54{
57 UnZoomed(pt);
58}
#define GRIP_SIZE
Definition: precomp.h:43
static int UnZoomed(int xy)
Definition: toolsmodel.h:155
#define SB_VERT
Definition: winuser.h:553
int WINAPI GetScrollPos(_In_ HWND, _In_ int)
#define SB_HORZ
Definition: winuser.h:552

Referenced by DoDraw(), CTextEditWindow::InvalidateEditRect(), OnButtonDblClk(), OnButtonDown(), OnButtonUp(), OnMouseMove(), and zoomTo().

◆ CanvasToImage() [2/2]

VOID CCanvasWindow::CanvasToImage ( RECT rc)

Definition at line 60 of file canvas.cpp.

61{
63 UnZoomed(rc);
64}
BOOL WINAPI OffsetRect(_Inout_ LPRECT, _In_ int, _In_ int)

◆ DECLARE_WND_CLASS_EX()

CCanvasWindow::DECLARE_WND_CLASS_EX ( L"ReactOSPaintCanvas"  ,
CS_DBLCLKS|CS_HREDRAW CS_VREDRAW,
COLOR_APPWORKSPACE   
)

◆ DoDraw()

VOID CCanvasWindow::DoDraw ( HDC  hDC,
RECT rcClient,
RECT rcPaint 
)
protected

Definition at line 122 of file canvas.cpp.

123{
124 // This is the target area we have to draw on
125 CRect rcCanvasDraw;
126 rcCanvasDraw.IntersectRect(&rcClient, &rcPaint);
127
128 // We use a memory bitmap to reduce flickering
129 HDC hdcMem0 = ::CreateCompatibleDC(hDC);
130 m_ahbmCached[0] = CachedBufferDIB(m_ahbmCached[0], rcClient.right, rcClient.bottom);
131 HGDIOBJ hbm0Old = ::SelectObject(hdcMem0, m_ahbmCached[0]);
132
133 // Fill the background on hdcMem0
134 ::FillRect(hdcMem0, &rcCanvasDraw, (HBRUSH)(COLOR_APPWORKSPACE + 1));
135
136 // Draw the sizeboxes if necessary
137 RECT rcBase = GetBaseRect();
139 drawSizeBoxes(hdcMem0, &rcBase, FALSE, &rcCanvasDraw);
140
141 // Calculate image size
142 CRect rcImage;
143 GetImageRect(rcImage);
144 SIZE sizeImage = { imageModel.GetWidth(), imageModel.GetHeight() };
145
146 // Calculate the target area on the image
147 CRect rcImageDraw = rcCanvasDraw;
148 CanvasToImage(rcImageDraw);
149 rcImageDraw.IntersectRect(&rcImageDraw, &rcImage);
150
151 // Consider rounding down by zooming
152 rcImageDraw.right += 1;
153 rcImageDraw.bottom += 1;
154
155 // hdcMem1 <-- imageModel
156 HDC hdcMem1 = ::CreateCompatibleDC(hDC);
157 m_ahbmCached[1] = CachedBufferDIB(m_ahbmCached[1], sizeImage.cx, sizeImage.cy);
158 HGDIOBJ hbm1Old = ::SelectObject(hdcMem1, m_ahbmCached[1]);
159 ::BitBlt(hdcMem1, rcImageDraw.left, rcImageDraw.top, rcImageDraw.Width(), rcImageDraw.Height(),
160 imageModel.GetDC(), rcImageDraw.left, rcImageDraw.top, SRCCOPY);
161
162 // Draw overlay #1 on hdcMem1
164
165 // Transfer the bits with stretch (hdcMem0 <-- hdcMem1)
166 ImageToCanvas(rcImage);
167 ::StretchBlt(hdcMem0, rcImage.left, rcImage.top, rcImage.Width(), rcImage.Height(),
168 hdcMem1, 0, 0, sizeImage.cx, sizeImage.cy, SRCCOPY);
169
170 // Clean up hdcMem1
171 ::SelectObject(hdcMem1, hbm1Old);
172 ::DeleteDC(hdcMem1);
173
174 // Draw the grid on hdcMem0
175 if (g_showGrid && toolsModel.GetZoom() >= 4000)
176 {
177 HPEN oldPen = (HPEN) ::SelectObject(hdcMem0, ::CreatePen(PS_SOLID, 1, RGB(160, 160, 160)));
178 for (INT counter = 0; counter < sizeImage.cy; counter++)
179 {
180 POINT pt0 = { 0, counter }, pt1 = { sizeImage.cx, counter };
181 ImageToCanvas(pt0);
182 ImageToCanvas(pt1);
183 ::MoveToEx(hdcMem0, pt0.x, pt0.y, NULL);
184 ::LineTo(hdcMem0, pt1.x, pt1.y);
185 }
186 for (INT counter = 0; counter < sizeImage.cx; counter++)
187 {
188 POINT pt0 = { counter, 0 }, pt1 = { counter, sizeImage.cy };
189 ImageToCanvas(pt0);
190 ImageToCanvas(pt1);
191 ::MoveToEx(hdcMem0, pt0.x, pt0.y, NULL);
192 ::LineTo(hdcMem0, pt1.x, pt1.y);
193 }
194 ::DeleteObject(::SelectObject(hdcMem0, oldPen));
195 }
196
197 // Draw overlay #2 on hdcMem0
199
200 // Draw new frame on hdcMem0 if any
202 DrawXorRect(hdcMem0, &m_rcResizing);
203
204 // Transfer the bits (hDC <-- hdcMem0)
205 ::BitBlt(hDC, rcCanvasDraw.left, rcCanvasDraw.top, rcCanvasDraw.Width(), rcCanvasDraw.Height(),
206 hdcMem0, rcCanvasDraw.left, rcCanvasDraw.top, SRCCOPY);
207
208 // Clean up hdcMem0
209 ::SelectObject(hdcMem0, hbm0Old);
210 ::DeleteDC(hdcMem0);
211}
static HDC hDC
Definition: 3dtext.c:33
BOOL g_showGrid
Definition: main.cpp:22
ToolsModel toolsModel
Definition: toolsmodel.cpp:10
@ HIT_NONE
Definition: precomp.h:56
HITTEST m_hitCanvasSizeBox
Definition: canvas.h:58
VOID ImageToCanvas(POINT &pt)
Definition: canvas.cpp:40
VOID CanvasToImage(POINT &pt)
Definition: canvas.cpp:53
CRect m_rcResizing
Definition: canvas.h:61
VOID GetImageRect(RECT &rc)
Definition: canvas.cpp:66
BOOL IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2) noexcept
Definition: atltypes.h:346
int Width() const noexcept
Definition: atltypes.h:461
int Height() const noexcept
Definition: atltypes.h:318
BOOL IsRectEmpty() const noexcept
Definition: atltypes.h:351
int GetWidth() const
Definition: history.cpp:253
int GetHeight() const
Definition: history.cpp:258
HDC GetDC()
Definition: history.cpp:271
void OnDrawOverlayOnCanvas(HDC hdc)
Definition: mouse.cpp:1191
void OnDrawOverlayOnImage(HDC hdc)
Definition: mouse.cpp:1186
int GetZoom() const
Definition: toolsmodel.cpp:261
HBITMAP CachedBufferDIB(HBITMAP hbm, int minimalWidth, int minimalHeight)
Definition: dib.cpp:115
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
void DrawXorRect(HDC hdc, const RECT *prc)
Definition: drawing.cpp:362
static VOID NTAPI BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:49
#define RGB(r, g, b)
Definition: precomp.h:62
ImageModel imageModel
Definition: history.cpp:11
static HDC
Definition: imagelist.c:92
VOID drawSizeBoxes(HDC hdc, LPCRECT prcBase, BOOL bDrawFrame, LPCRECT prcPaint)
Definition: sizebox.cpp:103
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
int32_t INT
Definition: typedefs.h:58
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
BOOL WINAPI MoveToEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL WINAPI StretchBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_opt_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
#define SRCCOPY
Definition: wingdi.h:333
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
BOOL WINAPI DeleteDC(_In_ HDC)
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
BOOL WINAPI LineTo(_In_ HDC, _In_ int, _In_ int)
#define PS_SOLID
Definition: wingdi.h:586
#define COLOR_APPWORKSPACE
Definition: winuser.h:924

Referenced by OnPaint().

◆ GetBaseRect()

RECT CCanvasWindow::GetBaseRect ( )
protected

Definition at line 31 of file canvas.cpp.

32{
33 CRect rcBase;
34 GetImageRect(rcBase);
35 ImageToCanvas(rcBase);
37 return rcBase;
38}
void InflateRect(int x, int y) noexcept
Definition: atltypes.h:323

Referenced by CanvasHitTest(), and DoDraw().

◆ GetImageRect()

VOID CCanvasWindow::GetImageRect ( RECT rc)

◆ getNewZoomRect()

VOID CCanvasWindow::getNewZoomRect ( CRect rcView,
INT  newZoom,
CPoint  ptTarget 
)

Definition at line 79 of file canvas.cpp.

80{
81 CRect rcImage;
82 GetImageRect(rcImage);
83 ImageToCanvas(rcImage);
84
85 // Calculate the zoom rectangle
86 INT oldZoom = toolsModel.GetZoom();
87 GetClientRect(rcView);
88 LONG cxView = rcView.right * oldZoom / newZoom, cyView = rcView.bottom * oldZoom / newZoom;
89 rcView.SetRect(ptTarget.x - cxView / 2, ptTarget.y - cyView / 2,
90 ptTarget.x + cxView / 2, ptTarget.y + cyView / 2);
91
92 // Shift the rectangle if necessary
93 INT dx = 0, dy = 0;
94 if (rcView.left < rcImage.left)
95 dx = rcImage.left - rcView.left;
96 else if (rcImage.right < rcView.right)
97 dx = rcImage.right - rcView.right;
98 if (rcView.top < rcImage.top)
99 dy = rcImage.top - rcView.top;
100 else if (rcImage.bottom < rcView.bottom)
101 dy = rcImage.bottom - rcView.bottom;
102 rcView.OffsetRect(dx, dy);
103
104 rcView.IntersectRect(&rcView, &rcImage);
105}
void OffsetRect(int x, int y) noexcept
Definition: atltypes.h:403
void SetRect(int x1, int y1, int x2, int y2) noexcept
Definition: atltypes.h:423
GLint dy
Definition: linetemp.h:97
GLint dx
Definition: linetemp.h:97
long LONG
Definition: pedump.c:60
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)

Referenced by ZoomTool::getNewZoomRect().

◆ ImageToCanvas() [1/2]

◆ ImageToCanvas() [2/2]

VOID CCanvasWindow::ImageToCanvas ( RECT rc)

Definition at line 47 of file canvas.cpp.

◆ OnButtonDblClk()

LRESULT CCanvasWindow::OnButtonDblClk ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 372 of file canvas.cpp.

373{
376
379 m_nMouseDownMsg = 0;
380
383 Invalidate();
384 return 0;
385}
BOOL m_drawing
Definition: canvas.h:43
UINT m_nMouseDownMsg
Definition: canvas.h:82
void resetTool()
Definition: toolsmodel.cpp:302
void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick)
Definition: mouse.cpp:1152
LPARAM lParam
Definition: combotst.c:139
#define TRUE
Definition: types.h:120
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:300
#define GET_X_LPARAM(lp)
Definition: windowsx.h:299
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2890
#define WM_LBUTTONDBLCLK
Definition: winuser.h:1777

◆ OnButtonDown()

LRESULT CCanvasWindow::OnButtonDown ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 300 of file canvas.cpp.

301{
303
304 m_nMouseDownMsg = nMsg;
305 BOOL bLeftButton = (nMsg == WM_LBUTTONDOWN);
306
307 if (nMsg == WM_MBUTTONDOWN)
308 {
309 m_ptOrig = pt;
310 SetCapture();
312 return 0;
313 }
314
315 HITTEST hitSelection = selectionModel.hitTest(pt);
316 if (hitSelection != HIT_NONE)
317 {
318 m_drawing = TRUE;
320 SetCapture();
321 toolsModel.OnButtonDown(bLeftButton, pt.x, pt.y, FALSE);
322 Invalidate();
323 return 0;
324 }
325
326 HITTEST hit = CanvasHitTest(pt);
327 if (hit == HIT_NONE || hit == HIT_BORDER)
328 {
329 switch (toolsModel.GetActiveTool())
330 {
331 case TOOL_BEZIER:
332 case TOOL_SHAPE:
334 Invalidate();
335 break;
336
337 case TOOL_FREESEL:
338 case TOOL_RECTSEL:
340 Invalidate();
341 break;
342
343 default:
344 break;
345 }
346
347 toolsModel.resetTool(); // resets the point-buffer of the polygon and bezier functions
348 return 0;
349 }
350
352
353 if (hit == HIT_INNER)
354 {
355 m_drawing = TRUE;
356 SetCapture();
357 toolsModel.OnButtonDown(bLeftButton, pt.x, pt.y, FALSE);
358 Invalidate();
359 return 0;
360 }
361
362 if (bLeftButton)
363 {
364 m_hitCanvasSizeBox = hit;
365 m_ptOrig = pt;
366 SetCapture();
367 }
368
369 return 0;
370}
HINSTANCE g_hinstExe
Definition: main.cpp:17
HITTEST
Definition: precomp.h:55
@ HIT_BORDER
Definition: precomp.h:65
#define IDC_HANDDRAG
Definition: resource.h:25
HITTEST CanvasHitTest(POINT pt)
Definition: canvas.cpp:71
POINT m_ptOrig
Definition: canvas.h:59
HITTEST hitTest(POINT ptCanvas)
void OnEndDraw(BOOL bCancel)
Definition: mouse.cpp:1178
TOOLTYPE GetActiveTool() const
Definition: toolsmodel.cpp:134
unsigned int BOOL
Definition: ntddk_ex.h:94
@ TOOL_SHAPE
Definition: toolsmodel.h:25
@ TOOL_BEZIER
Definition: toolsmodel.h:23
@ TOOL_FREESEL
Definition: toolsmodel.h:12
@ TOOL_RECTSEL
Definition: toolsmodel.h:13
HWND WINAPI SetCapture(_In_ HWND hWnd)
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
#define WM_LBUTTONDOWN
Definition: winuser.h:1775
HCURSOR WINAPI LoadCursorW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2088
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define WM_MBUTTONDOWN
Definition: winuser.h:1781

◆ OnButtonUp()

LRESULT CCanvasWindow::OnButtonUp ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 513 of file canvas.cpp.

514{
517
519
520 BOOL bLeftButton = (m_nMouseDownMsg == WM_LBUTTONDOWN);
521 m_nMouseDownMsg = 0;
522
523 if (m_drawing)
524 {
526 toolsModel.OnButtonUp(bLeftButton, pt.x, pt.y);
527 Invalidate(FALSE);
529 return 0;
530 }
531
532 if (m_hitCanvasSizeBox == HIT_NONE || !bLeftButton)
533 return 0;
534
535 // Resize the image
536 INT cxImage = imageModel.GetWidth(), cyImage = imageModel.GetHeight();
537 INT cxDelta = pt.x - m_ptOrig.x;
538 INT cyDelta = pt.y - m_ptOrig.y;
539 switch (m_hitCanvasSizeBox)
540 {
541 case HIT_UPPER_LEFT:
542 imageModel.Crop(cxImage - cxDelta, cyImage - cyDelta, cxDelta, cyDelta);
543 break;
544 case HIT_UPPER_CENTER:
545 imageModel.Crop(cxImage, cyImage - cyDelta, 0, cyDelta);
546 break;
547 case HIT_UPPER_RIGHT:
548 imageModel.Crop(cxImage + cxDelta, cyImage - cyDelta, 0, cyDelta);
549 break;
550 case HIT_MIDDLE_LEFT:
551 imageModel.Crop(cxImage - cxDelta, cyImage, cxDelta, 0);
552 break;
553 case HIT_MIDDLE_RIGHT:
554 imageModel.Crop(cxImage + cxDelta, cyImage, 0, 0);
555 break;
556 case HIT_LOWER_LEFT:
557 imageModel.Crop(cxImage - cxDelta, cyImage + cyDelta, cxDelta, 0);
558 break;
559 case HIT_LOWER_CENTER:
560 imageModel.Crop(cxImage, cyImage + cyDelta, 0, 0);
561 break;
562 case HIT_LOWER_RIGHT:
563 imageModel.Crop(cxImage + cxDelta, cyImage + cyDelta, 0, 0);
564 break;
565 default:
566 break;
567 }
569
571
573 toolsModel.resetTool(); // resets the point-buffer of the polygon and bezier functions
575 Invalidate(TRUE);
576 return 0;
577}
HWND g_hStatusBar
Definition: main.cpp:23
BOOL g_imageSaved
Definition: main.cpp:21
@ HIT_LOWER_RIGHT
Definition: precomp.h:64
@ HIT_LOWER_CENTER
Definition: precomp.h:63
@ HIT_UPPER_LEFT
Definition: precomp.h:57
@ HIT_LOWER_LEFT
Definition: precomp.h:62
@ HIT_UPPER_CENTER
Definition: precomp.h:58
@ HIT_UPPER_RIGHT
Definition: precomp.h:59
@ HIT_MIDDLE_RIGHT
Definition: precomp.h:61
@ HIT_MIDDLE_LEFT
Definition: precomp.h:60
VOID updateScrollRange()
Definition: canvas.cpp:213
void SetRectEmpty() noexcept
Definition: atltypes.h:431
void Crop(int nWidth, int nHeight, int nOffsetX=0, int nOffsetY=0)
Definition: history.cpp:191
void OnButtonUp(BOOL bLeftButton, LONG x, LONG y)
Definition: mouse.cpp:1169
#define L(x)
Definition: ntvdm.h:50
#define SB_SETTEXT
Definition: commctrl.h:1949
LONG_PTR LPARAM
Definition: windef.h:208
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

◆ OnCancelMode()

LRESULT CCanvasWindow::OnCancelMode ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 664 of file canvas.cpp.

665{
666 // Cancel dragging
669 Invalidate(TRUE);
670 return 0;
671}

◆ OnCaptureChanged()

LRESULT CCanvasWindow::OnCaptureChanged ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 678 of file canvas.cpp.

679{
681 return 0;
682}

◆ OnCtlColorEdit()

LRESULT CCanvasWindow::OnCtlColorEdit ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 708 of file canvas.cpp.

709{
713}
COLORREF GetFgColor() const
WPARAM wParam
Definition: combotst.c:138
PaletteModel paletteModel
LONG_PTR LRESULT
Definition: windef.h:209
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define TRANSPARENT
Definition: wingdi.h:950
#define NULL_BRUSH
Definition: wingdi.h:901
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:918

◆ OnEndDraw()

VOID CCanvasWindow::OnEndDraw ( BOOL  bCancel)

Definition at line 701 of file canvas.cpp.

702{
704 toolsModel.OnEndDraw(bCancel);
705 Invalidate(FALSE);
706}

Referenced by CMainWindow::ConfirmSave(), CMainWindow::OnCommand(), OnKeyDown(), and CMainWindow::saveImage().

◆ OnEraseBkgnd()

LRESULT CCanvasWindow::OnEraseBkgnd ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 684 of file canvas.cpp.

685{
686 return TRUE; // do nothing => transparent background
687}

◆ OnHScroll()

LRESULT CCanvasWindow::OnHScroll ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 288 of file canvas.cpp.

289{
291 return 0;
292}
VOID OnHVScroll(WPARAM wParam, INT fnBar)
Definition: canvas.cpp:258

◆ OnHVScroll()

VOID CCanvasWindow::OnHVScroll ( WPARAM  wParam,
INT  fnBar 
)
protected

Definition at line 258 of file canvas.cpp.

259{
260 SCROLLINFO si;
261 si.cbSize = sizeof(SCROLLINFO);
262 si.fMask = SIF_ALL;
263 GetScrollInfo(fnBar, &si);
264 switch (LOWORD(wParam))
265 {
266 case SB_THUMBTRACK:
267 case SB_THUMBPOSITION:
268 si.nPos = (SHORT)HIWORD(wParam);
269 break;
270 case SB_LINELEFT:
271 si.nPos -= 5;
272 break;
273 case SB_LINERIGHT:
274 si.nPos += 5;
275 break;
276 case SB_PAGELEFT:
277 si.nPos -= si.nPage;
278 break;
279 case SB_PAGERIGHT:
280 si.nPos += si.nPage;
281 break;
282 }
283 si.nPos = max(min(si.nPos, si.nMax), si.nMin);
284 SetScrollInfo(fnBar, &si);
285 Invalidate();
286}
#define min(a, b)
Definition: monoChain.cc:55
#define LOWORD(l)
Definition: pedump.c:82
short SHORT
Definition: pedump.c:59
#define max(a, b)
Definition: svc.c:63
#define HIWORD(l)
Definition: typedefs.h:247
#define SB_THUMBTRACK
Definition: winuser.h:573
struct tagSCROLLINFO SCROLLINFO
#define SB_PAGERIGHT
Definition: winuser.h:571
#define SB_LINERIGHT
Definition: winuser.h:567
#define SB_LINELEFT
Definition: winuser.h:566
#define SIF_ALL
Definition: winuser.h:1231
int WINAPI SetScrollInfo(_In_ HWND, _In_ int, _In_ LPCSCROLLINFO, _In_ BOOL)
BOOL WINAPI GetScrollInfo(_In_ HWND, _In_ int, _Inout_ LPSCROLLINFO)
#define SB_PAGELEFT
Definition: winuser.h:570
#define SB_THUMBPOSITION
Definition: winuser.h:572

Referenced by OnHScroll(), and OnVScroll().

◆ OnKeyDown()

LRESULT CCanvasWindow::OnKeyDown ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 649 of file canvas.cpp.

650{
651 if (wParam == VK_ESCAPE)
652 {
655 m_nMouseDownMsg = 0;
658 Invalidate(TRUE);
659 }
660
661 return 0;
662}
VOID OnEndDraw(BOOL bCancel)
Definition: canvas.cpp:701
#define VK_ESCAPE
Definition: winuser.h:2213

◆ OnMouseMove()

LRESULT CCanvasWindow::OnMouseMove ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 387 of file canvas.cpp.

388{
390
392 {
393 INT x = GetScrollPos(SB_HORZ) - (pt.x - m_ptOrig.x);
394 INT y = GetScrollPos(SB_VERT) - (pt.y - m_ptOrig.y);
397 m_ptOrig = pt;
398 return 0;
399 }
400
402
404 Invalidate();
405
407 {
408 TRACKMOUSEEVENT tme = { sizeof(tme) };
409 tme.dwFlags = TME_LEAVE;
410 tme.hwndTrack = m_hWnd;
411 tme.dwHoverTime = 0;
412 ::TrackMouseEvent(&tme);
413
414 if (!m_drawing)
415 {
416 CRect rcImage;
417 GetImageRect(rcImage);
418
419 CStringW strCoord;
420 if (rcImage.PtInRect(pt))
421 strCoord.Format(L"%ld, %ld", pt.x, pt.y);
423 }
424 }
425
427 {
429 return 0;
430 }
431
432 if (m_hitCanvasSizeBox == HIT_NONE || ::GetCapture() != m_hWnd)
433 return 0;
434
435 // Dragging now... Calculate the new size
436 INT cxImage = imageModel.GetWidth(), cyImage = imageModel.GetHeight();
437 INT cxDelta = pt.x - m_ptOrig.x;
438 INT cyDelta = pt.y - m_ptOrig.y;
439 switch (m_hitCanvasSizeBox)
440 {
441 case HIT_UPPER_LEFT:
442 cxImage -= cxDelta;
443 cyImage -= cyDelta;
444 break;
445 case HIT_UPPER_CENTER:
446 cyImage -= cyDelta;
447 break;
448 case HIT_UPPER_RIGHT:
449 cxImage += cxDelta;
450 cyImage -= cyDelta;
451 break;
452 case HIT_MIDDLE_LEFT:
453 cxImage -= cxDelta;
454 break;
455 case HIT_MIDDLE_RIGHT:
456 cxImage += cxDelta;
457 break;
458 case HIT_LOWER_LEFT:
459 cxImage -= cxDelta;
460 cyImage += cyDelta;
461 break;
462 case HIT_LOWER_CENTER:
463 cyImage += cyDelta;
464 break;
465 case HIT_LOWER_RIGHT:
466 cxImage += cxDelta;
467 cyImage += cyDelta;
468 break;
469 default:
470 return 0;
471 }
472
473 // Limit bitmap size
474 cxImage = max(1, cxImage);
475 cyImage = max(1, cyImage);
476 cxImage = min(MAXWORD, cxImage);
477 cyImage = min(MAXWORD, cyImage);
478
479 // Display new size
480 CStringW strSize;
481 strSize.Format(L"%d x %d", cxImage, cyImage);
483
484 // Dragging now... Fix the position...
485 CRect rcResizing = { 0, 0, cxImage, cyImage };
486 switch (m_hitCanvasSizeBox)
487 {
488 case HIT_UPPER_LEFT:
489 rcResizing.OffsetRect(cxDelta, cyDelta);
490 break;
491 case HIT_UPPER_CENTER:
492 rcResizing.OffsetRect(0, cyDelta);
493 break;
494 case HIT_UPPER_RIGHT:
495 rcResizing.OffsetRect(0, cyDelta);
496 break;
497 case HIT_MIDDLE_LEFT:
498 rcResizing.OffsetRect(cxDelta, 0);
499 break;
500 case HIT_LOWER_LEFT:
501 rcResizing.OffsetRect(cxDelta, 0);
502 break;
503 default:
504 break;
505 }
506 ImageToCanvas(rcResizing);
507 m_rcResizing = rcResizing;
508 Invalidate(TRUE);
509
510 return 0;
511}
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:818
BOOL PtInRect(POINT point) const noexcept
Definition: atltypes.h:418
BOOL IsSelection() const
Definition: toolsmodel.cpp:41
void DrawWithMouseTool(POINT pt, WPARAM wParam)
Definition: mouse.cpp:1201
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define MAXWORD
#define TME_LEAVE
Definition: commctrl.h:4981
@ TOOL_AIRBRUSH
Definition: toolsmodel.h:20
@ TOOL_ZOOM
Definition: toolsmodel.h:17
#define MAKEWPARAM(l, h)
Definition: winuser.h:4008
#define WM_HSCROLL
Definition: winuser.h:1742
#define WM_VSCROLL
Definition: winuser.h:1743
HWND WINAPI GetCapture(void)
Definition: message.c:2881
BOOL WINAPI TrackMouseEvent(_Inout_ LPTRACKMOUSEEVENT)
#define SendMessage
Definition: winuser.h:5842
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

◆ OnMouseWheel()

LRESULT CCanvasWindow::OnMouseWheel ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 673 of file canvas.cpp.

674{
675 return ::SendMessageW(GetParent(), nMsg, wParam, lParam);
676}
HWND WINAPI GetParent(_In_ HWND)

◆ OnPaint()

LRESULT CCanvasWindow::OnPaint ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 689 of file canvas.cpp.

690{
691 RECT rcClient;
692 GetClientRect(&rcClient);
693
694 PAINTSTRUCT ps;
695 HDC hDC = BeginPaint(&ps);
696 DoDraw(hDC, rcClient, ps.rcPaint);
697 EndPaint(&ps);
698 return 0;
699}
VOID DoDraw(HDC hDC, RECT &rcClient, RECT &rcPaint)
Definition: canvas.cpp:122
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)

◆ OnPaletteModelColorChanged()

LRESULT CCanvasWindow::OnPaletteModelColorChanged ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 715 of file canvas.cpp.

716{
718 return 0;
719}
void NotifyImageChanged()
Definition: history.cpp:23

◆ OnSetCursor()

LRESULT CCanvasWindow::OnSetCursor ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 579 of file canvas.cpp.

580{
582 {
583 bHandled = FALSE;
584 return 0;
585 }
586
588 {
590 return 0;
591 }
592
593 POINT pt;
596
597 CRect rcClient;
598 GetClientRect(&rcClient);
599
600 if (!rcClient.PtInRect(pt))
601 {
602 bHandled = FALSE;
603 return 0;
604 }
605
606 HITTEST hitSelection = selectionModel.hitTest(pt);
607 if (hitSelection != HIT_NONE)
608 {
609 if (!setCursorOnSizeBox(hitSelection))
611 return 0;
612 }
613
614 CRect rcImage;
615 GetImageRect(rcImage);
616 ImageToCanvas(rcImage);
617
618 if (rcImage.PtInRect(pt))
619 {
620 switch (toolsModel.GetActiveTool())
621 {
622 case TOOL_FILL:
624 break;
625 case TOOL_COLOR:
627 break;
628 case TOOL_ZOOM:
630 break;
631 case TOOL_PEN:
633 break;
634 case TOOL_AIRBRUSH:
636 break;
637 default:
639 }
640 return 0;
641 }
642
644 bHandled = FALSE;
645
646 return 0;
647}
#define IDC_ZOOM
Definition: resource.h:16
#define IDC_FILL
Definition: resource.h:20
#define IDC_PEN
Definition: resource.h:23
#define IDC_COLOR
Definition: resource.h:21
#define IDC_AIRBRUSH
Definition: resource.h:24
static BOOL IsWaiting()
Definition: CWaitCursor.h:40
BOOL setCursorOnSizeBox(HITTEST hit)
Definition: sizebox.cpp:20
@ TOOL_COLOR
Definition: toolsmodel.h:16
@ TOOL_FILL
Definition: toolsmodel.h:15
@ TOOL_PEN
Definition: toolsmodel.h:18
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2653
#define IDC_SIZEALL
Definition: winuser.h:696
#define IDC_CROSS
Definition: winuser.h:690
BOOL WINAPI ScreenToClient(_In_ HWND, _Inout_ LPPOINT)

◆ OnSize()

LRESULT CCanvasWindow::OnSize ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 250 of file canvas.cpp.

251{
252 if (m_hWnd)
254
255 return 0;
256}

◆ OnVScroll()

LRESULT CCanvasWindow::OnVScroll ( UINT  nMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
protected

Definition at line 294 of file canvas.cpp.

295{
297 return 0;
298}

◆ updateScrollPos()

VOID CCanvasWindow::updateScrollPos ( INT  x = 0,
INT  y = 0 
)

Definition at line 244 of file canvas.cpp.

245{
248}
int WINAPI SetScrollPos(_In_ HWND, _In_ int, _In_ int, _In_ BOOL)

Referenced by CMainWindow::OnCommand(), SetBitmapAndInfo(), and zoomTo().

◆ updateScrollRange()

VOID CCanvasWindow::updateScrollRange ( )

Definition at line 213 of file canvas.cpp.

214{
215 CRect rcClient;
216 GetClientRect(&rcClient);
217
218 CSize sizePage(rcClient.right, rcClient.bottom);
219 CSize sizeZoomed = { Zoomed(imageModel.GetWidth()), Zoomed(imageModel.GetHeight()) };
220 CSize sizeWhole = { sizeZoomed.cx + (GRIP_SIZE * 2), sizeZoomed.cy + (GRIP_SIZE * 2) };
221
222 // show/hide the scrollbars
223 ShowScrollBar(SB_HORZ, sizePage.cx < sizeWhole.cx);
224 ShowScrollBar(SB_VERT, sizePage.cy < sizeWhole.cy);
225
226 if (sizePage.cx < sizeWhole.cx || sizePage.cy < sizeWhole.cy)
227 {
228 GetClientRect(&rcClient); // Scrollbars might change, get client rectangle again
229 sizePage = CSize(rcClient.right, rcClient.bottom);
230 }
231
232 SCROLLINFO si = { sizeof(si), SIF_PAGE | SIF_RANGE };
233 si.nMin = 0;
234
235 si.nMax = sizeWhole.cx;
236 si.nPage = sizePage.cx;
238
239 si.nMax = sizeWhole.cy;
240 si.nPage = sizePage.cy;
242}
LONG cx
Definition: windef.h:334
LONG cy
Definition: windef.h:335
#define SIF_RANGE
Definition: winuser.h:1234
#define SIF_PAGE
Definition: winuser.h:1232
BOOL WINAPI ShowScrollBar(_In_ HWND, _In_ int, _In_ BOOL)

Referenced by ImageModel::NotifyImageChanged(), OnButtonUp(), OnSize(), and zoomTo().

◆ zoomTo()

VOID CCanvasWindow::zoomTo ( INT  newZoom,
LONG  left = 0,
LONG  top = 0 
)

Definition at line 107 of file canvas.cpp.

108{
109 POINT pt = { left, top };
111
112 toolsModel.SetZoom(newZoom);
114 pt.x += GetScrollPos(SB_HORZ);
115 pt.y += GetScrollPos(SB_VERT);
116
118 updateScrollPos(pt.x, pt.y);
119 Invalidate(TRUE);
120}
VOID updateScrollPos(INT x=0, INT y=0)
Definition: canvas.cpp:244
void SetZoom(int nZoom)
Definition: toolsmodel.cpp:266
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859
GLint left
Definition: glext.h:7726

Referenced by ZoomTool::OnButtonDown(), CMainWindow::OnCommand(), CMainWindow::OnMouseWheel(), and CToolSettingsWindow::OnVScroll().

Member Data Documentation

◆ m_ahbmCached

HBITMAP CCanvasWindow::m_ahbmCached[2]
protected

Definition at line 60 of file canvas.h.

Referenced by DoDraw(), and ~CCanvasWindow().

◆ m_drawing

◆ m_hitCanvasSizeBox

HITTEST CCanvasWindow::m_hitCanvasSizeBox
protected

Definition at line 58 of file canvas.h.

Referenced by DoDraw(), OnButtonDown(), OnButtonUp(), OnCancelMode(), OnKeyDown(), and OnMouseMove().

◆ m_nMouseDownMsg

UINT CCanvasWindow::m_nMouseDownMsg = 0
protected

Definition at line 82 of file canvas.h.

Referenced by OnButtonDblClk(), OnButtonDown(), OnButtonUp(), OnKeyDown(), OnMouseMove(), and OnSetCursor().

◆ m_ptOrig

POINT CCanvasWindow::m_ptOrig
protected

Definition at line 59 of file canvas.h.

Referenced by OnButtonDown(), OnButtonUp(), and OnMouseMove().

◆ m_rcResizing

CRect CCanvasWindow::m_rcResizing
protected

Definition at line 61 of file canvas.h.

Referenced by DoDraw(), OnButtonUp(), OnCancelMode(), OnKeyDown(), and OnMouseMove().


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