ScummVM API documentation
ProgressBar.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on the CRAB engine
24  *
25  * Copyright (c) Arvind Raja Yadav
26  *
27  * Licensed under MIT
28  *
29  */
30 
31 #ifndef CRAB_PROGRESSBAR_H
32 #define CRAB_PROGRESSBAR_H
33 
34 #include "crab/timer.h"
35 #include "crab/ui/ClipButton.h"
36 
37 namespace Crab {
38 
39 namespace pyrodactyl {
40 namespace ui {
41 class ProgressBar : public ClipButton {
42  // Whenever the progress bar value is changed, we display a glowing effect
43  Timer _timer;
44 
45  // The total time for which the change effect must be shown
46  uint32 _notifyRate;
47 
48  // Are we currently displaying the effect?
49  bool _changed;
50 
51  // The effect also depends on if the change was positive or negative, so store the previous value
52  int _old;
53 
54  // If we are drawing an animation, we need to smoothly transition from old->value
55  // This stores the current progress
56  int _cur;
57 
58  // The type of effect being drawn
59  enum {
60  NONE,
61  INCREASE,
62  DECREASE
63  } _type;
64 
65  // We reuse the button images for the 2 types of effect
66  ImageKey _inc, _dec;
67 
68  // Where to draw the effect
69  Vector2i _offset;
70 
71  // The caption text changes depending on the value of the progress bar - we store all possible text here
72  struct CaptionText {
73  // The text to be drawn
74  Common::String _text;
75 
76  // The above text is drawn only if the progress bar value is greater than this val
77  int _val;
78 
79  CaptionText() {
80  _val = 0;
81  }
82 
83  CaptionText(rapidxml::xml_node<char> *node) {
84  if (!loadNum(_val, "val", node))
85  _val = 0;
86 
87  if (!loadStr(_text, "text", node))
88  _text = "";
89  }
90  };
91 
93 
94 public:
95  ProgressBar() {
96  _old = 0;
97  _cur = 0;
98  _inc = 0;
99  _dec = 0;
100  _notifyRate = 5;
101  reset();
102  }
103  ~ProgressBar() {}
104 
105  // Reset the effect
106  void reset() {
107  _changed = false;
108  _type = NONE;
109  }
110  void load(rapidxml::xml_node<char> *node);
111 
112  void draw(const int &value, const int &max);
113  void effect(const int &value, const int &prev);
114 };
115 } // End of namespace ui
116 } // End of namespace pyrodactyl
117 
118 } // End of namespace Crab
119 
120 #endif // CRAB_PROGRESSBAR_H
Definition: str.h:59
Definition: moveeffect.h:37
Definition: ClipButton.h:41
Definition: timer.h:43
Definition: ProgressBar.h:41