Added a ProgressDialog class, which shows a sliderwidget that represents the

progress of some activity.

Some additions to the LauncherDialog.  When populating the ROM list by
directly examining the ROM files, it now uses a ProgressDialog to show
the current status (since this operation sometimes take a long time).

The last selected ROM is now re-selected when starting Stella.

Some minor code refactoring to take into account zipped ROM support
(yes, its coming soon).

Re-added paddle support.  Still TODO is tweak the sensitivity of mouse
movements.  Also still TODO is re-add joystick support.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@427 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-05-17 18:42:23 +00:00
parent e12d010c45
commit 61d3922e70
11 changed files with 337 additions and 119 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.79 2005-05-16 00:02:30 stephena Exp $
## $Id: makefile,v 1.80 2005-05-17 18:42:22 stephena Exp $
##============================================================================
##============================================================================
@ -159,7 +159,8 @@ GUI_OBJS = StellaFont.o Menu.o Launcher.o \
Widget.o PopUpWidget.o ScrollBarWidget.o ListWidget.o TabWidget.o \
Dialog.o DialogContainer.o OptionsDialog.o VideoDialog.o AudioDialog.o \
EventMappingDialog.o GameInfoDialog.o HelpDialog.o AboutDialog.o \
LauncherDialog.o LauncherOptionsDialog.o BrowserDialog.o GameList.o
LauncherDialog.o LauncherOptionsDialog.o BrowserDialog.o GameList.o \
ProgressDialog.o
CORE_OBJS = Booster.o Cart.o Cart2K.o Cart3F.o Cart4K.o CartAR.o CartDPC.o \
CartE0.o CartE7.o CartF4.o CartF4SC.o CartF6.o CartF6SC.o \
@ -438,3 +439,6 @@ BrowserDialog.o: $(GUI)/BrowserDialog.cxx $(GUI)/BrowserDialog.hxx
GameList.o: $(GUI)/GameList.cxx $(GUI)/GameList.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/GameList.cxx
ProgressDialog.o: $(GUI)/ProgressDialog.cxx $(GUI)/ProgressDialog.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/ProgressDialog.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.56 2005-05-16 00:02:31 stephena Exp $
// $Id: EventHandler.cxx,v 1.57 2005-05-17 18:42:22 stephena Exp $
//============================================================================
#include <algorithm>
@ -422,38 +422,26 @@ void EventHandler::handleMouseMotionEvent(SDL_Event& event)
switch(myState)
{
case S_EMULATE:
// FIXME - add code here to generate paddle events
/*
uInt32 zoom = theDisplay->zoomLevel();
Int32 width = theDisplay->width() * zoom;
{
// Take window zooming into account
Int32 x = event.motion.x, y = event.motion.y;
myOSystem->frameBuffer().translateCoords(&x, &y);
int w = myOSystem->frameBuffer().baseWidth();
// Grabmouse introduces some lag into the mouse movement,
// so we need to fudge the numbers a bit
if(theGrabMouseIndicator && theHideCursorIndicator)
mouseX = (int)((float)mouseX + (float)event.motion.xrel
* 1.5 * (float) zoom);
else
mouseX = mouseX + event.motion.xrel * zoom;
// Check to make sure mouseX is within the game window
if(mouseX < 0)
mouseX = 0;
else if(mouseX > width)
mouseX = width;
Int32 resistance = (Int32)(1000000.0 * (width - mouseX) / width);
theOSystem->eventHandler().handleEvent(Paddle_Resistance[thePaddleMode], resistance);
*/
// Grabmouse introduces some lag into the mouse movement,
// so we need to fudge the numbers a bit
// FIXME - possibly do x *= 1.5 ??
int resistance = (int)(1000000.0 * (w - x) / w);
handleEvent(Paddle_Resistance[myPaddleMode], resistance);
break;
}
case S_MENU:
{
// Take window zooming into account
Int32 x = event.motion.x, y = event.motion.y;
myOSystem->frameBuffer().translateCoords(&x, &y);
//cerr << "Motion: x = " << x << ", y = " << y << endl;
myOSystem->menu().handleMouseMotionEvent(x, y, 0);
break;
}
@ -463,7 +451,6 @@ void EventHandler::handleMouseMotionEvent(SDL_Event& event)
// Take window zooming into account
Int32 x = event.motion.x, y = event.motion.y;
myOSystem->frameBuffer().translateCoords(&x, &y);
//cerr << "Motion: x = " << x << ", y = " << y << endl;
myOSystem->launcher().handleMouseMotionEvent(x, y, 0);
break;
}
@ -486,11 +473,7 @@ void EventHandler::handleMouseButtonEvent(SDL_Event& event, uInt8 state)
switch(myState)
{
case S_EMULATE:
// FIXME - add code here to generate paddle buttons
/*
Int32 value = event.button.type == SDL_MOUSEBUTTONDOWN ? 1 : 0;
theOSystem->eventHandler().handleEvent(Paddle_Button[thePaddleMode], value);
*/
handleEvent(Paddle_Button[myPaddleMode], state);
break;
case S_MENU:
@ -1354,3 +1337,30 @@ ActionList EventHandler::ourActionList[61] = {
{ Event::KeyboardOne0, "P2 GamePad 0", "" },
{ Event::KeyboardOnePound, "P2 GamePad #", "" }
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event::Type EventHandler::Paddle_Resistance[4] = {
Event::PaddleZeroResistance, Event::PaddleOneResistance,
Event::PaddleTwoResistance, Event::PaddleThreeResistance
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event::Type EventHandler::Paddle_Button[4] = {
Event::PaddleZeroFire, Event::PaddleOneFire,
Event::PaddleTwoFire, Event::PaddleThreeFire
};
#ifdef JOYSTICK_SUPPORT
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event::Type EventHandler::SA_Axis[2][2][3] = {
Event::JoystickZeroLeft, Event::JoystickZeroRight, Event::PaddleZeroResistance,
Event::JoystickZeroUp, Event::JoystickZeroDown, Event::PaddleOneResistance,
Event::JoystickOneLeft, Event::JoystickOneRight, Event::PaddleTwoResistance,
Event::JoystickOneUp, Event::JoystickOneDown, Event::PaddleThreeResistance
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event::Type EventHandler::SA_DrivingValue[2] = {
Event::DrivingZeroValue, Event::DrivingOneValue
};
#endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: EventHandler.hxx,v 1.28 2005-05-16 00:02:31 stephena Exp $
// $Id: EventHandler.hxx,v 1.29 2005-05-17 18:42:22 stephena Exp $
//============================================================================
#ifndef EVENTHANDLER_HXX
@ -57,7 +57,7 @@ struct ActionList {
mapping can take place.
@author Stephen Anthony
@version $Id: EventHandler.hxx,v 1.28 2005-05-16 00:02:31 stephena Exp $
@version $Id: EventHandler.hxx,v 1.29 2005-05-17 18:42:22 stephena Exp $
*/
class EventHandler
{
@ -153,6 +153,18 @@ class EventHandler
// Holds static strings for the remap menu
static ActionList ourActionList[61];
// Lookup table for paddle resistance events
static Event::Type Paddle_Resistance[4];
// Lookup table for paddle button events
static Event::Type Paddle_Button[4];
#ifdef JOYSTICK_SUPPORT
// Static lookup tables for Stelladaptor axis support
static Event::Type SA_Axis[2][2][3];
static Event::Type SA_DrivingValue[2];
#endif
private:
/**
Send an event directly to the event handler.

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.32 2005-05-12 18:45:21 stephena Exp $
// $Id: FrameBuffer.hxx,v 1.33 2005-05-17 18:42:22 stephena Exp $
//============================================================================
#ifndef FRAMEBUFFER_HXX
@ -41,7 +41,7 @@ class OSystem;
All GUI elements (ala ScummVM) are drawn here as well.
@author Stephen Anthony
@version $Id: FrameBuffer.hxx,v 1.32 2005-05-12 18:45:21 stephena Exp $
@version $Id: FrameBuffer.hxx,v 1.33 2005-05-17 18:42:22 stephena Exp $
*/
class FrameBuffer
{
@ -138,7 +138,7 @@ class FrameBuffer
// cerr << "refresh() " << myNumRedraws++ << endl;
theRedrawEntireFrameIndicator = true;
myMenuRedraws = 2;
if(now) drawMediaSource();
if(now) update();
}
/**

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.15 2005-05-16 00:02:32 stephena Exp $
// $Id: OSystem.cxx,v 1.16 2005-05-17 18:42:23 stephena Exp $
//============================================================================
#include <cassert>
@ -256,20 +256,10 @@ bool OSystem::createConsole(const string& romfile)
myRomFile = romfile;
// Open the cartridge image and read it in
ifstream in(myRomFile.c_str(), ios_base::binary);
if(!in)
uInt8* image;
int size;
if(openROM(myRomFile, &image, &size))
{
cerr << "ERROR: Couldn't open " << myRomFile << "..." << endl;
// myEventHandler->quit();
retval = false;
}
else
{
uInt8* image = new uInt8[512 * 1024];
in.read((char*)image, 512 * 1024);
uInt32 size = in.gcount();
in.close();
delete myConsole; myConsole = NULL;
// Create an instance of the 2600 game console
@ -288,6 +278,12 @@ bool OSystem::createConsole(const string& romfile)
myEventHandler->reset(EventHandler::S_EMULATE);
myFrameBuffer->setCursorState();
}
else
{
cerr << "ERROR: Couldn't open " << myRomFile << "..." << endl;
// myEventHandler->quit();
retval = false;
}
return retval;
}
@ -309,6 +305,21 @@ void OSystem::createLauncher()
mySound->mute(true);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool OSystem::openROM(const string& rom, uInt8** image, int* size)
{
ifstream in(rom.c_str(), ios_base::binary);
if(!in)
return false;
*image = new uInt8[512 * 1024];
in.read((char*)(*image), 512 * 1024);
*size = in.gcount();
in.close();
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OSystem::OSystem(const OSystem& osystem)
{

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.14 2005-05-16 00:02:32 stephena Exp $
// $Id: OSystem.hxx,v 1.15 2005-05-17 18:42:23 stephena Exp $
//============================================================================
#ifndef OSYSTEM_HXX
@ -38,7 +38,7 @@ class Launcher;
other objects belong.
@author Stephen Anthony
@version $Id: OSystem.hxx,v 1.14 2005-05-16 00:02:32 stephena Exp $
@version $Id: OSystem.hxx,v 1.15 2005-05-17 18:42:23 stephena Exp $
*/
class OSystem
{
@ -262,6 +262,17 @@ class OSystem
*/
const string& features() { return myFeatures; }
/**
Open the given ROM and return an array containing its contents.
@param rom The absolute pathname of the ROM file
@param image A pointer to store the ROM data
Note, the calling method is responsible for deleting this
@param size The amount of data read into the image array
@return False on any errors, else true
*/
bool openROM(const string& rom, uInt8** image, int* size);
public:
//////////////////////////////////////////////////////////////////////
// The following methods are system-specific and must be implemented

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: Settings.cxx,v 1.43 2005-05-14 03:26:28 stephena Exp $
// $Id: Settings.cxx,v 1.44 2005-05-17 18:42:23 stephena Exp $
//============================================================================
#include <cassert>
@ -66,6 +66,7 @@ Settings::Settings(OSystem* osystem)
set("sssingle", "false");
set("romdir", "");
set("lastrom", "");
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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: LauncherDialog.cxx,v 1.14 2005-05-16 15:37:30 stephena Exp $
// $Id: LauncherDialog.cxx,v 1.15 2005-05-17 18:42:23 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -34,6 +34,7 @@
#include "DialogContainer.hxx"
#include "GuiUtils.hxx"
#include "BrowserDialog.hxx"
#include "ProgressDialog.hxx"
#include "LauncherOptionsDialog.hxx"
#include "LauncherDialog.hxx"
@ -50,8 +51,13 @@ enum {
LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent,
int x, int y, int w, int h)
: Dialog(osystem, parent, x, y, w, h),
myStartButton(NULL),
myOptionsButton(NULL),
myReloadButton(NULL),
myQuitButton(NULL),
myList(NULL),
myGameList(NULL)
myGameList(NULL),
myProgressBar(NULL)
{
// Show game name
new StaticTextWidget(this, 10, 8, 200, kLineHeight,
@ -68,22 +74,22 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent,
int xpos = border;
#ifndef MAC_OSX
new ButtonWidget(this, xpos, _h - 24, width, 16, "Play", kStartCmd, 'S');
myStartButton = new ButtonWidget(this, xpos, _h - 24, width, 16, "Play", kStartCmd, 'S');
xpos += space + width;
new ButtonWidget(this, xpos, _h - 24, width, 16, "Options", kOptionsCmd, 'O');
myOptionsButton = 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');
myReloadButton = new ButtonWidget(this, xpos, _h - 24, width, 16, "Reload", kReloadCmd, 'R');
xpos += space + width;
new ButtonWidget(this, xpos, _h - 24, width, 16, "Quit", kQuitCmd, 'Q');
myQuitButton = new ButtonWidget(this, xpos, _h - 24, width, 16, "Quit", kQuitCmd, 'Q');
xpos += space + width;
#else
new ButtonWidget(this, xpos, _h - 24, width, 16, "Quit", kQuitCmd, 'Q');
myQuitButton = new ButtonWidget(this, xpos, _h - 24, width, 16, "Quit", kQuitCmd, 'Q');
xpos += space + width;
new ButtonWidget(this, xpos, _h - 24, width, 16, "Options", kOptionsCmd, 'O');
myOptionsButton = 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');
myReloadButton = new ButtonWidget(this, xpos, _h - 24, width, 16, "Reload", kReloadCmd, 'R');
xpos += space + width;
new ButtonWidget(this, xpos, _h - 24, width, 16, "Start", kStartCmd, 'Q');
myStartButton = new ButtonWidget(this, xpos, _h - 24, width, 16, "Start", kStartCmd, 'Q');
xpos += space + width;
#endif
@ -97,24 +103,6 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent,
myNote = new StaticTextWidget(this, 50, _h - 43, w - 70, 16,
"", kTextAlignLeft);
// Restore last selection
/*
string last = ConfMan.get(String("lastselectedgame"), ConfigManager::kApplicationDomain);
if (!last.isEmpty())
{
int itemToSelect = 0;
StringList::const_iterator iter;
for (iter = _domains.begin(); iter != _domains.end(); ++iter, ++itemToSelect)
{
if (last == *iter)
{
myList->setSelected(itemToSelect);
break;
}
}
}
*/
// Create the launcher options dialog, where you can change ROM
// and snapshot paths
myOptions = new LauncherOptionsDialog(osystem, parent, 20, 60, _w - 40, _h - 120);
@ -140,36 +128,26 @@ void LauncherDialog::loadConfig()
updateListing();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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();
if (sel >= 0)
ConfMan.set(String("lastselectedgame"), _domains[sel], ConfigManager::kApplicationDomain);
else
ConfMan.removeKey(String("lastselectedgame"), ConfigManager::kApplicationDomain);
ConfMan.flushToDisk();
Dialog::close();
*/
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::reset()
{
myOptions->reset();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::enableButtons(bool enable)
{
myStartButton->setEnabled(enable);
myOptionsButton->setEnabled(enable);
myReloadButton->setEnabled(enable);
myQuitButton->setEnabled(enable);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::updateListing(bool fullReload)
{
enableButtons(false);
// Figure out if the ROM dir has changed since we last accessed it.
// If so, we do a full reload from disk (takes quite some time).
// Otherwise, we can use the cache file (which is much faster).
@ -204,18 +182,54 @@ void LauncherDialog::updateListing(bool fullReload)
ostringstream buf;
buf << myGameList->size() << " files found";
myRomCount->setLabel(buf.str());
enableButtons(true);
// Restore last selection
if(!myList->getList().isEmpty())
{
string lastrom = instance()->settings().getString("lastrom");
if(lastrom == "")
myList->setSelected(0);
else
{
unsigned int itemToSelect = 0;
StringList::const_iterator iter;
for (iter = myList->getList().begin(); iter != myList->getList().end();
++iter, ++itemToSelect)
{
if (lastrom == *iter)
{
myList->setSelected(itemToSelect);
break;
}
}
if(itemToSelect > myList->getList().size())
myList->setSelected(0);
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::loadListFromDisk()
{
Properties props;
string romdir = instance()->settings().getString("romdir");
FilesystemNode dir(romdir);
FSList files = dir.listDir(FilesystemNode::kListAll);
// Create a progress dialog box to show the progress of processing
// the ROMs, since this is usually a time-consuming operation
string message = "Loading ROM's from disk ...";
int w = instance()->frameBuffer().font().getStringWidth(message) + 20,
h = kLineHeight * 4;
int x = (_w - w) / 2,
y = (_h - h) / 2;
ProgressDialog progress(instance(), parent(), x, y, w, h);
progress.setMessage(message);
progress.setRange(0, files.size() - 1, 10);
// Create a entry for the GameList for each file
Properties props;
string path = dir.path(), rom, md5, name, note;
for (unsigned int idx = 0; idx < files.size(); idx++)
{
@ -234,7 +248,11 @@ void LauncherDialog::loadListFromDisk()
name = files[idx].displayName();
myGameList->appendGame(rom, name, note);
// Update the progress bar, indicating one more ROM has been processed
progress.setProgress(idx);
}
progress.done();
// Sort the list by rom name (since that's what we see in the listview)
myGameList->sortByName();
@ -303,19 +321,17 @@ void LauncherDialog::createListCache()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string LauncherDialog::MD5FromFile(const string& path)
{
ifstream in(path.c_str(), ios_base::binary);
if(!in)
uInt8* image;
int size;
if(instance()->openROM(path, &image, &size))
{
string md5 = MD5(image, size);
delete[] image;
return md5;
}
else
return "";
uInt8* image = new uInt8[512 * 1024];
in.read((char*)image, 512 * 1024);
int size = (int) in.gcount();
in.close();
string md5 = MD5(image, size);
delete[] image;
return md5;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -331,7 +347,9 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, int data)
item = myList->getSelected();
if(item >= 0)
{
string s = myList->getSelectedString();
instance()->createConsole(myGameList->rom(item));
instance()->settings().setString("lastrom", s);
close();
}
break;

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: LauncherDialog.hxx,v 1.7 2005-05-16 15:37:30 stephena Exp $
// $Id: LauncherDialog.hxx,v 1.8 2005-05-17 18:42:23 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -24,9 +24,11 @@
class DialogContainer;
class LauncherOptionsDialog;
class ProgressDialog;
class CommandSender;
class StaticTextWidget;
class ListWidget;
class ButtonWidget;
class OSystem;
#include "Dialog.hxx"
@ -45,19 +47,25 @@ class LauncherDialog : public Dialog
protected:
void updateListing(bool fullReload = false);
void close();
void reset();
void loadConfig();
protected:
ButtonWidget* myStartButton;
ButtonWidget* myOptionsButton;
ButtonWidget* myReloadButton;
ButtonWidget* myQuitButton;
ListWidget* myList;
StaticTextWidget* myNote;
StaticTextWidget* myRomCount;
GameList* myGameList;
LauncherOptionsDialog* myOptions;
ProgressDialog* myProgressBar;
private:
void enableButtons(bool enable);
void loadListFromDisk();
void loadListFromCache();
void createListCache();

View File

@ -0,0 +1,92 @@
//============================================================================
//
// 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: ProgressDialog.cxx,v 1.1 2005-05-17 18:42:23 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#include "OSystem.hxx"
#include "Widget.hxx"
#include "Dialog.hxx"
#include "DialogContainer.hxx"
#include "ProgressDialog.hxx"
#include "GuiUtils.hxx"
#include "bspf.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ProgressDialog::ProgressDialog(OSystem* osystem, DialogContainer* parent,
int x, int y, int w, int h)
: Dialog(osystem, parent, x, y, w, h),
myMessage(NULL),
mySlider(NULL),
myStart(0),
myFinish(0),
myStep(0)
{
myMessage = new StaticTextWidget(this, 0, 10, w, kLineHeight, "", kTextAlignCenter);
myMessage->setColor(kTextColorEm);
mySlider = new SliderWidget(this, 10, 15 + kLineHeight, w - 20, kLineHeight, "", 0, 0);
mySlider->setMinValue(100);
mySlider->setMaxValue(200);
mySlider->setValue(100); // Prevents the slider from initially drawing
// across the entire screen for a split-second
parent->addDialog(this);
instance()->frameBuffer().refresh(true);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ProgressDialog::~ProgressDialog()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ProgressDialog::done()
{
parent()->removeDialog();
instance()->frameBuffer().refresh(true);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ProgressDialog::setMessage(const string& message)
{
myMessage->setLabel(message);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ProgressDialog::setRange(int start, int finish, int step)
{
myStart = start;
myFinish = finish;
myStep = step;
myCurrentStep = 100;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ProgressDialog::setProgress(int progress)
{
// Only increase the progress bar if we have arrived at a new step
// IE, we only increase in intervals specified by setRange()
int p = (int) (((double)progress / myFinish) * 100 + 100);
if(p >= myCurrentStep)
{
myCurrentStep += myStep;
mySlider->setValue(p);
instance()->frameBuffer().refresh(true);
}
}

View File

@ -0,0 +1,51 @@
//============================================================================
//
// 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 and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: ProgressDialog.hxx,v 1.1 2005-05-17 18:42:23 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#ifndef PROGRESS_DIALOG_HXX
#define PROGRESS_DIALOG_HXX
class DialogContainer;
class StaticTextWidget;
class SliderWidget;
#include "OSystem.hxx"
#include "bspf.hxx"
class ProgressDialog : public Dialog
{
public:
ProgressDialog(OSystem* osystem, DialogContainer* parent,
int x, int y, int w, int h);
~ProgressDialog();
void setMessage(const string& message);
void setRange(int begin, int end, int step);
void setProgress(int progress);
void done();
protected:
StaticTextWidget* myMessage;
SliderWidget* mySlider;
int myStart, myFinish, myStep, myCurrentStep;
};
#endif