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