/* ----------------------------------------------------------------------------- GSFramework Copyright 2001-2013 Emmanuel Julien. All Rights Reserved. ----------------------------------------------------------------------------- */ #include "input/input_touch.h" #include "nstring/nstring.h" using namespace GS::Input; //------------------------------------------------------------------------------ void TouchDevice::RegisterTouchEvent(float x, float y, float weight) { pending_state.button = asbool(weight > 0); pending_state.x = x; pending_state.y = y; } void TouchDevice::Update() { last_state = state; state = pending_state; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ bool TouchDevice::IsDown(KeyCode key) const { return key == Key_Button0 ? state.button : false; } bool TouchDevice::WasDown(KeyCode key) const { return key == Key_Button0 ? last_state.button : false; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ bool TouchDevice::GetInputRange(InputCode i, float &mn, float &mx) const { switch (i) { case Input_AxisX: case Input_AxisY: mn = 0; mx = 1; return true; case Input_RotX: // Horizontal wheel. case Input_RotY: // Vertical wheel. mn = 0; mx = 1024; return true; default: break; } return false; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ float TouchDevice::GetValue(InputCode i) const { switch (i) { case Input_AxisX: return state.x; case Input_AxisY: return state.y; default: break; } return 0; } float TouchDevice::GetLastValue(InputCode i) const { switch (i) { case Input_AxisX: return last_state.x; case Input_AxisY: return last_state.y; default: break; } return 0; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void TouchDevice::SetIndex(int _index) { index = _index; } Device::Type TouchDevice::GetType() const { return index == -1 ? Type_Mouse : Type_Touch; } const char *TouchDevice::GetName() const { return index == -1 ? "mouse" : GS::String::Format("touch%d", index).c_str(); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ TouchDevice::TouchDevice(int i) : index(i) { state.x = 0; state.y = 0; state.button = false; pending_state = last_state = state; } //------------------------------------------------------------------------------