diff --git a/reactos/base/applications/mspaint_new/globalvar.h b/reactos/base/applications/mspaint_new/globalvar.h index 534647f20dc..7961100e0be 100644 --- a/reactos/base/applications/mspaint_new/globalvar.h +++ b/reactos/base/applications/mspaint_new/globalvar.h @@ -15,8 +15,6 @@ typedef struct tagSTRETCHSKEW { /* VARIABLES declared in main.c *************************************/ -extern HDC hDrawingDC; - extern int widthSetInDlg; extern int heightSetInDlg; diff --git a/reactos/base/applications/mspaint_new/history.cpp b/reactos/base/applications/mspaint_new/history.cpp index 8e6996b76ed..1aec2f5357a 100644 --- a/reactos/base/applications/mspaint_new/history.cpp +++ b/reactos/base/applications/mspaint_new/history.cpp @@ -210,3 +210,35 @@ void ImageModel::Clear(COLORREF color) Rectangle(hDrawingDC, 0 - 1, 0 - 1, GetWidth() + 1, GetHeight() + 1); NotifyImageChanged(); } + +HDC ImageModel::GetDC() +{ + return hDrawingDC; +} + +void ImageModel::FlipHorizontally() +{ + CopyPrevious(); + StretchBlt(hDrawingDC, GetWidth() - 1, 0, -GetWidth(), GetHeight(), GetDC(), 0, 0, + GetWidth(), GetHeight(), SRCCOPY); + NotifyImageChanged(); +} + +void ImageModel::FlipVertically() +{ + CopyPrevious(); + StretchBlt(hDrawingDC, 0, GetHeight() - 1, GetWidth(), -GetHeight(), GetDC(), 0, 0, + GetWidth(), GetHeight(), SRCCOPY); + NotifyImageChanged(); +} + +void ImageModel::RotateNTimes90Degrees(int iN) +{ + if (iN == 2) + { + CopyPrevious(); + StretchBlt(hDrawingDC, GetWidth() - 1, GetHeight() - 1, -GetWidth(), -GetHeight(), GetDC(), + 0, 0, GetWidth(), GetHeight(), SRCCOPY); + } + NotifyImageChanged(); +} diff --git a/reactos/base/applications/mspaint_new/history.h b/reactos/base/applications/mspaint_new/history.h index e02f27ae9e1..ad47bf9274b 100644 --- a/reactos/base/applications/mspaint_new/history.h +++ b/reactos/base/applications/mspaint_new/history.h @@ -11,6 +11,7 @@ class ImageModel private: void NotifyDimensionsChanged(); void NotifyImageChanged(); + HDC hDrawingDC; public: HBITMAP hBms[HISTORYSIZE]; private: @@ -37,4 +38,8 @@ public: int GetHeight(); void InvertColors(); void Clear(COLORREF color = 0x00ffffff); + HDC GetDC(); + void FlipHorizontally(); + void FlipVertically(); + void RotateNTimes90Degrees(int iN); }; diff --git a/reactos/base/applications/mspaint_new/imgarea.cpp b/reactos/base/applications/mspaint_new/imgarea.cpp index d00c9050b23..a6cdf0b22ce 100644 --- a/reactos/base/applications/mspaint_new/imgarea.cpp +++ b/reactos/base/applications/mspaint_new/imgarea.cpp @@ -99,7 +99,7 @@ LRESULT CImgAreaWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& b HDC hdc = GetDC(); int imgXRes = imageModel.GetWidth(); int imgYRes = imageModel.GetHeight(); - StretchBlt(hdc, 0, 0, imgXRes * toolsModel.GetZoom() / 1000, imgYRes * toolsModel.GetZoom() / 1000, hDrawingDC, 0, 0, imgXRes, + StretchBlt(hdc, 0, 0, imgXRes * toolsModel.GetZoom() / 1000, imgYRes * toolsModel.GetZoom() / 1000, imageModel.GetDC(), 0, 0, imgXRes, imgYRes, SRCCOPY); if (showGrid && (toolsModel.GetZoom() >= 4000)) { @@ -154,7 +154,7 @@ LRESULT CImgAreaWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, B { SetCapture(); drawing = TRUE; - startPaintingL(hDrawingDC, GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), + startPaintingL(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(), paletteModel.GetBgColor()); } else @@ -174,7 +174,7 @@ LRESULT CImgAreaWindow::OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, B { SetCapture(); drawing = TRUE; - startPaintingR(hDrawingDC, GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), + startPaintingR(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(), paletteModel.GetBgColor()); } else @@ -194,13 +194,13 @@ LRESULT CImgAreaWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO { ReleaseCapture(); drawing = FALSE; - endPaintingL(hDrawingDC, GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(), + endPaintingL(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(), paletteModel.GetBgColor()); Invalidate(FALSE); if (toolsModel.GetActiveTool() == TOOL_COLOR) { COLORREF tempColor = - GetPixel(hDrawingDC, GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom()); + GetPixel(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom()); if (tempColor != CLR_INVALID) paletteModel.SetFgColor(tempColor); } @@ -215,13 +215,13 @@ LRESULT CImgAreaWindow::OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO { ReleaseCapture(); drawing = FALSE; - endPaintingR(hDrawingDC, GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(), + endPaintingR(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(), paletteModel.GetBgColor()); Invalidate(FALSE); if (toolsModel.GetActiveTool() == TOOL_COLOR) { COLORREF tempColor = - GetPixel(hDrawingDC, GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom()); + GetPixel(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom()); if (tempColor != CLR_INVALID) paletteModel.SetBgColor(tempColor); } @@ -300,7 +300,7 @@ LRESULT CImgAreaWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO } if ((wParam & MK_LBUTTON) != 0) { - whilePaintingL(hDrawingDC, xNow, yNow, paletteModel.GetFgColor(), paletteModel.GetBgColor()); + whilePaintingL(imageModel.GetDC(), xNow, yNow, paletteModel.GetFgColor(), paletteModel.GetBgColor()); Invalidate(FALSE); if ((toolsModel.GetActiveTool() >= TOOL_TEXT) || (toolsModel.GetActiveTool() == TOOL_RECTSEL) || (toolsModel.GetActiveTool() == TOOL_FREESEL)) { @@ -313,7 +313,7 @@ LRESULT CImgAreaWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO } if ((wParam & MK_RBUTTON) != 0) { - whilePaintingR(hDrawingDC, xNow, yNow, paletteModel.GetFgColor(), paletteModel.GetBgColor()); + whilePaintingR(imageModel.GetDC(), xNow, yNow, paletteModel.GetFgColor(), paletteModel.GetBgColor()); Invalidate(FALSE); if (toolsModel.GetActiveTool() >= TOOL_TEXT) { diff --git a/reactos/base/applications/mspaint_new/main.cpp b/reactos/base/applications/mspaint_new/main.cpp index e39c435aeaa..3a2793bcecc 100644 --- a/reactos/base/applications/mspaint_new/main.cpp +++ b/reactos/base/applications/mspaint_new/main.cpp @@ -12,8 +12,6 @@ /* FUNCTIONS ********************************************************/ -HDC hDrawingDC; - int widthSetInDlg; int heightSetInDlg; diff --git a/reactos/base/applications/mspaint_new/miniature.cpp b/reactos/base/applications/mspaint_new/miniature.cpp index 702c7252901..fb11459b797 100644 --- a/reactos/base/applications/mspaint_new/miniature.cpp +++ b/reactos/base/applications/mspaint_new/miniature.cpp @@ -27,7 +27,7 @@ LRESULT CMiniatureWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& HDC hdc; miniature.GetClientRect(&mclient); hdc = miniature.GetDC(); - StretchBlt(hdc, 0, 0, mclient.right, mclient.bottom, hDrawingDC, 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), SRCCOPY); + StretchBlt(hdc, 0, 0, mclient.right, mclient.bottom, imageModel.GetDC(), 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), SRCCOPY); miniature.ReleaseDC(hdc); return 0; } diff --git a/reactos/base/applications/mspaint_new/selection.cpp b/reactos/base/applications/mspaint_new/selection.cpp index 906692982be..8bf57b63764 100644 --- a/reactos/base/applications/mspaint_new/selection.cpp +++ b/reactos/base/applications/mspaint_new/selection.cpp @@ -178,14 +178,14 @@ LRESULT CSelectionWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, B if (toolsModel.GetActiveTool() == TOOL_TEXT) { - selectionModel.DrawTextToolText(hDrawingDC, paletteModel.GetFgColor(), paletteModel.GetBgColor(), toolsModel.IsBackgroundTransparent()); + selectionModel.DrawTextToolText(imageModel.GetDC(), paletteModel.GetFgColor(), paletteModel.GetBgColor(), toolsModel.IsBackgroundTransparent()); } else { if (m_iAction != ACTION_MOVE) - selectionModel.DrawSelectionStretched(hDrawingDC); + selectionModel.DrawSelectionStretched(imageModel.GetDC()); else - selectionModel.DrawSelection(hDrawingDC, paletteModel.GetBgColor(), toolsModel.IsBackgroundTransparent()); + selectionModel.DrawSelection(imageModel.GetDC(), paletteModel.GetBgColor(), toolsModel.IsBackgroundTransparent()); } imageArea.InvalidateRect(NULL, FALSE); imageArea.SendMessage(WM_PAINT, 0, 0); diff --git a/reactos/base/applications/mspaint_new/winproc.cpp b/reactos/base/applications/mspaint_new/winproc.cpp index d088e60879d..279c157e140 100644 --- a/reactos/base/applications/mspaint_new/winproc.cpp +++ b/reactos/base/applications/mspaint_new/winproc.cpp @@ -306,9 +306,9 @@ LRESULT CMainWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH /* Deselect */ if ((toolsModel.GetActiveTool() == TOOL_RECTSEL) || (toolsModel.GetActiveTool() == TOOL_FREESEL)) { - startPaintingL(hDrawingDC, 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor()); - whilePaintingL(hDrawingDC, 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor()); - endPaintingL(hDrawingDC, 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor()); + startPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor()); + whilePaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor()); + endPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor()); selectionWindow.ShowWindow(SW_HIDE); } } @@ -443,14 +443,14 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0)); toolBoxContainer.SendMessage(WM_COMMAND, ID_RECTSEL); //TODO: do this properly - startPaintingL(hDrawingDC, 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor()); - whilePaintingL(hDrawingDC, imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor()); - endPaintingL(hDrawingDC, imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor()); + startPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor()); + whilePaintingL(imageModel.GetDC(), imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor()); + endPaintingL(imageModel.GetDC(), imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor()); break; } case IDM_EDITCOPYTO: if (GetSaveFileName(&ofn) != 0) - SaveDIBToFile(selectionModel.GetBitmap(), ofn.lpstrFile, hDrawingDC, NULL, NULL, fileHPPM, fileVPPM); + SaveDIBToFile(selectionModel.GetBitmap(), ofn.lpstrFile, imageModel.GetDC(), NULL, NULL, fileHPPM, fileVPPM); break; case IDM_EDITPASTEFROM: if (GetOpenFileName(&ofn) != 0) @@ -481,7 +481,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH } case IDM_IMAGEDELETEIMAGE: imageModel.CopyPrevious(); - Rect(hDrawingDC, 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetBgColor(), paletteModel.GetBgColor(), 0, TRUE); + Rect(imageModel.GetDC(), 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetBgColor(), paletteModel.GetBgColor(), 0, TRUE); imageArea.Invalidate(FALSE); break; case IDM_IMAGEROTATEMIRROR: @@ -491,23 +491,13 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH if (selectionWindow.IsWindowVisible()) selectionModel.FlipHorizontally(); else - { - imageModel.CopyPrevious(); - StretchBlt(hDrawingDC, imageModel.GetWidth() - 1, 0, -imageModel.GetWidth(), imageModel.GetHeight(), hDrawingDC, 0, 0, - imageModel.GetWidth(), imageModel.GetHeight(), SRCCOPY); - imageArea.Invalidate(FALSE); - } + imageModel.FlipHorizontally(); break; case 2: /* flip vertically */ if (selectionWindow.IsWindowVisible()) selectionModel.FlipVertically(); else - { - imageModel.CopyPrevious(); - StretchBlt(hDrawingDC, 0, imageModel.GetHeight() - 1, imageModel.GetWidth(), -imageModel.GetHeight(), hDrawingDC, 0, 0, - imageModel.GetWidth(), imageModel.GetHeight(), SRCCOPY); - imageArea.Invalidate(FALSE); - } + imageModel.FlipVertically(); break; case 3: /* rotate 90 degrees */ break; @@ -515,12 +505,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH if (selectionWindow.IsWindowVisible()) selectionModel.RotateNTimes90Degrees(2); else - { - imageModel.CopyPrevious(); - StretchBlt(hDrawingDC, imageModel.GetWidth() - 1, imageModel.GetHeight() - 1, -imageModel.GetWidth(), -imageModel.GetHeight(), hDrawingDC, - 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), SRCCOPY); - imageArea.Invalidate(FALSE); - } + imageModel.RotateNTimes90Degrees(2); break; case 5: /* rotate 270 degrees */ break;