diff src/win32/GBColorDlg.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/GBColorDlg.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,238 @@
     1.4 +// GBColorDlg.cpp : implementation file
     1.5 +//
     1.6 +
     1.7 +#include "stdafx.h"
     1.8 +#include "resource.h"
     1.9 +#include "GBColorDlg.h"
    1.10 +#include "Reg.h"
    1.11 +
    1.12 +extern int32 gbPaletteOption;
    1.13 +extern int   emulating;
    1.14 +extern int   systemCartridgeType;
    1.15 +extern u16   gbPalette[128];
    1.16 +extern u16   systemGbPalette[24];
    1.17 +
    1.18 +static u16 defaultPalettes[][24] = {
    1.19 +	{
    1.20 +		0x7FFF, 0x56B5, 0x318C, 0x0000,  0x7FFF, 0x56B5, 0x318C, 0x0000,
    1.21 +	},
    1.22 +	{
    1.23 +		0x6200, 0x7E10, 0x7C10, 0x5000,  0x6200, 0x7E10, 0x7C10, 0x5000,
    1.24 +	},
    1.25 +	{
    1.26 +		0x4008, 0x4000, 0x2000, 0x2008,  0x4008, 0x4000, 0x2000, 0x2008,
    1.27 +	},
    1.28 +	{
    1.29 +		0x43F0, 0x03E0, 0x4200, 0x2200,  0x43F0, 0x03E0, 0x4200, 0x2200,
    1.30 +	},
    1.31 +	{
    1.32 +		0x43FF, 0x03FF, 0x221F, 0x021F,  0x43FF, 0x03FF, 0x221F, 0x021F,
    1.33 +	},
    1.34 +	{
    1.35 +		0x621F, 0x7E1F, 0x7C1F, 0x2010,  0x621F, 0x7E1F, 0x7C1F, 0x2010,
    1.36 +	},
    1.37 +	{
    1.38 +		0x621F, 0x401F, 0x001F, 0x2010,  0x621F, 0x401F, 0x001F, 0x2010,
    1.39 +	},
    1.40 +	{
    1.41 +		0x1314, 0x0E91, 0x0E0D, 0x2108,  0x1314, 0x0E91, 0x0E0D, 0x2108,
    1.42 +	}
    1.43 +};
    1.44 +
    1.45 +/////////////////////////////////////////////////////////////////////////////
    1.46 +// GBColorDlg dialog
    1.47 +
    1.48 +GBColorDlg::GBColorDlg(CWnd*pParent /*=NULL*/)
    1.49 +	: CDialog(GBColorDlg::IDD, pParent)
    1.50 +{
    1.51 +	//{{AFX_DATA_INIT(GBColorDlg)
    1.52 +	which = -1;
    1.53 +	//}}AFX_DATA_INIT
    1.54 +	which = gbPaletteOption;
    1.55 +}
    1.56 +
    1.57 +void GBColorDlg::DoDataExchange(CDataExchange*pDX)
    1.58 +{
    1.59 +	CDialog::DoDataExchange(pDX);
    1.60 +	//{{AFX_DATA_MAP(GBColorDlg)
    1.61 +	DDX_Control(pDX, IDC_PREDEFINED, m_predefined);
    1.62 +	DDX_Radio(pDX, IDC_DEFAULT, which);
    1.63 +	//}}AFX_DATA_MAP
    1.64 +}
    1.65 +
    1.66 +BEGIN_MESSAGE_MAP(GBColorDlg, CDialog)
    1.67 +//{{AFX_MSG_MAP(GBColorDlg)
    1.68 +ON_BN_CLICKED(IDC_DEFAULT, OnDefault)
    1.69 +ON_BN_CLICKED(IDC_RESET, OnReset)
    1.70 +ON_BN_CLICKED(IDC_USER1, OnUser1)
    1.71 +ON_BN_CLICKED(IDC_USER2, OnUser2)
    1.72 +ON_BN_CLICKED(ID_OK, OnOk)
    1.73 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
    1.74 +ON_CBN_SELCHANGE(IDC_PREDEFINED, OnSelchangePredefined)
    1.75 +//}}AFX_MSG_MAP
    1.76 +ON_CONTROL_RANGE(BN_CLICKED, IDC_COLOR_BG0, IDC_COLOR_OB3, OnColorClicked)
    1.77 +END_MESSAGE_MAP()
    1.78 +
    1.79 +/////////////////////////////////////////////////////////////////////////////
    1.80 +// GBColorDlg message handlers
    1.81 +
    1.82 +void GBColorDlg::OnDefault()
    1.83 +{
    1.84 +	setWhich(0);
    1.85 +}
    1.86 +
    1.87 +void GBColorDlg::OnReset()
    1.88 +{
    1.89 +	int s = which * 8;
    1.90 +	colors[s++] = (0x1f) | (0x1f << 5) | (0x1f << 10);
    1.91 +	colors[s++] = (0x15) | (0x15 << 5) | (0x15 << 10);
    1.92 +	colors[s++] = (0x0c) | (0x0c << 5) | (0x0c << 10);
    1.93 +	colors[s++] = 0;
    1.94 +
    1.95 +	colors[s++] = (0x1f) | (0x1f << 5) | (0x1f << 10);
    1.96 +	colors[s++] = (0x15) | (0x15 << 5) | (0x15 << 10);
    1.97 +	colors[s++] = (0x0c) | (0x0c << 5) | (0x0c << 10);
    1.98 +	colors[s]   = 0;
    1.99 +	setWhich(which);
   1.100 +}
   1.101 +
   1.102 +void GBColorDlg::OnUser1()
   1.103 +{
   1.104 +	setWhich(1);
   1.105 +}
   1.106 +
   1.107 +void GBColorDlg::OnUser2()
   1.108 +{
   1.109 +	setWhich(2);
   1.110 +}
   1.111 +
   1.112 +void GBColorDlg::OnCancel()
   1.113 +{
   1.114 +	EndDialog(FALSE);
   1.115 +}
   1.116 +
   1.117 +void GBColorDlg::OnOk()
   1.118 +{
   1.119 +	EndDialog(TRUE);
   1.120 +}
   1.121 +
   1.122 +BOOL GBColorDlg::OnInitDialog()
   1.123 +{
   1.124 +	CDialog::OnInitDialog();
   1.125 +
   1.126 +	colorControls[0].SubclassDlgItem(IDC_COLOR_BG0, this);
   1.127 +	colorControls[1].SubclassDlgItem(IDC_COLOR_BG1, this);
   1.128 +	colorControls[2].SubclassDlgItem(IDC_COLOR_BG2, this);
   1.129 +	colorControls[3].SubclassDlgItem(IDC_COLOR_BG3, this);
   1.130 +	colorControls[4].SubclassDlgItem(IDC_COLOR_OB0, this);
   1.131 +	colorControls[5].SubclassDlgItem(IDC_COLOR_OB1, this);
   1.132 +	colorControls[6].SubclassDlgItem(IDC_COLOR_OB2, this);
   1.133 +	colorControls[7].SubclassDlgItem(IDC_COLOR_OB3, this);
   1.134 +
   1.135 +	for (int i = 0; i < 24; i++)
   1.136 +	{
   1.137 +		colors[i] = systemGbPalette[i];
   1.138 +	}
   1.139 +
   1.140 +	const char *names[] = {
   1.141 +		"Standard",
   1.142 +		"Blue Sea",
   1.143 +		"Dark Night",
   1.144 +		"Green Forest",
   1.145 +		"Hot Desert",
   1.146 +		"Pink Dreams",
   1.147 +		"Weird Colors",
   1.148 +		"Real Colors"
   1.149 +	};
   1.150 +
   1.151 +	for (int j = 0; j < 8; j++)
   1.152 +	{
   1.153 +		int index = m_predefined.AddString(names[j]);
   1.154 +		m_predefined.SetItemData(index, j);
   1.155 +	}
   1.156 +
   1.157 +	RECT cbSize;
   1.158 +	int  Height;
   1.159 +
   1.160 +	m_predefined.GetClientRect(&cbSize);
   1.161 +	Height  = m_predefined.GetItemHeight(0);
   1.162 +	Height += m_predefined.GetItemHeight(0) * (10);
   1.163 +
   1.164 +	// Note: The use of SM_CYEDGE assumes that we're using Windows '95
   1.165 +	// Now add on the height of the border of the edit box
   1.166 +	Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges
   1.167 +
   1.168 +	// The height of the border of the drop-down box
   1.169 +	Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges
   1.170 +
   1.171 +	// now set the size of the window
   1.172 +	m_predefined.SetWindowPos(NULL,
   1.173 +	                          0, 0,
   1.174 +	                          cbSize.right, Height,
   1.175 +	                          SWP_NOMOVE | SWP_NOZORDER);
   1.176 +
   1.177 +	setWhich(which);
   1.178 +
   1.179 +	CenterWindow();
   1.180 +
   1.181 +	return TRUE; // return TRUE unless you set the focus to a control
   1.182 +	             // EXCEPTION: OCX Property Pages should return FALSE
   1.183 +}
   1.184 +
   1.185 +void GBColorDlg::setWhich(int w)
   1.186 +{
   1.187 +	which = w;
   1.188 +
   1.189 +	for (int i = 0; i < 8; i++)
   1.190 +	{
   1.191 +		colorControls[i].setColor(colors[which*8+i]);
   1.192 +	}
   1.193 +}
   1.194 +
   1.195 +u16 *GBColorDlg::getColors()
   1.196 +{
   1.197 +	return colors;
   1.198 +}
   1.199 +
   1.200 +void GBColorDlg::OnColorClicked(UINT id)
   1.201 +{
   1.202 +	id -= IDC_COLOR_BG0;
   1.203 +
   1.204 +	u16 color = colors[which*8+id];
   1.205 +
   1.206 +	COLORREF colorInit =
   1.207 +	    RGB((color & 0x1f) << 3, ((color >> 5) & 0x1f) << 3, ((color >> 10) & 0x1f) << 3);
   1.208 +
   1.209 +	CColorDialog dlg(colorInit,
   1.210 +	                 CC_FULLOPEN | CC_ANYCOLOR, this);
   1.211 +
   1.212 +	if (IDOK == dlg.DoModal())
   1.213 +	{
   1.214 +		COLORREF c = dlg.GetColor();
   1.215 +
   1.216 +		colors[which*8+id] = (u16)((c >> 3) & 0x1f | ((c >> 11) & 0x1f) << 5 |
   1.217 +		                           ((c >> 19) & 0x1f) << 10);
   1.218 +		colorControls[id].setColor(colors[which*8+id]);
   1.219 +	}
   1.220 +}
   1.221 +
   1.222 +int GBColorDlg::getWhich()
   1.223 +{
   1.224 +	return which;
   1.225 +}
   1.226 +
   1.227 +void GBColorDlg::OnSelchangePredefined()
   1.228 +{
   1.229 +	int sel = m_predefined.GetCurSel();
   1.230 +
   1.231 +	if (sel != -1)
   1.232 +	{
   1.233 +		int data = m_predefined.GetItemData(sel);
   1.234 +		for (int i = 0; i < 8; i++)
   1.235 +		{
   1.236 +			colorControls[i].setColor(defaultPalettes[data][i]);
   1.237 +			colors[which*8+i] = defaultPalettes[data][i];
   1.238 +		}
   1.239 +	}
   1.240 +}
   1.241 +