2014-03-11 17:13:54 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __UIWIDGET_H__
|
|
|
|
#define __UIWIDGET_H__
|
|
|
|
|
2014-07-31 16:38:55 +08:00
|
|
|
#include "2d/CCProtectedNode.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
#include "ui/UILayoutParameter.h"
|
|
|
|
#include "ui/GUIDefine.h"
|
2014-07-21 17:45:56 +08:00
|
|
|
#include "ui/GUIExport.h"
|
2014-06-04 14:26:21 +08:00
|
|
|
#include "base/CCMap.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
2015-03-26 15:47:14 +08:00
|
|
|
NS_CC_BEGIN
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2014-06-04 14:26:21 +08:00
|
|
|
class EventListenerTouchOneByOne;
|
2015-06-18 10:23:52 +08:00
|
|
|
class Camera;
|
2014-06-04 14:26:21 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
namespace ui {
|
2014-10-09 18:28:09 +08:00
|
|
|
class LayoutComponent;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Touch event type.
|
|
|
|
*@deprecated use `Widget::TouchEventType` instead
|
|
|
|
*/
|
2014-07-10 00:45:27 +08:00
|
|
|
typedef enum
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
TOUCH_EVENT_BEGAN,
|
|
|
|
TOUCH_EVENT_MOVED,
|
|
|
|
TOUCH_EVENT_ENDED,
|
|
|
|
TOUCH_EVENT_CANCELED
|
|
|
|
}TouchEventType;
|
2014-05-04 11:23:20 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Touch event callback.
|
|
|
|
*@deprecated use `Widget::ccWidgetTouchCallback` instead
|
|
|
|
*/
|
2014-07-10 00:45:27 +08:00
|
|
|
typedef void (Ref::*SEL_TouchEvent)(Ref*,TouchEventType);
|
2014-03-11 17:13:54 +08:00
|
|
|
#define toucheventselector(_SELECTOR) (SEL_TouchEvent)(&_SELECTOR)
|
2014-05-09 11:28:36 +08:00
|
|
|
|
|
|
|
|
2015-05-09 00:19:13 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
2014-05-13 00:26:39 +08:00
|
|
|
#ifdef ABSOLUTE
|
|
|
|
#undef ABSOLUTE
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
*@brief Base class for all ui widgets.
|
2015-03-26 15:47:14 +08:00
|
|
|
* This class inherent from `ProtectedNode` and `LayoutParameterProtocol`.
|
2015-03-25 18:17:58 +08:00
|
|
|
* If you want to implements your own ui widget, you should subclass it.
|
|
|
|
*/
|
2014-07-21 17:45:56 +08:00
|
|
|
class CC_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Widget focus direction.
|
|
|
|
*/
|
2014-05-08 18:10:21 +08:00
|
|
|
enum class FocusDirection
|
|
|
|
{
|
|
|
|
LEFT,
|
|
|
|
RIGHT,
|
|
|
|
UP,
|
|
|
|
DOWN
|
|
|
|
};
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Widget position type for layout.
|
|
|
|
*/
|
2014-05-08 18:25:49 +08:00
|
|
|
enum class PositionType
|
|
|
|
{
|
|
|
|
ABSOLUTE,
|
|
|
|
PERCENT
|
|
|
|
};
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Widget size type for layout.
|
|
|
|
*/
|
2014-05-09 09:37:51 +08:00
|
|
|
enum class SizeType
|
|
|
|
{
|
|
|
|
ABSOLUTE,
|
|
|
|
PERCENT
|
|
|
|
};
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Touch event type.
|
|
|
|
*/
|
2014-05-09 11:28:36 +08:00
|
|
|
enum class TouchEventType
|
|
|
|
{
|
|
|
|
BEGAN,
|
|
|
|
MOVED,
|
|
|
|
ENDED,
|
|
|
|
CANCELED
|
|
|
|
};
|
2014-05-09 14:56:05 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Texture resource type.
|
|
|
|
* - LOCAL: It means the texture is loaded from image.
|
|
|
|
* - PLIST: It means the texture is loaded from texture atlas.
|
|
|
|
*/
|
2014-05-09 14:56:05 +08:00
|
|
|
enum class TextureResType
|
|
|
|
{
|
|
|
|
LOCAL = 0,
|
|
|
|
PLIST = 1
|
|
|
|
};
|
2014-05-09 15:16:33 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Widget bright style.
|
|
|
|
*/
|
2014-05-09 15:23:34 +08:00
|
|
|
enum class BrightStyle
|
|
|
|
{
|
|
|
|
NONE = -1,
|
|
|
|
NORMAL,
|
|
|
|
HIGHLIGHT
|
|
|
|
};
|
2014-05-09 11:28:36 +08:00
|
|
|
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Widget touch event callback.
|
|
|
|
*/
|
2014-05-09 11:28:36 +08:00
|
|
|
typedef std::function<void(Ref*,Widget::TouchEventType)> ccWidgetTouchCallback;
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Widget click event callback.
|
|
|
|
*/
|
2014-08-21 10:21:07 +08:00
|
|
|
typedef std::function<void(Ref*)> ccWidgetClickCallback;
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Widget custom event callback.
|
|
|
|
* It is mainly used together with Cocos Studio.
|
|
|
|
*/
|
2014-11-27 16:49:19 +08:00
|
|
|
typedef std::function<void(Ref*, int)> ccWidgetEventCallback;
|
2014-06-09 10:41:17 +08:00
|
|
|
/**
|
|
|
|
* Default constructor
|
2015-03-30 21:38:32 +08:00
|
|
|
* @js ctor
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua new
|
2014-06-09 10:41:17 +08:00
|
|
|
*/
|
|
|
|
Widget(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default destructor
|
2015-03-30 21:38:32 +08:00
|
|
|
* @js NA
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2014-06-09 10:41:17 +08:00
|
|
|
*/
|
|
|
|
virtual ~Widget();
|
2014-03-11 17:13:54 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Create and return a empty Widget instance pointer.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
static Widget* create();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the widget is enabled
|
2014-05-13 14:56:44 +08:00
|
|
|
*
|
|
|
|
* true if the widget is enabled, widget may be touched , false if the widget is disabled, widget cannot be touched.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-26 15:47:14 +08:00
|
|
|
* Note: If you want to change the widget's appearance to disabled state, you should also call `setBright(false)`.
|
2015-03-25 18:17:58 +08:00
|
|
|
*
|
|
|
|
* The default value is true, a widget is default to enable touch.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param enabled Set to true to enable touch, false otherwise.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
virtual void setEnabled(bool enabled);
|
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Determines if the widget is enabled or not.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
|
|
|
* @return true if the widget is enabled, false if the widget is disabled.
|
|
|
|
*/
|
|
|
|
bool isEnabled() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the widget is bright
|
|
|
|
*
|
|
|
|
* The default value is true, a widget is default to bright
|
|
|
|
*
|
2015-03-27 17:09:54 +08:00
|
|
|
* @param bright true if the widget is bright, false if the widget is dark.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
2015-03-27 18:26:14 +08:00
|
|
|
* Sets whether the widget is touch enabled.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-27 18:26:14 +08:00
|
|
|
* The default value is false, a widget is default to touch disabled.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-27 18:26:14 +08:00
|
|
|
* @param enabled True if the widget is touch enabled, false if the widget is touch disabled.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
virtual void setTouchEnabled(bool enabled);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To set the bright style of widget.
|
|
|
|
*
|
|
|
|
* @see BrightStyle
|
|
|
|
*
|
2014-07-16 10:08:23 +08:00
|
|
|
* @param style BrightStyle::NORMAL means the widget is in normal state, BrightStyle::HIGHLIGHT means the widget is in highlight state.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
2014-05-04 10:19:11 +08:00
|
|
|
* Determines if the widget is highlighted
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2014-05-04 10:19:11 +08:00
|
|
|
* @return true if the widget is highlighted, false if the widget is not hignlighted .
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-05-06 12:04:52 +08:00
|
|
|
bool isHighlighted() const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2014-05-04 10:19:11 +08:00
|
|
|
* Sets whether the widget is hilighted
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2014-05-04 10:19:11 +08:00
|
|
|
* The default value is false, a widget is default to not hilighted
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2014-05-04 10:19:11 +08:00
|
|
|
* @param hilight true if the widget is hilighted, false if the widget is not hilighted.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-05-06 12:04:52 +08:00
|
|
|
void setHighlighted(bool hilight);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2014-07-16 10:08:23 +08:00
|
|
|
* Gets the left boundary position of this widget in parent's coordination system.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @deprecated use `getLeftBoundary` instead.
|
2014-03-11 17:13:54 +08:00
|
|
|
* @return The left boundary position of this widget.
|
|
|
|
*/
|
2014-05-19 16:51:25 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE float getLeftInParent(){return this->getLeftBoundary();}
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the left boundary position of this widget in parent's coordination system.
|
|
|
|
* @return The left boundary position of this widget.
|
|
|
|
*/
|
2014-05-19 16:51:25 +08:00
|
|
|
float getLeftBoundary() const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2014-07-16 10:08:23 +08:00
|
|
|
* Gets the bottom boundary position of this widget in parent's coordination system.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @deprecated use `getBottomBoundary` instead.
|
2014-03-11 17:13:54 +08:00
|
|
|
* @return The bottom boundary position of this widget.
|
|
|
|
*/
|
2014-05-19 16:51:25 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE float getBottomInParent(){return this->getBottomBoundary();}
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Gets the bottom boundary position of this widget in parent's coordination system.
|
|
|
|
* @return The bottom boundary position of this widget.
|
|
|
|
*/
|
2014-05-19 16:51:25 +08:00
|
|
|
float getBottomBoundary() const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2014-07-16 10:08:23 +08:00
|
|
|
* Gets the right boundary position of this widget in parent's coordination system.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @deprecated use `getRightBoundary` instead.
|
2014-03-11 17:13:54 +08:00
|
|
|
* @return The right boundary position of this widget.
|
|
|
|
*/
|
2014-05-19 16:51:25 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE float getRightInParent(){return this->getRightBoundary();}
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Gets the right boundary position of this widget in parent's coordination system.
|
|
|
|
* @return The right boundary position of this widget.
|
|
|
|
*/
|
2014-05-19 16:51:25 +08:00
|
|
|
float getRightBoundary() const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2014-07-16 10:08:23 +08:00
|
|
|
* Gets the top boundary position of this widget in parent's coordination system.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @deprecated use `getTopBoundary` instead.
|
2014-03-11 17:13:54 +08:00
|
|
|
* @return The top boundary position of this widget.
|
|
|
|
*/
|
2014-05-19 16:51:25 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE float getTopInParent(){return this->getTopBoundary();}
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Gets the top boundary position of this widget in parent's coordination system.
|
|
|
|
* @return The top boundary position of this widget.
|
|
|
|
*/
|
2014-05-19 16:51:25 +08:00
|
|
|
float getTopBoundary() const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-30 21:38:32 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
*/
|
2014-05-31 07:42:05 +08:00
|
|
|
virtual void visit(cocos2d::Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2014-08-21 10:21:07 +08:00
|
|
|
* Sets the touch event target/selector to the widget
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-05-09 11:28:36 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void addTouchEventListener(Ref* target,SEL_TouchEvent selector);
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Set a callback to touch vent listener.
|
|
|
|
*@param callback The callback in `ccWidgetEventCallback.`
|
|
|
|
*/
|
2014-08-21 10:21:07 +08:00
|
|
|
void addTouchEventListener(const ccWidgetTouchCallback& callback);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-08-21 10:21:07 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Set a click event handler to the widget.
|
|
|
|
* @param callback The callback in `ccWidgetClickCallback`.
|
2014-08-21 10:21:07 +08:00
|
|
|
*/
|
|
|
|
void addClickEventListener(const ccWidgetClickCallback& callback);
|
2014-11-27 16:49:19 +08:00
|
|
|
/**
|
|
|
|
* Set a event handler to the widget in order to use cocostudio editor and framework
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param callback The callback in `ccWidgetEventCallback`.
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2014-11-27 16:49:19 +08:00
|
|
|
*/
|
|
|
|
virtual void addCCSEventListener(const ccWidgetEventCallback& callback);
|
|
|
|
/**/
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the position (x,y) of the widget in OpenGL coordinates
|
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* Usually we use p(x,y) to compose a Vec2 object.
|
2014-03-11 17:13:54 +08:00
|
|
|
* The original point (0,0) is at the left-bottom corner of screen.
|
|
|
|
*
|
2015-03-27 17:09:54 +08:00
|
|
|
* @param pos The position (x,y) of the widget in OpenGL coordinates
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
virtual void setPosition(const Vec2 &pos) override;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2014-07-15 15:56:07 +08:00
|
|
|
* Set the percent(x,y) of the widget in OpenGL coordinates
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
|
|
|
* @param percent The percent (x,y) of the widget in OpenGL coordinates
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void setPositionPercent(const Vec2 &percent);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the percent (x,y) of the widget in OpenGL coordinates
|
|
|
|
*
|
2014-05-15 01:07:09 +08:00
|
|
|
* @see setPosition(const Vec2&)
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
|
|
|
* @return The percent (x,y) of the widget in OpenGL coordinates
|
|
|
|
*/
|
2014-12-24 11:12:14 +08:00
|
|
|
const Vec2& getPositionPercent();
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the position type of the widget
|
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @see `PositionType`
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
|
|
|
* @param type the position type of widget
|
|
|
|
*/
|
|
|
|
void setPositionType(PositionType type);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the position type of the widget
|
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @see `PositionType`
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
|
|
|
* @return type the position type of widget
|
|
|
|
*/
|
|
|
|
PositionType getPositionType() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the widget should be flipped horizontally or not.
|
|
|
|
*
|
2015-03-27 17:09:54 +08:00
|
|
|
* @param flippedX true if the widget should be flipped horizaontally, false otherwise.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
virtual void setFlippedX(bool flippedX);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the flag which indicates whether the widget is flipped horizontally or not.
|
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* It not only flips the texture of the widget, but also the texture of the widget's children.
|
|
|
|
* Also, flipping relies on widget's anchor point.
|
|
|
|
* Internally, it just use setScaleX(-1) to flip the widget.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
|
|
|
* @return true if the widget is flipped horizaontally, false otherwise.
|
|
|
|
*/
|
2014-05-27 10:19:05 +08:00
|
|
|
virtual bool isFlippedX()const{return _flippedX;};
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the widget should be flipped vertically or not.
|
|
|
|
*
|
2015-03-27 17:09:54 +08:00
|
|
|
* @param flippedY true if the widget should be flipped vertically, flase otherwise.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
virtual void setFlippedY(bool flippedY);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the flag which indicates whether the widget is flipped vertically or not.
|
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* It not only flips the texture of the widget, but also the texture of the widget's children.
|
|
|
|
* Also, flipping relies on widget's anchor point.
|
|
|
|
* Internally, it just use setScaleY(-1) to flip the widget.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
|
|
|
* @return true if the widget is flipped vertically, flase otherwise.
|
|
|
|
*/
|
2014-05-27 10:19:05 +08:00
|
|
|
virtual bool isFlippedY()const{return _flippedY;};
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/** @deprecated Use isFlippedX() instead */
|
|
|
|
CC_DEPRECATED_ATTRIBUTE bool isFlipX() { return isFlippedX(); };
|
|
|
|
/** @deprecated Use setFlippedX() instead */
|
|
|
|
CC_DEPRECATED_ATTRIBUTE void setFlipX(bool flipX) { setFlippedX(flipX); };
|
|
|
|
/** @deprecated Use isFlippedY() instead */
|
|
|
|
CC_DEPRECATED_ATTRIBUTE bool isFlipY() { return isFlippedY(); };
|
|
|
|
/** @deprecated Use setFlippedY() instead */
|
|
|
|
CC_DEPRECATED_ATTRIBUTE void setFlipY(bool flipY) { setFlippedY(flipY); };
|
|
|
|
|
2014-11-05 20:22:35 +08:00
|
|
|
//override the setScale function of Node
|
|
|
|
virtual void setScaleX(float scaleX) override;
|
|
|
|
virtual void setScaleY(float scaleY) override;
|
|
|
|
virtual void setScale(float scale) override;
|
|
|
|
virtual void setScale(float scalex, float scaley) override;
|
|
|
|
using Node::setScaleZ;
|
|
|
|
virtual float getScaleX() const override;
|
|
|
|
virtual float getScaleY() const override;
|
|
|
|
virtual float getScale() const override;
|
|
|
|
using Node::getScaleZ;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
2014-03-11 17:13:54 +08:00
|
|
|
* Checks a point if in parent's area.
|
|
|
|
*
|
2015-03-27 17:09:54 +08:00
|
|
|
* @param pt A point in `Vec2`.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @deprecated use `isClippingParentContainsPoint` instead.
|
2014-03-11 17:13:54 +08:00
|
|
|
* @return true if the point is in parent's area, flase otherwise.
|
|
|
|
*/
|
2014-06-06 16:48:49 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE bool clippingParentAreaContainPoint(const Vec2 &pt){return this->isClippingParentContainsPoint(pt);}
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks a point if in parent's area.
|
|
|
|
*
|
2015-03-27 17:09:54 +08:00
|
|
|
* @param pt A point in `Vec2`.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @return true if the point is in parent's area, flase otherwise.
|
|
|
|
*/
|
2014-06-06 16:48:49 +08:00
|
|
|
bool isClippingParentContainsPoint(const Vec2& pt);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
2014-03-11 17:13:54 +08:00
|
|
|
* Gets the touch began point of widget when widget is selected.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @deprecated use `getTouchBeganPosition` instead.
|
2014-03-11 17:13:54 +08:00
|
|
|
* @return the touch began point.
|
|
|
|
*/
|
2014-06-06 16:48:49 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE const Vec2& getTouchStartPos()const{return this->getTouchBeganPosition();}
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Gets the touch began point of widget when widget is selected.
|
|
|
|
* @return the touch began point.
|
|
|
|
*/
|
2014-06-06 16:48:49 +08:00
|
|
|
const Vec2& getTouchBeganPosition()const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets the touch move point of widget when widget is selected.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @deprecated use `getTouchMovePosition` instead.
|
2014-03-11 17:13:54 +08:00
|
|
|
* @return the touch move point.
|
|
|
|
*/
|
2014-06-06 16:48:49 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE const Vec2& getTouchMovePos()const{ return this->getTouchMovePosition();}
|
2015-03-25 18:17:58 +08:00
|
|
|
/*
|
|
|
|
* Gets the touch move point of widget when widget is selected.
|
|
|
|
* @return the touch move point.
|
|
|
|
*/
|
2014-06-06 16:48:49 +08:00
|
|
|
const Vec2& getTouchMovePosition()const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets the touch end point of widget when widget is selected.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @deprecated use `getTouchEndPosition` instead.
|
2014-03-11 17:13:54 +08:00
|
|
|
* @return the touch end point.
|
|
|
|
*/
|
2014-06-06 16:48:49 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE const Vec2& getTouchEndPos()const{return this->getTouchEndPosition();}
|
2015-03-25 18:17:58 +08:00
|
|
|
/*
|
|
|
|
* Gets the touch end point of widget when widget is selected.
|
|
|
|
* @return the touch end point.
|
|
|
|
*/
|
2014-06-06 16:48:49 +08:00
|
|
|
const Vec2& getTouchEndPosition()const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the size that is widget's size
|
2015-03-25 18:17:58 +08:00
|
|
|
* @deprecated use `setContentSize` instead.
|
2014-03-11 17:13:54 +08:00
|
|
|
* @param size that is widget's size
|
|
|
|
*/
|
2014-06-20 11:18:53 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void setSize(const Size &size);
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Changes the size that is widget's size
|
|
|
|
* @param contentSize A content size in `Size`.
|
|
|
|
*/
|
2014-06-20 11:18:53 +08:00
|
|
|
virtual void setContentSize(const Size& contentSize) override;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the percent that is widget's percent size
|
|
|
|
*
|
|
|
|
* @param percent that is widget's percent size
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
virtual void setSizePercent(const Vec2 &percent);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the size type of widget.
|
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @see `SizeType`
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
|
|
|
* @param type that is widget's size type
|
|
|
|
*/
|
|
|
|
void setSizeType(SizeType type);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the size type of widget.
|
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @see `SizeType`
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
SizeType getSizeType() const;
|
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Get the size of widget
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @return Widget content size.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-06-20 11:18:53 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE const Size& getSize() const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Get the user defined widget size.
|
|
|
|
*@return User defined size.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
const Size& getCustomSize() const;
|
2014-03-13 10:11:41 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Get the content size of widget.
|
|
|
|
* @warning This API exists mainly for keeping back compatibility.
|
|
|
|
* @return
|
|
|
|
*/
|
2014-06-20 10:40:16 +08:00
|
|
|
virtual const Size& getLayoutSize() {return _contentSize;};
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Get size percent of widget.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @return Percent size.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-10-09 18:28:09 +08:00
|
|
|
const Vec2& getSizePercent();
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Checks a point is in widget's content space.
|
|
|
|
* This function is used for determining touch area of widget.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-06-18 10:23:52 +08:00
|
|
|
* @param pt The point in `Vec2`.
|
|
|
|
* @param camera The camera look at widget, used to convert GL screen point to near/far plane.
|
|
|
|
* @param p Point to a Vec3 for store the intersect point, if don't need them set to nullptr.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @return true if the point is in widget's content space, flase otherwise.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2015-06-18 10:23:52 +08:00
|
|
|
virtual bool hitTest(const Vec2 &pt, const Camera* camera, Vec3 *p) const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* A callback which will be called when touch began event is issued.
|
|
|
|
*@param touch The touch info.
|
|
|
|
*@param unusedEvent The touch event info.
|
|
|
|
*@return True if user want to handle touches, false otherwise.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual bool onTouchBegan(Touch *touch, Event *unusedEvent);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A callback which will be called when touch moved event is issued.
|
|
|
|
*@param touch The touch info.
|
|
|
|
*@param unusedEvent The touch event info.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual void onTouchMoved(Touch *touch, Event *unusedEvent);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A callback which will be called when touch ended event is issued.
|
|
|
|
*@param touch The touch info.
|
|
|
|
*@param unusedEvent The touch event info.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual void onTouchEnded(Touch *touch, Event *unusedEvent);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A callback which will be called when touch cancelled event is issued.
|
|
|
|
*@param touch The touch info.
|
|
|
|
*@param unusedEvent The touch event info.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual void onTouchCancelled(Touch *touch, Event *unusedEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a LayoutParameter to widget.
|
|
|
|
*
|
|
|
|
* @see LayoutParameter
|
2015-03-27 17:09:54 +08:00
|
|
|
* @param parameter LayoutParameter pointer
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
void setLayoutParameter(LayoutParameter* parameter);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets LayoutParameter of widget.
|
|
|
|
*
|
|
|
|
* @see LayoutParameter
|
|
|
|
* @return LayoutParameter
|
|
|
|
*/
|
2014-05-27 10:19:05 +08:00
|
|
|
LayoutParameter* getLayoutParameter()const override;
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Gets LayoutParameter of widget.
|
|
|
|
*
|
|
|
|
* @see LayoutParameter
|
|
|
|
* @deprecated use `getLayoutParameter()` instead.
|
|
|
|
* @param type Relative or Linear
|
|
|
|
* @return LayoutParameter
|
|
|
|
*/
|
2014-05-19 17:43:27 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE LayoutParameter* getLayoutParameter(LayoutParameter::Type type);
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Toggle whether ignore user defined content size for widget.
|
|
|
|
* Set true will ignore user defined content size which means
|
2015-03-26 15:47:14 +08:00
|
|
|
* the widget size is always equal to the return value of `getVirtualRendererSize`.
|
2014-07-15 11:46:53 +08:00
|
|
|
*
|
2015-03-27 17:09:54 +08:00
|
|
|
* @param ignore set member variabl _ignoreSize to ignore
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
virtual void ignoreContentAdaptWithSize(bool ignore);
|
|
|
|
|
|
|
|
/**
|
2014-07-15 11:46:53 +08:00
|
|
|
* Query whether the widget ignores user deinfed content size or not
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @return True means ignore user defined content size, false otherwise.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
bool isIgnoreContentAdaptWithSize() const;
|
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Gets position of widget in world space.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @return Position of widget in world space.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-05-27 10:19:05 +08:00
|
|
|
Vec2 getWorldPosition()const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Gets the inner Renderer node of widget.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
|
|
|
* For example, a button's Virtual Renderer is it's texture renderer.
|
|
|
|
*
|
|
|
|
* @return Node pointer.
|
|
|
|
*/
|
|
|
|
virtual Node* getVirtualRenderer();
|
|
|
|
|
2014-07-15 11:46:53 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Get the virtual renderer's size
|
|
|
|
*@return Widget virtual renderer size.
|
|
|
|
*/
|
2014-09-12 14:39:22 +08:00
|
|
|
virtual Size getVirtualRendererSize() const;
|
2014-04-17 14:08:25 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Returns the string representation of widget class name
|
|
|
|
* @return get the class description.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
virtual std::string getDescription() const override;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Create a new widget copy of the original one.
|
|
|
|
* @return A cloned widget copy of original.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
Widget* clone();
|
2015-03-30 15:47:47 +08:00
|
|
|
/**
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual void onEnter() override;
|
2015-03-30 15:47:47 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual void onExit() override;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Update all children's contents size and position recursively.
|
|
|
|
* @see `updateSizeAndPosition(const Size&)`
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void updateSizeAndPosition();
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Update all children's contents size and position recursively.
|
|
|
|
*/
|
2014-03-13 10:11:41 +08:00
|
|
|
void updateSizeAndPosition(const Size& parentSize);
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Set the tag of action.
|
|
|
|
*@param tag A integer tag value.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setActionTag(int tag);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the action tag.
|
|
|
|
*@return Action tag.
|
|
|
|
*/
|
|
|
|
int getActionTag()const;
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2014-08-15 15:28:28 +08:00
|
|
|
/**
|
2014-09-17 10:57:40 +08:00
|
|
|
* @brief Allow widget touch events to propagate to its parents. Set false will disable propagation
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param isPropagate True to allow propagation, false otherwise.
|
2014-09-17 10:57:40 +08:00
|
|
|
* @since v3.3
|
2014-08-15 15:28:28 +08:00
|
|
|
*/
|
|
|
|
void setPropagateTouchEvents(bool isPropagate);
|
2014-09-17 10:57:40 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return whether the widget is propagate touch events to its parents or not
|
2015-03-25 18:17:58 +08:00
|
|
|
* @return whether touch event propagation is allowed or not.
|
2014-09-17 10:57:40 +08:00
|
|
|
* @since v3.3
|
|
|
|
*/
|
|
|
|
|
2014-08-15 15:28:28 +08:00
|
|
|
bool isPropagateTouchEvents()const;
|
2014-09-17 10:57:40 +08:00
|
|
|
|
2014-08-15 15:28:28 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Toggle widget swallow touch option.
|
2014-09-17 10:57:40 +08:00
|
|
|
* @brief Specify widget to swallow touches or not
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param swallow True to swallow touch, false otherwise.
|
2014-09-17 10:57:40 +08:00
|
|
|
* @since v3.3
|
2014-08-15 15:28:28 +08:00
|
|
|
*/
|
|
|
|
void setSwallowTouches(bool swallow);
|
2014-09-17 10:57:40 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return whether the widget is swallowing touch or not
|
2015-03-25 18:17:58 +08:00
|
|
|
* @return Whether touch is swallowed.
|
2014-09-17 10:57:40 +08:00
|
|
|
* @since v3.3
|
|
|
|
*/
|
2014-08-15 15:28:28 +08:00
|
|
|
bool isSwallowTouches()const;
|
|
|
|
|
2014-05-04 11:23:20 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Query whether widget is focused or not.
|
2014-05-04 11:23:20 +08:00
|
|
|
*@return whether the widget is focused or not
|
|
|
|
*/
|
2014-05-27 10:19:05 +08:00
|
|
|
bool isFocused()const;
|
2014-05-04 11:23:20 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Toggle widget focus status.
|
2014-05-04 11:23:20 +08:00
|
|
|
*@param focus pass true to let the widget get focus or pass false to let the widget lose focus
|
|
|
|
*@return void
|
|
|
|
*/
|
|
|
|
void setFocused(bool focus);
|
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Query widget's focus enable state.
|
2014-05-04 11:23:20 +08:00
|
|
|
*@return true represent the widget could accept focus, false represent the widget couldn't accept focus
|
|
|
|
*/
|
2014-05-27 10:19:05 +08:00
|
|
|
bool isFocusEnabled()const;
|
2014-05-04 11:23:20 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Allow widget to accept focus.
|
2014-05-04 11:23:20 +08:00
|
|
|
*@param enable pass true/false to enable/disable the focus ability of a widget
|
|
|
|
*@return void
|
|
|
|
*/
|
|
|
|
void setFocusEnabled(bool enable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When a widget is in a layout, you could call this method to get the next focused widget within a specified direction.
|
|
|
|
* If the widget is not in a layout, it will return itself
|
2015-03-27 17:09:54 +08:00
|
|
|
*@param direction the direction to look for the next focused widget in a layout
|
2014-05-04 11:23:20 +08:00
|
|
|
*@param current the current focused widget
|
|
|
|
*@return the next focused widget in a layout
|
|
|
|
*/
|
2014-05-07 14:26:41 +08:00
|
|
|
virtual Widget* findNextFocusedWidget(FocusDirection direction, Widget* current);
|
2014-05-04 11:23:20 +08:00
|
|
|
|
2014-05-07 10:23:57 +08:00
|
|
|
/**
|
|
|
|
* when a widget calls this method, it will get focus immediately.
|
|
|
|
*/
|
|
|
|
void requestFocus();
|
2014-05-26 22:57:50 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Return a current focused widget in your UI scene.
|
|
|
|
* No matter what widget object you call this method on , it will return you the exact one focused widget.
|
2014-05-26 22:57:50 +08:00
|
|
|
* @param isWidget if your set isWidget to true, it will return the _realFocusedWidget which is always a widget
|
2015-03-25 18:17:58 +08:00
|
|
|
* otherwise, it will return a widget or a layout.
|
|
|
|
* @deprecated use `getCurrentFocusedWidget` instead.
|
2014-05-26 22:57:50 +08:00
|
|
|
*/
|
|
|
|
CC_DEPRECATED_ATTRIBUTE Widget* getCurrentFocusedWidget(bool isWidget){
|
|
|
|
CC_UNUSED_PARAM(isWidget);
|
|
|
|
return getCurrentFocusedWidget();
|
|
|
|
}
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Return a current focused widget in your UI scene.
|
|
|
|
* No matter what widget object you call this method on , it will return you the exact one focused widget.
|
|
|
|
*/
|
2014-05-27 10:19:05 +08:00
|
|
|
Widget* getCurrentFocusedWidget()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-05-27 13:49:00 +08:00
|
|
|
/*
|
2015-03-25 18:17:58 +08:00
|
|
|
* Call this method with parameter true to enable the Android Dpad focus navigation feature
|
2014-05-27 13:49:00 +08:00
|
|
|
*@param enable set true to enable dpad focus navigation, otherwise disenable dpad focus navigation
|
|
|
|
*/
|
2014-05-26 22:57:50 +08:00
|
|
|
static void enableDpadNavigation(bool enable);
|
|
|
|
|
2014-06-06 16:48:49 +08:00
|
|
|
/**
|
|
|
|
* When a widget lose/get focus, this method will be called. Be Caution when you provide your own version,
|
|
|
|
* you must call widget->setFocused(true/false) to change the focus state of the current focused widget;
|
|
|
|
*/
|
2014-05-26 22:57:50 +08:00
|
|
|
std::function<void(Widget*,Widget*)> onFocusChanged;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-06-06 16:48:49 +08:00
|
|
|
/**
|
|
|
|
* use this function to manually specify the next focused widget regards to each direction
|
|
|
|
*/
|
2014-05-26 22:57:50 +08:00
|
|
|
std::function<Widget*(FocusDirection)> onNextFocusedWidget;
|
2014-10-09 18:28:09 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
*Toggle use unify size.
|
|
|
|
*@param enable True to use unify size, false otherwise.
|
2014-10-09 18:28:09 +08:00
|
|
|
*@return void
|
|
|
|
*/
|
|
|
|
void setUnifySizeEnabled(bool enable);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-12-05 19:19:53 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Query whether unify size enable state.
|
|
|
|
*@return true represent the widget use Unify Size, false represent the widget couldn't use Unify Size
|
|
|
|
*/
|
2014-12-05 19:19:53 +08:00
|
|
|
bool isUnifySizeEnabled()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-11-27 16:49:19 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Set callback name.
|
|
|
|
*@param callbackName A string representation of callback name.
|
2014-11-27 16:49:19 +08:00
|
|
|
*/
|
|
|
|
void setCallbackName(const std::string& callbackName) { _callbackName = callbackName; }
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query callback name.
|
|
|
|
*@return The callback name.
|
|
|
|
*/
|
2014-11-27 16:49:19 +08:00
|
|
|
const std::string& getCallbackName() const{ return _callbackName; }
|
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Set callback type.
|
|
|
|
* @param callbackType A string representation of callback type.
|
2014-11-27 16:49:19 +08:00
|
|
|
*/
|
|
|
|
void setCallbackType(const std::string& callbackType) { _callbackType = callbackType; }
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Query callback type.
|
|
|
|
*@return Callback type string.
|
|
|
|
*/
|
2014-11-27 16:49:19 +08:00
|
|
|
const std::string& getCallbackType() const{ return _callbackType; }
|
2014-05-26 22:57:50 +08:00
|
|
|
|
2014-12-23 20:29:53 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Toggle layout component enable.
|
|
|
|
*@param enable Layout Component of a widget
|
|
|
|
*@return void
|
|
|
|
*/
|
2014-12-23 20:29:53 +08:00
|
|
|
void setLayoutComponentEnabled(bool enable);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-12-23 20:29:53 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Query whether layout component is enabled or not.
|
|
|
|
*@return true represent the widget use Layout Component, false represent the widget couldn't use Layout Component.
|
|
|
|
*/
|
2014-12-23 20:29:53 +08:00
|
|
|
bool isLayoutComponentEnabled()const;
|
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2014-06-06 16:48:49 +08:00
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
//initializes state of widget.
|
|
|
|
virtual bool init() override;
|
2014-06-06 16:48:49 +08:00
|
|
|
|
|
|
|
/*
|
2014-08-15 15:28:28 +08:00
|
|
|
* @brief Sends the touch event to widget's parent, if a widget wants to handle touch event under another widget,
|
|
|
|
* it must overide this function.
|
2014-06-06 16:48:49 +08:00
|
|
|
* @param event the touch event type, it could be BEGAN/MOVED/CANCELED/ENDED
|
|
|
|
* @param parent
|
|
|
|
* @param point
|
|
|
|
*/
|
|
|
|
virtual void interceptTouchEvent(TouchEventType event, Widget* sender, Touch *touch);
|
2014-08-15 15:28:28 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*@brief Propagate touch events to its parents
|
|
|
|
*/
|
|
|
|
void propagateTouchEvent(TouchEventType event, Widget* sender, Touch *touch);
|
|
|
|
|
2014-06-06 16:48:49 +08:00
|
|
|
friend class PageView;
|
2014-05-04 11:23:20 +08:00
|
|
|
/**
|
|
|
|
* This method is called when a focus change event happens
|
|
|
|
*@param widgetLostFocus The widget which lose its focus
|
|
|
|
*@param widgetGetFocus The widget whihc get its focus
|
|
|
|
*@return void
|
|
|
|
*/
|
|
|
|
void onFocusChange(Widget* widgetLostFocus, Widget* widgetGetFocus);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatch a EventFocus through a EventDispatcher
|
|
|
|
*@param widgetLoseFocus The widget which lose its focus
|
|
|
|
*@param widgetGetFocus he widget whihc get its focus
|
|
|
|
*@return void
|
|
|
|
*/
|
|
|
|
void dispatchFocusEvent(Widget* widgetLoseFocus, Widget* widgetGetFocus);
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
2014-12-23 15:03:31 +08:00
|
|
|
/**
|
|
|
|
* Get a normal state GLProgramState
|
|
|
|
*@since v3.4
|
|
|
|
*/
|
|
|
|
|
|
|
|
GLProgramState* getNormalGLProgramState()const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a disabled state GLProgramState
|
|
|
|
*@since v3.4
|
|
|
|
*/
|
|
|
|
GLProgramState* getGrayGLProgramState()const;
|
|
|
|
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
//call back function called when size changed.
|
|
|
|
virtual void onSizeChanged();
|
|
|
|
|
|
|
|
//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();
|
2014-06-06 16:48:49 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
void pushDownEvent();
|
|
|
|
void moveEvent();
|
2014-05-26 14:44:28 +08:00
|
|
|
|
|
|
|
virtual void releaseUpEvent();
|
|
|
|
virtual void cancelUpEvent();
|
2014-06-06 16:14:35 +08:00
|
|
|
|
2014-11-05 20:22:35 +08:00
|
|
|
|
2014-05-22 15:23:13 +08:00
|
|
|
virtual void adaptRenderers(){};
|
2014-08-11 15:04:00 +08:00
|
|
|
void updateChildrenDisplayedRGBA();
|
2014-05-22 15:23:13 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
void copyProperties(Widget* model);
|
|
|
|
virtual Widget* createCloneInstance();
|
|
|
|
virtual void copySpecialProperties(Widget* model);
|
|
|
|
virtual void copyClonedWidgetChildren(Widget* model);
|
2014-05-22 15:23:13 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
Widget* getWidgetParent();
|
2014-04-17 14:08:25 +08:00
|
|
|
void updateContentSizeWithTextureSize(const Size& size);
|
2014-05-22 15:23:13 +08:00
|
|
|
|
2014-05-14 09:23:56 +08:00
|
|
|
bool isAncestorsEnabled();
|
2014-05-13 16:37:41 +08:00
|
|
|
Widget* getAncensterWidget(Node* node);
|
|
|
|
bool isAncestorsVisible(Node* node);
|
|
|
|
|
2014-05-26 22:57:50 +08:00
|
|
|
void cleanupWidget();
|
2014-10-09 18:28:09 +08:00
|
|
|
LayoutComponent* getOrCreateLayoutComponent();
|
2014-05-26 22:57:50 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
2014-12-23 20:29:53 +08:00
|
|
|
bool _usingLayoutComponent;
|
2014-10-09 18:28:09 +08:00
|
|
|
bool _unifySize;
|
2014-07-16 10:08:23 +08:00
|
|
|
bool _enabled;
|
|
|
|
bool _bright;
|
|
|
|
bool _touchEnabled;
|
|
|
|
bool _highlight;
|
2014-06-06 16:48:49 +08:00
|
|
|
bool _affectByClipping;
|
|
|
|
bool _ignoreSize;
|
2014-08-15 15:28:28 +08:00
|
|
|
bool _propagateTouchEvents;
|
2014-06-06 16:48:49 +08:00
|
|
|
|
2014-07-16 10:08:23 +08:00
|
|
|
BrightStyle _brightStyle;
|
2014-06-06 16:48:49 +08:00
|
|
|
SizeType _sizeType;
|
|
|
|
PositionType _positionType;
|
|
|
|
|
2014-07-16 10:08:23 +08:00
|
|
|
//used for search widget by action tag in UIHelper class
|
2014-05-13 10:15:29 +08:00
|
|
|
int _actionTag;
|
2014-06-06 16:48:49 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
Size _customSize;
|
2014-05-19 17:43:27 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 _sizePercent;
|
|
|
|
Vec2 _positionPercent;
|
2014-06-06 16:48:49 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
bool _hitted;
|
2015-07-01 11:03:09 +08:00
|
|
|
// weak reference of the camera which made the widget passed the hit test when response touch begin event
|
|
|
|
// it's useful in the next touch move/end events
|
2015-06-18 10:23:52 +08:00
|
|
|
const Camera *_hittedByCamera;
|
2014-03-11 17:13:54 +08:00
|
|
|
EventListenerTouchOneByOne* _touchListener;
|
2014-07-16 10:08:23 +08:00
|
|
|
Vec2 _touchBeganPosition;
|
|
|
|
Vec2 _touchMovePosition;
|
|
|
|
Vec2 _touchEndPosition;
|
2014-06-06 16:48:49 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
bool _flippedX;
|
|
|
|
bool _flippedY;
|
2014-06-06 16:48:49 +08:00
|
|
|
|
2014-05-16 10:33:28 +08:00
|
|
|
//use map to enble switch back and forth for user layout parameters
|
2014-05-16 10:22:53 +08:00
|
|
|
Map<int,LayoutParameter*> _layoutParameterDictionary;
|
2014-05-16 10:33:28 +08:00
|
|
|
LayoutParameter::Type _layoutParameterType;
|
|
|
|
|
2014-05-04 11:23:20 +08:00
|
|
|
bool _focused;
|
|
|
|
bool _focusEnabled;
|
|
|
|
/**
|
|
|
|
* store the only one focued widget
|
|
|
|
*/
|
2014-05-07 18:27:05 +08:00
|
|
|
static Widget *_focusedWidget; //both layout & widget will be stored in this variable
|
2014-05-26 18:17:47 +08:00
|
|
|
|
2014-06-06 16:48:49 +08:00
|
|
|
Ref* _touchEventListener;
|
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (push)
|
|
|
|
#pragma warning (disable: 4996)
|
|
|
|
#endif
|
|
|
|
SEL_TouchEvent _touchEventSelector;
|
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (pop)
|
|
|
|
#endif
|
|
|
|
ccWidgetTouchCallback _touchEventCallback;
|
2014-08-21 10:21:07 +08:00
|
|
|
ccWidgetClickCallback _clickEventListener;
|
2014-11-27 16:49:19 +08:00
|
|
|
ccWidgetEventCallback _ccEventCallback;
|
|
|
|
|
|
|
|
std::string _callbackType;
|
|
|
|
std::string _callbackName;
|
2014-05-26 18:17:47 +08:00
|
|
|
private:
|
|
|
|
class FocusNavigationController;
|
2014-05-26 22:57:50 +08:00
|
|
|
static FocusNavigationController* _focusNavigationController;
|
2014-03-11 17:13:54 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-03-26 15:47:14 +08:00
|
|
|
NS_CC_END
|
2015-03-25 18:17:58 +08:00
|
|
|
// end of ui group
|
|
|
|
/// @}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
#endif /* defined(__Widget__) */
|