98 lines
2.1 KiB
C++
98 lines
2.1 KiB
C++
//
|
|
// Window and input event handling
|
|
//
|
|
#include "camera.h"
|
|
|
|
typedef enum _InteractionMode {
|
|
MODE_PAN = 0x01,
|
|
MODE_WIDTHLEVEL = 0x02,
|
|
MODE_ZOOM = 0x04,
|
|
MODE_SCROLL = 0x08,
|
|
}InteractionMode;
|
|
|
|
|
|
class EventHandler
|
|
{
|
|
public:
|
|
EventHandler(const char* windowTitle);
|
|
|
|
void processEvents();
|
|
Camera& camera() { return mCamera; }
|
|
void swapWindow();
|
|
|
|
int GetEventType();
|
|
|
|
float GetDeltaX();
|
|
float GetDeltaY();
|
|
|
|
SDL_Renderer* GetRenderer();
|
|
|
|
void SetInteractionMode(int mode);
|
|
|
|
void SetMouseButtonDownPosition(int x, int y);
|
|
void SetMouseButtonUpPosition(int x, int y);
|
|
|
|
|
|
public:
|
|
float m_fDeltaX;
|
|
float m_fDeltaY;
|
|
int m_nEventType;
|
|
int m_InteractionMode;
|
|
// Camera
|
|
Camera mCamera;
|
|
|
|
SDL_Renderer* m_pRenderer;
|
|
// Window
|
|
SDL_Window* mpWindow;
|
|
Uint32 mWindowID;
|
|
void windowResizeEvent(int width, int height);
|
|
void initWindow(const char* title);
|
|
|
|
// Mouse input
|
|
const float cMouseWheelZoomDelta;
|
|
bool mMouseButtonDown;
|
|
int mMouseButtonDownX, mMouseButtonDownY;
|
|
int mMousePositionX, mMousePositionY;
|
|
|
|
// Finger input
|
|
bool mFingerDown;
|
|
float mFingerDownX, mFingerDownY;
|
|
long long mFingerDownId;
|
|
|
|
// Pinch input
|
|
const float cPinchZoomThreshold, cPinchScale;
|
|
bool mPinch;
|
|
|
|
void zoom(float fDelta);
|
|
|
|
// Events
|
|
void zoomEventMouse(bool mouseWheelDown, int x, int y);
|
|
void zoomEventPinch (float pinchDist, float pinchX, float pinchY);
|
|
void panEventMouse(int x, int y);
|
|
void panEventFinger(float x, float y);
|
|
};
|
|
|
|
inline EventHandler::EventHandler(const char* windowTitle)
|
|
// Window
|
|
: mpWindow (nullptr)
|
|
, mWindowID (0)
|
|
|
|
// Mouse input
|
|
, cMouseWheelZoomDelta (0.05f)
|
|
, mMouseButtonDown (false)
|
|
, mMouseButtonDownX (0), mMouseButtonDownY (0)
|
|
, mMousePositionX (0), mMousePositionY (0)
|
|
|
|
// Finger input
|
|
, mFingerDown (false)
|
|
, mFingerDownX (0.0f), mFingerDownY (0.0f)
|
|
, mFingerDownId (0)
|
|
|
|
// Pinch input
|
|
, cPinchZoomThreshold (0.001f)
|
|
, cPinchScale (8.0f)
|
|
, mPinch (false)
|
|
{
|
|
initWindow(windowTitle);
|
|
}
|