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