-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpalettemodel.cpp
109 lines (95 loc) · 2.84 KB
/
palettemodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* PROJECT: PAINT for ReactOS
* LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
* PURPOSE: Keep track of palette data, notify listeners
* COPYRIGHT: Copyright 2015 Benedikt Freisen <[email protected]>
* Copyright 2021 Katayama Hirofumi MZ <[email protected]>
*/
#include "precomp.h"
PaletteModel paletteModel;
/* FUNCTIONS ********************************************************/
PaletteModel::PaletteModel()
{
m_fgColor = 0x00000000;
m_bgColor = 0x00ffffff;
SelectPalette(PAL_MODERN);
}
PAL_TYPE PaletteModel::SelectedPalette()
{
return m_nSelectedPalette;
}
void PaletteModel::SelectPalette(PAL_TYPE nPalette)
{
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
};
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
};
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();
}
COLORREF PaletteModel::GetColor(UINT nIndex) const
{
if (nIndex < NUM_COLORS)
return m_colors[nIndex];
else
return 0;
}
void PaletteModel::SetColor(UINT nIndex, COLORREF newColor)
{
if (nIndex < NUM_COLORS)
{
m_colors[nIndex] = newColor;
NotifyPaletteChanged();
}
}
COLORREF PaletteModel::GetFgColor() const
{
return m_fgColor;
}
void PaletteModel::SetFgColor(COLORREF newColor)
{
m_fgColor = newColor;
NotifyColorChanged();
}
COLORREF PaletteModel::GetBgColor() const
{
return m_bgColor;
}
void PaletteModel::SetBgColor(COLORREF newColor)
{
m_bgColor = newColor;
NotifyColorChanged();
}
void PaletteModel::NotifyColorChanged()
{
if (paletteWindow.IsWindow())
paletteWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
if (canvasWindow.IsWindow())
canvasWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
if (textEditWindow.IsWindow())
textEditWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
}
void PaletteModel::NotifyPaletteChanged()
{
if (paletteWindow.IsWindow())
paletteWindow.Invalidate(FALSE);
}