Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide SDL touch info via InputManager #5

Merged
merged 2 commits into from
Oct 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions QuickSDL/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ namespace QuickSDL {
return Vector2((float)mMouseXPos, (float)mMouseYPos);
}

Vector2 InputManager::TouchPos() {
return Vector2((float)mTouchXPos, (float)mTouchYPos);
}

bool InputManager::MouseButtonDown(MOUSE_BUTTON button) {

//mask to be using for bit wise operations
Expand Down Expand Up @@ -345,6 +349,11 @@ namespace QuickSDL {
//Updating the mouse state to get the key states of the current frame
mMouseState = SDL_GetMouseState(&mMouseXPos, &mMouseYPos);

SDL_Finger* touchState = SDL_GetTouchFinger(0, 0);
if (touchState != NULL) {
mTouchXPos = touchState->x;
mTouchYPos = touchState->y;
}

if (joy != NULL) {

Expand Down
4 changes: 4 additions & 0 deletions QuickSDL/InputManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ namespace QuickSDL {
int mMouseXPos;
int mMouseYPos;

int mTouchXPos;
int mTouchYPos;

SDL_Joystick* joy;

Uint8* mPrevJoyButtonState;
Expand Down Expand Up @@ -148,6 +151,7 @@ namespace QuickSDL {
//Returns a Vector2 containing the current mouse position on screen
//------------------------------------------------------------------
Vector2 MousePos();
Vector2 TouchPos();

bool JoyButtonDown(int button);
bool JoyButtonPressed(int button);
Expand Down