mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 16:02:56 +00:00
[MSPAINT] Improve GetSelectionContents for free-shape selection (#6554)
Follow-up to #6552. There was a bug that the cropped selection image is not the shape of selection. JIRA issue: CORE-19466 - Extend SelectionModel:: DrawSelection for drawing selection flexibly. - Improve SelectionModel:: GetSelectionContents method.
This commit is contained in:
parent
f0e45f07e1
commit
e928b42758
3 changed files with 34 additions and 11 deletions
|
@ -1056,8 +1056,8 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
|
||||||
HBITMAP hbmSelection = selectionModel.GetSelectionContents();
|
HBITMAP hbmSelection = selectionModel.GetSelectionContents();
|
||||||
if (hbmSelection)
|
if (hbmSelection)
|
||||||
{
|
{
|
||||||
selectionModel.HideSelection();
|
|
||||||
imageModel.PushImageForUndo(hbmSelection);
|
imageModel.PushImageForUndo(hbmSelection);
|
||||||
|
selectionModel.HideSelection();
|
||||||
imageModel.NotifyImageChanged();
|
imageModel.NotifyImageChanged();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -58,20 +58,21 @@ void SelectionModel::DrawBackground(HDC hDCImage, COLORREF crBg)
|
||||||
DrawBackgroundRect(hDCImage, crBg);
|
DrawBackgroundRect(hDCImage, crBg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionModel::DrawSelection(HDC hDCImage, COLORREF crBg, BOOL bBgTransparent)
|
void
|
||||||
|
SelectionModel::DrawSelection(HDC hDCImage, COLORREF crBg, BOOL bBgTransparent, const CRect& rc,
|
||||||
|
HBITMAP hbm)
|
||||||
{
|
{
|
||||||
CRect rc = m_rc;
|
|
||||||
if (rc.IsRectEmpty())
|
if (rc.IsRectEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BITMAP bm;
|
BITMAP bm;
|
||||||
if (!GetObjectW(m_hbmColor, sizeof(BITMAP), &bm))
|
if (!GetObjectW(hbm, sizeof(BITMAP), &bm))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
COLORREF keyColor = (bBgTransparent ? crBg : CLR_INVALID);
|
COLORREF keyColor = (bBgTransparent ? crBg : CLR_INVALID);
|
||||||
|
|
||||||
HDC hMemDC = CreateCompatibleDC(hDCImage);
|
HDC hMemDC = CreateCompatibleDC(hDCImage);
|
||||||
HGDIOBJ hbmOld = SelectObject(hMemDC, m_hbmColor);
|
HGDIOBJ hbmOld = SelectObject(hMemDC, hbm);
|
||||||
ColorKeyedMaskBlt(hDCImage, rc.left, rc.top, rc.Width(), rc.Height(),
|
ColorKeyedMaskBlt(hDCImage, rc.left, rc.top, rc.Width(), rc.Height(),
|
||||||
hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, m_hbmMask, keyColor);
|
hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, m_hbmMask, keyColor);
|
||||||
SelectObject(hMemDC, hbmOld);
|
SelectObject(hMemDC, hbmOld);
|
||||||
|
@ -89,13 +90,23 @@ void SelectionModel::setMask(const CRect& rc, HBITMAP hbmMask)
|
||||||
|
|
||||||
HBITMAP SelectionModel::GetSelectionContents()
|
HBITMAP SelectionModel::GetSelectionContents()
|
||||||
{
|
{
|
||||||
if (m_hbmColor)
|
|
||||||
return CopyDIBImage(m_hbmColor, m_rc.Width(), m_rc.Height());
|
|
||||||
|
|
||||||
HBITMAP hbmWhole = imageModel.LockBitmap();
|
HBITMAP hbmWhole = imageModel.LockBitmap();
|
||||||
HBITMAP hbmPart = getSubImage(hbmWhole, m_rc);
|
HBITMAP hbmPart = getSubImage(hbmWhole, (IsLanded() ? m_rc : m_rcOld));
|
||||||
imageModel.UnlockBitmap(hbmWhole);
|
imageModel.UnlockBitmap(hbmWhole);
|
||||||
return hbmPart;
|
if (!hbmPart)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
CRect rc = { 0, 0, m_rc.Width(), m_rc.Height() };
|
||||||
|
|
||||||
|
HDC hdcMem = ::CreateCompatibleDC(NULL);
|
||||||
|
HBITMAP hbmNew = CreateColorDIB(rc.Width(), rc.Height(), paletteModel.GetBgColor());
|
||||||
|
HGDIOBJ hbmOld = ::SelectObject(hdcMem, hbmNew);
|
||||||
|
selectionModel.DrawSelection(hdcMem, paletteModel.GetBgColor(), TRUE, rc, hbmPart);
|
||||||
|
::SelectObject(hdcMem, hbmOld);
|
||||||
|
::DeleteDC(hdcMem);
|
||||||
|
|
||||||
|
::DeleteObject(hbmPart);
|
||||||
|
return hbmNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL SelectionModel::IsLanded() const
|
BOOL SelectionModel::IsLanded() const
|
||||||
|
|
|
@ -41,7 +41,19 @@ public:
|
||||||
void DrawBackground(HDC hDCImage, COLORREF crBg);
|
void DrawBackground(HDC hDCImage, COLORREF crBg);
|
||||||
void DrawBackgroundPoly(HDC hDCImage, COLORREF crBg);
|
void DrawBackgroundPoly(HDC hDCImage, COLORREF crBg);
|
||||||
void DrawBackgroundRect(HDC hDCImage, COLORREF crBg);
|
void DrawBackgroundRect(HDC hDCImage, COLORREF crBg);
|
||||||
void DrawSelection(HDC hDCImage, COLORREF crBg = 0, BOOL bBgTransparent = FALSE);
|
|
||||||
|
void DrawSelection(HDC hDCImage, COLORREF crBg, BOOL bBgTransparent, const CRect& rc, HBITMAP hbm);
|
||||||
|
|
||||||
|
void DrawSelection(HDC hDCImage, COLORREF crBg, BOOL bBgTransparent)
|
||||||
|
{
|
||||||
|
return DrawSelection(hDCImage, crBg, bBgTransparent, m_rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawSelection(HDC hDCImage, COLORREF crBg, BOOL bBgTransparent, const CRect& rc)
|
||||||
|
{
|
||||||
|
return DrawSelection(hDCImage, crBg, bBgTransparent, rc, m_hbmColor);
|
||||||
|
}
|
||||||
|
|
||||||
void InsertFromHBITMAP(HBITMAP hbmColor, INT x = 0, INT y = 0, HBITMAP hbmMask = NULL);
|
void InsertFromHBITMAP(HBITMAP hbmColor, INT x = 0, INT y = 0, HBITMAP hbmMask = NULL);
|
||||||
|
|
||||||
// operation
|
// operation
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue