Added a new DialogContainer class, which contains code common to the Menu

and Browser classes.

Abstracted Menu class into a DialogContainer.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@408 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-05-04 19:04:47 +00:00
parent 58e906998a
commit 97081a75ee
7 changed files with 33 additions and 265 deletions

View File

@ -13,7 +13,7 @@
## See the file "license" for information on usage and redistribution of ## See the file "license" for information on usage and redistribution of
## this file, and for a DISCLAIMER OF ALL WARRANTIES. ## this file, and for a DISCLAIMER OF ALL WARRANTIES.
## ##
## $Id: makefile,v 1.73 2005-05-01 20:11:06 stephena Exp $ ## $Id: makefile,v 1.74 2005-05-04 19:04:38 stephena Exp $
##============================================================================ ##============================================================================
##============================================================================ ##============================================================================
@ -156,8 +156,8 @@ win32-gl:
M6502_OBJS = D6502.o Device.o M6502.o M6502Low.o M6502Hi.o NullDev.o System.o M6502_OBJS = D6502.o Device.o M6502.o M6502Low.o M6502Hi.o NullDev.o System.o
GUI_OBJS = StellaFont.o Menu.o Widget.o PopUpWidget.o ScrollBarWidget.o ListWidget.o \ GUI_OBJS = StellaFont.o Menu.o Widget.o PopUpWidget.o ScrollBarWidget.o ListWidget.o \
Dialog.o OptionsDialog.o VideoDialog.o AudioDialog.o \ Dialog.o DialogContainer.o OptionsDialog.o VideoDialog.o AudioDialog.o \
EventMappingDialog.o GameInfoDialog.o HelpDialog.o EventMappingDialog.o GameInfoDialog.o HelpDialog.o
CORE_OBJS = Booster.o Cart.o Cart2K.o Cart3F.o Cart4K.o CartAR.o CartDPC.o \ CORE_OBJS = Booster.o Cart.o Cart2K.o Cart3F.o Cart4K.o CartAR.o CartDPC.o \
CartE0.o CartE7.o CartF4.o CartF4SC.o CartF6.o CartF6SC.o \ CartE0.o CartE7.o CartF4.o CartF4SC.o CartF6.o CartF6SC.o \
@ -386,6 +386,9 @@ ListWidget.o: $(GUI)/ListWidget.cxx $(GUI)/ListWidget.hxx
Dialog.o: $(GUI)/Dialog.cxx $(GUI)/Dialog.hxx Dialog.o: $(GUI)/Dialog.cxx $(GUI)/Dialog.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/Dialog.cxx $(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/Dialog.cxx
DialogContainer.o: $(GUI)/DialogContainer.cxx $(GUI)/DialogContainer.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/DialogContainer.cxx
OptionsDialog.o: $(GUI)/OptionsDialog.cxx $(GUI)/OptionsDialog.hxx OptionsDialog.o: $(GUI)/OptionsDialog.cxx $(GUI)/OptionsDialog.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/OptionsDialog.cxx $(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/OptionsDialog.cxx

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: EventHandler.cxx,v 1.48 2005-05-04 00:43:22 stephena Exp $ // $Id: EventHandler.cxx,v 1.49 2005-05-04 19:04:45 stephena Exp $
//============================================================================ //============================================================================
#include <algorithm> #include <algorithm>
@ -376,7 +376,7 @@ void EventHandler::handleKeyEvent(SDLKey key, SDLMod mod, uInt8 state)
break; // S_EMULATE break; // S_EMULATE
case S_MENU: case S_MENU:
myOSystem->menu().handleKeyEvent(key, mod, state); myOSystem->menu().handleKeyEvent((uInt16) key, (Int32) mod, state);
break; break;
case S_BROWSER: case S_BROWSER:

View File

@ -13,13 +13,14 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: OSystem.hxx,v 1.7 2005-05-02 19:36:05 stephena Exp $ // $Id: OSystem.hxx,v 1.8 2005-05-04 19:04:46 stephena Exp $
//============================================================================ //============================================================================
#ifndef OSYSTEM_HXX #ifndef OSYSTEM_HXX
#define OSYSTEM_HXX #define OSYSTEM_HXX
class PropertiesSet; class PropertiesSet;
class Menu; class Menu;
class Browser; class Browser;
@ -37,7 +38,7 @@ class Browser;
other objects belong. other objects belong.
@author Stephen Anthony @author Stephen Anthony
@version $Id: OSystem.hxx,v 1.7 2005-05-02 19:36:05 stephena Exp $ @version $Id: OSystem.hxx,v 1.8 2005-05-04 19:04:46 stephena Exp $
*/ */
class OSystem class OSystem
{ {
@ -86,20 +87,6 @@ class OSystem
*/ */
void detachConsole(void) { delete myConsole; myConsole = NULL; } void detachConsole(void) { delete myConsole; myConsole = NULL; }
/**
Adds the specified settings menu yo the system.
@param menu The menu object to add
*/
void attach(Menu* menu) { myMenu = menu; }
/**
Adds the specified ROM browser to the system.
@param browser The browser object to add
*/
void attach(Browser* browser) { myBrowser = browser; }
/** /**
Get the event handler of the system Get the event handler of the system

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Dialog.hxx,v 1.8 2005-04-24 01:57:47 stephena Exp $ // $Id: Dialog.hxx,v 1.9 2005-05-04 19:04:46 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -23,7 +23,7 @@
#define DIALOG_HXX #define DIALOG_HXX
class OSystem; class OSystem;
class Menu; class DialogContainer;
#include "Command.hxx" #include "Command.hxx"
#include "Widget.hxx" #include "Widget.hxx"
@ -35,11 +35,11 @@ class Menu;
This is the base class for all dialog boxes. This is the base class for all dialog boxes.
@author Stephen Anthony @author Stephen Anthony
@version $Id: Dialog.hxx,v 1.8 2005-04-24 01:57:47 stephena Exp $ @version $Id: Dialog.hxx,v 1.9 2005-05-04 19:04:46 stephena Exp $
*/ */
class Dialog : public GuiObject class Dialog : public GuiObject
{ {
friend class Menu; friend class DialogContainer;
public: public:
Dialog(OSystem* instance, uInt16 x, uInt16 y, uInt16 w, uInt16 h); Dialog(OSystem* instance, uInt16 x, uInt16 y, uInt16 w, uInt16 h);

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: ListWidget.cxx,v 1.4 2005-05-04 00:43:22 stephena Exp $ // $Id: ListWidget.cxx,v 1.5 2005-05-04 19:04:46 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -194,10 +194,8 @@ static bool matchingCharsIgnoringCase(string s, string pattern)
transform(s.begin(), s.end(), s.begin(), (int(*)(int)) toupper); transform(s.begin(), s.end(), s.begin(), (int(*)(int)) toupper);
transform(pattern.begin(), pattern.end(), pattern.begin(), (int(*)(int)) toupper); transform(pattern.begin(), pattern.end(), pattern.begin(), (int(*)(int)) toupper);
uInt32 pos = s.find(pattern, 0);
// Make sure that if the pattern is found, it occurs at the start of 's' // Make sure that if the pattern is found, it occurs at the start of 's'
return (pos != string::npos && pos < pattern.length()); return (s.find(pattern, 0) == 0);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,173 +13,35 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Menu.cxx,v 1.6 2005-05-03 19:11:27 stephena Exp $ // $Id: Menu.cxx,v 1.7 2005-05-04 19:04:46 stephena Exp $
//============================================================================ //============================================================================
#include <SDL.h>
#include "OSystem.hxx"
#include "Dialog.hxx" #include "Dialog.hxx"
#include "OptionsDialog.hxx" #include "OptionsDialog.hxx"
#include "Stack.hxx"
#include "bspf.hxx" #include "bspf.hxx"
#include "Menu.hxx" #include "Menu.hxx"
class Properties;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Menu::Menu(OSystem* osystem) Menu::Menu(OSystem* osystem)
: myOSystem(osystem), : DialogContainer(osystem)
myOptionsDialog(NULL)
{ {
myOSystem->attach(this);
myCurrentKeyDown.keycode = 0;
myLastClick.x = myLastClick.y = 0;
myLastClick.time = 0;
myLastClick.count = 0;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Menu::~Menu() Menu::~Menu()
{ {
if(myOptionsDialog)
delete myOptionsDialog;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::initialize() void Menu::setBaseDialog()
{ {
if(myOptionsDialog) myBaseDialog = new OptionsDialog(myOSystem);
{
delete myOptionsDialog;
myOptionsDialog = NULL;
}
// Create the top-level menu
myOptionsDialog = new OptionsDialog(myOSystem);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::draw() void Menu::setGameProfile(Properties& props)
{ {
// Draw all the dialogs on the stack ((OptionsDialog*)myBaseDialog)->setGameProfile(props);
for(Int32 i = 0; i < myDialogStack.size(); i++)
{
myDialogStack[i]->open();
myDialogStack[i]->drawDialog();
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::addDialog(Dialog* d)
{
myDialogStack.push(d);
myOSystem->frameBuffer().refresh();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::removeDialog()
{
if(!myDialogStack.empty())
{
myDialogStack.pop();
myOSystem->frameBuffer().refresh();
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::reStack()
{
// Pop all items from the stack, and then add the base menu
while(!myDialogStack.empty())
{
Dialog* d = myDialogStack.pop();
d->close();
}
myDialogStack.push(myOptionsDialog);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::handleKeyEvent(SDLKey key, SDLMod mod, uInt8 state)
{
if(myDialogStack.empty())
return;
// Send the event to the dialog box on the top of the stack
Dialog* activeDialog = myDialogStack.top();
// Convert SDL values to ascii so the ScummVM subsystem can work with it
if(state == 1)
activeDialog->handleKeyDown(key, key, mod);
else
activeDialog->handleKeyUp(key, key, mod);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::handleMouseMotionEvent(Int32 x, Int32 y, Int32 button)
{
if(myDialogStack.empty())
return;
// Send the event to the dialog box on the top of the stack
Dialog* activeDialog = myDialogStack.top();
activeDialog->handleMouseMoved(x - activeDialog->_x,
y - activeDialog->_y,
button);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::handleMouseButtonEvent(MouseButton b, Int32 x, Int32 y, uInt8 state)
{
if(myDialogStack.empty())
return;
// Send the event to the dialog box on the top of the stack
Dialog* activeDialog = myDialogStack.top();
// Get the current time for detecting double clicks
uInt32 time = myOSystem->getTicks() / 1000; // we only need millisecond precision
switch(b)
{
case EVENT_LBUTTONDOWN:
case EVENT_RBUTTONDOWN:
// If more than two clicks have been recorded, we start over
if(myLastClick.count == 2)
{
myLastClick.x = myLastClick.y = 0;
myLastClick.time = 0;
myLastClick.count = 0;
}
if(myLastClick.count && (time < myLastClick.time + 500) // DoubleClickDelay
&& ABS(myLastClick.x - x) < 3
&& ABS(myLastClick.y - y) < 3)
{
myLastClick.count++;
}
else
{
myLastClick.x = x;
myLastClick.y = y;
myLastClick.count = 1;
}
myLastClick.time = time;
activeDialog->handleMouseDown(x - activeDialog->_x, y - activeDialog->_y,
1, myLastClick.count);
break;
case EVENT_LBUTTONUP:
case EVENT_RBUTTONUP:
activeDialog->handleMouseUp(x - activeDialog->_x, y - activeDialog->_y,
1, myLastClick.count);
break;
case EVENT_WHEELUP:
activeDialog->handleMouseWheel(x - activeDialog->_x, y - activeDialog->_y, -1);
break;
case EVENT_WHEELDOWN:
activeDialog->handleMouseWheel(x - activeDialog->_x, y - activeDialog->_y, 1);
break;
}
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Menu.hxx,v 1.6 2005-05-03 19:11:27 stephena Exp $ // $Id: Menu.hxx,v 1.7 2005-05-04 19:04:47 stephena Exp $
//============================================================================ //============================================================================
#ifndef MENU_HXX #ifndef MENU_HXX
@ -22,26 +22,15 @@
class Properties; class Properties;
class OSystem; class OSystem;
#include <SDL.h> #include "DialogContainer.hxx"
#include "Stack.hxx"
#include "EventHandler.hxx"
#include "Dialog.hxx"
#include "OptionsDialog.hxx"
#include "bspf.hxx"
typedef FixedStack<Dialog *> DialogStack;
/** /**
The base class for all menus in Stella. The base dialog for all configuration menus in Stella.
This class keeps track of all configuration menus. organizes them into
a stack, and handles their events.
@author Stephen Anthony @author Stephen Anthony
@version $Id: Menu.hxx,v 1.6 2005-05-03 19:11:27 stephena Exp $ @version $Id: Menu.hxx,v 1.7 2005-05-04 19:04:47 stephena Exp $
*/ */
class Menu class Menu : public DialogContainer
{ {
public: public:
/** /**
@ -56,87 +45,16 @@ class Menu
public: public:
/** /**
Handle a keyboard event. Updates the basedialog to be of the type defined for this derived class.
@param key keysym
@param mod modifiers
@param state state of key
*/ */
void handleKeyEvent(SDLKey key, SDLMod mod, uInt8 state); //FIXME - this shouldn't refer to SDL directly void setBaseDialog();
/**
Handle a mouse motion event.
@param x The x location
@param y The y location
@param button The currently pressed button
*/
void handleMouseMotionEvent(Int32 x, Int32 y, Int32 button);
/**
Handle a mouse button event.
@param b The mouse button
@param x The x location
@param y The y location
@param state The state (pressed or released)
*/
void handleMouseButtonEvent(MouseButton b, Int32 x, Int32 y, uInt8 state);
// FIXME - add joystick handler
/**
(Re)initialize the menuing system. This is necessary if a new Console
has been loaded, since in most cases the screen dimensions will have changed.
*/
void initialize();
/**
Draw the stack of menus.
*/
void draw();
/**
Add a dialog box to the stack
*/
void addDialog(Dialog* d);
/**
Remove the topmost dialog box from the stack
*/
void removeDialog();
/**
Reset dialog stack to the main configuration menu
*/
void reStack();
/** /**
Adds the specified game info to the appropriate menu item Adds the specified game info to the appropriate menu item
@param props The properties of the current game @param props The properties of the current game
*/ */
void setGameProfile(Properties& props) { myOptionsDialog->setGameProfile(props); } void setGameProfile(Properties& props);
private:
OSystem* myOSystem;
OptionsDialog* myOptionsDialog;
DialogStack myDialogStack;
// For continuous events (keyDown)
struct {
uInt16 ascii;
uInt8 flags;
uInt32 keycode;
} myCurrentKeyDown;
uInt32 myKeyRepeatTime;
// Position and time of last mouse click (used to detect double clicks)
struct {
Int16 x, y; // Position of mouse when the click occured
uInt32 time; // Time
Int32 count; // How often was it already pressed?
} myLastClick;
}; };
#endif #endif