mirror of
https://github.com/reactos/reactos.git
synced 2025-02-20 15:35:04 +00:00
[MSPAINT] Add Zoomed and UnZoomed and use them (#4188)
- Define Zoomed and UnZoomed helper functions. - Use them. CORE-17931
This commit is contained in:
parent
50cb4b3cb7
commit
9e1386db43
10 changed files with 59 additions and 48 deletions
|
@ -5,10 +5,21 @@
|
|||
* PURPOSE: Commonly used functions
|
||||
* PROGRAMMERS: Benedikt Freisen
|
||||
* Stanislav Motylkov
|
||||
* Katayama Hirofumi MZ
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/* FUNCTIONS ********************************************************/
|
||||
|
||||
extern BOOL zoomTo(int, int, int);
|
||||
BOOL zoomTo(int newZoom, int mouseX, int mouseY);
|
||||
|
||||
static inline int Zoomed(int xy)
|
||||
{
|
||||
return xy * toolsModel.GetZoom() / 1000;
|
||||
}
|
||||
|
||||
static inline int UnZoomed(int xy)
|
||||
{
|
||||
return xy * 1000 / toolsModel.GetZoom();
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ updateCanvasAndScrollbars()
|
|||
{
|
||||
selectionWindow.ShowWindow(SW_HIDE);
|
||||
|
||||
int zoomedWidth = imageModel.GetWidth() * toolsModel.GetZoom() / 1000;
|
||||
int zoomedHeight = imageModel.GetHeight() * toolsModel.GetZoom() / 1000;
|
||||
int zoomedWidth = Zoomed(imageModel.GetWidth());
|
||||
int zoomedHeight = Zoomed(imageModel.GetHeight());
|
||||
imageArea.MoveWindow(3, 3, zoomedWidth, zoomedHeight, FALSE);
|
||||
|
||||
scrollboxWindow.Invalidate(TRUE);
|
||||
|
@ -76,26 +76,26 @@ LRESULT CImgAreaWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
|
|||
0,
|
||||
0, 3, 3, TRUE);
|
||||
sizeboxCenterTop.MoveWindow(
|
||||
imgXRes * toolsModel.GetZoom() / 2000 + 3 * 3 / 4,
|
||||
Zoomed(imgXRes) / 2 + 3 * 3 / 4,
|
||||
0, 3, 3, TRUE);
|
||||
sizeboxRightTop.MoveWindow(
|
||||
imgXRes * toolsModel.GetZoom() / 1000 + 3,
|
||||
Zoomed(imgXRes) + 3,
|
||||
0, 3, 3, TRUE);
|
||||
sizeboxLeftCenter.MoveWindow(
|
||||
0,
|
||||
imgYRes * toolsModel.GetZoom() / 2000 + 3 * 3 / 4, 3, 3, TRUE);
|
||||
Zoomed(imgYRes) / 2 + 3 * 3 / 4, 3, 3, TRUE);
|
||||
sizeboxRightCenter.MoveWindow(
|
||||
imgXRes * toolsModel.GetZoom() / 1000 + 3,
|
||||
imgYRes * toolsModel.GetZoom() / 2000 + 3 * 3 / 4, 3, 3, TRUE);
|
||||
Zoomed(imgXRes) + 3,
|
||||
Zoomed(imgYRes) / 2 + 3 * 3 / 4, 3, 3, TRUE);
|
||||
sizeboxLeftBottom.MoveWindow(
|
||||
0,
|
||||
imgYRes * toolsModel.GetZoom() / 1000 + 3, 3, 3, TRUE);
|
||||
Zoomed(imgYRes) + 3, 3, 3, TRUE);
|
||||
sizeboxCenterBottom.MoveWindow(
|
||||
imgXRes * toolsModel.GetZoom() / 2000 + 3 * 3 / 4,
|
||||
imgYRes * toolsModel.GetZoom() / 1000 + 3, 3, 3, TRUE);
|
||||
Zoomed(imgXRes) / 2 + 3 * 3 / 4,
|
||||
Zoomed(imgYRes) + 3, 3, 3, TRUE);
|
||||
sizeboxRightBottom.MoveWindow(
|
||||
imgXRes * toolsModel.GetZoom() / 1000 + 3,
|
||||
imgYRes * toolsModel.GetZoom() / 1000 + 3, 3, 3, TRUE);
|
||||
Zoomed(imgXRes) + 3,
|
||||
Zoomed(imgYRes) + 3, 3, 3, TRUE);
|
||||
UpdateScrollbox();
|
||||
return 0;
|
||||
}
|
||||
|
@ -106,7 +106,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, imageModel.GetDC(), 0, 0, imgXRes,
|
||||
StretchBlt(hdc, 0, 0, Zoomed(imgXRes), Zoomed(imgYRes), imageModel.GetDC(), 0, 0, imgXRes,
|
||||
imgYRes, SRCCOPY);
|
||||
if (showGrid && (toolsModel.GetZoom() >= 4000))
|
||||
{
|
||||
|
@ -114,13 +114,13 @@ LRESULT CImgAreaWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& b
|
|||
int counter;
|
||||
for(counter = 0; counter <= imgYRes; counter++)
|
||||
{
|
||||
MoveToEx(hdc, 0, counter * toolsModel.GetZoom() / 1000, NULL);
|
||||
LineTo(hdc, imgXRes * toolsModel.GetZoom() / 1000, counter * toolsModel.GetZoom() / 1000);
|
||||
MoveToEx(hdc, 0, Zoomed(counter), NULL);
|
||||
LineTo(hdc, Zoomed(imgXRes), Zoomed(counter));
|
||||
}
|
||||
for(counter = 0; counter <= imgXRes; counter++)
|
||||
{
|
||||
MoveToEx(hdc, counter * toolsModel.GetZoom() / 1000, 0, NULL);
|
||||
LineTo(hdc, counter * toolsModel.GetZoom() / 1000, imgYRes * toolsModel.GetZoom() / 1000);
|
||||
MoveToEx(hdc, Zoomed(counter), 0, NULL);
|
||||
LineTo(hdc, Zoomed(counter), Zoomed(imgYRes));
|
||||
}
|
||||
DeleteObject(SelectObject(hdc, oldPen));
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ LRESULT CImgAreaWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, B
|
|||
{
|
||||
SetCapture();
|
||||
drawing = TRUE;
|
||||
startPaintingL(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(),
|
||||
startPaintingL(imageModel.GetDC(), UnZoomed(GET_X_LPARAM(lParam)), UnZoomed(GET_Y_LPARAM(lParam)),
|
||||
paletteModel.GetFgColor(), paletteModel.GetBgColor());
|
||||
}
|
||||
else
|
||||
|
@ -181,7 +181,7 @@ LRESULT CImgAreaWindow::OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, B
|
|||
{
|
||||
SetCapture();
|
||||
drawing = TRUE;
|
||||
startPaintingR(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(),
|
||||
startPaintingR(imageModel.GetDC(), UnZoomed(GET_X_LPARAM(lParam)), UnZoomed(GET_Y_LPARAM(lParam)),
|
||||
paletteModel.GetFgColor(), paletteModel.GetBgColor());
|
||||
}
|
||||
else
|
||||
|
@ -199,13 +199,13 @@ LRESULT CImgAreaWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
|
|||
{
|
||||
if (drawing)
|
||||
{
|
||||
endPaintingL(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(),
|
||||
endPaintingL(imageModel.GetDC(), UnZoomed(GET_X_LPARAM(lParam)), UnZoomed(GET_Y_LPARAM(lParam)), paletteModel.GetFgColor(),
|
||||
paletteModel.GetBgColor());
|
||||
Invalidate(FALSE);
|
||||
if (toolsModel.GetActiveTool() == TOOL_COLOR)
|
||||
{
|
||||
COLORREF tempColor =
|
||||
GetPixel(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom());
|
||||
GetPixel(imageModel.GetDC(), UnZoomed(GET_X_LPARAM(lParam)), UnZoomed(GET_Y_LPARAM(lParam)));
|
||||
if (tempColor != CLR_INVALID)
|
||||
paletteModel.SetFgColor(tempColor);
|
||||
}
|
||||
|
@ -234,12 +234,12 @@ void CImgAreaWindow::cancelDrawing()
|
|||
// FIXME: dirty hack
|
||||
if (GetKeyState(VK_LBUTTON) < 0)
|
||||
{
|
||||
endPaintingL(imageModel.GetDC(), pt.x * 1000 / toolsModel.GetZoom(), pt.y * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(),
|
||||
endPaintingL(imageModel.GetDC(), UnZoomed(pt.x), UnZoomed(pt.y), paletteModel.GetFgColor(),
|
||||
paletteModel.GetBgColor());
|
||||
}
|
||||
else if (GetKeyState(VK_RBUTTON) < 0)
|
||||
{
|
||||
endPaintingR(imageModel.GetDC(), pt.x * 1000 / toolsModel.GetZoom(), pt.y * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(),
|
||||
endPaintingR(imageModel.GetDC(), UnZoomed(pt.x), UnZoomed(pt.y), paletteModel.GetFgColor(),
|
||||
paletteModel.GetBgColor());
|
||||
}
|
||||
imageModel.Undo();
|
||||
|
@ -283,13 +283,13 @@ LRESULT CImgAreaWindow::OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
|
|||
{
|
||||
if (drawing)
|
||||
{
|
||||
endPaintingR(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(),
|
||||
endPaintingR(imageModel.GetDC(), UnZoomed(GET_X_LPARAM(lParam)), UnZoomed(GET_Y_LPARAM(lParam)), paletteModel.GetFgColor(),
|
||||
paletteModel.GetBgColor());
|
||||
Invalidate(FALSE);
|
||||
if (toolsModel.GetActiveTool() == TOOL_COLOR)
|
||||
{
|
||||
COLORREF tempColor =
|
||||
GetPixel(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom());
|
||||
GetPixel(imageModel.GetDC(), UnZoomed(GET_X_LPARAM(lParam)), UnZoomed(GET_Y_LPARAM(lParam)));
|
||||
if (tempColor != CLR_INVALID)
|
||||
paletteModel.SetBgColor(tempColor);
|
||||
}
|
||||
|
@ -302,8 +302,8 @@ LRESULT CImgAreaWindow::OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
|
|||
|
||||
LRESULT CImgAreaWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||||
{
|
||||
LONG xNow = GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom();
|
||||
LONG yNow = GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom();
|
||||
LONG xNow = UnZoomed(GET_X_LPARAM(lParam));
|
||||
LONG yNow = UnZoomed(GET_Y_LPARAM(lParam));
|
||||
if ((!drawing) || (toolsModel.GetActiveTool() <= TOOL_AIRBRUSH))
|
||||
{
|
||||
TRACKMOUSEEVENT tme;
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
void
|
||||
placeSelWin()
|
||||
{
|
||||
selectionWindow.MoveWindow(selectionModel.GetDestRectLeft() * toolsModel.GetZoom() / 1000, selectionModel.GetDestRectTop() * toolsModel.GetZoom() / 1000,
|
||||
selectionModel.GetDestRectWidth() * toolsModel.GetZoom() / 1000 + 6, selectionModel.GetDestRectHeight() * toolsModel.GetZoom() / 1000 + 6, TRUE);
|
||||
selectionWindow.MoveWindow(Zoomed(selectionModel.GetDestRectLeft()), Zoomed(selectionModel.GetDestRectTop()),
|
||||
Zoomed(selectionModel.GetDestRectWidth()) + 6, Zoomed(selectionModel.GetDestRectHeight()) + 6, TRUE);
|
||||
selectionWindow.BringWindowToTop();
|
||||
imageArea.InvalidateRect(NULL, FALSE);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include <shellapi.h>
|
||||
#include <htmlhelp.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "definitions.h"
|
||||
#include "drawing.h"
|
||||
#include "dib.h"
|
||||
|
@ -43,5 +42,6 @@
|
|||
#include "toolsettings.h"
|
||||
#include "toolsmodel.h"
|
||||
#include "winproc.h"
|
||||
#include "common.h"
|
||||
|
||||
#endif /* _MSPAINT_H */
|
||||
|
|
|
@ -132,8 +132,8 @@ LRESULT CScrollboxWindow::OnHScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
|
|||
}
|
||||
scrollboxWindow.SetScrollInfo(SB_HORZ, &si);
|
||||
scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
|
||||
-scrollboxWindow.GetScrollPos(SB_VERT), imageModel.GetWidth() * toolsModel.GetZoom() / 1000 + 6,
|
||||
imageModel.GetHeight() * toolsModel.GetZoom() / 1000 + 6, TRUE);
|
||||
-scrollboxWindow.GetScrollPos(SB_VERT), Zoomed(imageModel.GetWidth()) + 6,
|
||||
Zoomed(imageModel.GetHeight()) + 6, TRUE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -167,8 +167,8 @@ LRESULT CScrollboxWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
|
|||
}
|
||||
scrollboxWindow.SetScrollInfo(SB_VERT, &si);
|
||||
scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
|
||||
-scrollboxWindow.GetScrollPos(SB_VERT), imageModel.GetWidth() * toolsModel.GetZoom() / 1000 + 6,
|
||||
imageModel.GetHeight() * toolsModel.GetZoom() / 1000 + 6, TRUE);
|
||||
-scrollboxWindow.GetScrollPos(SB_VERT), Zoomed(imageModel.GetWidth()) + 6,
|
||||
Zoomed(imageModel.GetHeight()) + 6, TRUE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -99,8 +99,8 @@ LRESULT CSelectionWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
|
|||
{
|
||||
HDC hDC = GetDC();
|
||||
DefWindowProc(WM_PAINT, wParam, lParam);
|
||||
SelectionFrame(hDC, 1, 1, selectionModel.GetDestRectWidth() * toolsModel.GetZoom() / 1000 + 5,
|
||||
selectionModel.GetDestRectHeight() * toolsModel.GetZoom() / 1000 + 5,
|
||||
SelectionFrame(hDC, 1, 1, Zoomed(selectionModel.GetDestRectWidth()) + 5,
|
||||
Zoomed(selectionModel.GetDestRectHeight()) + 5,
|
||||
m_dwSystemSelectionColor);
|
||||
ReleaseDC(hDC);
|
||||
}
|
||||
|
@ -161,8 +161,8 @@ LRESULT CSelectionWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, B
|
|||
imageModel.ResetToPrevious();
|
||||
m_ptFrac.x += GET_X_LPARAM(lParam) - m_ptPos.x;
|
||||
m_ptFrac.y += GET_Y_LPARAM(lParam) - m_ptPos.y;
|
||||
m_ptDelta.x += m_ptFrac.x * 1000 / toolsModel.GetZoom();
|
||||
m_ptDelta.y += m_ptFrac.y * 1000 / toolsModel.GetZoom();
|
||||
m_ptDelta.x += UnZoomed(m_ptFrac.x);
|
||||
m_ptDelta.y += UnZoomed(m_ptFrac.y);
|
||||
if (toolsModel.GetZoom() < 1000)
|
||||
{
|
||||
m_ptFrac.x = 0;
|
||||
|
@ -170,8 +170,8 @@ LRESULT CSelectionWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, B
|
|||
}
|
||||
else
|
||||
{
|
||||
m_ptFrac.x -= (m_ptFrac.x * 1000 / toolsModel.GetZoom()) * toolsModel.GetZoom() / 1000;
|
||||
m_ptFrac.y -= (m_ptFrac.y * 1000 / toolsModel.GetZoom()) * toolsModel.GetZoom() / 1000;
|
||||
m_ptFrac.x -= Zoomed(UnZoomed(m_ptFrac.x));
|
||||
m_ptFrac.y -= Zoomed(UnZoomed(m_ptFrac.y));
|
||||
}
|
||||
selectionModel.ModifyDestRect(m_ptDelta, m_iAction);
|
||||
|
||||
|
@ -197,8 +197,8 @@ LRESULT CSelectionWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, B
|
|||
}
|
||||
else
|
||||
{
|
||||
int w = selectionModel.GetDestRectWidth() * toolsModel.GetZoom() / 1000 + 6;
|
||||
int h = selectionModel.GetDestRectHeight() * toolsModel.GetZoom() / 1000 + 6;
|
||||
int w = Zoomed(selectionModel.GetDestRectWidth()) + 6;
|
||||
int h = Zoomed(selectionModel.GetDestRectHeight()) + 6;
|
||||
m_ptPos.x = GET_X_LPARAM(lParam);
|
||||
m_ptPos.y = GET_Y_LPARAM(lParam);
|
||||
SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) NULL);
|
||||
|
|
|
@ -48,8 +48,8 @@ LRESULT CSizeboxWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
|
|||
short yRel;
|
||||
int imgXRes = imageModel.GetWidth();
|
||||
int imgYRes = imageModel.GetHeight();
|
||||
xRel = (GET_X_LPARAM(lParam) - xOrig) * 1000 / toolsModel.GetZoom();
|
||||
yRel = (GET_Y_LPARAM(lParam) - yOrig) * 1000 / toolsModel.GetZoom();
|
||||
xRel = UnZoomed(GET_X_LPARAM(lParam) - xOrig);
|
||||
yRel = UnZoomed(GET_Y_LPARAM(lParam) - yOrig);
|
||||
if (m_hWnd == sizeboxLeftTop.m_hWnd)
|
||||
strSize.Format(_T("%d x %d"), imgXRes - xRel, imgYRes - yRel);
|
||||
if (m_hWnd == sizeboxCenterTop.m_hWnd)
|
||||
|
|
|
@ -101,7 +101,7 @@ void ToolsModel::SetBackgroundTransparent(BOOL bTransparent)
|
|||
NotifyToolSettingsChanged();
|
||||
}
|
||||
|
||||
int ToolsModel::GetZoom()
|
||||
int ToolsModel::GetZoom() const
|
||||
{
|
||||
return m_zoom;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,6 @@ public:
|
|||
void SetRubberRadius(int nRubberRadius);
|
||||
BOOL IsBackgroundTransparent();
|
||||
void SetBackgroundTransparent(BOOL bTransparent);
|
||||
int GetZoom();
|
||||
int GetZoom() const;
|
||||
void SetZoom(int nZoom);
|
||||
};
|
||||
|
|
|
@ -39,7 +39,7 @@ zoomTo(int newZoom, int mouseX, int mouseY)
|
|||
toolsModel.SetZoom(newZoom);
|
||||
|
||||
selectionWindow.ShowWindow(SW_HIDE);
|
||||
imageArea.MoveWindow(3, 3, imageModel.GetWidth() * toolsModel.GetZoom() / 1000, imageModel.GetHeight() * toolsModel.GetZoom() / 1000, FALSE);
|
||||
imageArea.MoveWindow(3, 3, Zoomed(imageModel.GetWidth()), Zoomed(imageModel.GetHeight()), FALSE);
|
||||
scrollboxWindow.Invalidate(TRUE);
|
||||
imageArea.Invalidate(FALSE);
|
||||
|
||||
|
|
Loading…
Reference in a new issue