[MSPAINT] "Selection Clone" and "Selection Brush" (#5734)

- Stamp the image of the selection when the user clicks on
  the selection while holding down the Ctrl key.
- Draw the image of the selection continuously when the user
  starts dragging the selection while holding down the Shift key.
CORE-19094
This commit is contained in:
Katayama Hirofumi MZ 2023-09-28 07:34:25 +09:00 committed by GitHub
parent 03283371c1
commit cbc63d876c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 6 deletions

View file

@ -268,9 +268,18 @@ LRESULT CCanvasWindow::OnLRButtonDown(BOOL bLeftButton, UINT nMsg, WPARAM wParam
HITTEST hitSelection = SelectionHitTest(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
@ -790,6 +799,12 @@ VOID CCanvasWindow::StartSelectionDrag(HITTEST hit, POINT ptImage)
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);
}

View file

@ -299,3 +299,16 @@ void ImageModel::UnlockBitmap(HBITMAP hbmLocked)
m_hBms[m_currInd] = hbmLocked;
m_hbmOld = ::SelectObject(m_hDrawingDC, hbmLocked); // Re-select
}
void ImageModel::SelectionClone(BOOL bUndoable)
{
if (!selectionModel.m_bShow || ::IsRectEmpty(&selectionModel.m_rc))
return;
if (bUndoable)
PushImageForUndo(CopyBitmap());
selectionModel.DrawSelection(m_hDrawingDC, paletteModel.GetBgColor(),
toolsModel.IsBackgroundTransparent());
NotifyImageChanged();
}

View file

@ -41,6 +41,7 @@ public:
void NotifyImageChanged();
BOOL IsBlackAndWhite();
void PushBlackAndWhite();
void SelectionClone(BOOL bUndoable = TRUE);
protected:
HDC m_hDrawingDC; // The device context for this class

View file

@ -112,10 +112,7 @@ struct FreeSelTool : ToolBase
void OnDrawOverlayOnImage(HDC hdc) override
{
if (!selectionModel.IsLanded())
{
selectionModel.DrawBackgroundPoly(hdc, selectionModel.m_rgbBack);
selectionModel.DrawSelection(hdc, paletteModel.GetBgColor(), toolsModel.IsBackgroundTransparent());
}
if (canvasWindow.m_drawing)
{
@ -208,10 +205,7 @@ struct RectSelTool : ToolBase
void OnDrawOverlayOnImage(HDC hdc) override
{
if (!selectionModel.IsLanded())
{
selectionModel.DrawBackgroundRect(hdc, selectionModel.m_rgbBack);
selectionModel.DrawSelection(hdc, paletteModel.GetBgColor(), toolsModel.IsBackgroundTransparent());
}
if (canvasWindow.m_drawing)
{

View file

@ -187,6 +187,17 @@ BOOL SelectionModel::TakeOff()
// Save the selection area
m_rcOld = m_rc;
if (toolsModel.GetActiveTool() == TOOL_RECTSEL)
{
imageModel.PushImageForUndo();
selectionModel.DrawBackgroundRect(imageModel.GetDC(), selectionModel.m_rgbBack);
}
else if (toolsModel.GetActiveTool() == TOOL_FREESEL)
{
imageModel.PushImageForUndo();
selectionModel.DrawBackgroundPoly(imageModel.GetDC(), selectionModel.m_rgbBack);
}
imageModel.NotifyImageChanged();
return TRUE;
}

View file

@ -23,6 +23,7 @@ public:
CRect m_rc; // in image pixel coordinates
POINT m_ptHit; // in image pixel coordinates
CRect m_rcOld; // in image pixel coordinates
INT m_nSelectionBrush = 0;
SelectionModel();
~SelectionModel();

View file

@ -704,6 +704,16 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
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;
}
}