More work on implementing an in-game GUI.

git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@378 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-03-10 22:59:40 +00:00
parent 5489ca7248
commit 4e129001cd
16 changed files with 1575 additions and 486 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: makefile,v 1.62 2005-02-27 23:41:17 stephena Exp $
## $Id: makefile,v 1.63 2005-03-10 22:59:39 stephena Exp $
##============================================================================
##============================================================================
@ -41,7 +41,7 @@ OPTIMIZATIONS =
### to build on SMP (or distcc-based) machines
### change to number of CPU's you have
NUMBER_CPU = 3
NUMBER_CPU = 1
##============================================================================
## All done, type make to get a list of frontends
@ -61,9 +61,10 @@ SMP =
SRC = ..
CORE = $(SRC)/emucore
COMMON = $(SRC)/common
GUI = $(SRC)/gui
INCLUDES = -I. -I$(CORE) -I$(CORE)/m6502/src \
-I$(CORE)/m6502/src/bspf/src -I$(COMMON) -I$(SRC)/unix -I$(SRC)/win32
-I$(CORE)/m6502/src/bspf/src -I$(COMMON) -I$(GUI) -I$(SRC)/unix -I$(SRC)/win32
## set some sane optimizations if none have been provided
ifndef OPTIMIZATIONS
@ -152,7 +153,7 @@ CORE_OBJS = Booster.o Cart.o Cart2K.o Cart3F.o Cart4K.o CartAR.o CartDPC.o \
Event.o Joystick.o Keyboard.o M6532.o MD5.o MediaSrc.o Paddles.o \
Props.o PropsSet.o Random.o Sound.o Switches.o Settings.o TIA.o \
Serializer.o Deserializer.o TIASound.o EventHandler.o FrameBuffer.o \
OSystem.o \
OSystem.o Menu.o Widget.o Dialog.o OptionsDialog.o\
$(M6502_OBJS)
stella: $(CORE_OBJS) $(OBJS)
@ -350,3 +351,15 @@ NullDev.o: $(CORE)/m6502/src/NullDev.cxx $(CORE)/m6502/src/NullDev.hxx
System.o: $(CORE)/m6502/src/System.cxx $(CORE)/m6502/src/System.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(CORE)/m6502/src/System.cxx
Menu.o: $(GUI)/Menu.cxx $(GUI)/Menu.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/Menu.cxx
Widget.o: $(GUI)/Widget.cxx $(GUI)/Widget.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/Widget.cxx
Dialog.o: $(GUI)/Dialog.cxx $(GUI)/Dialog.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/Dialog.cxx
OptionsDialog.o: $(GUI)/OptionsDialog.cxx $(GUI)/OptionsDialog.hxx
$(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
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: EventHandler.cxx,v 1.35 2005-02-27 23:41:18 stephena Exp $
// $Id: EventHandler.cxx,v 1.36 2005-03-10 22:59:40 stephena Exp $
//============================================================================
#include <algorithm>
@ -28,6 +28,7 @@
#include "FrameBuffer.hxx"
#include "Sound.hxx"
#include "OSystem.hxx"
#include "Menu.hxx"
#include "bspf.hxx"
#ifdef SNAPSHOT_SUPPORT
@ -111,14 +112,14 @@ void EventHandler::handleKeyEvent(SDLKey key, SDLMod mod, uInt8 state)
if(myState == S_EMULATE)
{
myState = S_MENU;
myOSystem->frameBuffer().showMenu(true); // FIXME - move this into gui class
myOSystem->frameBuffer().refresh();
myOSystem->sound().mute(true);
return;
}
else if(myState == S_MENU)
{
myState = S_EMULATE;
myOSystem->frameBuffer().showMenu(false); // FIXME - move this into gui class
myOSystem->frameBuffer().refresh();
myOSystem->sound().mute(false);
return;
}
@ -137,11 +138,11 @@ void EventHandler::handleKeyEvent(SDLKey key, SDLMod mod, uInt8 state)
break;
case S_MENU:
//FIXME myOSystem->gui().menu().handleKeyEvent(key, mod, state);
myOSystem->menu().handleKeyEvent(key, mod, state);
break;
case S_BROWSER:
//FIXME myOSystem->gui().browser().handleKeyEvent(key, mod, state);
//FIXME myOSystem->browser().handleKeyEvent(key, mod, state);
break;
case S_DEBUGGER:
@ -209,6 +210,7 @@ void EventHandler::handleEvent(Event::Type event, Int32 state)
{
myExitGameFlag = true;
myOSystem->sound().mute(true);
myOSystem->settings().saveConfig();
return;
}
else if(event == Event::Quit)

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: FrameBuffer.cxx,v 1.17 2005-02-27 23:41:19 stephena Exp $
// $Id: FrameBuffer.cxx,v 1.18 2005-03-10 22:59:40 stephena Exp $
//============================================================================
#include <sstream>
@ -26,6 +26,7 @@
#include "Settings.hxx"
#include "MediaSrc.hxx"
#include "FrameBuffer.hxx"
#include "Menu.hxx"
#include "OSystem.hxx"
#include "stella.xpm" // The Stella icon
@ -231,15 +232,15 @@ void FrameBuffer::update()
case EventHandler::S_MENU: // FIXME - this whole thing will disappear into the gui().menu class
{
// Only update the screen if it's been invalidated
// or the menus have changed
// Only update the screen if it's been invalidated or the menus have changed
if(theMenuChangedIndicator || theRedrawEntireFrameIndicator)
{
drawMediaSource();
// Then overlay any menu items
// FIXME myOSystem->gui().menu().draw();
myOSystem->menu().draw();
/*
switch(myCurrentWidget)
{
case W_NONE:
@ -256,7 +257,7 @@ void FrameBuffer::update()
default:
break;
}
*/
// Now the screen is up to date
theRedrawEntireFrameIndicator = false;

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: OSystem.cxx,v 1.4 2005-02-22 20:19:32 stephena Exp $
// $Id: OSystem.cxx,v 1.5 2005-03-10 22:59:40 stephena Exp $
//============================================================================
#include <cassert>
@ -25,18 +25,28 @@
#include "Settings.hxx"
#include "PropsSet.hxx"
#include "EventHandler.hxx"
#include "Menu.hxx"
//#include "Browser.hxx"
#include "bspf.hxx"
#include "OSystem.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OSystem::OSystem()
: myMenu(NULL)
// myBrowser(NULL)
{
// Create gui-related classes
myMenu = new Menu(this);
// myBrowser = new Browser(this);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OSystem::~OSystem()
{
cerr << "OSystem::~OSystem()\n";
delete myMenu;
// delete myBrowser;
// Remove any game console that is currently attached
detachConsole();
}

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: OSystem.hxx,v 1.3 2005-02-22 18:41:12 stephena Exp $
// $Id: OSystem.hxx,v 1.4 2005-03-10 22:59:40 stephena Exp $
//============================================================================
#ifndef OSYSTEM_HXX
@ -24,6 +24,8 @@ class FrameBuffer;
class Sound;
class Settings;
class PropertiesSet;
class Menu;
class Browser;
#include "Console.hxx"
#include "bspf.hxx"
@ -35,7 +37,7 @@ class PropertiesSet;
other objects belong.
@author Stephen Anthony
@version $Id: OSystem.hxx,v 1.3 2005-02-22 18:41:12 stephena Exp $
@version $Id: OSystem.hxx,v 1.4 2005-03-10 22:59:40 stephena Exp $
*/
class OSystem
{
@ -98,6 +100,20 @@ class OSystem
*/
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
@ -140,6 +156,20 @@ class OSystem
*/
Console& console(void) const { return *myConsole; }
/**
Get the settings menu of the system.
@return The settings menu object
*/
Menu& menu(void) const { return *myMenu; }
/**
Get the ROM browser of the system.
@return The browser object
*/
Browser& browser(void) const { return *myBrowser; }
/**
Set the base directory for all configuration files
*/
@ -255,6 +285,12 @@ class OSystem
// Pointer to the (currently defined) Console object
Console* myConsole;
// Pointer to the Menu object
Menu* myMenu;
// Pointer to the Browser object
Browser* myBrowser;
private:
string myBaseDir;
string myStateDir;

View File

@ -0,0 +1,65 @@
//============================================================================
//
// 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: Command.hxx,v 1.1 2005-03-10 22:59:40 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#ifndef COMMAND_HXX
#define COMMAND_HXX
#include "bspf.hxx"
/**
Allows base GUI objects to send and receive commands.
@author Stephen Anthony
@version $Id: Command.hxx,v 1.1 2005-03-10 22:59:40 stephena Exp $
*/
class CommandReceiver;
class CommandSender;
class CommandReceiver
{
friend class CommandSender;
protected:
virtual void handleCommand(CommandSender* sender, uInt32 cmd, uInt32 data) {}
};
class CommandSender
{
// TODO - allow for multiple targets, i.e. store targets in a list
// and add methods addTarget/removeTarget.
public:
CommandSender(CommandReceiver* target)
: _target(target) {}
void setTarget(CommandReceiver* target) { _target = target; }
CommandReceiver* getTarget() const { return _target; }
virtual void sendCommand(uInt32 cmd, uInt32 data)
{
if(_target && cmd)
_target->handleCommand(this, cmd, data);
}
protected:
CommandReceiver* _target;
};
#endif

View File

@ -1,22 +1,23 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2002-2004 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header: /home/stephena/STELLA_CVS-to-SVN/stella/src/gui/Dialog.cxx,v 1.1 2005-02-27 23:41:19 stephena Exp $
*/
//============================================================================
//
// 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: Dialog.cxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#include <ctype.h>
@ -25,8 +26,6 @@
#include "dialog.h"
#include "widget.h"
namespace GUI {
/*
* TODO list
* - add some sense of the window being "active" (i.e. in front) or not. If it
@ -35,243 +34,293 @@ namespace GUI {
* like we have for class Widget?
* ...
*/
Dialog::~Dialog() {
delete _firstWidget;
_firstWidget = 0;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dialog::Dialog(uInt16 x, uInt16 y, uInt16 w, uInt16 h)
: GuiObject(x, y, w, h),
_mouseWidget(0),
_focusedWidget(0),
_visible(false)
{
}
int Dialog::runModal() {
// Open up
open();
// Start processing events
g_gui.runLoop();
// Return the result code
return _result;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dialog::~Dialog()
{
delete _firstWidget;
_firstWidget = 0;
}
void Dialog::open() {
Widget *w = _firstWidget;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int Dialog::runModal()
{
// Open up
open();
_result = 0;
_visible = true;
g_gui.openDialog(this);
// Start processing events
g_gui.runLoop();
// Search for the first objects that wantsFocus() (if any) and give it the focus
while (w && !w->wantsFocus()) {
w = w->_next;
}
if (w) {
w->receivedFocus();
_focusedWidget = w;
}
// Return the result code
return _result;
}
void Dialog::close() {
_visible = false;
g_gui.closeTopDialog();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::open()
{
Widget* w = _firstWidget;
if (_mouseWidget) {
_mouseWidget->handleMouseLeft(0);
_mouseWidget = 0;
}
releaseFocus();
_result = 0;
_visible = true;
g_gui.openDialog(this);
// Search for the first objects that wantsFocus() (if any) and give it the focus
while(w && !w->wantsFocus())
w = w->_next;
if(w)
{
w->receivedFocus();
_focusedWidget = w;
}
}
void Dialog::releaseFocus() {
if (_focusedWidget) {
_focusedWidget->lostFocus();
_focusedWidget = 0;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::close()
{
_visible = false;
g_gui.closeTopDialog();
if (_mouseWidget) {
_mouseWidget->handleMouseLeft(0);
_mouseWidget = 0;
}
releaseFocus();
}
void Dialog::draw() {
g_gui._needRedraw = true;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::releaseFocus()
{
if(_focusedWidget)
{
_focusedWidget->lostFocus();
_focusedWidget = 0;
}
}
void Dialog::drawDialog() {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::draw()
{
g_gui._needRedraw = true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::drawDialog()
{
if(!isVisible())
return;
g_gui.blendRect(_x, _y, _w, _h, g_gui._bgcolor);
g_gui.box(_x, _y, _w, _h, g_gui._color, g_gui._shadowcolor);
// Draw all children
Widget* w = _firstWidget;
while(w)
{
w->draw();
w = w->_next;
}
// Flag the draw area as dirty
g_gui.addDirtyRect(_x, _y, _w, _h);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleMouseDown(int x, int y, int button, int clickCount)
{
Widget* w;
w = findWidget(x, y);
// If the click occured inside a widget which is not the currently
// focused one, change the focus to that widget.
// TODO: use the wantsFocus() method to objects, so that only fields
// that want it get the focus (like edit fields, list field...)
// However, right now we "abuse" the focus also for the click&drag
// behaviour of buttons. This should probably be changed by adding
// a nother field, e.g. _clickedWidget or _dragWidget.
if(w && w != _focusedWidget)
{
// The focus will change. Tell the old focused widget (if any)
// that it lost the focus.
releaseFocus();
// Tell the new focused widget (if any) that it just gained the focus.
if(w)
w->receivedFocus();
_focusedWidget = w;
}
if(w && w == _focusedWidget)
_focusedWidget->handleMouseDown(x - (_focusedWidget->getAbsX() - _x), y - (_focusedWidget->getAbsY() - _y), button, clickCount);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleMouseUp(int x, int y, int button, int clickCount)
{
Widget* w;
if(_focusedWidget)
{
w = _focusedWidget;
// Lose focus on mouseup unless the widget requested to retain the focus
if(! (_focusedWidget->getFlags() & WIDGET_RETAIN_FOCUS ))
releaseFocus();
}
else
w = findWidget(x, y);
if(w)
w->handleMouseUp(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y), button, clickCount);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleMouseWheel(int x, int y, int direction)
{
Widget* w;
// This may look a bit backwards, but I think it makes more sense for
// the mouse wheel to primarily affect the widget the mouse is at than
// the widget that happens to be focused.
w = findWidget(x, y);
if(!w)
w = _focusedWidget;
if (w)
w->handleMouseWheel(x, y, direction);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)
{
if(_focusedWidget)
if (_focusedWidget->handleKeyDown(ascii, keycode, modifiers))
return;
// Hotkey handling
if(ascii != 0)
{
Widget* w = _firstWidget;
ascii = toupper(ascii);
while(w)
{
if(w->_type == kButtonWidget && ascii == toupper(((ButtonWidget *)w)->_hotkey))
{
// The hotkey for widget w was pressed. We fake a mouse click into the
// button by invoking the appropriate methods.
w->handleMouseDown(0, 0, 1, 1);
w->handleMouseUp(0, 0, 1, 1);
return;
}
w = w->_next;
}
}
// ESC closes all dialogs by default
if (keycode == 27) {
setResult(-1);
close();
}
// TODO: tab/shift-tab should focus the next/previous focusable widget
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleKeyUp(uint16 ascii, int keycode, int modifiers)
{
// Focused widget receives keyup events
if(_focusedWidget)
_focusedWidget->handleKeyUp(ascii, keycode, modifiers);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleMouseMoved(int x, int y, int button)
{
Widget* w;
if (!isVisible())
return;
g_gui.blendRect(_x, _y, _w, _h, g_gui._bgcolor);
g_gui.box(_x, _y, _w, _h, g_gui._color, g_gui._shadowcolor);
// Draw all children
Widget *w = _firstWidget;
while (w) {
w->draw();
w = w->_next;
}
// Flag the draw area as dirty
g_gui.addDirtyRect(_x, _y, _w, _h);
}
void Dialog::handleMouseDown(int x, int y, int button, int clickCount) {
Widget *w;
w = findWidget(x, y);
// If the click occured inside a widget which is not the currently
// focused one, change the focus to that widget.
// TODO: use the wantsFocus() method to objects, so that only fields
// that want it get the focus (like edit fields, list field...)
// However, right now we "abuse" the focus also for the click&drag
// behaviour of buttons. This should probably be changed by adding
// a nother field, e.g. _clickedWidget or _dragWidget.
if (w && w != _focusedWidget) {
// The focus will change. Tell the old focused widget (if any)
// that it lost the focus.
releaseFocus();
// Tell the new focused widget (if any) that it just gained the focus.
if (w)
w->receivedFocus();
_focusedWidget = w;
}
if (w && w == _focusedWidget)
_focusedWidget->handleMouseDown(x - (_focusedWidget->getAbsX() - _x), y - (_focusedWidget->getAbsY() - _y), button, clickCount);
}
void Dialog::handleMouseUp(int x, int y, int button, int clickCount) {
Widget *w;
if (_focusedWidget) {
w = _focusedWidget;
if(_focusedWidget)
{
w = _focusedWidget;
int wx = w->getAbsX() - _x;
int wy = w->getAbsY() - _y;
// Lose focus on mouseup unless the widget requested to retain the focus
if (! (_focusedWidget->getFlags() & WIDGET_RETAIN_FOCUS )) {
releaseFocus();
}
// We still send mouseEntered/Left messages to the focused item
// (but to no other items).
bool mouseInFocusedWidget = (x >= wx && x < wx + w->_w && y >= wy && y < wy + w->_h);
if(mouseInFocusedWidget && _mouseWidget != w)
{
_mouseWidget = w;
w->handleMouseEntered(button);
}
else if (!mouseInFocusedWidget && _mouseWidget == w)
{
_mouseWidget = 0;
w->handleMouseLeft(button);
}
} else {
w = findWidget(x, y);
}
w->handleMouseMoved(x - wx, y - wy, button);
}
if (w)
w->handleMouseUp(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y), button, clickCount);
w = findWidget(x, y);
if(_mouseWidget != w)
{
if(_mouseWidget)
_mouseWidget->handleMouseLeft(button);
if(w)
w->handleMouseEntered(button);
_mouseWidget = w;
}
if(!w || !(w->getFlags() & WIDGET_TRACK_MOUSE))
return;
w->handleMouseMoved(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y), button);
}
void Dialog::handleMouseWheel(int x, int y, int direction) {
Widget *w;
// This may look a bit backwards, but I think it makes more sense for
// the mouse wheel to primarily affect the widget the mouse is at than
// the widget that happens to be focused.
w = findWidget(x, y);
if (!w)
w = _focusedWidget;
if (w)
w->handleMouseWheel(x, y, direction);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleTickle()
{
// Focused widget receives tickle notifications
if(_focusedWidget && _focusedWidget->getFlags() & WIDGET_WANT_TICKLE)
_focusedWidget->handleTickle();
}
void Dialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
if (_focusedWidget) {
if (_focusedWidget->handleKeyDown(ascii, keycode, modifiers))
return;
}
// Hotkey handling
if (ascii != 0) {
Widget *w = _firstWidget;
ascii = toupper(ascii);
while (w) {
if (w->_type == kButtonWidget && ascii == toupper(((ButtonWidget *)w)->_hotkey)) {
// The hotkey for widget w was pressed. We fake a mouse click into the
// button by invoking the appropriate methods.
w->handleMouseDown(0, 0, 1, 1);
w->handleMouseUp(0, 0, 1, 1);
return;
}
w = w->_next;
}
}
// ESC closes all dialogs by default
if (keycode == 27) {
setResult(-1);
close();
}
// TODO: tab/shift-tab should focus the next/previous focusable widget
}
void Dialog::handleKeyUp(uint16 ascii, int keycode, int modifiers) {
// Focused widget receives keyup events
if (_focusedWidget)
_focusedWidget->handleKeyUp(ascii, keycode, modifiers);
}
void Dialog::handleMouseMoved(int x, int y, int button) {
Widget *w;
if (_focusedWidget) {
w = _focusedWidget;
int wx = w->getAbsX() - _x;
int wy = w->getAbsY() - _y;
// We still send mouseEntered/Left messages to the focused item
// (but to no other items).
bool mouseInFocusedWidget = (x >= wx && x < wx + w->_w && y >= wy && y < wy + w->_h);
if (mouseInFocusedWidget && _mouseWidget != w) {
_mouseWidget = w;
w->handleMouseEntered(button);
} else if (!mouseInFocusedWidget && _mouseWidget == w) {
_mouseWidget = 0;
w->handleMouseLeft(button);
}
w->handleMouseMoved(x - wx, y - wy, button);
}
w = findWidget(x, y);
if (_mouseWidget != w) {
if (_mouseWidget)
_mouseWidget->handleMouseLeft(button);
if (w)
w->handleMouseEntered(button);
_mouseWidget = w;
}
if (!w || !(w->getFlags() & WIDGET_TRACK_MOUSE)) {
return;
}
w->handleMouseMoved(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y), button);
}
void Dialog::handleTickle() {
// Focused widget receives tickle notifications
if (_focusedWidget && _focusedWidget->getFlags() & WIDGET_WANT_TICKLE) {
_focusedWidget->handleTickle();
}
}
void Dialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
case kCloseCmd:
close();
break;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleCommand(CommandSender* sender, uint32 cmd, uint32 data)
{
switch(cmd)
{
case kCloseCmd:
close();
break;
}
}
/*
* Determine the widget at location (x,y) if any. Assumes the coordinates are
* in the local coordinate system, i.e. relative to the top left of the dialog.
*/
Widget *Dialog::findWidget(int x, int y) {
return Widget::findWidgetInChain(_firstWidget, x, y);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Widget* Dialog::findWidget(int x, int y)
{
return Widget::findWidgetInChain(_firstWidget, x, y);
}
ButtonWidget *Dialog::addButton(int x, int y, const Common::String &label, uint32 cmd, char hotkey) {
return new ButtonWidget(this, x, y, kButtonWidth, 16, label, cmd, hotkey);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ButtonWidget* Dialog::addButton(int x, int y, const string &label,
uint32 cmd, char hotkey)
{
return new ButtonWidget(this, x, y, kButtonWidth, 16, label, cmd, hotkey);
}
} // End of namespace GUI

View File

@ -13,75 +13,74 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Dialog.hxx,v 1.1 2005-02-27 23:41:19 stephena Exp $
// $Id: Dialog.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#ifndef DIALOG_HXX
#define DIALOG_HXX
#include <SDL.h>
#include "Command.hxx"
#include "Widget.hxx"
#include "GuiObject.hxx"
#include "bspf.hxx"
#include "common/scummsys.h"
#include "common/str.h"
#include "gui/object.h"
/**
This is the base class for all dialog boxes.
@author Stephen Anthony
@version $Id: Dialog.hxx,v 1.1 2005-02-27 23:41:19 stephena Exp $
@version $Id: Dialog.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
*/
class Dialog
{
public:
Dialog(uInt16 x, uInt16 y, uInt16 w, uInt16 h)
: GuiObject(x, y, w, h),
_mouseWidget(0), _focusedWidget(0), _visible(false) {
}
virtual ~Dialog();
Dialog(uInt16 x, uInt16 y, uInt16 w, uInt16 h);
virtual int runModal();
virtual ~Dialog();
bool isVisible() const { return _visible; }
virtual int runModal();
void releaseFocus();
bool isVisible() const { return _visible; }
protected:
virtual void open();
virtual void close();
void releaseFocus();
virtual void drawDialog();
virtual void handleKeyDown(SDLKey key, SDLMod mod);
virtual void handleKeyUp(SDLKey key, SDLMod mod);
protected:
virtual void open();
virtual void close();
virtual void draw();
virtual void handleTickle(); // Called periodically (in every guiloop() )
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual void handleMouseUp(int x, int y, int button, int clickCount);
virtual void handleMouseWheel(int x, int y, int direction);
virtual void handleMouseMoved(int x, int y, int button);
virtual void handleCommand(CommandSender* sender, uInt32 cmd, uInt32 data);
virtual void handleScreenChanged() {}
virtual void draw();
virtual void drawDialog();
Widget* findWidget(int x, int y); // Find the widget at pos x,y if any
virtual void handleTickle(); // Called periodically (in every guiloop() )
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual void handleMouseUp(int x, int y, int button, int clickCount);
virtual void handleMouseWheel(int x, int y, int direction);
virtual void handleKeyDown(uint16 ascii, int keycode, int modifiers);
virtual void handleKeyUp(uint16 ascii, int keycode, int modifiers);
virtual void handleMouseMoved(int x, int y, int button);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
virtual void handleScreenChanged() {}
Widget *findWidget(int x, int y); // Find the widget at pos x,y if any
ButtonWidget* addButton(int x, int y, const string& label, uInt32 cmd, char hotkey);
ButtonWidget *addButton(int x, int y, const Common::String &label, uint32 cmd, char hotkey);
void setResult(int result) { _result = result; }
int getResult() const { return _result; }
void setResult(int result) { _result = result; }
int getResult() const { return _result; }
protected:
Widget *_mouseWidget;
Widget *_focusedWidget;
bool _visible;
private:
int _result;
protected:
Widget* _mouseWidget;
Widget* _focusedWidget;
bool _visible;
private:
int _result;
};
} // End of namespace GUI
#endif

View File

@ -13,7 +13,10 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: GuiObject.hxx,v 1.1 2005-02-27 23:41:19 stephena Exp $
// $Id: GuiObject.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#ifndef GUI_OBJECT_HXX
@ -21,20 +24,26 @@
class Widget;
#include "Command.hxx"
#include "bspf.hxx"
/**
This is the base class for all GUI objects/widgets.
@author Stephen Anthony
@version $Id: GuiObject.hxx,v 1.1 2005-02-27 23:41:19 stephena Exp $
@version $Id: GuiObject.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
*/
class GuiObject
class GuiObject : public CommandReceiver
{
//friend class Widget;
friend class Widget;
public:
GuiObject(int x, int y, int w, int h) : _x(x), _y(y), _w(w), _h(h), _firstWidget(0) { }
GuiObject(int x, int y, int w, int h)
: _x(x),
_y(y),
_w(w),
_h(h),
_firstWidget(0) { }
virtual Int16 getAbsX() const { return _x; }
virtual Int16 getAbsY() const { return _y; }
@ -44,7 +53,6 @@ class GuiObject
virtual uInt16 getHeight() const { return _h; }
virtual bool isVisible() const = 0;
virtual void draw() = 0;
protected:

View File

@ -13,35 +13,88 @@
// 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.1 2005-02-27 23:41:19 stephena Exp $
// $Id: Menu.cxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
//============================================================================
#include <SDL.h>
#include "OSystem.hxx"
#include "Dialog.hxx"
#include "OptionsDialog.hxx"
#include "Stack.hxx"
#include "bspf.hxx"
#include "Menu.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Menu::Menu()
Menu::Menu(OSystem* osystem)
: myOSystem(osystem),
myOptionsDialog(NULL)
{
#ifdef DEBUG
cerr << "Menu::Menu()\n";
#endif
myOSystem->attach(this);
// Create a stack to hold the various dialog boxes
// Create the top-level menu
myOptionsDialog = new OptionsDialog(myOSystem);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Menu::~Menu()
{
#ifdef DEBUG
cerr << "Menu::~Menu()\n";
}
#endif
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::handleKeyEvent(SDLKey key, SDLMod mod, uInt8 state)
{
cerr << "Menu::handleKeyEvent()\n";
delete myOptionsDialog;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::draw()
{
#ifdef DEBUG
cerr << "Menu::draw()\n";
#endif
// Draw all the dialogs on the stack
for(Int32 i = 0; i < myDialogStack.size(); i++)
myDialogStack[i]->drawDialog();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::addDialog(Dialog* d)
{
myDialogStack.push(d);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::removeDialog()
{
if(!myDialogStack.empty())
myDialogStack.pop();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::reset()
{
// Pop all items from the stack, and then add the base menu
for(Int32 i = 0; i < myDialogStack.size(); i++)
myDialogStack.pop();
myDialogStack.push(myOptionsDialog);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Menu::handleKeyEvent(SDLKey key, SDLMod mod, uInt8 state)
{
// Send the event to the dialog box on the top of the stack
Dialog* activeDialog = myDialogStack.top();
if(state == 1)
activeDialog->handleKeyDown(key, mod);
else
activeDialog->handleKeyUp(key, mod);
}

View File

@ -13,14 +13,21 @@
// 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.1 2005-02-27 23:41:19 stephena Exp $
// $Id: Menu.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
//============================================================================
#ifndef MENU_HXX
#define MENU_HXX
class Dialog;
class OSystem;
class OptionsDialog;
#include "Stack.hxx"
#include "bspf.hxx"
typedef FixedStack<Dialog *> DialogStack;
/**
The base class for all menus in Stella.
@ -28,7 +35,7 @@
a stack, and handles their events.
@author Stephen Anthony
@version $Id: Menu.hxx,v 1.1 2005-02-27 23:41:19 stephena Exp $
@version $Id: Menu.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
*/
class Menu
{
@ -36,7 +43,7 @@ class Menu
/**
Create a new menu stack
*/
Menu();
Menu(OSystem* osystem);
/**
Destructor
@ -60,8 +67,25 @@ class Menu
*/
void draw();
private:
/**
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 reset();
private:
OSystem* myOSystem;
OptionsDialog* myOptionsDialog;
DialogStack myDialogStack;
};
#endif

View File

@ -0,0 +1,638 @@
//============================================================================
//
// 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: OptionsDialog.cxx,v 1.1 2005-03-10 22:59:40 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#include "stdafx.h"
#include "common/config-manager.h"
#include "gui/chooser.h"
#include "gui/newgui.h"
#include "gui/ListWidget.h"
#include "scumm/dialogs.h"
#include "scumm/sound.h"
#include "scumm/scumm.h"
#include "scumm/imuse.h"
#include "scumm/imuse_digi/dimuse.h"
#include "scumm/player_v2.h"
#include "scumm/verbs.h"
#include "sound/mididrv.h"
#include "sound/mixer.h"
#ifndef DISABLE_HELP
#include "scumm/help.h"
#endif
#ifdef _WIN32_WCE
#include "backends/wince/CEKeysDialog.h"
#endif
/* FIXME
// Now create all the dialogs attached to each menu button
myVideoDialog = new VideoDialog(myOSystem);
myAudioDialog = new AudioDialog(myOSystem);
myEventMappingDialog = new EventMappingDialog(myOSystem);
myMiscDialog = new MiscDialog(myOSystem);
myGameInfoDialog = new GameInfoDialog(myOSystem);
myHelpDialog = new HelpDialog(myOSystem);
*/
/* FIXME
delete myVideoDialog;
delete myAudioDialog;
delete myEventMappingDialog;
delete myMiscDialog;
delete myGameInfoDialog;
delete myHelpDialog;
*/
using GUI::CommandSender;
using GUI::StaticTextWidget;
using GUI::kButtonWidth;
using GUI::kCloseCmd;
using GUI::kTextAlignCenter;
using GUI::kTextAlignLeft;
using GUI::WIDGET_ENABLED;
typedef GUI::OptionsDialog GUI_OptionsDialog;
typedef GUI::ChooserDialog GUI_ChooserDialog;
namespace Scumm {
struct ResString {
int num;
char string[80];
};
#ifdef __PALM_OS__
static ResString *string_map_table_v7;
static ResString *string_map_table_v6;
static ResString *string_map_table_v5;
#else
static ResString string_map_table_v7[] = {
{96, "game name and version"}, //that's how it's supposed to be
{77, "Select a game to LOAD"},
{76, "Name your SAVE game"},
{70, "save"}, //boot8
{71, "load"}, //boot9
{72, "play"}, //boot10
{73, "cancel"}, //boot11
{74, "quit"}, //boot12
{75, "ok"}, //boot13
{85, "game paused"}, // boot3
{96, "the dig v1.0"},
/* this is the almost complete string map for v7
{63, "how may I serve you?"},
{64, "the dig v1.0"}, //(game name/version)
{67, "text display only"},
{68, "c:\\dig"}, //boot007 (save path ?)
{69, "the dig"}, //boot21 (game name)
{70, "save"}, //boot8
{71, "load"}, //boot9
{72, "play"}, //boot10
{73, "cancel"}, //boot11
{74, "quit"}, //boot12
{75, "ok"}, //boot13
{76, "name your save game"}, //boot19
{77, "select a game to load"}, //boot20
{78, "you must enter a name"},//boot14
{79, "saving '%s'"}, //boot17
{80, "loading '%s'"}, //boot18
{81, "the game was NOT saved"}, //boot15
{82, "the game was NOT loaded"}, //boot16
{83, "how may I serve you?"},
{84, "how may I serve you?"},
{85, "game paused"}, // boot3
{86, "Are you sure you want to restart"},
{87, "Are you sure you want to quit?"}, //boot05
{89, "how may I serve you?"},
{90, "music"}, //boot22
{91, "voice"}, //boot23
{92, "sfx"}, //boot24
{93, "disabled"}, //boot25
{94, "text speed"}, //boot26
{95, "text display"}, //boot27
{96, "the dig v1.0"},*/
};
static ResString string_map_table_v6[] = {
{117, "How may I serve you?"},
{109, "Select a game to LOAD"},
{108, "Name your SAVE game"},
{96, "Save"},
{97, "Load"},
{98, "Play"},
{99, "Cancel"},
{100, "Quit"},
{101, "OK"},
{93, "Game paused"},
{210, "Game version"}
};
static ResString string_map_table_v5[] = {
{28, "How may I serve you?"},
{20, "Select a game to LOAD"},
{19, "Name your SAVE game"},
{7, "Save"},
{8, "Load"},
{9, "Play"},
{10, "Cancel"},
{11, "Quit"},
{12, "OK"},
{4, "Game paused"}
};
#endif
#pragma mark -
const Common::String ScummDialog::queryResString(int stringno) {
byte buf[256];
byte *result;
if (stringno == 0)
return String();
if (_vm->_version >= 7)
result = _vm->getStringAddressVar(string_map_table_v7[stringno - 1].num);
else if (_vm->_version == 6)
result = _vm->getStringAddressVar(string_map_table_v6[stringno - 1].num);
else if (_vm->_version == 5)
result = _vm->getStringAddress(string_map_table_v5[stringno - 1].num);
else
// TODO: For V8 games, maybe grab the strings from the language file?
return string_map_table_v5[stringno - 1].string;
if (result && *result == '/') {
_vm->translateText(result, buf);
result = buf;
}
if (!result || *result == '\0') { // Gracelessly degrade to english :)
return string_map_table_v5[stringno - 1].string;
}
// Convert to a proper string (take care of FF codes)
byte chr;
String tmp;
while ((chr = *result++)) {
if (chr == 0xFF) {
result += 3;
} else if (chr != '@') {
tmp += chr;
}
}
return tmp;
}
#pragma mark -
enum {
kSaveCmd = 'SAVE',
kLoadCmd = 'LOAD',
kPlayCmd = 'PLAY',
kOptionsCmd = 'OPTN',
kHelpCmd = 'HELP',
kAboutCmd = 'ABOU',
kQuitCmd = 'QUIT'
};
class SaveLoadChooser : public GUI::ChooserDialog {
typedef Common::String String;
typedef Common::StringList StringList;
protected:
bool _saveMode;
public:
SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
const String &getResultString() const;
};
SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode)
: GUI::ChooserDialog(title, buttonLabel, 182), _saveMode(saveMode) {
_list->setEditable(saveMode);
_list->setNumberingMode(saveMode ? GUI::kListNumberingOne : GUI::kListNumberingZero);
}
const Common::String &SaveLoadChooser::getResultString() const {
return _list->getSelectedString();
}
void SaveLoadChooser::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
int selItem = _list->getSelected();
switch (cmd) {
case GUI::kListItemActivatedCmd:
case GUI::kListItemDoubleClickedCmd:
if (selItem >= 0) {
if (_saveMode || !getResultString().isEmpty()) {
setResult(selItem);
close();
}
}
break;
case GUI::kListSelectionChangedCmd:
if (_saveMode) {
_list->startEditMode();
}
// Disable button if nothing is selected, or (in load mode) if an empty
// list item is selected. We allow choosing an empty item in save mode
// because we then just assign a default name.
_chooseButton->setEnabled(selItem >= 0 && (_saveMode || !getResultString().isEmpty()));
_chooseButton->draw();
break;
default:
GUI_ChooserDialog::handleCommand(sender, cmd, data);
}
}
Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode) {
// Get savegame names
Common::StringList l;
char name[32];
uint i = saveMode ? 1 : 0;
bool avail_saves[81];
scumm->listSavegames(avail_saves, ARRAYSIZE(avail_saves));
for (; i < ARRAYSIZE(avail_saves); i++) {
if (avail_saves[i])
scumm->getSavegameName(i, name);
else
name[0] = 0;
l.push_back(name);
}
return l;
}
enum {
kRowHeight = 18,
kBigButtonWidth = 90,
kMainMenuWidth = (kBigButtonWidth + 2 * 8),
kMainMenuHeight = 7 * kRowHeight + 3 * 5 + 7 + 5
};
#define addBigButton(label, cmd, hotkey) \
new GUI::ButtonWidget(this, x, y, kBigButtonWidth, 16, label, cmd, hotkey); y += kRowHeight
MainMenuDialog::MainMenuDialog(ScummEngine *scumm)
: ScummDialog(scumm, (320 - kMainMenuWidth) / 2, (200 - kMainMenuHeight)/2, kMainMenuWidth, kMainMenuHeight) {
int y = 7;
const int x = (_w - kBigButtonWidth) / 2;
addBigButton("Resume", kPlayCmd, 'P');
y += 5;
addBigButton("Load", kLoadCmd, 'L');
addBigButton("Save", kSaveCmd, 'S');
y += 5;
addBigButton("Options", kOptionsCmd, 'O');
#ifndef DISABLE_HELP
addBigButton("Help", kHelpCmd, 'H');
#endif
addBigButton("About", kAboutCmd, 'A');
y += 5;
addBigButton("Quit", kQuitCmd, 'Q');
//
// Create the sub dialog(s)
//
_aboutDialog = new GUI::AboutDialog();
#ifndef DISABLE_HELP
_helpDialog = new HelpDialog(scumm);
#endif
_saveDialog = new SaveLoadChooser("Save game:", "Save", true);
_loadDialog = new SaveLoadChooser("Load game:", "Load", false);
}
MainMenuDialog::~MainMenuDialog() {
delete _aboutDialog;
#ifndef DISABLE_HELP
delete _helpDialog;
#endif
delete _saveDialog;
delete _loadDialog;
}
void MainMenuDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
case kSaveCmd:
save();
break;
case kLoadCmd:
load();
break;
case kPlayCmd:
close();
break;
case kOptionsCmd:
_vm->optionsDialog();
break;
case kAboutCmd:
_aboutDialog->runModal();
break;
#ifndef DISABLE_HELP
case kHelpCmd:
_helpDialog->runModal();
break;
#endif
case kQuitCmd:
_vm->_quit = true;
close();
break;
default:
ScummDialog::handleCommand(sender, cmd, data);
}
}
void MainMenuDialog::save() {
int idx;
_saveDialog->setList(generateSavegameList(_vm, true));
g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);
idx = _saveDialog->runModal();
g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
if (idx >= 0) {
const String &result = _saveDialog->getResultString();
char buffer[20];
const char *str;
if (result.isEmpty()) {
// If the user was lazy and entered no save name, come up with a default name.
sprintf(buffer, "Save %d", idx + 1);
str = buffer;
} else
str = result.c_str();
_vm->requestSave(idx + 1, str);
close();
}
}
void MainMenuDialog::load() {
int idx;
_loadDialog->setList(generateSavegameList(_vm, false));
idx = _loadDialog->runModal();
if (idx >= 0) {
_vm->requestLoad(idx);
close();
}
}
#pragma mark -
enum {
kOKCmd = 'ok '
};
enum {
kKeysCmd = 'KEYS'
};
#ifndef _WIN32_WCE
ConfigDialog::ConfigDialog(ScummEngine *scumm)
: GUI::OptionsDialog("", 40, 30, 240, 124), _vm(scumm) {
#else
ConfigDialog::ConfigDialog(ScummEngine *scumm)
: GUI::OptionsDialog("", 40, 30, 240, 124 + 4), _vm(scumm) {
#endif
//
// Add the buttons
//
#ifdef _WIN32_WCE
addButton(_w - kButtonWidth - 8, _h - 24 - 4, "OK", GUI::OptionsDialog::kOKCmd, 'O');
addButton(_w - 2 * kButtonWidth - 12, _h - 24 - 4, "Cancel", kCloseCmd, 'C');
addButton(_w - 3 * kButtonWidth - 16, _h - 24 - 4, "Keys", kKeysCmd, 'K');
#else
addButton(_w - kButtonWidth-8, _h - 24, "OK", GUI::OptionsDialog::kOKCmd, 'O');
addButton(_w - 2 * kButtonWidth-12, _h - 24, "Cancel", kCloseCmd, 'C');
#endif
//
// Sound controllers
//
int yoffset = 8;
yoffset = addVolumeControls(this, yoffset);
//
// Some misc options
//
subtitlesCheckbox = new GUI::CheckboxWidget(this, 15, 78, 200, 16, "Show subtitles", 0, 'S');
//
// Create the sub dialog(s)
//
#ifdef _WIN32_WCE
_keysDialog = new CEKeysDialog();
#endif
}
ConfigDialog::~ConfigDialog() {
#ifdef _WIN32_WCE
delete _keysDialog;
#endif
}
void ConfigDialog::open() {
GUI_OptionsDialog::open();
// update checkboxes, too
subtitlesCheckbox->setState(ConfMan.getBool("subtitles"));
}
void ConfigDialog::close() {
if (getResult()) {
// Subtitles
ConfMan.set("subtitles", subtitlesCheckbox->getState(), _domain);
// Sync with current setting
if (_vm->_version >= 7)
_vm->VAR(_vm->VAR_VOICE_MODE) = subtitlesCheckbox->getState();
}
GUI_OptionsDialog::close();
_vm->setupVolumes();
}
void ConfigDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
case kKeysCmd:
#ifdef _WIN32_WCE
_keysDialog->runModal();
#endif
break;
default:
GUI_OptionsDialog::handleCommand (sender, cmd, data);
}
}
#ifndef DISABLE_HELP
#pragma mark -
enum {
kNextCmd = 'NEXT',
kPrevCmd = 'PREV'
};
HelpDialog::HelpDialog(ScummEngine *scumm)
: ScummDialog(scumm, 5, 5, 310, 190) {
_page = 1;
_numPages = ScummHelp::numPages(scumm->_gameId);
_prevButton = addButton(10, 170, "Previous", kPrevCmd, 'P');
_nextButton = addButton(90, 170, "Next", kNextCmd, 'N');
addButton(210, 170, "Close", kCloseCmd, 'C');
_prevButton->clearFlags(WIDGET_ENABLED);
_title = new StaticTextWidget(this, 10, 5, 290, 16, "", kTextAlignCenter);
for (int i = 0; i < HELP_NUM_LINES; i++) {
_key[i] = new StaticTextWidget(this, 10, 18 + (10 * i), 80, 16, "", kTextAlignLeft);
_dsc[i] = new StaticTextWidget(this, 90, 18 + (10 * i), 210, 16, "", kTextAlignLeft);
}
displayKeyBindings();
}
void HelpDialog::displayKeyBindings() {
String titleStr, *keyStr, *dscStr;
ScummHelp::updateStrings(_vm->_gameId, _vm->_version, _page, titleStr, keyStr, dscStr);
_title->setLabel(titleStr);
for (int i = 0; i < HELP_NUM_LINES; i++) {
_key[i]->setLabel(keyStr[i]);
_dsc[i]->setLabel(dscStr[i]);
}
delete [] keyStr;
delete [] dscStr;
}
void HelpDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
case kNextCmd:
_page++;
if (_page >= _numPages) {
_nextButton->clearFlags(WIDGET_ENABLED);
}
if (_page >= 2) {
_prevButton->setFlags(WIDGET_ENABLED);
}
displayKeyBindings();
draw();
break;
case kPrevCmd:
_page--;
if (_page <= _numPages) {
_nextButton->setFlags(WIDGET_ENABLED);
}
if (_page <= 1) {
_prevButton->clearFlags(WIDGET_ENABLED);
}
displayKeyBindings();
draw();
break;
default:
ScummDialog::handleCommand(sender, cmd, data);
}
}
#endif
#pragma mark -
InfoDialog::InfoDialog(ScummEngine *scumm, int res)
: ScummDialog(scumm, 0, 80, 0, 16) { // dummy x and w
setInfoText(queryResString (res));
}
InfoDialog::InfoDialog(ScummEngine *scumm, const String& message)
: ScummDialog(scumm, 0, 80, 0, 16) { // dummy x and w
setInfoText(message);
}
void InfoDialog::setInfoText(const String& message) {
int width = g_gui.getStringWidth(message) + 16;
_x = (_vm->_screenWidth - width) >> 1;
_w = width;
new StaticTextWidget(this, 4, 4, _w - 8, _h, message, kTextAlignCenter);
}
#pragma mark -
PauseDialog::PauseDialog(ScummEngine *scumm, int res)
: InfoDialog(scumm, res) {
}
void PauseDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
if (ascii == ' ') // Close pause dialog if space key is pressed
close();
else
ScummDialog::handleKeyDown(ascii, keycode, modifiers);
}
ConfirmDialog::ConfirmDialog(ScummEngine *scumm, const String& message)
: InfoDialog(scumm, message) {
}
void ConfirmDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
if (tolower(ascii) == 'n') {
setResult(0);
close();
} else if (tolower(ascii) == 'y') {
setResult(1);
close();
} else
ScummDialog::handleKeyDown(ascii, keycode, modifiers);
}
} // End of namespace Scumm
#ifdef __PALM_OS__
#include "scumm_globals.h"
_GINIT(Dialogs)
_GSETPTR(Scumm::string_map_table_v7, GBVARS_STRINGMAPTABLEV7_INDEX, Scumm::ResString, GBVARS_SCUMM)
_GSETPTR(Scumm::string_map_table_v6, GBVARS_STRINGMAPTABLEV6_INDEX, Scumm::ResString, GBVARS_SCUMM)
_GSETPTR(Scumm::string_map_table_v5, GBVARS_STRINGMAPTABLEV5_INDEX, Scumm::ResString, GBVARS_SCUMM)
_GEND
_GRELEASE(Dialogs)
_GRELEASEPTR(GBVARS_STRINGMAPTABLEV7_INDEX, GBVARS_SCUMM)
_GRELEASEPTR(GBVARS_STRINGMAPTABLEV6_INDEX, GBVARS_SCUMM)
_GRELEASEPTR(GBVARS_STRINGMAPTABLEV5_INDEX, GBVARS_SCUMM)
_GEND
#endif

View File

@ -0,0 +1,54 @@
//============================================================================
//
// 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: OptionsDialog.hxx,v 1.1 2005-03-10 22:59:40 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#ifndef OPTIONS_DIALOG_HXX
#define OPTIONS_DIALOG_HXX
class CommandSender;
class Dialog;
class VideoDialog;
class AudioDialog;
class EventMappingDialog;
class MiscDialog;
class GameInfoDialog;
class HelpDialog;
#include "OSystem.hxx"
#include "bspf.hxx"
class OptionsDialog : public Dialog
{
public:
OptionsDialog(OSystem* osystem);
~OptionsDialog();
virtual void handleCommand(CommandSender* sender, uInt32 cmd, uInt32 data);
protected:
VideoDialog* myVideoDialog;
AudioDialog* myAudioDialog;
EventMappingDialog* myEventMappingDialog;
MiscDialog* myMiscDialog;
GameInfoDialog* myGameInfoDialog;
HelpDialog* myHelpDialog;
};
#endif

70
stella/src/gui/Stack.hxx Normal file
View File

@ -0,0 +1,70 @@
//============================================================================
//
// 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: Stack.hxx,v 1.1 2005-03-10 22:59:40 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#ifndef STACK_HXX
#define STACK_HXX
#include <assert.h>
/**
* Extremly simple fixed size stack class.
*/
template <class T, int MAX_SIZE = 10>
class FixedStack
{
public:
FixedStack<T, MAX_SIZE>() : _size(0) {}
bool empty() const { return _size <= 0; }
void clear() { _size = 0; }
void push(const T& x)
{
assert(_size < MAX_SIZE);
_stack[_size++] = x;
}
T top() const
{
if(_size > 0)
return _stack[_size - 1];
else
return 0;
}
T pop()
{
T tmp;
assert(_size > 0);
tmp = _stack[_size - 1];
_stack[--_size] = 0;
return tmp;
}
int size() const { return _size; }
T operator [](int i)
{
assert(0 <= i && i < MAX_SIZE);
return _stack[i];
}
protected:
T _stack[MAX_SIZE];
int _size;
};
#endif

View File

@ -13,7 +13,10 @@
// 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.1 2005-02-27 23:41:19 stephena Exp $
// $Id: Widget.cxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#include "Dialog.hxx"
@ -24,8 +27,12 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Widget::Widget(GuiObject* boss, uInt32 x, uInt32 y, uInt32 w, uInt32 h)
: GuiObject(x, y, w, h), _type(0), _boss(boss),
_id(0), _flags(0), _hasFocus(false)
: GuiObject(x, y, w, h),
_type(0),
_boss(boss),
_id(0),
_flags(0),
_hasFocus(false)
{
// Insert into the widget list of the boss
_next = _boss->_firstWidget;
@ -41,116 +48,135 @@ Widget::~Widget()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Widget::draw()
{
NewGui *gui = &g_gui;
FrameBuffer* fb = _boss->instance().frameBuffer();
if (!isVisible() || !_boss->isVisible())
return;
if(!isVisible() || !_boss->isVisible())
return;
int oldX = _x, oldY = _y;
int oldX = _x, oldY = _y;
// Account for our relative position in the dialog
_x = getAbsX();
_y = getAbsY();
// Account for our relative position in the dialog
_x = getAbsX();
_y = getAbsY();
// Clear background (unless alpha blending is enabled)
if (_flags & WIDGET_CLEARBG)
gui->fillRect(_x, _y, _w, _h, gui->_bgcolor);
// Clear background (unless alpha blending is enabled)
if(_flags & WIDGET_CLEARBG)
gui->fillRect(_x, _y, _w, _h, gui->_bgcolor);
// Draw border
if (_flags & WIDGET_BORDER) {
OverlayColor colorA = gui->_color;
OverlayColor colorB = gui->_shadowcolor;
if ((_flags & WIDGET_INV_BORDER) == WIDGET_INV_BORDER)
SWAP(colorA, colorB);
gui->box(_x, _y, _w, _h, colorA, colorB);
_x += 4;
_y += 4;
_w -= 8;
_h -= 8;
}
// Draw border
if(_flags & WIDGET_BORDER) {
OverlayColor colorA = gui->_color;
OverlayColor colorB = gui->_shadowcolor;
if((_flags & WIDGET_INV_BORDER) == WIDGET_INV_BORDER)
SWAP(colorA, colorB);
gui->box(_x, _y, _w, _h, colorA, colorB);
_x += 4;
_y += 4;
_w -= 8;
_h -= 8;
}
// Now perform the actual widget draw
drawWidget((_flags & WIDGET_HILITED) ? true : false);
// Now perform the actual widget draw
drawWidget((_flags & WIDGET_HILITED) ? true : false);
// Restore x/y
if (_flags & WIDGET_BORDER) {
_x -= 4;
_y -= 4;
_w += 8;
_h += 8;
}
// Restore x/y
if (_flags & WIDGET_BORDER) {
_x -= 4;
_y -= 4;
_w += 8;
_h += 8;
}
// Flag the draw area as dirty
gui->addDirtyRect(_x, _y, _w, _h);
// Flag the draw area as dirty
gui->addDirtyRect(_x, _y, _w, _h);
_x = oldX;
_y = oldY;
_x = oldX;
_y = oldY;
// Draw all children
Widget *w = _firstWidget;
while (w) {
w->draw();
w = w->_next;
}
// Draw all children
Widget* w = _firstWidget;
while(w)
{
w->draw();
w = w->_next;
}
}
Widget *Widget::findWidgetInChain(Widget *w, int x, int y) {
while (w) {
// Stop as soon as we find a widget that contains the point (x,y)
if (x >= w->_x && x < w->_x + w->_w && y >= w->_y && y < w->_y + w->_h)
break;
w = w->_next;
}
if (w)
w = w->findWidget(x - w->_x, y - w->_y);
return w;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Widget* Widget::findWidgetInChain(Widget *w, int x, int y)
{
while(w)
{
// Stop as soon as we find a widget that contains the point (x,y)
if(x >= w->_x && x < w->_x + w->_w && y >= w->_y && y < w->_y + w->_h)
break;
w = w->_next;
}
if(w)
w = w->findWidget(x - w->_x, y - w->_y);
return w;
}
#pragma mark -
StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, TextAlignment align)
: Widget(boss, x, y, w, h), _align(align) {
_flags = WIDGET_ENABLED;
_type = kStaticTextWidget;
setLabel(text);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h,
const string& text, TextAlignment align)
: Widget(boss, x, y, w, h), _align(align)
{
_flags = WIDGET_ENABLED;
_type = kStaticTextWidget;
setLabel(text);
}
void StaticTextWidget::setValue(int value) {
char buf[256];
sprintf(buf, "%d", value);
_label = buf;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void StaticTextWidget::setValue(int value)
{
char buf[256];
sprintf(buf, "%d", value);
_label = buf;
}
void StaticTextWidget::drawWidget(bool hilite) {
NewGui *gui = &g_gui;
gui->drawString(_label, _x, _y, _w, isEnabled() ? gui->_textcolor : gui->_color, _align);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void StaticTextWidget::drawWidget(bool hilite)
{
NewGui *gui = &g_gui;
gui->drawString(_label, _x, _y, _w,
isEnabled() ? gui->_textcolor : gui->_color, _align);
}
#pragma mark -
ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)
: StaticTextWidget(boss, x, y, w, h, label, kTextAlignCenter), CommandSender(boss),
_cmd(cmd), _hotkey(hotkey) {
_flags = WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG;
_type = kButtonWidget;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h,
const string& label, uint32 cmd, uint8 hotkey)
: StaticTextWidget(boss, x, y, w, h, label, kTextAlignCenter),
CommandSender(boss),
_cmd(cmd),
_hotkey(hotkey)
{
_flags = WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG;
_type = kButtonWidget;
}
void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) {
if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h)
sendCommand(_cmd, 0);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount)
{
if(isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h)
sendCommand(_cmd, 0);
}
void ButtonWidget::drawWidget(bool hilite) {
NewGui *gui = &g_gui;
gui->drawString(_label, _x, _y + (_h - kLineHeight)/2 + 1, _w,
!isEnabled() ? gui->_color :
hilite ? gui->_textcolorhi : gui->_textcolor, _align);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ButtonWidget::drawWidget(bool hilite)
{
NewGui *gui = &g_gui;
gui->drawString(_label, _x, _y + (_h - kLineHeight)/2 + 1, _w,
!isEnabled() ? gui->_color :
hilite ? gui->_textcolorhi : gui->_textcolor, _align);
}
#pragma mark -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/* 8x8 checkbox bitmap */
static uint32 checked_img[8] = {
static uint32 checked_img[8] =
{
0x00000000,
0x01000010,
0x00100100,
@ -161,107 +187,139 @@ static uint32 checked_img[8] = {
0x00000000,
};
CheckboxWidget::CheckboxWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)
: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey), _state(false) {
_flags = WIDGET_ENABLED;
_type = kCheckboxWidget;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CheckboxWidget::CheckboxWidget(GuiObject *boss, int x, int y, int w, int h,
const string& label, uint32 cmd, uint8 hotkey)
: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey),
_state(false)
{
_flags = WIDGET_ENABLED;
_type = kCheckboxWidget;
}
void CheckboxWidget::handleMouseUp(int x, int y, int button, int clickCount) {
if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h) {
toggleState();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheckboxWidget::handleMouseUp(int x, int y, int button, int clickCount)
{
if(isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h)
toggleState();
}
void CheckboxWidget::setState(bool state) {
if (_state != state) {
_state = state;
_flags ^= WIDGET_INV_BORDER;
draw();
}
sendCommand(_cmd, _state);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheckboxWidget::setState(bool state)
{
if(_state != state)
{
_state = state;
_flags ^= WIDGET_INV_BORDER;
draw();
}
sendCommand(_cmd, _state);
}
void CheckboxWidget::drawWidget(bool hilite) {
NewGui *gui = &g_gui;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheckboxWidget::drawWidget(bool hilite)
{
NewGui *gui = &g_gui;
// Draw the box
gui->box(_x, _y, 14, 14, gui->_color, gui->_shadowcolor);
// Draw the box
gui->box(_x, _y, 14, 14, gui->_color, gui->_shadowcolor);
// If checked, draw cross inside the box
if (_state)
gui->drawBitmap(checked_img, _x + 3, _y + 3, isEnabled() ? gui->_textcolor : gui->_color);
else
gui->fillRect(_x + 2, _y + 2, 10, 10, gui->_bgcolor);
// If checked, draw cross inside the box
if(_state)
gui->drawBitmap(checked_img, _x + 3, _y + 3,
isEnabled() ? gui->_textcolor : gui->_color);
else
gui->fillRect(_x + 2, _y + 2, 10, 10, gui->_bgcolor);
// Finally draw the label
gui->drawString(_label, _x + 20, _y + 3, _w, isEnabled() ? gui->_textcolor : gui->_color);
// Finally draw the label
gui->drawString(_label, _x + 20, _y + 3, _w,
isEnabled() ? gui->_textcolor : gui->_color);
}
#pragma mark -
SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth, uint32 cmd, uint8 hotkey)
: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey),
_value(0), _oldValue(0),_valueMin(0), _valueMax(100), _isDragging(false),
_labelWidth(labelWidth) {
_flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG;
_type = kSliderWidget;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h,
const string& label, uint labelWidth, uint32 cmd, uint8 hotkey)
: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey),
_value(0),
_oldValue(0),
_valueMin(0),
_valueMax(100),
_isDragging(false),
_labelWidth(labelWidth)
{
_flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG;
_type = kSliderWidget;
}
void SliderWidget::handleMouseMoved(int x, int y, int button) {
// TODO: when the mouse is dragged outside the widget, the slider should
// snap back to the old value.
if (isEnabled() && _isDragging && x >= (int)_labelWidth) {
int newValue = posToValue(x - _labelWidth);
if (newValue < _valueMin)
newValue = _valueMin;
else if (newValue > _valueMax)
newValue = _valueMax;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SliderWidget::handleMouseMoved(int x, int y, int button)
{
// TODO: when the mouse is dragged outside the widget, the slider should
// snap back to the old value.
if(isEnabled() && _isDragging && x >= (int)_labelWidth)
{
int newValue = posToValue(x - _labelWidth);
if (newValue != _value) {
_value = newValue;
draw();
sendCommand(_cmd, _value); // FIXME - hack to allow for "live update" in sound dialog
}
}
if(newValue < _valueMin)
newValue = _valueMin;
else if (newValue > _valueMax)
newValue = _valueMax;
if(newValue != _value)
{
_value = newValue;
draw();
sendCommand(_cmd, _value); // FIXME - hack to allow for "live update" in sound dialog
}
}
}
void SliderWidget::handleMouseDown(int x, int y, int button, int clickCount) {
if (isEnabled()) {
_isDragging = true;
handleMouseMoved(x, y, button);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SliderWidget::handleMouseDown(int x, int y, int button, int clickCount)
{
if(isEnabled())
{
_isDragging = true;
handleMouseMoved(x, y, button);
}
}
void SliderWidget::handleMouseUp(int x, int y, int button, int clickCount) {
if (isEnabled() && _isDragging) {
sendCommand(_cmd, _value);
}
_isDragging = false;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SliderWidget::handleMouseUp(int x, int y, int button, int clickCount)
{
if(isEnabled() && _isDragging)
sendCommand(_cmd, _value);
_isDragging = false;
}
void SliderWidget::drawWidget(bool hilite) {
NewGui *gui = &g_gui;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SliderWidget::drawWidget(bool hilite)
{
NewGui *gui = &g_gui;
// Draw the label, if any
if (_labelWidth > 0)
gui->drawString(_label, _x, _y + 2, _labelWidth, isEnabled() ? gui->_textcolor : gui->_color, kTextAlignRight);
// Draw the label, if any
if(_labelWidth > 0)
gui->drawString(_label, _x, _y + 2, _labelWidth,
isEnabled() ? gui->_textcolor : gui->_color, kTextAlignRight);
// Draw the box
gui->box(_x + _labelWidth, _y, _w - _labelWidth, _h, gui->_color, gui->_shadowcolor);
// Draw the box
gui->box(_x + _labelWidth, _y, _w - _labelWidth, _h, gui->_color, gui->_shadowcolor);
// Draw the 'bar'
gui->fillRect(_x + _labelWidth + 2, _y + 2, valueToPos(_value), _h - 4,
!isEnabled() ? gui->_color :
hilite ? gui->_textcolorhi : gui->_textcolor);
// Draw the 'bar'
gui->fillRect(_x + _labelWidth + 2, _y + 2, valueToPos(_value), _h - 4,
!isEnabled() ? gui->_color :
hilite ? gui->_textcolorhi : gui->_textcolor);
}
int SliderWidget::valueToPos(int value) {
return ((_w - _labelWidth - 4) * (value - _valueMin) / (_valueMax - _valueMin));
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int SliderWidget::valueToPos(int value)
{
return ((_w - _labelWidth - 4) * (value - _valueMin) / (_valueMax - _valueMin));
}
int SliderWidget::posToValue(int pos) {
return (pos) * (_valueMax - _valueMin) / (_w - _labelWidth - 4) + _valueMin;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int SliderWidget::posToValue(int pos)
{
return (pos) * (_valueMax - _valueMin) / (_w - _labelWidth - 4) + _valueMin;
}
} // End of namespace GUI

View File

@ -13,7 +13,10 @@
// 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.1 2005-02-27 23:41:19 stephena Exp $
// $Id: Widget.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#ifndef WIDGET_HXX
@ -24,12 +27,23 @@ class Dialog;
#include "GuiObject.hxx"
#include "bspf.hxx"
enum {
WIDGET_ENABLED = 1 << 0,
WIDGET_INVISIBLE = 1 << 1,
WIDGET_HILITED = 1 << 2,
WIDGET_BORDER = 1 << 3,
WIDGET_INV_BORDER = 1 << 4,
WIDGET_CLEARBG = 1 << 5,
WIDGET_WANT_TICKLE = 1 << 7,
WIDGET_TRACK_MOUSE = 1 << 8,
WIDGET_RETAIN_FOCUS = 1 << 9
};
/**
This is the base class for all widgets.
@author Stephen Anthony
@version $Id: Widget.hxx,v 1.1 2005-02-27 23:41:19 stephena Exp $
@version $Id: Widget.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
*/
class Widget : public GuiObject
{
@ -48,8 +62,8 @@ class Widget : public GuiObject
virtual void handleMouseLeft(uInt32 button) {}
virtual void handleMouseMoved(uInt32 x, uInt32 y, uInt32 button) {}
virtual void handleMouseWheel(uInt32 x, uInt32 y, uInt32 direction) {}
//FIXME virtual bool handleKeyDown(uint16 ascii, int keycode, int modifiers) { return false; } // Return true if the event was handled
//FIXME virtual bool handleKeyUp(uint16 ascii, int keycode, int modifiers) { return false; } // Return true if the event was handled
virtual bool handleKeyDown(uInt16 ascii, int keycode, int modifiers) { return false; }
virtual bool handleKeyUp(uInt16 ascii, int keycode, int modifiers) { return false; }
virtual void handleTickle() {}
void draw();
@ -71,12 +85,12 @@ class Widget : public GuiObject
virtual void receivedFocusWidget() {}
virtual void lostFocusWidget() {}
virtual Widget *findWidget(uInt32 x, uInt32 y) { return this; }
virtual Widget* findWidget(uInt32 x, uInt32 y) { return this; }
void releaseFocus() { assert(_boss); _boss->releaseFocus(); }
// By default, delegate unhandled commands to the boss
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
void handleCommand(CommandSender* sender, uInt32 cmd, uInt32 data)
{ assert(_boss); _boss->handleCommand(sender, cmd, data); }
protected:
@ -88,7 +102,7 @@ class Widget : public GuiObject
bool _hasFocus;
public:
static Widget *findWidgetInChain(Widget *start, uInt32 x, uInt32 y);
static Widget* findWidgetInChain(Widget* start, uInt32 x, uInt32 y);
};
@ -97,21 +111,16 @@ class StaticTextWidget : public Widget
{
public:
StaticTextWidget(GuiObject* boss, uInt32 x, uInt32 y, uInt32 w, uInt32 h,
const String &text, TextAlignment align);
const string& text);
void setValue(uInt32 value);
void setLabel(const string& label) { _label = label; }
const string& getLabel() const { return _label; }
void setAlign(TextAlignment align) { _align = align; }
TextAlignment getAlign() const { return _align; }
protected:
void drawWidget(bool hilite);
protected:
// typedef Graphics::TextAlignment TextAlignment;
string _label;
// TextAlignment _align;
};
@ -122,8 +131,8 @@ class ButtonWidget : public StaticTextWidget
ButtonWidget(GuiObject* boss, uInt32 x, uInt32 y, uInt32 w, uInt32 h,
const string& label, uInt32 cmd = 0, uInt8 hotkey = 0);
void setCmd(uint32 cmd) { _cmd = cmd; }
uint32 getCmd() const { return _cmd; }
void setCmd(uInt32 cmd) { _cmd = cmd; }
uInt32 getCmd() const { return _cmd; }
void handleMouseUp(uInt32 x, uInt32 y, uInt32 button, uInt32 clickCount);
void handleMouseEntered(uInt32 button) { setFlags(WIDGET_HILITED); draw(); }