1
//============================================================================
5
// SS tttttt eeee ll ll aaaa
6
// SSSS tt ee ee ll ll aa
7
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8
// SS SS tt ee ll ll aa aa
9
// SSSS ttt eeeee llll llll aaaaa
11
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
13
// See the file "license" for information on usage and redistribution of
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
// $Id: ProgressDialog.cxx,v 1.6 2006/02/22 17:38:04 stephena Exp $
18
// Based on code from ScummVM - Scumm Interpreter
19
// Copyright (C) 2002-2004 The ScummVM project
20
//============================================================================
22
#include "OSystem.hxx"
25
#include "DialogContainer.hxx"
26
#include "ProgressDialog.hxx"
27
#include "GuiUtils.hxx"
31
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32
ProgressDialog::ProgressDialog(GuiObject* boss, const GUI::Font& font,
33
const string& message)
34
: Dialog(boss->instance(), boss->parent(), 0, 0, 16, 16),
41
const int fontWidth = font.getMaxCharWidth(),
42
fontHeight = font.getFontHeight(),
43
lineHeight = font.getLineHeight();
44
int xpos, ypos, lwidth;
46
// Calculate real dimensions
47
lwidth = font.getStringWidth(message);
48
_w = lwidth + 2 * fontWidth;
50
_x = (boss->getWidth() - _w) / 2;
51
_y = (boss->getHeight() - _h) / 2;
53
xpos = fontWidth; ypos = lineHeight;
54
myMessage = new StaticTextWidget(this, font, xpos, ypos, lwidth, fontHeight,
55
message, kTextAlignCenter);
56
myMessage->setColor(kTextColorEm);
58
xpos = fontWidth; ypos += 2 * lineHeight;
59
mySlider = new SliderWidget(this, font, xpos, ypos, lwidth, lineHeight, "", 0, 0);
60
mySlider->setMinValue(100);
61
mySlider->setMaxValue(200);
62
mySlider->setValue(100); // Prevents the slider from initially drawing
63
// across the entire screen for a split-second
65
parent()->addDialog(this);
66
instance()->frameBuffer().update();
69
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70
ProgressDialog::~ProgressDialog()
74
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
75
void ProgressDialog::done()
77
parent()->removeDialog();
80
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
81
void ProgressDialog::setMessage(const string& message)
83
myMessage->setLabel(message);
86
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87
void ProgressDialog::setRange(int start, int finish, int step)
95
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
96
void ProgressDialog::setProgress(int progress)
98
// Only increase the progress bar if we have arrived at a new step
99
// IE, we only increase in intervals specified by setRange()
100
int p = (int) (((double)progress / myFinish) * 100 + 100);
101
if(p >= myCurrentStep)
103
myCurrentStep += myStep;
104
mySlider->setValue(p);
105
instance()->frameBuffer().update();