cc68a136 |
1 | /*******************************************************************\r |
2 | *\r |
3 | * File: Dialogs.cpp\r |
4 | *\r |
5 | * Author: Peter van Sebille (peter@yipton.net)\r |
6 | *\r |
7 | * Modified/adapted for picodriveN by notaz, 2006\r |
8 | *\r |
9 | * (c) Copyright 2006, notaz\r |
10 | * (c) Copyright 2002, Peter van Sebille\r |
11 | * All Rights Reserved\r |
12 | *\r |
13 | *******************************************************************/\r |
14 | \r |
15 | #include "Dialogs.h"\r |
16 | #include "Engine.h"\r |
17 | #include "picodrive.hrh"\r |
18 | #include <picodrive.rsg>\r |
19 | \r |
20 | #include "version.h"\r |
21 | #include "CSimpleTextParser.h"\r |
22 | #include <txtrich.h> // CRichText\r |
23 | #include <eikrted.h> // CEikRichTextEditor\r |
24 | #include <qikvertoptionbuttonlist.h> // CEikHorOptionButtonList\r |
25 | #include <eikopbut.h> // CEikOptionButton\r |
26 | #include <eikedwin.h> // CEikEdwin\r |
27 | #include <QuartzKeys.h> // EQuartzKeyTwoWayDown\r |
28 | \r |
29 | #include <QikCommand.h>\r |
30 | \r |
31 | \r |
32 | /************************************************\r |
33 | *\r |
34 | * config Dialog\r |
35 | *\r |
36 | ************************************************/\r |
37 | \r |
38 | CPicoConfigDialog::CPicoConfigDialog(TPicoConfig &cfg) : config(cfg)\r |
39 | {\r |
40 | }\r |
41 | \r |
42 | void CPicoConfigDialog::PostLayoutDynInitL()\r |
43 | {\r |
44 | CEikHorOptionButtonList *buttons_rot = (CEikHorOptionButtonList*) Control( ECtlOptRotation );\r |
45 | CEikHorOptionButtonList *buttons_disp = (CEikHorOptionButtonList*) Control( ECtlOptScreenMode );\r |
46 | CEikCheckBox *chkbox_altrend= (CEikCheckBox*) Control( ECtlOptUseAltRend );\r |
47 | CEikCheckBox *chkbox_acctmng= (CEikCheckBox*) Control( ECtlOptUseAccTiming );\r |
48 | CEikCheckBox *chkbox_sram = (CEikCheckBox*) Control( ECtlOptUseSRAM );\r |
49 | CEikCheckBox *chkbox_fps = (CEikCheckBox*) Control( ECtlOptShowFPS );\r |
50 | CEikCheckBox *chkbox_sound = (CEikCheckBox*) Control( ECtlOptEnableSound );\r |
51 | CEikCheckBox *chkbox_z80 = (CEikCheckBox*) Control( ECtlOptEmulateZ80 );\r |
52 | CEikCheckBox *chkbox_ym2612 = (CEikCheckBox*) Control( ECtlOptEmulateYM2612 );\r |
53 | CEikCheckBox *chkbox_sn76496= (CEikCheckBox*) Control( ECtlOptEmulateSN76496 );\r |
54 | CEikChoiceListBase *combo_sndq = (CEikChoiceListBase*) Control( ECtlOptSndQuality );\r |
55 | CEikCheckBox *chkbox_6bpad = (CEikCheckBox*) Control( ECtlOpt6ButtonPad );\r |
56 | CEikCheckBox *chkbox_gzipst = (CEikCheckBox*) Control( ECtlOptGzipStates );\r |
57 | CEikCheckBox *chkbox_accsprt= (CEikCheckBox*) Control( ECtlOptUseAccSprites );\r |
58 | CEikChoiceListBase *combo_region = (CEikChoiceListBase*) Control( ECtlOptRegion );\r |
59 | CEikOptionButton *opt_fit2 = (CEikOptionButton*) buttons_disp->ComponentControl( TPicoConfig::PMFit2 );\r |
60 | \r |
61 | buttons_rot ->SetButtonById(ECtlOptRotation0 + config.iScreenRotation);\r |
62 | buttons_disp->SetButtonById(ECtlOptScreenModeCenter + config.iScreenMode);\r |
63 | chkbox_sram ->SetState(config.iFlags & 1 ? CEikButtonBase::ESet : CEikButtonBase::EClear);\r |
64 | chkbox_fps ->SetState(config.iFlags & 2 ? CEikButtonBase::ESet : CEikButtonBase::EClear);\r |
65 | chkbox_sound ->SetState(config.iFlags & 4 ? CEikButtonBase::ESet : CEikButtonBase::EClear);\r |
66 | chkbox_gzipst ->SetState(config.iFlags & 0x80 ? CEikButtonBase::ESet : CEikButtonBase::EClear);\r |
67 | chkbox_z80 ->SetState(config.iPicoOpt & 4 ? CEikButtonBase::ESet : CEikButtonBase::EClear);\r |
68 | chkbox_ym2612 ->SetState(config.iPicoOpt & 1 ? CEikButtonBase::ESet : CEikButtonBase::EClear);\r |
69 | chkbox_sn76496->SetState(config.iPicoOpt & 2 ? CEikButtonBase::ESet : CEikButtonBase::EClear);\r |
70 | chkbox_altrend->SetState(config.iPicoOpt & 0x10? CEikButtonBase::ESet : CEikButtonBase::EClear);\r |
71 | chkbox_6bpad ->SetState(config.iPicoOpt & 0x20? CEikButtonBase::ESet : CEikButtonBase::EClear);\r |
72 | chkbox_acctmng->SetState(config.iPicoOpt & 0x40? CEikButtonBase::ESet : CEikButtonBase::EClear);\r |
73 | chkbox_accsprt->SetState(config.iPicoOpt & 0x80? CEikButtonBase::ESet : CEikButtonBase::EClear);\r |
74 | \r |
75 | // dim "fit2" if we are not in 0 or 180 mode\r |
76 | if(config.iScreenRotation != TPicoConfig::PRot0 && config.iScreenRotation != TPicoConfig::PRot180) opt_fit2->SetDimmed(ETrue);\r |
77 | // dim some stuff for alternative renderer\r |
78 | if(config.iPicoOpt & 0x10) {\r |
79 | // dim accurate sprites\r |
80 | chkbox_accsprt->SetState(CEikButtonBase::EClear);\r |
81 | chkbox_accsprt->SetDimmed(ETrue);\r |
82 | // dim fit\r |
83 | if(buttons_rot->LabeledButtonId() == ECtlOptRotation0 || buttons_rot->LabeledButtonId() == ECtlOptRotation180)\r |
84 | ((CEikOptionButton*)(buttons_disp->ComponentControl(TPicoConfig::PMFit)))->SetDimmed(ETrue);\r |
85 | }\r |
86 | \r |
87 | TInt sel = (config.iPicoOpt&8) ? 5 : 0;\r |
88 | sel+= (config.iFlags>>3)&7;\r |
89 | if (sel >= 10) sel = 0;\r |
90 | combo_sndq->SetCurrentItem(sel);\r |
91 | switch(config.PicoRegion) {\r |
92 | case 1: sel = 4; break;\r |
93 | case 2: sel = 3; break;\r |
94 | case 4: sel = 2; break;\r |
95 | case 8: sel = 1; break;\r |
96 | default:sel = 0; // auto\r |
97 | }\r |
98 | combo_region->SetCurrentItem(sel);\r |
99 | }\r |
100 | \r |
101 | TBool CPicoConfigDialog::OkToExitL(TInt aButtonId)\r |
102 | {\r |
103 | if(aButtonId != EEikBidOk) return ETrue;\r |
104 | \r |
105 | CEikHorOptionButtonList *buttons_rot = (CEikHorOptionButtonList*) Control( ECtlOptRotation );\r |
106 | CEikHorOptionButtonList *buttons_disp = (CEikHorOptionButtonList*) Control( ECtlOptScreenMode );\r |
107 | CEikCheckBox *chkbox_altrend= (CEikCheckBox*) Control( ECtlOptUseAltRend );\r |
108 | CEikCheckBox *chkbox_acctmng= (CEikCheckBox*) Control( ECtlOptUseAccTiming );\r |
109 | CEikCheckBox *chkbox_sram = (CEikCheckBox*) Control( ECtlOptUseSRAM );\r |
110 | CEikCheckBox *chkbox_fps = (CEikCheckBox*) Control( ECtlOptShowFPS );\r |
111 | CEikCheckBox *chkbox_sound = (CEikCheckBox*) Control( ECtlOptEnableSound );\r |
112 | CEikCheckBox *chkbox_z80 = (CEikCheckBox*) Control( ECtlOptEmulateZ80 );\r |
113 | CEikCheckBox *chkbox_ym2612 = (CEikCheckBox*) Control( ECtlOptEmulateYM2612 );\r |
114 | CEikCheckBox *chkbox_sn76496= (CEikCheckBox*) Control( ECtlOptEmulateSN76496 );\r |
115 | CEikChoiceListBase *combo_sndq = (CEikChoiceListBase*) Control( ECtlOptSndQuality );\r |
116 | CEikCheckBox *chkbox_6bpad = (CEikCheckBox*) Control( ECtlOpt6ButtonPad );\r |
117 | CEikCheckBox *chkbox_gzipst = (CEikCheckBox*) Control( ECtlOptGzipStates );\r |
118 | CEikCheckBox *chkbox_accsprt= (CEikCheckBox*) Control( ECtlOptUseAccSprites );\r |
119 | CEikChoiceListBase *combo_region = (CEikChoiceListBase*) Control( ECtlOptRegion );\r |
120 | \r |
121 | config.iScreenRotation = (TPicoConfig::TPicoScreenRotation) (buttons_rot->LabeledButtonId() - ECtlOptRotation0);\r |
122 | config.iScreenMode = (TPicoConfig::TPicoScreenMode) (buttons_disp->LabeledButtonId() - ECtlOptScreenModeCenter);\r |
123 | \r |
124 | if(chkbox_sram ->State() == CEikButtonBase::ESet) config.iFlags |= 1; else config.iFlags &= ~1;\r |
125 | if(chkbox_fps ->State() == CEikButtonBase::ESet) config.iFlags |= 2; else config.iFlags &= ~2;\r |
126 | if(chkbox_sound ->State() == CEikButtonBase::ESet) config.iFlags |= 4; else config.iFlags &= ~4;\r |
127 | if(chkbox_gzipst ->State() == CEikButtonBase::ESet) config.iFlags |= 0x80; else config.iFlags &= ~0x80;\r |
128 | if(chkbox_z80 ->State() == CEikButtonBase::ESet) config.iPicoOpt |= 4; else config.iPicoOpt &= ~4;\r |
129 | if(chkbox_ym2612 ->State() == CEikButtonBase::ESet) config.iPicoOpt |= 1; else config.iPicoOpt &= ~1;\r |
130 | if(chkbox_sn76496->State() == CEikButtonBase::ESet) config.iPicoOpt |= 2; else config.iPicoOpt &= ~2;\r |
131 | if(chkbox_altrend->State() == CEikButtonBase::ESet) config.iPicoOpt |= 0x10;else config.iPicoOpt &= ~0x10;\r |
132 | if(chkbox_6bpad ->State() == CEikButtonBase::ESet) config.iPicoOpt |= 0x20;else config.iPicoOpt &= ~0x20;\r |
133 | if(chkbox_acctmng->State() == CEikButtonBase::ESet) config.iPicoOpt |= 0x40;else config.iPicoOpt &= ~0x40;\r |
134 | if(chkbox_accsprt->State() == CEikButtonBase::ESet) config.iPicoOpt |= 0x80;else config.iPicoOpt &= ~0x80;\r |
135 | \r |
136 | TInt sel = combo_sndq->CurrentItem();\r |
137 | if(sel >= 5) { config.iPicoOpt |= 8; sel-=5; } else config.iPicoOpt &= ~8;\r |
138 | config.iFlags &= ~0x38;\r |
139 | config.iFlags |= (sel<<3)&0x38;\r |
140 | \r |
141 | switch(combo_region->CurrentItem()) {\r |
142 | case 4: config.PicoRegion = 1; break;\r |
143 | case 3: config.PicoRegion = 2; break;\r |
144 | case 2: config.PicoRegion = 4; break;\r |
145 | case 1: config.PicoRegion = 8; break;\r |
146 | default:config.PicoRegion = 0; // auto\r |
147 | }\r |
148 | \r |
149 | return ETrue;\r |
150 | }\r |
151 | \r |
152 | // simple GUI stuff needs lots of code\r |
153 | void CPicoConfigDialog::HandleControlStateChangeL(TInt aControlId)\r |
154 | {\r |
155 | if(aControlId == ECtlOptEnableSound) {\r |
156 | CEikCheckBox *chkbox_sound = (CEikCheckBox*) Control( ECtlOptEnableSound );\r |
157 | CEikCheckBox *chkbox_z80 = (CEikCheckBox*) Control( ECtlOptEmulateZ80 );\r |
158 | CEikCheckBox *chkbox_ym2612 = (CEikCheckBox*) Control( ECtlOptEmulateYM2612 );\r |
159 | CEikCheckBox *chkbox_sn76496= (CEikCheckBox*) Control( ECtlOptEmulateSN76496 );\r |
160 | \r |
161 | if(chkbox_sound->State() == CEikButtonBase::ESet) {\r |
162 | // check all sound chips too, but only if they all are not set\r |
163 | if((chkbox_z80->State() | chkbox_ym2612->State() | chkbox_sn76496->State()) == CEikButtonBase::EClear) { // (==0)\r |
164 | chkbox_z80 ->SetState(CEikButtonBase::ESet);\r |
165 | chkbox_ym2612 ->SetState(CEikButtonBase::ESet);\r |
166 | chkbox_sn76496->SetState(CEikButtonBase::ESet);\r |
167 | chkbox_z80 ->DrawDeferred();\r |
168 | chkbox_ym2612 ->DrawDeferred();\r |
169 | chkbox_sn76496->DrawDeferred();\r |
170 | }\r |
171 | } else {\r |
172 | // clear everything, but only if everything is set\r |
173 | if((chkbox_z80->State() & chkbox_ym2612->State() & chkbox_sn76496->State()) == CEikButtonBase::ESet) { // (==1)\r |
174 | chkbox_z80 ->SetState(CEikButtonBase::EClear);\r |
175 | chkbox_ym2612 ->SetState(CEikButtonBase::EClear);\r |
176 | chkbox_sn76496->SetState(CEikButtonBase::EClear);\r |
177 | chkbox_z80 ->DrawDeferred();\r |
178 | chkbox_ym2612 ->DrawDeferred();\r |
179 | chkbox_sn76496->DrawDeferred();\r |
180 | }\r |
181 | }\r |
182 | } else if(aControlId == ECtlOptUseAltRend || aControlId == ECtlOptRotation) {\r |
183 | CEikCheckBox *chkbox_altrend= (CEikCheckBox*) Control( ECtlOptUseAltRend );\r |
184 | CEikCheckBox *chkbox_accsprt= (CEikCheckBox*) Control( ECtlOptUseAccSprites );\r |
185 | CEikHorOptionButtonList *buttons_rot = (CEikHorOptionButtonList*) Control( ECtlOptRotation );\r |
186 | CEikHorOptionButtonList *buttons_disp = (CEikHorOptionButtonList*) Control( ECtlOptScreenMode );\r |
187 | CEikOptionButton *opt_fit = (CEikOptionButton*) buttons_disp->ComponentControl( TPicoConfig::PMFit );\r |
188 | CEikOptionButton *opt_fit2 = (CEikOptionButton*) buttons_disp->ComponentControl( TPicoConfig::PMFit2 );\r |
189 | \r |
190 | TBool dimmed = chkbox_altrend->State() == CEikButtonBase::ESet;\r |
191 | // show/hide more stuff for alternative renderer\r |
192 | chkbox_accsprt->SetDimmed(dimmed);\r |
193 | if(buttons_rot->LabeledButtonId() == ECtlOptRotation0 || buttons_rot->LabeledButtonId() == ECtlOptRotation180) {\r |
194 | opt_fit->SetDimmed(dimmed);\r |
195 | if(dimmed && buttons_disp->LabeledButtonId() == ECtlOptScreenModeFit)\r |
196 | buttons_disp->SetButtonById(ECtlOptScreenModeFit2);\r |
197 | }\r |
198 | else opt_fit->SetDimmed(EFalse);\r |
199 | chkbox_accsprt->DrawDeferred();\r |
200 | buttons_disp->DrawDeferred();\r |
201 | \r |
202 | if(buttons_rot->LabeledButtonId() == ECtlOptRotation0 || buttons_rot->LabeledButtonId() == ECtlOptRotation180) {\r |
203 | opt_fit2->SetDimmed(EFalse);\r |
204 | } else {\r |
205 | if(opt_fit2->State() == CEikButtonBase::ESet) {\r |
206 | buttons_disp->SetButtonById(ECtlOptScreenModeFit);\r |
207 | buttons_disp->DrawDeferred();\r |
208 | }\r |
209 | opt_fit2->SetDimmed(ETrue);\r |
210 | }\r |
211 | opt_fit2->DrawDeferred();\r |
212 | }\r |
213 | }\r |
214 | \r |
215 | \r |
216 | /************************************************\r |
217 | *\r |
218 | * About Dialog\r |
219 | *\r |
220 | ************************************************/\r |
221 | \r |
222 | void CAboutDialog::PostLayoutDynInitL()\r |
223 | {\r |
224 | TBuf<16> versionText;\r |
225 | TBuf<512> text;\r |
226 | \r |
227 | #if (KPicoBuildNumber != 0)\r |
228 | versionText.Format(_L("%d.%d%d"), KPicoMajorVersionNumber, KPicoMinorVersionNumber, KPicoBuildNumber);\r |
229 | #else\r |
230 | versionText.Format(_L("%d.%d"), KPicoMajorVersionNumber, KPicoMinorVersionNumber);\r |
231 | #endif\r |
232 | \r |
233 | CEikRichTextEditor* richTextEd = LocateControlByUniqueHandle<CEikRichTextEditor>(ECtlPicoAboutText);\r |
234 | User::LeaveIfNull(richTextEd);\r |
235 | \r |
236 | HBufC *aboutFormat = CEikonEnv::Static()->AllocReadResourceLC(R_PICO_TEXT_ABOUT);\r |
237 | CSimpleTextFormatParser *parser = CSimpleTextFormatParser::NewLC();\r |
238 | \r |
239 | text.Format(*aboutFormat, &versionText);\r |
240 | parser->ParseL(text, *richTextEd->RichText());\r |
241 | \r |
242 | richTextEd->UpdateAllFieldsL(); // Updates all the fields in the document\r |
243 | \r |
244 | CleanupStack::PopAndDestroy(parser);\r |
245 | CleanupStack::PopAndDestroy(aboutFormat);\r |
246 | }\r |
247 | \r |
248 | /*************************************************************\r |
249 | *\r |
250 | * Credits dialog\r |
251 | *\r |
252 | **************************************************************/\r |
253 | \r |
254 | void CCreditsDialog::PreLayoutDynInitL()\r |
255 | {\r |
256 | CEikEdwin *edwin = LocateControlByUniqueHandle<CEikEdwin>(ECtlPicoCreditsText);\r |
257 | User::LeaveIfNull(edwin);\r |
258 | \r |
259 | CDesCArrayFlat* desArray = CEikonEnv::Static()->ReadDesCArrayResourceL(R_PICO_TBUF_CREDITS);\r |
260 | CleanupStack::PushL(desArray);\r |
261 | \r |
262 | edwin->SetTextLimit(2048); // to prevent stupid "too big" warning\r |
263 | TInt count = desArray->Count();\r |
264 | for (TInt i = 0; i < count; i++)\r |
265 | {\r |
266 | edwin->Text()->InsertL(edwin->TextLength(), desArray->operator[](i));\r |
267 | edwin->Text()->InsertL(edwin->TextLength(), CEditableText::ELineBreak);\r |
268 | }\r |
269 | CleanupStack::PopAndDestroy(desArray);\r |
270 | }\r |
271 | \r |
272 | TKeyResponse CCreditsDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)\r |
273 | {\r |
274 | if (aType == EEventKey)\r |
275 | {\r |
276 | CEikEdwin *edwin = LocateControlByUniqueHandle<CEikEdwin>(ECtlPicoCreditsText);\r |
277 | User::LeaveIfNull(edwin);\r |
278 | \r |
279 | if (aKeyEvent.iCode == EQuartzKeyTwoWayDown)\r |
280 | {\r |
281 | edwin->MoveDisplayL(TCursorPosition::EFLineDown);\r |
282 | edwin->UpdateScrollBarsL();\r |
283 | return EKeyWasConsumed;\r |
284 | }\r |
285 | else if (aKeyEvent.iCode == EQuartzKeyTwoWayUp)\r |
286 | {\r |
287 | edwin->MoveDisplayL(TCursorPosition::EFLineUp);\r |
288 | edwin->UpdateScrollBarsL();\r |
289 | return EKeyWasConsumed;\r |
290 | }\r |
291 | }\r |
292 | return CQikSimpleDialog::OfferKeyEventL(aKeyEvent, aType);\r |
293 | }\r |
294 | \r |
295 | /*************************************************************\r |
296 | *\r |
297 | * Debug dialog\r |
298 | *\r |
299 | **************************************************************/\r |
300 | \r |
301 | CDebugDialog::CDebugDialog(char *t)\r |
302 | {\r |
303 | Mem::Copy(iText, t, 1024);\r |
304 | iText[1023] = 0;\r |
305 | }\r |
306 | \r |
307 | void CDebugDialog::PreLayoutDynInitL()\r |
308 | {\r |
309 | char *p = iText, *line = iText;\r |
310 | TBool end=0;\r |
311 | TBuf<128> tbuf;\r |
312 | CEikEdwin *editor = LocateControlByUniqueHandle<CEikEdwin>(ECtlPicoCreditsText);\r |
313 | \r |
314 | while(!end) {\r |
315 | while(*p && *p != '\r' && *p != '\n') p++;\r |
316 | if(!*p) end=1;\r |
317 | *p = 0;\r |
318 | TPtrC8 ptr((TUint8*) line);\r |
319 | tbuf.Copy(ptr);\r |
320 | editor->Text()->InsertL(editor->TextLength(), tbuf);\r |
321 | editor->Text()->InsertL(editor->TextLength(), CEditableText::ELineBreak);\r |
322 | line = ++p;\r |
323 | }\r |
324 | }\r |