2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2022-07-09 01:23:11 +08:00
|
|
|
https://axis-project.github.io/
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
struct AX_DLL ResourceData;
|
2015-11-18 13:38:29 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace ui
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_GUI_DLL LoadingBar : public Widget
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
DECLARE_CLASS_GUI_INFO
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
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();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
/**
|
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();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
/**
|
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();
|
2021-12-25 10:04:45 +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.
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static LoadingBar* create(std::string_view textureName, float percentage = 0);
|
2021-12-25 10:04:45 +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.
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static LoadingBar* create(std::string_view textureName, TextureResType texType, float percentage = 0);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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
|
|
|
*/
|
2021-12-25 10:04:45 +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
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
void loadTexture(std::string_view texture, TextureResType texType = TextureResType::LOCAL);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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.
|
|
|
|
*/
|
2021-12-25 10:04:45 +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
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void setCapInsets(const Rect& capInsets);
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Query LoadingBar's capInsets.
|
|
|
|
* @return CapInsets of LoadingBar.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
const Rect& getCapInsets() const;
|
|
|
|
|
|
|
|
// override methods.
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual void ignoreContentAdaptWithSize(bool ignore) override;
|
2021-10-23 23:27:14 +08:00
|
|
|
virtual Vec2 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
|
|
|
|
2021-12-25 10:04:45 +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;
|
2021-12-25 10:04:45 +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);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-06 16:03:59 +08:00
|
|
|
virtual void adaptRenderers() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual Widget* createCloneInstance() override;
|
|
|
|
virtual void copySpecialProperties(Widget* model) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
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;
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 _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
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace ui
|
2015-03-25 18:17:58 +08:00
|
|
|
// end of ui group
|
|
|
|
/// @}
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2014-03-11 17:13:54 +08:00
|
|
|
#endif /* defined(__CocoGUI__LoadingBar__) */
|