axmol/cocos/ui/UILayoutComponent.h

166 lines
5.0 KiB
C
Raw Normal View History

2014-10-09 18:28:09 +08:00
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __cocos2d_libs__LayoutComponent__
#define __cocos2d_libs__LayoutComponent__
#include "2d/CCComponent.h"
#include "ui/GUIExport.h"
NS_CC_BEGIN
2014-12-22 11:20:03 +08:00
namespace ui {
class CC_GUI_DLL LayoutComponent : public Component
{
public:
LayoutComponent();
~LayoutComponent();
virtual bool init()override;
CREATE_FUNC(LayoutComponent);
2014-12-25 15:02:22 +08:00
static LayoutComponent* bindLayoutComponent(Node* node);
2014-12-22 14:51:50 +08:00
2014-12-24 10:56:01 +08:00
enum class HorizontalEdge
2014-10-09 18:28:09 +08:00
{
2014-12-22 11:20:03 +08:00
None,
Left,
Right,
Center
2014-10-09 18:28:09 +08:00
};
2014-12-24 10:56:01 +08:00
enum class VerticalEdge
2014-12-22 11:20:03 +08:00
{
None,
2014-12-22 14:51:50 +08:00
Bottom,
2014-12-22 11:20:03 +08:00
Top,
Center
};
2014-12-22 18:39:44 +08:00
// OldVersion
2014-12-23 20:29:53 +08:00
void setUsingPercentContentSize(bool isUsed);
bool getUsingPercentContentSize()const;
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
void setPercentContentSize(const Vec2 &percent);
Vec2 getPercentContentSize()const;
2014-12-22 11:20:03 +08:00
2014-12-22 18:39:44 +08:00
// Position & Margin
2014-12-23 20:29:53 +08:00
const Point& getAnchorPosition()const;
void setAnchorPosition(const Point& point);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
const Point& getPosition()const;
void setPosition(const Point& position);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
bool isPositionPercentXEnabled()const;
void setPositionPercentXEnabled(bool isUsed);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
float getPositionPercentX()const;
void setPositionPercentX(float percentMargin);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
bool isPositionPercentYEnabled()const;
void setPositionPercentYEnabled(bool isUsed);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
float getPositionPercentY()const;
void setPositionPercentY(float percentMargin);
2014-12-22 11:20:03 +08:00
2014-12-24 10:56:01 +08:00
HorizontalEdge getHorizontalEdge()const;
void setHorizontalEdge(HorizontalEdge hEage);
2014-12-22 11:20:03 +08:00
2014-12-24 10:56:01 +08:00
VerticalEdge getVerticalEdge()const;
void setVerticalEdge(VerticalEdge vEage);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
float getLeftMargin()const;
void setLeftMargin(float margin);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
float getRightMargin()const;
void setRightMargin(float margin);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
float getTopMargin()const;
void setTopMargin(float margin);
2014-12-22 11:20:03 +08:00
2014-12-24 10:56:01 +08:00
float getBottomMargin()const;
void setBottomMargin(float margin);
2014-12-22 11:20:03 +08:00
2014-12-22 18:39:44 +08:00
// Size & Percent
2014-12-23 20:29:53 +08:00
const Size& getSize()const;
void setSize(const Size& size);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
bool isPercentWidthEnabled()const;
void setPercentWidthEnabled(bool isUsed);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
float getSizeWidth()const;
void setSizeWidth(float width);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
float getPercentWidth()const;
void setPercentWidth(float percentWidth);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
bool isPercentHeightEnabled()const;
void setPercentHeightEnabled(bool isUsed);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
float getSizeHeight()const;
void setSizeHeight(float height);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
float getPercentHeight()const;
void setPercentHeight(float percentHeight);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
bool isStretchWidthEnabled()const;
void setStretchWidthEnabled(bool isUsed);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
bool isStretchHeightEnabled()const;
void setStretchHeightEnabled(bool isUsed);
2014-12-22 11:20:03 +08:00
2014-12-23 20:29:53 +08:00
void setActiveEnabled(bool enable);
void refreshLayout();
2014-12-22 11:20:03 +08:00
protected:
Node* getOwnerParent();
2014-12-23 20:29:53 +08:00
void refreshHorizontalMargin();
void refreshVerticalMargin();
2014-12-22 11:20:03 +08:00
protected:
2014-12-24 10:56:01 +08:00
HorizontalEdge _horizontalEdge;
VerticalEdge _verticalEdge;
2014-12-22 11:20:03 +08:00
float _leftMargin;
float _rightMargin;
2014-12-24 10:56:01 +08:00
float _bottomMargin;
2014-12-22 11:20:03 +08:00
float _topMargin;
bool _usingPositionPercentX;
float _positionPercentX;
bool _usingPositionPercentY;
float _positionPercentY;
bool _usingStretchWidth;
bool _usingStretchHeight;
float _percentWidth;
bool _usingPercentWidth;
float _percentHeight;
bool _usingPercentHeight;
2014-12-24 10:56:01 +08:00
bool _actived;
2014-12-22 11:20:03 +08:00
};
2014-10-09 18:28:09 +08:00
}
NS_CC_END
#endif /* defined(__cocos2d_libs__LayoutComponent__) */