Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Northfear committed Jun 26, 2021
1 parent b67e055 commit 9fdc8e8
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 66 deletions.
10 changes: 7 additions & 3 deletions common/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ SettingsClass::SettingsClass()
*/
Mouse.RawInput = true;
Mouse.Sensitivity = 100;
#ifdef VITA
Mouse.ControllerEnabled = true;
#else
Mouse.ControllerEnabled = false;
#endif
Mouse.ControllerPointerSpeed = 10;

/*
Expand All @@ -31,7 +36,6 @@ SettingsClass::SettingsClass()

#ifdef VITA
Vita.ScaleGameSurface = true;
Vita.ControllerPointerSpeed = 10;
#endif
}

Expand All @@ -42,6 +46,7 @@ void SettingsClass::Load(INIClass& ini)
*/
Mouse.RawInput = ini.Get_Bool("Mouse", "RawInput", Mouse.RawInput);
Mouse.Sensitivity = ini.Get_Int("Mouse", "Sensitivity", Mouse.Sensitivity);
Mouse.ControllerEnabled = ini.Get_Int("Mouse", "ControllerEnabled", Mouse.ControllerEnabled);
Mouse.ControllerPointerSpeed = ini.Get_Int("Mouse", "ControllerPointerSpeed", Mouse.ControllerPointerSpeed);

/*
Expand Down Expand Up @@ -73,7 +78,6 @@ void SettingsClass::Load(INIClass& ini)

#ifdef VITA
Vita.ScaleGameSurface = ini.Get_Bool("Vita", "ScaleGameSurface", Vita.ScaleGameSurface);
Vita.ControllerPointerSpeed = ini.Get_Int("Vita", "ControllerPointerSpeed", Vita.ControllerPointerSpeed);
#endif
}

Expand All @@ -84,6 +88,7 @@ void SettingsClass::Save(INIClass& ini)
*/
ini.Put_Bool("Mouse", "RawInput", Mouse.RawInput);
ini.Put_Int("Mouse", "Sensitivity", Mouse.Sensitivity);
ini.Put_Bool("Mouse", "ControllerEnabled", Mouse.ControllerEnabled);
ini.Put_Int("Mouse", "ControllerPointerSpeed", Mouse.ControllerPointerSpeed);

/*
Expand All @@ -108,6 +113,5 @@ void SettingsClass::Save(INIClass& ini)

#ifdef VITA
ini.Put_Bool("Vita", "ScaleGameSurface", Vita.ScaleGameSurface);
ini.Put_Int("Vita", "ControllerPointerSpeed", Vita.ControllerPointerSpeed);
#endif
}
2 changes: 1 addition & 1 deletion common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SettingsClass
{
bool RawInput;
int Sensitivity;
bool ControllerEnabled;
int ControllerPointerSpeed;
} Mouse;

Expand All @@ -39,7 +40,6 @@ class SettingsClass
struct
{
bool ScaleGameSurface;
int ControllerPointerSpeed;
} Vita;
#endif
};
Expand Down
2 changes: 0 additions & 2 deletions common/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ const int32_t VITA_FULLSCREEN_WIDTH = 960;
const int32_t VITA_FULLSCREEN_HEIGHT = 544;

SDL_Rect Get_Render_Rect();
void Get_Game_Resolution(int& w, int& h);
void Set_Video_Mouse(int x, int y);
#endif

/*
Expand Down
20 changes: 11 additions & 9 deletions common/video_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,10 @@ bool Set_Video_Mode(int w, int h, int bits_per_pixel)
/*
** Init gamepad.
*/
SDL_Init(SDL_INIT_GAMECONTROLLER);
Keyboard->Open_Controller();
if(Settings.Mouse.ControllerEnabled) {
SDL_Init(SDL_INIT_GAMECONTROLLER);
Keyboard->Open_Controller();
}

return true;
}
Expand Down Expand Up @@ -475,13 +477,6 @@ void Get_Video_Mouse(int& x, int& y)
}
}

#ifdef VITA
SDL_Rect Get_Render_Rect()
{
return render_dst;
}
#endif

void Get_Game_Resolution(int& w, int& h)
{
w = hwcursor.GameW;
Expand All @@ -494,6 +489,13 @@ void Set_Video_Mouse(int x, int y)
hwcursor.Y = y;
}

#ifdef VITA
SDL_Rect Get_Render_Rect()
{
return render_dst;
}
#endif

/***********************************************************************************************
* Reset_Video_Mode -- Resets video mode and deletes Direct Draw Object *
* *
Expand Down
102 changes: 53 additions & 49 deletions common/wwkeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,13 @@ void WWKeyboardClass::Fill_Buffer_From_System(void)
case SDL_CONTROLLERBUTTONUP:
Handle_Controller_Button_Event(event.cbutton);
break;
#ifdef VITA
case SDL_FINGERDOWN:
case SDL_FINGERUP:
case SDL_FINGERMOTION:
Handle_Touch_Event(event.tfinger);
break;
#endif
}
}
if (Is_Gamepad_Active()) {
Expand Down Expand Up @@ -666,7 +668,7 @@ void WWKeyboardClass::Open_Controller()
Get_Video_Mouse(mousePosX, mousePosY);
EmulatedPointerPosX = mousePosX;
EmulatedPointerPosY = mousePosY;
#if SDL_VERSION_ATLEAST(2, 0, 10)
#if SDL_VERSION_ATLEAST(2, 0, 10) && defined(VITA)
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
#endif
}
Expand Down Expand Up @@ -792,54 +794,6 @@ void WWKeyboardClass::Handle_Controller_Axis_Event(const SDL_ControllerAxisEvent
ScrollDirection = SDIR_N;
}

void WWKeyboardClass::Handle_Touch_Event(const SDL_TouchFingerEvent& event)
{
// ignore back touchpad
if (event.touchId != 0)
return;

if (event.type == SDL_FINGERDOWN) {
++NumTouches;
if (NumTouches == 1) {
FirstFingerId = event.fingerId;
}
} else if (event.type == SDL_FINGERUP) {
--NumTouches;
}

if (FirstFingerId == event.fingerId) {
const int screenWidth = 960;
const int screenHeight = 544;
int gameWidth;
int gameHeight;
Get_Game_Resolution(gameWidth, gameHeight);
SDL_Rect renderRect = Get_Render_Rect();

EmulatedPointerPosX =
static_cast<float>(screenWidth * event.x - renderRect.x) * (static_cast<double>(gameWidth) / renderRect.w);
EmulatedPointerPosY = static_cast<float>(screenHeight * event.y - renderRect.y)
* (static_cast<double>(gameHeight) / renderRect.h);

if (EmulatedPointerPosX < 0)
EmulatedPointerPosX = 0;
else if (EmulatedPointerPosX >= gameWidth)
EmulatedPointerPosX = gameWidth - 1;

if (EmulatedPointerPosY < 0)
EmulatedPointerPosY = 0;
else if (EmulatedPointerPosY >= gameHeight)
EmulatedPointerPosY = gameHeight - 1;

Set_Video_Mouse(EmulatedPointerPosX, EmulatedPointerPosY);

if (event.type == SDL_FINGERDOWN) {
Put_Mouse_Message(VK_LBUTTON, EmulatedPointerPosX, EmulatedPointerPosY, 0);
} else if (event.type == SDL_FINGERUP) {
Put_Mouse_Message(VK_LBUTTON, EmulatedPointerPosX, EmulatedPointerPosY, 1);
}
}
}

void WWKeyboardClass::Handle_Controller_Button_Event(const SDL_ControllerButtonEvent& button)
{
bool keyboardPress = false;
Expand Down Expand Up @@ -932,6 +886,56 @@ unsigned char WWKeyboardClass::Get_Scroll_Direction()
{
return ScrollDirection;
}

#ifdef VITA
void WWKeyboardClass::Handle_Touch_Event(const SDL_TouchFingerEvent& event)
{
// ignore back touchpad
if (event.touchId != 0)
return;

if (event.type == SDL_FINGERDOWN) {
++NumTouches;
if (NumTouches == 1) {
FirstFingerId = event.fingerId;
}
} else if (event.type == SDL_FINGERUP) {
--NumTouches;
}

if (FirstFingerId == event.fingerId) {
const int screenWidth = 960;
const int screenHeight = 544;
int gameWidth;
int gameHeight;
Get_Game_Resolution(gameWidth, gameHeight);
SDL_Rect renderRect = Get_Render_Rect();

EmulatedPointerPosX =
static_cast<float>(screenWidth * event.x - renderRect.x) * (static_cast<double>(gameWidth) / renderRect.w);
EmulatedPointerPosY = static_cast<float>(screenHeight * event.y - renderRect.y)
* (static_cast<double>(gameHeight) / renderRect.h);

if (EmulatedPointerPosX < 0)
EmulatedPointerPosX = 0;
else if (EmulatedPointerPosX >= gameWidth)
EmulatedPointerPosX = gameWidth - 1;

if (EmulatedPointerPosY < 0)
EmulatedPointerPosY = 0;
else if (EmulatedPointerPosY >= gameHeight)
EmulatedPointerPosY = gameHeight - 1;

Set_Video_Mouse(EmulatedPointerPosX, EmulatedPointerPosY);

if (event.type == SDL_FINGERDOWN) {
Put_Mouse_Message(VK_LBUTTON, EmulatedPointerPosX, EmulatedPointerPosY, 0);
} else if (event.type == SDL_FINGERUP) {
Put_Mouse_Message(VK_LBUTTON, EmulatedPointerPosX, EmulatedPointerPosY, 1);
}
}
}
#endif
#endif

/***********************************************************************************************
Expand Down
6 changes: 4 additions & 2 deletions common/wwkeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,6 @@ class WWKeyboardClass
#ifdef SDL2_BUILD
void Handle_Controller_Axis_Event(const SDL_ControllerAxisEvent& motion);
void Handle_Controller_Button_Event(const SDL_ControllerButtonEvent& button);
void Handle_Touch_Event(const SDL_TouchFingerEvent& event);
void Process_Controller_Axis_Motion();

// used to convert user-friendly pointer speed values into more useable ones
Expand Down Expand Up @@ -829,11 +828,14 @@ class WWKeyboardClass
float ControllerSpeedBoost = 1;
bool AnalogScrollActive = false;
ScrollDirType ScrollDirection = SDIR_NONE;

bool AnalogStickMouse = true;

#ifdef VITA
void Handle_Touch_Event(const SDL_TouchFingerEvent& event);
SDL_FingerID FirstFingerId = 0;
int16_t NumTouches = 0;
#endif
#endif
};

#endif

0 comments on commit 9fdc8e8

Please sign in to comment.