2020-08-04 12:31:33 +08:00
|
|
|
#ifndef __GOBJECT_H__
|
|
|
|
#define __GOBJECT_H__
|
|
|
|
|
|
|
|
#include "Controller.h"
|
|
|
|
#include "FairyGUIMacros.h"
|
|
|
|
#include "Relations.h"
|
|
|
|
#include "cocos2d.h"
|
|
|
|
#include "event/UIEventDispatcher.h"
|
|
|
|
#include "gears/GearBase.h"
|
|
|
|
|
|
|
|
NS_FGUI_BEGIN
|
|
|
|
|
|
|
|
class GComponent;
|
|
|
|
class GGroup;
|
|
|
|
class ByteBuffer;
|
|
|
|
class GRoot;
|
|
|
|
class PackageItem;
|
|
|
|
class GTreeNode;
|
|
|
|
|
|
|
|
class GObject : public UIEventDispatcher
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static GObject* getDraggingObject() { return _draggingObject; }
|
|
|
|
|
|
|
|
GObject();
|
|
|
|
virtual ~GObject();
|
|
|
|
|
|
|
|
CREATE_FUNC(GObject);
|
|
|
|
|
|
|
|
float getX() const { return _position.x; };
|
|
|
|
void setX(float value);
|
|
|
|
float getY() const { return _position.y; };
|
|
|
|
void setY(float value);
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Vec2& getPosition() const { return _position; }
|
2020-08-04 12:31:33 +08:00
|
|
|
void setPosition(float xv, float yv);
|
|
|
|
float getXMin() const;
|
|
|
|
void setXMin(float value);
|
|
|
|
float getYMin() const;
|
|
|
|
void setYMin(float value);
|
|
|
|
|
|
|
|
bool isPixelSnapping() const { return _pixelSnapping; }
|
|
|
|
void setPixelSnapping(bool value);
|
|
|
|
|
|
|
|
float getWidth() const { return _size.width; }
|
|
|
|
void setWidth(float value) { setSize(value, _rawSize.height); }
|
|
|
|
float getHeight() const { return _size.height; }
|
|
|
|
void setHeight(float value) { setSize(_rawSize.width, value); }
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Size& getSize() const { return _size; }
|
2020-08-04 12:31:33 +08:00
|
|
|
void setSize(float wv, float hv, bool ignorePivot = false);
|
|
|
|
|
|
|
|
void center(bool restraint = false);
|
|
|
|
void makeFullScreen();
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Vec2& getPivot() const { return _pivot; }
|
2020-08-04 12:31:33 +08:00
|
|
|
void setPivot(float xv, float yv, bool asAnchor = false);
|
|
|
|
bool isPivotAsAnchor() const { return _pivotAsAnchor; }
|
|
|
|
|
|
|
|
float getScaleX() const { return _scale.x; }
|
|
|
|
void setScaleX(float value) { setScale(value, _scale.y); }
|
|
|
|
float getScaleY() const { return _scale.y; }
|
|
|
|
void setScaleY(float value) { setScale(_scale.x, value); }
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Vec2& getScale() const { return _scale; }
|
2020-08-04 12:31:33 +08:00
|
|
|
void setScale(float xv, float yv);
|
|
|
|
|
|
|
|
float getSkewX() const { return _displayObject->getSkewX(); }
|
|
|
|
void setSkewX(float value);
|
|
|
|
|
|
|
|
float getSkewY() const { return _displayObject->getSkewY(); }
|
|
|
|
void setSkewY(float value);
|
|
|
|
|
|
|
|
float getRotation() const { return _rotation; }
|
|
|
|
void setRotation(float value);
|
|
|
|
|
|
|
|
float getAlpha() const { return _alpha; }
|
|
|
|
void setAlpha(float value);
|
|
|
|
|
|
|
|
bool isGrayed() const { return _grayed; }
|
|
|
|
void setGrayed(bool value);
|
|
|
|
|
|
|
|
bool isVisible() const { return _visible; }
|
|
|
|
void setVisible(bool value);
|
|
|
|
|
|
|
|
bool isTouchable() const { return _touchable; }
|
|
|
|
void setTouchable(bool value);
|
|
|
|
|
|
|
|
int getSortingOrder() const { return _sortingOrder; }
|
|
|
|
void setSortingOrder(int value);
|
|
|
|
|
|
|
|
GGroup* getGroup() const { return _group; }
|
|
|
|
void setGroup(GGroup* value);
|
|
|
|
|
|
|
|
virtual const std::string& getText() const;
|
|
|
|
virtual void setText(const std::string& text);
|
|
|
|
|
|
|
|
virtual const std::string& getIcon() const;
|
|
|
|
virtual void setIcon(const std::string& text);
|
|
|
|
|
|
|
|
const std::string& getTooltips() const { return _tooltips; }
|
|
|
|
void setTooltips(const std::string& value);
|
|
|
|
|
|
|
|
void* getData() const { return _data; };
|
|
|
|
void setData(void* value) { _data = value; }
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Value& getCustomData() const { return _customData; }
|
|
|
|
void setCustomData(const ax::Value& value) { _customData = value; }
|
2020-08-04 12:31:33 +08:00
|
|
|
|
|
|
|
bool isDraggable() const { return _draggable; }
|
|
|
|
void setDraggable(bool value);
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Rect* getDragBounds() const { return _dragBounds; }
|
|
|
|
void setDragBounds(const ax::Rect& value);
|
2020-08-04 12:31:33 +08:00
|
|
|
|
|
|
|
void startDrag(int touchId = -1);
|
|
|
|
void stopDrag();
|
|
|
|
|
|
|
|
std::string getResourceURL() const;
|
|
|
|
|
|
|
|
PackageItem* getPackageItem() const { return _packageItem; }
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Vec2 globalToLocal(const ax::Vec2& pt);
|
|
|
|
ax::Rect globalToLocal(const ax::Rect& rect);
|
|
|
|
ax::Vec2 localToGlobal(const ax::Vec2& pt);
|
|
|
|
ax::Rect localToGlobal(const ax::Rect& rect);
|
|
|
|
ax::Rect transformRect(const ax::Rect& rect, GObject* targetSpace);
|
2020-08-04 12:31:33 +08:00
|
|
|
|
|
|
|
Relations* relations() { return _relations; }
|
|
|
|
void addRelation(GObject* target, RelationType relationType, bool usePercent = false);
|
|
|
|
void removeRelation(GObject* target, RelationType relationType);
|
|
|
|
|
|
|
|
GearBase* getGear(int index);
|
|
|
|
bool checkGearController(int index, GController* c);
|
|
|
|
uint32_t addDisplayLock();
|
|
|
|
void releaseDisplayLock(uint32_t token);
|
|
|
|
|
|
|
|
GComponent* getParent() const { return _parent; }
|
|
|
|
GObject* findParent() const;
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* displayObject() const { return _displayObject; }
|
2020-08-04 12:31:33 +08:00
|
|
|
GRoot* getRoot() const;
|
|
|
|
bool onStage() const;
|
|
|
|
void removeFromParent();
|
|
|
|
|
|
|
|
void addClickListener(const EventCallback& callback) { addEventListener(UIEventType::Click, callback); }
|
|
|
|
void addClickListener(const EventCallback& callback, const EventTag& tag) { addEventListener(UIEventType::Click, callback, tag); }
|
|
|
|
void removeClickListener(const EventTag& tag) { removeEventListener(UIEventType::Click, tag); }
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
virtual ax::Value getProp(ObjectPropID propId);
|
|
|
|
virtual void setProp(ObjectPropID propId, const ax::Value& value);
|
2020-08-04 12:31:33 +08:00
|
|
|
|
|
|
|
virtual void constructFromResource();
|
2022-08-08 18:02:17 +08:00
|
|
|
virtual GObject* hitTest(const ax::Vec2& worldPoint, const ax::Camera* camera);
|
2020-08-04 12:31:33 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T* as();
|
|
|
|
|
|
|
|
GTreeNode* treeNode() const { return _treeNode; }
|
|
|
|
|
|
|
|
std::string id;
|
|
|
|
std::string name;
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Size sourceSize;
|
|
|
|
ax::Size initSize;
|
|
|
|
ax::Size minSize;
|
|
|
|
ax::Size maxSize;
|
2020-08-04 12:31:33 +08:00
|
|
|
|
|
|
|
//internal use
|
|
|
|
bool _underConstruct;
|
|
|
|
bool _gearLocked;
|
|
|
|
bool _alignToBL;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
GComponent* _parent;
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* _displayObject;
|
2020-08-04 12:31:33 +08:00
|
|
|
PackageItem* _packageItem;
|
|
|
|
int _sizeImplType;
|
|
|
|
bool _touchDisabled;
|
|
|
|
|
|
|
|
virtual void handleInit();
|
|
|
|
virtual void handleSizeChanged();
|
|
|
|
virtual void handleScaleChanged();
|
|
|
|
virtual void handleGrayedChanged();
|
|
|
|
virtual void handlePositionChanged();
|
|
|
|
virtual void handleControllerChanged(GController* c);
|
|
|
|
virtual void handleAlphaChanged();
|
|
|
|
virtual void handleVisibleChanged();
|
|
|
|
|
|
|
|
virtual void onEnter();
|
|
|
|
virtual void onExit();
|
|
|
|
|
|
|
|
virtual void setup_beforeAdd(ByteBuffer* buffer, int beginPos);
|
|
|
|
virtual void setup_afterAdd(ByteBuffer* buffer, int beginPos);
|
|
|
|
|
|
|
|
bool init();
|
|
|
|
|
|
|
|
void updateGear(int index);
|
|
|
|
void checkGearDisplay();
|
|
|
|
|
|
|
|
void setSizeDirectly(float wv, float hv);
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Vec2 _position;
|
|
|
|
ax::Size _size;
|
|
|
|
ax::Size _rawSize;
|
|
|
|
ax::Vec2 _pivot;
|
|
|
|
ax::Vec2 _scale;
|
2020-08-04 12:31:33 +08:00
|
|
|
bool _pivotAsAnchor;
|
|
|
|
float _alpha;
|
|
|
|
float _rotation;
|
|
|
|
bool _visible;
|
|
|
|
bool _touchable;
|
|
|
|
bool _grayed;
|
|
|
|
bool _finalGrayed;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool internalVisible() const;
|
|
|
|
bool internalVisible2() const;
|
|
|
|
bool internalVisible3() const;
|
|
|
|
void updateGearFromRelations(int index, float dx, float dy);
|
2022-08-08 18:02:17 +08:00
|
|
|
void transformRectPoint(const ax::Vec2& pt, float rect[], GObject* targetSpace);
|
2020-08-04 12:31:33 +08:00
|
|
|
|
|
|
|
void initDrag();
|
|
|
|
void dragBegin(int touchId);
|
|
|
|
void dragEnd();
|
|
|
|
void onTouchBegin(EventContext* context);
|
|
|
|
void onTouchMove(EventContext* context);
|
|
|
|
void onTouchEnd(EventContext* context);
|
|
|
|
void onRollOver(EventContext* context);
|
|
|
|
void onRollOut(EventContext* context);
|
|
|
|
|
|
|
|
bool _internalVisible;
|
|
|
|
bool _handlingController;
|
|
|
|
bool _draggable;
|
|
|
|
int _sortingOrder;
|
|
|
|
bool _focusable;
|
|
|
|
std::string _tooltips;
|
|
|
|
bool _pixelSnapping;
|
|
|
|
GGroup* _group;
|
|
|
|
float _sizePercentInGroup;
|
|
|
|
Relations* _relations;
|
|
|
|
GearBase* _gears[10];
|
|
|
|
void* _data;
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Value _customData;
|
|
|
|
ax::Vec2 _dragTouchStartPos;
|
|
|
|
ax::Rect* _dragBounds;
|
2020-08-04 12:31:33 +08:00
|
|
|
bool _dragTesting;
|
|
|
|
GTreeNode* _treeNode;
|
|
|
|
|
|
|
|
uint64_t _uid;
|
|
|
|
size_t _weakPtrRef;
|
|
|
|
|
|
|
|
static GObject* _draggingObject;
|
|
|
|
|
|
|
|
friend class GComponent;
|
|
|
|
friend class GGroup;
|
|
|
|
friend class RelationItem;
|
|
|
|
friend class UIObjectFactory;
|
|
|
|
friend class WeakPtr;
|
|
|
|
friend class UIPackage;
|
|
|
|
friend class GTree;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline T* GObject::as()
|
|
|
|
{
|
|
|
|
return dynamic_cast<T*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_FGUI_END
|
|
|
|
|
|
|
|
#endif
|