2013-09-13 22:20:20 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
|
|
|
|
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 __UILAYER_H__
|
|
|
|
#define __UILAYER_H__
|
|
|
|
|
|
|
|
#include "cocos2d.h"
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "gui/UIRootWidget.h"
|
|
|
|
#include "gui/UIInputManager.h"
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
namespace gui {
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
class UILayer : public cocos2d::Layer
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor
|
2013-11-20 12:04:47 +08:00
|
|
|
* @js ctor
|
2013-09-13 22:20:20 +08:00
|
|
|
*/
|
|
|
|
UILayer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default destructor
|
2013-11-20 12:04:47 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2013-09-13 22:20:20 +08:00
|
|
|
*/
|
|
|
|
virtual ~UILayer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates and initializes a widget.
|
|
|
|
*/
|
|
|
|
static UILayer *create(void);
|
|
|
|
|
|
|
|
//initializes state of uilayer.
|
2013-11-14 13:42:10 +08:00
|
|
|
virtual bool init() override;
|
2013-11-20 12:04:47 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-11-14 13:42:10 +08:00
|
|
|
virtual void onEnter() override;
|
2013-11-20 12:04:47 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-11-14 13:42:10 +08:00
|
|
|
virtual void onExit() override;
|
|
|
|
virtual void onEnterTransitionDidFinish() override;
|
2013-11-20 12:04:47 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual bool onTouchBegan(cocos2d::Touch *pTouch, cocos2d::Event *pEvent);
|
2013-11-20 12:04:47 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void onTouchMoved(cocos2d::Touch *pTouch, cocos2d::Event *pEvent);
|
2013-11-20 12:04:47 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void onTouchEnded(cocos2d::Touch *pTouch, cocos2d::Event *pEvent);
|
2013-11-20 12:04:47 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void onTouchCancelled(cocos2d::Touch *pTouch, cocos2d::Event *pEvent);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a widget to UILayer, for drawing.
|
|
|
|
*
|
|
|
|
* @param widget.
|
|
|
|
*/
|
|
|
|
void addWidget(UIWidget* widget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a widget from UILayer.
|
|
|
|
*
|
|
|
|
* @param widget.
|
|
|
|
*
|
|
|
|
* @param cleanup true if all running actions on all children widgets should be cleanup, false otherwise.
|
|
|
|
*/
|
|
|
|
void removeWidget(UIWidget* widget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the UILayer is visible
|
|
|
|
*
|
|
|
|
* The default value is true, a UILayer is default to visible
|
|
|
|
*
|
|
|
|
* @param visible true if the UILayer is visible, false if the UILayer is hidden.
|
|
|
|
*/
|
2013-11-14 13:42:10 +08:00
|
|
|
virtual void setVisible(bool visible) override;
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds a widget whose tag is equal tag param from widget tree.
|
|
|
|
*
|
|
|
|
* @param tag.
|
|
|
|
*/
|
|
|
|
UIWidget* getWidgetByTag(int tag);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Seek a widget whose name is equal name param from widget tree.
|
|
|
|
*
|
|
|
|
* @param name.
|
|
|
|
*/
|
|
|
|
UIWidget* getWidgetByName(const char* name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets UIInputManager.
|
|
|
|
*
|
|
|
|
* UIInputManager is the touch manager of UILayer.
|
|
|
|
*
|
|
|
|
* @return UIInputManager.
|
2013-11-20 12:04:47 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2013-09-13 22:20:20 +08:00
|
|
|
*/
|
|
|
|
UIInputManager* getInputManager();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove and clean up all of UILayer's widget.
|
|
|
|
*/
|
|
|
|
virtual void clear();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets root widget of UILayer.
|
|
|
|
*
|
|
|
|
* @return UIRootWidget, "UIRootWidget" is the root widget of UILayer.
|
|
|
|
*/
|
|
|
|
UIRootWidget* getRootWidget();
|
|
|
|
|
|
|
|
protected:
|
2013-09-16 20:54:13 +08:00
|
|
|
UIRootWidget* _rootWidget;
|
|
|
|
UIInputManager* _inputManager;
|
2013-09-13 22:20:20 +08:00
|
|
|
};
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* defined(__UILAYER_H__) */
|