Touchscreen improvements

This commit is contained in:
elasota
2020-10-14 18:12:02 -04:00
parent 62e234c777
commit e4cddda183
10 changed files with 249 additions and 45 deletions

View File

@@ -207,7 +207,7 @@ bool GpSystemServices_Android::IsTouchscreen() const
bool GpSystemServices_Android::IsUsingMouseAsTouch() const bool GpSystemServices_Android::IsUsingMouseAsTouch() const
{ {
return true; return false;
} }
bool GpSystemServices_Android::IsTextInputObstructive() const bool GpSystemServices_Android::IsTextInputObstructive() const

View File

@@ -704,7 +704,7 @@ public:
bool Init(); bool Init();
static void TranslateSDLMessage(const SDL_Event *msg, IGpVOSEventQueue *eventQueue, float pixelScaleX, float pixelScaleY, bool obstructiveTextInput); void TranslateSDLMessage(const SDL_Event *msg, IGpVOSEventQueue *eventQueue, float pixelScaleX, float pixelScaleY, bool obstructiveTextInput);
void Run() override; void Run() override;
void Shutdown() override; void Shutdown() override;
@@ -1100,6 +1100,9 @@ GpDisplayDriver_SDL_GL2::GpDisplayDriver_SDL_GL2(const GpDisplayDriverProperties
m_bgColor[2] = 0.f; m_bgColor[2] = 0.f;
m_bgColor[3] = 1.f; m_bgColor[3] = 1.f;
// Stupid hack to detect mobile...
m_isFullScreenDesired = m_properties.m_systemServices->IsTouchscreen();
const intmax_t periodNum = std::chrono::high_resolution_clock::period::num; const intmax_t periodNum = std::chrono::high_resolution_clock::period::num;
const intmax_t periodDen = std::chrono::high_resolution_clock::period::den; const intmax_t periodDen = std::chrono::high_resolution_clock::period::den;
@@ -1207,7 +1210,6 @@ bool GpDisplayDriver_SDL_GL2::Init()
return true; return true;
} }
static void PostMouseEvent(IGpVOSEventQueue *eventQueue, GpMouseEventType_t eventType, GpMouseButton_t button, int32_t x, int32_t y, float pixelScaleX, float pixelScaleY) static void PostMouseEvent(IGpVOSEventQueue *eventQueue, GpMouseEventType_t eventType, GpMouseButton_t button, int32_t x, int32_t y, float pixelScaleX, float pixelScaleY)
{ {
if (GpVOSEvent *evt = eventQueue->QueueEvent()) if (GpVOSEvent *evt = eventQueue->QueueEvent())
@@ -1228,6 +1230,21 @@ static void PostMouseEvent(IGpVOSEventQueue *eventQueue, GpMouseEventType_t even
} }
} }
static void PostTouchEvent(IGpVOSEventQueue *eventQueue, GpTouchEventType_t eventType, int32_t x, int32_t y, int64_t deviceID, int64_t fingerID)
{
if (GpVOSEvent *evt = eventQueue->QueueEvent())
{
evt->m_eventType = GpVOSEventTypes::kTouchInput;
GpTouchInputEvent &tEvent = evt->m_event.m_touchInputEvent;
tEvent.m_deviceID = deviceID;
tEvent.m_fingerID = fingerID;
tEvent.m_x = x;
tEvent.m_y = y;
tEvent.m_eventType = eventType;
}
}
static bool IdentifyVKey(const SDL_KeyboardEvent *keyEvt, GpKeyIDSubset_t &outSubset, GpKeyboardInputEvent::KeyUnion &outKey) static bool IdentifyVKey(const SDL_KeyboardEvent *keyEvt, GpKeyIDSubset_t &outSubset, GpKeyboardInputEvent::KeyUnion &outKey)
{ {
SDL_KeyCode keyCode = static_cast<SDL_KeyCode>(keyEvt->keysym.sym); SDL_KeyCode keyCode = static_cast<SDL_KeyCode>(keyEvt->keysym.sym);
@@ -1555,7 +1572,6 @@ void GpDisplayDriver_SDL_GL2::TranslateSDLMessage(const SDL_Event *msg, IGpVOSEv
PostMouseEvent(eventQueue, GpMouseEventTypes::kMove, GpMouseButtons::kNone, mouseEvt->x, mouseEvt->y, pixelScaleX, pixelScaleY); PostMouseEvent(eventQueue, GpMouseEventTypes::kMove, GpMouseButtons::kNone, mouseEvt->x, mouseEvt->y, pixelScaleX, pixelScaleY);
} }
break; break;
break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
{ {
@@ -1586,6 +1602,28 @@ void GpDisplayDriver_SDL_GL2::TranslateSDLMessage(const SDL_Event *msg, IGpVOSEv
PostMouseEvent(eventQueue, evtType, mouseButton, mouseEvt->x, mouseEvt->y, pixelScaleX, pixelScaleY); PostMouseEvent(eventQueue, evtType, mouseButton, mouseEvt->x, mouseEvt->y, pixelScaleX, pixelScaleY);
} }
break; break;
case SDL_FINGERUP:
case SDL_FINGERDOWN:
case SDL_FINGERMOTION:
{
const SDL_TouchFingerEvent *fingerEvt = reinterpret_cast<const SDL_TouchFingerEvent *>(msg);
GpTouchEventType_t evtType = GpTouchEventTypes::kDown;
if (fingerEvt->type == SDL_FINGERUP)
evtType = GpTouchEventTypes::kUp;
else if (fingerEvt->type == SDL_FINGERDOWN)
evtType = GpTouchEventTypes::kDown;
else if (fingerEvt->type == SDL_FINGERMOTION)
evtType = GpTouchEventTypes::kMove;
else
break;
float unnormalizedX = static_cast<float>(m_windowWidthVirtual) * fingerEvt->x;
float unnormalizedY = static_cast<float>(m_windowHeightVirtual) * fingerEvt->y;
PostTouchEvent(eventQueue, evtType, static_cast<int32_t>(unnormalizedX), static_cast<int32_t>(unnormalizedY), fingerEvt->touchId, fingerEvt->fingerId);
}
break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
{ {
const SDL_KeyboardEvent *keyEvt = reinterpret_cast<const SDL_KeyboardEvent *>(msg); const SDL_KeyboardEvent *keyEvt = reinterpret_cast<const SDL_KeyboardEvent *>(msg);

View File

@@ -366,25 +366,59 @@ namespace TouchScreenCtrlIDs
{ {
enum TouchScreenCtrlID enum TouchScreenCtrlID
{ {
None,
MoveLeft,
MoveRight,
Flip, Flip,
Bands, Bands,
BatteryHelium, BatteryHelium,
Movement,
Count, Count,
Invalid,
}; };
}; };
typedef TouchScreenCtrlIDs::TouchScreenCtrlID TouchScreenCtrlID_t; typedef TouchScreenCtrlIDs::TouchScreenCtrlID TouchScreenCtrlID_t;
struct touchScreenFingerID
{
int64_t m_deviceID;
int64_t m_fingerID;
touchScreenFingerID();
touchScreenFingerID(int64_t deviceID, int64_t fingerID);
bool operator ==(const touchScreenFingerID &other) const;
bool operator !=(const touchScreenFingerID &other) const;
};
inline touchScreenFingerID::touchScreenFingerID()
: m_fingerID(0)
, m_deviceID(0)
{
}
inline touchScreenFingerID::touchScreenFingerID(int64_t deviceID, int64_t fingerID)
: m_fingerID(fingerID)
, m_deviceID(deviceID)
{
}
inline bool touchScreenFingerID::operator==(const touchScreenFingerID &other) const
{
return this->m_fingerID == other.m_fingerID && this->m_deviceID == other.m_deviceID;
}
inline bool touchScreenFingerID::operator!=(const touchScreenFingerID &other) const
{
return !((*this) == other);
}
typedef struct typedef struct
{ {
int fingerID; touchScreenFingerID tfingerID;
Point point; Point point;
TouchScreenCtrlID_t capturingControl; TouchScreenCtrlID_t capturingControl;
bool active;
} touchScreenFingerState; } touchScreenFingerState;
typedef struct typedef struct

View File

@@ -8,6 +8,7 @@
#include "PLDialogs.h" #include "PLDialogs.h"
#include "PLKeyEncoding.h" #include "PLKeyEncoding.h"
#include "DialogManager.h" #include "DialogManager.h"
#include "Environ.h"
#include "Externs.h" #include "Externs.h"
#include "InputManager.h" #include "InputManager.h"
#include "MainWindow.h" #include "MainWindow.h"
@@ -39,6 +40,8 @@ Boolean isEscPauseKey, paused, batteryWasEngaged;
extern long gameFrame; extern long gameFrame;
extern short otherPlayerEscaped; extern short otherPlayerEscaped;
extern Boolean quitting, playing, onePlayerLeft, twoPlayerGame, demoGoing; extern Boolean quitting, playing, onePlayerLeft, twoPlayerGame, demoGoing;
extern touchScreenControlState touchScreen;
extern macEnviron thisMac;
//============================================================== Functions //============================================================== Functions
@@ -320,6 +323,8 @@ void GetInput (gliderPtr thisGlider)
bool holdFlipState = false; bool holdFlipState = false;
bool leftState = false; bool leftState = false;
bool rightState = false; bool rightState = false;
bool bandsState = false;
bool batteryState = false;
const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys();
@@ -337,6 +342,56 @@ void GetInput (gliderPtr thisGlider)
else else
thisGlider->tipped = false; thisGlider->tipped = false;
if (thisMac.isTouchscreen)
{
for (int fi = 0; fi < touchScreenControlState::kMaxFingers; fi++)
{
const touchScreenFingerState &fstate = touchScreen.fingers[fi];
if (!fstate.active)
continue;
const Point touchScreenPoint = touchScreen.fingers[fi].point;
if (!touchScreen.controls[fstate.capturingControl].touchRect.Contains(touchScreenPoint))
continue;
switch (fstate.capturingControl)
{
case TouchScreenCtrlIDs::Movement:
{
int32_t screenWidth = mainWindowRect.Width();
const bool touchLeftState = (touchScreenPoint.h * 2 <= screenWidth);
const bool touchRightState = (touchScreenPoint.h * 2 - screenWidth >= 0);
if (touchLeftState)
{
if (touchRightState)
continuousFlipState = true;
else
leftState = true;
}
else
{
if (touchRightState)
rightState = true;
}
}
break;
case TouchScreenCtrlIDs::Flip:
holdFlipState = true;
break;
case TouchScreenCtrlIDs::Bands:
bandsState = true;
break;
case TouchScreenCtrlIDs::BatteryHelium:
batteryState = true;
break;
default:
break;
}
}
}
if (theKeys->IsSet(thisGlider->gamepadRightKey)) if (theKeys->IsSet(thisGlider->gamepadRightKey))
rightState = true; rightState = true;
@@ -407,7 +462,7 @@ void GetInput (gliderPtr thisGlider)
if (!leftState && !rightState) if (!leftState && !rightState)
thisGlider->tipped = false; thisGlider->tipped = false;
if ((theKeys->IsSet(thisGlider->battKey) || theKeys->IsSet(thisGlider->gamepadBattKey)) && (batteryTotal != 0) && if ((theKeys->IsSet(thisGlider->battKey) || theKeys->IsSet(thisGlider->gamepadBattKey) || batteryState) && (batteryTotal != 0) &&
(thisGlider->mode == kGliderNormal)) (thisGlider->mode == kGliderNormal))
{ {
#ifdef CREATEDEMODATA #ifdef CREATEDEMODATA
@@ -421,7 +476,7 @@ void GetInput (gliderPtr thisGlider)
else else
batteryWasEngaged = false; batteryWasEngaged = false;
if ((theKeys->IsSet(thisGlider->bandKey) || theKeys->IsSet(thisGlider->gamepadBandKey)) && (bandsTotal > 0) && if ((theKeys->IsSet(thisGlider->bandKey) || theKeys->IsSet(thisGlider->gamepadBandKey) || bandsState) && (bandsTotal > 0) &&
(thisGlider->mode == kGliderNormal)) (thisGlider->mode == kGliderNormal))
{ {
#ifdef CREATEDEMODATA #ifdef CREATEDEMODATA

View File

@@ -390,14 +390,16 @@ void HandleGameResolutionChange(void)
//-------------------------------------------------------------- HandleTouchUp //-------------------------------------------------------------- HandleTouchUp
void HandleTouchUp(int fingerID) void HandleTouchUp(touchScreenFingerID fingerID)
{ {
for (int i = 0; i < touchScreenControlState::kMaxFingers; i++) for (int i = 0; i < touchScreenControlState::kMaxFingers; i++)
{ {
if (touchScreen.fingers[i].fingerID == fingerID) touchScreenFingerState &fstate = touchScreen.fingers[i];
if (fstate.active && fstate.tfingerID == fingerID)
{ {
touchScreen.fingers[i].fingerID = -1; fstate.active = false;
touchScreen.fingers[i].capturingControl = TouchScreenCtrlIDs::None; fstate.tfingerID = touchScreenFingerID();
fstate.capturingControl = TouchScreenCtrlIDs::Invalid;
return; return;
} }
} }
@@ -405,13 +407,15 @@ void HandleTouchUp(int fingerID)
//-------------------------------------------------------------- HandleTouchMove //-------------------------------------------------------------- HandleTouchMove
void HandleTouchMove(int fingerID, const Point &pt) void HandleTouchMove(touchScreenFingerID fingerID, const Point &pt)
{ {
for (int i = 0; i < touchScreenControlState::kMaxFingers; i++) for (int i = 0; i < touchScreenControlState::kMaxFingers; i++)
{ {
if (touchScreen.fingers[i].fingerID == fingerID) touchScreenFingerState &fstate = touchScreen.fingers[i];
if (fstate.active && fstate.tfingerID == fingerID)
{ {
touchScreen.fingers[i].point = pt; fstate.point = pt;
return; return;
} }
} }
@@ -419,19 +423,21 @@ void HandleTouchMove(int fingerID, const Point &pt)
//-------------------------------------------------------------- HandleTouchDown //-------------------------------------------------------------- HandleTouchDown
void HandleTouchDown(int fingerID, const Point &pt) void HandleTouchDown(touchScreenFingerID fingerID, const Point &pt)
{ {
int freeFingerIndex = -1; int freeFingerIndex = -1;
for (int i = 0; i < touchScreenControlState::kMaxFingers; i++) for (int i = 0; i < touchScreenControlState::kMaxFingers; i++)
{ {
if (touchScreen.fingers[i].fingerID == fingerID) touchScreenFingerState &fstate = touchScreen.fingers[i];
if (fstate.active && fstate.tfingerID == fingerID)
{ {
// Finger is already considered down, something weird happened // Finger is already considered down, something weird happened
HandleTouchMove(fingerID, pt); HandleTouchMove(fingerID, pt);
return; return;
} }
else if (touchScreen.fingers[i].fingerID < 0) else if (!fstate.active)
freeFingerIndex = i; freeFingerIndex = i;
} }
@@ -446,7 +452,8 @@ void HandleTouchDown(int fingerID, const Point &pt)
{ {
if (touchScreen.controls[j].touchRect.Contains(pt)) if (touchScreen.controls[j].touchRect.Contains(pt))
{ {
fingerState.fingerID = fingerID; fingerState.tfingerID = fingerID;
fingerState.active = true;
fingerState.capturingControl = static_cast<TouchScreenCtrlID_t>(j); fingerState.capturingControl = static_cast<TouchScreenCtrlID_t>(j);
fingerState.point = pt; fingerState.point = pt;
return; return;
@@ -458,14 +465,17 @@ void HandleTouchDown(int fingerID, const Point &pt)
//-------------------------------------------------------------- HandleTouchLeave //-------------------------------------------------------------- HandleTouchLeave
void HandleTouchLeave(int fingerID) void HandleTouchLeave(touchScreenFingerID fingerID)
{ {
for (int i = 0; i < touchScreenControlState::kMaxFingers; i++) for (int i = 0; i < touchScreenControlState::kMaxFingers; i++)
{ {
if (touchScreen.fingers[i].fingerID == fingerID) touchScreenFingerState &fstate = touchScreen.fingers[i];
if (fstate.active && fstate.tfingerID == fingerID)
{ {
touchScreen.fingers[i].fingerID = -1; fstate.tfingerID = touchScreenFingerID();
touchScreen.fingers[i].capturingControl = TouchScreenCtrlIDs::None; fstate.active = false;
fstate.capturingControl = TouchScreenCtrlIDs::Invalid;
return; return;
} }
} }
@@ -492,17 +502,43 @@ void HandleInGameEvents(void)
{ {
case GpMouseEventTypes::kDown: case GpMouseEventTypes::kDown:
if (mouseInput.m_button == GpMouseButtons::kLeft) if (mouseInput.m_button == GpMouseButtons::kLeft)
HandleTouchDown(0, mousePt); HandleTouchDown(touchScreenFingerID(), mousePt);
break; break;
case GpMouseEventTypes::kLeave: case GpMouseEventTypes::kLeave:
HandleTouchLeave(0); HandleTouchLeave(touchScreenFingerID());
break; break;
case GpMouseEventTypes::kUp: case GpMouseEventTypes::kUp:
HandleTouchMove(0, mousePt); HandleTouchMove(touchScreenFingerID(), mousePt);
HandleTouchUp(0); HandleTouchUp(touchScreenFingerID());
break; break;
case GpMouseEventTypes::kMove: case GpMouseEventTypes::kMove:
HandleTouchMove(0, mousePt); HandleTouchMove(touchScreenFingerID(), mousePt);
break;
default:
break;
};
}
if (!thisMac.isMouseTouchscreen && evt.m_vosEvent.m_eventType == GpVOSEventTypes::kTouchInput)
{
const GpTouchInputEvent &touchInput = evt.m_vosEvent.m_event.m_touchInputEvent;
const Point touchPt = mainWindow->TouchToLocal(touchInput);
switch (touchInput.m_eventType)
{
case GpTouchEventTypes::kDown:
HandleTouchDown(touchScreenFingerID(touchInput.m_deviceID, touchInput.m_fingerID), touchPt);
break;
case GpTouchEventTypes::kLeave:
HandleTouchLeave(touchScreenFingerID(touchInput.m_deviceID, touchInput.m_fingerID));
break;
case GpTouchEventTypes::kUp:
HandleTouchMove(touchScreenFingerID(touchInput.m_deviceID, touchInput.m_fingerID), touchPt);
HandleTouchUp(touchScreenFingerID(touchInput.m_deviceID, touchInput.m_fingerID));
break;
case GpTouchEventTypes::kMove:
HandleTouchMove(touchScreenFingerID(), touchPt);
break; break;
default: default:
break; break;
@@ -530,9 +566,7 @@ void ResetTouchScreenControlBounds (void)
Point points[TouchScreenCtrlIDs::Count]; Point points[TouchScreenCtrlIDs::Count];
Point sizes[TouchScreenCtrlIDs::Count]; Point sizes[TouchScreenCtrlIDs::Count];
points[TouchScreenCtrlIDs::MoveLeft] = Point::Create(mainWindowRect.left + touchScreenControlEdgeSpacing, mainWindowRect.bottom - touchScreenControlEdgeSpacing - touchScreenControlSize); points[TouchScreenCtrlIDs::Movement] = Point::Create(mainWindowRect.left, mainWindowRect.top);
points[TouchScreenCtrlIDs::MoveRight] = points[TouchScreenCtrlIDs::MoveLeft] + Point::Create(touchScreenControlInterSpacing + touchScreenControlSize, 0);
points[TouchScreenCtrlIDs::BatteryHelium] = Point::Create(mainWindowRect.right - touchScreenControlEdgeSpacing - touchScreenControlSize, mainWindowRect.bottom - touchScreenControlEdgeSpacing - touchScreenControlSize); points[TouchScreenCtrlIDs::BatteryHelium] = Point::Create(mainWindowRect.right - touchScreenControlEdgeSpacing - touchScreenControlSize, mainWindowRect.bottom - touchScreenControlEdgeSpacing - touchScreenControlSize);
points[TouchScreenCtrlIDs::Flip] = points[TouchScreenCtrlIDs::BatteryHelium] + Point::Create(0, -touchScreenControlInterSpacing - touchScreenControlSize); points[TouchScreenCtrlIDs::Flip] = points[TouchScreenCtrlIDs::BatteryHelium] + Point::Create(0, -touchScreenControlInterSpacing - touchScreenControlSize);
points[TouchScreenCtrlIDs::Bands] = points[TouchScreenCtrlIDs::BatteryHelium] + Point::Create(-touchScreenControlInterSpacing - touchScreenControlSize, 0); points[TouchScreenCtrlIDs::Bands] = points[TouchScreenCtrlIDs::BatteryHelium] + Point::Create(-touchScreenControlInterSpacing - touchScreenControlSize, 0);
@@ -540,6 +574,8 @@ void ResetTouchScreenControlBounds (void)
for (int i = 0; i < TouchScreenCtrlIDs::Count; i++) for (int i = 0; i < TouchScreenCtrlIDs::Count; i++)
sizes[i] = Point::Create(touchScreenControlSize, touchScreenControlSize); sizes[i] = Point::Create(touchScreenControlSize, touchScreenControlSize);
sizes[TouchScreenCtrlIDs::Movement] = Point::Create(mainWindowRect.Width(), mainWindowRect.Height());
for (int i = 0; i < TouchScreenCtrlIDs::Count; i++) for (int i = 0; i < TouchScreenCtrlIDs::Count; i++)
{ {
Point lowerRight = points[i] + sizes[i]; Point lowerRight = points[i] + sizes[i];
@@ -550,8 +586,9 @@ void ResetTouchScreenControlBounds (void)
// Clear all active touches // Clear all active touches
for (int i = 0; i < touchScreenControlState::kMaxFingers; i++) for (int i = 0; i < touchScreenControlState::kMaxFingers; i++)
{ {
touchScreen.fingers[i].fingerID = -1; touchScreen.fingers[i].tfingerID = touchScreenFingerID();
touchScreen.fingers[i].capturingControl = TouchScreenCtrlIDs::None; touchScreen.fingers[i].active = false;
touchScreen.fingers[i].capturingControl = TouchScreenCtrlIDs::Invalid;
} }
} }
@@ -581,10 +618,13 @@ void InitTouchScreenControlState(void)
void PlayGame (void) void PlayGame (void)
{ {
const houseType *debugHouse = nullptr;
if (thisHouse)
debugHouse = *thisHouse;
InitTouchScreenControlState(); InitTouchScreenControlState();
touchScreen.controls[TouchScreenCtrlIDs::MoveLeft].isEnabled = true; touchScreen.controls[TouchScreenCtrlIDs::Movement].isEnabled = true;
touchScreen.controls[TouchScreenCtrlIDs::MoveRight].isEnabled = true;
touchScreen.controls[TouchScreenCtrlIDs::Flip].isEnabled = true; touchScreen.controls[TouchScreenCtrlIDs::Flip].isEnabled = true;
touchScreen.controls[TouchScreenCtrlIDs::Bands].isEnabled = true; touchScreen.controls[TouchScreenCtrlIDs::Bands].isEnabled = true;
touchScreen.controls[TouchScreenCtrlIDs::BatteryHelium].isEnabled = true; touchScreen.controls[TouchScreenCtrlIDs::BatteryHelium].isEnabled = true;

View File

@@ -615,8 +615,7 @@ void RenderTouchScreenControls (void)
for (int i = 0; i < TouchScreenCtrlIDs::Count; i++) for (int i = 0; i < TouchScreenCtrlIDs::Count; i++)
ctrlGraphics[i] = nullptr; ctrlGraphics[i] = nullptr;
ctrlGraphics[TouchScreenCtrlIDs::MoveLeft] = touchScreen.graphics[touchScreenControlGraphics::MoveLeftIdle]; ctrlGraphics[TouchScreenCtrlIDs::Movement] = nullptr;
ctrlGraphics[TouchScreenCtrlIDs::MoveRight] = touchScreen.graphics[touchScreenControlGraphics::MoveRightIdle];
ctrlGraphics[TouchScreenCtrlIDs::Flip] = touchScreen.graphics[touchScreenControlGraphics::FlipIdle]; ctrlGraphics[TouchScreenCtrlIDs::Flip] = touchScreen.graphics[touchScreenControlGraphics::FlipIdle];
ctrlGraphics[TouchScreenCtrlIDs::Bands] = touchScreen.graphics[touchScreenControlGraphics::BandsDisabled]; ctrlGraphics[TouchScreenCtrlIDs::Bands] = touchScreen.graphics[touchScreenControlGraphics::BandsDisabled];
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::BatteryDisabled]; ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::BatteryDisabled];
@@ -636,7 +635,7 @@ void RenderTouchScreenControls (void)
if (batteryTotal < 0) if (batteryTotal < 0)
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::HeliumActive]; ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::HeliumActive];
else if (batteryTotal > 0) else if (batteryTotal > 0)
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::BandsActive]; ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::BatteryActive];
} }
else if (touchScreen.fingers[i].capturingControl == TouchScreenCtrlIDs::Bands) else if (touchScreen.fingers[i].capturingControl == TouchScreenCtrlIDs::Bands)
{ {
@@ -645,10 +644,6 @@ void RenderTouchScreenControls (void)
} }
else if (touchScreen.fingers[i].capturingControl == TouchScreenCtrlIDs::Flip) else if (touchScreen.fingers[i].capturingControl == TouchScreenCtrlIDs::Flip)
ctrlGraphics[TouchScreenCtrlIDs::Flip] = touchScreen.graphics[touchScreenControlGraphics::FlipActive]; ctrlGraphics[TouchScreenCtrlIDs::Flip] = touchScreen.graphics[touchScreenControlGraphics::FlipActive];
else if (touchScreen.fingers[i].capturingControl == TouchScreenCtrlIDs::MoveLeft)
ctrlGraphics[TouchScreenCtrlIDs::MoveLeft] = touchScreen.graphics[touchScreenControlGraphics::MoveLeftActive];
else if (touchScreen.fingers[i].capturingControl == TouchScreenCtrlIDs::MoveRight)
ctrlGraphics[TouchScreenCtrlIDs::MoveRight] = touchScreen.graphics[touchScreenControlGraphics::MoveRightActive];
} }
for (int i = 0; i < TouchScreenCtrlIDs::Count; i++) for (int i = 0; i < TouchScreenCtrlIDs::Count; i++)

View File

@@ -237,6 +237,29 @@ struct GpMouseInputEvent
GpMouseButton_t m_button; GpMouseButton_t m_button;
}; };
namespace GpTouchEventTypes
{
enum GpTouchEventType
{
kUp,
kDown,
kMove,
kLeave,
};
}
typedef GpTouchEventTypes::GpTouchEventType GpTouchEventType_t;
struct GpTouchInputEvent
{
int32_t m_x;
int32_t m_y;
int64_t m_deviceID;
int64_t m_fingerID;
GpTouchEventType_t m_eventType;
};
struct GpVideoResolutionChangedEvent struct GpVideoResolutionChangedEvent
{ {
uint32_t m_prevWidth; uint32_t m_prevWidth;
@@ -251,6 +274,7 @@ namespace GpVOSEventTypes
{ {
kKeyboardInput, kKeyboardInput,
kMouseInput, kMouseInput,
kTouchInput,
kGamepadInput, kGamepadInput,
kVideoResolutionChanged, kVideoResolutionChanged,
kQuit kQuit
@@ -265,6 +289,7 @@ struct GpVOSEvent
{ {
GpKeyboardInputEvent m_keyboardInputEvent; GpKeyboardInputEvent m_keyboardInputEvent;
GpMouseInputEvent m_mouseInputEvent; GpMouseInputEvent m_mouseInputEvent;
GpTouchInputEvent m_touchInputEvent;
GpGamepadInputEvent m_gamepadInputEvent; GpGamepadInputEvent m_gamepadInputEvent;
GpVideoResolutionChangedEvent m_resolutionChangedEvent; GpVideoResolutionChangedEvent m_resolutionChangedEvent;
}; };

View File

@@ -679,6 +679,11 @@ DrawSurface *Window::GetDrawSurface() const
return const_cast<DrawSurface*>(&m_surface); return const_cast<DrawSurface*>(&m_surface);
} }
Point Window::TouchToLocal(const GpTouchInputEvent &evt) const
{
return Point::Create(evt.m_x - m_wmX, evt.m_y - m_wmY);
}
Point Window::MouseToLocal(const GpMouseInputEvent &evt) const Point Window::MouseToLocal(const GpMouseInputEvent &evt) const
{ {
return Point::Create(evt.m_x - m_wmX, evt.m_y - m_wmY); return Point::Create(evt.m_x - m_wmX, evt.m_y - m_wmY);

View File

@@ -19,6 +19,7 @@ struct IGpCursor;
class GpIOStream; class GpIOStream;
struct GpVOSEvent; struct GpVOSEvent;
struct GpMouseInputEvent; struct GpMouseInputEvent;
struct GpTouchInputEvent;
struct TimeTaggedVOSEvent; struct TimeTaggedVOSEvent;
@@ -95,6 +96,8 @@ struct Window
// Convenience method to convert a mouse event to local point // Convenience method to convert a mouse event to local point
Point MouseToLocal(const GpMouseInputEvent &evt) const; Point MouseToLocal(const GpMouseInputEvent &evt) const;
Point TouchToLocal(const GpTouchInputEvent &evt) const;
// Convenience method that returns a 16-bit precision X/Y // Convenience method that returns a 16-bit precision X/Y
Point GetTopLeftCoord() const; Point GetTopLeftCoord() const;

View File

@@ -42,6 +42,12 @@ static void TranslateMouseInputEvent(const GpVOSEvent &vosEventBase, uint32_t ti
inputManager->ApplyMouseEvent(vosEvent); inputManager->ApplyMouseEvent(vosEvent);
} }
static void TranslateTouchInputEvent(const GpVOSEvent &vosEventBase, uint32_t timestamp, PortabilityLayer::EventQueue *queue)
{
if (TimeTaggedVOSEvent *evt = queue->Enqueue())
*evt = TimeTaggedVOSEvent::Create(vosEventBase, timestamp);
}
static void TranslateGamepadInputEvent(const GpGamepadInputEvent &vosEvent, PortabilityLayer::EventQueue *queue) static void TranslateGamepadInputEvent(const GpGamepadInputEvent &vosEvent, PortabilityLayer::EventQueue *queue)
{ {
PortabilityLayer::InputManager *inputManager = PortabilityLayer::InputManager::GetInstance(); PortabilityLayer::InputManager *inputManager = PortabilityLayer::InputManager::GetInstance();
@@ -127,6 +133,9 @@ static void TranslateVOSEvent(const GpVOSEvent *vosEvent, uint32_t timestamp, Po
case GpVOSEventTypes::kMouseInput: case GpVOSEventTypes::kMouseInput:
TranslateMouseInputEvent(*vosEvent, timestamp, queue); TranslateMouseInputEvent(*vosEvent, timestamp, queue);
break; break;
case GpVOSEventTypes::kTouchInput:
TranslateTouchInputEvent(*vosEvent, timestamp, queue);
break;
case GpVOSEventTypes::kKeyboardInput: case GpVOSEventTypes::kKeyboardInput:
TranslateKeyboardInputEvent(*vosEvent, timestamp, queue); TranslateKeyboardInputEvent(*vosEvent, timestamp, queue);
break; break;