mirror of https://github.com/stella-emu/stella.git
Implemented "Save ROM" functionality in context menu of RomWidget.
Modified InputTextDialog so that any error messages disappear once new data is entered. Fixed bug with ContextMenu where showing a dialog box (from the CMenu) didn't work properly. Removed redundant EditNumWidget class. It's functionality will be handled by EditTextWidget eventually, when we add more comprehensive error checking on input. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@814 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
225049893a
commit
b7d13671cd
|
@ -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: Debugger.cxx,v 1.95 2005-09-23 23:35:02 stephena Exp $
|
||||
// $Id: Debugger.cxx,v 1.96 2005-10-06 17:28:54 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include "bspf.hxx"
|
||||
|
@ -1110,7 +1110,8 @@ const string Debugger::builtinHelp() {
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool Debugger::saveROM(string filename) {
|
||||
bool Debugger::saveROM(string filename)
|
||||
{
|
||||
// TODO: error checking
|
||||
ofstream *out = new ofstream(filename.c_str(), ios::out | ios::binary);
|
||||
bool res = myConsole->cartridge().save(*out);
|
||||
|
|
|
@ -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: DebuggerParser.cxx,v 1.83 2005-10-02 01:15:53 stephena Exp $
|
||||
// $Id: DebuggerParser.cxx,v 1.84 2005-10-06 17:28:54 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include "bspf.hxx"
|
||||
|
@ -1673,7 +1673,7 @@ void DebuggerParser::executeSave() {
|
|||
// "saverom"
|
||||
void DebuggerParser::executeSaverom() {
|
||||
if(debugger->saveROM(argStrings[0]))
|
||||
commandResult = "saved ROM";
|
||||
commandResult = "saved ROM as " + argStrings[0];
|
||||
else
|
||||
commandResult = red("failed to save ROM");
|
||||
}
|
||||
|
|
|
@ -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: ContextMenu.cxx,v 1.3 2005-09-23 23:35:02 stephena Exp $
|
||||
// $Id: ContextMenu.cxx,v 1.4 2005-10-06 17:28:55 stephena Exp $
|
||||
//
|
||||
// Based on code from ScummVM - Scumm Interpreter
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
|
@ -157,10 +157,10 @@ void ContextMenu::setSelection(int item)
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void ContextMenu::sendSelection()
|
||||
{
|
||||
sendCommand(kCMenuItemSelectedCmd, _selectedItem, -1);
|
||||
|
||||
// We remove the dialog when the user has selected an item
|
||||
parent()->removeDialog();
|
||||
|
||||
sendCommand(kCMenuItemSelectedCmd, _selectedItem, -1);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -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: RomWidget.cxx,v 1.7 2005-09-23 23:35:02 stephena Exp $
|
||||
// $Id: RomWidget.cxx,v 1.8 2005-10-06 17:28:55 stephena Exp $
|
||||
//
|
||||
// Based on code from ScummVM - Scumm Interpreter
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
|
@ -26,10 +26,15 @@
|
|||
#include "CpuDebug.hxx"
|
||||
#include "PackedBitArray.hxx"
|
||||
#include "GuiObject.hxx"
|
||||
#include "InputTextDialog.hxx"
|
||||
#include "ContextMenu.hxx"
|
||||
#include "RomListWidget.hxx"
|
||||
#include "RomWidget.hxx"
|
||||
|
||||
enum {
|
||||
kRomNameEntered = 'RWrn'
|
||||
};
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
RomWidget::RomWidget(GuiObject* boss, const GUI::Font& font, int x, int y)
|
||||
: Widget(boss, x, y, 16, 16),
|
||||
|
@ -50,6 +55,10 @@ RomWidget::RomWidget(GuiObject* boss, const GUI::Font& font, int x, int y)
|
|||
// Calculate real dimensions
|
||||
_w = myRomList->getWidth();
|
||||
_h = myRomList->getHeight();
|
||||
|
||||
// Create dialog box for save ROM (get name)
|
||||
mySaveRom = new InputTextDialog(boss, font, _x + 50, _y + 80);
|
||||
mySaveRom->setTarget(this);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -81,12 +90,29 @@ void RomWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
|
|||
const string& rmb = myRomList->myMenu->getSelectedString();
|
||||
|
||||
if(rmb == "Save ROM")
|
||||
saveROM();
|
||||
{
|
||||
mySaveRom->setTitle("");
|
||||
mySaveRom->setEmitSignal(kRomNameEntered);
|
||||
parent()->addDialog(mySaveRom);
|
||||
}
|
||||
else if(rmb == "Set PC")
|
||||
setPC(myRomList->getSelected());
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case kRomNameEntered:
|
||||
{
|
||||
const string& rom = mySaveRom->getResult();
|
||||
if(rom == "")
|
||||
mySaveRom->setTitle("Invalid name");
|
||||
else
|
||||
{
|
||||
saveROM(rom);
|
||||
parent()->removeDialog();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,7 +219,9 @@ void RomWidget::patchROM(int data, const string& bytes)
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void RomWidget::saveROM()
|
||||
void RomWidget::saveROM(const string& rom)
|
||||
{
|
||||
cerr << "save ROM\n";
|
||||
ostringstream command;
|
||||
command << "saverom " << rom;
|
||||
instance()->debugger().run(command.str());
|
||||
}
|
||||
|
|
|
@ -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: RomWidget.hxx,v 1.5 2005-09-23 17:38:27 stephena Exp $
|
||||
// $Id: RomWidget.hxx,v 1.6 2005-10-06 17:28:55 stephena Exp $
|
||||
//
|
||||
// Based on code from ScummVM - Scumm Interpreter
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
|
@ -23,6 +23,7 @@
|
|||
#define ROM_WIDGET_HXX
|
||||
|
||||
class GuiObject;
|
||||
class InputTextDialog;
|
||||
class RomListWidget;
|
||||
class StringList;
|
||||
|
||||
|
@ -53,7 +54,7 @@ class RomWidget : public Widget, public CommandSender
|
|||
void setBreak(int data);
|
||||
void setPC(int data);
|
||||
void patchROM(int data, const string& bytes);
|
||||
void saveROM();
|
||||
void saveROM(const string& rom);
|
||||
|
||||
private:
|
||||
RomListWidget* myRomList;
|
||||
|
@ -64,6 +65,8 @@ class RomWidget : public Widget, public CommandSender
|
|||
/** List of line numbers indexed by address */
|
||||
AddrToLine myLineList;
|
||||
|
||||
InputTextDialog* mySaveRom;
|
||||
|
||||
bool myListIsDirty;
|
||||
bool mySourceAvailable;
|
||||
int myCurrentBank;
|
||||
|
|
|
@ -1,129 +0,0 @@
|
|||
//============================================================================
|
||||
//
|
||||
// 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: EditNumWidget.cxx,v 1.8 2005-08-10 12:23:42 stephena Exp $
|
||||
//
|
||||
// Based on code from ScummVM - Scumm Interpreter
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
//============================================================================
|
||||
|
||||
#include "OSystem.hxx"
|
||||
#include "FrameBuffer.hxx"
|
||||
#include "Dialog.hxx"
|
||||
#include "EditNumWidget.hxx"
|
||||
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
EditNumWidget::EditNumWidget(GuiObject* boss, int x, int y, int w, int h,
|
||||
const string& text)
|
||||
: EditableWidget(boss, x, y, w, h)
|
||||
{
|
||||
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS;
|
||||
_type = kEditTextWidget;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EditNumWidget::setEditString(const string& str)
|
||||
{
|
||||
EditableWidget::setEditString(str);
|
||||
_backupString = str;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool EditNumWidget::tryInsertChar(char c, int pos)
|
||||
{
|
||||
// Not sure how efficient this is, or should we even care?
|
||||
c = tolower(c);
|
||||
if((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
|
||||
c == '%' || c == '#' || c == '$' || c == '+' || c == '-')
|
||||
{
|
||||
_editString.insert(pos, 1, c);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EditNumWidget::handleMouseDown(int x, int y, int button, int clickCount)
|
||||
{
|
||||
x += _editScrollOffset;
|
||||
|
||||
int width = 0;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < _editString.size(); ++i)
|
||||
{
|
||||
width += _font->getCharWidth(_editString[i]);
|
||||
if (width >= x)
|
||||
break;
|
||||
}
|
||||
|
||||
setCaretPos(i);
|
||||
setDirty(); draw();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EditNumWidget::drawWidget(bool hilite)
|
||||
{
|
||||
cerr << "EditNumWidget::drawWidget\n";
|
||||
FrameBuffer& fb = _boss->instance()->frameBuffer();
|
||||
|
||||
// Draw a thin frame around us.
|
||||
fb.hLine(_x, _y, _x + _w - 1, kColor);
|
||||
fb.hLine(_x, _y + _h - 1, _x +_w - 1, kShadowColor);
|
||||
fb.vLine(_x, _y, _y + _h - 1, kColor);
|
||||
fb.vLine(_x + _w - 1, _y, _y + _h - 1, kShadowColor);
|
||||
|
||||
// Draw the text
|
||||
adjustOffset();
|
||||
fb.drawString(_font, _editString, _x + 2, _y + 2, getEditRect().width(),
|
||||
kTextColor, kTextAlignLeft, -_editScrollOffset, false);
|
||||
|
||||
// Draw the caret
|
||||
drawCaret();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
GUI::Rect EditNumWidget::getEditRect() const
|
||||
{
|
||||
GUI::Rect r(2, 0, _w - 2, _h - 1);
|
||||
return r;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EditNumWidget::lostFocusWidget()
|
||||
{
|
||||
// If we loose focus, 'commit' the user changes
|
||||
_backupString = _editString;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EditNumWidget::startEditMode()
|
||||
{
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EditNumWidget::endEditMode()
|
||||
{
|
||||
releaseFocus();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EditNumWidget::abortEditMode()
|
||||
{
|
||||
setEditString(_backupString);
|
||||
releaseFocus();
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
//============================================================================
|
||||
//
|
||||
// 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: EditNumWidget.hxx,v 1.3 2005-06-30 00:08:01 stephena Exp $
|
||||
//
|
||||
// Based on code from ScummVM - Scumm Interpreter
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
//============================================================================
|
||||
|
||||
#ifndef EDIT_NUM_WIDGET_HXX
|
||||
#define EDIT_NUM_WIDGET_HXX
|
||||
|
||||
#include "Rect.hxx"
|
||||
#include "EditableWidget.hxx"
|
||||
|
||||
|
||||
/* EditNumWidget */
|
||||
class EditNumWidget : public EditableWidget
|
||||
{
|
||||
public:
|
||||
EditNumWidget(GuiObject* boss, int x, int y, int w, int h, const string& text);
|
||||
|
||||
void setEditString(const string& str);
|
||||
|
||||
virtual void handleMouseDown(int x, int y, int button, int clickCount);
|
||||
|
||||
protected:
|
||||
void drawWidget(bool hilite);
|
||||
void lostFocusWidget();
|
||||
|
||||
void startEditMode();
|
||||
void endEditMode();
|
||||
void abortEditMode();
|
||||
|
||||
bool tryInsertChar(char c, int pos);
|
||||
|
||||
GUI::Rect getEditRect() const;
|
||||
|
||||
protected:
|
||||
string _backupString;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -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.5 2005-09-26 19:10:37 stephena Exp $
|
||||
// $Id: InputTextDialog.cxx,v 1.6 2005-10-06 17:28:55 stephena Exp $
|
||||
//
|
||||
// Based on code from ScummVM - Scumm Interpreter
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
|
@ -37,7 +37,8 @@ enum {
|
|||
InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font,
|
||||
int x, int y)
|
||||
: Dialog(boss->instance(), boss->parent(), x, y, 16, 16),
|
||||
CommandSender(boss)
|
||||
CommandSender(boss),
|
||||
_errorFlag(false)
|
||||
{
|
||||
const int fontWidth = font.getMaxCharWidth(),
|
||||
fontHeight = font.getFontHeight(),
|
||||
|
@ -77,6 +78,13 @@ InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font,
|
|||
#endif
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void InputTextDialog::setTitle(const string& title)
|
||||
{
|
||||
_title->setLabel(title);
|
||||
_errorFlag = true;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void InputTextDialog::handleCommand(CommandSender* sender, int cmd,
|
||||
int data, int id)
|
||||
|
@ -96,10 +104,20 @@ void InputTextDialog::handleCommand(CommandSender* sender, int cmd,
|
|||
break;
|
||||
}
|
||||
|
||||
case kEditChangedCmd:
|
||||
// Erase the invalid message once editing is restarted
|
||||
if(_errorFlag)
|
||||
{
|
||||
_title->setLabel("");
|
||||
_errorFlag = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case kEditCancelCmd:
|
||||
Dialog::handleCommand(sender, kCloseCmd, data, id);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
Dialog::handleCommand(sender, cmd, data, id);
|
||||
break;
|
||||
|
|
|
@ -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.hxx,v 1.2 2005-08-11 19:12:39 stephena Exp $
|
||||
// $Id: InputTextDialog.hxx,v 1.3 2005-10-06 17:28:55 stephena Exp $
|
||||
//
|
||||
// Based on code from ScummVM - Scumm Interpreter
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
|
@ -37,8 +37,8 @@ class InputTextDialog : public Dialog, public CommandSender
|
|||
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; }
|
||||
void setTitle(const string& title);
|
||||
|
||||
protected:
|
||||
virtual void handleCommand(CommandSender* sender, int cmd, int data, int id);
|
||||
|
@ -48,6 +48,7 @@ class InputTextDialog : public Dialog, public CommandSender
|
|||
EditTextWidget* _input;
|
||||
|
||||
int _cmd;
|
||||
bool _errorFlag;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue