Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
SDL: Implement touchscreen support
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp authored and sfan5 committed Jan 13, 2024
1 parent a2b6244 commit 7df45b4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 45 additions & 1 deletion source/Irrlicht/CIrrDeviceSDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
Window((SDL_Window*)param.WindowId), SDL_Flags(0),
MouseX(0), MouseY(0), MouseXRel(0), MouseYRel(0), MouseButtonStates(0),
Width(param.WindowSize.Width), Height(param.WindowSize.Height),
Resizable(param.WindowResizable == 1 ? true : false)
Resizable(param.WindowResizable == 1 ? true : false), CurrentTouchCount(0)
{
#ifdef _DEBUG
setDebugName("CIrrDeviceSDL");
Expand All @@ -254,6 +254,11 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
}
}

// Minetest has its own code to synthesize mouse events from touch events,
// so we prevent SDL from doing it.
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "0");

// create keymap
createKeyMap();

Expand Down Expand Up @@ -745,6 +750,45 @@ bool CIrrDeviceSDL::run()
postEventFromUser(irrevent);
break;

case SDL_FINGERDOWN:
irrevent.EventType = EET_TOUCH_INPUT_EVENT;
irrevent.TouchInput.Event = ETIE_PRESSED_DOWN;
irrevent.TouchInput.ID = SDL_event.tfinger.fingerId;
irrevent.TouchInput.X = SDL_event.tfinger.x * Width;
irrevent.TouchInput.Y = SDL_event.tfinger.y * Height;
CurrentTouchCount++;
irrevent.TouchInput.touchedCount = CurrentTouchCount;

postEventFromUser(irrevent);
break;

case SDL_FINGERMOTION:
irrevent.EventType = EET_TOUCH_INPUT_EVENT;
irrevent.TouchInput.Event = ETIE_MOVED;
irrevent.TouchInput.ID = SDL_event.tfinger.fingerId;
irrevent.TouchInput.X = SDL_event.tfinger.x * Width;
irrevent.TouchInput.Y = SDL_event.tfinger.y * Height;
irrevent.TouchInput.touchedCount = CurrentTouchCount;

postEventFromUser(irrevent);
break;

case SDL_FINGERUP:
irrevent.EventType = EET_TOUCH_INPUT_EVENT;
irrevent.TouchInput.Event = ETIE_LEFT_UP;
irrevent.TouchInput.ID = SDL_event.tfinger.fingerId;
irrevent.TouchInput.X = SDL_event.tfinger.x * Width;
irrevent.TouchInput.Y = SDL_event.tfinger.y * Height;
// To match Android behavior, still count the pointer that was
// just released.
irrevent.TouchInput.touchedCount = CurrentTouchCount;
if (CurrentTouchCount > 0) {
CurrentTouchCount--;
}

postEventFromUser(irrevent);
break;

default:
break;
} // end switch
Expand Down
2 changes: 2 additions & 0 deletions source/Irrlicht/CIrrDeviceSDL.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ namespace irr

core::array<SKeyMap> KeyMap;
SDL_SysWMinfo Info;

s32 CurrentTouchCount;
};

} // end namespace irr
Expand Down

0 comments on commit 7df45b4

Please sign in to comment.