1 //
2 // Copyright (c) 2008-2017 the Urho3D project.
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21 //
22 
23 #pragma once
24 
25 #include "BorderImage.h"
26 #include "../Math/Vector2.h"
27 #include "Text.h"
28 
29 namespace Urho3D
30 {
31 
32 /// %ProgressBar bar %UI element.
33 class URHO3D_API ProgressBar : public BorderImage
34 {
35     URHO3D_OBJECT(ProgressBar, BorderImage);
36 
37 public:
38     /// Construct.
39     ProgressBar(Context *context);
40 
41     /// Destruct.
42     virtual ~ProgressBar();
43 
44     /// Register object factory.
45     static void RegisterObject(Context *context);
46 
47     /// React to resize.
48     virtual void OnResize(const IntVector2& newSize, const IntVector2& delta);
49 
50     /// Set orientation type.
51     void SetOrientation(Orientation orientation);
52 
53     /// Set ProgressBar range maximum value (minimum value is always 0.)
54     void SetRange(float range);
55 
56     /// Set ProgressBar current value.
57     void SetValue(float value);
58 
59     /// Change value by a delta.
60     void ChangeValue(float delta);
61 
62     /// Return orientation type.
GetOrientation()63     Orientation GetOrientation() const { return orientation_; }
64 
65     /// Return ProgressBar range.
GetRange()66     float GetRange() const { return range_; }
67 
68     /// Return ProgressBar current value.
GetValue()69     float GetValue() const { return value_; }
70 
71     /// Return knob element.
GetKnob()72     BorderImage *GetKnob() const { return knob_; }
73 
74     /// Sets the loading percent style.
SetLoadingPercentStyle(const String & style)75     void SetLoadingPercentStyle(const String &style) { loadingPercentStyle_ = style; }
76 
77     /// Returns the loading percent style.
GetLoadingPercentStyle()78     const String& GetLoadingPercentStyle() const { return loadingPercentStyle_; }
79 
80     /// Sets the flag to display the percent text.
81     void SetShowPercentText(bool showPercentText);
82 
83     /// Returns the flag to display the percent text.
GetShowPercentText()84     bool GetShowPercentText() const { return showPercentText_; }
85 
86 protected:
87     /// Filter implicit attributes in serialization process.
88     virtual bool FilterImplicitAttributes(XMLElement &dest) const;
89 
90     /// Update ProgressBar knob position & size.
91     void UpdateProgressBar();
92 
93     /// ProgressBar knob.
94     SharedPtr <BorderImage> knob_;
95     /// ProgressBar text
96     SharedPtr <Text> loadingText_;
97     /// Orientation.
98     Orientation orientation_;
99     /// ProgressBar text style
100     String loadingPercentStyle_;
101     /// ProgressBar range.
102     float range_;
103     /// ProgressBar current value.
104     float value_;
105     /// Flag to show the percent text.
106     bool showPercentText_;
107 };
108 
109 }
110