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