Fixed bug whereby properties weren't being merged when they didn't

exist in the stella.pro file.  Properties to be saved are now explicitly
marked as such, and don't rely on how often they're insert()'ed.

Made 'Exit ROM' in the CommandDialog do the appropriate thing based
on whether we want to go back to the ROM launcher or completely
exit the emulator.

Moved bounding rectangle for drawing focus around a widget into a
Widget::getRect() method and updated Widget class to use these coordinates.
This means widgets that contain other widgets (ie, attached scrollbars)
can define their own getRect() and have the focus rectange draw correctly.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@780 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-09-16 18:15:44 +00:00
parent fb04fddae7
commit 65711293a3
7 changed files with 65 additions and 35 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: mainSDL.cxx,v 1.50 2005-09-11 22:55:51 stephena Exp $
// $Id: mainSDL.cxx,v 1.51 2005-09-16 18:15:44 stephena Exp $
//============================================================================
#include <fstream>
@ -84,7 +84,7 @@ void SetupProperties(PropertiesSet& set)
if(altpro != "")
{
buf << "Game properties: \'" << altpro << "\'\n";
set.load(altpro);
set.load(altpro, false); // don't save alternate properties to userPro
}
else
{
@ -92,8 +92,8 @@ void SetupProperties(PropertiesSet& set)
const string& userPro = theOSystem->userProperties();
buf << "Game properties: \'" << sysPro << "\', \'" << userPro << "\'\n";
set.load(sysPro);
set.load(userPro);
set.load(sysPro, false); // don't save system-wide properties
set.load(userPro, true);
}
if(theOSystem->settings().getBool("showinfo"))

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: EventHandler.hxx,v 1.49 2005-08-30 23:32:42 stephena Exp $
// $Id: EventHandler.hxx,v 1.50 2005-09-16 18:15:44 stephena Exp $
//============================================================================
#ifndef EVENTHANDLER_HXX
@ -74,7 +74,7 @@ struct Stella_Joystick {
mapping can take place.
@author Stephen Anthony
@version $Id: EventHandler.hxx,v 1.49 2005-08-30 23:32:42 stephena Exp $
@version $Id: EventHandler.hxx,v 1.50 2005-09-16 18:15:44 stephena Exp $
*/
class EventHandler
{
@ -150,6 +150,12 @@ class EventHandler
*/
inline State state() { return myState; }
/**
Returns the current launcher state (decide whether to enter launcher
on game exit).
*/
inline bool useLauncher() { return myUseLauncherFlag; }
/**
Resets the state machine of the EventHandler to the defaults

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: PropsSet.cxx,v 1.12 2005-09-11 22:55:51 stephena Exp $
// $Id: PropsSet.cxx,v 1.13 2005-09-16 18:15:44 stephena Exp $
//============================================================================
#include <assert.h>
@ -75,13 +75,14 @@ void PropertiesSet::getMD5(const string& md5, Properties &properties)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PropertiesSet::insert(const Properties& properties)
void PropertiesSet::insert(const Properties& properties, bool save)
{
insertNode(myRoot, properties);
insertNode(myRoot, properties, save);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PropertiesSet::insertNode(TreeNode* &t, const Properties& properties)
void PropertiesSet::insertNode(TreeNode* &t, const Properties& properties,
bool save)
{
if(t)
{
@ -89,14 +90,14 @@ void PropertiesSet::insertNode(TreeNode* &t, const Properties& properties)
string currentMd5 = t->props->get("Cartridge.MD5");
if(md5 < currentMd5)
insertNode(t->left, properties);
insertNode(t->left, properties, save);
else if(md5 > currentMd5)
insertNode(t->right, properties);
insertNode(t->right, properties, save);
else
{
delete t->props;
t->props = new Properties(properties);
t->count++;
t->save = save;
}
}
else
@ -105,7 +106,7 @@ void PropertiesSet::insertNode(TreeNode* &t, const Properties& properties)
t->props = new Properties(properties);
t->left = 0;
t->right = 0;
t->count = 1;
t->save = save;
++mySize;
}
@ -124,7 +125,7 @@ void PropertiesSet::deleteNode(TreeNode *node)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PropertiesSet::load(const string& filename)
void PropertiesSet::load(const string& filename, bool save)
{
ifstream in(filename.c_str(), ios::in);
@ -141,7 +142,7 @@ void PropertiesSet::load(const string& filename)
// If the stream is still good then insert the properties
if(in)
insert(properties);
insert(properties, save);
}
if(in)
in.close();
@ -165,7 +166,7 @@ void PropertiesSet::saveNode(ostream& out, TreeNode *node)
{
if(node)
{
if(node->count > 1)
if(node->save)
node->props->save(out);
saveNode(out, node->left);
saveNode(out, node->right);
@ -195,7 +196,7 @@ bool PropertiesSet::merge(const Properties& properties, const string& filename)
ofstream out(filename.c_str());
if(out.is_open())
{
insert(properties);
insert(properties, true); // always save merged properties
save(out);
out.close();
return true;

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: PropsSet.hxx,v 1.8 2005-09-11 22:55:51 stephena Exp $
// $Id: PropsSet.hxx,v 1.9 2005-09-16 18:15:44 stephena Exp $
//============================================================================
#ifndef PROPERTIES_SET_HXX
@ -64,8 +64,10 @@ class PropertiesSet
defaults properties as the defaults for any properties loaded.
@param filename Full pathname of input file to use
@param save Indicates whether to set the 'save' tag for
these properties
*/
void load(const string& filename);
void load(const string& filename, bool save);
/**
Save properties to the specified output stream
@ -102,7 +104,7 @@ class PropertiesSet
Properties* props;
TreeNode* left;
TreeNode* right;
int count;
bool save;
};
/**
@ -110,16 +112,20 @@ class PropertiesSet
the old properties are overwritten with the new ones.
@param properties The collection of properties
@param save Indicates whether to set the 'save' tag for
this property
*/
void insert(const Properties& properties);
void insert(const Properties& properties, bool save);
/**
Insert a node in the bst, keeping the tree sorted.
@param node The current subroot of the tree
@param properties The collection of properties
@param save Indicates whether to set the 'save' tag for
this property
*/
void insertNode(TreeNode* &node, const Properties& properties);
void insertNode(TreeNode* &node, const Properties& properties, bool save);
/**
Deletes a node from the bst. Does not preserve bst sorting.

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: CommandDialog.cxx,v 1.2 2005-08-30 23:32:42 stephena Exp $
// $Id: CommandDialog.cxx,v 1.3 2005-09-16 18:15:44 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -42,7 +42,7 @@ enum {
kFormatCmd = 'Cfmt',
kPaletteCmd = 'Cpal',
kReloadRomCmd = 'Crom',
kLauncherCmd = 'Clch'
kExitCmd = 'Clex'
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -115,7 +115,7 @@ CommandDialog::CommandDialog(OSystem* osystem, DialogContainer* parent)
"Reload ROM", kReloadRomCmd, 0);
xoffset += lwidth;
new ButtonWidget(this, xoffset, yoffset, buttonWidth, buttonHeight,
"Exit Game", kLauncherCmd, 0);
"Exit Game", kExitCmd, 0);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -198,8 +198,11 @@ void CommandDialog::handleCommand(CommandSender* sender, int cmd,
return;
break;
case kLauncherCmd:
event = Event::LauncherMode;
case kExitCmd:
if(instance()->eventHandler().useLauncher())
event = Event::LauncherMode;
else
event = Event::Quit;
break;
default:

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: Widget.cxx,v 1.34 2005-08-31 19:15:10 stephena Exp $
// $Id: Widget.cxx,v 1.35 2005-09-16 18:15:44 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -137,6 +137,16 @@ void Widget::lostFocus()
lostFocusWidget();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
GUI::Rect Widget::getRect() const
{
int x = getAbsX() - 1, y = getAbsY() - 1,
w = getWidth() + 2, h = getHeight() + 2;
GUI::Rect r(x, y, x+w, y+h);
return r;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Widget::setEnabled(bool e)
{
@ -216,8 +226,9 @@ Widget* Widget::setFocusForChain(GuiObject* boss, WidgetArray& arr,
if(wid == tmp)
pos = i;
int x = tmp->getAbsX() - 1, y = tmp->getAbsY() - 1,
w = tmp->getWidth() + 2, h = tmp->getHeight() + 2;
GUI::Rect rect = tmp->getRect();
int x = rect.left, y = rect.top,
w = rect.width(), h = rect.height();
// First clear area surrounding all widgets
if(tmp->_hasFocus)
@ -257,8 +268,9 @@ Widget* Widget::setFocusForChain(GuiObject* boss, WidgetArray& arr,
// Now highlight the active widget
tmp = arr[pos];
int x = tmp->getAbsX() - 1, y = tmp->getAbsY() - 1,
w = tmp->getWidth() + 2, h = tmp->getHeight() + 2;
GUI::Rect rect = tmp->getRect();
int x = rect.left, y = rect.top,
w = rect.width(), h = rect.height();
tmp->receivedFocus();
if(!(tmp->_flags & WIDGET_NODRAW_FOCUS))

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: Widget.hxx,v 1.36 2005-08-31 19:15:10 stephena Exp $
// $Id: Widget.hxx,v 1.37 2005-09-16 18:15:44 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -31,6 +31,7 @@ class Dialog;
#include "GuiObject.hxx"
#include "GuiUtils.hxx"
#include "Array.hxx"
#include "Rect.hxx"
#include "bspf.hxx"
enum {
@ -71,7 +72,7 @@ enum {
This is the base class for all widgets.
@author Stephen Anthony
@version $Id: Widget.hxx,v 1.36 2005-08-31 19:15:10 stephena Exp $
@version $Id: Widget.hxx,v 1.37 2005-09-16 18:15:44 stephena Exp $
*/
class Widget : public GuiObject
{
@ -100,6 +101,7 @@ class Widget : public GuiObject
void lostFocus();
void addFocusWidget(Widget* w) { _focusList.push_back(w); }
virtual GUI::Rect getRect() const;
virtual bool wantsFocus() { return false; };
/** Set/clear WIDGET_ENABLED flag and immediately redraw */