2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2020-05-20 08:56:12 +08:00
|
|
|
Copyright (c) 2020 c4games.com.
|
2014-03-11 17:13:54 +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 __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
|
|
|
|
|
|
|
/**
|
|
|
|
*@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
|
|
|
*/
|
2019-07-22 09:38:46 +08:00
|
|
|
Widget();
|
2014-06-09 10:41:17 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*
|
2015-10-23 15:37:33 +08:00
|
|
|
* @return true if the widget is highlighted, false if the widget is not highlighted.
|
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
|
|
|
|
|
|
|
/**
|
2015-10-23 15:37:33 +08:00
|
|
|
* Sets whether the widget is highlighted
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-10-23 15:37:33 +08:00
|
|
|
* The default value is false, a widget is default to not highlighted
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-10-23 15:37:33 +08:00
|
|
|
* @param highlight true if the widget is highlighted, false if the widget is not highlighted.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2015-10-23 15:37:33 +08:00
|
|
|
void setHighlighted(bool highlight);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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-10-23 15:37:33 +08:00
|
|
|
* @param flippedX true if the widget should be flipped horizontally, 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
|
|
|
*
|
2015-10-23 15:37:33 +08:00
|
|
|
* @return true if the widget is flipped horizontally, false otherwise.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
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-10-09 16:59:11 +08:00
|
|
|
* @param flippedY true if the widget should be flipped vertically, false 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
|
|
|
*
|
2015-10-09 16:59:11 +08:00
|
|
|
* @return true if the widget is flipped vertically, false otherwise.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-05-27 10:19:05 +08:00
|
|
|
virtual bool isFlippedY()const{return _flippedY;};
|
2014-03-11 17:13:54 +08:00
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks a point if in parent's area.
|
|
|
|
*
|
2015-03-27 17:09:54 +08:00
|
|
|
* @param pt A point in `Vec2`.
|
2015-10-09 16:59:11 +08:00
|
|
|
* @return true if the point is in parent's area, false otherwise.
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
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
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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 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-10-09 16:59:11 +08:00
|
|
|
* @return true if the point is in widget's content space, false 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;
|
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-10-23 15:37:33 +08:00
|
|
|
* @param ignore set member variable _ignoreSize to ignore
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
virtual void ignoreContentAdaptWithSize(bool ignore);
|
|
|
|
|
|
|
|
/**
|
2015-10-23 15:37:33 +08:00
|
|
|
* Query whether the widget ignores user defined 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
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*/
|
2015-09-30 17:31:33 +08:00
|
|
|
static Widget* getCurrentFocusedWidget();
|
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
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
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:
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
|
|
|
|
friend class PageView;
|
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,
|
2015-10-23 15:37:33 +08:00
|
|
|
* it must override 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-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
|
2015-10-23 15:37:33 +08:00
|
|
|
*@param widgetGetFocus The widget which get its focus
|
2014-05-04 11:23:20 +08:00
|
|
|
*/
|
|
|
|
void onFocusChange(Widget* widgetLostFocus, Widget* widgetGetFocus);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatch a EventFocus through a EventDispatcher
|
|
|
|
*@param widgetLoseFocus The widget which lose its focus
|
2015-10-23 15:37:33 +08:00
|
|
|
*@param widgetGetFocus he widget which get its focus
|
2014-05-04 11:23:20 +08:00
|
|
|
*/
|
|
|
|
void dispatchFocusEvent(Widget* widgetLoseFocus, Widget* widgetGetFocus);
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
|
|
|
//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();
|
2017-01-11 21:36:13 +08:00
|
|
|
Widget* getAncestorWidget(Node* node);
|
2014-05-13 16:37:41 +08:00
|
|
|
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
|
|
|
|
2015-12-21 07:21:45 +08:00
|
|
|
//use map to enable 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;
|
|
|
|
/**
|
2015-12-21 07:21:45 +08:00
|
|
|
* store the only one focused widget
|
2014-05-04 11:23:20 +08:00
|
|
|
*/
|
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;
|
|
|
|
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__) */
|