Fixed text alignment issues in InputTextDialog.

Some fixes and reformatting for the Cheat code stuff.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@797 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-09-26 19:10:37 +00:00
parent 98387c6c80
commit 0158d919e6
9 changed files with 278 additions and 153 deletions

View File

@ -1,43 +1,74 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: BankRomCheat.cxx,v 1.2 2005-09-26 19:10:37 stephena Exp $
//============================================================================
// FIXME - don't use the debugger for this, since it may not be included
//#include "Debugger.hxx"
#include "BankRomCheat.hxx"
BankRomCheat::BankRomCheat(OSystem *os, string code) {
myOSystem = os;
_enabled = false;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BankRomCheat::BankRomCheat(OSystem *os, string code)
{
myOSystem = os;
_enabled = false;
if(code.length() == 7)
code = "0" + code;
if(code.length() == 7)
code = "0" + code;
bank = unhex(code.substr(0, 2));
address = 0xf000 + unhex(code.substr(2, 3));
value = unhex(code.substr(5, 2));
count = unhex(code.substr(7, 1)) + 1;
bank = unhex(code.substr(0, 2));
address = 0xf000 + unhex(code.substr(2, 3));
value = unhex(code.substr(5, 2));
count = unhex(code.substr(7, 1)) + 1;
}
BankRomCheat::~BankRomCheat() {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BankRomCheat::~BankRomCheat()
{
}
bool BankRomCheat::enabled() { return _enabled; }
bool BankRomCheat::enable() {
int oldBank = myOSystem->console().cartridge().bank();
myOSystem->console().cartridge().bank(bank);
for(int i=0; i<count; i++) {
savedRom[i] = myOSystem->console().cartridge().peek(address + i);
myOSystem->console().cartridge().patch(address + i, value);
}
myOSystem->console().cartridge().bank(oldBank);
return _enabled = true;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool BankRomCheat::enabled()
{
return _enabled;
}
bool BankRomCheat::disable() {
int oldBank = myOSystem->console().cartridge().bank();
myOSystem->console().cartridge().bank(bank);
for(int i=0; i<count; i++) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool BankRomCheat::enable()
{
int oldBank = myOSystem->console().cartridge().bank();
myOSystem->console().cartridge().bank(bank);
for(int i=0; i<count; i++)
{
savedRom[i] = myOSystem->console().cartridge().peek(address + i);
myOSystem->console().cartridge().patch(address + i, value);
}
myOSystem->console().cartridge().bank(oldBank);
return _enabled = true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool BankRomCheat::disable()
{
int oldBank = myOSystem->console().cartridge().bank();
myOSystem->console().cartridge().bank(bank);
for(int i=0; i<count; i++)
myOSystem->console().cartridge().patch(address + i, savedRom[i]);
}
myOSystem->console().cartridge().bank(oldBank);
return _enabled = false;
myOSystem->console().cartridge().bank(oldBank);
return _enabled = false;
}

View File

@ -1,8 +1,26 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Cheat.cxx,v 1.4 2005-09-26 19:10:37 stephena Exp $
//============================================================================
#include "Cheat.hxx"
#include "CheetahCheat.hxx"
#include "BankRomCheat.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt16 Cheat::unhex(string hex) {
int ret = 0;
@ -21,6 +39,7 @@ uInt16 Cheat::unhex(string hex) {
return ret;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cheat* Cheat::parse(OSystem *osystem, string code) {
for(unsigned int i=0; i<code.size(); i++)
if(!isxdigit(code[i]))
@ -38,6 +57,3 @@ Cheat* Cheat::parse(OSystem *osystem, string code) {
return 0;
}
}
Cheat::~Cheat() {
}

View File

@ -1,3 +1,20 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Cheat.hxx,v 1.3 2005-09-26 19:10:37 stephena Exp $
//============================================================================
#ifndef CHEAT_HXX
#define CHEAT_HXX
@ -5,19 +22,21 @@
#include "bspf.hxx"
#include "OSystem.hxx"
class Cheat {
public:
static Cheat *parse(OSystem *osystem, string code);
static uInt16 unhex(string hex);
class Cheat
{
public:
Cheat() { }
virtual ~Cheat() { }
virtual ~Cheat();
static Cheat *parse(OSystem *osystem, string code);
static uInt16 unhex(string hex);
virtual bool enabled() = 0;
virtual bool enable() = 0;
virtual bool disable() = 0;
virtual bool enabled() = 0;
virtual bool enable() = 0;
virtual bool disable() = 0;
protected:
// Cheat(string code);
protected:
//Cheat(string code);
};
#endif

View File

@ -1,33 +1,62 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: CheetahCheat.cxx,v 1.3 2005-09-26 19:10:37 stephena Exp $
//============================================================================
// FIXME - don't use the debugger for this, since it may not be included
//#include "Debugger.hxx"
#include "CheetahCheat.hxx"
CheetahCheat::CheetahCheat(OSystem *os, string code) {
myOSystem = os;
_enabled = false;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CheetahCheat::CheetahCheat(OSystem *os, string code)
{
myOSystem = os;
_enabled = false;
address = 0xf000 + unhex(code.substr(0, 3));
value = unhex(code.substr(3, 2));
count = unhex(code.substr(5, 1)) + 1;
address = 0xf000 + unhex(code.substr(0, 3));
value = unhex(code.substr(3, 2));
count = unhex(code.substr(5, 1)) + 1;
}
CheetahCheat::~CheetahCheat() {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CheetahCheat::~CheetahCheat()
{
}
bool CheetahCheat::enabled() { return _enabled; }
bool CheetahCheat::enable() {
for(int i=0; i<count; i++) {
savedRom[i] = myOSystem->console().cartridge().peek(address + i);
myOSystem->console().cartridge().patch(address + i, value);
}
return _enabled = true;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CheetahCheat::enabled()
{
return _enabled;
}
bool CheetahCheat::disable() {
for(int i=0; i<count; i++) {
myOSystem->console().cartridge().patch(address + i, savedRom[i]);
}
return _enabled = false;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CheetahCheat::enable()
{
for(int i=0; i<count; i++)
{
savedRom[i] = myOSystem->console().cartridge().peek(address + i);
myOSystem->console().cartridge().patch(address + i, value);
}
return _enabled = true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CheetahCheat::disable()
{
for(int i=0; i<count; i++)
myOSystem->console().cartridge().patch(address + i, savedRom[i]);
return _enabled = false;
}

View File

@ -1,3 +1,20 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: CheetahCheat.hxx,v 1.3 2005-09-26 19:10:37 stephena Exp $
//============================================================================
#ifndef CHEETAH_CHEAT_HXX
#define CHEETAH_CHEAT_HXX
@ -5,23 +22,24 @@
#include "OSystem.hxx"
#include "Cheat.hxx"
class CheetahCheat : public Cheat {
public:
CheetahCheat(OSystem *os, string code);
~CheetahCheat();
class CheetahCheat : public Cheat
{
public:
CheetahCheat(OSystem *os, string code);
~CheetahCheat();
virtual bool enabled();
virtual bool enable();
virtual bool disable();
virtual bool enabled();
virtual bool enable();
virtual bool disable();
private:
OSystem* myOSystem;
private:
bool _enabled;
uInt8 savedRom[16];
uInt16 address;
uInt8 value;
uInt8 count;
OSystem *myOSystem;
bool _enabled;
uInt8 savedRom[16];
uInt16 address;
uInt8 value;
uInt8 count;
};
#endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: CheatCodeDialog.cxx,v 1.5 2005-09-25 23:14:00 urchlay Exp $
// $Id: CheatCodeDialog.cxx,v 1.6 2005-09-26 19:10:37 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -28,23 +28,36 @@
#include "bspf.hxx"
/*
enum {
kEnableCheat = 'ENAC',
kLoadCmd = 'LDCH',
kEnableCheat = 'ENAC',
kLoadCmd = 'LDCH'
};
*/
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CheatCodeDialog::CheatCodeDialog(OSystem* osystem, DialogContainer* parent,
int x, int y, int w, int h)
: Dialog(osystem, parent, x, y, w, h)
: Dialog(osystem, parent, x, y, w, h)
{
// const GUI::Font& font = instance()->font();
const GUI::Font& font = instance()->font();
const int fontHeight = font.getFontHeight(),
lwidth = font.getMaxCharWidth() * 8;
int xpos, ypos;
myTitle = new StaticTextWidget(this, 10, 5, w - 20, kFontHeight, "Cheat Code", kTextAlignLeft);
myError = new StaticTextWidget(this, 10, 5 + kFontHeight + 2, w - 20, kFontHeight, "Invalid Code", kTextAlignLeft);
myError->setFlags(WIDGET_INVISIBLE);
myInput = new EditTextWidget(this, 80, 5, 48, kFontHeight, "");
xpos = 10; ypos = 10;
myTitle = new StaticTextWidget(this, xpos, ypos, lwidth, fontHeight,
"Cheat Code", kTextAlignLeft);
xpos += myTitle->getWidth();
myInput = new EditTextWidget(this, xpos, ypos-1, 48, fontHeight, "");
addFocusWidget(myInput);
xpos = 10; ypos += fontHeight + 5;
myError = new StaticTextWidget(this, xpos, ypos, lwidth, kFontHeight,
"", kTextAlignLeft);
myError->setColor(kTextColorEm);
// addButton(w - (kButtonWidth + 10), 5, "Close", kCloseCmd, 'C');
}
@ -54,54 +67,53 @@ CheatCodeDialog::~CheatCodeDialog()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheatCodeDialog::handleCommand(CommandSender* sender, int cmd,
int data, int id)
void CheatCodeDialog::loadConfig()
{
switch(cmd)
{
case kEditAcceptCmd:
// cerr << myInput->getEditString() << endl;
myCheat = Cheat::parse(instance(), myInput->getEditString());
if(myCheat) {
// make sure "invalid code" isn't showing any more:
myError->setFlags(WIDGET_INVISIBLE);
myError->setDirty();
myError->draw();
// set up the cheat
myCheat->enable();
delete myCheat; // TODO: keep and add to list
// get out of menu mode (back to emulation):
Dialog::handleCommand(sender, kCloseCmd, data, id);
instance()->eventHandler().leaveMenuMode();
} else { // parse() returned 0 (null)
// cerr << "bad cheat code" << endl;
// show error message "invalid code":
myInput->setEditString("");
myError->clearFlags(WIDGET_INVISIBLE);
myError->setDirty();
myError->draw();
// not sure this does anything useful:
Dialog::handleCommand(sender, cmd, data, 0);
}
break;
case kEditCancelCmd:
Dialog::handleCommand(sender, kCloseCmd, data, id);
instance()->eventHandler().leaveMenuMode();
break;
default:
Dialog::handleCommand(sender, cmd, data, 0);
break;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheatCodeDialog::loadConfig() {
void CheatCodeDialog::handleCommand(CommandSender* sender, int cmd,
int data, int id)
{
switch(cmd)
{
case kEditAcceptCmd:
// cerr << myInput->getEditString() << endl;
myCheat = Cheat::parse(instance(), myInput->getEditString());
if(myCheat)
{
// make sure "invalid code" isn't showing any more:
myError->setLabel("");
// set up the cheat
myCheat->enable();
delete myCheat; // TODO: keep and add to list
// get out of menu mode (back to emulation):
Dialog::handleCommand(sender, kCloseCmd, data, id);
instance()->eventHandler().leaveMenuMode();
}
else // parse() returned 0 (null)
{
// cerr << "bad cheat code" << endl;
// show error message "invalid code":
myInput->setEditString("");
myError->setLabel("Invalid Code");
// not sure this does anything useful:
Dialog::handleCommand(sender, cmd, data, 0);
}
break;
case kEditCancelCmd:
Dialog::handleCommand(sender, kCloseCmd, data, id);
instance()->eventHandler().leaveMenuMode();
break;
default:
Dialog::handleCommand(sender, cmd, data, 0);
break;
}
}

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: CheatCodeDialog.hxx,v 1.2 2005-09-25 18:35:26 urchlay Exp $
// $Id: CheatCodeDialog.hxx,v 1.3 2005-09-26 19:10:37 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -42,18 +42,18 @@ class CheatCodeDialog : public Dialog
int x, int y, int w, int h);
~CheatCodeDialog();
protected:
ButtonWidget *myExitButton;
StaticTextWidget *myTitle;
StaticTextWidget *myError;
// CheckboxWidget *myEnableCheat;
virtual void handleCommand(CommandSender* sender, int cmd, int data, int id);
void loadConfig();
private:
virtual void handleCommand(CommandSender* sender, int cmd, int data, int id);
void loadConfig();
Cheat *myCheat;
EditTextWidget *myInput;
Cheat* myCheat;
ButtonWidget* myExitButton;
StaticTextWidget* myTitle;
StaticTextWidget* myError;
EditTextWidget* myInput;
// CheckboxWidget* myEnableCheat;
};
#endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: InputTextDialog.cxx,v 1.4 2005-08-11 19:12:39 stephena Exp $
// $Id: InputTextDialog.cxx,v 1.5 2005-09-26 19:10:37 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -46,7 +46,7 @@ InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font,
// Calculate real dimensions
_w = fontWidth * 30;
_h = lineHeight * 6;
_h = lineHeight * 5;
xpos = 10; ypos = lineHeight;
int lwidth = font.getStringWidth("Enter Data:");
@ -62,9 +62,11 @@ InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font,
_input->setFont(font);
addFocusWidget(_input);
xpos = 10; ypos = 2*lineHeight;
xpos = 10; ypos = 2*lineHeight + 5;
_title = new StaticTextWidget(this, xpos, ypos, _w - 2*xpos, fontHeight,
"", kTextAlignCenter);
_title->setFont(font);
_title->setColor(kTextColorEm);
#ifndef MAC_OSX
addButton(_w - 2 * (kButtonWidth + 10), _h - 24, "OK", kAcceptCmd, 0);

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: OptionsDialog.cxx,v 1.28 2005-09-25 23:14:00 urchlay Exp $
// $Id: OptionsDialog.cxx,v 1.29 2005-09-26 19:10:37 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -71,19 +71,17 @@ OptionsDialog::OptionsDialog(OSystem* osystem, DialogContainer* parent)
{
int yoffset = 7;
const int xoffset = (_w - kBigButtonWidth) / 2;
ButtonWidget* b = NULL;
addBigButton("Video Settings", kVidCmd, 0);
#ifdef SOUND_SUPPORT
addBigButton("Audio Settings", kAudCmd, 0);
#else
b = addBigButton("Audio Settings", kAudCmd, 0);
ButtonWidget* b = addBigButton("Audio Settings", kAudCmd, 0);
b->clearFlags(WIDGET_ENABLED);
#endif
addBigButton("Event Mapping", kEMapCmd, 0);
addBigButton("Game Information", kInfoCmd, 0);
b = addBigButton("Cheat Code", kCheatCmd, 0);
// b->clearFlags(WIDGET_ENABLED); // TODO - finish after next release
addBigButton("Cheat Code", kCheatCmd, 0);
addBigButton("Help", kHelpCmd, 0);
addBigButton("About", kAboutCmd, 0);
addBigButton("Exit Menu", kExitCmd, 0);
@ -110,7 +108,7 @@ OptionsDialog::OptionsDialog(OSystem* osystem, DialogContainer* parent)
checkBounds(fbWidth, fbHeight, &x, &y, &w, &h);
myGameInfoDialog = new GameInfoDialog(myOSystem, parent, x, y, w, h);
w = 140; h = 35;
w = 140; h = 40;
checkBounds(fbWidth, fbHeight, &x, &y, &w, &h);
myCheatCodeDialog = new CheatCodeDialog(myOSystem, parent, x, y, w, h);