diff --git a/stella/src/common/SoundSDL.cxx b/stella/src/common/SoundSDL.cxx index 0908b899e..90c77a139 100644 --- a/stella/src/common/SoundSDL.cxx +++ b/stella/src/common/SoundSDL.cxx @@ -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: SoundSDL.cxx,v 1.15 2005-05-11 19:35:59 stephena Exp $ +// $Id: SoundSDL.cxx,v 1.16 2005-05-13 01:03:27 stephena Exp $ //============================================================================ #include @@ -67,6 +67,12 @@ void SoundSDL::initialize(bool forcerestart) return; } + // Clear the sound queue FIXME - still an annoying partial sound playing? + SDL_PauseAudio(1); + Tia_clear_registers(); + myRegWriteQueue.clear(); + SDL_PauseAudio(0); + if(forcerestart && myIsInitializedFlag) closeAudio(); diff --git a/stella/src/emucore/TIASound.c b/stella/src/emucore/TIASound.c index f300a69e7..70d288b37 100644 --- a/stella/src/emucore/TIASound.c +++ b/stella/src/emucore/TIASound.c @@ -547,6 +547,33 @@ void Tia_set_registers (unsigned char reg1, unsigned char reg2, unsigned char re } +/*****************************************************************************/ +/* Module: Tia_clear_registers() */ +/* Purpose: Clears all TIA sound registers; soft reboot */ +/* */ +/* Author: Stephen Anthony */ +/* Date: May 12, 2005 */ +/* */ +/*****************************************************************************/ + +void Tia_clear_registers () +{ + uint8 chan; + for (chan = CHAN1; chan <= CHAN2; chan++) + { + Outvol[chan] = 0; + Div_n_cnt[chan] = 0; + Div_n_max[chan] = 0; + AUDC[chan] = 0; + AUDF[chan] = 0; + AUDV[chan] = 0; + P4[chan] = 0; + P5[chan] = 0; + P9[chan] = 0; + } +} + + /*****************************************************************************/ /* Module: Tia_volume() */ /* Purpose: Set volume to the specified percentage */ diff --git a/stella/src/emucore/TIASound.h b/stella/src/emucore/TIASound.h index 13e8fc2d8..b6b6e4d56 100644 --- a/stella/src/emucore/TIASound.h +++ b/stella/src/emucore/TIASound.h @@ -52,6 +52,8 @@ void Tia_get_registers (unsigned char *reg1, unsigned char *reg2, unsigned char void Tia_set_registers (unsigned char reg1, unsigned char reg2, unsigned char reg3, unsigned char reg4, unsigned char reg5, unsigned char reg6); +void Tia_clear_registers (void); + void Tia_volume (unsigned int percent); #ifdef __cplusplus diff --git a/stella/src/gui/Array.hxx b/stella/src/gui/Array.hxx index 84a27a1f4..978e151da 100644 --- a/stella/src/gui/Array.hxx +++ b/stella/src/gui/Array.hxx @@ -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: Array.hxx,v 1.2 2005-04-04 02:19:21 stephena Exp $ +// $Id: Array.hxx,v 1.3 2005-05-13 01:03:27 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -121,7 +121,7 @@ class Array return *this; } - uInt32 size() const { return _size; } + unsigned int size() const { return _size; } void clear() { diff --git a/stella/src/gui/Dialog.cxx b/stella/src/gui/Dialog.cxx index babf487c8..4b8fcd83b 100644 --- a/stella/src/gui/Dialog.cxx +++ b/stella/src/gui/Dialog.cxx @@ -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.cxx,v 1.12 2005-05-10 19:20:43 stephena Exp $ +// $Id: Dialog.cxx,v 1.13 2005-05-13 01:03:27 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -54,19 +54,6 @@ Dialog::~Dialog() _firstWidget = NULL; } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int Dialog::runModal() // FIXME -{ - // Open up - open(); - - // Start processing events - // g_gui.runLoop(); - - // Return the result code - return _result; -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::open() { diff --git a/stella/src/gui/Dialog.hxx b/stella/src/gui/Dialog.hxx index 68d6d64e8..925cc3842 100644 --- a/stella/src/gui/Dialog.hxx +++ b/stella/src/gui/Dialog.hxx @@ -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.10 2005-05-10 19:20:43 stephena Exp $ +// $Id: Dialog.hxx,v 1.11 2005-05-13 01:03:27 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -35,7 +35,7 @@ class DialogContainer; This is the base class for all dialog boxes. @author Stephen Anthony - @version $Id: Dialog.hxx,v 1.10 2005-05-10 19:20:43 stephena Exp $ + @version $Id: Dialog.hxx,v 1.11 2005-05-13 01:03:27 stephena Exp $ */ class Dialog : public GuiObject { @@ -47,8 +47,6 @@ class Dialog : public GuiObject virtual ~Dialog(); - virtual int runModal(); - bool isVisible() const { return _visible; } virtual void open(); diff --git a/stella/src/gui/GuiObject.hxx b/stella/src/gui/GuiObject.hxx index fa5820c37..b1388806f 100644 --- a/stella/src/gui/GuiObject.hxx +++ b/stella/src/gui/GuiObject.hxx @@ -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.5 2005-05-10 19:20:43 stephena Exp $ +// $Id: GuiObject.hxx,v 1.6 2005-05-13 01:03:27 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -25,7 +25,6 @@ class OSystem; class DialogContainer; class Widget; -class Menu; #include "Command.hxx" #include "bspf.hxx" @@ -34,12 +33,12 @@ class Menu; This is the base class for all GUI objects/widgets. @author Stephen Anthony - @version $Id: GuiObject.hxx,v 1.5 2005-05-10 19:20:43 stephena Exp $ + @version $Id: GuiObject.hxx,v 1.6 2005-05-13 01:03:27 stephena Exp $ */ class GuiObject : public CommandReceiver { friend class Widget; - friend class Menu; + friend class DialogContainer; public: GuiObject(OSystem* osystem, DialogContainer* parent, int x, int y, int w, int h) diff --git a/stella/src/gui/LauncherDialog.cxx b/stella/src/gui/LauncherDialog.cxx index 54504340b..d4f75b8e1 100644 --- a/stella/src/gui/LauncherDialog.cxx +++ b/stella/src/gui/LauncherDialog.cxx @@ -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: LauncherDialog.cxx,v 1.10 2005-05-12 18:45:21 stephena Exp $ +// $Id: LauncherDialog.cxx,v 1.11 2005-05-13 01:03:27 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -39,10 +39,10 @@ #include "bspf.hxx" enum { - kStartCmd = 'STRT', - kLocationCmd = 'LOCA', - kReloadCmd = 'RELO', - kQuitCmd = 'QUIT', + kStartCmd = 'STRT', + kOptionsCmd = 'OPTI', + kReloadCmd = 'RELO', + kQuitCmd = 'QUIT', kCmdGlobalGraphicsOverride = 'OGFX', kCmdGlobalAudioOverride = 'OSFX', @@ -58,7 +58,6 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent, uInt16 x, uInt16 y, uInt16 w, uInt16 h) : Dialog(osystem, parent, x, y, w, h), myList(NULL), - myBrowser(NULL), myGameList(NULL) { // Show game name @@ -77,7 +76,7 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent, new ButtonWidget(this, xpos, _h - 24, width, 16, "Play", kStartCmd, 'S'); xpos += space + width; - new ButtonWidget(this, xpos, _h - 24, width, 16, "Options", kLocationCmd, 'O'); + new ButtonWidget(this, xpos, _h - 24, width, 16, "Options", kOptionsCmd, 'O'); xpos += space + width; new ButtonWidget(this, xpos, _h - 24, width, 16, "Reload", kReloadCmd, 'R'); xpos += space + width; @@ -112,11 +111,12 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent, } */ +/* // Create file browser dialog string romdir = instance()->settings().getString("romdir"); myBrowser = new BrowserDialog(osystem, parent, "Select ROM directory", romdir, 20, 20, _w - 40, _h - 40); - +*/ // Create a game list, which contains all the information about a ROM that // the launcher needs myGameList = new GameList(); @@ -125,7 +125,6 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - LauncherDialog::~LauncherDialog() { - delete myBrowser; delete myGameList; } @@ -142,8 +141,10 @@ void LauncherDialog::loadConfig() void LauncherDialog::close() { // Save romdir specified by the browser +/* FilesystemNode dir(myBrowser->getResult()); instance()->settings().setString("romdir", dir.path()); +*/ /* // Save last selection const int sel = _list->getSelected(); @@ -201,7 +202,8 @@ void LauncherDialog::loadListFromDisk() { Properties props; - FilesystemNode dir(myBrowser->getResult()); + string romdir = instance()->settings().getString("romdir"); + FilesystemNode dir(romdir); FSList files = dir.listDir(FilesystemNode::kListAll); // Create a entry for the GameList for each file @@ -325,8 +327,9 @@ void LauncherDialog::handleCommand(CommandSender* sender, uInt32 cmd, uInt32 dat } break; - case kLocationCmd: - parent()->addDialog(myBrowser); + case kOptionsCmd: + cerr << "add options to stack\n"; +// parent()->addDialog(myBrowser); break; case kReloadCmd: diff --git a/stella/src/gui/LauncherDialog.hxx b/stella/src/gui/LauncherDialog.hxx index 695f03037..23c063243 100644 --- a/stella/src/gui/LauncherDialog.hxx +++ b/stella/src/gui/LauncherDialog.hxx @@ -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: LauncherDialog.hxx,v 1.4 2005-05-11 01:44:39 stephena Exp $ +// $Id: LauncherDialog.hxx,v 1.5 2005-05-13 01:03:27 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -24,15 +24,12 @@ class DialogContainer; class CommandSender; -class ButtonWidget; class StaticTextWidget; class ListWidget; -class BrowserDialog; +class OSystem; -#include "GameList.hxx" #include "Dialog.hxx" -#include "Launcher.hxx" -#include "OSystem.hxx" +#include "GameList.hxx" #include "bspf.hxx" class LauncherDialog : public Dialog @@ -52,7 +49,6 @@ class LauncherDialog : public Dialog protected: ListWidget* myList; - BrowserDialog* myBrowser; StaticTextWidget* myNote; StaticTextWidget* myRomCount; GameList* myGameList; diff --git a/stella/src/gui/LauncherOptionsDialog.cxx b/stella/src/gui/LauncherOptionsDialog.cxx new file mode 100644 index 000000000..543af752b --- /dev/null +++ b/stella/src/gui/LauncherOptionsDialog.cxx @@ -0,0 +1,221 @@ +//============================================================================ +// +// 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: LauncherOptionsDialog.cxx,v 1.1 2005-05-13 01:03:27 stephena Exp $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#include "BrowserDialog.hxx" +#include "gui/chooser.h" +//#include "gui/options.h" +#include "PopUpWidget.hxx" +#include "TabWidget.hxx" + +#include "FSNode.hxx" + + +OptionsDialog::OptionsDialog(const string& domain, int x, int y, int w, int h) + : Dialog(x, y, w, h), + _domain(domain) +{ + + const int vBorder = 4; + int yoffset; + + // The tab widget + TabWidget *tab = new TabWidget(this, 0, vBorder, _w, _h - 24 - 2 * vBorder); + + // 1) The file locations tab + // + tab->addTab("File Locations"); + yoffset = vBorder; + + // ROM path + new ButtonWidget(tab, 5, yoffset, kButtonWidth + 14, 16, "ROM Path: ", kChooseSaveDirCmd, 0); + _savePath = new StaticTextWidget(tab, 5 + kButtonWidth + 20, yoffset + 3, _w - (5 + kButtonWidth + 20) - 10, kLineHeight, "Enter valid path", kTextAlignLeft); + yoffset += 18; + + // 2) The snapshot settings tab + // + tab->addTab("Snapshot Settings"); + yoffset = vBorder; + + // Save game path + new ButtonWidget(tab, 5, yoffset, kButtonWidth + 14, 16, "Save Path: ", kChooseSaveDirCmd, 0); + _savePath = new StaticTextWidget(tab, 5 + kButtonWidth + 20, yoffset + 3, _w - (5 + kButtonWidth + 20) - 10, kLineHeight, "/foo/bar", kTextAlignLeft); + + yoffset += 18; + + new ButtonWidget(tab, 5, yoffset, kButtonWidth + 14, 16, "Extra Path:", kChooseExtraDirCmd, 0); + _extraPath = new StaticTextWidget(tab, 5 + kButtonWidth + 20, yoffset + 3, _w - (5 + kButtonWidth + 20) - 10, kLineHeight, "None", kTextAlignLeft); + yoffset += 18; + +/* + // + // 3) The miscellaneous tab + // + tab->addTab("Misc"); + yoffset = vBorder; + +#if !( defined(__DC__) || defined(__GP32__) ) + // Save game path + new ButtonWidget(tab, 5, yoffset, kButtonWidth + 14, 16, "Save Path: ", kChooseSaveDirCmd, 0); + _savePath = new StaticTextWidget(tab, 5 + kButtonWidth + 20, yoffset + 3, _w - (5 + kButtonWidth + 20) - 10, kLineHeight, "/foo/bar", kTextAlignLeft); + + yoffset += 18; + + new ButtonWidget(tab, 5, yoffset, kButtonWidth + 14, 16, "Extra Path:", kChooseExtraDirCmd, 0); + _extraPath = new StaticTextWidget(tab, 5 + kButtonWidth + 20, yoffset + 3, _w - (5 + kButtonWidth + 20) - 10, kLineHeight, "None", kTextAlignLeft); + yoffset += 18; +#endif + + // TODO: joystick setting +*/ + + // Activate the first tab + tab->setActiveTab(0); + + // Add OK & Cancel buttons + addButton(_w - 2 *(kButtonWidth + 10), _h - 24, "OK", kOKCmd, 0); + addButton(_w - (kButtonWidth + 10), _h - 24, "Cancel", kCloseCmd, 0); + + // Create file browser dialog + _browser = new BrowserDialog("Select directory for savegames"); + +} + +GlobalOptionsDialog::~GlobalOptionsDialog() { + delete _browser; +} + +void OptionsDialog::close() +{ +/* + if (getResult()) { + if (_fullscreenCheckbox) { + if (_enableGraphicSettings) { + ConfMan.set("fullscreen", _fullscreenCheckbox->getState(), _domain); + ConfMan.set("aspect_ratio", _aspectCheckbox->getState(), _domain); + + if ((int32)_gfxPopUp->getSelectedTag() >= 0) + ConfMan.set("gfx_mode", _gfxPopUp->getSelectedString(), _domain); + } else { + ConfMan.removeKey("fullscreen", _domain); + ConfMan.removeKey("aspect_ratio", _domain); + ConfMan.removeKey("gfx_mode", _domain); + } + } + + if (_masterVolumeSlider) { + if (_enableVolumeSettings) { + ConfMan.set("master_volume", _masterVolumeSlider->getValue(), _domain); + ConfMan.set("music_volume", _musicVolumeSlider->getValue(), _domain); + ConfMan.set("sfx_volume", _sfxVolumeSlider->getValue(), _domain); + ConfMan.set("speech_volume", _speechVolumeSlider->getValue(), _domain); + } else { + ConfMan.removeKey("master_volume", _domain); + ConfMan.removeKey("music_volume", _domain); + ConfMan.removeKey("sfx_volume", _domain); + ConfMan.removeKey("speech_volume", _domain); + } + } + + if (_multiMidiCheckbox) { + if (_enableAudioSettings) { + ConfMan.set("multi_midi", _multiMidiCheckbox->getState(), _domain); + ConfMan.set("native_mt32", _mt32Checkbox->getState(), _domain); + ConfMan.set("subtitles", _subCheckbox->getState(), _domain); + const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers(); + while (md->name && md->id != (int)_midiPopUp->getSelectedTag()) + md++; + if (md->name) + ConfMan.set("music_driver", md->name, _domain); + else + ConfMan.removeKey("music_driver", _domain); + } else { + ConfMan.removeKey("multi_midi", _domain); + ConfMan.removeKey("native_mt32", _domain); + ConfMan.removeKey("music_driver", _domain); + ConfMan.removeKey("subtitles", _domain); + } + } + + // Save config file + ConfMan.flushToDisk(); + } +*/ + Dialog::close(); +} + +int OptionsDialog::addGraphicControls(GuiObject *boss, int yoffset) { + const int x = 10; + const int w = _w - 2 * 10; + const OSystem::GraphicsMode *gm = g_system->getSupportedGraphicsModes(); + + // The GFX mode popup + _gfxPopUp = new PopUpWidget(boss, x-5, yoffset, w+5, kLineHeight, "Graphics mode: ", 100); + yoffset += 16; + + _gfxPopUp->appendEntry(""); + _gfxPopUp->appendEntry(""); + while (gm->name) { + _gfxPopUp->appendEntry(gm->name, gm->id); + gm++; + } + + // Fullscreen checkbox + _fullscreenCheckbox = new CheckboxWidget(boss, x, yoffset, w, 16, "Fullscreen mode"); + yoffset += 16; + + // Aspect ratio checkbox + _aspectCheckbox = new CheckboxWidget(boss, x, yoffset, w, 16, "Aspect ratio correction"); + yoffset += 16; + +#ifdef _WIN32_WCE + _fullscreenCheckbox->setState(TRUE); + _fullscreenCheckbox->setEnabled(FALSE); + _aspectCheckbox->setEnabled(FALSE); +#endif + + _enableGraphicSettings = true; + + return yoffset; +} + +void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { + switch (cmd) { +/* + case kChooseSaveDirCmd: + if (_browser->runModal() > 0) { + // User made his choice... + FilesystemNode dir(_browser->getResult()); + _savePath->setLabel(dir.path()); + // TODO - we should check if the directory is writeable before accepting it + } + break; + case kChooseExtraDirCmd: + if (_browser->runModal() > 0) { + // User made his choice... + FilesystemNode dir(_browser->getResult()); + _extraPath->setLabel(dir.path()); + } + break; +*/ + default: + OptionsDialog::handleCommand(sender, cmd, data); + } +} diff --git a/stella/src/gui/LauncherOptionsDialog.hxx b/stella/src/gui/LauncherOptionsDialog.hxx new file mode 100644 index 000000000..46b3cc248 --- /dev/null +++ b/stella/src/gui/LauncherOptionsDialog.hxx @@ -0,0 +1,96 @@ +//============================================================================ +// +// 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: LauncherOptionsDialog.hxx,v 1.1 2005-05-13 01:03:27 stephena Exp $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#ifndef LAUNCHER_OPTIONS_DIALOG_HXX +#define LAUNCHER_OPTIONS_DIALOG_HXX + +#include "Dialog.hxx" + +class BrowserDialog; +class CheckboxWidget; +class PopUpWidget; +class SliderWidget; +class StaticTextWidget; + +class LauncherOptionsDialog : public Dialog +{ + public: + LauncherOptionsDialog(const String &domain, int x, int y, int w, int h); + + void open(); + void close(); + void handleCommand(CommandSender* sender, uInt32 cmd, uInt32 data); + + protected: + BrowserDialog *myRomBrowser; + BrowserDialog *mySnapBrowser; + StaticTextWidget *_savePath; + StaticTextWidget *_extraPath; + + protected: + /** Config domain this dialog is used to edit. */ + string _domain; + + int addGraphicControls(GuiObject *boss, int yoffset); + int addMIDIControls(GuiObject *boss, int yoffset); + int addVolumeControls(GuiObject *boss, int yoffset); + + void setGraphicSettingsState(bool enabled); + void setAudioSettingsState(bool enabled); + void setVolumeSettingsState(bool enabled); + + private: + // + // Graphics controls + // + bool _enableGraphicSettings; + PopUpWidget *_gfxPopUp; + CheckboxWidget *_fullscreenCheckbox; + CheckboxWidget *_aspectCheckbox; + + // + // Audio controls + // + bool _enableAudioSettings; + PopUpWidget *_midiPopUp; + CheckboxWidget *_multiMidiCheckbox; + CheckboxWidget *_mt32Checkbox; + CheckboxWidget *_subCheckbox; + + // + // Volume controls + // + bool _enableVolumeSettings; + + SliderWidget *_masterVolumeSlider; + StaticTextWidget *_masterVolumeLabel; + + SliderWidget *_musicVolumeSlider; + StaticTextWidget *_musicVolumeLabel; + + SliderWidget *_sfxVolumeSlider; + StaticTextWidget *_sfxVolumeLabel; + + SliderWidget *_speechVolumeSlider; + StaticTextWidget *_speechVolumeLabel; +}; + +#endif diff --git a/stella/src/gui/OptionsDialog.cxx b/stella/src/gui/OptionsDialog.cxx index d20c16f5e..513313961 100644 --- a/stella/src/gui/OptionsDialog.cxx +++ b/stella/src/gui/OptionsDialog.cxx @@ -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: OptionsDialog.cxx,v 1.14 2005-05-10 19:20:44 stephena Exp $ +// $Id: OptionsDialog.cxx,v 1.15 2005-05-13 01:03:27 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -54,9 +54,6 @@ enum { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - OptionsDialog::OptionsDialog(OSystem* osystem, DialogContainer* parent) -// FIXME - we have to initialize the video system at least once *before* -// creating a new console. For now, just use predefined values. -// Eventually, this subsystem will have to take into account screen size changes : Dialog(osystem, parent, (osystem->frameBuffer().baseWidth() - kMainMenuWidth) / 2, (osystem->frameBuffer().baseHeight() - kMainMenuHeight)/2, diff --git a/stella/src/gui/PopUpWidget.cxx b/stella/src/gui/PopUpWidget.cxx index f91f47c48..443531659 100644 --- a/stella/src/gui/PopUpWidget.cxx +++ b/stella/src/gui/PopUpWidget.cxx @@ -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: PopUpWidget.cxx,v 1.6 2005-05-11 01:44:39 stephena Exp $ +// $Id: PopUpWidget.cxx,v 1.7 2005-05-13 01:03:27 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -57,15 +57,13 @@ PopUpDialog::PopUpDialog(PopUpWidget* boss, Int32 clickX, Int32 clickY) _w = _popUpBoss->_w - 10 - _popUpBoss->_labelWidth; // Perform clipping / switch to scrolling mode if we don't fit on the screen - // FIXME - hard coded screen height 200. We really need an API in OSystem to query the - // screen height, and also OSystem should send out notification messages when the screen - // resolution changes... we could generalize CommandReceiver and CommandSender. - if(_h >= 200) // FIXME - change this to actual height of the window - _h = 199; + int height = instance()->frameBuffer().baseHeight(); + if(_h >= height) + _h = height - 1; if(_y < 0) _y = 0; - else if(_y + _h >= 200) - _y = 199 - _h; + else if(_y + _h >= height) + _y = height - _h - 1; // TODO - implement scrolling if we had to move the menu, or if there are too many entries diff --git a/stella/src/gui/TabWidget.cxx b/stella/src/gui/TabWidget.cxx new file mode 100644 index 000000000..570efe3c9 --- /dev/null +++ b/stella/src/gui/TabWidget.cxx @@ -0,0 +1,177 @@ +/* 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/TabWidget.cxx,v 1.1 2005-05-13 01:03:27 stephena Exp $ + */ + +#include "stdafx.h" +#include "common/util.h" +#include "gui/TabWidget.h" +#include "gui/dialog.h" +#include "gui/newgui.h" + +namespace GUI { + +enum { + kTabHeight = 16, + + kTabLeftOffset = 4, + kTabSpacing = 2, + kTabPadding = 3 +}; + +TabWidget::TabWidget(GuiObject *boss, int x, int y, int w, int h) + : Widget(boss, x, y, w, h) { + + _flags = WIDGET_ENABLED; + _type = kTabWidget; + _activeTab = -1; + + _tabWidth = 40; +} + +TabWidget::~TabWidget() { + for (uint i = 0; i < _tabs.size(); ++i) { + delete _tabs[i].firstWidget; + _tabs[i].firstWidget = 0; + } + _tabs.clear(); +} + +int16 TabWidget::getChildY() const { + return getAbsY() + kTabHeight; +} + +int TabWidget::addTab(const String &title) { + // Add a new tab page + Tab newTab; + newTab.title = title; + newTab.firstWidget = NULL; + + _tabs.push_back(newTab); + + int numTabs = _tabs.size(); + + // Determine the new tab width + int newWidth = g_gui.getStringWidth(title) + 2 * kTabPadding; + if (_tabWidth < newWidth) + _tabWidth = newWidth; + int maxWidth = (_w - kTabLeftOffset) / numTabs - kTabLeftOffset; + if (_tabWidth > maxWidth) + _tabWidth = maxWidth; + + // Activate the new tab + setActiveTab(numTabs - 1); + + return _activeTab; +} + +void TabWidget::setActiveTab(int tabID) { + assert(0 <= tabID && tabID < (int)_tabs.size()); + if (_activeTab != tabID) { + // Exchange the widget lists, and switch to the new tab + if (_activeTab != -1) + _tabs[_activeTab].firstWidget = _firstWidget; + _activeTab = tabID; + _firstWidget = _tabs[tabID].firstWidget; + _boss->draw(); + } +} + + +void TabWidget::handleMouseDown(int x, int y, int button, int clickCount) { + assert(y < kTabHeight); + + // Determine which tab was clicked + int tabID = -1; + x -= kTabLeftOffset; + if (x >= 0 && x % (_tabWidth + kTabSpacing) < _tabWidth) { + tabID = x / (_tabWidth + kTabSpacing); + if (tabID >= (int)_tabs.size()) + tabID = -1; + } + + // If a tab was clicked, switch to that pane + if (tabID >= 0) { + setActiveTab(tabID); + } +} + +bool TabWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) { + // TODO: maybe there should be a way to switch between tabs + // using the keyboard? E.g. Alt-Shift-Left/Right-Arrow or something + // like that. + return Widget::handleKeyDown(ascii, keycode, modifiers); +} + +static void box(int x, int y, int width, int height, OverlayColor colorA, OverlayColor colorB, bool omitBottom) { + NewGui &gui = g_gui; + + gui.hLine(x + 1, y, x + width - 2, colorA); + gui.hLine(x, y + 1, x + width - 1, colorA); + gui.vLine(x, y + 1, y + height - (omitBottom ? 1 : 2), colorA); + gui.vLine(x + 1, y, y + height - (omitBottom ? 2 : 1), colorA); + + if (!omitBottom) { + gui.hLine(x + 1, y + height - 2, x + width - 1, colorB); + gui.hLine(x + 1, y + height - 1, x + width - 2, colorB); + } + gui.vLine(x + width - 1, y + 1, y + height - (omitBottom ? 1 : 2), colorB); + gui.vLine(x + width - 2, y + 1, y + height - (omitBottom ? 2 : 1), colorB); +} + + +void TabWidget::drawWidget(bool hilite) { + NewGui *gui = &g_gui; + + const int left1 = _x + 1; + const int right1 = _x + kTabLeftOffset + _activeTab * (_tabWidth + kTabSpacing); + const int left2 = right1 + _tabWidth; + const int right2 = _x + _w - 2; + + // Draw horizontal line + gui->hLine(left1, _y + kTabHeight - 2, right1, gui->_shadowcolor); + gui->hLine(left2, _y + kTabHeight - 2, right2, gui->_shadowcolor); + + // Iterate over all tabs and draw them + int i, x = _x + kTabLeftOffset; + for (i = 0; i < (int)_tabs.size(); ++i) { + OverlayColor color = (i == _activeTab) ? gui->_color : gui->_shadowcolor; + int yOffset = (i == _activeTab) ? 0 : 2; + box(x, _y + yOffset, _tabWidth, kTabHeight - yOffset, color, color, (i == _activeTab)); + gui->drawString(_tabs[i].title, x + kTabPadding, _y + yOffset / 2 + (kTabHeight - kLineHeight - 1), _tabWidth - 2 * kTabPadding, gui->_textcolor, kTextAlignCenter); + x += _tabWidth + kTabSpacing; + } + + // Draw more horizontal lines + gui->hLine(left1, _y + kTabHeight - 1, right1, gui->_color); + gui->hLine(left2, _y + kTabHeight - 1, right2, gui->_color); + gui->hLine(_x+1, _y + _h - 2, _x + _w - 2, gui->_shadowcolor); + gui->hLine(_x+1, _y + _h - 1, _x + _w - 2, gui->_color); +} + +Widget *TabWidget::findWidget(int x, int y) { + if (y < kTabHeight) { + // Click was in the tab area + return this; + } else { + // Iterate over all child widgets and find the one which was clicked + return Widget::findWidgetInChain(_firstWidget, x, y - kTabHeight); + } +} + +} // End of namespace GUI diff --git a/stella/src/gui/TabWidget.hxx b/stella/src/gui/TabWidget.hxx new file mode 100644 index 000000000..5f118366a --- /dev/null +++ b/stella/src/gui/TabWidget.hxx @@ -0,0 +1,73 @@ +/* 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/TabWidget.hxx,v 1.1 2005-05-13 01:03:27 stephena Exp $ + */ + +#ifndef TABWIDGET_H +#define TABWIDGET_H + +#include "widget.h" +#include "common/str.h" +#include "common/array.h" + +namespace GUI { + +class TabWidget : public Widget { + typedef Common::String String; + struct Tab { + String title; + Widget *firstWidget; + }; + typedef Common::Array TabList; +protected: + int _activeTab; + TabList _tabs; + int _tabWidth; + +public: + TabWidget(GuiObject *boss, int x, int y, int w, int h); + ~TabWidget(); + + virtual int16 getChildY() const; + +// use Dialog::releaseFocus() when changing to another tab + +// Problem: how to add items to a tab? +// First off, widget should allow non-dialog bosses, (i.e. also other widgets) +// Could add a common base class for Widgets and Dialogs. +// Then you add tabs using the following method, which returns a unique ID + int addTab(const String &title); +// Maybe we need to remove tabs again? Hm + //void removeTab(int tabID); +// Setting the active tab: + void setActiveTab(int tabID); +// setActiveTab changes the value of _firstWidget. This means Widgets added afterwards +// will be added to the active tab. + + virtual void handleMouseDown(int x, int y, int button, int clickCount); + virtual bool handleKeyDown(uint16 ascii, int keycode, int modifiers); + +protected: + virtual void drawWidget(bool hilite); + + virtual Widget *findWidget(int x, int y); +}; + +} // End of namespace GUI + +#endif diff --git a/stella/src/unix/FSNodePOSIX.cxx b/stella/src/unix/FSNodePOSIX.cxx index 68307bd14..142bce7e7 100644 --- a/stella/src/unix/FSNodePOSIX.cxx +++ b/stella/src/unix/FSNodePOSIX.cxx @@ -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: FSNodePOSIX.cxx,v 1.2 2005-05-10 19:20:44 stephena Exp $ +// $Id: FSNodePOSIX.cxx,v 1.3 2005-05-13 01:03:27 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -61,7 +61,6 @@ class POSIXFilesystemNode : public AbstractFilesystemNode // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - static const char* lastPathComponent(const string& str) { - // FIXME - use native C++ string code const char *start = str.c_str(); const char *cur = start + str.size() - 2;