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