Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
katahiromz committed Nov 25, 2023
1 parent 6d01edc commit 421341a
Show file tree
Hide file tree
Showing 16 changed files with 327 additions and 459 deletions.
89 changes: 12 additions & 77 deletions canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ CCanvasWindow canvasWindow;

CCanvasWindow::CCanvasWindow()
: m_drawing(FALSE)
, m_hitSelection(HIT_NONE)
, m_hitCanvasSizeBox(HIT_NONE)
, m_ptOrig { -1, -1 }
{
Expand Down Expand Up @@ -316,25 +315,11 @@ LRESULT CCanvasWindow::OnButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
HITTEST hitSelection = selectionModel.hitTest(pt);
if (hitSelection != HIT_NONE)
{
selectionModel.m_nSelectionBrush = 0; // Selection Brush is OFF
if (bLeftButton)
{
CanvasToImage(pt);
if (::GetKeyState(VK_CONTROL) < 0) // Ctrl+Click is Selection Clone
{
imageModel.SelectionClone();
}
else if (::GetKeyState(VK_SHIFT) < 0) // Shift+Dragging is Selection Brush
{
selectionModel.m_nSelectionBrush = 1; // Selection Brush is ON
}
StartSelectionDrag(hitSelection, pt);
}
else
{
ClientToScreen(&pt);
mainWindow.TrackPopupMenu(pt, 0);
}
m_drawing = TRUE;
CanvasToImage(pt);
SetCapture();
toolsModel.OnButtonDown(bLeftButton, pt.x, pt.y, FALSE);
Invalidate();
return 0;
}

Expand Down Expand Up @@ -370,7 +355,7 @@ LRESULT CCanvasWindow::OnButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
m_drawing = TRUE;
SetCapture();
toolsModel.OnButtonDown(bLeftButton, pt.x, pt.y, FALSE);
Invalidate(FALSE);
Invalidate();
return 0;
}

Expand All @@ -395,7 +380,7 @@ LRESULT CCanvasWindow::OnButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, B

toolsModel.OnButtonDown(nMsg == WM_LBUTTONDBLCLK, pt.x, pt.y, TRUE);
toolsModel.resetTool();
Invalidate(FALSE);
Invalidate();
return 0;
}

Expand All @@ -418,12 +403,6 @@ LRESULT CCanvasWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL
if (toolsModel.GetActiveTool() == TOOL_ZOOM)
Invalidate();

if (m_hitSelection != HIT_NONE)
{
SelectionDragging(pt);
return 0;
}

if (!m_drawing || toolsModel.GetActiveTool() <= TOOL_AIRBRUSH)
{
TRACKMOUSEEVENT tme = { sizeof(tme) };
Expand All @@ -444,7 +423,7 @@ LRESULT CCanvasWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL
}
}

if (m_drawing)
if (m_drawing || toolsModel.IsSelection())
{
toolsModel.DrawWithMouseTool(pt, wParam);
return 0;
Expand Down Expand Up @@ -549,11 +528,6 @@ LRESULT CCanvasWindow::OnButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
::SendMessageW(g_hStatusBar, SB_SETTEXT, 2, (LPARAM)L"");
return 0;
}
else if (m_hitSelection != HIT_NONE && bLeftButton)
{
EndSelectionDrag(pt);
return 0;
}

if (m_hitCanvasSizeBox == HIT_NONE || !bLeftButton)
return 0;
Expand Down Expand Up @@ -674,9 +648,9 @@ LRESULT CCanvasWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL

LRESULT CCanvasWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (wParam == VK_ESCAPE && ::GetCapture() == m_hWnd)
if (wParam == VK_ESCAPE)
{
cancelDrawing();
OnEndDraw(TRUE);
::ReleaseCapture();
m_nMouseDownMsg = 0;
m_hitCanvasSizeBox = HIT_NONE;
Expand Down Expand Up @@ -724,49 +698,10 @@ LRESULT CCanvasWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
return 0;
}

VOID CCanvasWindow::cancelDrawing()
VOID CCanvasWindow::OnEndDraw(BOOL bCancel)
{
selectionModel.ClearColorImage();
selectionModel.ClearMaskImage();
m_hitSelection = HIT_NONE;
m_drawing = FALSE;
toolsModel.OnEndDraw(TRUE);
Invalidate(FALSE);
}

VOID CCanvasWindow::finishDrawing()
{
toolsModel.OnEndDraw(FALSE);
m_drawing = FALSE;
Invalidate(FALSE);
}

VOID CCanvasWindow::StartSelectionDrag(HITTEST hit, POINT ptImage)
{
m_hitSelection = hit;
selectionModel.m_ptHit = ptImage;
selectionModel.TakeOff();

SetCapture();
Invalidate(FALSE);
}

VOID CCanvasWindow::SelectionDragging(POINT ptImage)
{
if (selectionModel.m_nSelectionBrush)
{
imageModel.SelectionClone(selectionModel.m_nSelectionBrush == 1);
selectionModel.m_nSelectionBrush = 2; // Selection Brush is ON and drawn
}

selectionModel.Dragging(m_hitSelection, ptImage);
Invalidate(FALSE);
}

VOID CCanvasWindow::EndSelectionDrag(POINT ptImage)
{
selectionModel.Dragging(m_hitSelection, ptImage);
m_hitSelection = HIT_NONE;
toolsModel.OnEndDraw(bCancel);
Invalidate(FALSE);
}

Expand Down
8 changes: 1 addition & 7 deletions canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class CCanvasWindow : public CWindowImpl<CCanvasWindow>

BOOL m_drawing;

VOID cancelDrawing();
VOID finishDrawing();
VOID OnEndDraw(BOOL bCancel);
VOID updateScrollRange();
VOID updateScrollPos(INT x = 0, INT y = 0);

Expand All @@ -56,7 +55,6 @@ class CCanvasWindow : public CWindowImpl<CCanvasWindow>
VOID zoomTo(INT newZoom, LONG left = 0, LONG top = 0);

protected:
HITTEST m_hitSelection;
HITTEST m_hitCanvasSizeBox;
POINT m_ptOrig; // The origin of drag start
HBITMAP m_ahbmCached[2]; // The cached buffer bitmaps
Expand All @@ -67,10 +65,6 @@ class CCanvasWindow : public CWindowImpl<CCanvasWindow>
VOID DoDraw(HDC hDC, RECT& rcClient, RECT& rcPaint);
VOID OnHVScroll(WPARAM wParam, INT fnBar);

VOID StartSelectionDrag(HITTEST hit, POINT ptImage);
VOID SelectionDragging(POINT ptImage);
VOID EndSelectionDrag(POINT ptImage);

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);
Expand Down
5 changes: 0 additions & 5 deletions dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
* COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
*/

/* INCLUDES *********************************************************/

#include "precomp.h"

#include "dialogs.h"

#include <winnls.h>

/* GLOBALS **********************************************************/

CMirrorRotateDialog mirrorRotateDialog;
CAttributesDialog attributesDialog;
CStretchSkewDialog stretchSkewDialog;
Expand Down
2 changes: 0 additions & 2 deletions drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
*/

/* INCLUDES *********************************************************/

#include "precomp.h"

/* FUNCTIONS ********************************************************/
Expand Down
20 changes: 6 additions & 14 deletions history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,13 @@ void ImageModel::PushImageForUndo(const RECT& rcPartial)
part.m_bPartial = TRUE;
part.m_rcPart = rcPartial;

CRect rcImage = { 0, 0, GetWidth(), GetHeight() };
CRect& rc = part.m_rcPart;
if (!rc.IntersectRect(rc, rcImage))
rc.SetRect(-1, -1, 0, 0);

HBITMAP hbmMaster = LockBitmap();
part.m_hbmImage = getSubImage(hbmMaster, rcPartial);
part.m_hbmImage = getSubImage(hbmMaster, rc);
UnlockBitmap(hbmMaster);

PushDone();
Expand Down Expand Up @@ -351,16 +356,3 @@ void ImageModel::UnlockBitmap(HBITMAP hbmLocked)
m_hbmMaster = hbmLocked;
m_hbmOld = ::SelectObject(m_hDrawingDC, m_hbmMaster); // Re-select
}

void ImageModel::SelectionClone(BOOL bUndoable)
{
if (!selectionModel.m_bShow || selectionModel.m_rc.IsRectEmpty())
return;

if (bUndoable)
PushImageForUndo();

selectionModel.DrawSelection(m_hDrawingDC, paletteModel.GetBgColor(),
toolsModel.IsBackgroundTransparent());
NotifyImageChanged();
}
1 change: 0 additions & 1 deletion history.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class ImageModel
void NotifyImageChanged();
BOOL IsBlackAndWhite();
void PushBlackAndWhite();
void SelectionClone(BOOL bUndoable = TRUE);

protected:
HDC m_hDrawingDC; // The device context for this class
Expand Down
62 changes: 7 additions & 55 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ void CMainWindow::alignChildrenToMainWindow()

void CMainWindow::saveImage(BOOL overwrite)
{
canvasWindow.finishDrawing();
canvasWindow.OnEndDraw(FALSE);

// Is the extension not supported?
PWCHAR pchDotExt = PathFindExtensionW(g_szFileName);
Expand Down Expand Up @@ -606,7 +606,7 @@ LRESULT CMainWindow::OnDestroy(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH

BOOL CMainWindow::ConfirmSave()
{
canvasWindow.finishDrawing();
canvasWindow.OnEndDraw(FALSE);

if (imageModel.IsImageSaved())
return TRUE;
Expand Down Expand Up @@ -693,17 +693,13 @@ BOOL CMainWindow::CanUndo() const
return (BOOL)textEditWindow.SendMessage(EM_CANUNDO);
if (selectionModel.m_bShow && toolsModel.IsSelection())
return TRUE;
if (ToolBase::s_pointSP != 0)
return TRUE;
return imageModel.CanUndo();
}

BOOL CMainWindow::CanRedo() const
{
if (toolsModel.GetActiveTool() == TOOL_TEXT && ::IsWindowVisible(textEditWindow))
return FALSE; // There is no "WM_REDO" in EDIT control
if (ToolBase::s_pointSP != 0)
return TRUE;
return imageModel.CanRedo();
}

Expand Down Expand Up @@ -802,29 +798,11 @@ LRESULT CMainWindow::OnGetMinMaxInfo(UINT nMsg, WPARAM wParam, LPARAM lParam, BO

LRESULT CMainWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
HWND hwndCapture;
switch (wParam)
{
case VK_ESCAPE:
hwndCapture = GetCapture();
if (hwndCapture)
{
if (canvasWindow.m_hWnd == hwndCapture ||
fullscreenWindow.m_hWnd == hwndCapture)
{
::SendMessageW(hwndCapture, nMsg, wParam, lParam);
}
}
else if (selectionModel.m_bShow)
{
selectionModel.HideSelection();
}
else
{
canvasWindow.cancelDrawing();
}
canvasWindow.PostMessage(nMsg, wParam, lParam);
break;

case VK_LEFT:
selectionModel.moveSelection(-1, 0);
break;
Expand Down Expand Up @@ -932,7 +910,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
GlobalFree(pd.hDevNames);
break;
case IDM_FILESEND:
canvasWindow.finishDrawing();
canvasWindow.OnEndDraw(FALSE);
if (!OpenMailer(m_hWnd, g_szFileName))
{
ShowError(IDS_CANTSENDMAIL);
Expand Down Expand Up @@ -963,29 +941,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
textEditWindow.PostMessage(WM_UNDO, 0, 0);
break;
}
if (selectionModel.m_bShow)
{
if (toolsModel.IsSelection())
{
canvasWindow.cancelDrawing();
if (toolsModel.GetActiveTool() == TOOL_FREESEL ||
toolsModel.GetActiveTool() == TOOL_RECTSEL)
{
imageModel.Undo();
if (selectionModel.m_nSelectionBrush == 2) // Selection Brush is drawn
{
imageModel.Undo();
selectionModel.m_nSelectionBrush = 0;
}
}
break;
}
}
if (ToolBase::s_pointSP != 0) // drawing something?
{
canvasWindow.cancelDrawing();
break;
}
canvasWindow.OnEndDraw(FALSE);
imageModel.Undo();
break;
case IDM_EDITREDO:
Expand All @@ -994,11 +950,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
// There is no "WM_REDO" in EDIT control
break;
}
if (ToolBase::s_pointSP != 0) // drawing something?
{
canvasWindow.finishDrawing();
break;
}
canvasWindow.OnEndDraw(FALSE);
imageModel.Redo();
break;
case IDM_EDITCOPY:
Expand Down Expand Up @@ -1113,7 +1065,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
break;

case TOOL_TEXT:
canvasWindow.cancelDrawing();
canvasWindow.OnEndDraw(TRUE);
break;
default:
break;
Expand Down
Loading

0 comments on commit 421341a

Please sign in to comment.