Partial fixes for InputTextDialog issues in the debugger. They now appear

onscreen, and don't cause a segfault, but there's still a positioning
problem when toggling fullscreen/windowed modes and when the base surface
has 'unusable' area (ie, an 800x600 window centered in a 1024x768 screen).


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1540 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2008-06-19 19:15:44 +00:00
parent 2e2867cb6e
commit 604217009c
12 changed files with 139 additions and 114 deletions

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.18 2008-06-13 13:14:50 stephena Exp $
// $Id: CheatCodeDialog.cxx,v 1.19 2008-06-19 19:15:44 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -66,29 +66,15 @@ CheatCodeDialog::CheatCodeDialog(OSystem* osystem, DialogContainer* parent,
StringList labels;
labels.push_back("Name: ");
labels.push_back("Code: ");
myCheatInput = new InputTextDialog(this, font, labels, 0, 0);
myCheatInput = new InputTextDialog(this, font, labels);
myCheatInput->setTarget(this);
// Add OK and Cancel buttons
#ifndef MAC_OSX
b = addButton(font, _w - 2 * (kButtonWidth + 7), _h - 24, "OK", kOKCmd);
wid.push_back(b);
addOKWidget(b);
myCancelButton = addButton(font, _w - (kButtonWidth + 10), _h - 24,
"Cancel", kCloseCmd);
wid.push_back(myCancelButton);
addCancelWidget(myCancelButton);
#else
myCancelButton = addButton(font, _w - 2 * (kButtonWidth + 7), _h - 24,
"Cancel", kCloseCmd);
wid.push_back(myCancelButton);
addCancelWidget(myCancelButton);
b = addButton(font, _w - (kButtonWidth + 10), _h - 24, "OK", kOKCmd);
wid.push_back(b);
addOKWidget(b);
#endif
addToFocusList(wid);
// Add OK and Cancel buttons
wid.clear();
addOKCancelBGroup(wid, font);
addBGroupToFocusList(wid);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -138,9 +124,12 @@ void CheatCodeDialog::saveConfig()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheatCodeDialog::addCheat()
{
// We have to add the dialog first, so it can be centered
// The methods after this depend on the dialog having the correct dimensions
parent().addDialog(myCheatInput);
// Center input dialog over entire screen
const GUI::Rect& screen = instance().frameBuffer().screenRect();
uInt32 x = (screen.width() - myCheatInput->getWidth()) >> 1;
uInt32 y = (screen.height() - myCheatInput->getHeight()) >> 1;
myCheatInput->show(x, y);
myCheatInput->setEditString("", 0);
myCheatInput->setEditString("", 1);
myCheatInput->setTitle("");
@ -159,9 +148,12 @@ void CheatCodeDialog::editCheat()
const string& name = list[idx]->name();
const string& code = list[idx]->code();
// We have to add the dialog first, so it can be centered
// The methods after this depend on the dialog having the correct dimensions
parent().addDialog(myCheatInput);
// Center input dialog over entire screen
const GUI::Rect& screen = instance().frameBuffer().screenRect();
uInt32 x = (screen.width() - myCheatInput->getWidth()) >> 1;
uInt32 y = (screen.height() - myCheatInput->getHeight()) >> 1;
myCheatInput->show(x, y);
myCheatInput->setEditString(name, 0);
myCheatInput->setEditString(code, 1);
myCheatInput->setTitle("");
@ -179,9 +171,12 @@ void CheatCodeDialog::removeCheat()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheatCodeDialog::addOneShotCheat()
{
// We have to add the dialog first, so it can be centered
// The methods after this depend on the dialog having the correct dimensions
parent().addDialog(myCheatInput);
// Center input dialog over entire screen
const GUI::Rect& screen = instance().frameBuffer().screenRect();
uInt32 x = (screen.width() - myCheatInput->getWidth()) >> 1;
uInt32 y = (screen.height() - myCheatInput->getHeight()) >> 1;
myCheatInput->show(x, y);
myCheatInput->setEditString("One-shot cheat", 0);
myCheatInput->setEditString("", 1);
myCheatInput->setTitle("");
@ -225,7 +220,6 @@ void CheatCodeDialog::handleCommand(CommandSender* sender, int cmd,
instance().cheat().add(name, code);
parent().removeDialog();
loadConfig(); // show changes onscreen
myCancelButton->setEnabled(false); // cannot cancel when a new cheat added
}
else
myCheatInput->setTitle("Invalid code");
@ -243,7 +237,6 @@ void CheatCodeDialog::handleCommand(CommandSender* sender, int cmd,
instance().cheat().add(name, code, enable, idx);
parent().removeDialog();
loadConfig(); // show changes onscreen
myCancelButton->setEnabled(false); // cannot cancel when a new cheat added
}
else
myCheatInput->setTitle("Invalid code");

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.9 2008-02-06 13:45:19 stephena Exp $
// $Id: CheatCodeDialog.hxx,v 1.10 2008-06-19 19:15:44 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -62,7 +62,6 @@ class CheatCodeDialog : public Dialog
ButtonWidget* myEditButton;
ButtonWidget* myRemoveButton;
ButtonWidget* myCancelButton;
enum {
kAddCheatCmd = 'CHTa',

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: RamWidget.cxx,v 1.18 2008-06-13 13:14:50 stephena Exp $
// $Id: RamWidget.cxx,v 1.19 2008-06-19 19:15:44 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -129,12 +129,10 @@ RamWidget::RamWidget(GuiObject* boss, const GUI::Font& font, int x, int y)
_h = ypos + lineHeight - y;
// Inputbox which will pop up when searching RAM
StringList label;
label.push_back("Search: ");
myInputBox = new InputTextDialog(boss, font, label,
x + lwidth + 20, y + 2*lineHeight - 5);
StringList labels;
labels.push_back("Search: ");
myInputBox = new InputTextDialog(boss, font, labels);
myInputBox->setTarget(this);
myInputBox->setCenter(false);
// Start with these buttons disabled
myCompareButton->clearFlags(WIDGET_ENABLED);
@ -196,17 +194,11 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
break;
case kSearchCmd:
parent().addDialog(myInputBox);
myInputBox->setEditString("");
myInputBox->setTitle("");
myInputBox->setEmitSignal(kSValEntered);
showInputBox(kSValEntered);
break;
case kCmpCmd:
parent().addDialog(myInputBox);
myInputBox->setEditString("");
myInputBox->setTitle("");
myInputBox->setEmitSignal(kCValEntered);
showInputBox(kCValEntered);
break;
case kRestartCmd:
@ -274,7 +266,22 @@ void RamWidget::fillGrid(bool updateOld)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const string RamWidget::doSearch(const string& str)
void RamWidget::showInputBox(int cmd)
{
// Add inputbox in the middle of the RAM widget
uInt32 tx, ty;
dialog().surface().getPos(tx, ty);
tx += getAbsX() + ((getWidth() - myInputBox->getWidth()) >> 1);
ty += getAbsY() + ((getHeight() - myInputBox->getHeight()) >> 1);
myInputBox->show(tx, ty);
myInputBox->setEditString("");
myInputBox->setTitle("");
myInputBox->setFocus(0);
myInputBox->setEmitSignal(cmd);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string RamWidget::doSearch(const string& str)
{
bool comparisonSearch = true;
@ -324,7 +331,7 @@ const string RamWidget::doSearch(const string& str)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const string RamWidget::doCompare(const string& str)
string RamWidget::doCompare(const string& str)
{
bool comparitiveSearch = false;
int searchVal = 0, offset = 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: RamWidget.hxx,v 1.5 2008-02-06 13:45:20 stephena Exp $
// $Id: RamWidget.hxx,v 1.6 2008-06-19 19:15:44 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -48,8 +48,9 @@ class RamWidget : public Widget, public CommandSender
private:
void fillGrid(bool updateOld);
const string doSearch(const string& str);
const string doCompare(const string& str);
void showInputBox(int cmd);
string doSearch(const string& str);
string doCompare(const string& str);
void doRestart();
private:

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: RomWidget.cxx,v 1.25 2008-06-13 13:14:50 stephena Exp $
// $Id: RomWidget.cxx,v 1.26 2008-06-19 19:15:44 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -96,9 +96,8 @@ RomWidget::RomWidget(GuiObject* boss, const GUI::Font& font, int x, int y)
// Create dialog box for save ROM (get name)
StringList label;
label.push_back("Filename: ");
mySaveRom = new InputTextDialog(boss, font, label, _x + 50, _y + 80);
mySaveRom = new InputTextDialog(boss, font, label);
mySaveRom->setTarget(this);
mySaveRom->setCenter(false);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -131,9 +130,9 @@ void RomWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
if(rmb == "Save ROM")
{
mySaveRom->show(_x + 50, _y + 80);
mySaveRom->setTitle("");
mySaveRom->setEmitSignal(kRomNameEntered);
parent().addDialog(mySaveRom);
}
else if(rmb == "Set PC")
setPC(myRomList->getSelected());

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: ContextMenu.cxx,v 1.3 2008-06-19 12:01:31 stephena Exp $
// $Id: ContextMenu.cxx,v 1.4 2008-06-19 19:15:44 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -36,7 +36,9 @@ ContextMenu::ContextMenu(GuiObject* boss, const GUI::Font& font,
_rowHeight(font.getLineHeight()),
_twoColumns(false),
_font(&font),
_cmd(cmd)
_cmd(cmd),
_xorig(0),
_yorig(0)
{
// Create two columns of entries if there are more than 10 items
if(_entries.size() > 10)
@ -79,16 +81,37 @@ void ContextMenu::show(uInt32 x, uInt32 y, int item)
// Make sure position is set *after* the dialog is added, since the surface
// may not exist before then
parent().addDialog(this);
_xorig = x;
_yorig = y;
center();
setSelected(item);
}
// Are we in the current screen bounds?
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ContextMenu::center()
{
cerr << " ==> ContextMenu::center()" << endl;
// Make sure the menu is exactly where it should be, in case the image
// offset has changed
uInt32 x = _xorig, y = _yorig;
const GUI::Rect& image = instance().frameBuffer().imageRect();
uInt32 dx = image.x() + image.width();
uInt32 dy = image.y() + image.height();
if(x + _w > dx) x -= (x + _w - dx);
if(y + _h > dy) y -= (y + _h - dy);
uInt32 tx = image.x() + image.width();
uInt32 ty = image.y() + image.height();
if(x + _w > tx) x -= (x + _w - tx);
if(y + _h > ty) y -= (y + _h - ty);
surface().setPos(x, y);
setSelected(item);
/*
uInt32 tx, ty;
const GUI::Rect& image = instance().frameBuffer().imageRect();
dialog().surface().getPos(tx, ty);
tx += image.x();
ty += image.y();
surface().setPos(tx, ty);
*/
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -264,12 +287,15 @@ void ContextMenu::drawCurrentSelection(int item)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ContextMenu::sendSelection()
{
// We remove the dialog when the user has selected an item
// Make sure the dialog is removed before sending any commands,
// since one consequence of sending a command may be to add another
// dialog/menu
parent().removeDialog();
// Send any command associated with the selection
_selectedItem = _currentItem;
sendCommand(_cmd ? _cmd : kCMenuItemSelectedCmd, _selectedItem, -1);
// We remove the dialog when the user has selected an item
parent().removeDialog();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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: ContextMenu.hxx,v 1.3 2008-06-19 12:01:31 stephena Exp $
// $Id: ContextMenu.hxx,v 1.4 2008-06-19 19:15:44 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -66,7 +66,7 @@ class ContextMenu : public Dialog, public CommandSender
const string& getSelectedString() const;
/** This dialog uses its own positioning, so we override Dialog::center() */
void center() { }
void center();
protected:
void handleMouseDown(int x, int y, int button, int clickCount);
@ -103,6 +103,8 @@ class ContextMenu : public Dialog, public CommandSender
const GUI::Font* _font;
int _cmd;
uInt32 _xorig, _yorig;
};
#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: Dialog.cxx,v 1.62 2008-06-19 12:01:31 stephena Exp $
// $Id: Dialog.cxx,v 1.63 2008-06-19 19:15:44 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -44,7 +44,6 @@ Dialog::Dialog(OSystem* instance, DialogContainer* parent,
_okWidget(0),
_cancelWidget(0),
_visible(true),
_center(true),
_isBase(isBase),
_ourTab(NULL),
_surface(NULL),

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: Dialog.hxx,v 1.38 2008-06-13 13:14:51 stephena Exp $
// $Id: Dialog.hxx,v 1.39 2008-06-19 19:15:44 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -47,7 +47,7 @@ class TabWidget;
This is the base class for all dialog boxes.
@author Stephen Anthony
@version $Id: Dialog.hxx,v 1.38 2008-06-13 13:14:51 stephena Exp $
@version $Id: Dialog.hxx,v 1.39 2008-06-19 19:15:44 stephena Exp $
*/
class Dialog : public GuiObject
{
@ -84,7 +84,6 @@ class Dialog : public GuiObject
void addOKWidget(Widget* w) { _okWidget = w; }
void addCancelWidget(Widget* w) { _cancelWidget = w; }
void setFocus(Widget* w);
void setCenter(bool state) { _center = state; }
inline FBSurface& surface() { return *_surface; }
@ -126,7 +125,6 @@ class Dialog : public GuiObject
Widget* _okWidget;
Widget* _cancelWidget;
bool _visible;
bool _center;
bool _isBase;
private:

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: DialogContainer.cxx,v 1.45 2008-06-13 13:14:51 stephena Exp $
// $Id: DialogContainer.cxx,v 1.46 2008-06-19 19:15:44 stephena Exp $
//============================================================================
#include "OSystem.hxx"
@ -102,7 +102,7 @@ void DialogContainer::draw()
}
else if(!myDialogStack.empty())
{
myDialogStack.top()->center();
// myDialogStack.top()->center();
myDialogStack.top()->drawDialog();
}
}

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.21 2008-06-13 13:14:51 stephena Exp $
// $Id: InputTextDialog.cxx,v 1.22 2008-06-19 19:15:44 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -22,6 +22,7 @@
#include "bspf.hxx"
#include "Dialog.hxx"
#include "DialogContainer.hxx"
#include "EditTextWidget.hxx"
#include "GuiObject.hxx"
#include "OSystem.hxx"
@ -31,16 +32,14 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font,
const StringList& labels, int x, int y)
: Dialog(&boss->instance(), &boss->parent(), x, y, 16, 16),
const StringList& labels)
: Dialog(&boss->instance(), &boss->parent(), 0, 0, 16, 16),
CommandSender(boss),
myErrorFlag(false)
{
const int fontWidth = font.getMaxCharWidth(),
fontHeight = font.getFontHeight(),
lineHeight = font.getLineHeight(),
bwidth = font.getStringWidth(" Cancel "),
bheight = font.getLineHeight() + 4;
lineHeight = font.getLineHeight();
unsigned int xpos, ypos, i, lwidth = 0, maxIdx = 0;
WidgetArray wid;
@ -82,28 +81,12 @@ InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font,
"", kTextAlignCenter);
myTitle->setTextColor(kTextColorEm);
ButtonWidget* b;
#ifndef MAC_OSX
b = new ButtonWidget(this, font, _w - 2 * (bwidth + 10), _h - bheight - 10,
bwidth, bheight, "OK", kAcceptCmd);
wid.push_back(b);
addOKWidget(b);
b = new ButtonWidget(this, font, _w - (bwidth + 10), _h - bheight - 10,
bwidth, bheight, "Cancel", kCloseCmd);
wid.push_back(b);
addCancelWidget(b);
#else
b = new ButtonWidget(this, font, _w - 2 * (bwidth + 10), _h - bheight - 10,
bwidth, bheight, "Cancel", kCloseCmd);
wid.push_back(b);
addCancelWidget(b);
b = new ButtonWidget(this, font, _w - (bwidth + 10), _h - bheight - 10,
bwidth, bheight, "OK", kAcceptCmd);
wid.push_back(b);
addOKWidget(b);
#endif
addToFocusList(wid);
// Add OK and Cancel buttons
wid.clear();
addOKCancelBGroup(wid, font);
addBGroupToFocusList(wid);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -112,6 +95,23 @@ InputTextDialog::~InputTextDialog()
myInput.clear();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void InputTextDialog::show(uInt32 x, uInt32 y)
{
// Make sure position is set *after* the dialog is added, since the surface
// may not exist before then
parent().addDialog(this);
// Are we in the current screen bounds?
const GUI::Rect& image = instance().frameBuffer().imageRect();
uInt32 dx = image.x() + image.width();
uInt32 dy = image.y() + image.height();
if(x + _w > dx) x -= (x + _w - dx);
if(y + _h > dy) y -= (y + _h - dy);
surface().setPos(x, y);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void InputTextDialog::setTitle(const string& title)
{
@ -146,9 +146,9 @@ void InputTextDialog::setFocus(int idx)
void InputTextDialog::handleCommand(CommandSender* sender, int cmd,
int data, int id)
{
switch (cmd)
switch(cmd)
{
case kAcceptCmd:
case kOKCmd:
case kEditAcceptCmd:
{
// Send a signal to the calling class that a selection has been made

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.hxx,v 1.10 2008-02-06 13:45:23 stephena Exp $
// $Id: InputTextDialog.hxx,v 1.11 2008-06-19 19:15:44 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -35,9 +35,12 @@ class InputTextDialog : public Dialog, public CommandSender
{
public:
InputTextDialog(GuiObject* boss, const GUI::Font& font,
const StringList& labels, int x, int y);
const StringList& labels);
virtual ~InputTextDialog();
/** Show input dialog onscreen at the specified coordinates */
void show(uInt32 x, uInt32 y);
const string& getResult(int idx = 0);
void setEditString(const string& str, int idx = 0);
@ -46,20 +49,18 @@ class InputTextDialog : public Dialog, public CommandSender
void setFocus(int idx = 0);
/** This dialog uses its own positioning, so we override Dialog::center() */
void center() { }
protected:
virtual void handleCommand(CommandSender* sender, int cmd, int data, int id);
private:
private:
InputWidget myInput;
StaticTextWidget* myTitle;
bool myErrorFlag;
int myCmd;
enum {
kAcceptCmd = 'ACPT'
};
};
#endif