1 /*******************************************************************
\r
5 * Author: Peter van Sebille (peter@yipton.net)
\r
7 * Modified/adapted for picodriveN by notaz, 2006
\r
9 * (c) Copyright 2006, notaz
\r
10 * (c) Copyright 2002, Peter van Sebille
\r
11 * All Rights Reserved
\r
13 *******************************************************************/
\r
15 #include "Dialogs.h"
\r
17 #include "picodrive.hrh"
\r
18 #include <picodrive.rsg>
\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
29 #include <QikCommand.h>
\r
32 /************************************************
\r
36 ************************************************/
\r
38 CPicoConfigDialog::CPicoConfigDialog(TPicoConfig &cfg) : config(cfg)
\r
42 void CPicoConfigDialog::PostLayoutDynInitL()
\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
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
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
83 if(buttons_rot->LabeledButtonId() == ECtlOptRotation0 || buttons_rot->LabeledButtonId() == ECtlOptRotation180)
\r
84 ((CEikOptionButton*)(buttons_disp->ComponentControl(TPicoConfig::PMFit)))->SetDimmed(ETrue);
\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
98 combo_region->SetCurrentItem(sel);
\r
101 TBool CPicoConfigDialog::OkToExitL(TInt aButtonId)
\r
103 if(aButtonId != EEikBidOk) return ETrue;
\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
121 config.iScreenRotation = (TPicoConfig::TPicoScreenRotation) (buttons_rot->LabeledButtonId() - ECtlOptRotation0);
\r
122 config.iScreenMode = (TPicoConfig::TPicoScreenMode) (buttons_disp->LabeledButtonId() - ECtlOptScreenModeCenter);
\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
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
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
152 // simple GUI stuff needs lots of code
\r
153 void CPicoConfigDialog::HandleControlStateChangeL(TInt aControlId)
\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
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
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
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
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
198 else opt_fit->SetDimmed(EFalse);
\r
199 chkbox_accsprt->DrawDeferred();
\r
200 buttons_disp->DrawDeferred();
\r
202 if(buttons_rot->LabeledButtonId() == ECtlOptRotation0 || buttons_rot->LabeledButtonId() == ECtlOptRotation180) {
\r
203 opt_fit2->SetDimmed(EFalse);
\r
205 if(opt_fit2->State() == CEikButtonBase::ESet) {
\r
206 buttons_disp->SetButtonById(ECtlOptScreenModeFit);
\r
207 buttons_disp->DrawDeferred();
\r
209 opt_fit2->SetDimmed(ETrue);
\r
211 opt_fit2->DrawDeferred();
\r
216 /************************************************
\r
220 ************************************************/
\r
222 void CAboutDialog::PostLayoutDynInitL()
\r
224 TBuf<16> versionText;
\r
227 #if (KPicoBuildNumber != 0)
\r
228 versionText.Format(_L("%d.%d%d"), KPicoMajorVersionNumber, KPicoMinorVersionNumber, KPicoBuildNumber);
\r
230 versionText.Format(_L("%d.%d"), KPicoMajorVersionNumber, KPicoMinorVersionNumber);
\r
233 CEikRichTextEditor* richTextEd = LocateControlByUniqueHandle<CEikRichTextEditor>(ECtlPicoAboutText);
\r
234 User::LeaveIfNull(richTextEd);
\r
236 HBufC *aboutFormat = CEikonEnv::Static()->AllocReadResourceLC(R_PICO_TEXT_ABOUT);
\r
237 CSimpleTextFormatParser *parser = CSimpleTextFormatParser::NewLC();
\r
239 text.Format(*aboutFormat, &versionText);
\r
240 parser->ParseL(text, *richTextEd->RichText());
\r
242 richTextEd->UpdateAllFieldsL(); // Updates all the fields in the document
\r
244 CleanupStack::PopAndDestroy(parser);
\r
245 CleanupStack::PopAndDestroy(aboutFormat);
\r
248 /*************************************************************
\r
252 **************************************************************/
\r
254 void CCreditsDialog::PreLayoutDynInitL()
\r
256 CEikEdwin *edwin = LocateControlByUniqueHandle<CEikEdwin>(ECtlPicoCreditsText);
\r
257 User::LeaveIfNull(edwin);
\r
259 CDesCArrayFlat* desArray = CEikonEnv::Static()->ReadDesCArrayResourceL(R_PICO_TBUF_CREDITS);
\r
260 CleanupStack::PushL(desArray);
\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
266 edwin->Text()->InsertL(edwin->TextLength(), desArray->operator[](i));
\r
267 edwin->Text()->InsertL(edwin->TextLength(), CEditableText::ELineBreak);
\r
269 CleanupStack::PopAndDestroy(desArray);
\r
272 TKeyResponse CCreditsDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
\r
274 if (aType == EEventKey)
\r
276 CEikEdwin *edwin = LocateControlByUniqueHandle<CEikEdwin>(ECtlPicoCreditsText);
\r
277 User::LeaveIfNull(edwin);
\r
279 if (aKeyEvent.iCode == EQuartzKeyTwoWayDown)
\r
281 edwin->MoveDisplayL(TCursorPosition::EFLineDown);
\r
282 edwin->UpdateScrollBarsL();
\r
283 return EKeyWasConsumed;
\r
285 else if (aKeyEvent.iCode == EQuartzKeyTwoWayUp)
\r
287 edwin->MoveDisplayL(TCursorPosition::EFLineUp);
\r
288 edwin->UpdateScrollBarsL();
\r
289 return EKeyWasConsumed;
\r
292 return CQikSimpleDialog::OfferKeyEventL(aKeyEvent, aType);
\r
295 /*************************************************************
\r
299 **************************************************************/
\r
301 CDebugDialog::CDebugDialog(char *t)
\r
303 Mem::Copy(iText, t, 1024);
\r
307 void CDebugDialog::PreLayoutDynInitL()
\r
309 char *p = iText, *line = iText;
\r
312 CEikEdwin *editor = LocateControlByUniqueHandle<CEikEdwin>(ECtlPicoCreditsText);
\r
315 while(*p && *p != '\r' && *p != '\n') p++;
\r
318 TPtrC8 ptr((TUint8*) line);
\r
320 editor->Text()->InsertL(editor->TextLength(), tbuf);
\r
321 editor->Text()->InsertL(editor->TextLength(), CEditableText::ELineBreak);
\r