mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 20:25:39 +00:00
[MSPAINT] Fix crash on zoom out
- Check the denominator for zero for both zoomed width and height. - Do not allow to move zoom slider above possible position. - Move commonly used `zoomTo` function into new header file. CORE-14539
This commit is contained in:
parent
065e70048d
commit
955048e50a
5 changed files with 31 additions and 9 deletions
14
base/applications/mspaint/common.h
Normal file
14
base/applications/mspaint/common.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/*
|
||||||
|
* PROJECT: PAINT for ReactOS
|
||||||
|
* LICENSE: LGPL
|
||||||
|
* FILE: base/applications/mspaint/common.h
|
||||||
|
* PURPOSE: Commonly used functions
|
||||||
|
* PROGRAMMERS: Benedikt Freisen
|
||||||
|
* Stanislav Motylkov
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/* FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
|
extern BOOL zoomTo(int, int, int);
|
|
@ -16,9 +16,6 @@
|
||||||
|
|
||||||
/* FUNCTIONS ********************************************************/
|
/* FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
extern void
|
|
||||||
zoomTo(int newZoom, int mouseX, int mouseY);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
updateCanvasAndScrollbars()
|
updateCanvasAndScrollbars()
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
#include <htmlhelp.h>
|
#include <htmlhelp.h>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include "definitions.h"
|
#include "definitions.h"
|
||||||
#include "drawing.h"
|
#include "drawing.h"
|
||||||
#include "dib.h"
|
#include "dib.h"
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* FILE: base/applications/mspaint/toolsettings.cpp
|
* FILE: base/applications/mspaint/toolsettings.cpp
|
||||||
* PURPOSE: Window procedure of the tool settings window
|
* PURPOSE: Window procedure of the tool settings window
|
||||||
* PROGRAMMERS: Benedikt Freisen
|
* PROGRAMMERS: Benedikt Freisen
|
||||||
|
* Stanislav Motylkov
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* INCLUDES *********************************************************/
|
/* INCLUDES *********************************************************/
|
||||||
|
@ -12,8 +13,6 @@
|
||||||
|
|
||||||
/* FUNCTIONS ********************************************************/
|
/* FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
extern void zoomTo(int, int, int);
|
|
||||||
|
|
||||||
LRESULT CToolSettingsWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, WINBOOL& bHandled)
|
LRESULT CToolSettingsWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, WINBOOL& bHandled)
|
||||||
{
|
{
|
||||||
RECT trackbarZoomPos = {1, 1, 1 + 40, 1 + 64};
|
RECT trackbarZoomPos = {1, 1, 1 + 40, 1 + 64};
|
||||||
|
@ -25,7 +24,10 @@ LRESULT CToolSettingsWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, W
|
||||||
|
|
||||||
LRESULT CToolSettingsWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
LRESULT CToolSettingsWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||||||
{
|
{
|
||||||
zoomTo(125 << trackbarZoom.SendMessage(TBM_GETPOS, 0, 0), 0, 0);
|
if (!zoomTo(125 << trackbarZoom.SendMessage(TBM_GETPOS, 0, 0), 0, 0))
|
||||||
|
{
|
||||||
|
OnToolsModelZoomChanged(nMsg, wParam, lParam, bHandled);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
* hPalWin, hToolSettings and hSelection
|
* hPalWin, hToolSettings and hSelection
|
||||||
* PROGRAMMERS: Benedikt Freisen
|
* PROGRAMMERS: Benedikt Freisen
|
||||||
* Katayama Hirofumi MZ
|
* Katayama Hirofumi MZ
|
||||||
|
* Stanislav Motylkov
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* INCLUDES *********************************************************/
|
/* INCLUDES *********************************************************/
|
||||||
|
@ -16,7 +17,7 @@
|
||||||
|
|
||||||
/* FUNCTIONS ********************************************************/
|
/* FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
void
|
BOOL
|
||||||
zoomTo(int newZoom, int mouseX, int mouseY)
|
zoomTo(int newZoom, int mouseX, int mouseY)
|
||||||
{
|
{
|
||||||
RECT clientRectScrollbox;
|
RECT clientRectScrollbox;
|
||||||
|
@ -24,8 +25,14 @@ zoomTo(int newZoom, int mouseX, int mouseY)
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
scrollboxWindow.GetClientRect(&clientRectScrollbox);
|
scrollboxWindow.GetClientRect(&clientRectScrollbox);
|
||||||
imageArea.GetClientRect(&clientRectImageArea);
|
imageArea.GetClientRect(&clientRectImageArea);
|
||||||
w = clientRectImageArea.right * clientRectScrollbox.right / (clientRectImageArea.right * newZoom / toolsModel.GetZoom());
|
w = clientRectImageArea.right * newZoom / toolsModel.GetZoom();
|
||||||
h = clientRectImageArea.bottom * clientRectScrollbox.bottom / (clientRectImageArea.bottom * newZoom / toolsModel.GetZoom());
|
h = clientRectImageArea.bottom * newZoom / toolsModel.GetZoom();
|
||||||
|
if (!w || !h)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
w = clientRectImageArea.right * clientRectScrollbox.right / w;
|
||||||
|
h = clientRectImageArea.bottom * clientRectScrollbox.bottom / h;
|
||||||
x = max(0, min(clientRectImageArea.right - w, mouseX - w / 2)) * newZoom / toolsModel.GetZoom();
|
x = max(0, min(clientRectImageArea.right - w, mouseX - w / 2)) * newZoom / toolsModel.GetZoom();
|
||||||
y = max(0, min(clientRectImageArea.bottom - h, mouseY - h / 2)) * newZoom / toolsModel.GetZoom();
|
y = max(0, min(clientRectImageArea.bottom - h, mouseY - h / 2)) * newZoom / toolsModel.GetZoom();
|
||||||
|
|
||||||
|
@ -38,6 +45,7 @@ zoomTo(int newZoom, int mouseX, int mouseY)
|
||||||
|
|
||||||
scrollboxWindow.SendMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, x), 0);
|
scrollboxWindow.SendMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, x), 0);
|
||||||
scrollboxWindow.SendMessage(WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, y), 0);
|
scrollboxWindow.SendMessage(WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, y), 0);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainWindow::alignChildrenToMainWindow()
|
void CMainWindow::alignChildrenToMainWindow()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue