123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661 |
- #ifndef __LAYOUT_H__
- #define __LAYOUT_H__
- #include "ui/UIWidget.h"
- #include "ui/GUIExport.h"
- #include "renderer/CCCustomCommand.h"
- #include "renderer/CCGroupCommand.h"
- NS_CC_BEGIN
- class DrawNode;
- class LayerColor;
- class LayerGradient;
- class StencilStateManager;
- struct CC_DLL ResourceData;
- namespace ui {
-
- class LayoutManager;
- class Scale9Sprite;
- class CC_GUI_DLL LayoutProtocol
- {
- public:
-
- LayoutProtocol(){}
-
- virtual ~LayoutProtocol(){}
-
-
- virtual LayoutManager* createLayoutManager() = 0;
-
-
- virtual Size getLayoutContentSize()const = 0;
-
-
- virtual const Vector<Node*>& getLayoutElements()const = 0;
-
-
- virtual void doLayout() = 0;
- };
- #if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
- #ifdef RELATIVE
- #undef RELATIVE
- #endif
- #endif
- class CC_GUI_DLL Layout : public Widget, public LayoutProtocol
- {
-
- DECLARE_CLASS_GUI_INFO
-
- public:
-
- enum class Type
- {
- ABSOLUTE,
- VERTICAL,
- HORIZONTAL,
- RELATIVE
- };
-
-
- enum class ClippingType
- {
- STENCIL,
- SCISSOR
- };
-
-
- enum class BackGroundColorType
- {
- NONE,
- SOLID,
- GRADIENT
- };
-
-
- Layout();
-
-
- virtual ~Layout();
-
-
- static Layout* create();
-
-
- void setBackGroundImage(const std::string& fileName,TextureResType texType = TextureResType::LOCAL);
-
-
- void setBackGroundImageCapInsets(const Rect& capInsets);
-
-
- const Rect& getBackGroundImageCapInsets()const;
-
-
- void setBackGroundColorType(BackGroundColorType type);
-
-
- BackGroundColorType getBackGroundColorType()const;
-
-
- void setBackGroundImageScale9Enabled(bool enabled);
-
-
- bool isBackGroundImageScale9Enabled()const;
-
-
- void setBackGroundColor(const Color3B &color);
-
-
- const Color3B& getBackGroundColor()const;
-
-
- void setBackGroundColor(const Color3B &startColor, const Color3B &endColor);
-
-
- const Color3B& getBackGroundStartColor()const;
-
-
- const Color3B& getBackGroundEndColor()const;
-
-
- void setBackGroundColorOpacity(GLubyte opacity);
-
-
- GLubyte getBackGroundColorOpacity()const;
-
-
- void setBackGroundColorVector(const Vec2 &vector);
-
-
- const Vec2& getBackGroundColorVector()const;
-
-
- void setBackGroundImageColor(const Color3B& color);
-
-
- void setBackGroundImageOpacity(GLubyte opacity);
-
-
- const Color3B& getBackGroundImageColor()const;
-
-
- GLubyte getBackGroundImageOpacity()const;
-
-
- void removeBackGroundImage();
-
-
- const Size& getBackGroundImageTextureSize() const;
-
-
- virtual void setClippingEnabled(bool enabled);
-
-
-
- void setClippingType(ClippingType type);
-
- ClippingType getClippingType()const;
-
-
- virtual bool isClippingEnabled()const;
-
-
- virtual std::string getDescription() const override;
-
-
- virtual void setLayoutType(Type type);
-
-
- virtual Type getLayoutType() const;
-
- virtual void addChild(Node* child)override;
- virtual void addChild(Node * child, int localZOrder)override;
-
- virtual void addChild(Node* child, int localZOrder, int tag) override;
- virtual void addChild(Node* child, int localZOrder, const std::string &name) override;
-
- virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
- virtual void removeChild(Node* child, bool cleanup = true) override;
-
-
- virtual void removeAllChildren() override;
-
- virtual void removeAllChildrenWithCleanup(bool cleanup) override;
-
- virtual void forceDoLayout();
-
-
- virtual void requestDoLayout();
-
-
- virtual void onEnter() override;
-
-
- virtual void onExit() override;
-
- virtual void setGlobalZOrder(float globalZOrder) override;
-
-
- void setLoopFocus(bool loop);
-
-
- bool isLoopFocus()const;
-
-
- void setPassFocusToChild(bool pass);
-
-
- bool isPassFocusToChild()const;
-
-
- virtual Widget* findNextFocusedWidget(FocusDirection direction, Widget* current) override;
-
-
- std::function<int(FocusDirection, Widget*)> onPassFocusToChild;
-
-
- virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override;
- ResourceData getRenderFile();
- CC_CONSTRUCTOR_ACCESS:
-
- virtual bool init() override;
-
- protected:
-
- virtual void onSizeChanged() override;
-
-
- void addBackGroundImage();
-
- void supplyTheLayoutParameterLackToChild(Widget* child);
- virtual Widget* createCloneInstance() override;
- virtual void copySpecialProperties(Widget* model) override;
- virtual void copyClonedWidgetChildren(Widget* model) override;
-
- void stencilClippingVisit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags);
- void scissorClippingVisit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags);
-
- void setStencilClippingSize(const Size& size);
- const Rect& getClippingRect();
-
- virtual void doLayout()override;
- virtual LayoutManager* createLayoutManager()override;
- virtual Size getLayoutContentSize()const override;
- virtual const Vector<Node*>& getLayoutElements()const override;
-
-
-
- void onBeforeVisitScissor();
- void onAfterVisitScissor();
- void updateBackGroundImageColor();
- void updateBackGroundImageOpacity();
- void updateBackGroundImageRGBA();
-
-
- Size getLayoutAccumulatedSize() const;
-
-
- int findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWidget);
-
-
- int findFarthestChildWidgetIndex(FocusDirection direction, Widget* baseWidget);
-
-
- float calculateNearestDistance(Widget* baseWidget);
-
-
- float calculateFarthestDistance(Widget* baseWidget);
-
-
- void findProperSearchingFunctor(FocusDirection dir, Widget* baseWidget);
-
-
- Widget *findFirstNonLayoutWidget();
-
-
- int findFirstFocusEnabledWidgetIndex();
-
-
- Widget* findFocusEnabledChildWidgetByIndex(ssize_t index);
-
-
- Vec2 getWorldCenterPoint(Widget* node)const;
-
-
- Widget* getNextFocusedWidget(FocusDirection direction,Widget *current);
-
-
- Widget* getPreviousFocusedWidget(FocusDirection direction, Widget *current);
-
-
- Widget* getChildWidgetByIndex(ssize_t index)const;
-
- bool isLastWidgetInContainer(Widget* widget, FocusDirection direction)const;
-
-
- bool isWidgetAncestorSupportLoopFocus(Widget* widget, FocusDirection direction)const;
-
-
- Widget* passFocusToChild(FocusDirection direction, Widget* current);
-
-
- bool checkFocusEnabledChild()const;
-
- protected:
-
-
- bool _backGroundScale9Enabled;
- Scale9Sprite* _backGroundImage;
- std::string _backGroundImageFileName;
- Rect _backGroundImageCapInsets;
- BackGroundColorType _colorType;
- TextureResType _bgImageTexType;
- Size _backGroundImageTextureSize;
- Color3B _backGroundImageColor;
- GLubyte _backGroundImageOpacity;
- LayerColor* _colorRender;
- LayerGradient* _gradientRender;
- Color3B _cColor;
- Color3B _gStartColor;
- Color3B _gEndColor;
- Vec2 _alongVector;
- GLubyte _cOpacity;
-
-
- bool _clippingEnabled;
- Type _layoutType;
- ClippingType _clippingType;
- DrawNode* _clippingStencil;
- bool _scissorOldState;
- Rect _clippingOldRect;
- Rect _clippingRect;
- Layout* _clippingParent;
- bool _clippingRectDirty;
-
-
- StencilStateManager *_stencilStateManager;
- GroupCommand _groupCommand;
- CustomCommand _beforeVisitCmdStencil;
- CustomCommand _afterDrawStencilCmd;
- CustomCommand _afterVisitCmdStencil;
- CustomCommand _beforeVisitCmdScissor;
- CustomCommand _afterVisitCmdScissor;
-
- bool _doLayoutDirty;
- bool _isInterceptTouch;
-
-
- bool _loopFocus;
-
- bool _passFocusToChild;
-
- bool _isFocusPassing;
- };
-
- }
- NS_CC_END
- #endif
|