diff --git a/stella/src/debugger/CheatWidget.cxx b/stella/src/debugger/CheatWidget.cxx index 7b86136e9..b3d419a57 100644 --- a/stella/src/debugger/CheatWidget.cxx +++ b/stella/src/debugger/CheatWidget.cxx @@ -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: CheatWidget.cxx,v 1.1 2005-08-01 22:33:12 stephena Exp $ +// $Id: CheatWidget.cxx,v 1.2 2005-08-04 16:31:23 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -29,19 +29,23 @@ #include "Widget.hxx" #include "EditNumWidget.hxx" #include "AddrValueWidget.hxx" +#include "InputTextDialog.hxx" #include "CheatWidget.hxx" enum { - kSearchCmd = 'CSEA', - kCmpCmd = 'CCMP', - kRestartCmd = 'CRST' + kSearchCmd = 'CSEA', + kCmpCmd = 'CCMP', + kRestartCmd = 'CRST', + kSValEntered = 'CSVE', + kCValEntered = 'CCVE' }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CheatWidget::CheatWidget(GuiObject* boss, int x, int y, int w, int h) : Widget(boss, x, y, w, h), - CommandSender(boss) + CommandSender(boss), + myInputBox(NULL) { const int border = 20; const int bwidth = 50; @@ -91,6 +95,9 @@ CheatWidget::CheatWidget(GuiObject* boss, int x, int y, int w, int h) myResultsList = new AddrValueWidget(boss, xpos, ypos, 100, 75, 0xff); myResultsList->setFont(instance()->consoleFont()); myResultsList->setTarget(this); + + myInputBox = new InputTextDialog(boss, instance()->consoleFont()); + myInputBox->setTarget(this); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -98,6 +105,8 @@ CheatWidget::~CheatWidget() { mySearchArray.clear(); myCompareArray.clear(); + + delete myInputBox; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -106,17 +115,43 @@ void CheatWidget::handleCommand(CommandSender* sender, int cmd, int data, int id switch(cmd) { case kSearchCmd: - doSearch(); + myInputBox->setEditString(""); + myInputBox->setTitle(""); + myInputBox->setEmitSignal(kSValEntered); + parent()->addDialog(myInputBox); break; case kCmpCmd: - doCompare(); + myInputBox->setEditString(""); + myInputBox->setTitle(""); + myInputBox->setEmitSignal(kCValEntered); + parent()->addDialog(myInputBox); break; case kRestartCmd: doRestart(); break; + case kSValEntered: + { + const string& result = doSearch(myInputBox->getResult()); + if(result != "") + myInputBox->setTitle(result); + else + parent()->removeDialog(); + break; + } + + case kCValEntered: + { + const string& result = doCompare(myInputBox->getResult()); + if(result != "") + myInputBox->setTitle(result); + else + parent()->removeDialog(); + break; + } + case kAVItemDataChangedCmd: int addr = myResultsList->getSelectedAddr() - kRamStart; int value = myResultsList->getSelectedValue(); @@ -126,11 +161,10 @@ void CheatWidget::handleCommand(CommandSender* sender, int cmd, int data, int id } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheatWidget::doSearch() +const string CheatWidget::doSearch(const string& str) { bool comparisonSearch = true; - string str = myEditBox->getEditString(); if(str.length() == 0) { // An empty field means return all memory locations @@ -139,8 +173,7 @@ void CheatWidget::doSearch() else if(str.find_first_of("+-", 0) != string::npos) { // Don't accept these characters here, only in compare - myResult->setLabel("Invalid input +|-"); - return; + return "Invalid input +|-"; } int searchVal = instance()->debugger().stringToValue(str); @@ -190,28 +223,25 @@ void CheatWidget::doSearch() // Finally, show the search results in the list fillResultsList(); + + return ""; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheatWidget::doCompare() +const string CheatWidget::doCompare(const string& str) { bool comparitiveSearch = false; int searchVal = 0; - string str = myEditBox->getEditString(); if(str.length() == 0) - { - myResult->setLabel("Enter an absolute or comparitive value"); - return; - } + return "Enter an absolute or comparitive value"; // Do some pre-processing on the string string::size_type pos = str.find_first_of("+-", 0); if(pos > 0 && pos != string::npos) { // Only accept '+' or '-' at the start of the string - myResult->setLabel("Input must be [+|-]NUM"); - return; + return "Input must be [+|-]NUM"; } if(str[0] == '+' || str[0] == '-') @@ -220,8 +250,9 @@ void CheatWidget::doCompare() if(str[0] == '-') negative = true; - str.erase(0, 1); // remove the operator - searchVal = instance()->debugger().stringToValue(str); + string tmp = str; + tmp.erase(0, 1); // remove the operator + searchVal = instance()->debugger().stringToValue(tmp); if(negative) searchVal = -searchVal; @@ -276,6 +307,8 @@ void CheatWidget::doCompare() // Finally, show the search results in the list fillResultsList(); + + return ""; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/debugger/CheatWidget.hxx b/stella/src/debugger/CheatWidget.hxx index cbbbb8ddb..39d9ee4c7 100644 --- a/stella/src/debugger/CheatWidget.hxx +++ b/stella/src/debugger/CheatWidget.hxx @@ -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: CheatWidget.hxx,v 1.1 2005-08-01 22:33:12 stephena Exp $ +// $Id: CheatWidget.hxx,v 1.2 2005-08-04 16:31:24 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -27,6 +27,7 @@ class ButtonWidget; class StaticTextWidget; class EditNumWidget; class AddrValueWidget; +class InputTextDialog; #include "Array.hxx" #include "Widget.hxx" @@ -55,8 +56,8 @@ class CheatWidget : public Widget, public CommandSender void handleCommand(CommandSender* sender, int cmd, int data, int id); private: - void doSearch(); - void doCompare(); + const string doSearch(const string& str); + const string doCompare(const string& str); void doRestart(); void fillResultsList(); @@ -72,6 +73,8 @@ class CheatWidget : public Widget, public CommandSender ButtonWidget* myRestartButton; AddrValueWidget* myResultsList; + + InputTextDialog* myInputBox; }; #endif diff --git a/stella/src/gui/EditableWidget.cxx b/stella/src/gui/EditableWidget.cxx index bbade8028..f47a8954d 100644 --- a/stella/src/gui/EditableWidget.cxx +++ b/stella/src/gui/EditableWidget.cxx @@ -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: EditableWidget.cxx,v 1.8 2005-08-01 22:33:15 stephena Exp $ +// $Id: EditableWidget.cxx,v 1.9 2005-08-04 16:31:24 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -173,7 +173,7 @@ void EditableWidget::drawCaret() x += getCaretOffset(); - x += getAbsX(); + x += _x; y += _y; FrameBuffer& fb = _boss->instance()->frameBuffer(); diff --git a/stella/src/gui/InputTextDialog.cxx b/stella/src/gui/InputTextDialog.cxx new file mode 100644 index 000000000..cc432334f --- /dev/null +++ b/stella/src/gui/InputTextDialog.cxx @@ -0,0 +1,101 @@ +//============================================================================ +// +// 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: InputTextDialog.cxx,v 1.1 2005-08-04 16:31:24 stephena Exp $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#include "OSystem.hxx" +#include "Widget.hxx" +#include "EditNumWidget.hxx" +#include "Dialog.hxx" +#include "GuiObject.hxx" +#include "GuiUtils.hxx" +#include "InputTextDialog.hxx" + +#include "bspf.hxx" + +enum { + kAcceptCmd = 'ACPT' +}; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font) + : Dialog(boss->instance(), boss->parent(), 0, 0, 16, 16), + CommandSender(boss) +{ + const int fontWidth = font.getMaxCharWidth(), + fontHeight = font.getFontHeight(), + lineHeight = font.getLineHeight(); + int xpos, ypos; + + // Calculate real dimensions + _w = fontWidth * 30; + _h = lineHeight * 6; +// FIXME + _x = 100;//(boss->getAbsX() - _w) / 2; + _y = 400;//(boss->getAbsY() - _h) / 2; + + xpos = 10; ypos = lineHeight; + int lwidth = font.getStringWidth("Enter Data:"); + StaticTextWidget* t = + new StaticTextWidget(this, xpos, ypos, + lwidth, fontHeight, + "Enter Data:", kTextAlignLeft); + t->setFont(font); + + xpos += lwidth + fontWidth; + _input = new EditNumWidget(this, xpos, ypos, + _w - xpos - 10, lineHeight, ""); + _input->setFont(font); + _input->clearFlags(WIDGET_TAB_NAVIGATE); + + xpos = 10; ypos = 2*lineHeight; + _title = new StaticTextWidget(this, xpos, ypos, _w - 2*xpos, fontHeight, + "", kTextAlignCenter); + +#ifndef MAC_OSX + addButton(_w - 2 * (kButtonWidth + 10), _h - 24, "OK", kAcceptCmd, 0); + addButton(_w - (kButtonWidth+10), _h - 24, "Cancel", kCloseCmd, 0); +#else + addButton(_w - 2 * (kButtonWidth + 10), _h - 24, "Cancel", kCloseCmd, 0); + addButton(_w - (kButtonWidth+10), _h - 24, "OK", kAcceptCmd, 0); +#endif +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void InputTextDialog::handleCommand(CommandSender* sender, int cmd, + int data, int id) +{ + switch (cmd) + { + case kAcceptCmd: + { + // Send a signal to the calling class that a selection has been made + // Since we aren't derived from a widget, we don't have a 'data' or 'id' + if(_cmd) + sendCommand(_cmd, 0, 0); + + // We don't close, but leave the parent to do it + // If the data isn't valid, the parent may wait until it is + break; + } + default: + Dialog::handleCommand(sender, cmd, data, 0); + break; + } +} diff --git a/stella/src/gui/InputTextDialog.hxx b/stella/src/gui/InputTextDialog.hxx new file mode 100644 index 000000000..e96e68810 --- /dev/null +++ b/stella/src/gui/InputTextDialog.hxx @@ -0,0 +1,54 @@ +//============================================================================ +// +// 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: InputTextDialog.hxx,v 1.1 2005-08-04 16:31:24 stephena Exp $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#ifndef INPUT_TEXT_DIALOG_HXX +#define INPUT_TEXT_DIALOG_HXX + +class GuiObject; +class StaticTextWidget; +class EditNumWidget; + +#include "Dialog.hxx" +#include "Command.hxx" +#include "bspf.hxx" + +class InputTextDialog : public Dialog, public CommandSender +{ + public: + InputTextDialog(GuiObject* boss, const GUI::Font& font); + + const string& getResult() { return _input->getEditString(); } + + void setEditString(const string& str) { _input->setEditString(str); } + void setTitle(const string& title) { _title->setLabel(title); } + void setEmitSignal(int cmd) { _cmd = cmd; } + + protected: + virtual void handleCommand(CommandSender* sender, int cmd, int data, int id); + + private: + StaticTextWidget* _title; + EditNumWidget* _input; + + int _cmd; +}; + +#endif diff --git a/stella/src/gui/module.mk b/stella/src/gui/module.mk index 66879c08f..67b4fea37 100644 --- a/stella/src/gui/module.mk +++ b/stella/src/gui/module.mk @@ -18,6 +18,7 @@ MODULE_OBJS := \ src/gui/GameInfoDialog.o \ src/gui/GameList.o \ src/gui/HelpDialog.o \ + src/gui/InputTextDialog.o \ src/gui/Launcher.o \ src/gui/LauncherDialog.o \ src/gui/LauncherOptionsDialog.o \