annotate src/win32/GBColorDlg.cpp @ 3:b05d00f19d80

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