axmol/extensions/fairygui/GComponent.h

151 lines
4.7 KiB
C
Raw Normal View History

2020-08-04 12:31:33 +08:00
#ifndef __GCOMPONENT_H__
#define __GCOMPONENT_H__
#include "FairyGUIMacros.h"
#include "GObject.h"
#include "Margin.h"
#include "ScrollPane.h"
#include "Transition.h"
#include "cocos2d.h"
#include "display/FUIContainer.h"
#include "event/HitTest.h"
NS_FGUI_BEGIN
class GComponent : public GObject
{
public:
GComponent();
virtual ~GComponent();
CREATE_FUNC(GComponent);
GObject* addChild(GObject* child);
virtual GObject* addChildAt(GObject* child, int index);
void removeChild(GObject* child);
virtual void removeChildAt(int index);
void removeChildren() { removeChildren(0, -1); }
void removeChildren(int beginIndex, int endIndex);
GObject* getChildAt(int index) const;
GObject* getChild(const std::string& name) const;
GObject* getChildByPath(const std::string& path) const;
GObject* getChildInGroup(const GGroup* group, const std::string& name) const;
GObject* getChildById(const std::string& id) const;
2022-08-08 18:02:17 +08:00
const ax::Vector<GObject*>& getChildren() const { return _children; }
2020-08-04 12:31:33 +08:00
int getChildIndex(const GObject* child) const;
void setChildIndex(GObject* child, int index);
int setChildIndexBefore(GObject* child, int index);
void swapChildren(GObject* child1, GObject* child2);
void swapChildrenAt(int index1, int index2);
int numChildren() const;
bool isAncestorOf(const GObject* obj) const;
virtual bool isChildInView(GObject* child);
virtual int getFirstChildInView();
void addController(GController* c);
GController* getControllerAt(int index) const;
GController* getController(const std::string& name) const;
2022-08-08 18:02:17 +08:00
const ax::Vector<GController*>& getControllers() const { return _controllers; }
2020-08-04 12:31:33 +08:00
void removeController(GController* c);
void applyController(GController* c);
void applyAllControllers();
Transition* getTransition(const std::string& name) const;
Transition* getTransitionAt(int index) const;
2022-08-08 18:02:17 +08:00
const ax::Vector<Transition*>& getTransitions() const { return _transitions; }
2020-08-04 12:31:33 +08:00
bool getOpaque() const { return _opaque; }
void setOpaque(bool value);
const Margin& getMargin() { return _margin; }
void setMargin(const Margin& value);
ChildrenRenderOrder getChildrenRenderOrder() const { return _childrenRenderOrder; }
void setChildrenRenderOrder(ChildrenRenderOrder value);
int getApexIndex() const { return _apexIndex; }
void setApexIndex(int value);
2022-08-08 18:02:17 +08:00
ax::Node* getMask() const;
void setMask(ax::Node* value, bool inverted = false);
2020-08-04 12:31:33 +08:00
IHitTest* getHitArea() const { return _hitArea; }
void setHitArea(IHitTest* value);
ScrollPane* getScrollPane() const { return _scrollPane; }
float getViewWidth() const;
void setViewWidth(float value);
float getViewHeight() const;
void setViewHeight(float value);
void setBoundsChangedFlag();
void ensureBoundsCorrect();
2022-08-08 18:02:17 +08:00
virtual GObject* hitTest(const ax::Vec2& worldPoint, const ax::Camera* camera) override;
virtual ax::Vec2 getSnappingPosition(const ax::Vec2& pt);
2020-08-04 12:31:33 +08:00
//internal use
void childSortingOrderChanged(GObject* child, int oldValue, int newValue);
void childStateChanged(GObject* child);
void adjustRadioGroupDepth(GObject* obj, GController* c);
virtual void constructFromResource() override;
void constructFromResource(std::vector<GObject*>* objectPool, int poolIndex);
bool _buildingDisplayList;
protected:
virtual void constructExtension(ByteBuffer* buffer);
virtual void onConstruct();
virtual void setup_afterAdd(ByteBuffer* buffer, int beginPos) override;
virtual void handleInit() override;
virtual void handleSizeChanged() override;
virtual void handleGrayedChanged() override;
virtual void handleControllerChanged(GController* c) override;
virtual void onEnter() override;
virtual void onExit() override;
virtual void updateBounds();
void setBounds(float ax, float ay, float aw, float ah);
void setupOverflow(OverflowType overflow);
void setupScroll(ByteBuffer* buffer);
2022-08-08 18:02:17 +08:00
ax::Vector<GObject*> _children;
ax::Vector<GController*> _controllers;
ax::Vector<Transition*> _transitions;
2020-08-04 12:31:33 +08:00
FUIInnerContainer* _container;
ScrollPane* _scrollPane;
Margin _margin;
2022-08-08 18:02:17 +08:00
ax::Vec2 _alignOffset;
2020-08-04 12:31:33 +08:00
ChildrenRenderOrder _childrenRenderOrder;
int _apexIndex;
bool _boundsChanged;
bool _trackBounds;
GObject* _maskOwner;
IHitTest* _hitArea;
private:
int getInsertPosForSortingChild(GObject* target);
int moveChild(GObject* child, int oldIndex, int index);
CALL_LATER_FUNC(GComponent, doUpdateBounds);
CALL_LATER_FUNC(GComponent, buildNativeDisplayList);
bool _opaque;
int _sortingChildCount;
GController* _applyingController;
friend class ScrollPane;
};
NS_FGUI_END
#endif