https://git.reactos.org/?p=reactos.git;a=commitdiff;h=57891b5f34d5832fccce9…
commit 57891b5f34d5832fccce99155f568c983161b002
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Tue Mar 21 13:13:53 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Tue Mar 21 13:13:53 2023 +0900
[MSPAINT] Tool settings: Reduce magic numbers (#5168)
Many coordinates are dynamically calculated. It is adjustable against client area
change.
- Fix some brush/eraser shapes for pixel perfection.
- Reduce magic numbers in toolssettings.cpp.
- Refactoring.
CORE-18867
---
base/applications/mspaint/drawing.cpp | 30 +-
base/applications/mspaint/main.cpp | 9 +-
base/applications/mspaint/toolbox.cpp | 9 +
base/applications/mspaint/toolbox.h | 7 +-
base/applications/mspaint/toolsettings.cpp | 461 +++++++++++++++++++----------
base/applications/mspaint/toolsettings.h | 11 +
base/applications/mspaint/winproc.cpp | 2 +-
7 files changed, 356 insertions(+), 173 deletions(-)
diff --git a/base/applications/mspaint/drawing.cpp
b/base/applications/mspaint/drawing.cpp
index 296a6f57a1e..f94da436eca 100644
--- a/base/applications/mspaint/drawing.cpp
+++ b/base/applications/mspaint/drawing.cpp
@@ -123,9 +123,11 @@ Erase(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color,
LONG radius)
b = max(1, max(abs(x2 - x1), abs(y2 - y1)));
oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_SOLID, 1, color));
for(a = 0; a <= b; a++)
- Rectangle(hdc, (x1 * (b - a) + x2 * a) / b - radius + 1,
- (y1 * (b - a) + y2 * a) / b - radius + 1, (x1 * (b - a) + x2 * a) / b +
radius + 1,
- (y1 * (b - a) + y2 * a) / b + radius + 1);
+ Rectangle(hdc,
+ (x1 * (b - a) + x2 * a) / b - radius,
+ (y1 * (b - a) + y2 * a) / b - radius,
+ (x1 * (b - a) + x2 * a) / b + radius,
+ (y1 * (b - a) + y2 * a) / b + radius);
DeleteObject(SelectObject(hdc, oldBrush));
DeleteObject(SelectObject(hdc, oldPen));
}
@@ -172,8 +174,11 @@ Brush(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color,
LONG style)
break;
case 1:
for(a = 0; a <= b; a++)
- Ellipse(hdc, (x1 * (b - a) + x2 * a) / b - 1, (y1 * (b - a) + y2 * a) / b
- 1,
- (x1 * (b - a) + x2 * a) / b + 3, (y1 * (b - a) + y2 * a) / b +
3);
+ Ellipse(hdc,
+ (x1 * (b - a) + x2 * a) / b - 2,
+ (y1 * (b - a) + y2 * a) / b - 2,
+ (x1 * (b - a) + x2 * a) / b + 2,
+ (y1 * (b - a) + y2 * a) / b + 2);
break;
case 2:
MoveToEx(hdc, x1, y1, NULL);
@@ -182,8 +187,11 @@ Brush(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color,
LONG style)
break;
case 3:
for(a = 0; a <= b; a++)
- Rectangle(hdc, (x1 * (b - a) + x2 * a) / b - 3, (y1 * (b - a) + y2 * a) /
b - 3,
- (x1 * (b - a) + x2 * a) / b + 5, (y1 * (b - a) + y2 * a) / b +
5);
+ Rectangle(hdc,
+ (x1 * (b - a) + x2 * a) / b - 4,
+ (y1 * (b - a) + y2 * a) / b - 4,
+ (x1 * (b - a) + x2 * a) / b + 4,
+ (y1 * (b - a) + y2 * a) / b + 4);
break;
case 4:
for(a = 0; a <= b; a++)
@@ -202,10 +210,10 @@ Brush(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color,
LONG style)
case 10:
case 11:
{
- POINT offsTop[] = {{4, -3}, {2, -2}, {0, 0},
- {-3, -3}, {-2, -2}, {-1, 0}};
- POINT offsBtm[] = {{-3, 4}, {-2, 2}, {-1, 1},
- {4, 4}, {2, 2}, {0, 1}};
+ POINT offsTop[] = {{3, -3}, {2, -2}, {0, 0},
+ {-4, -4}, {-2, -2}, {-1, 0}};
+ POINT offsBtm[] = {{-3, 3}, {-2, 2}, {-1, 1},
+ {3, 3}, {2, 2}, {0, 1}};
LONG idx = style - 6;
POINT pts[4];
pts[0].x = x1 + offsTop[idx].x;
diff --git a/base/applications/mspaint/main.cpp b/base/applications/mspaint/main.cpp
index f24a12b1a1f..1099f6af3f8 100644
--- a/base/applications/mspaint/main.cpp
+++ b/base/applications/mspaint/main.cpp
@@ -180,13 +180,8 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR
lpszArgument
SetMenu(hwnd, menu);
haccel = LoadAccelerators(hThisInstance, MAKEINTRESOURCE(800));
- RECT toolBoxContainerPos = {2, 2, 2 + 52, 2 + 350};
- toolBoxContainer.Create(hwnd, toolBoxContainerPos, NULL, WS_CHILD);
- if (registrySettings.ShowToolBox)
- toolBoxContainer.ShowWindow(SW_SHOWNOACTIVATE);
- /* creating the tool settings child window */
- RECT toolSettingsWindowPos = {5, 208, 5 + 42, 208 + 140};
- toolSettingsWindow.Create(toolBoxContainer.m_hWnd, toolSettingsWindowPos, NULL,
WS_CHILD | WS_VISIBLE);
+ /* Create ToolBox */
+ toolBoxContainer.DoCreate(hwnd);
/* creating the palette child window */
RECT paletteWindowPos = {56, 9, 56 + 255, 9 + 32};
diff --git a/base/applications/mspaint/toolbox.cpp
b/base/applications/mspaint/toolbox.cpp
index 4af48b5917a..793c62bbfda 100644
--- a/base/applications/mspaint/toolbox.cpp
+++ b/base/applications/mspaint/toolbox.cpp
@@ -13,6 +13,13 @@
/* FUNCTIONS ********************************************************/
+BOOL CToolBox::DoCreate(HWND hwndParent)
+{
+ RECT toolBoxContainerPos = { 0, 0, 0, 0 };
+ DWORD style = WS_CHILD | (registrySettings.ShowToolBox ? WS_VISIBLE : 0);
+ return !!Create(hwndParent, toolBoxContainerPos, NULL, style);
+}
+
LRESULT CToolBox::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
HIMAGELIST hImageList;
@@ -20,6 +27,8 @@ LRESULT CToolBox::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam,
BOOL& bHandl
int i;
TCHAR tooltips[NUM_TOOLS][30];
+ toolSettingsWindow.DoCreate(m_hWnd);
+
/* NOTE: The horizontal line above the toolbar is hidden by CCS_NODIVIDER style. */
RECT toolbarPos = {0, 0, CX_TOOLBAR, CY_TOOLBAR};
DWORD style = WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_VERT | CCS_NORESIZE |
diff --git a/base/applications/mspaint/toolbox.h b/base/applications/mspaint/toolbox.h
index ac40ab19e5a..b6699c67455 100644
--- a/base/applications/mspaint/toolbox.h
+++ b/base/applications/mspaint/toolbox.h
@@ -12,8 +12,8 @@
#define TOOLBAR_ROWS 8
#define TOOLBAR_COLUMNS 2
#define CXY_TB_BUTTON 25
-#define CX_TOOLBAR ((TOOLBAR_COLUMNS * CXY_TB_BUTTON) + 2)
-#define CY_TOOLBAR ((TOOLBAR_ROWS * CXY_TB_BUTTON) + 2)
+#define CX_TOOLBAR (TOOLBAR_COLUMNS * CXY_TB_BUTTON)
+#define CY_TOOLBAR (TOOLBAR_ROWS * CXY_TB_BUTTON)
class CToolBox : public CWindowImpl<CToolBox>
{
@@ -27,6 +27,9 @@ public:
MESSAGE_HANDLER(WM_TOOLSMODELTOOLCHANGED, OnToolsModelToolChanged)
END_MSG_MAP()
+ BOOL DoCreate(HWND hwndParent);
+
+private:
CWindow toolbar;
LRESULT OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
diff --git a/base/applications/mspaint/toolsettings.cpp
b/base/applications/mspaint/toolsettings.cpp
index dc1883bf47e..c8b3978e8b6 100644
--- a/base/applications/mspaint/toolsettings.cpp
+++ b/base/applications/mspaint/toolsettings.cpp
@@ -5,21 +5,264 @@
* PURPOSE: Window procedure of the tool settings window
* PROGRAMMERS: Benedikt Freisen
* Stanislav Motylkov
+ * Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
*/
/* INCLUDES *********************************************************/
#include "precomp.h"
+#define X_TOOLSETTINGS 0
+#define Y_TOOLSETTINGS (CY_TOOLBAR + 3)
+#define CX_TOOLSETTINGS CX_TOOLBAR
+#define CY_TOOLSETTINGS 140
+
+#define CX_TRANS_ICON 40
+#define CY_TRANS_ICON 30
+#define MARGIN1 3
+#define MARGIN2 2
+
+static const BYTE s_AirRadius[4] = { 5, 8, 3, 12 };
+
/* FUNCTIONS ********************************************************/
+BOOL CToolSettingsWindow::DoCreate(HWND hwndParent)
+{
+ /* creating the tool settings child window */
+ RECT toolSettingsWindowPos =
+ {
+ X_TOOLSETTINGS, Y_TOOLSETTINGS,
+ X_TOOLSETTINGS + CX_TOOLSETTINGS, Y_TOOLSETTINGS + CY_TOOLSETTINGS
+ };
+ return !!Create(toolBoxContainer, toolSettingsWindowPos, NULL, WS_CHILD |
WS_VISIBLE);
+}
+
+static INT
+getSplitRects(RECT *rects, INT cColumns, INT cRows, LPCRECT prc, LPPOINT ppt)
+{
+ INT cx = prc->right - prc->left, cy = prc->bottom - prc->top;
+ for (INT i = 0, iRow = 0; iRow < cRows; ++iRow)
+ {
+ for (INT iColumn = 0; iColumn < cColumns; ++iColumn)
+ {
+ RECT& rc = rects[i];
+ rc.left = prc->left + (iColumn * cx / cColumns);
+ rc.top = prc->top + (iRow * cy / cRows);
+ rc.right = prc->left + ((iColumn + 1) * cx / cColumns);
+ rc.bottom = prc->top + ((iRow + 1) * cy / cRows);
+ if (ppt && ::PtInRect(&rc, *ppt))
+ return i;
+ ++i;
+ }
+ }
+ return -1;
+}
+
+static inline INT getTransRects(RECT rects[2], LPCRECT prc, LPPOINT ppt = NULL)
+{
+ return getSplitRects(rects, 1, 2, prc, ppt);
+}
+
+VOID CToolSettingsWindow::drawTrans(HDC hdc, LPCRECT prc)
+{
+ RECT rc[2];
+ getTransRects(rc, prc);
+
+ HBRUSH hbrHigh = ::GetSysColorBrush(COLOR_HIGHLIGHT);
+ ::FillRect(hdc, &rc[toolsModel.IsBackgroundTransparent()], hbrHigh);
+ ::DrawIconEx(hdc, rc[0].left, rc[0].top, m_hNontranspIcon,
+ CX_TRANS_ICON, CY_TRANS_ICON, 0, NULL, DI_NORMAL);
+ ::DrawIconEx(hdc, rc[1].left, rc[1].top, m_hTranspIcon,
+ CX_TRANS_ICON, CY_TRANS_ICON, 0, NULL, DI_NORMAL);
+}
+
+static inline INT getRubberRects(RECT rects[4], LPCRECT prc, LPPOINT ppt = NULL)
+{
+ return getSplitRects(rects, 1, 4, prc, ppt);
+}
+
+VOID CToolSettingsWindow::drawRubber(HDC hdc, LPCRECT prc)
+{
+ RECT rects[4], rcRubber;
+ getRubberRects(rects, prc);
+ INT xCenter = (prc->left + prc->right) / 2;
+ for (INT i = 0; i < 4; i++)
+ {
+ INT iColor, radius = i + 2;
+ if (toolsModel.GetRubberRadius() == radius)
+ {
+ ::FillRect(hdc, &rects[i], ::GetSysColorBrush(COLOR_HIGHLIGHT));
+ iColor = COLOR_HIGHLIGHTTEXT;
+ }
+ else
+ {
+ iColor = COLOR_WINDOWTEXT;
+ }
+
+ INT yCenter = (rects[i].top + rects[i].bottom) / 2;
+ rcRubber.left = xCenter - radius;
+ rcRubber.top = yCenter - radius;
+ rcRubber.right = rcRubber.left + radius * 2;
+ rcRubber.bottom = rcRubber.top + radius * 2;
+ ::FillRect(hdc, &rcRubber, GetSysColorBrush(iColor));
+ }
+}
+
+static inline INT getBrushRects(RECT rects[12], LPCRECT prc, LPPOINT ppt = NULL)
+{
+ return getSplitRects(rects, 3, 4, prc, ppt);
+}
+
+VOID CToolSettingsWindow::drawBrush(HDC hdc, LPCRECT prc)
+{
+ RECT rects[12];
+ getBrushRects(rects, prc);
+
+ HBRUSH hbrHigh = ::GetSysColorBrush(COLOR_HIGHLIGHT);
+ ::FillRect(hdc, &rects[toolsModel.GetBrushStyle()], hbrHigh);
+
+ for (INT i = 0; i < 12; i++)
+ {
+ RECT rcItem = rects[i];
+ INT x = (rcItem.left + rcItem.right) / 2, y = (rcItem.top + rcItem.bottom) / 2;
+ INT iColor;
+ if (i == toolsModel.GetBrushStyle())
+ iColor = COLOR_HIGHLIGHTTEXT;
+ else
+ iColor = COLOR_WINDOWTEXT;
+ Brush(hdc, x, y, x, y, ::GetSysColor(iColor), i);
+ }
+}
+
+static inline INT getLineRects(RECT rects[5], LPCRECT prc, LPPOINT ppt = NULL)
+{
+ return getSplitRects(rects, 1, 5, prc, ppt);
+}
+
+VOID CToolSettingsWindow::drawLine(HDC hdc, LPCRECT prc)
+{
+ RECT rects[5];
+ getLineRects(rects, prc);
+
+ for (INT i = 0; i < 5; i++)
+ {
+ INT penWidth = i + 1;
+ RECT rcLine = rects[i];
+ ::InflateRect(&rcLine, -2, 0);
+ rcLine.top = (rcLine.top + rcLine.bottom - penWidth) / 2;
+ rcLine.bottom = rcLine.top + penWidth;
+ if (toolsModel.GetLineWidth() == penWidth)
+ {
+ ::FillRect(hdc, &rects[i], ::GetSysColorBrush(COLOR_HIGHLIGHT));
+ ::FillRect(hdc, &rcLine, ::GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
+ }
+ else
+ {
+ ::FillRect(hdc, &rcLine, ::GetSysColorBrush(COLOR_WINDOWTEXT));
+ }
+ }
+}
+
+static INT getAirBrushRects(RECT rects[4], LPCRECT prc, LPPOINT ppt = NULL)
+{
+ INT cx = (prc->right - prc->left), cy = (prc->bottom - prc->top);
+
+ rects[0] = rects[1] = rects[2] = rects[3] = *prc;
+
+ rects[0].right = rects[1].left = prc->left + cx * 3 / 8;
+ rects[0].bottom = rects[1].bottom = prc->top + cy / 2;
+
+ rects[2].top = rects[3].top = prc->top + cy / 2;
+ rects[2].right = rects[3].left = prc->left + cx * 2 / 8;
+
+ if (ppt)
+ {
+ for (INT i = 0; i < 4; ++i)
+ {
+ if (::PtInRect(&rects[i], *ppt))
+ return i;
+ }
+ }
+ return -1;
+}
+
+VOID CToolSettingsWindow::drawAirBrush(HDC hdc, LPCRECT prc)
+{
+ RECT rects[4];
+ getAirBrushRects(rects, prc);
+
+ srand(0);
+ for (size_t i = 0; i < 4; ++i)
+ {
+ RECT& rc = rects[i];
+ INT x = (rc.left + rc.right) / 2;
+ INT y = (rc.top + rc.bottom) / 2;
+ BOOL bHigh = (s_AirRadius[i] == toolsModel.GetAirBrushWidth());
+ if (bHigh)
+ {
+ ::FillRect(hdc, &rc, ::GetSysColorBrush(COLOR_HIGHLIGHT));
+ Airbrush(hdc, x, y, ::GetSysColor(COLOR_HIGHLIGHTTEXT), s_AirRadius[i]);
+ }
+ else
+ {
+ Airbrush(hdc, x, y, ::GetSysColor(COLOR_WINDOWTEXT), s_AirRadius[i]);
+ }
+ }
+}
+
+static inline INT getBoxRects(RECT rects[3], LPCRECT prc, LPPOINT ppt = NULL)
+{
+ return getSplitRects(rects, 1, 3, prc, ppt);
+}
+
+VOID CToolSettingsWindow::drawBox(HDC hdc, LPCRECT prc)
+{
+ RECT rects[3];
+ getBoxRects(rects, prc);
+
+ for (INT iItem = 0; iItem < 3; ++iItem)
+ {
+ RECT& rcItem = rects[iItem];
+
+ if (toolsModel.GetShapeStyle() == iItem)
+ ::FillRect(hdc, &rcItem, ::GetSysColorBrush(COLOR_HIGHLIGHT));
+
+ ::InflateRect(&rcItem, -5, -5);
+
+ if (iItem <= 1)
+ {
+ COLORREF rgbPen;
+ if (toolsModel.GetShapeStyle() == iItem)
+ rgbPen = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
+ else
+ rgbPen = ::GetSysColor(COLOR_WINDOWTEXT);
+ HGDIOBJ hOldBrush;
+ if (iItem == 0)
+ hOldBrush = ::SelectObject(hdc, ::GetStockObject(NULL_BRUSH));
+ else
+ hOldBrush = ::SelectObject(hdc, ::GetSysColorBrush(COLOR_APPWORKSPACE));
+ HGDIOBJ hOldPen = ::SelectObject(hdc, ::CreatePen(PS_SOLID, 1, rgbPen));
+ ::Rectangle(hdc, rcItem.left, rcItem.top, rcItem.right, rcItem.bottom);
+ ::DeleteObject(::SelectObject(hdc, hOldPen));
+ ::SelectObject(hdc, hOldBrush);
+ }
+ else
+ {
+ if (toolsModel.GetShapeStyle() == iItem)
+ ::FillRect(hdc, &rcItem, ::GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
+ else
+ ::FillRect(hdc, &rcItem, ::GetSysColorBrush(COLOR_WINDOWTEXT));
+ }
+ }
+}
+
LRESULT CToolSettingsWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam,
WINBOOL& bHandled)
{
/* preloading the draw transparent/nontransparent icons for later use */
m_hNontranspIcon = (HICON)LoadImage(hProgInstance,
MAKEINTRESOURCE(IDI_NONTRANSPARENT),
- IMAGE_ICON, 40, 30, LR_DEFAULTCOLOR);
+ IMAGE_ICON, CX_TRANS_ICON, CY_TRANS_ICON,
LR_DEFAULTCOLOR);
m_hTranspIcon = (HICON)LoadImage(hProgInstance, MAKEINTRESOURCE(IDI_TRANSPARENT),
- IMAGE_ICON, 40, 30, LR_DEFAULTCOLOR);
+ IMAGE_ICON, CX_TRANS_ICON, CY_TRANS_ICON,
LR_DEFAULTCOLOR);
RECT trackbarZoomPos = {1, 1, 1 + 40, 1 + 64};
trackbarZoom.Create(TRACKBAR_CLASS, m_hWnd, trackbarZoomPos, NULL, WS_CHILD |
TBS_VERT | TBS_AUTOTICKS);
@@ -44,149 +287,65 @@ LRESULT CToolSettingsWindow::OnVScroll(UINT nMsg, WPARAM wParam,
LPARAM lParam,
return 0;
}
+VOID CToolSettingsWindow::calculateTwoBoxes(RECT& rect1, RECT& rect2)
+{
+ RECT rcClient;
+ GetClientRect(&rcClient);
+ ::InflateRect(&rcClient, -MARGIN1, -MARGIN1);
+
+ INT yCenter = (rcClient.top + rcClient.bottom) / 2;
+ ::SetRect(&rect1, rcClient.left, rcClient.top, rcClient.right, yCenter);
+ ::SetRect(&rect2, rcClient.left, yCenter, rcClient.right, rcClient.bottom);
+
+ ::InflateRect(&rect1, -MARGIN2, -MARGIN2);
+ ::InflateRect(&rect2, -MARGIN2, -MARGIN2);
+}
+
LRESULT CToolSettingsWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
- PAINTSTRUCT ps;
- RECT rect1 = { 0, 0, 42, 66 };
- RECT rect2 = { 0, 70, 42, 136 };
+ RECT rect1, rect2;
+ calculateTwoBoxes(rect1, rect2);
+ PAINTSTRUCT ps;
HDC hdc = BeginPaint(&ps);
- DrawEdge(hdc, &rect1, BDR_SUNKENOUTER, (toolsModel.GetActiveTool() == TOOL_ZOOM)
? BF_RECT : BF_RECT | BF_MIDDLE);
- DrawEdge(hdc, &rect2, (toolsModel.GetActiveTool() >= TOOL_RECT) ?
BDR_SUNKENOUTER : 0, BF_RECT | BF_MIDDLE);
+
+ if (toolsModel.GetActiveTool() == TOOL_ZOOM)
+ ::DrawEdge(hdc, &rect1, BDR_SUNKENOUTER, BF_RECT);
+ else
+ ::DrawEdge(hdc, &rect1, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
+
+ if (toolsModel.GetActiveTool() >= TOOL_RECT)
+ ::DrawEdge(hdc, &rect2, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
+
+ ::InflateRect(&rect1, -MARGIN2, -MARGIN2);
+ ::InflateRect(&rect2, -MARGIN2, -MARGIN2);
switch (toolsModel.GetActiveTool())
{
case TOOL_FREESEL:
case TOOL_RECTSEL:
case TOOL_TEXT:
- {
- HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
- SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
- Rectangle(hdc, 2, toolsModel.IsBackgroundTransparent() * 31 + 2, 41,
toolsModel.IsBackgroundTransparent() * 31 + 33);
- DeleteObject(SelectObject(hdc, oldPen));
- DrawIconEx(hdc, 1, 2, m_hNontranspIcon, 40, 30, 0, NULL, DI_NORMAL);
- DrawIconEx(hdc, 1, 33, m_hTranspIcon, 40, 30, 0, NULL, DI_NORMAL);
+ drawTrans(hdc, &rect1);
break;
- }
case TOOL_RUBBER:
- {
- int i;
- HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
- for(i = 0; i < 4; i++)
- {
- if (toolsModel.GetRubberRadius() == i + 2)
- {
- SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
- Rectangle(hdc, 14, i * 15 + 2, 29, i * 15 + 17);
- SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
- }
- else
- SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
- Rectangle(hdc, 19 - i, i * 14 + 7, 24 + i, i * 16 + 12);
- }
- DeleteObject(SelectObject(hdc, oldPen));
+ drawRubber(hdc, &rect1);
break;
- }
case TOOL_BRUSH:
- {
- int i;
- HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
- SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
- Rectangle(hdc, toolsModel.GetBrushStyle() % 3 * 13 + 2,
toolsModel.GetBrushStyle() / 3 * 15 + 2, toolsModel.GetBrushStyle() % 3 * 13 + 15,
- toolsModel.GetBrushStyle() / 3 * 15 + 17);
- DeleteObject(SelectObject(hdc, oldPen));
- for(i = 0; i < 12; i++)
- Brush(hdc, i % 3 * 13 + 7, i / 3 * 15 + 8, i % 3 * 13 + 7, i / 3 * 15 +
8,
- GetSysColor((i == toolsModel.GetBrushStyle()) ? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT), i);
+ drawBrush(hdc, &rect1);
break;
- }
case TOOL_AIRBRUSH:
- {
- HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
- SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
- switch (toolsModel.GetAirBrushWidth())
- {
- case 5:
- Rectangle(hdc, 2, 2, 21, 31);
- break;
- case 8:
- Rectangle(hdc, 20, 2, 41, 31);
- break;
- case 3:
- Rectangle(hdc, 2, 30, 16, 61);
- break;
- case 12:
- Rectangle(hdc, 15, 30, 41, 61);
- break;
- }
- Airbrush(hdc, 10, 15,
- GetSysColor((toolsModel.GetAirBrushWidth() == 5) ?
COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 5);
- Airbrush(hdc, 30, 15,
- GetSysColor((toolsModel.GetAirBrushWidth() == 8) ?
COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 8);
- Airbrush(hdc, 8, 45,
- GetSysColor((toolsModel.GetAirBrushWidth() == 3) ?
COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 3);
- Airbrush(hdc, 27, 45,
- GetSysColor((toolsModel.GetAirBrushWidth() == 12) ?
COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 12);
- DeleteObject(SelectObject(hdc, oldPen));
+ drawAirBrush(hdc, &rect1);
break;
- }
case TOOL_LINE:
case TOOL_BEZIER:
- {
- int i;
- HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
- for(i = 0; i < 5; i++)
- {
- if (toolsModel.GetLineWidth() == i + 1)
- {
- SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
- Rectangle(hdc, 2, i * 12 + 2, 41, i * 12 + 14);
- SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
- }
- else
- SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
- Rectangle(hdc, 5, i * 12 + 6, 38, i * 12 + 8 + i);
- }
- DeleteObject(SelectObject(hdc, oldPen));
+ drawLine(hdc, &rect1);
break;
- }
case TOOL_RECT:
case TOOL_SHAPE:
case TOOL_ELLIPSE:
case TOOL_RRECT:
- {
- int i;
- HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
- for(i = 0; i < 3; i++)
- {
- if (toolsModel.GetShapeStyle() == i)
- {
- SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
- Rectangle(hdc, 2, i * 20 + 2, 41, i * 20 + 22);
- }
- }
- Rect(hdc, 5, 6, 37, 16,
- GetSysColor((toolsModel.GetShapeStyle() == 0) ? COLOR_HIGHLIGHTTEXT :
COLOR_WINDOWTEXT),
- GetSysColor(COLOR_APPWORKSPACE), 1, 0);
- Rect(hdc, 5, 26, 37, 36,
- GetSysColor((toolsModel.GetShapeStyle() == 1) ? COLOR_HIGHLIGHTTEXT :
COLOR_WINDOWTEXT),
- GetSysColor(COLOR_APPWORKSPACE), 1, 1);
- Rect(hdc, 5, 46, 37, 56, GetSysColor(COLOR_APPWORKSPACE),
GetSysColor(COLOR_APPWORKSPACE),
- 1, 1);
- for(i = 0; i < 5; i++)
- {
- if (toolsModel.GetLineWidth() == i + 1)
- {
- SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
- Rectangle(hdc, 2, i * 12 + 72, 41, i * 12 + 84);
- SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
- }
- else
- SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
- Rectangle(hdc, 5, i * 12 + 76, 38, i * 12 + 78 + i);
- }
- DeleteObject(SelectObject(hdc, oldPen));
+ drawBox(hdc, &rect1);
+ drawLine(hdc, &rect2);
break;
- }
case TOOL_FILL:
case TOOL_COLOR:
case TOOL_ZOOM:
@@ -199,56 +358,54 @@ LRESULT CToolSettingsWindow::OnPaint(UINT nMsg, WPARAM wParam,
LPARAM lParam, BO
LRESULT CToolSettingsWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam,
BOOL& bHandled)
{
- int x = GET_X_LPARAM(lParam);
- int y = GET_Y_LPARAM(lParam);
+ POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
+
+ RECT rect1, rect2;
+ calculateTwoBoxes(rect1, rect2);
+ RECT rects[12];
+
+ INT iItem;
switch (toolsModel.GetActiveTool())
{
case TOOL_FREESEL:
case TOOL_RECTSEL:
case TOOL_TEXT:
- if ((y > 1) && (y < 64))
- toolsModel.SetBackgroundTransparent((y - 2) / 31);
+ iItem = getTransRects(rects, &rect1, &pt);
+ if (iItem != -1)
+ toolsModel.SetBackgroundTransparent(iItem);
break;
case TOOL_RUBBER:
- if ((y > 1) && (y < 62))
- toolsModel.SetRubberRadius((y - 2) / 15 + 2);
+ iItem = getRubberRects(rects, &rect1, &pt);
+ if (iItem != -1)
+ toolsModel.SetRubberRadius(iItem + 2);
break;
case TOOL_BRUSH:
- if ((x > 1) && (x < 40) && (y > 1) && (y
< 62))
- toolsModel.SetBrushStyle((y - 2) / 15 * 3 + (x - 2) / 13);
+ iItem = getBrushRects(rects, &rect1, &pt);
+ if (iItem != -1)
+ toolsModel.SetBrushStyle(iItem);
break;
case TOOL_AIRBRUSH:
- if (y < 62)
- {
- if (y < 30)
- {
- if (x < 20)
- toolsModel.SetAirBrushWidth(5);
- else
- toolsModel.SetAirBrushWidth(8);
- }
- else
- {
- if (x < 15)
- toolsModel.SetAirBrushWidth(3);
- else
- toolsModel.SetAirBrushWidth(12);
- }
- }
+ iItem = getAirBrushRects(rects, &rect1, &pt);
+ if (iItem != -1)
+ toolsModel.SetAirBrushWidth(s_AirRadius[iItem]);
break;
case TOOL_LINE:
case TOOL_BEZIER:
- if (y <= 62)
- toolsModel.SetLineWidth((y - 2) / 12 + 1);
+ iItem = getLineRects(rects, &rect1, &pt);
+ if (iItem != -1)
+ toolsModel.SetLineWidth(iItem + 1);
break;
case TOOL_RECT:
case TOOL_SHAPE:
case TOOL_ELLIPSE:
case TOOL_RRECT:
- if (y <= 60)
- toolsModel.SetShapeStyle((y - 2) / 20);
- if ((y >= 70) && (y <= 132))
- toolsModel.SetLineWidth((y - 72) / 12 + 1);
+ iItem = getBoxRects(rects, &rect1, &pt);
+ if (iItem != -1)
+ toolsModel.SetShapeStyle(iItem);
+
+ iItem = getLineRects(rects, &rect2, &pt);
+ if (iItem != -1)
+ toolsModel.SetLineWidth(iItem + 1);
break;
case TOOL_FILL:
case TOOL_COLOR:
diff --git a/base/applications/mspaint/toolsettings.h
b/base/applications/mspaint/toolsettings.h
index bd92d61a6ac..6ad02e22e09 100644
--- a/base/applications/mspaint/toolsettings.h
+++ b/base/applications/mspaint/toolsettings.h
@@ -24,10 +24,21 @@ public:
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
END_MSG_MAP()
+ BOOL DoCreate(HWND hwndParent);
+
+private:
CWindow trackbarZoom;
HICON m_hNontranspIcon;
HICON m_hTranspIcon;
+ VOID drawTrans(HDC hdc, LPCRECT prc);
+ VOID drawRubber(HDC hdc, LPCRECT prc);
+ VOID drawBrush(HDC hdc, LPCRECT prc);
+ VOID drawLine(HDC hdc, LPCRECT prc);
+ VOID drawBox(HDC hdc, LPCRECT prc);
+ VOID drawAirBrush(HDC hdc, LPCRECT prc);
+ VOID calculateTwoBoxes(RECT& rect1, RECT& rect2);
+
LRESULT OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnDestroy(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
diff --git a/base/applications/mspaint/winproc.cpp
b/base/applications/mspaint/winproc.cpp
index ee4e9daa87a..5208e37d610 100644
--- a/base/applications/mspaint/winproc.cpp
+++ b/base/applications/mspaint/winproc.cpp
@@ -426,7 +426,7 @@ LRESULT CMainWindow::OnGetMinMaxInfo(UINT nMsg, WPARAM wParam, LPARAM
lParam, BO
{
MINMAXINFO *mm = (LPMINMAXINFO) lParam;
mm->ptMinTrackSize.x = 330;
- mm->ptMinTrackSize.y = 430;
+ mm->ptMinTrackSize.y = 360;
return 0;
}