From 65711293a31ab825dd2d455662c19f2eed39a875 Mon Sep 17 00:00:00 2001 From: stephena Date: Fri, 16 Sep 2005 18:15:44 +0000 Subject: [PATCH] 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 --- stella/src/common/mainSDL.cxx | 8 ++++---- stella/src/emucore/EventHandler.hxx | 10 ++++++++-- stella/src/emucore/PropsSet.cxx | 25 +++++++++++++------------ stella/src/emucore/PropsSet.hxx | 16 +++++++++++----- stella/src/gui/CommandDialog.cxx | 13 ++++++++----- stella/src/gui/Widget.cxx | 22 +++++++++++++++++----- stella/src/gui/Widget.hxx | 6 ++++-- 7 files changed, 65 insertions(+), 35 deletions(-) diff --git a/stella/src/common/mainSDL.cxx b/stella/src/common/mainSDL.cxx index bf1e9b152..eaf636323 100644 --- a/stella/src/common/mainSDL.cxx +++ b/stella/src/common/mainSDL.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: 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 @@ -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")) diff --git a/stella/src/emucore/EventHandler.hxx b/stella/src/emucore/EventHandler.hxx index b5c101c5c..f9797d8fc 100644 --- a/stella/src/emucore/EventHandler.hxx +++ b/stella/src/emucore/EventHandler.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: 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 diff --git a/stella/src/emucore/PropsSet.cxx b/stella/src/emucore/PropsSet.cxx index 0c19bd2ac..38f0e0dca 100644 --- a/stella/src/emucore/PropsSet.cxx +++ b/stella/src/emucore/PropsSet.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: 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 @@ -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; diff --git a/stella/src/emucore/PropsSet.hxx b/stella/src/emucore/PropsSet.hxx index 4d3238aa9..45f00d491 100644 --- a/stella/src/emucore/PropsSet.hxx +++ b/stella/src/emucore/PropsSet.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: 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. diff --git a/stella/src/gui/CommandDialog.cxx b/stella/src/gui/CommandDialog.cxx index e40f4550e..248f530b3 100644 --- a/stella/src/gui/CommandDialog.cxx +++ b/stella/src/gui/CommandDialog.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: 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: diff --git a/stella/src/gui/Widget.cxx b/stella/src/gui/Widget.cxx index c983d10c8..dcedabc95 100644 --- a/stella/src/gui/Widget.cxx +++ b/stella/src/gui/Widget.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: 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)) diff --git a/stella/src/gui/Widget.hxx b/stella/src/gui/Widget.hxx index 49c4a48cd..51d3b1e4e 100644 --- a/stella/src/gui/Widget.hxx +++ b/stella/src/gui/Widget.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: 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 */