~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/gui/ProgressDialog.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Mario Iseli
  • Date: 2006-04-08 18:38:25 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060408183825-vu1jk57rk929derx
* New Maintainer (Closes: #361345)
* New upstream release (Closes: #349725)
* Build-Depend now on libslang2-dev (Closes: #325577)
* Complete rebuild of debian/, upgraded to policy-standards
  3.6.2 and compat-level 5.
* Removed stellarc since stella only reads ~/.stellarc and even
  works without a first config.
* New debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//============================================================================
 
2
//
 
3
//   SSSS    tt          lll  lll       
 
4
//  SS  SS   tt           ll   ll        
 
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
 
10
//
 
11
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
 
12
//
 
13
// See the file "license" for information on usage and redistribution of
 
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
 
15
//
 
16
// $Id: ProgressDialog.cxx,v 1.6 2006/02/22 17:38:04 stephena Exp $
 
17
//
 
18
//   Based on code from ScummVM - Scumm Interpreter
 
19
//   Copyright (C) 2002-2004 The ScummVM project
 
20
//============================================================================
 
21
 
 
22
#include "OSystem.hxx"
 
23
#include "Widget.hxx"
 
24
#include "Dialog.hxx"
 
25
#include "DialogContainer.hxx"
 
26
#include "ProgressDialog.hxx"
 
27
#include "GuiUtils.hxx"
 
28
 
 
29
#include "bspf.hxx"
 
30
 
 
31
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
32
ProgressDialog::ProgressDialog(GuiObject* boss, const GUI::Font& font,
 
33
                               const string& message)
 
34
    : Dialog(boss->instance(), boss->parent(), 0, 0, 16, 16),
 
35
      myMessage(NULL),
 
36
      mySlider(NULL),
 
37
      myStart(0),
 
38
      myFinish(0),
 
39
      myStep(0)
 
40
{
 
41
  const int fontWidth  = font.getMaxCharWidth(),
 
42
            fontHeight = font.getFontHeight(),
 
43
            lineHeight = font.getLineHeight();
 
44
  int xpos, ypos, lwidth;
 
45
 
 
46
  // Calculate real dimensions
 
47
  lwidth = font.getStringWidth(message);
 
48
  _w = lwidth + 2 * fontWidth;
 
49
  _h = lineHeight * 5;
 
50
  _x = (boss->getWidth() - _w) / 2;
 
51
  _y = (boss->getHeight() - _h) / 2;
 
52
 
 
53
  xpos = fontWidth; ypos = lineHeight;
 
54
  myMessage = new StaticTextWidget(this, font, xpos, ypos, lwidth, fontHeight,
 
55
                                   message, kTextAlignCenter);
 
56
  myMessage->setColor(kTextColorEm);
 
57
 
 
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
 
64
 
 
65
  parent()->addDialog(this);
 
66
  instance()->frameBuffer().update();
 
67
}
 
68
 
 
69
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
70
ProgressDialog::~ProgressDialog()
 
71
{
 
72
}
 
73
 
 
74
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
75
void ProgressDialog::done()
 
76
{
 
77
  parent()->removeDialog();
 
78
}
 
79
 
 
80
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
81
void ProgressDialog::setMessage(const string& message)
 
82
{
 
83
  myMessage->setLabel(message);
 
84
}
 
85
 
 
86
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
87
void ProgressDialog::setRange(int start, int finish, int step)
 
88
{
 
89
  myStart = start;
 
90
  myFinish = finish;
 
91
  myStep = step;
 
92
  myCurrentStep = 100;
 
93
}
 
94
 
 
95
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
96
void ProgressDialog::setProgress(int progress)
 
97
{
 
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)
 
102
  {
 
103
    myCurrentStep += myStep;
 
104
    mySlider->setValue(p);
 
105
    instance()->frameBuffer().update();
 
106
  }
 
107
}