axmol/extensions/fairygui/GRoot.h

103 lines
2.7 KiB
C
Raw Normal View History

2020-08-04 12:31:33 +08:00
#ifndef __GROOT_H__
#define __GROOT_H__
#include "FairyGUIMacros.h"
#include "GComponent.h"
#include "GGraph.h"
#include "Window.h"
#include "cocos2d.h"
#include "event/InputProcessor.h"
NS_FGUI_BEGIN
class WeakPtr;
class GRoot : public GComponent
{
public:
GRoot();
virtual ~GRoot();
static GRoot* create(axis::Scene* scene, int zOrder = 1000);
2020-08-04 12:31:33 +08:00
static GRoot* getInstance() { return _inst; }
void showWindow(Window* win);
void hideWindow(Window* win);
void hideWindowImmediately(Window* win);
void bringToFront(Window* win);
void showModalWait();
void closeModalWait();
void closeAllExceptModals();
void closeAllWindows();
Window* getTopWindow();
GObject* getModalWaitingPane();
GGraph* getModalLayer();
bool hasModalWindow();
bool isModalWaiting();
InputProcessor* getInputProcessor() const { return _inputProcessor; }
axis::Vec2 getTouchPosition(int touchId);
2020-08-04 12:31:33 +08:00
GObject* getTouchTarget();
axis::Vec2 worldToRoot(const axis::Vec2 &pt);
axis::Vec2 rootToWorld(const axis::Vec2 &pt);
2020-08-04 12:31:33 +08:00
void showPopup(GObject* popup);
void showPopup(GObject* popup, GObject* target, PopupDirection dir);
void togglePopup(GObject* popup);
void togglePopup(GObject* popup, GObject* target, PopupDirection dir);
void hidePopup();
void hidePopup(GObject* popup);
bool hasAnyPopup();
axis::Vec2 getPoupPosition(GObject* popup, GObject* target, PopupDirection dir);
2020-08-04 12:31:33 +08:00
void showTooltips(const std::string& msg);
void showTooltipsWin(GObject* tooltipWin);
void hideTooltips();
void playSound(const std::string& url, float volumeScale = 1);
bool isSoundEnabled() const { return _soundEnabled; }
void setSoundEnabled(bool value);
float getSoundVolumeScale() const { return _soundVolumeScale; }
void setSoundVolumeScale(float value);
static int contentScaleLevel;
protected:
virtual void handlePositionChanged() override;
virtual void onEnter() override;
virtual void onExit() override;
private:
bool initWithScene(axis::Scene* scene, int zOrder);
2020-08-04 12:31:33 +08:00
void onWindowSizeChanged();
void createModalLayer();
void adjustModalLayer();
void closePopup(GObject* target);
void checkPopups();
void onTouchEvent(int eventType);
void updateContentScaleLevel();
CALL_LATER_FUNC(GRoot, doShowTooltipsWin);
axis::EventListener* _windowSizeListener;
2020-08-04 12:31:33 +08:00
InputProcessor* _inputProcessor;
GGraph* _modalLayer;
GObject* _modalWaitPane;
std::vector<WeakPtr> _popupStack;
std::vector<WeakPtr> _justClosedPopups;
GObject* _tooltipWin;
GObject* _defaultTooltipWin;
static bool _soundEnabled;
static float _soundVolumeScale;
static GRoot* _inst;
};
NS_FGUI_END
#endif