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