view src/win32/GBColorDlg.cpp @ 6:458a4f18f3cd

working on lua generation
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:48:33 -0600
parents f9f4f1b99eed
children
line wrap: on
line source
1 // GBColorDlg.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "resource.h"
6 #include "GBColorDlg.h"
7 #include "Reg.h"
9 extern int32 gbPaletteOption;
10 extern int emulating;
11 extern int systemCartridgeType;
12 extern u16 gbPalette[128];
13 extern u16 systemGbPalette[24];
15 static u16 defaultPalettes[][24] = {
16 {
17 0x7FFF, 0x56B5, 0x318C, 0x0000, 0x7FFF, 0x56B5, 0x318C, 0x0000,
18 },
19 {
20 0x6200, 0x7E10, 0x7C10, 0x5000, 0x6200, 0x7E10, 0x7C10, 0x5000,
21 },
22 {
23 0x4008, 0x4000, 0x2000, 0x2008, 0x4008, 0x4000, 0x2000, 0x2008,
24 },
25 {
26 0x43F0, 0x03E0, 0x4200, 0x2200, 0x43F0, 0x03E0, 0x4200, 0x2200,
27 },
28 {
29 0x43FF, 0x03FF, 0x221F, 0x021F, 0x43FF, 0x03FF, 0x221F, 0x021F,
30 },
31 {
32 0x621F, 0x7E1F, 0x7C1F, 0x2010, 0x621F, 0x7E1F, 0x7C1F, 0x2010,
33 },
34 {
35 0x621F, 0x401F, 0x001F, 0x2010, 0x621F, 0x401F, 0x001F, 0x2010,
36 },
37 {
38 0x1314, 0x0E91, 0x0E0D, 0x2108, 0x1314, 0x0E91, 0x0E0D, 0x2108,
39 }
40 };
42 /////////////////////////////////////////////////////////////////////////////
43 // GBColorDlg dialog
45 GBColorDlg::GBColorDlg(CWnd*pParent /*=NULL*/)
46 : CDialog(GBColorDlg::IDD, pParent)
47 {
48 //{{AFX_DATA_INIT(GBColorDlg)
49 which = -1;
50 //}}AFX_DATA_INIT
51 which = gbPaletteOption;
52 }
54 void GBColorDlg::DoDataExchange(CDataExchange*pDX)
55 {
56 CDialog::DoDataExchange(pDX);
57 //{{AFX_DATA_MAP(GBColorDlg)
58 DDX_Control(pDX, IDC_PREDEFINED, m_predefined);
59 DDX_Radio(pDX, IDC_DEFAULT, which);
60 //}}AFX_DATA_MAP
61 }
63 BEGIN_MESSAGE_MAP(GBColorDlg, CDialog)
64 //{{AFX_MSG_MAP(GBColorDlg)
65 ON_BN_CLICKED(IDC_DEFAULT, OnDefault)
66 ON_BN_CLICKED(IDC_RESET, OnReset)
67 ON_BN_CLICKED(IDC_USER1, OnUser1)
68 ON_BN_CLICKED(IDC_USER2, OnUser2)
69 ON_BN_CLICKED(ID_OK, OnOk)
70 ON_BN_CLICKED(ID_CANCEL, OnCancel)
71 ON_CBN_SELCHANGE(IDC_PREDEFINED, OnSelchangePredefined)
72 //}}AFX_MSG_MAP
73 ON_CONTROL_RANGE(BN_CLICKED, IDC_COLOR_BG0, IDC_COLOR_OB3, OnColorClicked)
74 END_MESSAGE_MAP()
76 /////////////////////////////////////////////////////////////////////////////
77 // GBColorDlg message handlers
79 void GBColorDlg::OnDefault()
80 {
81 setWhich(0);
82 }
84 void GBColorDlg::OnReset()
85 {
86 int s = which * 8;
87 colors[s++] = (0x1f) | (0x1f << 5) | (0x1f << 10);
88 colors[s++] = (0x15) | (0x15 << 5) | (0x15 << 10);
89 colors[s++] = (0x0c) | (0x0c << 5) | (0x0c << 10);
90 colors[s++] = 0;
92 colors[s++] = (0x1f) | (0x1f << 5) | (0x1f << 10);
93 colors[s++] = (0x15) | (0x15 << 5) | (0x15 << 10);
94 colors[s++] = (0x0c) | (0x0c << 5) | (0x0c << 10);
95 colors[s] = 0;
96 setWhich(which);
97 }
99 void GBColorDlg::OnUser1()
100 {
101 setWhich(1);
102 }
104 void GBColorDlg::OnUser2()
105 {
106 setWhich(2);
107 }
109 void GBColorDlg::OnCancel()
110 {
111 EndDialog(FALSE);
112 }
114 void GBColorDlg::OnOk()
115 {
116 EndDialog(TRUE);
117 }
119 BOOL GBColorDlg::OnInitDialog()
120 {
121 CDialog::OnInitDialog();
123 colorControls[0].SubclassDlgItem(IDC_COLOR_BG0, this);
124 colorControls[1].SubclassDlgItem(IDC_COLOR_BG1, this);
125 colorControls[2].SubclassDlgItem(IDC_COLOR_BG2, this);
126 colorControls[3].SubclassDlgItem(IDC_COLOR_BG3, this);
127 colorControls[4].SubclassDlgItem(IDC_COLOR_OB0, this);
128 colorControls[5].SubclassDlgItem(IDC_COLOR_OB1, this);
129 colorControls[6].SubclassDlgItem(IDC_COLOR_OB2, this);
130 colorControls[7].SubclassDlgItem(IDC_COLOR_OB3, this);
132 for (int i = 0; i < 24; i++)
133 {
134 colors[i] = systemGbPalette[i];
135 }
137 const char *names[] = {
138 "Standard",
139 "Blue Sea",
140 "Dark Night",
141 "Green Forest",
142 "Hot Desert",
143 "Pink Dreams",
144 "Weird Colors",
145 "Real Colors"
146 };
148 for (int j = 0; j < 8; j++)
149 {
150 int index = m_predefined.AddString(names[j]);
151 m_predefined.SetItemData(index, j);
152 }
154 RECT cbSize;
155 int Height;
157 m_predefined.GetClientRect(&cbSize);
158 Height = m_predefined.GetItemHeight(0);
159 Height += m_predefined.GetItemHeight(0) * (10);
161 // Note: The use of SM_CYEDGE assumes that we're using Windows '95
162 // Now add on the height of the border of the edit box
163 Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges
165 // The height of the border of the drop-down box
166 Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges
168 // now set the size of the window
169 m_predefined.SetWindowPos(NULL,
170 0, 0,
171 cbSize.right, Height,
172 SWP_NOMOVE | SWP_NOZORDER);
174 setWhich(which);
176 CenterWindow();
178 return TRUE; // return TRUE unless you set the focus to a control
179 // EXCEPTION: OCX Property Pages should return FALSE
180 }
182 void GBColorDlg::setWhich(int w)
183 {
184 which = w;
186 for (int i = 0; i < 8; i++)
187 {
188 colorControls[i].setColor(colors[which*8+i]);
189 }
190 }
192 u16 *GBColorDlg::getColors()
193 {
194 return colors;
195 }
197 void GBColorDlg::OnColorClicked(UINT id)
198 {
199 id -= IDC_COLOR_BG0;
201 u16 color = colors[which*8+id];
203 COLORREF colorInit =
204 RGB((color & 0x1f) << 3, ((color >> 5) & 0x1f) << 3, ((color >> 10) & 0x1f) << 3);
206 CColorDialog dlg(colorInit,
207 CC_FULLOPEN | CC_ANYCOLOR, this);
209 if (IDOK == dlg.DoModal())
210 {
211 COLORREF c = dlg.GetColor();
213 colors[which*8+id] = (u16)((c >> 3) & 0x1f | ((c >> 11) & 0x1f) << 5 |
214 ((c >> 19) & 0x1f) << 10);
215 colorControls[id].setColor(colors[which*8+id]);
216 }
217 }
219 int GBColorDlg::getWhich()
220 {
221 return which;
222 }
224 void GBColorDlg::OnSelchangePredefined()
225 {
226 int sel = m_predefined.GetCurSel();
228 if (sel != -1)
229 {
230 int data = m_predefined.GetItemData(sel);
231 for (int i = 0; i < 8; i++)
232 {
233 colorControls[i].setColor(defaultPalettes[data][i]);
234 colors[which*8+i] = defaultPalettes[data][i];
235 }
236 }
237 }