2013-09-13 22:20:20 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
|
|
|
|
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 __UIWIDGET_H__
|
|
|
|
#define __UIWIDGET_H__
|
|
|
|
|
|
|
|
#include "cocos2d.h"
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "gui/UILayoutDefine.h"
|
2013-11-06 16:04:06 +08:00
|
|
|
#include "gui/UILayoutParameter.h"
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-11-06 16:04:06 +08:00
|
|
|
namespace gui {
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
BRIGHT_NONE = -1,
|
|
|
|
BRIGHT_NORMAL,
|
|
|
|
BRIGHT_HIGHLIGHT
|
|
|
|
}BrightStyle;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
WidgetTypeWidget, //control
|
|
|
|
WidgetTypeContainer //container
|
|
|
|
}WidgetType;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
UI_TEX_TYPE_LOCAL,
|
|
|
|
UI_TEX_TYPE_PLIST
|
|
|
|
}TextureResType;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
TOUCH_EVENT_BEGAN,
|
|
|
|
TOUCH_EVENT_MOVED,
|
|
|
|
TOUCH_EVENT_ENDED,
|
|
|
|
TOUCH_EVENT_CANCELED
|
|
|
|
}TouchEventType;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
SIZE_ABSOLUTE,
|
|
|
|
SIZE_PERCENT
|
|
|
|
}SizeType;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
POSITION_ABSOLUTE,
|
|
|
|
POSITION_PERCENT
|
|
|
|
}PositionType;
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
typedef void (cocos2d::Object::*SEL_TouchEvent)(cocos2d::Object*,TouchEventType);
|
|
|
|
#define toucheventselector(_SELECTOR) (SEL_TouchEvent)(&_SELECTOR)
|
2013-11-06 16:04:06 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
class UIWidget : public cocos2d::Object
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*/
|
|
|
|
UIWidget(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default destructor
|
|
|
|
*/
|
|
|
|
virtual ~UIWidget();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates and initializes a widget.
|
|
|
|
*/
|
|
|
|
static UIWidget* create();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the widget is enabled
|
|
|
|
*
|
|
|
|
* Highest control of widget.
|
|
|
|
* The default value is true, a widget is default to enabled
|
|
|
|
*
|
|
|
|
* @param enabled true if the widget is enabled, widget may be touched and visible, false if the widget is disabled, widget cannot be touched and hidden.
|
|
|
|
*/
|
|
|
|
virtual void setEnabled(bool enabled);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the widget is enabled
|
|
|
|
*
|
|
|
|
* @return true if the widget is enabled, false if the widget is disabled.
|
|
|
|
*/
|
|
|
|
bool isEnabled() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the widget is visible
|
|
|
|
*
|
|
|
|
* The default value is true, a widget is default to visible
|
|
|
|
*
|
|
|
|
* @param visible true if the widget is visible, false if the widget is hidden.
|
|
|
|
*/
|
|
|
|
void setVisible(bool visible);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the widget is visible
|
|
|
|
*
|
|
|
|
* @return true if the widget is visible, false if the widget is hidden.
|
|
|
|
*/
|
|
|
|
bool isVisible() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the widget is bright
|
|
|
|
*
|
|
|
|
* The default value is true, a widget is default to bright
|
|
|
|
*
|
|
|
|
* @param visible true if the widget is bright, false if the widget is dark.
|
|
|
|
*/
|
|
|
|
void setBright(bool bright);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the widget is bright
|
|
|
|
*
|
|
|
|
* @return true if the widget is bright, false if the widget is dark.
|
|
|
|
*/
|
|
|
|
bool isBright() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the widget is touch enabled
|
|
|
|
*
|
|
|
|
* The default value is false, a widget is default to touch disabled
|
|
|
|
*
|
|
|
|
* @param visible true if the widget is touch enabled, false if the widget is touch disabled.
|
|
|
|
*/
|
|
|
|
virtual void setTouchEnabled(bool enabled);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To set the bright style of widget.
|
|
|
|
*
|
|
|
|
* @see BrightStyle
|
|
|
|
*
|
|
|
|
* @param style BRIGHT_NORMAL the widget is normal state, BRIGHT_HIGHLIGHT the widget is height light state.
|
|
|
|
*/
|
|
|
|
void setBrightStyle(BrightStyle style);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the widget is touch enabled
|
|
|
|
*
|
|
|
|
* @return true if the widget is touch enabled, false if the widget is touch disabled.
|
|
|
|
*/
|
|
|
|
bool isTouchEnabled() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the widget is on focused
|
|
|
|
*
|
|
|
|
* @return true if the widget is on focused, false if the widget is not on focused.
|
|
|
|
*/
|
|
|
|
bool isFocused() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the widget is on focused
|
|
|
|
*
|
|
|
|
* The default value is false, a widget is default to not on focused
|
|
|
|
*
|
|
|
|
* @param fucosed true if the widget is on focused, false if the widget is not on focused.
|
|
|
|
*/
|
|
|
|
void setFocused(bool fucosed);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the Z order which stands for the drawing order, and reorder this widget in its parent's children array.
|
|
|
|
*
|
|
|
|
* The Z order of widget is relative to its "brothers": children of the same parent.
|
|
|
|
* It's nothing to do with OpenGL's z vertex. This one only affects the draw order of widgets in cocos2d.
|
|
|
|
* The larger number it is, the later this widget will be drawn in each message loop.
|
|
|
|
* Please refer to setVertexZ(float) for the difference.
|
|
|
|
*
|
|
|
|
* @param nZOrder Z order of this widget.
|
|
|
|
*/
|
|
|
|
void setZOrder(int z);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Z order of this widget.
|
|
|
|
*
|
|
|
|
* @see setZOrder(int)
|
|
|
|
*
|
|
|
|
* @return The Z order.
|
|
|
|
*/
|
|
|
|
int getZOrder();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the left boundary position of this widget.
|
|
|
|
*
|
|
|
|
* @return The left boundary position of this widget.
|
|
|
|
*/
|
|
|
|
float getLeftInParent();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the bottom boundary position of this widget.
|
|
|
|
*
|
|
|
|
* @return The bottom boundary position of this widget.
|
|
|
|
*/
|
|
|
|
float getBottomInParent();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the right boundary position of this widget.
|
|
|
|
*
|
|
|
|
* @return The right boundary position of this widget.
|
|
|
|
*/
|
|
|
|
float getRightInParent();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the top boundary position of this widget.
|
|
|
|
*
|
|
|
|
* @return The top boundary position of this widget.
|
|
|
|
*/
|
|
|
|
float getTopInParent();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a child to the container.
|
|
|
|
*
|
|
|
|
* @param child A child widget
|
|
|
|
*/
|
|
|
|
virtual bool addChild(UIWidget* child);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a child from the container with a cleanup
|
|
|
|
*
|
|
|
|
* @param child The child widget which will be removed.
|
|
|
|
*
|
|
|
|
* @return the result of removing, succeeded or failed.
|
|
|
|
*/
|
|
|
|
virtual bool removeChild(UIWidget* child);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes this widget itself from its parent widget.
|
|
|
|
* If the widget orphan, then it will destroy itself.
|
|
|
|
*/
|
|
|
|
virtual void removeFromParent();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all children from the container, and do a cleanup to all running actions depending on the cleanup parameter.
|
|
|
|
*/
|
|
|
|
virtual void removeAllChildren();
|
2013-11-06 16:04:06 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
/**
|
|
|
|
* Reorders a child according to a new z value.
|
|
|
|
*
|
|
|
|
* @param child An already added child node. It MUST be already added.
|
|
|
|
* @param zOrder Z order for drawing priority and touched priority. Please refer to setZOrder(int)
|
|
|
|
*/
|
|
|
|
virtual void reorderChild(UIWidget* child);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a child from the container with its name
|
|
|
|
*
|
|
|
|
* @param name An key to find the child widget.
|
|
|
|
*
|
|
|
|
* @return a UIWidget object whose name equals to the input parameter
|
|
|
|
*/
|
|
|
|
UIWidget* getChildByName(const char* name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a child from the container with its tag
|
|
|
|
*
|
|
|
|
* @param tag An identifier to find the child widget.
|
|
|
|
*
|
|
|
|
* @return a UIWidget object whose tag equals to the input parameter
|
|
|
|
*/
|
|
|
|
UIWidget* getChildByTag(int tag);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an array of children
|
|
|
|
*
|
|
|
|
* Composing a "tree" structure is a very important feature of UIWidget
|
|
|
|
*
|
|
|
|
* @return An array of children
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual cocos2d::Array* getChildren();
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the renderer of widget
|
|
|
|
*
|
2013-11-06 16:04:06 +08:00
|
|
|
* renderer is a Node, it's for drawing
|
2013-09-13 22:20:20 +08:00
|
|
|
*
|
2013-11-06 16:04:06 +08:00
|
|
|
* @return a Node object
|
2013-09-13 22:20:20 +08:00
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Node* getRenderer();
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
2013-11-06 16:04:06 +08:00
|
|
|
* Add a Node for rendering.
|
2013-09-13 22:20:20 +08:00
|
|
|
*
|
2013-11-06 16:04:06 +08:00
|
|
|
* renderer is a Node, it's for drawing
|
2013-09-13 22:20:20 +08:00
|
|
|
*
|
|
|
|
* @param renderer A render node
|
|
|
|
*
|
2013-11-06 16:04:06 +08:00
|
|
|
* @param zOrder Z order for drawing priority. Please refer to Node::setZOrder(int)
|
2013-09-13 22:20:20 +08:00
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
void addRenderer(cocos2d::Node* renderer, int zOrder);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
2013-11-06 16:04:06 +08:00
|
|
|
* Remove a Node from widget.
|
2013-09-13 22:20:20 +08:00
|
|
|
*
|
2013-11-06 16:04:06 +08:00
|
|
|
* renderer is a Node, it's for drawing
|
2013-09-13 22:20:20 +08:00
|
|
|
*
|
|
|
|
* @param renderer A render node which needs to be removed
|
|
|
|
*
|
|
|
|
* @param cleanup true if all running actions and callbacks on the render node will be cleanup, false otherwise.
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
void removeRenderer(cocos2d::Node* renderer, bool cleanup);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the parent widget
|
|
|
|
*
|
|
|
|
* @param parent A pointer to the parnet widget
|
|
|
|
*/
|
|
|
|
void setParent(UIWidget* parent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a pointer to the parent widget
|
|
|
|
*
|
|
|
|
* @see setParent(UIWidget*)
|
|
|
|
*
|
|
|
|
* @returns A pointer to the parnet widget
|
|
|
|
*/
|
|
|
|
UIWidget* getParent();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the touch event target/selector of the menu item
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
void addTouchEventListener(cocos2d::Object* target,SEL_TouchEvent selector);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
//cocos2d property
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the position (x,y) of the widget in OpenGL coordinates
|
|
|
|
*
|
2013-11-06 16:04:06 +08:00
|
|
|
* Usually we use p(x,y) to compose Point object.
|
2013-09-13 22:20:20 +08:00
|
|
|
* The original point (0,0) is at the left-bottom corner of screen.
|
|
|
|
*
|
|
|
|
* @param position The position (x,y) of the widget in OpenGL coordinates
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
void setPosition(const cocos2d::Point &pos);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the position (x,y) of the widget in OpenGL coordinates
|
|
|
|
*
|
2013-11-06 16:04:06 +08:00
|
|
|
* Usually we use p(x,y) to compose Point object.
|
2013-09-13 22:20:20 +08:00
|
|
|
* The original point (0,0) is at the left-bottom corner of screen.
|
|
|
|
*
|
|
|
|
* @param percent The percent (x,y) of the widget in OpenGL coordinates
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
void setPositionPercent(const cocos2d::Point &percent);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the position (x,y) of the widget in OpenGL coordinates
|
|
|
|
*
|
|
|
|
* @see setPosition(const Point&)
|
|
|
|
*
|
|
|
|
* @return The position (x,y) of the widget in OpenGL coordinates
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
const cocos2d::Point& getPosition();
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the percent (x,y) of the widget in OpenGL coordinates
|
|
|
|
*
|
|
|
|
* @see setPosition(const Point&)
|
|
|
|
*
|
|
|
|
* @return The percent (x,y) of the widget in OpenGL coordinates
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
const cocos2d::Point& getPositionPercent();
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the position type of the widget
|
|
|
|
*
|
|
|
|
* @see PositionType
|
|
|
|
*
|
|
|
|
* @param type the position type of widget
|
|
|
|
*/
|
|
|
|
void setPositionType(PositionType type);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the position type of the widget
|
|
|
|
*
|
|
|
|
* @see PositionType
|
|
|
|
*
|
|
|
|
* @return type the position type of widget
|
|
|
|
*/
|
|
|
|
PositionType getPositionType() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the anchor point in percent.
|
|
|
|
*
|
|
|
|
* anchorPoint is the point around which all transformations and positioning manipulations take place.
|
|
|
|
* It's like a pin in the widget where it is "attached" to its parent.
|
|
|
|
* The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
|
|
|
|
* But you can use values higher than (1,1) and lower than (0,0) too.
|
|
|
|
* The default anchorPoint is (0.5,0.5), so it starts in the center of the widget.
|
|
|
|
*
|
|
|
|
* @param anchorPoint The anchor point of widget.
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void setAnchorPoint(const cocos2d::Point &pt);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the anchor point in percent.
|
|
|
|
*
|
|
|
|
* @see setAnchorPoint(const Point&)
|
|
|
|
*
|
|
|
|
* @return The anchor point of widget.
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
const cocos2d::Point& getAnchorPoint();
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes both X and Y scale factor of the widget.
|
|
|
|
*
|
|
|
|
* 1.0 is the default scale factor. It modifies the X and Y scale at the same time.
|
|
|
|
*
|
|
|
|
* @param scale The scale factor for both X and Y axis.
|
|
|
|
*/
|
|
|
|
virtual void setScale(float fScale);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the scale factor of the widget, when X and Y have the same scale factor.
|
|
|
|
*
|
|
|
|
* @warning Assert when m_fScaleX != m_fScaleY.
|
|
|
|
* @see setScale(float)
|
|
|
|
*
|
|
|
|
* @return The scale factor of the widget.
|
|
|
|
*/
|
|
|
|
float getScale();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the scale factor on X axis of this widget
|
|
|
|
*
|
|
|
|
* The deafult value is 1.0 if you haven't changed it before
|
|
|
|
*
|
|
|
|
* @param fScaleX The scale factor on X axis.
|
|
|
|
*/
|
|
|
|
virtual void setScaleX(float fScaleX);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the scale factor on X axis of this widget
|
|
|
|
*
|
|
|
|
* @see setScaleX(float)
|
|
|
|
*
|
|
|
|
* @return The scale factor on X axis.
|
|
|
|
*/
|
|
|
|
float getScaleX();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the scale factor on Y axis of this widget
|
|
|
|
*
|
|
|
|
* The Default value is 1.0 if you haven't changed it before.
|
|
|
|
*
|
|
|
|
* @param fScaleY The scale factor on Y axis.
|
|
|
|
*/
|
|
|
|
virtual void setScaleY(float fScaleY);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the scale factor on Y axis of this widget
|
|
|
|
*
|
|
|
|
* @see setScaleY(float)
|
|
|
|
*
|
|
|
|
* @return The scale factor on Y axis.
|
|
|
|
*/
|
|
|
|
float getScaleY();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the rotation (angle) of the widget in degrees.
|
|
|
|
*
|
|
|
|
* 0 is the default rotation angle.
|
|
|
|
* Positive values rotate widget clockwise, and negative values for anti-clockwise.
|
|
|
|
*
|
|
|
|
* @param fRotation The roration of the widget in degrees.
|
|
|
|
*/
|
|
|
|
void setRotation(float rotation);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the rotation of the widget in degrees.
|
|
|
|
*
|
|
|
|
* @see setRotation(float)
|
|
|
|
*
|
|
|
|
* @return The rotation of the widget in degrees.
|
|
|
|
*/
|
|
|
|
float getRotation();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the X rotation (angle) of the widget in degrees which performs a horizontal rotational skew.
|
|
|
|
*
|
|
|
|
* 0 is the default rotation angle.
|
|
|
|
* Positive values rotate widget clockwise, and negative values for anti-clockwise.
|
|
|
|
*
|
|
|
|
* @param fRotationX The X rotation in degrees which performs a horizontal rotational skew.
|
|
|
|
*/
|
|
|
|
void setRotationX(float rotationX);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the X rotation (angle) of the widget in degrees which performs a horizontal rotation skew.
|
|
|
|
*
|
|
|
|
* @see setRotationX(float)
|
|
|
|
*
|
|
|
|
* @return The X rotation in degrees.
|
|
|
|
*/
|
|
|
|
float getRotationX();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the Y rotation (angle) of the widget in degrees which performs a vertical rotational skew.
|
|
|
|
*
|
|
|
|
* 0 is the default rotation angle.
|
|
|
|
* Positive values rotate widget clockwise, and negative values for anti-clockwise.
|
|
|
|
*
|
|
|
|
* @param fRotationY The Y rotation in degrees.
|
|
|
|
*/
|
|
|
|
void setRotationY(float rotationY);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Y rotation (angle) of the widget in degrees which performs a vertical rotational skew.
|
|
|
|
*
|
|
|
|
* @see setRotationY(float)
|
|
|
|
*
|
|
|
|
* @return The Y rotation in degrees.
|
|
|
|
*/
|
|
|
|
float getRotationY();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the widget should be flipped horizontally or not.
|
|
|
|
*
|
|
|
|
* @param bFlipX true if the widget should be flipped horizaontally, false otherwise.
|
|
|
|
*/
|
|
|
|
virtual void setFlipX(bool flipX){};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the flag which indicates whether the widget is flipped horizontally or not.
|
|
|
|
*
|
|
|
|
* It only flips the texture of the widget, and not the texture of the widget's children.
|
|
|
|
* Also, flipping the texture doesn't alter the anchorPoint.
|
|
|
|
* If you want to flip the anchorPoint too, and/or to flip the children too use:
|
|
|
|
* widget->setScaleX(sprite->getScaleX() * -1);
|
|
|
|
*
|
|
|
|
* @return true if the widget is flipped horizaontally, false otherwise.
|
|
|
|
*/
|
|
|
|
virtual bool isFlipX(){return false;};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the widget should be flipped vertically or not.
|
|
|
|
*
|
|
|
|
* @param bFlipY true if the widget should be flipped vertically, flase otherwise.
|
|
|
|
*/
|
|
|
|
virtual void setFlipY(bool flipY){};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the flag which indicates whether the widget is flipped vertically or not.
|
|
|
|
*
|
|
|
|
* It only flips the texture of the widget, and not the texture of the widget's children.
|
|
|
|
* Also, flipping the texture doesn't alter the anchorPoint.
|
|
|
|
* If you want to flip the anchorPoint too, and/or to flip the children too use:
|
|
|
|
* widget->setScaleY(widget->getScaleY() * -1);
|
|
|
|
*
|
|
|
|
* @return true if the widget is flipped vertically, flase otherwise.
|
|
|
|
*/
|
|
|
|
virtual bool isFlipY(){return false;};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets color to widget
|
|
|
|
*
|
|
|
|
* It default change the color of widget's children.
|
|
|
|
*
|
|
|
|
* @param color
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void setColor(const cocos2d::Color3B &color);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets color of widget
|
|
|
|
*
|
|
|
|
* @return color
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual const cocos2d::Color3B& getColor();
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets opacity to widget
|
|
|
|
*
|
|
|
|
* It default change the opacity of widget's children.
|
|
|
|
*
|
|
|
|
* @param color
|
|
|
|
*/
|
|
|
|
virtual void setOpacity(int opacity);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets opacity of widget
|
|
|
|
*
|
|
|
|
* @return opacity
|
|
|
|
*/
|
|
|
|
virtual int getOpacity();
|
|
|
|
virtual bool isCascadeOpacityEnabled();
|
|
|
|
virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled);
|
|
|
|
virtual bool isCascadeColorEnabled();
|
|
|
|
virtual void setCascadeColorEnabled(bool cascadeColorEnabled);
|
2013-10-15 18:00:03 +08:00
|
|
|
void setBlendFunc(cocos2d::BlendFunc blendFunc);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
//cocos action
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void setActionManager(cocos2d::ActionManager* actionManager);
|
|
|
|
virtual cocos2d::ActionManager* getActionManager();
|
|
|
|
cocos2d::Action* runAction(cocos2d::Action* action);
|
2013-09-13 22:20:20 +08:00
|
|
|
void stopAllActions(void);
|
2013-10-15 18:00:03 +08:00
|
|
|
void stopAction(cocos2d::Action* action);
|
2013-09-13 22:20:20 +08:00
|
|
|
void stopActionByTag(int tag);
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Action* getActionByTag(int tag);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A call back function when widget lost of focus.
|
|
|
|
*/
|
|
|
|
void didNotSelectSelf();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checks a point if in parent's area.
|
|
|
|
*
|
|
|
|
* @param point
|
|
|
|
*
|
|
|
|
* @return true if the point is in parent's area, flase otherwise.
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
bool clippingParentAreaContainPoint(const cocos2d::Point &pt);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sends the touch event to widget's parent
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void checkChildInfo(int handleState,UIWidget* sender,const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets the touch began point of widget when widget is selected.
|
|
|
|
*
|
|
|
|
* @return the touch began point.
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
const cocos2d::Point& getTouchStartPos();
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets the touch move point of widget when widget is selected.
|
|
|
|
*
|
|
|
|
* @return the touch move point.
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
const cocos2d::Point& getTouchMovePos();
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets the touch end point of widget when widget is selected.
|
|
|
|
*
|
|
|
|
* @return the touch end point.
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
const cocos2d::Point& getTouchEndPos();
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the tag that is used to identify the widget easily.
|
|
|
|
*
|
|
|
|
* @param A interger that indentifies the widget.
|
|
|
|
*/
|
|
|
|
void setTag(int tag);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a tag that is used to identify the widget easily.
|
|
|
|
*
|
|
|
|
* You can set tags to widget then identify them easily.
|
|
|
|
*
|
|
|
|
* @return A interger that identifies the widget.
|
|
|
|
*/
|
|
|
|
int getTag() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the name that is used to identify the widget easily.
|
|
|
|
*
|
|
|
|
* @param A const char* that indentifies the widget.
|
|
|
|
*/
|
|
|
|
void setName(const char* name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a name that is used to identify the widget easily.
|
|
|
|
*
|
|
|
|
* You can set tags to widget then identify them easily.
|
|
|
|
*
|
|
|
|
* @return A const char* that identifies the widget.
|
|
|
|
*/
|
|
|
|
const char* getName() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a type that is widget's type
|
|
|
|
*
|
|
|
|
* @see WidgetType
|
|
|
|
*
|
|
|
|
* @return A WidgetType
|
|
|
|
*/
|
|
|
|
WidgetType getWidgetType() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the size that is widget's size
|
|
|
|
*
|
|
|
|
* @param size that is widget's size
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void setSize(const cocos2d::Size &size);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the percent that is widget's percent size
|
|
|
|
*
|
|
|
|
* @param percent that is widget's percent size
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void setSizePercent(const cocos2d::Point &percent);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the size type of widget.
|
|
|
|
*
|
|
|
|
* @see SizeType
|
|
|
|
*
|
|
|
|
* @param type that is widget's size type
|
|
|
|
*/
|
|
|
|
void setSizeType(SizeType type);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the size type of widget.
|
|
|
|
*
|
|
|
|
* @see SizeType
|
|
|
|
*
|
|
|
|
* @param type that is widget's size type
|
|
|
|
*/
|
|
|
|
SizeType getSizeType() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns size of widget
|
|
|
|
*
|
|
|
|
* @return size
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
const cocos2d::Size& getSize() const;
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns size percent of widget
|
|
|
|
*
|
|
|
|
* @return size percent
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
const cocos2d::Point& getSizePercent() const;
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks a point if is in widget's space
|
|
|
|
*
|
|
|
|
* @param point
|
|
|
|
*
|
|
|
|
* @return true if the point is in widget's space, flase otherwise.
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual bool hitTest(const cocos2d::Point &pt);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A call back function called when widget is selected, and on touch began.
|
|
|
|
*
|
|
|
|
* @param touch point
|
|
|
|
*
|
|
|
|
* @return true if the event should be pass to parent, flase otherwise.
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual bool onTouchBegan(const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A call back function called when widget is selected, and on touch moved.
|
|
|
|
*
|
|
|
|
* @param touch point
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void onTouchMoved(const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A call back function called when widget is selected, and on touch ended.
|
|
|
|
*
|
|
|
|
* @param touch point
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void onTouchEnded(const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A call back function called when widget is selected, and on touch canceled.
|
|
|
|
*
|
|
|
|
* @param touch point
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void onTouchCancelled(const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A call back function called when widget is selected, and on touch long clicked.
|
|
|
|
*
|
|
|
|
* @param touch point
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void onTouchLongClicked(const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a LayoutParameter to widget.
|
|
|
|
*
|
|
|
|
* @see LayoutParameter
|
|
|
|
*
|
|
|
|
* @param LayoutParameter pointer
|
2013-11-06 16:04:06 +08:00
|
|
|
*
|
|
|
|
* @param type Relative or Linear
|
2013-09-13 22:20:20 +08:00
|
|
|
*/
|
2013-11-06 16:04:06 +08:00
|
|
|
void setLayoutParameter(UILayoutParameter* parameter);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets LayoutParameter of widget.
|
|
|
|
*
|
|
|
|
* @see LayoutParameter
|
2013-11-06 16:04:06 +08:00
|
|
|
*
|
|
|
|
* @param type Relative or Linear
|
|
|
|
*
|
|
|
|
* @return LayoutParameter
|
2013-09-13 22:20:20 +08:00
|
|
|
*/
|
2013-11-06 16:04:06 +08:00
|
|
|
UILayoutParameter* getLayoutParameter(LayoutParameterType type);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ignore the widget size
|
|
|
|
*
|
|
|
|
* @param ignore, true that widget will ignore it's size, use texture size, false otherwise. Default value is true.
|
|
|
|
*/
|
|
|
|
virtual void ignoreContentAdaptWithSize(bool ignore);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the widget if is ignore it's size.
|
|
|
|
*
|
|
|
|
* @param ignore, true that widget will ignore it's size, use texture size, false otherwise. Default value is true.
|
|
|
|
*/
|
|
|
|
bool isIgnoreContentAdaptWithSize() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets world position of widget.
|
|
|
|
*
|
|
|
|
* @return world position of widget.
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Point getWorldPosition();
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a Point to world space coordinates. The result is in Points.
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Point convertToWorldSpace(const cocos2d::Point& pt);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Virtual Renderer of widget.
|
|
|
|
*
|
|
|
|
* For example, a button's Virtual Renderer is it's texture renderer.
|
|
|
|
*
|
2013-11-06 16:04:06 +08:00
|
|
|
* @return Node pointer.
|
2013-09-13 22:20:20 +08:00
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual cocos2d::Node* getVirtualRenderer();
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Schedules the "update" method.
|
|
|
|
*/
|
|
|
|
void setUpdateEnabled(bool enable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* is the "update" method scheduled.
|
|
|
|
*/
|
|
|
|
bool isUpdateEnabled();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the content size of widget.
|
|
|
|
*
|
|
|
|
* Content size is widget's texture size.
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual const cocos2d::Size& getContentSize() const;
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-09-17 17:59:20 +08:00
|
|
|
/**
|
|
|
|
* Returns the "class name" of widget.
|
|
|
|
*/
|
|
|
|
virtual const char* getDescription() const;
|
|
|
|
|
2013-11-06 16:04:06 +08:00
|
|
|
UIWidget* clone();
|
|
|
|
|
|
|
|
virtual void onEnter();
|
|
|
|
virtual void onExit();
|
2013-11-08 14:58:20 +08:00
|
|
|
|
|
|
|
virtual Object* getUserObject() { return _userObject; }
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual const Object* getUserObject() const { return _userObject; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a user assigned Object
|
|
|
|
*
|
|
|
|
* Similar to UserData, but instead of holding a void* it holds an object.
|
|
|
|
* The UserObject will be retained once in this method,
|
|
|
|
* and the previous UserObject (if existed) will be relese.
|
|
|
|
* The UserObject will be released in Node's destructure.
|
|
|
|
*
|
|
|
|
* @param userObject A user assigned Object
|
|
|
|
*/
|
|
|
|
virtual void setUserObject(Object *userObject);
|
2013-09-13 22:20:20 +08:00
|
|
|
/*temp action*/
|
|
|
|
void setActionTag(int tag);
|
|
|
|
int getActionTag();
|
|
|
|
protected:
|
|
|
|
//call back function called when size changed.
|
|
|
|
virtual void onSizeChanged();
|
|
|
|
|
|
|
|
//initializes state of widget.
|
|
|
|
virtual bool init();
|
|
|
|
|
|
|
|
//initializes renderer of widget.
|
|
|
|
virtual void initRenderer();
|
|
|
|
|
|
|
|
//call back function called widget's state changed to normal.
|
|
|
|
virtual void onPressStateChangedToNormal();
|
|
|
|
|
|
|
|
//call back function called widget's state changed to selected.
|
|
|
|
virtual void onPressStateChangedToPressed();
|
|
|
|
|
|
|
|
//call back function called widget's state changed to dark.
|
|
|
|
virtual void onPressStateChangedToDisabled();
|
|
|
|
void pushDownEvent();
|
|
|
|
void moveEvent();
|
|
|
|
void releaseUpEvent();
|
|
|
|
void cancelUpEvent();
|
|
|
|
void longClickEvent();
|
|
|
|
void updateAnchorPoint();
|
|
|
|
void updateSizeAndPosition();
|
2013-11-06 16:04:06 +08:00
|
|
|
void copyProperties(UIWidget* model);
|
|
|
|
virtual UIWidget* createCloneInstance();
|
|
|
|
virtual void copySpecialProperties(UIWidget* model);
|
|
|
|
virtual void copyClonedWidgetChildren(UIWidget* model);
|
2013-09-13 22:20:20 +08:00
|
|
|
protected:
|
2013-09-16 15:32:52 +08:00
|
|
|
bool _enabled; ///< Highest control of widget
|
|
|
|
bool _visible; ///< is this widget visible
|
|
|
|
bool _bright; ///< is this widget bright
|
|
|
|
bool _touchEnabled; ///< is this widget touch endabled
|
|
|
|
bool _touchPassedEnabled; ///< is the touch event should be passed
|
|
|
|
bool _focus; ///< is the widget on focus
|
|
|
|
int _widgetZOrder; ///< z-order value that affects the draw order and touch order
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Point _anchorPoint; ///< anchor point normalized
|
2013-09-16 15:32:52 +08:00
|
|
|
UIWidget* _widgetParent; ///< parent of widget
|
|
|
|
BrightStyle _brightStyle; ///< bright style
|
|
|
|
bool _updateEnabled; ///< is "update" method scheduled
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Node* _renderer; ///< base renderer
|
|
|
|
cocos2d::Point _touchStartPos; ///< touch began point
|
|
|
|
cocos2d::Point _touchMovePos; ///< touch moved point
|
|
|
|
cocos2d::Point _touchEndPos; ///< touch ended point
|
2013-09-16 15:32:52 +08:00
|
|
|
|
2013-11-06 16:04:06 +08:00
|
|
|
Object* _touchEventListener;
|
2013-09-16 15:32:52 +08:00
|
|
|
SEL_TouchEvent _touchEventSelector;
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-16 15:32:52 +08:00
|
|
|
int _widgetTag;
|
|
|
|
std::string _name;
|
|
|
|
WidgetType _widgetType;
|
|
|
|
int _actionTag;
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Size _size;
|
|
|
|
cocos2d::Size _customSize;
|
2013-11-06 16:04:06 +08:00
|
|
|
cocos2d::Dictionary* _layoutParameterDictionary;
|
2013-09-16 15:32:52 +08:00
|
|
|
bool _ignoreSize;
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Array* _children;
|
2013-09-16 15:32:52 +08:00
|
|
|
bool _affectByClipping;
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Scheduler* _scheduler;
|
2013-09-16 15:32:52 +08:00
|
|
|
|
|
|
|
SizeType _sizeType;
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Point _sizePercent;
|
2013-09-16 15:32:52 +08:00
|
|
|
PositionType _positionType;
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Point _positionPercent;
|
2013-09-16 15:32:52 +08:00
|
|
|
bool _isRunning;
|
2013-11-08 14:58:20 +08:00
|
|
|
cocos2d::Object* _userObject;
|
2013-09-13 22:20:20 +08:00
|
|
|
};
|
2013-11-06 16:04:06 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
class GUIRenderer : public cocos2d::NodeRGBA
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
GUIRenderer();
|
|
|
|
virtual ~GUIRenderer();
|
|
|
|
virtual void visit(void);
|
|
|
|
static GUIRenderer* create();
|
|
|
|
void setEnabled(bool enabled);
|
|
|
|
bool isEnabled() const;
|
|
|
|
protected:
|
2013-09-16 15:32:52 +08:00
|
|
|
bool _enabled;
|
2013-09-13 22:20:20 +08:00
|
|
|
};
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|
2013-09-13 22:20:20 +08:00
|
|
|
#endif /* defined(__UIWidget__) */
|