2015-07-07 11:15:24 +00:00
|
|
|
/*
|
2023-06-23 11:04:32 +00:00
|
|
|
* 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
|
2023-06-27 18:22:21 +00:00
|
|
|
* COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
|
2023-06-23 11:04:32 +00:00
|
|
|
* Copyright 2021 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
|
2015-07-07 11:15:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
2023-03-28 13:31:26 +00:00
|
|
|
PaletteModel paletteModel;
|
|
|
|
|
2015-07-07 11:15:24 +00:00
|
|
|
/* FUNCTIONS ********************************************************/
|
|
|
|
|
|
|
|
PaletteModel::PaletteModel()
|
|
|
|
{
|
|
|
|
m_fgColor = 0x00000000;
|
|
|
|
m_bgColor = 0x00ffffff;
|
2021-12-28 10:01:31 +00:00
|
|
|
SelectPalette(PAL_MODERN);
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-28 10:01:31 +00:00
|
|
|
PAL_TYPE PaletteModel::SelectedPalette()
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
return m_nSelectedPalette;
|
|
|
|
}
|
|
|
|
|
2021-12-28 10:01:31 +00:00
|
|
|
void PaletteModel::SelectPalette(PAL_TYPE nPalette)
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
2021-12-28 10:01:31 +00:00
|
|
|
static const COLORREF modernColors[NUM_COLORS] =
|
|
|
|
{
|
2015-07-07 11:15:24 +00:00
|
|
|
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
|
|
|
|
};
|
2021-12-28 10:01:31 +00:00
|
|
|
static const COLORREF oldColors[NUM_COLORS] =
|
|
|
|
{
|
2015-07-07 11:15:24 +00:00
|
|
|
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
|
|
|
|
};
|
2021-12-28 10:01:31 +00:00
|
|
|
switch (nPalette)
|
|
|
|
{
|
|
|
|
case PAL_MODERN:
|
|
|
|
CopyMemory(m_colors, modernColors, sizeof(m_colors));
|
|
|
|
break;
|
|
|
|
case PAL_OLDTYPE:
|
|
|
|
CopyMemory(m_colors, oldColors, sizeof(m_colors));
|
|
|
|
break;
|
|
|
|
}
|
2015-07-07 11:15:24 +00:00
|
|
|
m_nSelectedPalette = nPalette;
|
2015-07-07 11:44:50 +00:00
|
|
|
NotifyPaletteChanged();
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-28 10:01:31 +00:00
|
|
|
COLORREF PaletteModel::GetColor(UINT nIndex) const
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
2021-12-28 10:01:31 +00:00
|
|
|
if (nIndex < NUM_COLORS)
|
2015-07-07 11:15:24 +00:00
|
|
|
return m_colors[nIndex];
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-12-28 10:01:31 +00:00
|
|
|
void PaletteModel::SetColor(UINT nIndex, COLORREF newColor)
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
2021-12-28 10:01:31 +00:00
|
|
|
if (nIndex < NUM_COLORS)
|
2015-07-07 11:44:50 +00:00
|
|
|
{
|
2015-07-07 11:15:24 +00:00
|
|
|
m_colors[nIndex] = newColor;
|
2015-07-07 11:44:50 +00:00
|
|
|
NotifyPaletteChanged();
|
|
|
|
}
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-28 10:01:31 +00:00
|
|
|
COLORREF PaletteModel::GetFgColor() const
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
return m_fgColor;
|
|
|
|
}
|
|
|
|
|
2021-12-28 10:01:31 +00:00
|
|
|
void PaletteModel::SetFgColor(COLORREF newColor)
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
m_fgColor = newColor;
|
2015-07-07 11:44:50 +00:00
|
|
|
NotifyColorChanged();
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-28 10:01:31 +00:00
|
|
|
COLORREF PaletteModel::GetBgColor() const
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
return m_bgColor;
|
|
|
|
}
|
|
|
|
|
2021-12-28 10:01:31 +00:00
|
|
|
void PaletteModel::SetBgColor(COLORREF newColor)
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
m_bgColor = newColor;
|
2015-07-07 11:44:50 +00:00
|
|
|
NotifyColorChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PaletteModel::NotifyColorChanged()
|
|
|
|
{
|
2022-01-22 15:59:12 +00:00
|
|
|
if (paletteWindow.IsWindow())
|
|
|
|
paletteWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
|
2023-04-08 13:25:27 +00:00
|
|
|
if (canvasWindow.IsWindow())
|
|
|
|
canvasWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
|
2022-01-05 07:26:05 +00:00
|
|
|
if (textEditWindow.IsWindow())
|
|
|
|
textEditWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
|
2015-07-07 11:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaletteModel::NotifyPaletteChanged()
|
|
|
|
{
|
2022-01-22 15:59:12 +00:00
|
|
|
if (paletteWindow.IsWindow())
|
2023-06-17 12:15:35 +00:00
|
|
|
paletteWindow.Invalidate(FALSE);
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|