From fe7b711e8a50e8aff8b7bf8c8b68c2885ab98058 Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Wed, 11 Oct 2023 12:17:02 +0900 Subject: [PATCH] update --- canvas.cpp | 29 ++++++++--------------------- canvas.h | 1 - mouse.cpp | 16 +++++++++++++++- toolbox.cpp | 7 ++++++- toolsettings.cpp | 47 +++++++++++++++++++++++++++++++++++++---------- toolsettings.h | 2 ++ 6 files changed, 68 insertions(+), 34 deletions(-) diff --git a/canvas.cpp b/canvas.cpp index a4eeead..17eb261 100644 --- a/canvas.cpp +++ b/canvas.cpp @@ -29,18 +29,6 @@ CCanvasWindow::~CCanvasWindow() ::DeleteObject(m_ahbmCached[1]); } -VOID CCanvasWindow::drawZoomFrame(INT mouseX, INT mouseY) -{ - // FIXME: Draw the border of the area that is to be zoomed in - CRect rc; - GetImageRect(rc); - ImageToCanvas(rc); - - HDC hdc = GetDC(); - DrawXorRect(hdc, &rc); - ReleaseDC(hdc); -} - RECT CCanvasWindow::GetBaseRect() { CRect rcBase; @@ -376,6 +364,9 @@ LRESULT CCanvasWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; CanvasToImage(pt); + if (toolsModel.GetActiveTool() == TOOL_ZOOM) + Invalidate(); + if (m_hitSelection != HIT_NONE) { SelectionDragging(pt); @@ -384,14 +375,6 @@ LRESULT CCanvasWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL if (!m_drawing || toolsModel.GetActiveTool() <= TOOL_AIRBRUSH) { - if (toolsModel.GetActiveTool() == TOOL_ZOOM) - { - Invalidate(FALSE); - UpdateWindow(); - CanvasToImage(pt); - drawZoomFrame(pt.x, pt.y); - } - TRACKMOUSEEVENT tme = { sizeof(tme) }; tme.dwFlags = TME_LEAVE; tme.hwndTrack = m_hWnd; @@ -400,8 +383,12 @@ LRESULT CCanvasWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL if (!m_drawing) { + RECT rcImage; + GetImageRect(rcImage); + CString strCoord; - strCoord.Format(_T("%ld, %ld"), pt.x, pt.y); + if (::PtInRect(&rcImage, pt)) + strCoord.Format(_T("%ld, %ld"), pt.x, pt.y); ::SendMessage(g_hStatusBar, SB_SETTEXT, 1, (LPARAM) (LPCTSTR) strCoord); } } diff --git a/canvas.h b/canvas.h index dc26707..1992001 100644 --- a/canvas.h +++ b/canvas.h @@ -62,7 +62,6 @@ class CCanvasWindow : public CWindowImpl RECT GetBaseRect(); VOID DoDraw(HDC hDC, RECT& rcClient, RECT& rcPaint); VOID OnHVScroll(WPARAM wParam, INT fnBar); - VOID drawZoomFrame(INT mouseX, INT mouseY); HITTEST SelectionHitTest(POINT ptImage); VOID StartSelectionDrag(HITTEST hit, POINT ptImage); diff --git a/mouse.cpp b/mouse.cpp index 8412cc0..4984ab6 100644 --- a/mouse.cpp +++ b/mouse.cpp @@ -569,9 +569,23 @@ struct ZoomTool : ToolBase { } + void OnDrawOverlayOnCanvas(HDC hdc) override + { + CRect rc; + canvasWindow.GetImageRect(rc); + canvasWindow.ImageToCanvas(rc); + + POINT pt; + ::GetCursorPos(&pt); + ::ScreenToClient(canvasWindow, &pt); + + // FIXME: Draw the border of the area that is to be zoomed in + if (rc.PtInRect(pt)) + DrawXorRect(hdc, &rc); + } + void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick) override { - imageModel.PushImageForUndo(); if (bLeftButton) { if (toolsModel.GetZoom() < MAX_ZOOM) diff --git a/toolbox.cpp b/toolbox.cpp index 54d5bd8..891093f 100644 --- a/toolbox.cpp +++ b/toolbox.cpp @@ -34,7 +34,12 @@ CPaintToolBar::ToolBarWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam BOOL CPaintToolBar::DoCreate(HWND hwndParent) { // NOTE: The horizontal line above the toolbar is hidden by CCS_NODIVIDER style. - RECT toolbarPos = { 0, 0, CX_TOOLBAR, CY_TOOLBAR }; + RECT toolbarPos = + { + 0, 0, + CX_TOOLBAR + 2 * GetSystemMetrics(SM_CXBORDER), + CY_TOOLBAR + 2 * GetSystemMetrics(SM_CYBORDER) + }; DWORD style = WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_VERT | CCS_NORESIZE | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT; if (!CWindow::Create(TOOLBARCLASSNAME, hwndParent, toolbarPos, NULL, style)) diff --git a/toolsettings.cpp b/toolsettings.cpp index 3d86984..daf1bfc 100644 --- a/toolsettings.cpp +++ b/toolsettings.cpp @@ -21,6 +21,10 @@ #define MARGIN1 3 #define MARGIN2 2 +#define MAX_ZOOM_TRACK 6 +#define MIN_ZOOM_TRACK 0 +#define DEFAULT_ZOOM_TRACK 3 + static const BYTE s_AirRadius[4] = { 5, 8, 3, 12 }; CToolSettingsWindow toolSettingsWindow; @@ -285,10 +289,13 @@ LRESULT CToolSettingsWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, W m_hTranspIcon = (HICON)LoadImage(g_hinstExe, MAKEINTRESOURCE(IDI_TRANSPARENT), IMAGE_ICON, CX_TRANS_ICON, CY_TRANS_ICON, LR_DEFAULTCOLOR); - RECT trackbarZoomPos = {1, 1, 1 + 40, 1 + 64}; + RECT trackbarZoomPos, rect2; + calculateTwoBoxes(trackbarZoomPos, rect2); + ::InflateRect(&trackbarZoomPos, -1, -1); + trackbarZoom.Create(TRACKBAR_CLASS, m_hWnd, trackbarZoomPos, NULL, WS_CHILD | TBS_VERT | TBS_AUTOTICKS); - trackbarZoom.SendMessage(TBM_SETRANGE, (WPARAM) TRUE, MAKELPARAM(0, 6)); - trackbarZoom.SendMessage(TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 3); + trackbarZoom.SendMessage(TBM_SETRANGE, TRUE, MAKELPARAM(MIN_ZOOM_TRACK, MAX_ZOOM_TRACK)); + trackbarZoom.SendMessage(TBM_SETPOS, TRUE, DEFAULT_ZOOM_TRACK); return 0; } @@ -301,9 +308,30 @@ LRESULT CToolSettingsWindow::OnDestroy(UINT nMsg, WPARAM wParam, LPARAM lParam, LRESULT CToolSettingsWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - if (!zoomTo(125 << trackbarZoom.SendMessage(TBM_GETPOS, 0, 0), 0, 0)) + INT trackPos = MAX_ZOOM_TRACK - (INT)trackbarZoom.SendMessage(TBM_GETPOS, 0, 0); + zoomTo(MIN_ZOOM << trackPos, 0, 0); + + INT zoomRate = toolsModel.GetZoom(); + + CString strZoom; + if (zoomRate % 10 == 0) + strZoom.Format(_T("%d%%"), zoomRate / 10); + else + strZoom.Format(_T("%d.%d%%"), zoomRate / 10, zoomRate % 10); + + ::SendMessage(g_hStatusBar, SB_SETTEXT, 1, (LPARAM)(LPCTSTR)strZoom); + + OnToolsModelZoomChanged(nMsg, wParam, lParam, bHandled); + return 0; +} + +LRESULT CToolSettingsWindow::OnNotify(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + NMHDR *pnmhdr = (NMHDR*)lParam; + if (pnmhdr->code == NM_CUSTOMDRAW) { - OnToolsModelZoomChanged(nMsg, wParam, lParam, bHandled); + NMCUSTOMDRAW *pCustomDraw = (NMCUSTOMDRAW*)pnmhdr; + pCustomDraw->uItemState &= ~CDIS_FOCUS; // Do not draw the focus } return 0; } @@ -330,9 +358,7 @@ LRESULT CToolSettingsWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BO PAINTSTRUCT ps; HDC hdc = BeginPaint(&ps); - if (toolsModel.GetActiveTool() == TOOL_ZOOM) - ::DrawEdge(hdc, &rect1, BDR_SUNKENOUTER, BF_RECT); - else + if (toolsModel.GetActiveTool() != TOOL_ZOOM) ::DrawEdge(hdc, &rect1, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE); if (toolsModel.GetActiveTool() >= TOOL_RECT) @@ -458,7 +484,7 @@ LRESULT CToolSettingsWindow::OnToolsModelSettingsChanged(UINT nMsg, WPARAM wPara LRESULT CToolSettingsWindow::OnToolsModelZoomChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - int tbPos = 0; + int tbPos = MIN_ZOOM_TRACK; int tempZoom = toolsModel.GetZoom(); while (tempZoom > MIN_ZOOM) @@ -466,6 +492,7 @@ LRESULT CToolSettingsWindow::OnToolsModelZoomChanged(UINT nMsg, WPARAM wParam, L tbPos++; tempZoom = tempZoom >> 1; } - trackbarZoom.SendMessage(TBM_SETPOS, (WPARAM) TRUE, (LPARAM) tbPos); + + trackbarZoom.SendMessage(TBM_SETPOS, TRUE, MAX_ZOOM_TRACK - tbPos); return 0; } diff --git a/toolsettings.h b/toolsettings.h index 7b58225..b6cc048 100644 --- a/toolsettings.h +++ b/toolsettings.h @@ -17,6 +17,7 @@ class CToolSettingsWindow : public CWindowImpl MESSAGE_HANDLER(WM_VSCROLL, OnVScroll) MESSAGE_HANDLER(WM_PAINT, OnPaint) MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown) + MESSAGE_HANDLER(WM_NOTIFY, OnNotify) MESSAGE_HANDLER(WM_TOOLSMODELTOOLCHANGED, OnToolsModelToolChanged) MESSAGE_HANDLER(WM_TOOLSMODELSETTINGSCHANGED, OnToolsModelSettingsChanged) MESSAGE_HANDLER(WM_TOOLSMODELZOOMCHANGED, OnToolsModelZoomChanged) @@ -43,6 +44,7 @@ class CToolSettingsWindow : public CWindowImpl LRESULT OnVScroll(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 OnNotify(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnToolsModelZoomChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);