axmol/extensions/fairygui/display/FUIContainer.h

115 lines
3.3 KiB
C
Raw Normal View History

2020-08-04 12:31:33 +08:00
#ifndef __FUICONTAINER_H__
#define __FUICONTAINER_H__
#include "cocos2d.h"
#include "FairyGUIMacros.h"
NS_FGUI_BEGIN
class GObject;
class RectClippingSupport
{
public:
RectClippingSupport();
axis::Rect _clippingRegion;
2020-08-04 12:31:33 +08:00
bool _clippingEnabled;
bool _scissorOldState;
axis::Rect _clippingOldRect;
axis::Rect _clippingRect;
2020-08-04 12:31:33 +08:00
bool _clippingRectDirty;
#if COCOS2D_VERSION >= 0x00040000
axis::GroupCommand _groupCommand;
//axis::CallbackCommand _beforeVisitCmdScissor;
//axis::CallbackCommand _afterVisitCmdScissor;
2020-08-04 12:31:33 +08:00
#else
axis::CustomCommand _beforeVisitCmdScissor;
axis::CustomCommand _afterVisitCmdScissor;
2020-08-04 12:31:33 +08:00
#endif
};
class StencilClippingSupport
{
public:
StencilClippingSupport();
axis::Node* _stencil;
axis::StencilStateManager* _stencilStateManager;
axis::GroupCommand _groupCommand;
2020-08-04 12:31:33 +08:00
#if COCOS2D_VERSION >= 0x00040000
axis::backend::ProgramState* _originStencilProgram;
//axis::CallbackCommand _beforeVisitCmd;
//axis::CallbackCommand _afterDrawStencilCmd;
//axis::CallbackCommand _afterVisitCmd;
2020-08-04 12:31:33 +08:00
#else
axis::GLProgram* _originStencilProgram;
axis::CustomCommand _beforeVisitCmd;
axis::CustomCommand _afterDrawStencilCmd;
axis::CustomCommand _afterVisitCmd;
2020-08-04 12:31:33 +08:00
#endif
};
class FUIContainer : public axis::Node
2020-08-04 12:31:33 +08:00
{
public:
FUIContainer();
virtual ~FUIContainer();
CREATE_FUNC(FUIContainer);
bool isClippingEnabled() const;
void setClippingEnabled(bool value);
const axis::Rect& getClippingRegion() const;
void setClippingRegion(const axis::Rect& clippingRegion);
2020-08-04 12:31:33 +08:00
axis::Node* getStencil() const;
void setStencil(axis::Node* stencil);
2020-08-04 12:31:33 +08:00
float getAlphaThreshold() const;
void setAlphaThreshold(float alphaThreshold);
bool isInverted() const;
void setInverted(bool inverted);
void onEnter() override;
void onEnterTransitionDidFinish() override;
void onExitTransitionDidStart() override;
void onExit() override;
void visit(axis::Renderer *renderer, const axis::Mat4 &parentTransform, uint32_t parentFlags) override;
2020-08-04 12:31:33 +08:00
void setCameraMask(unsigned short mask, bool applyChildren = true) override;
2021-12-27 15:10:29 +08:00
void setGlobalZOrder(float globalZOrder) override;
2020-08-04 12:31:33 +08:00
GObject* gOwner;
private:
void onBeforeVisitScissor();
void onAfterVisitScissor();
const axis::Rect& getClippingRect();
2020-08-04 12:31:33 +08:00
RectClippingSupport* _rectClippingSupport;
StencilClippingSupport* _stencilClippingSupport;
#if COCOS2D_VERSION >= 0x00040000
void setProgramStateRecursively(Node* node, axis::backend::ProgramState* programState);
2020-08-04 12:31:33 +08:00
void restoreAllProgramStates();
std::unordered_map<Node*, axis::backend::ProgramState*> _originalStencilProgramState;
2020-08-04 12:31:33 +08:00
#endif
};
//internal use
class FUIInnerContainer : public axis::Node
2020-08-04 12:31:33 +08:00
{
public:
CREATE_FUNC(FUIInnerContainer);
void setPosition2(const axis::Vec2 &position) { setPosition(position.x, _parent->getContentSize().height - position.y); }
axis::Vec2 getPosition2() { return axis::Vec2(_position.x, _parent->getContentSize().height - _position.y); }
2020-08-04 12:31:33 +08:00
void setPosition2(float x, float y) { setPosition(x, _parent->getContentSize().height - y); }
void setPositionY2(float y) { setPositionY(_parent->getContentSize().height - y); }
float getPositionY2(void) const { return _parent->getContentSize().height - _position.y; }
};
NS_FGUI_END
#endif