VOGONS


First post, by superfury

User metadata
Rank l33t++
Rank
l33t++

I've added a simple compatibility layer from Pelya's libSDL 'Joystick' touch events to provide SDL2 touch events. This doesn't seem to be working correctly on Pelya's libSDL somehow?

Anyone knows what's going wrong here?

From https://bitbucket.org/superfury/unipcemu/src/ … put.c?at=master :

#ifdef PELYAS_SDL
byte touchstatus[0x10] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //All Pelya finger statuses!
float touchscreencoordinates_x[0x10] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f}; //Current screen coordinates of each finger!
float touchscreencoordinates_y[0x10] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f}; //Current screen coordinates of each finger!
#endif

...

void updateInput(SDL_Event *event) //Update all input!
{
byte joysticktype=0; //What joystick type?
static byte RALT = 0;
switch (event->type)
{
...
case SDL_JOYBUTTONDOWN: /* Handle Joystick Button Presses */
#ifdef PELYAS_SDL
if (event->jbutton.which==0)
{
if (event->jbutton.button<0x10) //Valid button protection?
{
if (!touchstatus[event->jbutton.button]) //Not touched yet?
{
touchstatus[event->jbutton.button] = 1; //We're touched!
touch_fingerDown(touchscreencoordinates_x[event->jbutton.button], touchscreencoordinates_y[event->jbutton.button],(SDL_FingerID)event->jbutton.button); //Press the finger now!
}
}
}
break; //Disable normal joystick handling: this is disabled!
#endif
...
case SDL_JOYBALLMOTION:
#ifdef PELYAS_SDL
if (event->jball.which == 0)
{
if (event->jball.ball<0x10) //Valid button protection?
{
float ballx,bally;
ballx = ((event->jball.xrel/32767.0f)+1.0f)*0.5f; //X coordinate, normalized!
bally = ((event->jball.yrel/32767.0f)+1.0f)*0.5f; //Y coordinate, normalized!
touchscreencoordinates_x[event->jball.ball] = ballx; //Set screen x coordinate normalized!
touchscreencoordinates_y[event->jball.ball] = bally; //Set screen y coordinate normalized!
if (touchstatus[event->jball.ball]) //Already touched?
{
touch_fingerMotion(touchscreencoordinates_x[event->jball.ball], touchscreencoordinates_y[event->jball.ball], (SDL_FingerID)event->jball.ball); //Motion of the pressed finger now!
}
}
}
break; //Disable normal joystick handling: this is disabled!
#endif
//We're not handling it normally!
break;
case SDL_JOYBUTTONUP: /* Handle Joystick Button Releases */
#ifdef PELYAS_SDL
if (event->jbutton.which == 0)
{
if (event->jbutton.button<0x10) //Valid button protection?
{
if (touchstatus[event->jbutton.button]) //Not touched yet?
{
Show last 8 lines
						touchstatus[event->jbutton.button] = 0; //We're not touched anymore!
touch_fingerUp(touchscreencoordinates_x[event->jbutton.button], touchscreencoordinates_y[event->jbutton.button], (SDL_FingerID)event->jbutton.button); //Press the finger now!
}
}
}
break; //Disable normal joystick handling: this is disabled!
#endif

The SDL2 version of this(which is working on the Android device):

	case SDL_FINGERDOWN:
//Convert the touchId and fingerId to finger! For now, allow only one finger!
touch_fingerDown(event->tfinger.x,event->tfinger.y, event->tfinger.fingerId);
break;
case SDL_FINGERUP:
//Convert the touchId and fingerId to finger! For now, allow only one finger!
touch_fingerUp(event->tfinger.x, event->tfinger.y, event->tfinger.fingerId);
break;
case SDL_FINGERMOTION:
//Convert the touchId and fingerId to finger! For now, allow only one finger!
touch_fingerMotion(event->tfinger.x, event->tfinger.y, event->tfinger.fingerId);
break;

Also, during initialization:

#ifdef SDL2
SDL_AddEventWatch(myEventFilter, NULL); //For applying critical updates!
#ifdef SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4
SDL_SetHintWithPriority(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4,"1",SDL_HINT_OVERRIDE); //We're forcing the window not to quit on ALT-F4!
#endif
#ifdef SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH
SDL_SetHintWithPriority(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,"1",SDL_HINT_OVERRIDE); //We're forcing us to use seperate mouse and touch events!
#endif
#endif

Anyone can see why the libSDL version of Pelya isn't working?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 1 of 1, by superfury

User metadata
Rank l33t++
Rank
l33t++

I've looked at https://github.com/pelya/commandergenius/blob … n/xserver/gfx.c . Looking at the way it processes x and y coordinates, it seems that the event->jball.xrel and event->jball.yrel contain the actual coordinates on the screen, not relative coordinates (-32767 - + 32767 being coordinates 0 to xres/yes)?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io