annotate src/win32/PaletteView.cpp @ 2:3549bbe597ed

adding makefile.am
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:47 -0600
parents f9f4f1b99eed
children
rev   line source
rlm@1 1 // PaletteView.cpp : implementation file
rlm@1 2 //
rlm@1 3
rlm@1 4 #include "stdafx.h"
rlm@1 5 #include "FileDlg.h"
rlm@1 6 #include "PaletteView.h"
rlm@1 7 #include "WinResUtil.h"
rlm@1 8 #include "VBA.h" // for theApp
rlm@1 9
rlm@1 10 #include "../gba/GBAGlobals.h"
rlm@1 11
rlm@1 12 void GBAPaletteViewControl::updatePalette()
rlm@1 13 {
rlm@1 14 if (paletteRAM != NULL)
rlm@1 15 memcpy(palette, &paletteRAM[paletteAddress], 512);
rlm@1 16 }
rlm@1 17
rlm@1 18 /////////////////////////////////////////////////////////////////////////////
rlm@1 19 // PaletteView dialog
rlm@1 20
rlm@1 21 PaletteView::PaletteView(CWnd*pParent /*=NULL*/)
rlm@1 22 : ResizeDlg(PaletteView::IDD, pParent)
rlm@1 23 {
rlm@1 24 //{{AFX_DATA_INIT(PaletteView)
rlm@1 25 // NOTE: the ClassWizard will add member initialization here
rlm@1 26 //}}AFX_DATA_INIT
rlm@1 27 autoUpdate = false;
rlm@1 28 }
rlm@1 29
rlm@1 30 PaletteView::~PaletteView()
rlm@1 31 {}
rlm@1 32
rlm@1 33 void PaletteView::DoDataExchange(CDataExchange*pDX)
rlm@1 34 {
rlm@1 35 CDialog::DoDataExchange(pDX);
rlm@1 36 //{{AFX_DATA_MAP(PaletteView)
rlm@1 37 // NOTE: the ClassWizard will add DDX and DDV calls here
rlm@1 38 //}}AFX_DATA_MAP
rlm@1 39 DDX_Control(pDX, IDC_PALETTE_VIEW, paletteView);
rlm@1 40 DDX_Control(pDX, IDC_PALETTE_VIEW_OBJ, paletteViewOBJ);
rlm@1 41 DDX_Control(pDX, IDC_COLOR, colorControl);
rlm@1 42 }
rlm@1 43
rlm@1 44 BEGIN_MESSAGE_MAP(PaletteView, CDialog)
rlm@1 45 //{{AFX_MSG_MAP(PaletteView)
rlm@1 46 ON_BN_CLICKED(IDC_SAVE_BG, OnSaveBg)
rlm@1 47 ON_BN_CLICKED(IDC_SAVE_OBJ, OnSaveObj)
rlm@1 48 ON_BN_CLICKED(IDC_REFRESH2, OnRefresh2)
rlm@1 49 ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
rlm@1 50 ON_BN_CLICKED(IDC_CLOSE, OnClose)
rlm@1 51 //}}AFX_MSG_MAP
rlm@1 52 ON_MESSAGE(WM_PALINFO, OnPalInfo)
rlm@1 53 END_MESSAGE_MAP()
rlm@1 54
rlm@1 55 /////////////////////////////////////////////////////////////////////////////
rlm@1 56 // PaletteView message handlers
rlm@1 57
rlm@1 58 BOOL PaletteView::OnInitDialog()
rlm@1 59 {
rlm@1 60 CDialog::OnInitDialog();
rlm@1 61
rlm@1 62 DIALOG_SIZER_START(sz)
rlm@1 63 DIALOG_SIZER_END()
rlm@1 64 SetData(sz,
rlm@1 65 FALSE,
rlm@1 66 HKEY_CURRENT_USER,
rlm@1 67 "Software\\Emulators\\VisualBoyAdvance\\Viewer\\PaletteView",
rlm@1 68 NULL);
rlm@1 69
rlm@1 70 paletteView.setPaletteAddress(0);
rlm@1 71 paletteView.refresh();
rlm@1 72
rlm@1 73 paletteViewOBJ.setPaletteAddress(0x200);
rlm@1 74 paletteViewOBJ.refresh();
rlm@1 75
rlm@1 76 return TRUE; // return TRUE unless you set the focus to a control
rlm@1 77 // EXCEPTION: OCX Property Pages should return FALSE
rlm@1 78 }
rlm@1 79
rlm@1 80 void PaletteView::save(int which)
rlm@1 81 {
rlm@1 82 CString captureBuffer;
rlm@1 83
rlm@1 84 if (which == 0)
rlm@1 85 captureBuffer = "bg.pal";
rlm@1 86 else
rlm@1 87 captureBuffer = "obj.pal";
rlm@1 88
rlm@1 89 LPCTSTR exts[] = {".pal", ".pal", ".act", NULL };
rlm@1 90
rlm@1 91 CString filter = winResLoadFilter(IDS_FILTER_PAL);
rlm@1 92 CString title = winResLoadString(IDS_SELECT_PALETTE_NAME);
rlm@1 93 FileDlg dlg(this,
rlm@1 94 captureBuffer,
rlm@1 95 filter,
rlm@1 96 1,
rlm@1 97 "PAL",
rlm@1 98 exts,
rlm@1 99 "",
rlm@1 100 title,
rlm@1 101 true);
rlm@1 102
rlm@1 103 if (dlg.DoModal() == IDCANCEL)
rlm@1 104 {
rlm@1 105 return;
rlm@1 106 }
rlm@1 107
rlm@1 108 PaletteViewControl *p = NULL;
rlm@1 109
rlm@1 110 if (which == 0)
rlm@1 111 p = &paletteView;
rlm@1 112 else
rlm@1 113 p = &paletteViewOBJ;
rlm@1 114
rlm@1 115 switch (dlg.getFilterIndex())
rlm@1 116 {
rlm@1 117 case 0:
rlm@1 118 case 1:
rlm@1 119 p->saveMSPAL(captureBuffer);
rlm@1 120 break;
rlm@1 121 case 2:
rlm@1 122 p->saveJASCPAL(captureBuffer);
rlm@1 123 break;
rlm@1 124 case 3:
rlm@1 125 p->saveAdobe(captureBuffer);
rlm@1 126 break;
rlm@1 127 }
rlm@1 128 }
rlm@1 129
rlm@1 130 void PaletteView::OnSaveBg()
rlm@1 131 {
rlm@1 132 save(0);
rlm@1 133 }
rlm@1 134
rlm@1 135 void PaletteView::OnSaveObj()
rlm@1 136 {
rlm@1 137 save(1);
rlm@1 138 }
rlm@1 139
rlm@1 140 void PaletteView::OnRefresh2()
rlm@1 141 {
rlm@1 142 paletteView.refresh();
rlm@1 143 paletteViewOBJ.refresh();
rlm@1 144 }
rlm@1 145
rlm@1 146 void PaletteView::update()
rlm@1 147 {
rlm@1 148 OnRefresh2();
rlm@1 149 }
rlm@1 150
rlm@1 151 void PaletteView::OnAutoUpdate()
rlm@1 152 {
rlm@1 153 autoUpdate = !autoUpdate;
rlm@1 154 if (autoUpdate)
rlm@1 155 {
rlm@1 156 theApp.winAddUpdateListener(this);
rlm@1 157 }
rlm@1 158 else
rlm@1 159 {
rlm@1 160 theApp.winRemoveUpdateListener(this);
rlm@1 161 }
rlm@1 162 }
rlm@1 163
rlm@1 164 void PaletteView::OnClose()
rlm@1 165 {
rlm@1 166 theApp.winRemoveUpdateListener(this);
rlm@1 167
rlm@1 168 DestroyWindow();
rlm@1 169 }
rlm@1 170
rlm@1 171 LRESULT PaletteView::OnPalInfo(WPARAM wParam, LPARAM lParam)
rlm@1 172 {
rlm@1 173 u16 color = (u16)wParam;
rlm@1 174 u32 address = (u32)lParam;
rlm@1 175 CString buffer;
rlm@1 176
rlm@1 177 if (address >= 0x200)
rlm@1 178 address = 0x5000200 + 2*(address & 255);
rlm@1 179 else
rlm@1 180 address = 0x5000000 + 2*(address & 255);
rlm@1 181
rlm@1 182 buffer.Format("0x%08X", address);
rlm@1 183 GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer);
rlm@1 184
rlm@1 185 int r = (color & 0x1f);
rlm@1 186 int g = (color & 0x3e0) >> 5;
rlm@1 187 int b = (color & 0x7c00) >> 10;
rlm@1 188
rlm@1 189 buffer.Format("%d", r);
rlm@1 190 GetDlgItem(IDC_R)->SetWindowText(buffer);
rlm@1 191
rlm@1 192 buffer.Format("%d", g);
rlm@1 193 GetDlgItem(IDC_G)->SetWindowText(buffer);
rlm@1 194
rlm@1 195 buffer.Format("%d", b);
rlm@1 196 GetDlgItem(IDC_B)->SetWindowText(buffer);
rlm@1 197
rlm@1 198 buffer.Format("0x%04X", color);
rlm@1 199 GetDlgItem(IDC_VALUE)->SetWindowText(buffer);
rlm@1 200
rlm@1 201 colorControl.setColor(color);
rlm@1 202
rlm@1 203 if (address >= 0x5000200)
rlm@1 204 {
rlm@1 205 paletteView.setSelected(-1);
rlm@1 206 }
rlm@1 207 else
rlm@1 208 paletteViewOBJ.setSelected(-1);
rlm@1 209
rlm@1 210 return TRUE;
rlm@1 211 }
rlm@1 212
rlm@1 213 void PaletteView::PostNcDestroy()
rlm@1 214 {
rlm@1 215 delete this;
rlm@1 216 }
rlm@1 217