2005-05-04 21:32:25 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
2005-05-16 00:02:32 +00:00
|
|
|
// $Id: DialogContainer.cxx,v 1.4 2005-05-16 00:02:32 stephena Exp $
|
2005-05-04 21:32:25 +00:00
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#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
|
2005-05-13 18:28:06 +00:00
|
|
|
for(int i = 0; i < myDialogStack.size(); i++)
|
2005-05-04 21:32:25 +00:00
|
|
|
{
|
|
|
|
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
|
2005-05-16 00:02:32 +00:00
|
|
|
Dialog* d;
|
2005-05-04 21:32:25 +00:00
|
|
|
while(!myDialogStack.empty())
|
2005-05-16 00:02:32 +00:00
|
|
|
{
|
|
|
|
d = myDialogStack.pop();
|
|
|
|
d->close();
|
|
|
|
}
|
2005-05-04 21:32:25 +00:00
|
|
|
myDialogStack.push(myBaseDialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2005-05-13 18:28:06 +00:00
|
|
|
void DialogContainer::handleKeyEvent(int key, int mod, uInt8 state)
|
2005-05-04 21:32:25 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2005-05-13 18:28:06 +00:00
|
|
|
void DialogContainer::handleMouseMotionEvent(int x, int y, int button)
|
2005-05-04 21:32:25 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2005-05-13 18:28:06 +00:00
|
|
|
void DialogContainer::handleMouseButtonEvent(MouseButton b, int x, int y, uInt8 state)
|
2005-05-04 21:32:25 +00:00
|
|
|
{
|
|
|
|
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
|
2005-05-13 18:28:06 +00:00
|
|
|
int time = myOSystem->getTicks() / 1000; // we only need millisecond precision
|
2005-05-04 21:32:25 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|