[MSPAINT] Define enum TOOLTYPE and use it (#4197)

Improve code quality and debuggability. CORE-17931
This commit is contained in:
Katayama Hirofumi MZ 2021-12-27 23:23:32 +09:00 committed by GitHub
parent 90c3f89bb2
commit e9330371ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 90 additions and 39 deletions

View file

@ -131,24 +131,6 @@
#define ID_ELLIPSE 614
#define ID_RRECT 615
/* the following 16 numbers need to be in order, increasing by 1 */
#define TOOL_FREESEL 1
#define TOOL_RECTSEL 2
#define TOOL_RUBBER 3
#define TOOL_FILL 4
#define TOOL_COLOR 5
#define TOOL_ZOOM 6
#define TOOL_PEN 7
#define TOOL_BRUSH 8
#define TOOL_AIRBRUSH 9
#define TOOL_TEXT 10
#define TOOL_LINE 11
#define TOOL_BEZIER 12
#define TOOL_RECT 13
#define TOOL_SHAPE 14
#define TOOL_ELLIPSE 15
#define TOOL_RRECT 16
#define ID_ACCELERATORS 800
#define IDD_MIRRORROTATE 700

View file

@ -275,6 +275,8 @@ LRESULT CImgAreaWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
case TOOL_SHAPE: case TOOL_BEZIER:
cancelDrawing();
break;
default:
break;
}
}
}
@ -369,6 +371,8 @@ LRESULT CImgAreaWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) (LPCTSTR) strCoord);
break;
}
default:
break;
}
if ((wParam & MK_LBUTTON) != 0)
{

View file

@ -127,6 +127,9 @@ startPaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
pointSP++;
}
break;
case TOOL_COLOR:
case TOOL_ZOOM:
break;
}
}
@ -217,6 +220,10 @@ whilePaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
regularize(start.x, start.y, x, y);
RRect(hdc, start.x, start.y, x, y, fg, bg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle());
break;
case TOOL_FILL:
case TOOL_COLOR:
case TOOL_ZOOM:
break;
}
last.x = x;
@ -330,6 +337,12 @@ endPaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
regularize(start.x, start.y, x, y);
RRect(hdc, start.x, start.y, x, y, fg, bg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle());
break;
case TOOL_FILL:
case TOOL_COLOR:
case TOOL_ZOOM:
case TOOL_BRUSH:
case TOOL_AIRBRUSH:
break;
}
}
@ -390,6 +403,10 @@ startPaintingR(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
pointSP++;
}
break;
case TOOL_RECTSEL:
case TOOL_COLOR:
case TOOL_ZOOM:
break;
}
}
@ -462,6 +479,13 @@ whilePaintingR(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
regularize(start.x, start.y, x, y);
RRect(hdc, start.x, start.y, x, y, bg, fg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle());
break;
case TOOL_FREESEL:
case TOOL_RECTSEL:
case TOOL_FILL:
case TOOL_COLOR:
case TOOL_ZOOM:
case TOOL_TEXT:
break;
}
last.x = x;
@ -532,5 +556,14 @@ endPaintingR(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
regularize(start.x, start.y, x, y);
RRect(hdc, start.x, start.y, x, y, bg, fg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle());
break;
case TOOL_FREESEL:
case TOOL_RECTSEL:
case TOOL_FILL:
case TOOL_COLOR:
case TOOL_ZOOM:
case TOOL_BRUSH:
case TOOL_AIRBRUSH:
case TOOL_TEXT:
break;
}
}

View file

@ -76,52 +76,52 @@ LRESULT CToolBox::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHand
switch (LOWORD(wParam))
{
case ID_FREESEL:
toolsModel.SetActiveTool(1);
toolsModel.SetActiveTool(TOOL_FREESEL);
break;
case ID_RECTSEL:
toolsModel.SetActiveTool(2);
toolsModel.SetActiveTool(TOOL_RECTSEL);
break;
case ID_RUBBER:
toolsModel.SetActiveTool(3);
toolsModel.SetActiveTool(TOOL_RUBBER);
break;
case ID_FILL:
toolsModel.SetActiveTool(4);
toolsModel.SetActiveTool(TOOL_FILL);
break;
case ID_COLOR:
toolsModel.SetActiveTool(5);
toolsModel.SetActiveTool(TOOL_COLOR);
break;
case ID_ZOOM:
toolsModel.SetActiveTool(6);
toolsModel.SetActiveTool(TOOL_ZOOM);
break;
case ID_PEN:
toolsModel.SetActiveTool(7);
toolsModel.SetActiveTool(TOOL_PEN);
break;
case ID_BRUSH:
toolsModel.SetActiveTool(8);
toolsModel.SetActiveTool(TOOL_BRUSH);
break;
case ID_AIRBRUSH:
toolsModel.SetActiveTool(9);
toolsModel.SetActiveTool(TOOL_AIRBRUSH);
break;
case ID_TEXT:
toolsModel.SetActiveTool(10);
toolsModel.SetActiveTool(TOOL_TEXT);
break;
case ID_LINE:
toolsModel.SetActiveTool(11);
toolsModel.SetActiveTool(TOOL_LINE);
break;
case ID_BEZIER:
toolsModel.SetActiveTool(12);
toolsModel.SetActiveTool(TOOL_BEZIER);
break;
case ID_RECT:
toolsModel.SetActiveTool(13);
toolsModel.SetActiveTool(TOOL_RECT);
break;
case ID_SHAPE:
toolsModel.SetActiveTool(14);
toolsModel.SetActiveTool(TOOL_SHAPE);
break;
case ID_ELLIPSE:
toolsModel.SetActiveTool(15);
toolsModel.SetActiveTool(TOOL_ELLIPSE);
break;
case ID_RRECT:
toolsModel.SetActiveTool(16);
toolsModel.SetActiveTool(TOOL_RRECT);
break;
}
return 0;

View file

@ -175,6 +175,11 @@ LRESULT CToolSettingsWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BO
DeleteObject(SelectObject(hdc, oldPen));
break;
}
case TOOL_FILL:
case TOOL_COLOR:
case TOOL_ZOOM:
case TOOL_PEN:
break;
}
ReleaseDC(hdc);
return 0;
@ -233,6 +238,11 @@ LRESULT CToolSettingsWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lPar
if ((y >= 70) && (y <= 132))
toolsModel.SetLineWidth((y - 72) / 12 + 1);
break;
case TOOL_FILL:
case TOOL_COLOR:
case TOOL_ZOOM:
case TOOL_PEN:
break;
}
return 0;
}

View file

@ -57,12 +57,12 @@ void ToolsModel::SetBrushStyle(int nBrushStyle)
NotifyToolSettingsChanged();
}
int ToolsModel::GetActiveTool() const
TOOLTYPE ToolsModel::GetActiveTool() const
{
return m_activeTool;
}
void ToolsModel::SetActiveTool(int nActiveTool)
void ToolsModel::SetActiveTool(TOOLTYPE nActiveTool)
{
m_activeTool = nActiveTool;
NotifyToolChanged();

View file

@ -8,6 +8,26 @@
#pragma once
enum TOOLTYPE
{
TOOL_FREESEL = 1,
TOOL_RECTSEL = 2,
TOOL_RUBBER = 3,
TOOL_FILL = 4,
TOOL_COLOR = 5,
TOOL_ZOOM = 6,
TOOL_PEN = 7,
TOOL_BRUSH = 8,
TOOL_AIRBRUSH = 9,
TOOL_TEXT = 10,
TOOL_LINE = 11,
TOOL_BEZIER = 12,
TOOL_RECT = 13,
TOOL_SHAPE = 14,
TOOL_ELLIPSE = 15,
TOOL_RRECT = 16,
};
/* CLASSES **********************************************************/
class ToolsModel
@ -16,7 +36,7 @@ private:
int m_lineWidth;
int m_shapeStyle;
int m_brushStyle;
int m_activeTool;
TOOLTYPE m_activeTool;
int m_airBrushWidth;
int m_rubberRadius;
BOOL m_transpBg;
@ -34,8 +54,8 @@ public:
void SetShapeStyle(int nShapeStyle);
int GetBrushStyle() const;
void SetBrushStyle(int nBrushStyle);
int GetActiveTool() const;
void SetActiveTool(int nActiveTool);
TOOLTYPE GetActiveTool() const;
void SetActiveTool(TOOLTYPE nActiveTool);
int GetAirBrushWidth() const;
void SetAirBrushWidth(int nAirBrushWidth);
int GetRubberRadius() const;

View file

@ -405,6 +405,8 @@ LRESULT CMainWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
case TOOL_SHAPE: case TOOL_BEZIER:
imageArea.SendMessage(nMsg, wParam, lParam);
break;
default:
break;
}
}
}