axmol/extensions/fairygui/event/InputProcessor.h

80 lines
2.4 KiB
C
Raw Normal View History

2020-08-04 12:31:33 +08:00
#ifndef __INPUTPROCESSOR_H__
#define __INPUTPROCESSOR_H__
#include "FairyGUIMacros.h"
#include "cocos2d.h"
#include "UIEventDispatcher.h"
#include "InputEvent.h"
NS_FGUI_BEGIN
class GComponent;
class TouchInfo;
class InputProcessor
{
public:
typedef std::function<void(int eventType)> CaptureEventCallback;
InputEvent* getRecentInput() { return &_recentInput; }
static bool isTouchOnUI();
InputProcessor(GComponent* owner);
~InputProcessor();
2022-08-08 18:02:17 +08:00
ax::Vec2 getTouchPosition(int touchId);
2020-08-04 12:31:33 +08:00
void addTouchMonitor(int touchId, GObject* target);
void removeTouchMonitor(GObject* target);
void cancelClick(int touchId);
void simulateClick(GObject* target, int touchId = -1);
void setCaptureCallback(CaptureEventCallback value) { _captureCallback = value; }
void disableDefaultTouchEvent();
2022-08-08 18:02:17 +08:00
bool touchDown(ax::Touch *touch, ax::Event *event);
void touchMove(ax::Touch *touch, ax::Event *event);
void touchUp(ax::Touch *touch, ax::Event *event);
2020-08-04 12:31:33 +08:00
private:
2022-08-08 18:02:17 +08:00
bool onTouchBegan(ax::Touch * touch, ax::Event *);
void onTouchMoved(ax::Touch * touch, ax::Event *);
void onTouchEnded(ax::Touch * touch, ax::Event *);
void onTouchCancelled(ax::Touch * touch, ax::Event *);
2020-08-04 12:31:33 +08:00
2022-08-08 18:02:17 +08:00
void onMouseDown(ax::EventMouse* event);
void onMouseUp(ax::EventMouse* event);
void onMouseMove(ax::EventMouse* event);
void onMouseScroll(ax::EventMouse* event);
2020-08-04 12:31:33 +08:00
2022-08-08 18:02:17 +08:00
void onKeyDown(ax::EventKeyboard::KeyCode keyCode, ax::Event*);
void onKeyUp(ax::EventKeyboard::KeyCode keyCode, ax::Event*);
2020-08-04 12:31:33 +08:00
TouchInfo* getTouch(int touchId, bool createIfNotExisits = true);
void updateRecentInput(TouchInfo* touch, GObject* target);
void handleRollOver(TouchInfo* touch, GObject* target);
void setBegin(TouchInfo* touch, GObject* target);
void setEnd(TouchInfo* touch, GObject* target);
GObject* clickTest(TouchInfo* touch, GObject* target);
2022-08-08 18:02:17 +08:00
ax::EventListenerTouchOneByOne* _touchListener;
ax::EventListenerMouse* _mouseListener;
ax::EventListenerKeyboard* _keyboardListener;
2020-08-04 12:31:33 +08:00
std::vector<TouchInfo*> _touches;
GComponent* _owner;
CaptureEventCallback _captureCallback;
InputEvent _recentInput;
uint16_t _keyModifiers;
static bool _touchOnUI;
static unsigned int _touchOnUIFlagFrameId;
static InputProcessor* _activeProcessor;
friend class UIEventDispatcher;
};
NS_FGUI_END
#endif