UILoadingBar.h
5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/****************************************************************************
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __UILOADINGBAR_H__
#define __UILOADINGBAR_H__
#include "ui/UIWidget.h"
#include "ui/GUIExport.h"
NS_CC_BEGIN
/**
* @addtogroup ui
* @{
*/
struct CC_DLL ResourceData;
namespace ui {
class Scale9Sprite;
/**
*@brief Visual indicator of progress in some operation.
* Displays a bar to the user representing how far the operation has progressed.
*
*/
class CC_GUI_DLL LoadingBar : public Widget
{
DECLARE_CLASS_GUI_INFO
public:
/**
* Loading bar progress direction.
*/
enum class Direction
{
LEFT,
RIGHT
};
/**
* Default constructor.
* @js ctor
* @lua new
*/
LoadingBar();
/**
* Default destructor.
* @js NA
* @lua NA
*/
virtual ~LoadingBar();
/**
* Create an empty LoadingBar.
*@return A LoadingBar instance.
*/
static LoadingBar* create();
/**
* @brief Create a LoadingBar with a texture name and a predefined progress value.
*
* @param textureName LoadingBar background texture name.
* @param percentage A percentage in float.
* @return A LoadingBar instance.
*/
static LoadingBar* create(const std::string& textureName, float percentage = 0);
/**
* @brief Create a LoadingBar with a texture name along with its texture type and a predefined progress value.
*
* @param textureName LoadingBar background texture name.
* @param texType LoadingBar background texture type.
* @param percentage A percentage in float, default value is 0.
* @return A LoadingBar instance.
*/
static LoadingBar* create(const std::string& textureName,
TextureResType texType,
float percentage = 0);
/**
* Change the progress direction of LoadingBar.
*
* @see Direction `LEFT` means progress left to right, `RIGHT` otherwise.
* @param direction Direction
*/
void setDirection(Direction direction);
/**
* Get the progress direction of LoadingBar.
*
* @see Direction `LEFT` means progress left to right, `RIGHT` otherwise.
* @return LoadingBar progress direction.
*/
Direction getDirection()const;
/**
* Load texture for LoadingBar.
*
* @param texture File name of texture.
* @param texType Texture resource type,@see TextureResType.
*/
void loadTexture(const std::string& texture,TextureResType texType = TextureResType::LOCAL);
/**
* Changes the progress value of LoadingBar.
*
* @param percent Percent value from 1 to 100.
*/
void setPercent(float percent);
/**
* Get the progress value of LoadingBar.
*
* @return Progress value from 1 to 100.
*/
float getPercent() const;
/**
* Enable scale9 renderer.
*
* @param enabled Set to true will use scale9 renderer, false otherwise.
*/
void setScale9Enabled(bool enabled);
/**
* @brief Query whether LoadingBar is using scale9 renderer or not.
* @return Whether LoadingBar uses scale9 renderer or not.
*/
bool isScale9Enabled()const;
/**
* Set capInsets for LoadingBar.
* This setting only take effect when enable scale9 renderer.
* @param capInsets CapInset in `Rect`.
*/
void setCapInsets(const Rect &capInsets);
/**
* @brief Query LoadingBar's capInsets.
* @return CapInsets of LoadingBar.
*/
const Rect& getCapInsets()const;
//override methods.
virtual void ignoreContentAdaptWithSize(bool ignore) override;
virtual Size getVirtualRendererSize() const override;
virtual Node* getVirtualRenderer() override;
virtual std::string getDescription() const override;
ResourceData getRenderFile();
protected:
virtual void initRenderer() override;
virtual void onSizeChanged() override;
void setScale9Scale();
void updateProgressBar();
void barRendererScaleChangedWithSize();
void setupTexture();
void handleSpriteFlipX();
void loadTexture(SpriteFrame* spriteframe);
virtual void adaptRenderers() override;
virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;
protected:
Direction _direction;
float _percent;
float _totalLength;
Scale9Sprite* _barRenderer;
TextureResType _renderBarTexType;
Size _barRendererTextureSize;
Rect _originalRect;
bool _scale9Enabled;
bool _prevIgnoreSize;
Rect _capInsets;
bool _barRendererAdaptDirty;
std::string _textureFile;
};
}
// end of ui group
/// @}
NS_CC_END
#endif /* defined(__CocoGUI__LoadingBar__) */