2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
2016-08-05 09:42:15 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
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"
|
2014-07-21 17:45:56 +08:00
|
|
|
#include "ui/GUIExport.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-12-05 00:26:07 +08:00
|
|
|
struct CC_DLL ResourceData;
|
2015-11-18 13:38:29 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
namespace ui {
|
2014-07-30 16:08:29 +08:00
|
|
|
class Scale9Sprite;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
*@brief Visual indicator of progress in some operation.
|
|
|
|
* Displays a bar to the user representing how far the operation has progressed.
|
|
|
|
*
|
|
|
|
*/
|
2014-07-21 17:45:56 +08:00
|
|
|
class CC_GUI_DLL LoadingBar : public Widget
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
DECLARE_CLASS_GUI_INFO
|
|
|
|
|
|
|
|
public:
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Loading bar progress direction.
|
|
|
|
*/
|
2014-05-12 10:12:22 +08:00
|
|
|
enum class Direction
|
|
|
|
{
|
|
|
|
LEFT,
|
|
|
|
RIGHT
|
|
|
|
};
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Default constructor.
|
2015-03-28 16:02:47 +08:00
|
|
|
* @js ctor
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua new
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
LoadingBar();
|
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Default destructor.
|
2015-03-28 16:02:47 +08:00
|
|
|
* @js NA
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
virtual ~LoadingBar();
|
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Create an empty LoadingBar.
|
|
|
|
*@return A LoadingBar instance.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
static LoadingBar* create();
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-04-02 17:53:06 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* @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.
|
|
|
|
*/
|
2014-05-13 10:34:08 +08:00
|
|
|
static LoadingBar* create(const std::string& textureName, float percentage = 0);
|
2014-04-02 17:53:06 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
2014-12-10 10:21:17 +08:00
|
|
|
static LoadingBar* create(const std::string& textureName,
|
|
|
|
TextureResType texType,
|
|
|
|
float percentage = 0);
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Change the progress direction of LoadingBar.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @see Direction `LEFT` means progress left to right, `RIGHT` otherwise.
|
2014-05-21 16:35:47 +08:00
|
|
|
* @param direction Direction
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-05-14 10:48:16 +08:00
|
|
|
void setDirection(Direction direction);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Get the progress direction of LoadingBar.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @see Direction `LEFT` means progress left to right, `RIGHT` otherwise.
|
|
|
|
* @return LoadingBar progress direction.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-05-14 17:07:24 +08:00
|
|
|
Direction getDirection()const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Load texture for LoadingBar.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param texture File name of texture.
|
|
|
|
* @param texType Texture resource type,@see TextureResType.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-05-09 14:56:05 +08:00
|
|
|
void loadTexture(const std::string& texture,TextureResType texType = TextureResType::LOCAL);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Changes the progress value of LoadingBar.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param percent Percent value from 1 to 100.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-05-13 10:34:08 +08:00
|
|
|
void setPercent(float percent);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Get the progress value of LoadingBar.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @return Progress value from 1 to 100.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-05-13 12:06:28 +08:00
|
|
|
float getPercent() const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Enable scale9 renderer.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param enabled Set to true will use scale9 renderer, false otherwise.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
void setScale9Enabled(bool enabled);
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query whether LoadingBar is using scale9 renderer or not.
|
|
|
|
* @return Whether LoadingBar uses scale9 renderer or not.
|
|
|
|
*/
|
2014-05-27 10:42:11 +08:00
|
|
|
bool isScale9Enabled()const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Set capInsets for LoadingBar.
|
|
|
|
* This setting only take effect when enable scale9 renderer.
|
|
|
|
* @param capInsets CapInset in `Rect`.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
void setCapInsets(const Rect &capInsets);
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query LoadingBar's capInsets.
|
|
|
|
* @return CapInsets of LoadingBar.
|
|
|
|
*/
|
2014-05-27 10:42:11 +08:00
|
|
|
const Rect& getCapInsets()const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
//override methods.
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual void ignoreContentAdaptWithSize(bool ignore) override;
|
2014-09-12 14:39:22 +08:00
|
|
|
virtual Size getVirtualRendererSize() const override;
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual Node* getVirtualRenderer() override;
|
|
|
|
virtual std::string getDescription() const override;
|
2015-11-18 13:38:29 +08:00
|
|
|
|
2015-12-05 00:26:07 +08:00
|
|
|
ResourceData getRenderFile();
|
2015-11-18 13:38:29 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
|
|
|
virtual void initRenderer() override;
|
|
|
|
virtual void onSizeChanged() override;
|
2014-06-06 16:03:59 +08:00
|
|
|
|
2015-12-22 19:53:24 +08:00
|
|
|
void setScale9Scale();
|
2015-01-26 13:49:54 +08:00
|
|
|
void updateProgressBar();
|
2014-03-11 17:13:54 +08:00
|
|
|
void barRendererScaleChangedWithSize();
|
2015-06-05 15:57:39 +08:00
|
|
|
|
|
|
|
void setupTexture();
|
2015-12-23 14:43:25 +08:00
|
|
|
void handleSpriteFlipX();
|
2015-06-05 15:57:39 +08:00
|
|
|
void loadTexture(SpriteFrame* spriteframe);
|
2014-06-06 16:03:59 +08:00
|
|
|
|
|
|
|
virtual void adaptRenderers() override;
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual Widget* createCloneInstance() override;
|
|
|
|
virtual void copySpecialProperties(Widget* model) override;
|
|
|
|
protected:
|
2014-05-12 10:12:22 +08:00
|
|
|
Direction _direction;
|
2014-05-13 10:34:08 +08:00
|
|
|
float _percent;
|
2014-03-11 17:13:54 +08:00
|
|
|
float _totalLength;
|
2014-07-30 16:08:29 +08:00
|
|
|
Scale9Sprite* _barRenderer;
|
2014-03-11 17:13:54 +08:00
|
|
|
TextureResType _renderBarTexType;
|
|
|
|
Size _barRendererTextureSize;
|
2016-12-03 23:35:22 +08:00
|
|
|
Rect _originalRect;
|
2014-03-11 17:13:54 +08:00
|
|
|
bool _scale9Enabled;
|
|
|
|
bool _prevIgnoreSize;
|
|
|
|
Rect _capInsets;
|
2014-04-17 14:08:25 +08:00
|
|
|
bool _barRendererAdaptDirty;
|
2015-11-18 13:38:29 +08:00
|
|
|
std::string _textureFile;
|
2014-03-11 17:13:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2015-03-25 18:17:58 +08:00
|
|
|
// end of ui group
|
|
|
|
/// @}
|
2014-03-11 17:13:54 +08:00
|
|
|
NS_CC_END
|
|
|
|
#endif /* defined(__CocoGUI__LoadingBar__) */
|