ReactOS 0.4.15-dev-6047-gb29e82d
CCanvasWindow Class Reference

#include <canvas.h>

Inheritance diagram for CCanvasWindow:
Collaboration diagram for CCanvasWindow:

Public Member Functions

 CCanvasWindow ()
 
VOID cancelDrawing ()
 
VOID finishDrawing ()
 
VOID Update (HWND hwndFrom)
 
VOID ImageToCanvas (POINT &pt)
 
VOID ImageToCanvas (RECT &rc)
 
VOID CanvasToImage (POINT &pt, BOOL bZoomed=FALSE)
 
VOID CanvasToImage (RECT &rc, BOOL bZoomed=FALSE)
 
VOID GetImageRect (RECT &rc)
 

Public Attributes

BOOL m_drawing
 

Protected Member Functions

CANVAS_HITTEST CanvasHitTest (POINT pt)
 
RECT GetBaseRect ()
 
VOID DoDraw (HDC hDC, RECT &rcClient, RECT &rcPaint)
 
VOID OnHVScroll (WPARAM wParam, INT fnBar)
 
VOID drawZoomFrame (INT mouseX, INT mouseY)
 
CANVAS_HITTEST SelectionHitTest (POINT ptZoomed)
 
VOID StartSelectionDrag (CANVAS_HITTEST hit, POINT ptUnZoomed)
 
VOID SelectionDragging (POINT ptUnZoomed)
 
VOID EndSelectionDrag (POINT ptUnZoomed)
 
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 OnLButtonDown (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnRButtonDown (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnLButtonDblClk (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnRButtonDblClk (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 OnLButtonUp (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnRButtonUp (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 OnLRButtonDown (BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnLRButtonDblClk (BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnLRButtonUp (BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 

Protected Attributes

CANVAS_HITTEST m_hitSelection
 
CANVAS_HITTEST m_whereHit
 
POINT m_ptOrig
 
CRect m_rcNew
 

Detailed Description

Definition at line 11 of file canvas.h.

Constructor & Destructor Documentation

◆ CCanvasWindow()

CCanvasWindow::CCanvasWindow ( )

Definition at line 15 of file canvas.cpp.

19 , m_ptOrig { -1, -1 }
20{
22}
@ HIT_NONE
Definition: common.h:42
BOOL m_drawing
Definition: canvas.h:38
CANVAS_HITTEST m_hitSelection
Definition: canvas.h:51
POINT m_ptOrig
Definition: canvas.h:53
CRect m_rcNew
Definition: canvas.h:54
CANVAS_HITTEST m_whereHit
Definition: canvas.h:52
#define FALSE
Definition: types.h:117
BOOL WINAPI SetRectEmpty(_Out_ LPRECT)

Member Function Documentation

◆ cancelDrawing()

VOID CCanvasWindow::cancelDrawing ( )

Definition at line 717 of file canvas.cpp.

718{
724 Invalidate(FALSE);
725}
void OnCancelDraw()
Definition: toolsmodel.cpp:213
ToolsModel toolsModel
Definition: toolsmodel.cpp:11
SelectionModel selectionModel

Referenced by CMainWindow::OnCommand().

◆ CanvasHitTest()

CANVAS_HITTEST CCanvasWindow::CanvasHitTest ( POINT  pt)
protected

Definition at line 88 of file canvas.cpp.

89{
90 RECT rcBase = GetBaseRect();
91 return getSizeBoxHitTest(pt, &rcBase);
92}
RECT GetBaseRect()
Definition: canvas.cpp:36
#define pt(x, y)
Definition: drawing.c:79
CANVAS_HITTEST getSizeBoxHitTest(POINT pt, LPCRECT prcBase)
Definition: sizebox.cpp:81

Referenced by OnLRButtonDown(), and OnSetCursor().

◆ CanvasToImage() [1/2]

VOID CCanvasWindow::CanvasToImage ( POINT pt,
BOOL  bZoomed = FALSE 
)

Definition at line 62 of file canvas.cpp.

63{
66 if (bZoomed)
67 return;
68 pt.x = UnZoomed(pt.x);
69 pt.y = UnZoomed(pt.y);
70}
#define GRIP_SIZE
Definition: common.h:13
static int UnZoomed(int xy)
Definition: toolsmodel.h:131
#define SB_VERT
Definition: winuser.h:553
int WINAPI GetScrollPos(_In_ HWND, _In_ int)
#define SB_HORZ
Definition: winuser.h:552

Referenced by CTextEditWindow::InvalidateEditRect(), OnLRButtonDblClk(), OnLRButtonDown(), OnLRButtonUp(), OnMouseMove(), and CTextEditWindow::Reposition().

◆ CanvasToImage() [2/2]

VOID CCanvasWindow::CanvasToImage ( RECT rc,
BOOL  bZoomed = FALSE 
)

Definition at line 72 of file canvas.cpp.

73{
75 if (bZoomed)
76 return;
77 rc.left = UnZoomed(rc.left);
78 rc.top = UnZoomed(rc.top);
79 rc.right = UnZoomed(rc.right);
80 rc.bottom = UnZoomed(rc.bottom);
81}
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
BOOL WINAPI OffsetRect(_Inout_ LPRECT, _In_ int, _In_ int)

◆ DoDraw()

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

Definition at line 94 of file canvas.cpp.

95{
96 // We use a memory bitmap to reduce flickering
98 HBITMAP hbm = ::CreateCompatibleBitmap(hDC, rcClient.right, rcClient.bottom);
100
101 // Fill the background
102 ::FillRect(hdcMem, &rcPaint, (HBRUSH)(COLOR_APPWORKSPACE + 1));
103
104 // Draw the sizeboxes if necessary
105 RECT rcBase = GetBaseRect();
107 drawSizeBoxes(hdcMem, &rcBase, FALSE, &rcPaint);
108
109 // Draw the image
110 CRect rcImage;
111 GetImageRect(rcImage);
112 ImageToCanvas(rcImage);
113 SIZE sizeImage = { imageModel.GetWidth(), imageModel.GetHeight() };
114 StretchBlt(hdcMem, rcImage.left, rcImage.top, rcImage.Width(), rcImage.Height(),
115 imageModel.GetDC(), 0, 0, sizeImage.cx, sizeImage.cy, SRCCOPY);
116
117 // Draw the grid
118 if (showGrid && toolsModel.GetZoom() >= 4000)
119 {
120 HPEN oldPen = (HPEN) SelectObject(hdcMem, CreatePen(PS_SOLID, 1, RGB(160, 160, 160)));
121 for (INT counter = 0; counter < sizeImage.cy; counter++)
122 {
123 POINT pt0 = { 0, counter }, pt1 = { sizeImage.cx, counter };
124 ImageToCanvas(pt0);
125 ImageToCanvas(pt1);
126 ::MoveToEx(hdcMem, pt0.x, pt0.y, NULL);
127 ::LineTo(hdcMem, pt1.x, pt1.y);
128 }
129 for (INT counter = 0; counter < sizeImage.cx; counter++)
130 {
131 POINT pt0 = { counter, 0 }, pt1 = { counter, sizeImage.cy };
132 ImageToCanvas(pt0);
133 ImageToCanvas(pt1);
134 ::MoveToEx(hdcMem, pt0.x, pt0.y, NULL);
135 ::LineTo(hdcMem, pt1.x, pt1.y);
136 }
138 }
139
140 // Draw selection
142 {
143 RECT rcSelection = selectionModel.m_rc;
144 ImageToCanvas(rcSelection);
145
146 ::InflateRect(&rcSelection, GRIP_SIZE, GRIP_SIZE);
147 drawSizeBoxes(hdcMem, &rcSelection, TRUE, &rcPaint);
148 ::InflateRect(&rcSelection, -GRIP_SIZE, -GRIP_SIZE);
149
150 INT iSaveDC = ::SaveDC(hdcMem);
151 ::IntersectClipRect(hdcMem, rcImage.left, rcImage.top, rcImage.right, rcImage.bottom);
154 ::RestoreDC(hdcMem, iSaveDC);
155 }
156
157 // Draw new frame if any
160
161 // Transfer the bits
163 rcPaint.left, rcPaint.top,
164 rcPaint.right - rcPaint.left, rcPaint.bottom - rcPaint.top,
165 hdcMem, rcPaint.left, rcPaint.top, SRCCOPY);
166
169}
static HDC hDC
Definition: 3dtext.c:33
VOID ImageToCanvas(POINT &pt)
Definition: canvas.cpp:45
VOID GetImageRect(RECT &rc)
Definition: canvas.cpp:83
int Width() const
Definition: atltypes.h:407
int Height() const
Definition: atltypes.h:318
int GetWidth() const
Definition: history.cpp:215
int GetHeight() const
Definition: history.cpp:220
HDC GetDC()
Definition: history.cpp:239
COLORREF GetBgColor() const
void DrawSelection(HDC hDCImage, LPCRECT prc, COLORREF crBg=0, BOOL bBgTransparent=FALSE)
int GetZoom() const
Definition: toolsmodel.cpp:148
BOOL IsBackgroundTransparent() const
Definition: toolsmodel.cpp:135
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
void DrawXorRect(HDC hdc, const RECT *prc)
Definition: drawing.cpp:367
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
pKey DeleteObject()
ImageModel imageModel
Definition: history.cpp:11
BOOL showGrid
Definition: main.cpp:19
PaletteModel paletteModel
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
VOID drawSizeBoxes(HDC hdc, LPCRECT prcBase, BOOL bDrawFrame, LPCRECT prcPaint)
Definition: sizebox.cpp:104
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
int32_t INT
Definition: typedefs.h:58
HDC hdcMem
Definition: welcome.c:104
int WINAPI IntersectClipRect(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
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)
BOOL WINAPI RestoreDC(_In_ HDC, _In_ int)
#define SRCCOPY
Definition: wingdi.h:333
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
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
int WINAPI SaveDC(_In_ HDC)
BOOL WINAPI IsRectEmpty(_In_ LPCRECT)
#define COLOR_APPWORKSPACE
Definition: winuser.h:919
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)

Referenced by OnPaint().

◆ drawZoomFrame()

VOID CCanvasWindow::drawZoomFrame ( INT  mouseX,
INT  mouseY 
)
protected

Definition at line 24 of file canvas.cpp.

25{
26 // FIXME: Draw the border of the area that is to be zoomed in
27 CRect rc;
28 GetImageRect(rc);
29 ImageToCanvas(rc);
30
31 HDC hdc = GetDC();
32 DrawXorRect(hdc, &rc);
34}
HDC hdc
Definition: main.c:9
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC WINAPI GetDC(_In_opt_ HWND)

Referenced by OnMouseMove().

◆ EndSelectionDrag()

VOID CCanvasWindow::EndSelectionDrag ( POINT  ptUnZoomed)
protected

Definition at line 763 of file canvas.cpp.

764{
767 Invalidate(FALSE);
768}
void Dragging(CANVAS_HITTEST hit, POINT pt)

Referenced by OnLRButtonUp().

◆ finishDrawing()

VOID CCanvasWindow::finishDrawing ( )

Definition at line 727 of file canvas.cpp.

728{
731 Invalidate(FALSE);
732}
void OnFinishDraw()
Definition: toolsmodel.cpp:221

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

◆ GetBaseRect()

RECT CCanvasWindow::GetBaseRect ( )
protected

Definition at line 36 of file canvas.cpp.

37{
38 CRect rcBase;
39 GetImageRect(rcBase);
40 ImageToCanvas(rcBase);
42 return rcBase;
43}

Referenced by CanvasHitTest(), and DoDraw().

◆ GetImageRect()

VOID CCanvasWindow::GetImageRect ( RECT rc)

Definition at line 83 of file canvas.cpp.

84{
86}
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)

Referenced by DoDraw(), drawZoomFrame(), GetBaseRect(), OnSetCursor(), and CTextEditWindow::Reposition().

◆ ImageToCanvas() [1/2]

VOID CCanvasWindow::ImageToCanvas ( POINT pt)

Definition at line 45 of file canvas.cpp.

46{
47 pt.x = Zoomed(pt.x);
48 pt.y = Zoomed(pt.y);
51}
static int Zoomed(int xy)
Definition: toolsmodel.h:126

Referenced by DoDraw(), drawZoomFrame(), GetBaseRect(), OnMouseMove(), OnSetCursor(), CTextEditWindow::Reposition(), and CTextEditWindow::ValidateEditRect().

◆ ImageToCanvas() [2/2]

VOID CCanvasWindow::ImageToCanvas ( RECT rc)

Definition at line 53 of file canvas.cpp.

54{
55 rc.left = Zoomed(rc.left);
56 rc.top = Zoomed(rc.top);
57 rc.right = Zoomed(rc.right);
58 rc.bottom = Zoomed(rc.bottom);
60}

◆ OnCancelMode()

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

Definition at line 680 of file canvas.cpp.

681{
682 // Cancel dragging
685 Invalidate(TRUE);
686 return 0;
687}

◆ OnCaptureChanged()

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

Definition at line 694 of file canvas.cpp.

695{
697 return 0;
698}
HWND hStatusBar
Definition: winproc.cpp:20
#define SB_SETTEXT
Definition: commctrl.h:1949
#define _T(x)
Definition: vfdio.h:22
LONG_PTR LPARAM
Definition: windef.h:208
#define SendMessage
Definition: winuser.h:5833

◆ OnEraseBkgnd()

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

Definition at line 700 of file canvas.cpp.

701{
702 return TRUE; // do nothing => transparent background
703}

◆ OnHScroll()

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

Definition at line 240 of file canvas.cpp.

241{
243 return 0;
244}
VOID OnHVScroll(WPARAM wParam, INT fnBar)
Definition: canvas.cpp:210
WPARAM wParam
Definition: combotst.c:138

◆ OnHVScroll()

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

Definition at line 210 of file canvas.cpp.

211{
212 SCROLLINFO si;
213 si.cbSize = sizeof(SCROLLINFO);
214 si.fMask = SIF_ALL;
215 GetScrollInfo(fnBar, &si);
216 switch (LOWORD(wParam))
217 {
218 case SB_THUMBTRACK:
219 case SB_THUMBPOSITION:
220 si.nPos = HIWORD(wParam);
221 break;
222 case SB_LINELEFT:
223 si.nPos -= 5;
224 break;
225 case SB_LINERIGHT:
226 si.nPos += 5;
227 break;
228 case SB_PAGELEFT:
229 si.nPos -= si.nPage;
230 break;
231 case SB_PAGERIGHT:
232 si.nPos += si.nPage;
233 break;
234 }
235 SetScrollInfo(fnBar, &si);
236 Update(m_hWnd);
237 Invalidate(FALSE); // FIXME: Flicker
238}
@ Update
Definition: registry.c:565
#define LOWORD(l)
Definition: pedump.c:82
#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:1222
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 666 of file canvas.cpp.

667{
668 if (wParam == VK_ESCAPE && ::GetCapture() == m_hWnd)
669 {
670 // Cancel dragging
674 Invalidate(TRUE);
675 }
676
677 return 0;
678}
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2890
HWND WINAPI GetCapture(void)
Definition: message.c:2881
#define VK_ESCAPE
Definition: winuser.h:2204

◆ OnLButtonDblClk()

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

Definition at line 338 of file canvas.cpp.

339{
340 return OnLRButtonDblClk(TRUE, nMsg, wParam, lParam, bHandled);
341}
LRESULT OnLRButtonDblClk(BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: canvas.cpp:324
LPARAM lParam
Definition: combotst.c:139

◆ OnLButtonDown()

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

Definition at line 314 of file canvas.cpp.

315{
316 return OnLRButtonDown(TRUE, nMsg, wParam, lParam, bHandled);
317}
LRESULT OnLRButtonDown(BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: canvas.cpp:252

◆ OnLButtonUp()

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

Definition at line 608 of file canvas.cpp.

609{
610 return OnLRButtonUp(TRUE, nMsg, wParam, lParam, bHandled);
611}
LRESULT OnLRButtonUp(BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: canvas.cpp:540

◆ OnLRButtonDblClk()

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

Definition at line 324 of file canvas.cpp.

325{
328
331
332 toolsModel.OnButtonDown(bLeftButton, pt.x, pt.y, TRUE);
334 Invalidate(FALSE);
335 return 0;
336}
VOID CanvasToImage(POINT &pt, BOOL bZoomed=FALSE)
Definition: canvas.cpp:62
void resetTool()
Definition: toolsmodel.cpp:229
void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick)
Definition: toolsmodel.cpp:189
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:300
#define GET_X_LPARAM(lp)
Definition: windowsx.h:299

Referenced by OnLButtonDblClk(), and OnRButtonDblClk().

◆ OnLRButtonDown()

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

Definition at line 252 of file canvas.cpp.

253{
255
256 CANVAS_HITTEST hitSelection = SelectionHitTest(pt);
257 if (hitSelection != HIT_NONE)
258 {
259 if (bLeftButton)
260 {
261 UnZoomed(pt);
262 StartSelectionDrag(hitSelection, pt);
263 }
264 return 0;
265 }
266
268 if (hit == HIT_NONE || hit == HIT_BORDER)
269 {
270 switch (toolsModel.GetActiveTool())
271 {
272 case TOOL_BEZIER:
273 case TOOL_SHAPE:
275 canvasWindow.Invalidate();
276 break;
277
278 case TOOL_FREESEL:
279 case TOOL_RECTSEL:
281 canvasWindow.Invalidate();
282 break;
283
284 default:
285 break;
286 }
287
288 toolsModel.resetTool(); // resets the point-buffer of the polygon and bezier functions
289 return 0;
290 }
291
293
294 if (hit == HIT_INNER)
295 {
296 m_drawing = TRUE;
297 UnZoomed(pt);
298 SetCapture();
299 toolsModel.OnButtonDown(bLeftButton, pt.x, pt.y, FALSE);
300 Invalidate(FALSE);
301 return 0;
302 }
303
304 if (bLeftButton)
305 {
306 m_whereHit = hit;
307 UnZoomed(pt);
308 m_ptOrig = pt;
309 SetCapture();
310 }
311 return 0;
312}
CANVAS_HITTEST
Definition: common.h:41
@ HIT_BORDER
Definition: common.h:51
@ HIT_INNER
Definition: common.h:52
CCanvasWindow canvasWindow
Definition: canvas.cpp:11
CANVAS_HITTEST SelectionHitTest(POINT ptZoomed)
Definition: canvas.cpp:734
VOID StartSelectionDrag(CANVAS_HITTEST hit, POINT ptUnZoomed)
Definition: canvas.cpp:747
CANVAS_HITTEST CanvasHitTest(POINT pt)
Definition: canvas.cpp:88
TOOLTYPE GetActiveTool() const
Definition: toolsmodel.cpp:76
@ TOOL_SHAPE
Definition: toolsmodel.h:26
@ TOOL_BEZIER
Definition: toolsmodel.h:24
@ TOOL_FREESEL
Definition: toolsmodel.h:13
@ TOOL_RECTSEL
Definition: toolsmodel.h:14
HWND WINAPI SetCapture(_In_ HWND hWnd)

Referenced by OnLButtonDown(), and OnRButtonDown().

◆ OnLRButtonUp()

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

Definition at line 540 of file canvas.cpp.

541{
544
546
547 if (m_drawing)
548 {
550 toolsModel.OnButtonUp(bLeftButton, pt.x, pt.y);
551 Invalidate(FALSE);
553 return 0;
554 }
555 else if (m_hitSelection != HIT_NONE && bLeftButton)
556 {
558 return 0;
559 }
560
561 if (m_whereHit == HIT_NONE || !bLeftButton)
562 return 0;
563
564 // Resize the image
565 INT cxImage = imageModel.GetWidth(), cyImage = imageModel.GetHeight();
566 INT cxDelta = pt.x - m_ptOrig.x;
567 INT cyDelta = pt.y - m_ptOrig.y;
568 switch (m_whereHit)
569 {
570 case HIT_UPPER_LEFT:
571 imageModel.Crop(cxImage - cxDelta, cyImage - cyDelta, cxDelta, cyDelta);
572 break;
573 case HIT_UPPER_CENTER:
574 imageModel.Crop(cxImage, cyImage - cyDelta, 0, cyDelta);
575 break;
576 case HIT_UPPER_RIGHT:
577 imageModel.Crop(cxImage + cxDelta, cyImage - cyDelta, 0, cyDelta);
578 break;
579 case HIT_MIDDLE_LEFT:
580 imageModel.Crop(cxImage - cxDelta, cyImage, cxDelta, 0);
581 break;
582 case HIT_MIDDLE_RIGHT:
583 imageModel.Crop(cxImage + cxDelta, cyImage, 0, 0);
584 break;
585 case HIT_LOWER_LEFT:
586 imageModel.Crop(cxImage - cxDelta, cyImage + cyDelta, cxDelta, 0);
587 break;
588 case HIT_LOWER_CENTER:
589 imageModel.Crop(cxImage, cyImage + cyDelta, 0, 0);
590 break;
591 case HIT_LOWER_RIGHT:
592 imageModel.Crop(cxImage + cxDelta, cyImage + cyDelta, 0, 0);
593 break;
594 default:
595 break;
596 }
598
600
602 toolsModel.resetTool(); // resets the point-buffer of the polygon and bezier functions
603 Update(NULL);
604 Invalidate(TRUE);
605 return 0;
606}
@ HIT_LOWER_RIGHT
Definition: common.h:50
@ HIT_LOWER_CENTER
Definition: common.h:49
@ HIT_UPPER_LEFT
Definition: common.h:43
@ HIT_LOWER_LEFT
Definition: common.h:48
@ HIT_UPPER_CENTER
Definition: common.h:44
@ HIT_UPPER_RIGHT
Definition: common.h:45
@ HIT_MIDDLE_RIGHT
Definition: common.h:47
@ HIT_MIDDLE_LEFT
Definition: common.h:46
VOID EndSelectionDrag(POINT ptUnZoomed)
Definition: canvas.cpp:763
void Crop(int nWidth, int nHeight, int nOffsetX=0, int nOffsetY=0)
Definition: history.cpp:131
void OnButtonUp(BOOL bLeftButton, LONG x, LONG y)
Definition: toolsmodel.cpp:205
BOOL imageSaved
Definition: main.cpp:18

Referenced by OnLButtonUp(), and OnRButtonUp().

◆ OnMouseMove()

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

Definition at line 348 of file canvas.cpp.

349{
352
354 {
356 return 0;
357 }
358
360 {
362 {
363 Invalidate(FALSE);
364 UpdateWindow();
366 drawZoomFrame(pt.x, pt.y);
367 }
368
369 TRACKMOUSEEVENT tme = { sizeof(tme) };
370 tme.dwFlags = TME_LEAVE;
371 tme.hwndTrack = m_hWnd;
372 tme.dwHoverTime = 0;
373 ::TrackMouseEvent(&tme);
374
375 if (!m_drawing)
376 {
377 CString strCoord;
378 strCoord.Format(_T("%ld, %ld"), pt.x, pt.y);
380 }
381 }
382
383 if (m_drawing)
384 {
385 // values displayed in statusbar
386 LONG xRel = pt.x - start.x;
387 LONG yRel = pt.y - start.y;
388
389 switch (toolsModel.GetActiveTool())
390 {
391 // freesel, rectsel and text tools always show numbers limited to fit into image area
392 case TOOL_FREESEL:
393 case TOOL_RECTSEL:
394 case TOOL_TEXT:
395 if (xRel < 0)
396 xRel = (pt.x < 0) ? -start.x : xRel;
397 else if (pt.x > imageModel.GetWidth())
398 xRel = imageModel.GetWidth() - start.x;
399 if (yRel < 0)
400 yRel = (pt.y < 0) ? -start.y : yRel;
401 else if (pt.y > imageModel.GetHeight())
402 yRel = imageModel.GetHeight() - start.y;
403 break;
404
405 // while drawing, update cursor coordinates only for tools 3, 7, 8, 9, 14
406 case TOOL_RUBBER:
407 case TOOL_PEN:
408 case TOOL_BRUSH:
409 case TOOL_AIRBRUSH:
410 case TOOL_SHAPE:
411 {
412 CString strCoord;
413 strCoord.Format(_T("%ld, %ld"), pt.x, pt.y);
415 break;
416 }
417 default:
418 break;
419 }
420
421 // rectsel and shape tools always show non-negative numbers when drawing
423 {
424 if (xRel < 0)
425 xRel = -xRel;
426 if (yRel < 0)
427 yRel = -yRel;
428 }
429
430 if (wParam & MK_LBUTTON)
431 {
433 Invalidate(FALSE);
435 {
436 CString strSize;
438 yRel = xRel;
439 strSize.Format(_T("%ld x %ld"), xRel, yRel);
441 }
442 }
443
444 if (wParam & MK_RBUTTON)
445 {
447 Invalidate(FALSE);
449 {
450 CString strSize;
452 yRel = xRel;
453 strSize.Format(_T("%ld x %ld"), xRel, yRel);
455 }
456 }
457 return 0;
458 }
459
460 if (m_whereHit == HIT_NONE || ::GetCapture() != m_hWnd)
461 return 0;
462
463 // Dragging now... Calculate the new size
464 INT cxImage = imageModel.GetWidth(), cyImage = imageModel.GetHeight();
465 INT cxDelta = pt.x - m_ptOrig.x;
466 INT cyDelta = pt.y - m_ptOrig.y;
467 switch (m_whereHit)
468 {
469 case HIT_UPPER_LEFT:
470 cxImage -= cxDelta;
471 cyImage -= cyDelta;
472 break;
473 case HIT_UPPER_CENTER:
474 cyImage -= cyDelta;
475 break;
476 case HIT_UPPER_RIGHT:
477 cxImage += cxDelta;
478 cyImage -= cyDelta;
479 break;
480 case HIT_MIDDLE_LEFT:
481 cxImage -= cxDelta;
482 break;
483 case HIT_MIDDLE_RIGHT:
484 cxImage += cxDelta;
485 break;
486 case HIT_LOWER_LEFT:
487 cxImage -= cxDelta;
488 cyImage += cyDelta;
489 break;
490 case HIT_LOWER_CENTER:
491 cyImage += cyDelta;
492 break;
493 case HIT_LOWER_RIGHT:
494 cxImage += cxDelta;
495 cyImage += cyDelta;
496 break;
497 default:
498 return 0;
499 }
500
501 // Limit bitmap size
502 cxImage = max(1, cxImage);
503 cyImage = max(1, cyImage);
504 cxImage = min(MAXWORD, cxImage);
505 cyImage = min(MAXWORD, cyImage);
506
507 // Display new size
508 CString strSize;
509 strSize.Format(_T("%d x %d"), cxImage, cyImage);
511
512 CRect rc = { 0, 0, cxImage, cyImage };
513 switch (m_whereHit)
514 {
515 case HIT_UPPER_LEFT:
516 ::OffsetRect(&rc, cxDelta, cyDelta);
517 break;
518 case HIT_UPPER_CENTER:
519 ::OffsetRect(&rc, 0, cyDelta);
520 break;
521 case HIT_UPPER_RIGHT:
522 ::OffsetRect(&rc, 0, cyDelta);
523 break;
524 case HIT_MIDDLE_LEFT:
525 ::OffsetRect(&rc, cxDelta, 0);
526 break;
527 case HIT_LOWER_LEFT:
528 ::OffsetRect(&rc, cxDelta, 0);
529 break;
530 default:
531 break;
532 }
533 ImageToCanvas(rc);
534 m_rcNew = rc;
535 Invalidate(TRUE);
536
537 return 0;
538}
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:770
VOID SelectionDragging(POINT ptUnZoomed)
Definition: canvas.cpp:757
VOID drawZoomFrame(INT mouseX, INT mouseY)
Definition: canvas.cpp:24
void OnMouseMove(BOOL bLeftButton, LONG x, LONG y)
Definition: toolsmodel.cpp:197
GLuint start
Definition: gl.h:1545
if(dx< 0)
Definition: linetemp.h:194
#define min(a, b)
Definition: monoChain.cc:55
#define MAXWORD
long LONG
Definition: pedump.c:60
#define TME_LEAVE
Definition: commctrl.h:4981
#define max(a, b)
Definition: svc.c:63
@ TOOL_AIRBRUSH
Definition: toolsmodel.h:21
@ TOOL_RUBBER
Definition: toolsmodel.h:15
@ TOOL_BRUSH
Definition: toolsmodel.h:20
@ TOOL_TEXT
Definition: toolsmodel.h:22
@ TOOL_PEN
Definition: toolsmodel.h:19
@ TOOL_LINE
Definition: toolsmodel.h:23
@ TOOL_ZOOM
Definition: toolsmodel.h:18
#define MK_RBUTTON
Definition: winuser.h:2358
BOOL WINAPI TrackMouseEvent(_Inout_ LPTRACKMOUSEEVENT)
BOOL WINAPI UpdateWindow(_In_ HWND)
#define MK_LBUTTON
Definition: winuser.h:2357
#define VK_SHIFT
Definition: winuser.h:2192
SHORT WINAPI GetAsyncKeyState(_In_ int)
const CHAR * LPCTSTR
Definition: xmlstorage.h:193

◆ OnMouseWheel()

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

Definition at line 689 of file canvas.cpp.

690{
691 return ::SendMessage(GetParent(), nMsg, wParam, lParam);
692}
HWND WINAPI GetParent(_In_ HWND)

◆ OnPaint()

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

Definition at line 705 of file canvas.cpp.

706{
707 RECT rcClient;
708 GetClientRect(&rcClient);
709
710 PAINTSTRUCT ps;
711 HDC hDC = BeginPaint(&ps);
712 DoDraw(hDC, rcClient, ps.rcPaint);
713 EndPaint(&ps);
714 return 0;
715}
VOID DoDraw(HDC hDC, RECT &rcClient, RECT &rcPaint)
Definition: canvas.cpp:94
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)

◆ OnRButtonDblClk()

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

Definition at line 343 of file canvas.cpp.

344{
345 return OnLRButtonDblClk(FALSE, nMsg, wParam, lParam, bHandled);
346}

◆ OnRButtonDown()

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

Definition at line 319 of file canvas.cpp.

320{
321 return OnLRButtonDown(FALSE, nMsg, wParam, lParam, bHandled);
322}

◆ OnRButtonUp()

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

Definition at line 613 of file canvas.cpp.

614{
615 return OnLRButtonUp(FALSE, nMsg, wParam, lParam, bHandled);
616}

◆ OnSetCursor()

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

Definition at line 618 of file canvas.cpp.

619{
620 POINT pt;
623
624 CANVAS_HITTEST hitSelection = SelectionHitTest(pt);
625 if (hitSelection != HIT_NONE)
626 {
627 if (!setCursorOnSizeBox(hitSelection))
629 return 0;
630 }
631
632 CRect rcImage;
633 GetImageRect(rcImage);
634 ImageToCanvas(rcImage);
635 if (::PtInRect(&rcImage, pt))
636 {
637 switch (toolsModel.GetActiveTool())
638 {
639 case TOOL_FILL:
641 break;
642 case TOOL_COLOR:
644 break;
645 case TOOL_ZOOM:
647 break;
648 case TOOL_PEN:
650 break;
651 case TOOL_AIRBRUSH:
653 break;
654 default:
656 }
657 return 0;
658 }
659
662
663 return 0;
664}
#define IDC_ZOOM
Definition: resource.h:16
#define IDC_FILL
Definition: resource.h:21
#define IDC_PEN
Definition: resource.h:24
#define IDC_COLOR
Definition: resource.h:22
#define IDC_AIRBRUSH
Definition: resource.h:25
HINSTANCE hProgInstance
Definition: main.cpp:15
BOOL setCursorOnSizeBox(CANVAS_HITTEST hit)
Definition: sizebox.cpp:21
@ TOOL_COLOR
Definition: toolsmodel.h:17
@ TOOL_FILL
Definition: toolsmodel.h:16
#define IDC_ARROW
Definition: winuser.h:682
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2639
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
#define IDC_SIZEALL
Definition: winuser.h:691
BOOL WINAPI PtInRect(_In_ LPCRECT, _In_ POINT)
#define IDC_CROSS
Definition: winuser.h:685
#define LoadIcon
Definition: winuser.h:5803
#define LoadCursor
Definition: winuser.h:5802
#define MAKEINTRESOURCE
Definition: winuser.h:591
BOOL WINAPI ScreenToClient(_In_ HWND, _Inout_ LPPOINT)

◆ OnSize()

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

Definition at line 202 of file canvas.cpp.

203{
204 if (m_hWnd)
205 Update(m_hWnd);
206
207 return 0;
208}

◆ OnVScroll()

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

Definition at line 246 of file canvas.cpp.

247{
249 return 0;
250}

◆ SelectionDragging()

VOID CCanvasWindow::SelectionDragging ( POINT  ptUnZoomed)
protected

Definition at line 757 of file canvas.cpp.

758{
760 Invalidate(FALSE);
761}

Referenced by OnMouseMove().

◆ SelectionHitTest()

CANVAS_HITTEST CCanvasWindow::SelectionHitTest ( POINT  ptZoomed)
protected

Definition at line 734 of file canvas.cpp.

735{
737 return HIT_NONE;
738
739 RECT rcSelection = selectionModel.m_rc;
740 Zoomed(rcSelection);
742 ::InflateRect(&rcSelection, GRIP_SIZE, GRIP_SIZE);
743
744 return getSizeBoxHitTest(ptZoomed, &rcSelection);
745}

Referenced by OnLRButtonDown(), and OnSetCursor().

◆ StartSelectionDrag()

VOID CCanvasWindow::StartSelectionDrag ( CANVAS_HITTEST  hit,
POINT  ptUnZoomed 
)
protected

Definition at line 747 of file canvas.cpp.

748{
749 m_hitSelection = hit;
750 selectionModel.m_ptHit = ptUnZoomed;
752
753 SetCapture();
754 Invalidate(FALSE);
755}

Referenced by OnLRButtonDown().

◆ Update()

VOID CCanvasWindow::Update ( HWND  hwndFrom)

Definition at line 171 of file canvas.cpp.

172{
173 CRect rcClient;
174 GetClientRect(&rcClient);
175
176 CSize sizePage(rcClient.right, rcClient.bottom);
177 CSize sizeZoomed = { Zoomed(imageModel.GetWidth()), Zoomed(imageModel.GetHeight()) };
178 CSize sizeWhole = { sizeZoomed.cx + (GRIP_SIZE * 2), sizeZoomed.cy + (GRIP_SIZE * 2) };
179
180 // show/hide the scrollbars
181 ShowScrollBar(SB_HORZ, sizePage.cx < sizeWhole.cx);
182 ShowScrollBar(SB_VERT, sizePage.cy < sizeWhole.cy);
183
184 if (sizePage.cx < sizeWhole.cx || sizePage.cy < sizeWhole.cy)
185 {
186 GetClientRect(&rcClient); // Scrollbars might change, get client rectangle again
187 sizePage = CSize(rcClient.right, rcClient.bottom);
188 }
189
190 SCROLLINFO si = { sizeof(si), SIF_PAGE | SIF_RANGE };
191 si.nMin = 0;
192
193 si.nMax = sizeWhole.cx;
194 si.nPage = sizePage.cx;
196
197 si.nMax = sizeWhole.cy;
198 si.nPage = sizePage.cy;
200}
LONG cx
Definition: windef.h:334
LONG cy
Definition: windef.h:335
#define SIF_RANGE
Definition: winuser.h:1225
#define SIF_PAGE
Definition: winuser.h:1223
BOOL WINAPI ShowScrollBar(_In_ HWND, _In_ int, _In_ BOOL)

Member Data Documentation

◆ m_drawing

BOOL CCanvasWindow::m_drawing

◆ m_hitSelection

CANVAS_HITTEST CCanvasWindow::m_hitSelection
protected

◆ m_ptOrig

POINT CCanvasWindow::m_ptOrig
protected

Definition at line 53 of file canvas.h.

Referenced by OnLRButtonDown(), OnLRButtonUp(), and OnMouseMove().

◆ m_rcNew

CRect CCanvasWindow::m_rcNew
protected

Definition at line 54 of file canvas.h.

Referenced by CCanvasWindow(), DoDraw(), OnCancelMode(), OnKeyDown(), OnLRButtonUp(), and OnMouseMove().

◆ m_whereHit

CANVAS_HITTEST CCanvasWindow::m_whereHit
protected

Definition at line 52 of file canvas.h.

Referenced by DoDraw(), OnCancelMode(), OnKeyDown(), OnLRButtonDown(), OnLRButtonUp(), and OnMouseMove().


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