Yet more in-game GUI changes. It's getting close to compiling, but no

idea on if it will actually work :)


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@379 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-03-11 23:36:30 +00:00
parent 4e129001cd
commit bed46fe840
9 changed files with 449 additions and 779 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: FrameBuffer.cxx,v 1.18 2005-03-10 22:59:40 stephena Exp $
// $Id: FrameBuffer.cxx,v 1.19 2005-03-11 23:36:30 stephena Exp $
//============================================================================
#include <sstream>
@ -218,7 +218,7 @@ void FrameBuffer::update()
uInt32 y = myHeight - height - LINEOFFSET/2;
// Draw the bounded box and text
drawBoundedBox(x, y+1, width, height-2);
box(x, y+1, width, height-2, 0, 0); // FIXME
drawText(x + XBOXOFFSET/2, LINEOFFSET/2 + y, myMessageText);
myMessageTime--;
@ -320,7 +320,7 @@ inline void FrameBuffer::drawMainMenu()
// Draw the bounded box and text, leaving a little room for arrows
xpos = x + XBOXOFFSET;
drawBoundedBox(x-2, y-2, width+3, height+3);
box(x-2, y-2, width+3, height+3, 0, 0); //FIXME
for(i = 0; i < myMainMenuItems; i++)
drawText(xpos, LINEOFFSET*i + y + YBOXOFFSET, ourMainMenu[i].action);
@ -341,7 +341,7 @@ inline void FrameBuffer::drawRemapMenu()
y = (myHeight >> 1) - (height >> 1);
// Draw the bounded box and text, leaving a little room for arrows
drawBoundedBox(x-2, y-2, width+3, height+3);
box(x-2, y-2, width+3, height+3, 0, 0); //FIXME
for(Int32 i = myRemapMenuLowIndex; i < myRemapMenuHighIndex; i++)
{
ypos = LINEOFFSET*(i-myRemapMenuLowIndex) + y + YBOXOFFSET;
@ -392,7 +392,7 @@ inline void FrameBuffer::drawInfoMenu()
// Draw the bounded box and text
xpos = x + XBOXOFFSET;
drawBoundedBox(x, y, width, height);
box(x, y, width, height, 0, 0); //FIXME
for(i = 0; i < 9; i++)
drawText(xpos, LINEOFFSET*i + y + YBOXOFFSET, ourPropertiesInfo[i]);
}
@ -1117,3 +1117,18 @@ void FrameBuffer::setWindowIcon()
SDL_FreeSurface(surface);
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::box(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
OverlayColor colorA, OverlayColor colorB)
{
hLine(x + 1, y, x + w - 2, colorA);
hLine(x, y + 1, x + w - 1, colorA);
vLine(x, y + 1, y + h - 2, colorA);
vLine(x + 1, y, y + h - 1, colorA);
hLine(x + 1, y + h - 2, x + w - 1, colorB);
hLine(x + 1, y + h - 1, x + w - 2, colorB);
vLine(x + w - 1, y + 1, y + h - 2, colorB);
vLine(x + w - 2, y + 1, y + h - 1, colorB);
}

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.hxx,v 1.17 2005-02-27 23:41:19 stephena Exp $
// $Id: FrameBuffer.hxx,v 1.18 2005-03-11 23:36:30 stephena Exp $
//============================================================================
#ifndef FRAMEBUFFER_HXX
@ -30,16 +30,24 @@
class Console;
class OSystem;
typedef uInt32 OverlayColor;
// Text alignment modes for drawString()
enum TextAlignment {
kTextAlignLeft,
kTextAlignCenter,
kTextAlignRight
};
/**
This class encapsulates the MediaSource and is the basis for the video
display in Stella. All graphics ports should derive from this class for
platform-specific video stuff.
FIXME This class also implements a MAME-like user interface where Stella settings
can be changed.
All GUI elements (ala ScummVM) are drawn here as well.
@author Stephen Anthony
@version $Id: FrameBuffer.hxx,v 1.17 2005-02-27 23:41:19 stephena Exp $
@version $Id: FrameBuffer.hxx,v 1.18 2005-03-11 23:36:30 stephena Exp $
*/
class FrameBuffer
{
@ -216,6 +224,34 @@ FIXME
*/
void setupPalette();
/**
Colors to use for the various GUI elements
*/
OverlayColor color, shadowcolor;
OverlayColor bgcolor;
OverlayColor textcolor;
OverlayColor textcolorhi;
/**
This routine should be called to draw a rectangular box with sides
at the specified coordinates.
@param x The x coordinate
@param y The y coordinate
@param w The width of the box
@param h The height of the box
@param colorA FIXME
@param colorB FIXME
*/
void box(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
OverlayColor colorA, OverlayColor colorB);
/**
Indicate that the specified area should be redrawn.
Currently this is a null-op.
*/
void addDirtyRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h) {}
public:
//////////////////////////////////////////////////////////////////////
// The following methods are system-specific and must be implemented
@ -232,15 +268,6 @@ FIXME
*/
virtual bool createScreen() = 0;
/**
This routine is called to map a given r,g,b triple to the screen palette.
@param r The red component of the color.
@param g The green component of the color.
@param b The blue component of the color.
*/
virtual Uint32 mapRGB(Uint8 r, Uint8 g, Uint8 b) = 0;
/**
Switches between the filtering options in the video subsystem.
*/
@ -252,35 +279,6 @@ FIXME
*/
virtual void drawMediaSource() = 0;
/**
This routine should be called to draw a rectangular box with sides
at the specified coordinates.
@param x The x coordinate
@param y The y coordinate
@param w The width of the box
@param h The height of the box
*/
virtual void drawBoundedBox(uInt32 x, uInt32 y, uInt32 w, uInt32 h) = 0;
/**
This routine should be called to draw text at the specified coordinates.
@param x The x coordinate
@param y The y coordinate
@param message The message text
*/
virtual void drawText(uInt32 x, uInt32 y, const string& message) = 0;
/**
This routine should be called to draw character 'c' at the specified coordinates.
@param x The x coordinate
@param y The y coordinate
@param c The character to draw
*/
virtual void drawChar(uInt32 x, uInt32 y, uInt32 c) = 0;
/**
This routine is called before any drawing is done (per-frame).
*/
@ -299,6 +297,115 @@ FIXME
*/
virtual void scanline(uInt32 row, uInt8* data) = 0;
/**
This routine is called to map a given r,g,b triple to the screen palette.
@param r The red component of the color.
@param g The green component of the color.
@param b The blue component of the color.
*/
virtual Uint32 mapRGB(Uint8 r, Uint8 g, Uint8 b) = 0;
/**
This routine should be called to draw a horizontal line.
@param x The first x coordinate
@param y The y coordinate
@param x2 The second x coordinate
@param color The color of the line
*/
virtual void hLine(uInt32 x, uInt32 y, uInt32 x2, OverlayColor color) = 0;
/**
This routine should be called to draw a vertical line.
@param x The x coordinate
@param y The first y coordinate
@param y2 The second y coordinate
@param color The color of the line
*/
virtual void vLine(uInt32 x, uInt32 y, uInt32 y2, OverlayColor color);
/**
This routine should be called to draw a blended rectangle.
@param x The x coordinate
@param y The y coordinate
@param w The width of the box
@param h The height of the box
@param color FIXME
@param level FIXME
*/
virtual void blendRect(int x, int y, int w, int h,
OverlayColor color, int level = 3) = 0;
/**
This routine should be called to draw a filled rectangle.
@param x The x coordinate
@param y The y coordinate
@param w The width of the area
@param h The height of the area
@param color The color of the area
*/
virtual void fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
OverlayColor color) = 0;
/**
This routine should be called to draw a framed rectangle.
@param x The x coordinate
@param y The y coordinate
@param w The width of the area
@param h The height of the area
@param color The color of the surrounding frame
*/
virtual void frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
OverlayColor color) = 0;
/**
This routine should be called to draw the specified string.
@param x The x coordinate
@param y The y coordinate
@param w The width of the area
@param h The height of the area
@param color The color of the surrounding frame
*/
virtual void drawString(const string& str, Int32 x, Int32 y, Int32 w,
OverlayColor color, TextAlignment align = kTextAlignLeft,
Int32 deltax = 0, bool useEllipsis = true) = 0;
/* FIXME
void drawChar(byte c, int x, int y, OverlayColor color, const Graphics::Font *font = 0);
int getStringWidth(const String &str);
int getCharWidth(byte c);
void drawBitmap(uint32 *bitmap, int x, int y, OverlayColor color, int h = 8);
*/
/**
This routine should be called to draw text at the specified coordinates.
@param x The x coordinate
@param y The y coordinate
@param message The message text
*/
virtual void drawText(uInt32 x, uInt32 y, const string& message) = 0;
/**
This routine should be called to draw character 'c' at the specified coordinates.
@param x The x coordinate
@param y The y coordinate
@param c The character to draw
*/
virtual void drawChar(uInt32 x, uInt32 y, uInt32 c) = 0;
#if 0
FIXME
/**

View File

@ -13,18 +13,20 @@
// 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 $
// $Id: Dialog.cxx,v 1.3 2005-03-11 23:36:30 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#include <SDL.h>
#include <ctype.h>
#include "stdafx.h"
#include "newgui.h"
#include "dialog.h"
#include "widget.h"
#include "OSystem.hxx"
#include "FrameBuffer.hxx"
#include "Menu.hxx"
#include "Dialog.hxx"
#include "Widget.hxx"
/*
* TODO list
@ -35,8 +37,8 @@
* ...
*/
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dialog::Dialog(uInt16 x, uInt16 y, uInt16 w, uInt16 h)
: GuiObject(x, y, w, h),
Dialog::Dialog(OSystem* instance, uInt16 x, uInt16 y, uInt16 w, uInt16 h)
: GuiObject(instance, x, y, w, h),
_mouseWidget(0),
_focusedWidget(0),
_visible(false)
@ -51,13 +53,13 @@ Dialog::~Dialog()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int Dialog::runModal()
int Dialog::runModal() // FIXME
{
// Open up
open();
// Start processing events
g_gui.runLoop();
// g_gui.runLoop();
// Return the result code
return _result;
@ -70,7 +72,7 @@ void Dialog::open()
_result = 0;
_visible = true;
g_gui.openDialog(this);
instance()->menu().addDialog(this);
// Search for the first objects that wantsFocus() (if any) and give it the focus
while(w && !w->wantsFocus())
@ -87,7 +89,7 @@ void Dialog::open()
void Dialog::close()
{
_visible = false;
g_gui.closeTopDialog();
instance()->menu().removeDialog();
if (_mouseWidget) {
_mouseWidget->handleMouseLeft(0);
@ -110,7 +112,7 @@ void Dialog::releaseFocus()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::draw()
{
g_gui._needRedraw = true;
instance()->frameBuffer().refresh();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -119,8 +121,10 @@ 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);
FrameBuffer& fb = instance()->frameBuffer();
fb.blendRect(_x, _y, _w, _h, fb.bgcolor);
fb.box(_x, _y, _w, _h, fb.color, fb.shadowcolor);
// Draw all children
Widget* w = _firstWidget;
@ -131,7 +135,7 @@ void Dialog::drawDialog()
}
// Flag the draw area as dirty
g_gui.addDirtyRect(_x, _y, _w, _h);
fb.addDirtyRect(_x, _y, _w, _h);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -201,7 +205,7 @@ void Dialog::handleMouseWheel(int x, int y, int direction)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)
void Dialog::handleKeyDown(uInt16 ascii, Int32 keycode, Int32 modifiers)
{
if(_focusedWidget)
if (_focusedWidget->handleKeyDown(ascii, keycode, modifiers))
@ -214,7 +218,7 @@ void Dialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)
ascii = toupper(ascii);
while(w)
{
if(w->_type == kButtonWidget && ascii == toupper(((ButtonWidget *)w)->_hotkey))
if(0)//FIXME - don't let it access a protected variable 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.
@ -236,7 +240,7 @@ void Dialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleKeyUp(uint16 ascii, int keycode, int modifiers)
void Dialog::handleKeyUp(uInt16 ascii, Int32 keycode, Int32 modifiers)
{
// Focused widget receives keyup events
if(_focusedWidget)
@ -298,7 +302,7 @@ void Dialog::handleTickle()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleCommand(CommandSender* sender, uint32 cmd, uint32 data)
void Dialog::handleCommand(CommandSender* sender, uInt32 cmd, uInt32 data)
{
switch(cmd)
{
@ -319,8 +323,8 @@ Widget* Dialog::findWidget(int x, int y)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ButtonWidget* Dialog::addButton(int x, int y, const string &label,
uint32 cmd, char hotkey)
ButtonWidget* Dialog::addButton(Int32 x, Int32 y, const string& label,
uInt32 cmd, char hotkey)
{
return new ButtonWidget(this, x, y, kButtonWidth, 16, label, cmd, hotkey);
}

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: Dialog.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
// $Id: Dialog.hxx,v 1.3 2005-03-11 23:36:30 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -22,7 +22,7 @@
#ifndef DIALOG_HXX
#define DIALOG_HXX
#include <SDL.h>
class OSystem;
#include "Command.hxx"
#include "Widget.hxx"
@ -30,16 +30,21 @@
#include "bspf.hxx"
// Some "common" commands sent to handleCommand()
enum {
kCloseCmd = 'clos'
};
/**
This is the base class for all dialog boxes.
@author Stephen Anthony
@version $Id: Dialog.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
@version $Id: Dialog.hxx,v 1.3 2005-03-11 23:36:30 stephena Exp $
*/
class Dialog
class Dialog : public GuiObject
{
public:
Dialog(uInt16 x, uInt16 y, uInt16 w, uInt16 h);
Dialog(OSystem* instance, uInt16 x, uInt16 y, uInt16 w, uInt16 h);
virtual ~Dialog();
@ -51,8 +56,8 @@ class Dialog
virtual void drawDialog();
virtual void handleKeyDown(SDLKey key, SDLMod mod);
virtual void handleKeyUp(SDLKey key, SDLMod mod);
virtual void handleKeyDown(uInt16 ascii, Int32 keycode, Int32 modifiers);
virtual void handleKeyUp(uInt16 ascii, Int32 keycode, Int32 modifiers);
protected:
virtual void open();

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: GuiObject.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
// $Id: GuiObject.hxx,v 1.3 2005-03-11 23:36:30 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -22,6 +22,7 @@
#ifndef GUI_OBJECT_HXX
#define GUI_OBJECT_HXX
class OSystem;
class Widget;
#include "Command.hxx"
@ -31,20 +32,23 @@ class Widget;
This is the base class for all GUI objects/widgets.
@author Stephen Anthony
@version $Id: GuiObject.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
@version $Id: GuiObject.hxx,v 1.3 2005-03-11 23:36:30 stephena Exp $
*/
class GuiObject : public CommandReceiver
{
friend class Widget;
public:
GuiObject(int x, int y, int w, int h)
: _x(x),
GuiObject(OSystem* osystem, int x, int y, int w, int h)
: myOSystem(osystem),
_x(x),
_y(y),
_w(w),
_h(h),
_firstWidget(0) { }
OSystem* instance() { return myOSystem; }
virtual Int16 getAbsX() const { return _x; }
virtual Int16 getAbsY() const { return _y; }
virtual Int16 getChildX() const { return getAbsX(); }
@ -56,6 +60,8 @@ class GuiObject : public CommandReceiver
virtual void draw() = 0;
protected:
OSystem* myOSystem;
Int16 _x, _y;
uInt16 _w, _h;

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.2 2005-03-10 22:59:40 stephena Exp $
// $Id: Menu.hxx,v 1.3 2005-03-11 23:36:30 stephena Exp $
//============================================================================
#ifndef MENU_HXX
@ -23,6 +23,8 @@ class Dialog;
class OSystem;
class OptionsDialog;
#include <SDL.h>
#include "Stack.hxx"
#include "bspf.hxx"
@ -35,7 +37,7 @@ typedef FixedStack<Dialog *> DialogStack;
a stack, and handles their events.
@author Stephen Anthony
@version $Id: Menu.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
@version $Id: Menu.hxx,v 1.3 2005-03-11 23:36:30 stephena Exp $
*/
class Menu
{

View File

@ -13,60 +13,22 @@
// 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 $
// $Id: OptionsDialog.cxx,v 1.2 2005-03-11 23:36:30 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;
*/
#include "OSystem.hxx"
#include "Menu.hxx"
#include "Dialog.hxx"
#include "Widget.hxx"
#include "Control.hxx"
#include "OptionsDialog.hxx"
#include "bspf.hxx"
/*
using GUI::CommandSender;
using GUI::StaticTextWidget;
using GUI::kButtonWidth;
@ -77,219 +39,17 @@ 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',
kVidCmd = 'VIDO',
kAudCmd = 'AUDO',
kEMapCmd = 'EMAP',
kMiscCmd = 'MISC',
kInfoCmd = 'INFO',
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,
@ -298,341 +58,84 @@ enum {
};
#define addBigButton(label, cmd, hotkey) \
new GUI::ButtonWidget(this, x, y, kBigButtonWidth, 16, label, cmd, hotkey); y += kRowHeight
new 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) {
OptionsDialog::OptionsDialog(OSystem* osystem)
: Dialog(osystem, (320 - kMainMenuWidth) / 2, (200 - kMainMenuHeight)/2, kMainMenuWidth, kMainMenuHeight)
{
int y = 7;
const int x = (_w - kBigButtonWidth) / 2;
addBigButton("Resume", kPlayCmd, 'P');
addBigButton("Video", kVidCmd, 'V');
y += 5;
addBigButton("Load", kLoadCmd, 'L');
addBigButton("Save", kSaveCmd, 'S');
addBigButton("Audio", kAudCmd, 'A');
addBigButton("Event Remapping", kEMapCmd, 'E');
y += 5;
addBigButton("Options", kOptionsCmd, 'O');
#ifndef DISABLE_HELP
addBigButton("Misc", kMiscCmd, 'M');
addBigButton("Game Info", kInfoCmd, 'I');
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);
/*
// 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);
*/
}
MainMenuDialog::~MainMenuDialog() {
delete _aboutDialog;
#ifndef DISABLE_HELP
delete _helpDialog;
#endif
delete _saveDialog;
delete _loadDialog;
OptionsDialog::~OptionsDialog()
{
/* FIXME
delete myVideoDialog;
delete myAudioDialog;
delete myEventMappingDialog;
delete myMiscDialog;
delete myGameInfoDialog;
delete myHelpDialog;
*/
}
void MainMenuDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
case kSaveCmd:
save();
void OptionsDialog::handleCommand(CommandSender* sender, uInt32 cmd, uInt32 data)
{
switch(cmd)
{
case kVidCmd:
// instance()->menu().addDialog(myVideoDialog);
cerr << "push VideoDialog to top of stack\n";
break;
case kLoadCmd:
load();
case kAudCmd:
// instance()->menu().addDialog(myAudioDialog);
cerr << "push AudioDialog to top of stack\n";
break;
case kPlayCmd:
close();
case kEMapCmd:
// instance()->menu().addDialog(myEventMappingDialog);
cerr << "push EventMappingDialog to top of stack\n";
break;
case kOptionsCmd:
_vm->optionsDialog();
case kMiscCmd:
// instance()->menu().addDialog(myMiscDialog);
cerr << "push MiscDialog to top of stack\n";
break;
case kAboutCmd:
_aboutDialog->runModal();
case kInfoCmd:
// instance()->menu().addDialog(myGameInfoDialog);
cerr << "push GameInfoDialog to top of stack\n";
break;
#ifndef DISABLE_HELP
case kHelpCmd:
_helpDialog->runModal();
break;
#endif
case kQuitCmd:
_vm->_quit = true;
close();
// instance()->menu().addDialog(myHelpDialog);
cerr << "push HelpDialog to top of stack\n";
break;
default:
ScummDialog::handleCommand(sender, cmd, data);
Dialog::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

@ -13,21 +13,24 @@
// 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.2 2005-03-10 22:59:40 stephena Exp $
// $Id: Widget.cxx,v 1.3 2005-03-11 23:36:30 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#include "OSystem.hxx"
#include "FrameBuffer.hxx"
#include "Dialog.hxx"
#include "Command.hxx"
#include "GuiObject.hxx"
#include "bspf.hxx"
#include "Widget.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Widget::Widget(GuiObject* boss, uInt32 x, uInt32 y, uInt32 w, uInt32 h)
: GuiObject(x, y, w, h),
Widget::Widget(GuiObject* boss, Int32 x, Int32 y, Int32 w, Int32 h)
: GuiObject(boss->instance(), x, y, w, h),
_type(0),
_boss(boss),
_id(0),
@ -48,12 +51,12 @@ Widget::~Widget()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Widget::draw()
{
FrameBuffer* fb = _boss->instance().frameBuffer();
FrameBuffer& fb = _boss->instance()->frameBuffer();
if(!isVisible() || !_boss->isVisible())
return;
int oldX = _x, oldY = _y;
Int32 oldX = _x, oldY = _y;
// Account for our relative position in the dialog
_x = getAbsX();
@ -61,15 +64,15 @@ void Widget::draw()
// Clear background (unless alpha blending is enabled)
if(_flags & WIDGET_CLEARBG)
gui->fillRect(_x, _y, _w, _h, gui->_bgcolor);
fb.fillRect(_x, _y, _w, _h, fb.bgcolor);
// Draw border
if(_flags & WIDGET_BORDER) {
OverlayColor colorA = gui->_color;
OverlayColor colorB = gui->_shadowcolor;
OverlayColor colorA = fb.color;
OverlayColor colorB = fb.shadowcolor;
if((_flags & WIDGET_INV_BORDER) == WIDGET_INV_BORDER)
SWAP(colorA, colorB);
gui->box(_x, _y, _w, _h, colorA, colorB);
; //FIXME - add swap function SWAP(colorA, colorB);
fb.box(_x, _y, _w, _h, colorA, colorB);
_x += 4;
_y += 4;
_w -= 8;
@ -88,7 +91,7 @@ void Widget::draw()
}
// Flag the draw area as dirty
gui->addDirtyRect(_x, _y, _w, _h);
fb.addDirtyRect(_x, _y, _w, _h);
_x = oldX;
_y = oldY;
@ -103,7 +106,7 @@ void Widget::draw()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Widget* Widget::findWidgetInChain(Widget *w, int x, int y)
Widget* Widget::findWidgetInChain(Widget *w, Int32 x, Int32 y)
{
while(w)
{
@ -120,9 +123,10 @@ Widget* Widget::findWidgetInChain(Widget *w, int x, int y)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h,
StaticTextWidget::StaticTextWidget(GuiObject *boss, Int32 x, Int32 y, Int32 w, Int32 h,
const string& text, TextAlignment align)
: Widget(boss, x, y, w, h), _align(align)
: Widget(boss, x, y, w, h),
_align(align)
{
_flags = WIDGET_ENABLED;
_type = kStaticTextWidget;
@ -130,7 +134,7 @@ StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h,
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void StaticTextWidget::setValue(int value)
void StaticTextWidget::setValue(Int32 value)
{
char buf[256];
sprintf(buf, "%d", value);
@ -140,14 +144,14 @@ void StaticTextWidget::setValue(int value)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void StaticTextWidget::drawWidget(bool hilite)
{
NewGui *gui = &g_gui;
gui->drawString(_label, _x, _y, _w,
isEnabled() ? gui->_textcolor : gui->_color, _align);
FrameBuffer& fb = _boss->instance()->frameBuffer();
fb.drawString(_label, _x, _y, _w,
isEnabled() ? fb.textcolor : fb.color, _align);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h,
const string& label, uint32 cmd, uint8 hotkey)
ButtonWidget::ButtonWidget(GuiObject *boss, Int32 x, Int32 y, Int32 w, Int32 h,
const string& label, Int32 cmd, uInt8 hotkey)
: StaticTextWidget(boss, x, y, w, h, label, kTextAlignCenter),
CommandSender(boss),
_cmd(cmd),
@ -158,7 +162,7 @@ ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h,
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount)
void ButtonWidget::handleMouseUp(Int32 x, Int32 y, Int32 button, Int32 clickCount)
{
if(isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h)
sendCommand(_cmd, 0);
@ -167,15 +171,17 @@ void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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);
int kLineHeight = 10; //FIXME
FrameBuffer& fb = _boss->instance()->frameBuffer();
fb.drawString(_label, _x, _y + (_h - kLineHeight)/2 + 1, _w,
!isEnabled() ? fb.color :
hilite ? fb.textcolorhi : fb.textcolor, _align);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/* 8x8 checkbox bitmap */
static uint32 checked_img[8] =
static uInt32 checked_img[8] =
{
0x00000000,
0x01000010,
@ -188,8 +194,8 @@ static uint32 checked_img[8] =
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CheckboxWidget::CheckboxWidget(GuiObject *boss, int x, int y, int w, int h,
const string& label, uint32 cmd, uint8 hotkey)
CheckboxWidget::CheckboxWidget(GuiObject *boss, Int32 x, Int32 y, Int32 w, Int32 h,
const string& label, Int32 cmd, uInt8 hotkey)
: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey),
_state(false)
{
@ -198,7 +204,7 @@ CheckboxWidget::CheckboxWidget(GuiObject *boss, int x, int y, int w, int h,
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheckboxWidget::handleMouseUp(int x, int y, int button, int clickCount)
void CheckboxWidget::handleMouseUp(Int32 x, Int32 y, Int32 button, Int32 clickCount)
{
if(isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h)
toggleState();
@ -219,26 +225,27 @@ void CheckboxWidget::setState(bool state)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheckboxWidget::drawWidget(bool hilite)
{
NewGui *gui = &g_gui;
FrameBuffer& fb = _boss->instance()->frameBuffer();
// Draw the box
gui->box(_x, _y, 14, 14, gui->_color, gui->_shadowcolor);
fb.box(_x, _y, 14, 14, fb.color, fb.shadowcolor);
// If checked, draw cross inside the box
if(_state)
gui->drawBitmap(checked_img, _x + 3, _y + 3,
isEnabled() ? gui->_textcolor : gui->_color);
; // FIXME - change bitmap to be a character in the font set, then draw that
// fb.drawBitmap(checked_img, _x + 3, _y + 3,
// isEnabled() ? fb.textcolor : fb.color);
else
gui->fillRect(_x + 2, _y + 2, 10, 10, gui->_bgcolor);
fb.fillRect(_x + 2, _y + 2, 10, 10, fb.bgcolor);
// Finally draw the label
gui->drawString(_label, _x + 20, _y + 3, _w,
isEnabled() ? gui->_textcolor : gui->_color);
fb.drawString(_label, _x + 20, _y + 3, _w,
isEnabled() ? fb.textcolor : fb.color);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h,
const string& label, uint labelWidth, uint32 cmd, uint8 hotkey)
SliderWidget::SliderWidget(GuiObject *boss, Int32 x, Int32 y, Int32 w, Int32 h,
const string& label, Int32 labelWidth, Int32 cmd, uInt8 hotkey)
: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey),
_value(0),
_oldValue(0),
@ -252,13 +259,13 @@ SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h,
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SliderWidget::handleMouseMoved(int x, int y, int button)
void SliderWidget::handleMouseMoved(Int32 x, Int32 y, Int32 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);
Int32 newValue = posToValue(x - _labelWidth);
if(newValue < _valueMin)
newValue = _valueMin;
@ -275,7 +282,7 @@ void SliderWidget::handleMouseMoved(int x, int y, int button)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SliderWidget::handleMouseDown(int x, int y, int button, int clickCount)
void SliderWidget::handleMouseDown(Int32 x, Int32 y, Int32 button, Int32 clickCount)
{
if(isEnabled())
{
@ -285,7 +292,7 @@ void SliderWidget::handleMouseDown(int x, int y, int button, int clickCount)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SliderWidget::handleMouseUp(int x, int y, int button, int clickCount)
void SliderWidget::handleMouseUp(Int32 x, Int32 y, Int32 button, Int32 clickCount)
{
if(isEnabled() && _isDragging)
sendCommand(_cmd, _value);
@ -296,30 +303,30 @@ void SliderWidget::handleMouseUp(int x, int y, int button, int clickCount)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SliderWidget::drawWidget(bool hilite)
{
NewGui *gui = &g_gui;
FrameBuffer& fb = _boss->instance()->frameBuffer();
// Draw the label, if any
if(_labelWidth > 0)
gui->drawString(_label, _x, _y + 2, _labelWidth,
isEnabled() ? gui->_textcolor : gui->_color, kTextAlignRight);
fb.drawString(_label, _x, _y + 2, _labelWidth,
isEnabled() ? fb.textcolor : fb.color, kTextAlignRight);
// Draw the box
gui->box(_x + _labelWidth, _y, _w - _labelWidth, _h, gui->_color, gui->_shadowcolor);
fb.box(_x + _labelWidth, _y, _w - _labelWidth, _h, fb.color, fb.shadowcolor);
// Draw the 'bar'
gui->fillRect(_x + _labelWidth + 2, _y + 2, valueToPos(_value), _h - 4,
!isEnabled() ? gui->_color :
hilite ? gui->_textcolorhi : gui->_textcolor);
fb.fillRect(_x + _labelWidth + 2, _y + 2, valueToPos(_value), _h - 4,
!isEnabled() ? fb.color :
hilite ? fb.textcolorhi : fb.textcolor);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int SliderWidget::valueToPos(int value)
Int32 SliderWidget::valueToPos(Int32 value)
{
return ((_w - _labelWidth - 4) * (value - _valueMin) / (_valueMax - _valueMin));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int SliderWidget::posToValue(int pos)
Int32 SliderWidget::posToValue(Int32 pos)
{
return (pos) * (_valueMax - _valueMin) / (_w - _labelWidth - 4) + _valueMin;
}

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: Widget.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
// $Id: Widget.hxx,v 1.3 2005-03-11 23:36:30 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -24,6 +24,7 @@
class Dialog;
#include "FrameBuffer.hxx"
#include "GuiObject.hxx"
#include "bspf.hxx"
@ -39,31 +40,48 @@ enum {
WIDGET_RETAIN_FOCUS = 1 << 9
};
enum {
kStaticTextWidget ='TEXT',
kEditTextWidget = 'EDIT',
kButtonWidget = 'BTTN',
kCheckboxWidget = 'CHKB',
kSliderWidget = 'SLDE',
kListWidget = 'LIST',
kScrollBarWidget = 'SCRB',
kPopUpWidget = 'POPU',
kTabWidget = 'TABW'
};
enum {
kButtonWidth = 72,
kButtonHeight = 16
};
/**
This is the base class for all widgets.
@author Stephen Anthony
@version $Id: Widget.hxx,v 1.2 2005-03-10 22:59:40 stephena Exp $
@version $Id: Widget.hxx,v 1.3 2005-03-11 23:36:30 stephena Exp $
*/
class Widget : public GuiObject
{
friend class Dialog;
public:
Widget(GuiObject* boss, uInt32 x, uInt32 y, uInt32 w, uInt32 h);
Widget(GuiObject* boss, Int32 x, Int32 y, Int32 w, Int32 h);
virtual ~Widget();
virtual Int16 getAbsX() const { return _x + _boss->getChildX(); }
virtual Int16 getAbsY() const { return _y + _boss->getChildY(); }
virtual void handleMouseDown(uInt32 x, uInt32 y, uInt32 button, uInt32 clickCount) {}
virtual void handleMouseUp(uInt32 x, uInt32 y, uInt32 button, uInt32 clickCount) {}
virtual void handleMouseEntered(uInt32 button) {}
virtual void handleMouseLeft(uInt32 button) {}
virtual void handleMouseMoved(uInt32 x, uInt32 y, uInt32 button) {}
virtual void handleMouseWheel(uInt32 x, uInt32 y, uInt32 direction) {}
virtual bool handleKeyDown(uInt16 ascii, int keycode, int modifiers) { return false; }
virtual bool handleKeyUp(uInt16 ascii, int keycode, int modifiers) { return false; }
virtual void handleMouseDown(Int32 x, Int32 y, Int32 button, Int32 clickCount) {}
virtual void handleMouseUp(Int32 x, Int32 y, Int32 button, Int32 clickCount) {}
virtual void handleMouseEntered(Int32 button) {}
virtual void handleMouseLeft(Int32 button) {}
virtual void handleMouseMoved(Int32 x, Int32 y, Int32 button) {}
virtual void handleMouseWheel(Int32 x, Int32 y, Int32 direction) {}
virtual bool handleKeyDown(uInt16 ascii, Int32 keycode, Int32 modifiers) { return false; }
virtual bool handleKeyUp(uInt16 ascii, Int32 keycode, Int32 modifiers) { return false; }
virtual void handleTickle() {}
void draw();
@ -71,9 +89,9 @@ class Widget : public GuiObject
void lostFocus() { _hasFocus = false; lostFocusWidget(); }
virtual bool wantsFocus() { return false; };
void setFlags(int flags) { _flags |= flags; }
void clearFlags(int flags) { _flags &= ~flags; }
uInt32 getFlags() const { return _flags; }
void setFlags(Int32 flags) { _flags |= flags; }
void clearFlags(Int32 flags) { _flags &= ~flags; }
Int32 getFlags() const { return _flags; }
void setEnabled(bool e) { if (e) setFlags(WIDGET_ENABLED); else clearFlags(WIDGET_ENABLED); }
bool isEnabled() const { return _flags & WIDGET_ENABLED; }
@ -85,16 +103,16 @@ class Widget : public GuiObject
virtual void receivedFocusWidget() {}
virtual void lostFocusWidget() {}
virtual Widget* findWidget(uInt32 x, uInt32 y) { return this; }
virtual Widget* findWidget(Int32 x, Int32 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, Int32 cmd, Int32 data)
{ assert(_boss); _boss->handleCommand(sender, cmd, data); }
protected:
uInt32 _type;
Int32 _type;
GuiObject* _boss;
Widget* _next;
uInt16 _id;
@ -102,7 +120,7 @@ class Widget : public GuiObject
bool _hasFocus;
public:
static Widget* findWidgetInChain(Widget* start, uInt32 x, uInt32 y);
static Widget* findWidgetInChain(Widget* start, Int32 x, Int32 y);
};
@ -110,9 +128,10 @@ class Widget : public GuiObject
class StaticTextWidget : public Widget
{
public:
StaticTextWidget(GuiObject* boss, uInt32 x, uInt32 y, uInt32 w, uInt32 h,
const string& text);
void setValue(uInt32 value);
StaticTextWidget(GuiObject* boss,
Int32 x, Int32 y, Int32 w, Int32 h,
const string& text, TextAlignment align);
void setValue(Int32 value);
void setLabel(const string& label) { _label = label; }
const string& getLabel() const { return _label; }
@ -121,22 +140,24 @@ class StaticTextWidget : public Widget
protected:
string _label;
TextAlignment _align;
};
/* ButtonWidget */
class ButtonWidget : public StaticTextWidget
class ButtonWidget : public StaticTextWidget, public CommandSender
{
public:
ButtonWidget(GuiObject* boss, uInt32 x, uInt32 y, uInt32 w, uInt32 h,
const string& label, uInt32 cmd = 0, uInt8 hotkey = 0);
ButtonWidget(GuiObject* boss,
Int32 x, Int32 y, Int32 w, Int32 h,
const string& label, Int32 cmd = 0, uInt8 hotkey = 0);
void setCmd(uInt32 cmd) { _cmd = cmd; }
uInt32 getCmd() const { return _cmd; }
void setCmd(Int32 cmd) { _cmd = cmd; }
Int32 getCmd() const { return _cmd; }
void handleMouseUp(uInt32 x, uInt32 y, uInt32 button, uInt32 clickCount);
void handleMouseEntered(uInt32 button) { setFlags(WIDGET_HILITED); draw(); }
void handleMouseLeft(uInt32 button) { clearFlags(WIDGET_HILITED); draw(); }
void handleMouseUp(Int32 x, Int32 y, Int32 button, Int32 clickCount);
void handleMouseEntered(Int32 button) { setFlags(WIDGET_HILITED); draw(); }
void handleMouseLeft(Int32 button) { clearFlags(WIDGET_HILITED); draw(); }
protected:
void drawWidget(bool hilite);
@ -151,12 +172,12 @@ class ButtonWidget : public StaticTextWidget
class CheckboxWidget : public ButtonWidget
{
public:
CheckboxWidget(GuiObject* boss, uInt32 x, uInt32 y, uInt32 w, uInt32 h,
const string& label, uInt32 cmd = 0, uInt8 hotkey = 0);
CheckboxWidget(GuiObject* boss, Int32 x, Int32 y, Int32 w, Int32 h,
const string& label, Int32 cmd = 0, uInt8 hotkey = 0);
void handleMouseUp(uInt32 x, uInt32 y, uInt32 button, uInt32 clickCount);
virtual void handleMouseEntered(uInt32 button) {}
virtual void handleMouseLeft(uInt32 button) {}
void handleMouseUp(Int32 x, Int32 y, Int32 button, Int32 clickCount);
virtual void handleMouseEntered(Int32 button) {}
virtual void handleMouseLeft(Int32 button) {}
void setState(bool state);
void toggleState() { setState(!_state); }
@ -174,32 +195,32 @@ class CheckboxWidget : public ButtonWidget
class SliderWidget : public ButtonWidget
{
public:
SliderWidget(GuiObject *boss, int x, int y, int w, int h, const string& label = "",
uInt32 labelWidth = 0, uInt32 cmd = 0, uInt8 hotkey = 0);
SliderWidget(GuiObject *boss, Int32 x, Int32 y, Int32 w, Int32 h, const string& label = "",
Int32 labelWidth = 0, Int32 cmd = 0, uInt8 hotkey = 0);
void setValue(uInt32 value) { _value = value; }
uInt32 getValue() const { return _value; }
void setValue(Int32 value) { _value = value; }
Int32 getValue() const { return _value; }
void setMinValue(uInt32 value) { _valueMin = value; }
uInt32 getMinValue() const { return _valueMin; }
void setMaxValue(uInt32 value) { _valueMax = value; }
uInt32 getMaxValue() const { return _valueMax; }
void setMinValue(Int32 value) { _valueMin = value; }
Int32 getMinValue() const { return _valueMin; }
void setMaxValue(Int32 value) { _valueMax = value; }
Int32 getMaxValue() const { return _valueMax; }
void handleMouseMoved(uInt32 x, uInt32 y, uInt32 button);
void handleMouseDown(uInt32 x, uInt32 y, uInt32 button, uInt32 clickCount);
void handleMouseUp(uInt32 x, uInt32 y, uInt32 button, uInt32 clickCount);
void handleMouseMoved(Int32 x, Int32 y, Int32 button);
void handleMouseDown(Int32 x, Int32 y, Int32 button, Int32 clickCount);
void handleMouseUp(Int32 x, Int32 y, Int32 button, Int32 clickCount);
protected:
void drawWidget(bool hilite);
uInt32 valueToPos(uInt32 value);
uInt32 posToValue(uInt32 pos);
Int32 valueToPos(Int32 value);
Int32 posToValue(Int32 pos);
protected:
uInt32 _value, _oldValue;
uInt32 _valueMin, _valueMax;
Int32 _value, _oldValue;
Int32 _valueMin, _valueMax;
bool _isDragging;
uInt32 _labelWidth;
Int32 _labelWidth;
};
#endif