Oops, forget to include the DialogContainer class.

git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@409 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-05-04 21:32:25 +00:00
parent 97081a75ee
commit 79f738b93e
4 changed files with 304 additions and 5 deletions

View File

@ -0,0 +1,165 @@
//============================================================================
//
// 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
//
// 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.1 2005-05-04 21:32:25 stephena Exp $
//============================================================================
#include "OSystem.hxx"
#include "Dialog.hxx"
#include "Stack.hxx"
#include "bspf.hxx"
#include "DialogContainer.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DialogContainer::DialogContainer(OSystem* osystem)
: myOSystem(osystem),
myBaseDialog(NULL)
{
myCurrentKeyDown.keycode = 0;
myLastClick.x = myLastClick.y = 0;
myLastClick.time = 0;
myLastClick.count = 0;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DialogContainer::~DialogContainer()
{
if(myBaseDialog)
delete myBaseDialog;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::draw()
{
// Draw all the dialogs on the stack
for(Int32 i = 0; i < myDialogStack.size(); i++)
{
myDialogStack[i]->open();
myDialogStack[i]->drawDialog();
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::addDialog(Dialog* d)
{
myDialogStack.push(d);
myOSystem->frameBuffer().refresh();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::removeDialog()
{
if(!myDialogStack.empty())
{
myDialogStack.pop();
myOSystem->frameBuffer().refresh();
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::reStack()
{
// Pop all items from the stack, and then add the base menu
while(!myDialogStack.empty())
{
Dialog* d = myDialogStack.pop();
d->close();
}
myDialogStack.push(myBaseDialog);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::handleKeyEvent(uInt16 key, Int32 mod, uInt8 state)
{
if(myDialogStack.empty())
return;
// Send the event to the dialog box on the top of the stack
Dialog* activeDialog = myDialogStack.top();
if(state == 1)
activeDialog->handleKeyDown(key, key, mod);
else
activeDialog->handleKeyUp(key, key, mod);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::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 DialogContainer::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

@ -0,0 +1,133 @@
//============================================================================
//
// 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
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: DialogContainer.hxx,v 1.1 2005-05-04 21:32:25 stephena Exp $
//============================================================================
#ifndef DIALOG_CONTAINER_HXX
#define DIALOG_CONTAINER_HXX
class OSystem;
#include "Stack.hxx"
#include "EventHandler.hxx"
#include "Dialog.hxx"
#include "bspf.hxx"
typedef FixedStack<Dialog *> DialogStack;
/**
The base class for groups of dialog boxes. Each dialog box has a
parent. In most cases, the parent is itself a dialog box, but in the
case of the lower-most dialog box, this class is its parent.
This class keeps track of its children (dialog boxes), organizes them into
a stack, and handles their events.
@author Stephen Anthony
@version $Id: DialogContainer.hxx,v 1.1 2005-05-04 21:32:25 stephena Exp $
*/
class DialogContainer
{
public:
/**
Create a new DialogContainer stack
*/
DialogContainer(OSystem* osystem);
/**
Destructor
*/
virtual ~DialogContainer();
public:
/**
Handle a keyboard event.
@param key keysym
@param mod modifiers
@param state state of key
*/
void handleKeyEvent(uInt16 key, Int32 mod, uInt8 state);
/**
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
/**
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();
/**
(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.
*/
virtual void initialize() = 0;
protected:
OSystem* myOSystem;
Dialog* myBaseDialog;
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

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: Menu.cxx,v 1.7 2005-05-04 19:04:46 stephena Exp $
// $Id: Menu.cxx,v 1.8 2005-05-04 21:32:25 stephena Exp $
//============================================================================
#include "Dialog.hxx"
@ -35,8 +35,9 @@ Menu::~Menu()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::setBaseDialog()
void Menu::initialize()
{
delete myBaseDialog;
myBaseDialog = new OptionsDialog(myOSystem);
}

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: Menu.hxx,v 1.7 2005-05-04 19:04:47 stephena Exp $
// $Id: Menu.hxx,v 1.8 2005-05-04 21:32:25 stephena Exp $
//============================================================================
#ifndef MENU_HXX
@ -28,7 +28,7 @@ class OSystem;
The base dialog for all configuration menus in Stella.
@author Stephen Anthony
@version $Id: Menu.hxx,v 1.7 2005-05-04 19:04:47 stephena Exp $
@version $Id: Menu.hxx,v 1.8 2005-05-04 21:32:25 stephena Exp $
*/
class Menu : public DialogContainer
{
@ -47,7 +47,7 @@ class Menu : public DialogContainer
/**
Updates the basedialog to be of the type defined for this derived class.
*/
void setBaseDialog();
void initialize();
/**
Adds the specified game info to the appropriate menu item