/
PaletteDefinitionDialog.cpp
198 lines (163 loc) · 5.74 KB
/
PaletteDefinitionDialog.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// ChooseColorDialog.cpp : implementation file
//
#include "stdafx.h"
#include "SCIPicEditor.h"
#include "ChooseColorDialog.h"
#include "PaletteDefinitionDialog.h"
#include "ChooseColorAdvancedDialog.h"
volatile int g_fChecked = 0;
volatile int g_fPreview = 0;
// CChooseColorDialog dialog
CPaletteDefinitionDialog::CPaletteDefinitionDialog(CWnd* pParent /*=NULL*/)
: CExtResizableDialog(CPaletteDefinitionDialog::IDD, pParent)
{
_bSelection = 0;
_iCurPalette = 0;
// 40 things here.
m_wndStaticPalette.SetRowsAndColumns(5, 8);
m_wndStaticPalette.ShowSelection(TRUE);
m_wndStaticPalette.SetSelection(_bSelection); // Just always start with zero.
m_wndStaticPalette.SetPalette(_palette); // In which someone will copy something.
// Just 16 here.
m_wndStaticColors.SetRowsAndColumns(2, 8);
m_wndStaticColors.ShowSelection(TRUE);
m_wndStaticColors.ShowSelectionNumbers(TRUE); // show a 1 and 2
m_wndStaticColors.SetPalette(g_egaColorChooserPalette);// just provide a basic palette
}
CPaletteDefinitionDialog::~CPaletteDefinitionDialog()
{
}
void CPaletteDefinitionDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
ShowSizeGrip(FALSE);
DDX_Control(pDX, IDC_CHOOSECOLORSTATIC, m_wndStaticColors);
m_wndStaticColors.SetCallback(this);
DDX_Control(pDX, IDC_PALETTECOLORS, m_wndStaticPalette);
m_wndStaticPalette.SetCallback(this);
// The tab control:
DDX_Control(pDX, IDC_PALETTETAB, m_wndTab);
for (int i = 0; i < 4; i++)
{
TCHAR szBuf[4];
StringCchPrintf(szBuf, ARRAYSIZE(szBuf), TEXT("%d"), i);
m_wndTab.InsertItem(i, szBuf);
}
m_wndTab.SetCurSel(0); // Set first one active
DDX_Control(pDX, IDC_CHECK1, m_wndCheck);
DDX_Control(pDX, IDC_CHECK2, m_wndPreview);
m_wndCheck.SetCheck(g_fChecked);
m_wndPreview.SetCheck(g_fPreview);
if (g_fPreview && _pCallbackWeak)
{
_pCallbackWeak->OnSomethingChanged(g_fChecked, _palette, _iCurPalette);
}
// Visuals
DDX_Control(pDX, IDC_BUTTONADVANCED, m_wndAdvanced);
DDX_Control(pDX, IDOK, m_wndOK);
DDX_Control(pDX, IDCANCEL, m_wndCancel);
}
BEGIN_MESSAGE_MAP(CPaletteDefinitionDialog, CExtResizableDialog)
ON_NOTIFY(TCN_SELCHANGE, IDC_PALETTETAB, OnTabChange)
ON_BN_CLICKED(IDC_CHECK1, OnCheckClick)
ON_BN_CLICKED(IDC_CHECK2, OnPreviewToggle)
ON_BN_CLICKED(IDC_BUTTONADVANCED, OnAdvancedClick)
END_MESSAGE_MAP()
void CPaletteDefinitionDialog::InitPalettes(const EGACOLOR *pPalette)
{
CopyMemory(_palette, pPalette, sizeof(_palette));
// Set initial selection in color boxes.
m_wndStaticColors.SetSelection(GetCurrentPalettePtr()[_bSelection].color1);
m_wndStaticColors.SetAuxSelection(GetCurrentPalettePtr()[_bSelection].color2);
}
void CPaletteDefinitionDialog::RetrievePalettes(EGACOLOR *pPalette)
{
CopyMemory(pPalette, _palette, sizeof(_palette));
}
void CPaletteDefinitionDialog::OnTabChange(NMHDR *pnmhdr, LRESULT *ples)
{
_iCurPalette = m_wndTab.GetCurSel();
m_wndStaticPalette.SetPalette(GetCurrentPalettePtr());
m_wndStaticPalette.OnPaletteUpdated();
// Also update the selections in the colors list
m_wndStaticColors.SetSelection(GetCurrentPalettePtr()[_bSelection].color1);
m_wndStaticColors.SetAuxSelection(GetCurrentPalettePtr()[_bSelection].color2);
// And finally, if we're previewing...
if (g_fPreview && _pCallbackWeak)
{
_pCallbackWeak->OnSomethingChanged(g_fChecked, _palette, _iCurPalette);
}
}
void CPaletteDefinitionDialog::OnCheckClick()
{
// Update the selection.
g_fChecked = m_wndCheck.GetCheck();
}
void CPaletteDefinitionDialog::OnPreviewToggle()
{
g_fPreview = m_wndPreview.GetCheck();
if (_pCallbackWeak)
{
if (g_fPreview)
{
_pCallbackWeak->OnSomethingChanged(g_fChecked, _palette, _iCurPalette);
}
else
{
_pCallbackWeak->OnPreviewOff();
}
}
}
void CPaletteDefinitionDialog::OnAdvancedClick()
{
CChooseColorAdvancedDialog dialog;
EGACOLOR color = GetCurrentPalettePtr()[_bSelection];
dialog.SetColor(color);
if (IDOK == dialog.DoModal())
{
color = dialog.GetColor();
GetCurrentPalettePtr()[_bSelection] = color;
m_wndStaticColors.SetSelection(color.color1);
m_wndStaticColors.SetAuxSelection(color.color2);
m_wndStaticPalette.OnPaletteUpdated();
}
}
void CPaletteDefinitionDialog::OnColorClick(BYTE bIndex, int nID, BOOL fLeftClick)
{
// Figure out which child it was from.
if (nID == m_wndStaticPalette.GetDlgCtrlID())
{
// It was from the palette. Make this the new selection.
if (_bSelection < 40)
{
_bSelection = bIndex;
m_wndStaticPalette.SetSelection(_bSelection);
m_wndStaticColors.SetSelection(GetCurrentPalettePtr()[_bSelection].color1);
m_wndStaticColors.SetAuxSelection(GetCurrentPalettePtr()[_bSelection].color2);
}
}
else // colors.
{
ASSERT(nID == m_wndStaticColors.GetDlgCtrlID());
ASSERT(bIndex < 16);
ASSERT(_bSelection < 40);
if (fLeftClick)
{
// Change color 1.
GetCurrentPalettePtr()[_bSelection].color1 = bIndex;
m_wndStaticColors.SetSelection(bIndex);
}
else
{
// Change color 2.
GetCurrentPalettePtr()[_bSelection].color2 = bIndex;
m_wndStaticColors.SetAuxSelection(bIndex);
}
m_wndStaticPalette.OnPaletteUpdated();
if (_pCallbackWeak && g_fPreview)
{
// If we're supposed to preview, tell the callback that something changed.
_pCallbackWeak->OnSomethingChanged(g_fChecked, _palette, _iCurPalette);
}
}
}