2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 Lam Pham
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2017-02-14 14:36:57 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2012-04-19 14:35:52 +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 __MISC_NODE_CCPROGRESS_TIMER_H__
|
|
|
|
#define __MISC_NODE_CCPROGRESS_TIMER_H__
|
|
|
|
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "renderer/CCCustomCommand.h"
|
2014-08-28 17:03:29 +08:00
|
|
|
#include "2d/CCNode.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2014-08-28 17:03:29 +08:00
|
|
|
class Sprite;
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
2015-03-21 17:06:26 +08:00
|
|
|
* @addtogroup _2d
|
2012-06-20 18:09:11 +08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2010-08-11 18:15:52 +08:00
|
|
|
/**
|
2015-03-19 10:00:30 +08:00
|
|
|
* @brief ProgressTimer is a subclass of Node.
|
|
|
|
* It renders the inner sprite according to the percentage.
|
|
|
|
* The progress can be Radial, Horizontal or vertical.
|
|
|
|
* @since v0.99.1
|
|
|
|
*/
|
2013-12-06 18:07:16 +08:00
|
|
|
class CC_DLL ProgressTimer : public Node
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-07-25 15:11:36 +08:00
|
|
|
/** Types of progress
|
2015-03-19 10:00:30 +08:00
|
|
|
* @since v0.99.1
|
2013-07-25 15:11:36 +08:00
|
|
|
*/
|
2013-07-26 17:28:18 +08:00
|
|
|
enum class Type
|
2013-07-25 15:11:36 +08:00
|
|
|
{
|
2015-03-19 10:00:30 +08:00
|
|
|
RADIAL,/** Radial Counter-Clockwise. */
|
|
|
|
BAR,/** Bar. */
|
2013-07-25 15:11:36 +08:00
|
|
|
};
|
|
|
|
|
2015-03-19 10:00:30 +08:00
|
|
|
/** Creates a progress timer with the sprite as the shape the timer goes through.
|
|
|
|
*
|
|
|
|
* @param sp The sprite as the shape the timer goes through.
|
|
|
|
* @return A ProgressTimer.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
static ProgressTimer* create(Sprite* sp);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-19 10:00:30 +08:00
|
|
|
/** Change the percentage to change progress.
|
|
|
|
*
|
|
|
|
* @return A Type
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
Type getType() const { return _type; }
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-19 10:00:30 +08:00
|
|
|
/** Percentages are from 0 to 100.
|
|
|
|
*
|
|
|
|
* @return Percentages.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getPercentage() const { return _percentage; }
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-19 10:00:30 +08:00
|
|
|
/** The image to show the progress percentage, retain.
|
|
|
|
*
|
|
|
|
* @return A sprite.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
Sprite* getSprite() const { return _sprite; }
|
2015-03-19 10:00:30 +08:00
|
|
|
|
|
|
|
/** Set the initial percentage values.
|
|
|
|
*
|
|
|
|
* @param percentage The initial percentage values.
|
|
|
|
*/
|
2013-12-18 17:47:20 +08:00
|
|
|
void setPercentage(float percentage);
|
2015-03-19 10:00:30 +08:00
|
|
|
|
|
|
|
/** Set the sprite as the shape.
|
|
|
|
*
|
|
|
|
* @param sprite The sprite as the shape.
|
|
|
|
*/
|
2013-12-18 17:47:20 +08:00
|
|
|
void setSprite(Sprite *sprite);
|
2015-03-19 10:00:30 +08:00
|
|
|
|
|
|
|
/** Set the ProgressTimer type.
|
|
|
|
*
|
|
|
|
* @param type Is an Type.
|
|
|
|
*/
|
2013-07-25 15:11:36 +08:00
|
|
|
void setType(Type type);
|
2015-03-19 10:00:30 +08:00
|
|
|
|
2016-08-15 14:08:42 +08:00
|
|
|
/** Return the Reverse direction.
|
2015-03-19 10:00:30 +08:00
|
|
|
*
|
|
|
|
* @return If the direction is Anti-clockwise,it will return true.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
bool isReverseDirection() { return _reverseDirection; };
|
2015-03-19 10:00:30 +08:00
|
|
|
|
|
|
|
/** Set the Reverse direction.
|
|
|
|
*
|
|
|
|
* @param value If value is false it will clockwise,if is true it will Anti-clockwise.
|
|
|
|
*/
|
2016-08-15 14:08:42 +08:00
|
|
|
void setReverseDirection(bool value);
|
|
|
|
|
|
|
|
/** Set the Reverse direction.
|
|
|
|
* @js setReverseDirection
|
|
|
|
* @lua setReverseDirection
|
|
|
|
* @param reverse If reverse is false it will clockwise,if is true it will Anti-clockwise.
|
|
|
|
*/
|
|
|
|
CC_DEPRECATED_ATTRIBUTE void setReverseProgress(bool reverse) { setReverseDirection(reverse); }
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-20 04:16:38 +08:00
|
|
|
/**
|
|
|
|
* Midpoint is used to modify the progress start position.
|
2015-03-19 10:00:30 +08:00
|
|
|
* If you're using radials type then the midpoint changes the center point.
|
2016-02-18 15:16:36 +08:00
|
|
|
* If you're using bar type then the midpoint changes the bar growth.
|
2013-07-20 04:16:38 +08:00
|
|
|
* it expands from the center but clamps to the sprites edge so:
|
2015-03-19 10:00:30 +08:00
|
|
|
* you want a left to right then set the midpoint all the way to Vec2(0,y).
|
|
|
|
* you want a right to left then set the midpoint all the way to Vec2(1,y).
|
|
|
|
* you want a bottom to top then set the midpoint all the way to Vec2(x,0).
|
|
|
|
* you want a top to bottom then set the midpoint all the way to Vec2(x,1).
|
|
|
|
* @param point A Vec2 point.
|
2013-07-20 04:16:38 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void setMidpoint(const Vec2& point);
|
2015-03-19 10:00:30 +08:00
|
|
|
|
2015-03-19 21:42:31 +08:00
|
|
|
/** Returns the Midpoint.
|
|
|
|
*
|
|
|
|
* @return A Vec2.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 getMidpoint() const;
|
2013-07-20 04:16:38 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-19 10:00:30 +08:00
|
|
|
* This allows the bar type to move the component at a specific rate.
|
2013-07-20 04:16:38 +08:00
|
|
|
* Set the component to 0 to make sure it stays at 100%.
|
2015-03-19 10:00:30 +08:00
|
|
|
* For example you want a left to right bar but not have the height stay 100%.
|
|
|
|
* Set the rate to be Vec2(0,1); and set the midpoint to = Vec2(0,.5f).
|
|
|
|
* @param barChangeRate A Vec2.
|
2013-07-20 04:16:38 +08:00
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setBarChangeRate(const Vec2& barChangeRate ) { _barChangeRate = barChangeRate; }
|
2015-03-19 10:00:30 +08:00
|
|
|
|
|
|
|
/** Returns the BarChangeRate.
|
|
|
|
*
|
|
|
|
* @return A barChangeRate.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
Vec2 getBarChangeRate() const { return _barChangeRate; }
|
2013-07-20 04:16:38 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
// Overrides
|
2014-05-31 07:42:05 +08:00
|
|
|
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
|
2014-05-15 01:07:09 +08:00
|
|
|
virtual void setAnchorPoint(const Vec2& anchorPoint) override;
|
2014-01-07 16:23:58 +08:00
|
|
|
virtual void setColor(const Color3B &color) override;
|
|
|
|
virtual const Color3B& getColor() const override;
|
|
|
|
virtual void setOpacity(GLubyte opacity) override;
|
2014-01-07 16:30:12 +08:00
|
|
|
virtual GLubyte getOpacity() const override;
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-15 08:33:43 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
|
|
|
ProgressTimer();
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual ~ProgressTimer();
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2013-11-15 08:33:43 +08:00
|
|
|
/** Initializes a progress timer with the sprite as the shape the timer goes through */
|
|
|
|
bool initWithSprite(Sprite* sp);
|
2014-03-21 13:44:29 +08:00
|
|
|
|
|
|
|
protected:
|
2014-05-31 07:42:05 +08:00
|
|
|
void onDraw(const Mat4 &transform, uint32_t flags);
|
2013-12-07 09:42:16 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Tex2F textureCoordFromAlphaPoint(Vec2 alpha);
|
|
|
|
Vec2 vertexFromAlphaPoint(Vec2 alpha);
|
2012-04-19 14:35:52 +08:00
|
|
|
void updateProgress(void);
|
|
|
|
void updateBar(void);
|
|
|
|
void updateRadial(void);
|
2013-12-11 16:12:14 +08:00
|
|
|
virtual void updateColor(void) override;
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 boundaryTexCoord(char index);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-25 15:11:36 +08:00
|
|
|
Type _type;
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 _midpoint;
|
|
|
|
Vec2 _barChangeRate;
|
2013-06-15 14:03:30 +08:00
|
|
|
float _percentage;
|
2013-06-20 14:13:12 +08:00
|
|
|
Sprite *_sprite;
|
2013-06-15 14:03:30 +08:00
|
|
|
int _vertexDataCount;
|
2013-07-05 16:49:22 +08:00
|
|
|
V2F_C4B_T2F *_vertexData;
|
2013-12-26 21:19:12 +08:00
|
|
|
|
|
|
|
CustomCommand _customCommand;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _reverseDirection;
|
2013-11-15 08:33:43 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(ProgressTimer);
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of misc_nodes group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif //__MISC_NODE_CCPROGRESS_TIMER_H__
|