2014-05-14 18:03:44 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-05-28 10:17:34 +08:00
|
|
|
#ifndef __cocos2d_libs__CCLayoutManager__
|
|
|
|
#define __cocos2d_libs__CCLayoutManager__
|
2014-05-14 18:03:44 +08:00
|
|
|
|
2014-05-15 10:07:42 +08:00
|
|
|
#include "base/CCRef.h"
|
2014-05-20 16:09:30 +08:00
|
|
|
#include "base/CCVector.h"
|
2014-07-21 17:45:56 +08:00
|
|
|
#include "ui/GUIExport.h"
|
2014-05-14 18:03:44 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
namespace ui {
|
2014-05-15 10:07:42 +08:00
|
|
|
|
|
|
|
class LayoutProtocol;
|
2014-05-20 16:09:30 +08:00
|
|
|
class Widget;
|
|
|
|
class RelativeLayoutParameter;
|
2014-05-14 18:03:44 +08:00
|
|
|
|
2014-07-21 17:45:56 +08:00
|
|
|
class CC_GUI_DLL LayoutManager : public Ref
|
2014-05-14 18:03:44 +08:00
|
|
|
{
|
|
|
|
public:
|
2014-05-28 10:11:49 +08:00
|
|
|
virtual ~LayoutManager(){};
|
|
|
|
LayoutManager(){};
|
2014-05-14 18:24:23 +08:00
|
|
|
|
2014-05-15 10:07:42 +08:00
|
|
|
virtual void doLayout(LayoutProtocol *layout) = 0;
|
2014-05-28 10:11:49 +08:00
|
|
|
|
|
|
|
friend class Layout;
|
2014-05-14 18:03:44 +08:00
|
|
|
};
|
|
|
|
|
2014-07-21 17:45:56 +08:00
|
|
|
class CC_GUI_DLL LinearVerticalLayoutManager : public LayoutManager
|
2014-05-14 18:03:44 +08:00
|
|
|
{
|
2014-05-28 10:11:49 +08:00
|
|
|
private:
|
|
|
|
LinearVerticalLayoutManager(){};
|
|
|
|
virtual ~LinearVerticalLayoutManager(){};
|
|
|
|
static LinearVerticalLayoutManager* create();
|
2014-05-15 10:07:42 +08:00
|
|
|
virtual void doLayout(LayoutProtocol *layout) override;
|
2014-05-28 10:11:49 +08:00
|
|
|
|
|
|
|
friend class Layout;
|
2014-05-14 18:03:44 +08:00
|
|
|
};
|
|
|
|
|
2014-07-21 17:45:56 +08:00
|
|
|
class CC_GUI_DLL LinearHorizontalLayoutManager : public LayoutManager
|
2014-05-14 18:03:44 +08:00
|
|
|
{
|
2014-05-28 10:11:49 +08:00
|
|
|
private:
|
|
|
|
LinearHorizontalLayoutManager(){};
|
|
|
|
virtual ~LinearHorizontalLayoutManager(){};
|
|
|
|
static LinearHorizontalLayoutManager* create();
|
2014-05-15 10:07:42 +08:00
|
|
|
virtual void doLayout(LayoutProtocol *layout) override;
|
2014-05-28 10:11:49 +08:00
|
|
|
|
|
|
|
friend class Layout;
|
2014-05-14 18:03:44 +08:00
|
|
|
};
|
|
|
|
|
2014-07-21 17:45:56 +08:00
|
|
|
class CC_GUI_DLL RelativeLayoutManager : public LayoutManager
|
2014-05-14 18:03:44 +08:00
|
|
|
{
|
2014-05-28 10:11:49 +08:00
|
|
|
private:
|
|
|
|
RelativeLayoutManager()
|
2014-05-26 09:51:05 +08:00
|
|
|
:_unlayoutChildCount(0),
|
|
|
|
_widget(nullptr),
|
|
|
|
_finalPositionX(0.0f),
|
|
|
|
_finalPositionY(0.0f),
|
|
|
|
_relativeWidgetLP(nullptr)
|
|
|
|
{}
|
2014-05-28 10:11:49 +08:00
|
|
|
virtual ~RelativeLayoutManager(){};
|
|
|
|
static RelativeLayoutManager* create();
|
2014-05-15 10:07:42 +08:00
|
|
|
virtual void doLayout(LayoutProtocol *layout) override;
|
2014-05-20 16:09:30 +08:00
|
|
|
|
|
|
|
Vector<Widget*> getAllWidgets(LayoutProtocol *layout);
|
|
|
|
Widget* getRelativeWidget(Widget* widget);
|
|
|
|
bool caculateFinalPositionWithRelativeWidget(LayoutProtocol *layout);
|
|
|
|
void caculateFinalPositionWithRelativeAlign();
|
|
|
|
|
2014-05-26 09:51:05 +08:00
|
|
|
ssize_t _unlayoutChildCount;
|
2014-05-20 16:09:30 +08:00
|
|
|
Vector<Widget*> _widgetChildren;
|
2014-05-26 09:51:05 +08:00
|
|
|
Widget* _widget;
|
|
|
|
float _finalPositionX;
|
|
|
|
float _finalPositionY;
|
2014-05-20 16:09:30 +08:00
|
|
|
|
2014-05-26 09:51:05 +08:00
|
|
|
RelativeLayoutParameter* _relativeWidgetLP;
|
2014-05-28 10:11:49 +08:00
|
|
|
|
|
|
|
friend class Layout;
|
2014-05-14 18:24:23 +08:00
|
|
|
};
|
2014-05-14 18:03:44 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|
2014-05-28 10:17:34 +08:00
|
|
|
#endif /* defined(__cocos2d_libs__CCLayoutManager__) */
|