1c2c66affSColin Finck /*
2c2c66affSColin Finck * PROJECT: PAINT for ReactOS
38f1f1c7aSStanislav Motylkov * LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4c2c66affSColin Finck * PURPOSE: Keep track of palette data, notify listeners
5*f5200e6cSStanislav Motylkov * COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
68f1f1c7aSStanislav Motylkov * Copyright 2021 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
7c2c66affSColin Finck */
8c2c66affSColin Finck
9c2c66affSColin Finck #include "precomp.h"
10c2c66affSColin Finck
1129e147beSKatayama Hirofumi MZ PaletteModel paletteModel;
1229e147beSKatayama Hirofumi MZ
13c2c66affSColin Finck /* FUNCTIONS ********************************************************/
14c2c66affSColin Finck
PaletteModel()15c2c66affSColin Finck PaletteModel::PaletteModel()
16c2c66affSColin Finck {
17c2c66affSColin Finck m_fgColor = 0x00000000;
18c2c66affSColin Finck m_bgColor = 0x00ffffff;
19d30e5eb5SKatayama Hirofumi MZ SelectPalette(PAL_MODERN);
20c2c66affSColin Finck }
21c2c66affSColin Finck
SelectedPalette()22d30e5eb5SKatayama Hirofumi MZ PAL_TYPE PaletteModel::SelectedPalette()
23c2c66affSColin Finck {
24c2c66affSColin Finck return m_nSelectedPalette;
25c2c66affSColin Finck }
26c2c66affSColin Finck
SelectPalette(PAL_TYPE nPalette)27d30e5eb5SKatayama Hirofumi MZ void PaletteModel::SelectPalette(PAL_TYPE nPalette)
28c2c66affSColin Finck {
29d30e5eb5SKatayama Hirofumi MZ static const COLORREF modernColors[NUM_COLORS] =
30d30e5eb5SKatayama Hirofumi MZ {
31c2c66affSColin Finck 0x000000, 0x464646, 0x787878, 0x300099, 0x241ced, 0x0078ff, 0x0ec2ff,
32c2c66affSColin Finck 0x00f2ff, 0x1de6a8, 0x4cb122, 0xefb700, 0xf36d4d, 0x99362f, 0x98316f,
33c2c66affSColin Finck 0xffffff, 0xdcdcdc, 0xb4b4b4, 0x3c5a9c, 0xb1a3ff, 0x7aaae5, 0x9ce4f5,
34c2c66affSColin Finck 0xbdf9ff, 0xbcf9d3, 0x61bb9d, 0xead999, 0xd19a70, 0x8e6d54, 0xd5a5b5
35c2c66affSColin Finck };
36d30e5eb5SKatayama Hirofumi MZ static const COLORREF oldColors[NUM_COLORS] =
37d30e5eb5SKatayama Hirofumi MZ {
38c2c66affSColin Finck 0x000000, 0x808080, 0x000080, 0x008080, 0x008000, 0x808000, 0x800000,
39c2c66affSColin Finck 0x800080, 0x408080, 0x404000, 0xff8000, 0x804000, 0xff0040, 0x004080,
40c2c66affSColin Finck 0xffffff, 0xc0c0c0, 0x0000ff, 0x00ffff, 0x00ff00, 0xffff00, 0xff0000,
41c2c66affSColin Finck 0xff00ff, 0x80ffff, 0x80ff00, 0xffff80, 0xff8080, 0x8000ff, 0x4080ff
42c2c66affSColin Finck };
43d30e5eb5SKatayama Hirofumi MZ switch (nPalette)
44d30e5eb5SKatayama Hirofumi MZ {
45d30e5eb5SKatayama Hirofumi MZ case PAL_MODERN:
46c2c66affSColin Finck CopyMemory(m_colors, modernColors, sizeof(m_colors));
47d30e5eb5SKatayama Hirofumi MZ break;
48d30e5eb5SKatayama Hirofumi MZ case PAL_OLDTYPE:
49c2c66affSColin Finck CopyMemory(m_colors, oldColors, sizeof(m_colors));
50d30e5eb5SKatayama Hirofumi MZ break;
51d30e5eb5SKatayama Hirofumi MZ }
52c2c66affSColin Finck m_nSelectedPalette = nPalette;
53c2c66affSColin Finck NotifyPaletteChanged();
54c2c66affSColin Finck }
55c2c66affSColin Finck
GetColor(UINT nIndex) const56d30e5eb5SKatayama Hirofumi MZ COLORREF PaletteModel::GetColor(UINT nIndex) const
57c2c66affSColin Finck {
58d30e5eb5SKatayama Hirofumi MZ if (nIndex < NUM_COLORS)
59c2c66affSColin Finck return m_colors[nIndex];
60c2c66affSColin Finck else
61c2c66affSColin Finck return 0;
62c2c66affSColin Finck }
63c2c66affSColin Finck
SetColor(UINT nIndex,COLORREF newColor)64d30e5eb5SKatayama Hirofumi MZ void PaletteModel::SetColor(UINT nIndex, COLORREF newColor)
65c2c66affSColin Finck {
66d30e5eb5SKatayama Hirofumi MZ if (nIndex < NUM_COLORS)
67c2c66affSColin Finck {
68c2c66affSColin Finck m_colors[nIndex] = newColor;
69c2c66affSColin Finck NotifyPaletteChanged();
70c2c66affSColin Finck }
71c2c66affSColin Finck }
72c2c66affSColin Finck
GetFgColor() const73d30e5eb5SKatayama Hirofumi MZ COLORREF PaletteModel::GetFgColor() const
74c2c66affSColin Finck {
75c2c66affSColin Finck return m_fgColor;
76c2c66affSColin Finck }
77c2c66affSColin Finck
SetFgColor(COLORREF newColor)78d30e5eb5SKatayama Hirofumi MZ void PaletteModel::SetFgColor(COLORREF newColor)
79c2c66affSColin Finck {
80c2c66affSColin Finck m_fgColor = newColor;
81c2c66affSColin Finck NotifyColorChanged();
82c2c66affSColin Finck }
83c2c66affSColin Finck
GetBgColor() const84d30e5eb5SKatayama Hirofumi MZ COLORREF PaletteModel::GetBgColor() const
85c2c66affSColin Finck {
86c2c66affSColin Finck return m_bgColor;
87c2c66affSColin Finck }
88c2c66affSColin Finck
SetBgColor(COLORREF newColor)89d30e5eb5SKatayama Hirofumi MZ void PaletteModel::SetBgColor(COLORREF newColor)
90c2c66affSColin Finck {
91c2c66affSColin Finck m_bgColor = newColor;
92c2c66affSColin Finck NotifyColorChanged();
93c2c66affSColin Finck }
94c2c66affSColin Finck
NotifyColorChanged()95c2c66affSColin Finck void PaletteModel::NotifyColorChanged()
96c2c66affSColin Finck {
977014cf04SKatayama Hirofumi MZ if (paletteWindow.IsWindow())
98c2c66affSColin Finck paletteWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
99efe7368cSKatayama Hirofumi MZ if (canvasWindow.IsWindow())
100efe7368cSKatayama Hirofumi MZ canvasWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
101361a2ce4SKatayama Hirofumi MZ if (textEditWindow.IsWindow())
102361a2ce4SKatayama Hirofumi MZ textEditWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
103c2c66affSColin Finck }
104c2c66affSColin Finck
NotifyPaletteChanged()105c2c66affSColin Finck void PaletteModel::NotifyPaletteChanged()
106c2c66affSColin Finck {
1077014cf04SKatayama Hirofumi MZ if (paletteWindow.IsWindow())
108e8c7e300SKatayama Hirofumi MZ paletteWindow.Invalidate(FALSE);
109c2c66affSColin Finck }
110