[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_ELLIPSE 614
#define ID_RRECT 615 #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 ID_ACCELERATORS 800
#define IDD_MIRRORROTATE 700 #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: case TOOL_SHAPE: case TOOL_BEZIER:
cancelDrawing(); cancelDrawing();
break; 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); SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) (LPCTSTR) strCoord);
break; break;
} }
default:
break;
} }
if ((wParam & MK_LBUTTON) != 0) if ((wParam & MK_LBUTTON) != 0)
{ {

View file

@ -127,6 +127,9 @@ startPaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
pointSP++; pointSP++;
} }
break; 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); regularize(start.x, start.y, x, y);
RRect(hdc, start.x, start.y, x, y, fg, bg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); RRect(hdc, start.x, start.y, x, y, fg, bg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle());
break; break;
case TOOL_FILL:
case TOOL_COLOR:
case TOOL_ZOOM:
break;
} }
last.x = x; 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); regularize(start.x, start.y, x, y);
RRect(hdc, start.x, start.y, x, y, fg, bg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); RRect(hdc, start.x, start.y, x, y, fg, bg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle());
break; 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++; pointSP++;
} }
break; 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); regularize(start.x, start.y, x, y);
RRect(hdc, start.x, start.y, x, y, bg, fg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); RRect(hdc, start.x, start.y, x, y, bg, fg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle());
break; break;
case TOOL_FREESEL:
case TOOL_RECTSEL:
case TOOL_FILL:
case TOOL_COLOR:
case TOOL_ZOOM:
case TOOL_TEXT:
break;
} }
last.x = x; 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); regularize(start.x, start.y, x, y);
RRect(hdc, start.x, start.y, x, y, bg, fg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); RRect(hdc, start.x, start.y, x, y, bg, fg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle());
break; 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)) switch (LOWORD(wParam))
{ {
case ID_FREESEL: case ID_FREESEL:
toolsModel.SetActiveTool(1); toolsModel.SetActiveTool(TOOL_FREESEL);
break; break;
case ID_RECTSEL: case ID_RECTSEL:
toolsModel.SetActiveTool(2); toolsModel.SetActiveTool(TOOL_RECTSEL);
break; break;
case ID_RUBBER: case ID_RUBBER:
toolsModel.SetActiveTool(3); toolsModel.SetActiveTool(TOOL_RUBBER);
break; break;
case ID_FILL: case ID_FILL:
toolsModel.SetActiveTool(4); toolsModel.SetActiveTool(TOOL_FILL);
break; break;
case ID_COLOR: case ID_COLOR:
toolsModel.SetActiveTool(5); toolsModel.SetActiveTool(TOOL_COLOR);
break; break;
case ID_ZOOM: case ID_ZOOM:
toolsModel.SetActiveTool(6); toolsModel.SetActiveTool(TOOL_ZOOM);
break; break;
case ID_PEN: case ID_PEN:
toolsModel.SetActiveTool(7); toolsModel.SetActiveTool(TOOL_PEN);
break; break;
case ID_BRUSH: case ID_BRUSH:
toolsModel.SetActiveTool(8); toolsModel.SetActiveTool(TOOL_BRUSH);
break; break;
case ID_AIRBRUSH: case ID_AIRBRUSH:
toolsModel.SetActiveTool(9); toolsModel.SetActiveTool(TOOL_AIRBRUSH);
break; break;
case ID_TEXT: case ID_TEXT:
toolsModel.SetActiveTool(10); toolsModel.SetActiveTool(TOOL_TEXT);
break; break;
case ID_LINE: case ID_LINE:
toolsModel.SetActiveTool(11); toolsModel.SetActiveTool(TOOL_LINE);
break; break;
case ID_BEZIER: case ID_BEZIER:
toolsModel.SetActiveTool(12); toolsModel.SetActiveTool(TOOL_BEZIER);
break; break;
case ID_RECT: case ID_RECT:
toolsModel.SetActiveTool(13); toolsModel.SetActiveTool(TOOL_RECT);
break; break;
case ID_SHAPE: case ID_SHAPE:
toolsModel.SetActiveTool(14); toolsModel.SetActiveTool(TOOL_SHAPE);
break; break;
case ID_ELLIPSE: case ID_ELLIPSE:
toolsModel.SetActiveTool(15); toolsModel.SetActiveTool(TOOL_ELLIPSE);
break; break;
case ID_RRECT: case ID_RRECT:
toolsModel.SetActiveTool(16); toolsModel.SetActiveTool(TOOL_RRECT);
break; break;
} }
return 0; return 0;

View file

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

View file

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

View file

@ -8,6 +8,26 @@
#pragma once #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 **********************************************************/ /* CLASSES **********************************************************/
class ToolsModel class ToolsModel
@ -16,7 +36,7 @@ private:
int m_lineWidth; int m_lineWidth;
int m_shapeStyle; int m_shapeStyle;
int m_brushStyle; int m_brushStyle;
int m_activeTool; TOOLTYPE m_activeTool;
int m_airBrushWidth; int m_airBrushWidth;
int m_rubberRadius; int m_rubberRadius;
BOOL m_transpBg; BOOL m_transpBg;
@ -34,8 +54,8 @@ public:
void SetShapeStyle(int nShapeStyle); void SetShapeStyle(int nShapeStyle);
int GetBrushStyle() const; int GetBrushStyle() const;
void SetBrushStyle(int nBrushStyle); void SetBrushStyle(int nBrushStyle);
int GetActiveTool() const; TOOLTYPE GetActiveTool() const;
void SetActiveTool(int nActiveTool); void SetActiveTool(TOOLTYPE nActiveTool);
int GetAirBrushWidth() const; int GetAirBrushWidth() const;
void SetAirBrushWidth(int nAirBrushWidth); void SetAirBrushWidth(int nAirBrushWidth);
int GetRubberRadius() const; 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: case TOOL_SHAPE: case TOOL_BEZIER:
imageArea.SendMessage(nMsg, wParam, lParam); imageArea.SendMessage(nMsg, wParam, lParam);
break; break;
default:
break;
} }
} }
} }