axmol/cocos/gui/UILoadingBar.h

162 lines
4.5 KiB
C
Raw Normal View History

2013-09-20 22:23:13 +08:00
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
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.
****************************************************************************/
2013-09-20 22:23:13 +08:00
#ifndef __UILOADINGBAR_H__
#define __UILOADINGBAR_H__
#include "gui/UIWidget.h"
2013-09-20 22:23:13 +08:00
2013-12-23 15:02:52 +08:00
NS_CC_BEGIN
namespace ui {
2013-09-20 22:23:13 +08:00
typedef enum
{
LoadingBarTypeLeft,
LoadingBarTypeRight
}LoadingBarType;
2013-12-23 15:02:52 +08:00
/**
* @js NA
* @lua NA
*/
class LoadingBar : public Widget
2013-09-20 22:23:13 +08:00
{
2014-03-04 16:51:35 +08:00
DECLARE_CLASS_GUI_INFO
2013-09-20 22:23:13 +08:00
public:
/**
* Default constructor
*/
2013-12-23 15:02:52 +08:00
LoadingBar();
2013-09-20 22:23:13 +08:00
/**
* Default destructor
*/
2013-12-23 15:02:52 +08:00
virtual ~LoadingBar();
2013-09-20 22:23:13 +08:00
/**
* Allocates and initializes.
*/
2013-12-23 15:02:52 +08:00
static LoadingBar* create();
2013-09-20 22:23:13 +08:00
/**
* Changes the progress direction of loadingbar.
*
* @see LoadingBarType LoadingBarTypeLeft means progress left to right, LoadingBarTypeRight otherwise.
*
* @param LoadingBarType
*/
void setDirection(LoadingBarType dir);
/**
* Gets the progress direction of loadingbar.
*
* @see LoadingBarType LoadingBarTypeLeft means progress left to right, LoadingBarTypeRight otherwise.
*
* @param LoadingBarType
*/
int getDirection();
/**
* Load texture for loadingbar.
*
* @param fileName file name of texture.
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTexture(const char* texture,TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Changes the progress direction of loadingbar.
*
* @param percent percent value from 1 to 100.
*/
void setPercent(int percent);
/**
* Gets the progress direction of loadingbar.
*
* @return percent percent value from 1 to 100.
*/
int getPercent();
/**
* Sets if loadingbar is using scale9 renderer.
*
* @param true that using scale9 renderer, false otherwise.
*/
void setScale9Enabled(bool enabled);
2014-03-01 22:34:25 +08:00
bool isScale9Enabled();
2013-09-20 22:23:13 +08:00
/**
* Sets capinsets for loadingbar, if loadingbar is using scale9 renderer.
*
* @param capInsets capinsets for loadingbar
*/
2013-12-23 15:02:52 +08:00
void setCapInsets(const Rect &capInsets);
2013-09-20 22:23:13 +08:00
2014-03-01 22:34:25 +08:00
const Rect& getCapInsets();
2013-09-20 22:23:13 +08:00
//override "ignoreContentAdaptWithSize" method of widget.
2013-11-14 13:42:10 +08:00
virtual void ignoreContentAdaptWithSize(bool ignore) override;
2013-09-20 22:23:13 +08:00
//override "getContentSize" method of widget.
2013-12-23 15:02:52 +08:00
virtual const Size& getContentSize() const override;
2013-09-20 22:23:13 +08:00
//override "getVirtualRenderer" method of widget.
2013-12-23 15:02:52 +08:00
virtual Node* getVirtualRenderer() override;
2013-09-20 22:23:13 +08:00
/**
* Returns the "class name" of widget.
*/
2013-12-23 15:02:52 +08:00
virtual std::string getDescription() const override;
2013-09-20 22:23:13 +08:00
protected:
2013-11-14 13:42:10 +08:00
virtual void initRenderer() override;
virtual void onSizeChanged() override;
virtual void updateTextureColor() override;
virtual void updateTextureOpacity() override;
virtual void updateTextureRGBA() override;
2013-09-20 22:23:13 +08:00
void setScale9Scale();
void barRendererScaleChangedWithSize();
2013-12-23 15:02:52 +08:00
virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;
2013-09-20 22:23:13 +08:00
protected:
LoadingBarType _barType;
int _percent;
float _totalLength;
2013-12-23 15:02:52 +08:00
Node* _barRenderer;
2013-09-20 22:23:13 +08:00
TextureResType _renderBarTexType;
2013-12-23 15:02:52 +08:00
Size _barRendererTextureSize;
2013-09-20 22:23:13 +08:00
bool _scale9Enabled;
bool _prevIgnoreSize;
2013-12-23 15:02:52 +08:00
Rect _capInsets;
2013-09-20 22:23:13 +08:00
std::string _textureFile;
};
}
2013-12-23 15:02:52 +08:00
NS_CC_END
#endif /* defined(__CocoGUI__LoadingBar__) */