https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d30e5eb51c25777527cf0…
commit d30e5eb51c25777527cf0b63ee213410603a7483
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Tue Dec 28 19:01:31 2021 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Tue Dec 28 19:01:31 2021 +0900
[MSPAINT] Add NUM_COLORS and enum PAL_TYPE (#4203)
Reduce magic numbers and improve debuggability. CORE-17931
---
base/applications/mspaint/palettemodel.cpp | 44 +++++++++++++++++-------------
base/applications/mspaint/palettemodel.h | 32 ++++++++++++++--------
base/applications/mspaint/winproc.cpp | 8 +++---
3 files changed, 49 insertions(+), 35 deletions(-)
diff --git a/base/applications/mspaint/palettemodel.cpp
b/base/applications/mspaint/palettemodel.cpp
index 021a9e0af7f..ffbde5706fd 100644
--- a/base/applications/mspaint/palettemodel.cpp
+++ b/base/applications/mspaint/palettemodel.cpp
@@ -4,6 +4,7 @@
* FILE: base/applications/mspaint/palettemodel.cpp
* PURPOSE: Keep track of palette data, notify listeners
* PROGRAMMERS: Benedikt Freisen
+ * Katayama Hirofumi MZ
*/
/* INCLUDES *********************************************************/
@@ -16,72 +17,77 @@ PaletteModel::PaletteModel()
{
m_fgColor = 0x00000000;
m_bgColor = 0x00ffffff;
- SelectPalette(1);
+ SelectPalette(PAL_MODERN);
}
-int PaletteModel::SelectedPalette()
+PAL_TYPE PaletteModel::SelectedPalette()
{
return m_nSelectedPalette;
}
-void PaletteModel::SelectPalette(int nPalette)
+void PaletteModel::SelectPalette(PAL_TYPE nPalette)
{
- int modernColors[28] = {
+ static const COLORREF modernColors[NUM_COLORS] =
+ {
0x000000, 0x464646, 0x787878, 0x300099, 0x241ced, 0x0078ff, 0x0ec2ff,
0x00f2ff, 0x1de6a8, 0x4cb122, 0xefb700, 0xf36d4d, 0x99362f, 0x98316f,
0xffffff, 0xdcdcdc, 0xb4b4b4, 0x3c5a9c, 0xb1a3ff, 0x7aaae5, 0x9ce4f5,
0xbdf9ff, 0xbcf9d3, 0x61bb9d, 0xead999, 0xd19a70, 0x8e6d54, 0xd5a5b5
};
- int oldColors[28] = {
+ static const COLORREF oldColors[NUM_COLORS] =
+ {
0x000000, 0x808080, 0x000080, 0x008080, 0x008000, 0x808000, 0x800000,
0x800080, 0x408080, 0x404000, 0xff8000, 0x804000, 0xff0040, 0x004080,
0xffffff, 0xc0c0c0, 0x0000ff, 0x00ffff, 0x00ff00, 0xffff00, 0xff0000,
0xff00ff, 0x80ffff, 0x80ff00, 0xffff80, 0xff8080, 0x8000ff, 0x4080ff
};
- if (nPalette == 1)
- CopyMemory(m_colors, modernColors, sizeof(m_colors));
- else if (nPalette == 2)
- CopyMemory(m_colors, oldColors, sizeof(m_colors));
- else
- return;
+ switch (nPalette)
+ {
+ case PAL_MODERN:
+ CopyMemory(m_colors, modernColors, sizeof(m_colors));
+ break;
+ case PAL_OLDTYPE:
+ CopyMemory(m_colors, oldColors, sizeof(m_colors));
+ break;
+ }
m_nSelectedPalette = nPalette;
NotifyPaletteChanged();
}
-int PaletteModel::GetColor(int nIndex) const
+COLORREF PaletteModel::GetColor(UINT nIndex) const
{
- if (nIndex < 28)
+ if (nIndex < NUM_COLORS)
return m_colors[nIndex];
else
return 0;
}
-void PaletteModel::SetColor(int nIndex, int newColor)
+void PaletteModel::SetColor(UINT nIndex, COLORREF newColor)
{
- if (nIndex < 28)
+ if (nIndex < NUM_COLORS)
{
m_colors[nIndex] = newColor;
NotifyPaletteChanged();
}
}
-int PaletteModel::GetFgColor() const
+COLORREF PaletteModel::GetFgColor() const
{
return m_fgColor;
}
-void PaletteModel::SetFgColor(int newColor)
+void PaletteModel::SetFgColor(COLORREF newColor)
{
m_fgColor = newColor;
NotifyColorChanged();
}
-int PaletteModel::GetBgColor() const
+COLORREF PaletteModel::GetBgColor() const
{
return m_bgColor;
}
-void PaletteModel::SetBgColor(int newColor)
+void PaletteModel::SetBgColor(COLORREF newColor)
{
m_bgColor = newColor;
NotifyColorChanged();
diff --git a/base/applications/mspaint/palettemodel.h
b/base/applications/mspaint/palettemodel.h
index 2dccc2aa405..b2a8c40631d 100644
--- a/base/applications/mspaint/palettemodel.h
+++ b/base/applications/mspaint/palettemodel.h
@@ -8,27 +8,35 @@
#pragma once
+#define NUM_COLORS 28
+
+enum PAL_TYPE
+{
+ PAL_MODERN = 1,
+ PAL_OLDTYPE = 2,
+};
+
/* CLASSES **********************************************************/
class PaletteModel
{
private:
- int m_colors[28];
- int m_nSelectedPalette;
- int m_fgColor;
- int m_bgColor;
+ COLORREF m_colors[NUM_COLORS];
+ PAL_TYPE m_nSelectedPalette;
+ COLORREF m_fgColor;
+ COLORREF m_bgColor;
void NotifyColorChanged();
void NotifyPaletteChanged();
public:
PaletteModel();
- int SelectedPalette();
- void SelectPalette(int nPalette);
- int GetColor(int nIndex) const;
- void SetColor(int nIndex, int newColor);
- int GetFgColor() const;
- void SetFgColor(int newColor);
- int GetBgColor() const;
- void SetBgColor(int newColor);
+ PAL_TYPE SelectedPalette();
+ void SelectPalette(PAL_TYPE nPalette);
+ COLORREF GetColor(UINT nIndex) const;
+ void SetColor(UINT nIndex, COLORREF newColor);
+ COLORREF GetFgColor() const;
+ void SetFgColor(COLORREF newColor);
+ COLORREF GetBgColor() const;
+ void SetBgColor(COLORREF newColor);
};
diff --git a/base/applications/mspaint/winproc.cpp
b/base/applications/mspaint/winproc.cpp
index 026d5536def..4ccc7be0cdb 100644
--- a/base/applications/mspaint/winproc.cpp
+++ b/base/applications/mspaint/winproc.cpp
@@ -346,8 +346,8 @@ LRESULT CMainWindow::OnInitMenuPopup(UINT nMsg, WPARAM wParam, LPARAM
lParam, BO
CheckMenuItem(menu, IDM_VIEWZOOM400, CHECKED_IF(toolsModel.GetZoom() == 4000));
CheckMenuItem(menu, IDM_VIEWZOOM800, CHECKED_IF(toolsModel.GetZoom() == 8000));
- CheckMenuItem(menu, IDM_COLORSMODERNPALETTE,
CHECKED_IF(paletteModel.SelectedPalette() == 1));
- CheckMenuItem(menu, IDM_COLORSOLDPALETTE,
CHECKED_IF(paletteModel.SelectedPalette() == 2));
+ CheckMenuItem(menu, IDM_COLORSMODERNPALETTE,
CHECKED_IF(paletteModel.SelectedPalette() == PAL_MODERN));
+ CheckMenuItem(menu, IDM_COLORSOLDPALETTE,
CHECKED_IF(paletteModel.SelectedPalette() == PAL_OLDTYPE));
return 0;
}
@@ -586,10 +586,10 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bH
paletteModel.SetFgColor(choosecolor.rgbResult);
break;
case IDM_COLORSMODERNPALETTE:
- paletteModel.SelectPalette(1);
+ paletteModel.SelectPalette(PAL_MODERN);
break;
case IDM_COLORSOLDPALETTE:
- paletteModel.SelectPalette(2);
+ paletteModel.SelectPalette(PAL_OLDTYPE);
break;
case IDM_IMAGEINVERTCOLORS:
{