diff src/win32/GBPaletteView.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/GBPaletteView.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,219 @@
     1.4 +// GBPaletteView.cpp : implementation file
     1.5 +//
     1.6 +
     1.7 +#include "stdafx.h"
     1.8 +#include "resource.h"
     1.9 +#include "GBPaletteView.h"
    1.10 +#include "FileDlg.h"
    1.11 +#include "WinResUtil.h"
    1.12 +#include "VBA.h"
    1.13 +
    1.14 +#include "../gb/gbGlobals.h"
    1.15 +
    1.16 +void GBPaletteViewControl::updatePalette()
    1.17 +{
    1.18 +	if (gbRom)
    1.19 +	{
    1.20 +		memcpy(palette, &gbPalette[paletteAddress], 64);
    1.21 +	}
    1.22 +}
    1.23 +
    1.24 +/////////////////////////////////////////////////////////////////////////////
    1.25 +// GBPaletteView dialog
    1.26 +
    1.27 +GBPaletteView::GBPaletteView(CWnd*pParent /*=NULL*/)
    1.28 +	: ResizeDlg(GBPaletteView::IDD, pParent)
    1.29 +{
    1.30 +	//{{AFX_DATA_INIT(GBPaletteView)
    1.31 +	// NOTE: the ClassWizard will add member initialization here
    1.32 +	//}}AFX_DATA_INIT
    1.33 +	autoUpdate = false;
    1.34 +}
    1.35 +
    1.36 +GBPaletteView::~GBPaletteView()
    1.37 +{}
    1.38 +
    1.39 +void GBPaletteView::DoDataExchange(CDataExchange*pDX)
    1.40 +{
    1.41 +	CDialog::DoDataExchange(pDX);
    1.42 +	//{{AFX_DATA_MAP(GBPaletteView)
    1.43 +	// NOTE: the ClassWizard will add DDX and DDV calls here
    1.44 +	//}}AFX_DATA_MAP
    1.45 +	DDX_Control(pDX, IDC_PALETTE_VIEW, paletteView);
    1.46 +	DDX_Control(pDX, IDC_PALETTE_VIEW_OBJ, paletteViewOBJ);
    1.47 +	DDX_Control(pDX, IDC_COLOR, colorControl);
    1.48 +}
    1.49 +
    1.50 +BEGIN_MESSAGE_MAP(GBPaletteView, CDialog)
    1.51 +//{{AFX_MSG_MAP(GBPaletteView)
    1.52 +ON_BN_CLICKED(IDC_SAVE_BG, OnSaveBg)
    1.53 +ON_BN_CLICKED(IDC_SAVE_OBJ, OnSaveObj)
    1.54 +ON_BN_CLICKED(IDC_REFRESH2, OnRefresh2)
    1.55 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
    1.56 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
    1.57 +//}}AFX_MSG_MAP
    1.58 +ON_MESSAGE(WM_PALINFO, OnPalInfo)
    1.59 +END_MESSAGE_MAP()
    1.60 +
    1.61 +/////////////////////////////////////////////////////////////////////////////
    1.62 +// GBPaletteView message handlers
    1.63 +
    1.64 +BOOL GBPaletteView::OnInitDialog()
    1.65 +{
    1.66 +	CDialog::OnInitDialog();
    1.67 +
    1.68 +	DIALOG_SIZER_START(sz)
    1.69 +	DIALOG_SIZER_END()
    1.70 +    SetData(sz,
    1.71 +            FALSE,
    1.72 +            HKEY_CURRENT_USER,
    1.73 +            "Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBPaletteView",
    1.74 +            NULL);
    1.75 +
    1.76 +	paletteView.init(32, 64, 128);
    1.77 +	paletteViewOBJ.init(32, 64, 128);
    1.78 +
    1.79 +	paletteView.setPaletteAddress(0);
    1.80 +	paletteView.refresh();
    1.81 +
    1.82 +	paletteViewOBJ.setPaletteAddress(32);
    1.83 +	paletteViewOBJ.refresh();
    1.84 +
    1.85 +	return TRUE; // return TRUE unless you set the focus to a control
    1.86 +	             // EXCEPTION: OCX Property Pages should return FALSE
    1.87 +}
    1.88 +
    1.89 +void GBPaletteView::save(int which)
    1.90 +{
    1.91 +	CString captureBuffer;
    1.92 +
    1.93 +	if (which == 0)
    1.94 +		captureBuffer = "bg.pal";
    1.95 +	else
    1.96 +		captureBuffer = "obj.pal";
    1.97 +
    1.98 +	LPCTSTR exts[] = {".pal", ".pal", ".act", NULL };
    1.99 +
   1.100 +	CString filter = winResLoadFilter(IDS_FILTER_PAL);
   1.101 +	CString title  = winResLoadString(IDS_SELECT_PALETTE_NAME);
   1.102 +	FileDlg dlg(this,
   1.103 +	            captureBuffer,
   1.104 +	            filter,
   1.105 +	            1,
   1.106 +	            "PAL",
   1.107 +	            exts,
   1.108 +	            "",
   1.109 +	            title,
   1.110 +	            true);
   1.111 +
   1.112 +	if (dlg.DoModal() == IDCANCEL)
   1.113 +	{
   1.114 +		return;
   1.115 +	}
   1.116 +
   1.117 +	PaletteViewControl *p = NULL;
   1.118 +
   1.119 +	if (which == 0)
   1.120 +		p = &paletteView;
   1.121 +	else
   1.122 +		p = &paletteViewOBJ;
   1.123 +
   1.124 +	switch (dlg.getFilterIndex())
   1.125 +	{
   1.126 +	case 0:
   1.127 +	case 1:
   1.128 +		p->saveMSPAL(captureBuffer);
   1.129 +		break;
   1.130 +	case 2:
   1.131 +		p->saveJASCPAL(captureBuffer);
   1.132 +		break;
   1.133 +	case 3:
   1.134 +		p->saveAdobe(captureBuffer);
   1.135 +		break;
   1.136 +	}
   1.137 +}
   1.138 +
   1.139 +void GBPaletteView::OnSaveBg()
   1.140 +{
   1.141 +	save(0);
   1.142 +}
   1.143 +
   1.144 +void GBPaletteView::OnSaveObj()
   1.145 +{
   1.146 +	save(1);
   1.147 +}
   1.148 +
   1.149 +void GBPaletteView::OnRefresh2()
   1.150 +{
   1.151 +	paletteView.refresh();
   1.152 +	paletteViewOBJ.refresh();
   1.153 +}
   1.154 +
   1.155 +void GBPaletteView::update()
   1.156 +{
   1.157 +	OnRefresh2();
   1.158 +}
   1.159 +
   1.160 +void GBPaletteView::OnAutoUpdate()
   1.161 +{
   1.162 +	autoUpdate = !autoUpdate;
   1.163 +	if (autoUpdate)
   1.164 +	{
   1.165 +		theApp.winAddUpdateListener(this);
   1.166 +	}
   1.167 +	else
   1.168 +	{
   1.169 +		theApp.winRemoveUpdateListener(this);
   1.170 +	}
   1.171 +}
   1.172 +
   1.173 +void GBPaletteView::OnClose()
   1.174 +{
   1.175 +	theApp.winRemoveUpdateListener(this);
   1.176 +
   1.177 +	DestroyWindow();
   1.178 +}
   1.179 +
   1.180 +LRESULT GBPaletteView::OnPalInfo(WPARAM wParam, LPARAM lParam)
   1.181 +{
   1.182 +	u16     color   = (u16)wParam;
   1.183 +	u32     address = (u32)lParam;
   1.184 +	CString buffer;
   1.185 +
   1.186 +	bool isOBJ = address >= 32;
   1.187 +	address &= 31;
   1.188 +
   1.189 +	buffer.Format("%d", address);
   1.190 +	GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer);
   1.191 +
   1.192 +	int r = (color & 0x1f);
   1.193 +	int g = (color & 0x3e0) >> 5;
   1.194 +	int b = (color & 0x7c00) >> 10;
   1.195 +
   1.196 +	buffer.Format("%d", r);
   1.197 +	GetDlgItem(IDC_R)->SetWindowText(buffer);
   1.198 +
   1.199 +	buffer.Format("%d", g);
   1.200 +	GetDlgItem(IDC_G)->SetWindowText(buffer);
   1.201 +
   1.202 +	buffer.Format("%d", b);
   1.203 +	GetDlgItem(IDC_B)->SetWindowText(buffer);
   1.204 +
   1.205 +	buffer.Format("0x%04X", color);
   1.206 +	GetDlgItem(IDC_VALUE)->SetWindowText(buffer);
   1.207 +
   1.208 +	colorControl.setColor(color);
   1.209 +
   1.210 +	if (isOBJ)
   1.211 +		paletteView.setSelected(-1);
   1.212 +	else
   1.213 +		paletteViewOBJ.setSelected(-1);
   1.214 +
   1.215 +	return TRUE;
   1.216 +}
   1.217 +
   1.218 +void GBPaletteView::PostNcDestroy()
   1.219 +{
   1.220 +	delete this;
   1.221 +}
   1.222 +