Treballant en la conversió a SDL3
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
#include "jinput.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include "jdraw.h"
|
||||
#include "jfile.h"
|
||||
|
||||
namespace input
|
||||
{
|
||||
static const uint8_t *keys = nullptr;
|
||||
static const bool *keys = nullptr;
|
||||
static uint8_t keypressed = 0;
|
||||
static uint8_t keydown = 0;
|
||||
static uint8_t btnClicked = 0;
|
||||
static int wheel = 0;
|
||||
static SDL_GameController *gamepad = NULL;
|
||||
static SDL_Gamepad *gamepad = NULL;
|
||||
static int8_t pad_btn_pressed = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
static int8_t pad_btn_down = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
|
||||
@@ -18,14 +18,23 @@ namespace input
|
||||
{
|
||||
int size;
|
||||
char *buffer = file::getFileBuffer("gamecontrollerdb.txt", size);
|
||||
if (SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(buffer, size), 1) < 0) printf("No s'ha pogut carregar el gamecontrollersdb.txt\n");
|
||||
if (SDL_AddGamepadMappingsFromIO(SDL_IOFromMem(buffer, size), 1) < 0) printf("No s'ha pogut carregar el gamecontrollersdb.txt\n");
|
||||
free(buffer);
|
||||
|
||||
int num_gamepads;
|
||||
SDL_JoystickID *gamepads = SDL_GetGamepads(&num_gamepads);
|
||||
if (num_gamepads>0)
|
||||
{
|
||||
gamepad = SDL_OpenGamepad(gamepads[0]);
|
||||
SDL_SetGamepadEventsEnabled(true);
|
||||
SDL_free(gamepads);
|
||||
}
|
||||
/*
|
||||
const int num_joysticks = SDL_NumJoysticks();
|
||||
if (num_joysticks>=1) {
|
||||
for (int i=0; i<num_joysticks; ++i) {
|
||||
if (SDL_IsGameController(i)) {
|
||||
gamepad = SDL_GameControllerOpen(i);
|
||||
gamepad = SDL_OpenGamepad() GameControllerOpen(i);
|
||||
if (SDL_GameControllerGetAttached(gamepad) == SDL_TRUE) {
|
||||
SDL_GameControllerEventState(SDL_ENABLE);
|
||||
return;
|
||||
@@ -33,6 +42,7 @@ namespace input
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void init()
|
||||
@@ -76,7 +86,7 @@ namespace input
|
||||
bool padBtnDown(const int8_t btn)
|
||||
{
|
||||
if (!gamepad) return false;
|
||||
return SDL_GameControllerGetButton(gamepad, SDL_GameControllerButton(btn)) == 1;
|
||||
return SDL_GetGamepadButton(gamepad, SDL_GamepadButton(btn)) == 1;
|
||||
}
|
||||
|
||||
// Determina si el botó del pad especificat ha sigut polsat, pero no tornarà a ser true fins
|
||||
@@ -144,7 +154,7 @@ namespace input
|
||||
// Torna la posició X actual del ratolí
|
||||
const int mouseX()
|
||||
{
|
||||
int x;
|
||||
float x;
|
||||
SDL_GetMouseState(&x, NULL);
|
||||
return x/draw::getZoom();
|
||||
}
|
||||
@@ -152,7 +162,7 @@ namespace input
|
||||
// Torna la posició Y actual del ratolí
|
||||
const int mouseY()
|
||||
{
|
||||
int y;
|
||||
float y;
|
||||
SDL_GetMouseState(NULL, &y);
|
||||
return y/draw::getZoom();
|
||||
}
|
||||
@@ -160,7 +170,7 @@ namespace input
|
||||
// Determina si el botó del ratolí especificat està sent polsada ara mateix
|
||||
const bool mouseBtn(const int btn)
|
||||
{
|
||||
return (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(btn));
|
||||
return (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_MASK(btn));
|
||||
}
|
||||
|
||||
// Determina si el botó especificat ha sigut polsat, pero no tornarà a ser true fins
|
||||
|
||||
Reference in New Issue
Block a user