axmol/extensions/fairygui/display/FUIContainer.h

115 lines
3.2 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();
2022-08-08 18:02:17 +08:00
ax::Rect _clippingRegion;
2020-08-04 12:31:33 +08:00
bool _clippingEnabled;
bool _scissorOldState;
2022-08-08 18:02:17 +08:00
ax::Rect _clippingOldRect;
ax::Rect _clippingRect;
2020-08-04 12:31:33 +08:00
bool _clippingRectDirty;
#if COCOS2D_VERSION >= 0x00040000
2022-08-08 18:02:17 +08:00
ax::GroupCommand _groupCommand;
//ax::CallbackCommand _beforeVisitCmdScissor;
//ax::CallbackCommand _afterVisitCmdScissor;
2020-08-04 12:31:33 +08:00
#else
2022-08-08 18:02:17 +08:00
ax::CustomCommand _beforeVisitCmdScissor;
ax::CustomCommand _afterVisitCmdScissor;
2020-08-04 12:31:33 +08:00
#endif
};
class StencilClippingSupport
{
public:
StencilClippingSupport();
2022-08-08 18:02:17 +08:00
ax::Node* _stencil;
ax::StencilStateManager* _stencilStateManager;
ax::GroupCommand _groupCommand;
2020-08-04 12:31:33 +08:00
#if COCOS2D_VERSION >= 0x00040000
2022-08-08 18:02:17 +08:00
ax::backend::ProgramState* _originStencilProgram;
//ax::CallbackCommand _beforeVisitCmd;
//ax::CallbackCommand _afterDrawStencilCmd;
//ax::CallbackCommand _afterVisitCmd;
2020-08-04 12:31:33 +08:00
#else
2022-08-08 18:02:17 +08:00
ax::GLProgram* _originStencilProgram;
ax::CustomCommand _beforeVisitCmd;
ax::CustomCommand _afterDrawStencilCmd;
ax::CustomCommand _afterVisitCmd;
2020-08-04 12:31:33 +08:00
#endif
};
2022-08-08 18:02:17 +08:00
class FUIContainer : public ax::Node
2020-08-04 12:31:33 +08:00
{
public:
FUIContainer();
virtual ~FUIContainer();
CREATE_FUNC(FUIContainer);
bool isClippingEnabled() const;
void setClippingEnabled(bool value);
2022-08-08 18:02:17 +08:00
const ax::Rect& getClippingRegion() const;
void setClippingRegion(const ax::Rect& clippingRegion);
2020-08-04 12:31:33 +08:00
2022-08-08 18:02:17 +08:00
ax::Node* getStencil() const;
void setStencil(ax::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;
2022-08-08 18:02:17 +08:00
void visit(ax::Renderer *renderer, const ax::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();
2022-08-08 18:02:17 +08:00
const ax::Rect& getClippingRect();
2020-08-04 12:31:33 +08:00
RectClippingSupport* _rectClippingSupport;
StencilClippingSupport* _stencilClippingSupport;
#if COCOS2D_VERSION >= 0x00040000
2022-08-08 18:02:17 +08:00
void setProgramStateRecursively(Node* node, ax::backend::ProgramState* programState);
2020-08-04 12:31:33 +08:00
void restoreAllProgramStates();
2022-08-08 18:02:17 +08:00
std::unordered_map<Node*, ax::backend::ProgramState*> _originalStencilProgramState;
2020-08-04 12:31:33 +08:00
#endif
};
//internal use
2022-08-08 18:02:17 +08:00
class FUIInnerContainer : public ax::Node
2020-08-04 12:31:33 +08:00
{
public:
CREATE_FUNC(FUIInnerContainer);
2022-08-08 18:02:17 +08:00
void setPosition2(const ax::Vec2 &position) { setPosition(position.x, _parent->getContentSize().height - position.y); }
ax::Vec2 getPosition2() { return ax::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