Dreamcast: Wheel support for mice

This commit is contained in:
UnknownShadow200 2024-07-12 17:56:34 +10:00
parent d8676cbd6c
commit 5be965131c
31 changed files with 24 additions and 61 deletions

View File

@ -64,6 +64,7 @@ cc_bool Game_Anaglyph3D;
cc_bool Game_ViewBobbing, Game_HideGui; cc_bool Game_ViewBobbing, Game_HideGui;
cc_bool Game_BreakableLiquids, Game_ScreenshotRequested; cc_bool Game_BreakableLiquids, Game_ScreenshotRequested;
struct GameVersion Game_Version; struct GameVersion Game_Version;
Game_Draw2DHook Game_Draw2DHooks[4];
static char usernameBuffer[STRING_SIZE]; static char usernameBuffer[STRING_SIZE];
static char mppassBuffer[STRING_SIZE]; static char mppassBuffer[STRING_SIZE];
@ -657,6 +658,7 @@ static void LimitFPS(void) {
#endif #endif
static CC_INLINE void Game_DrawFrame(float delta, float t) { static CC_INLINE void Game_DrawFrame(float delta, float t) {
int i;
UpdateViewMatrix(); UpdateViewMatrix();
if (!Gui_GetBlocksWorld()) { if (!Gui_GetBlocksWorld()) {
@ -675,7 +677,11 @@ static CC_INLINE void Game_DrawFrame(float delta, float t) {
Gfx_Begin2D(Game.Width, Game.Height); Gfx_Begin2D(Game.Width, Game.Height);
Gui_RenderGui(delta); Gui_RenderGui(delta);
OnscreenKeyboard_Draw3D(); for (i = 0; i < Array_Elems(Game_Draw2DHooks); i++)
{
if (Game_Draw2DHooks[i]) Game_Draw2DHooks[i]();
}
/* TODO find a better solution than this */ /* TODO find a better solution than this */
#ifdef CC_BUILD_3DS #ifdef CC_BUILD_3DS
if (Game_Anaglyph3D) { if (Game_Anaglyph3D) {

View File

@ -21,6 +21,8 @@ extern cc_bool Game_UseCPEBlocks;
extern cc_string Game_Username; extern cc_string Game_Username;
extern cc_string Game_Mppass; extern cc_string Game_Mppass;
typedef void (*Game_Draw2DHook)(void);
extern Game_Draw2DHook Game_Draw2DHooks[4];
#ifdef CC_BUILD_SPLITSCREEN #ifdef CC_BUILD_SPLITSCREEN
extern int Game_NumLocalPlayers; extern int Game_NumLocalPlayers;

View File

@ -21,7 +21,7 @@ static void VirtualCursor_Display2D(struct Context2D* ctx) {
x - CURSOR_SIZE, y - CURSOR_EXTENT, CURSOR_SIZE * 3, CURSOR_EXTENT * 2); x - CURSOR_SIZE, y - CURSOR_EXTENT, CURSOR_SIZE * 3, CURSOR_EXTENT * 2);
} }
static void VirtualCursor_SetPosition(int x, int y) { static void VirtualCursor_SetPositionm(int x, int y) {
x = max(0, min(x, Window_Main.Width - 1)); x = max(0, min(x, Window_Main.Width - 1));
y = max(0, min(y, Window_Main.Height - 1)); y = max(0, min(y, Window_Main.Height - 1));
vc_hooked = true; vc_hooked = true;

View File

@ -9,6 +9,7 @@
#include "LBackend.h" #include "LBackend.h"
#include "Window.h" #include "Window.h"
#include "Graphics.h" #include "Graphics.h"
#include "Game.h"
static cc_bool kb_inited, kb_shift, kb_needsHook; static cc_bool kb_inited, kb_shift, kb_needsHook;
static struct FontDesc kb_font; static struct FontDesc kb_font;
@ -305,7 +306,7 @@ static void VirtualKeyboard_Display2D(struct Context2D* real_ctx) {
} }
static void VirtualKeyboard_Close2D(void) { static void VirtualKeyboard_Close2D(void) {
LBackend_Hooks[0] = NULL; LBackend_Hooks[0] = NULL;
LBackend_Redraw(); LBackend_Redraw();
} }
@ -321,7 +322,9 @@ static void VirtualKeyboard_MarkDirty3D(void) {
static void VirtualKeyboard_Close3D(void) { static void VirtualKeyboard_Close3D(void) {
Gfx_DeleteTexture(&kb_texture.ID); Gfx_DeleteTexture(&kb_texture.ID);
Game_Draw2DHooks[0] = NULL;
} }
static void VirtualKeyboard_MakeTexture(void) { static void VirtualKeyboard_MakeTexture(void) {
struct Context2D ctx; struct Context2D ctx;
int width = VirtualKeyboard_Width(); int width = VirtualKeyboard_Width();
@ -399,7 +402,8 @@ static void VirtualKeyboard_Open(struct OpenKeyboardArgs* args, cc_bool launcher
Window_Main.SoftKeyboardFocus = true; Window_Main.SoftKeyboardFocus = true;
Input.DownHook = VirtualKeyboard_ProcessDown; Input.DownHook = VirtualKeyboard_ProcessDown;
LBackend_Hooks[0] = VirtualKeyboard_Display2D; LBackend_Hooks[0] = VirtualKeyboard_Display2D;
Game_Draw2DHooks[0] = VirtualKeyboard_Display3D;
} }
static void VirtualKeyboard_SetText(const cc_string* text) { static void VirtualKeyboard_SetText(const cc_string* text) {

View File

@ -215,8 +215,6 @@ void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args);
/* As such, this is necessary to ensure the HTML input is consistent with */ /* As such, this is necessary to ensure the HTML input is consistent with */
/* whatever text input widget is actually being displayed on screen. */ /* whatever text input widget is actually being displayed on screen. */
void OnscreenKeyboard_SetText(const cc_string* text); void OnscreenKeyboard_SetText(const cc_string* text);
void OnscreenKeyboard_Draw2D(Rect2D* r, struct Bitmap* bmp);
void OnscreenKeyboard_Draw3D(void);
/* Hides/Removes the previously displayed on-screen keyboard. */ /* Hides/Removes the previously displayed on-screen keyboard. */
void OnscreenKeyboard_Close(void); void OnscreenKeyboard_Close(void);
/* Locks/Unlocks the landscape orientation. */ /* Locks/Unlocks the landscape orientation. */

View File

@ -279,7 +279,6 @@ void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) {
OnscreenTextChanged(output); OnscreenTextChanged(output);
} }
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { void OnscreenKeyboard_Close(void) {
DisplayInfo.ShowingSoftKeyboard = false; DisplayInfo.ShowingSoftKeyboard = false;

View File

@ -547,8 +547,6 @@ void OnscreenKeyboard_SetText(const cc_string* text) {
(*env)->DeleteLocalRef(env, args[0].l); (*env)->DeleteLocalRef(env, args[0].l);
} }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { void OnscreenKeyboard_Close(void) {
JNIEnv* env; JNIEnv* env;
JavaGetCurrentEnv(env); JavaGetCurrentEnv(env);

View File

@ -681,7 +681,6 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { } void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { }
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { } void OnscreenKeyboard_Close(void) { }
void Window_EnableRawMouse(void) { void Window_EnableRawMouse(void) {

View File

@ -202,6 +202,7 @@ static void ProcessMouseInput(float delta) {
Input_SetNonRepeatable(CCMOUSE_L, mods & MOUSE_LEFTBUTTON); Input_SetNonRepeatable(CCMOUSE_L, mods & MOUSE_LEFTBUTTON);
Input_SetNonRepeatable(CCMOUSE_R, mods & MOUSE_RIGHTBUTTON); Input_SetNonRepeatable(CCMOUSE_R, mods & MOUSE_RIGHTBUTTON);
Input_SetNonRepeatable(CCMOUSE_M, mods & MOUSE_SIDEBUTTON); Input_SetNonRepeatable(CCMOUSE_M, mods & MOUSE_SIDEBUTTON);
Mouse_ScrollVWheel(-state->dz * 0.5f);
if (!vc_hooked) { if (!vc_hooked) {
Pointer_SetPosition(0, Window_Main.Width / 2, Window_Main.Height / 2); Pointer_SetPosition(0, Window_Main.Width / 2, Window_Main.Height / 2);
@ -219,7 +220,9 @@ void Window_ProcessEvents(float delta) {
ProcessMouseInput(delta); ProcessMouseInput(delta);
} }
void Cursor_SetPosition(int x, int y) { } /* TODO: Dreamcast mouse support */ void Cursor_SetPosition(int x, int y) {
if (vc_hooked) VirtualCursor_SetPosition(x, y);
}
void Window_EnableRawMouse(void) { Input.RawMode = true; } void Window_EnableRawMouse(void) { Input.RawMode = true; }
void Window_DisableRawMouse(void) { Input.RawMode = false; } void Window_DisableRawMouse(void) { Input.RawMode = false; }
@ -347,10 +350,6 @@ void OnscreenKeyboard_SetText(const cc_string* text) {
VirtualKeyboard_SetText(text); VirtualKeyboard_SetText(text);
} }
void OnscreenKeyboard_Draw3D(void) {
VirtualKeyboard_Display3D();
}
void OnscreenKeyboard_Close(void) { void OnscreenKeyboard_Close(void) {
VirtualKeyboard_Close(); VirtualKeyboard_Close();
} }

View File

@ -526,10 +526,6 @@ void OnscreenKeyboard_SetText(const cc_string* text) {
VirtualKeyboard_SetText(text); VirtualKeyboard_SetText(text);
} }
void OnscreenKeyboard_Draw3D(void) {
VirtualKeyboard_Display3D();
}
void OnscreenKeyboard_Close(void) { void OnscreenKeyboard_Close(void) {
VirtualKeyboard_Close(); VirtualKeyboard_Close();
} }

View File

@ -518,7 +518,6 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { } void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { }
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { } void OnscreenKeyboard_Close(void) { }
void Window_EnableRawMouse(void) { void Window_EnableRawMouse(void) {

View File

@ -184,7 +184,6 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
*#########################################################################################################################*/ *#########################################################################################################################*/
void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { /* TODO implement */ } void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { /* TODO implement */ }
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { /* TODO implement */ } void OnscreenKeyboard_Close(void) { /* TODO implement */ }

View File

@ -323,8 +323,6 @@ void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) {
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { void OnscreenKeyboard_Close(void) {
keyboardHide(); keyboardHide();
if (!DisplayInfo.ShowingSoftKeyboard) return; if (!DisplayInfo.ShowingSoftKeyboard) return;

View File

@ -193,7 +193,6 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
*#########################################################################################################################*/ *#########################################################################################################################*/
void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { /* TODO implement */ } void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { /* TODO implement */ }
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { /* TODO implement */ } void OnscreenKeyboard_Close(void) { /* TODO implement */ }

View File

@ -150,7 +150,7 @@ static void ProcessMouseInput(float delta) {
Input_SetNonRepeatable(CCMOUSE_L, mData.buttons & PS2MOUSE_BTN1); Input_SetNonRepeatable(CCMOUSE_L, mData.buttons & PS2MOUSE_BTN1);
Input_SetNonRepeatable(CCMOUSE_R, mData.buttons & PS2MOUSE_BTN2); Input_SetNonRepeatable(CCMOUSE_R, mData.buttons & PS2MOUSE_BTN2);
Input_SetNonRepeatable(CCMOUSE_M, mData.buttons & PS2MOUSE_BTN3); Input_SetNonRepeatable(CCMOUSE_M, mData.buttons & PS2MOUSE_BTN3);
Mouse_ScrollVWheel(mData.wheel); Mouse_ScrollVWheel(mData.wheel * 0.5f);
if (!vc_hooked) { if (!vc_hooked) {
Pointer_SetPosition(0, Window_Main.Width / 2, Window_Main.Height / 2); Pointer_SetPosition(0, Window_Main.Width / 2, Window_Main.Height / 2);
@ -177,7 +177,9 @@ void Window_ProcessEvents(float delta) {
ProcessKeyboardInput(); ProcessKeyboardInput();
} }
void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita void Cursor_SetPosition(int x, int y) {
if (vc_hooked) VirtualCursor_SetPosition(x, y);
}
void Window_EnableRawMouse(void) { Input.RawMode = true; } void Window_EnableRawMouse(void) { Input.RawMode = true; }
void Window_UpdateRawMouse(void) { } void Window_UpdateRawMouse(void) { }
@ -321,10 +323,6 @@ void OnscreenKeyboard_SetText(const cc_string* text) {
VirtualKeyboard_SetText(text); VirtualKeyboard_SetText(text);
} }
void OnscreenKeyboard_Draw3D(void) {
VirtualKeyboard_Display3D();
}
void OnscreenKeyboard_Close(void) { void OnscreenKeyboard_Close(void) {
VirtualKeyboard_Close(); VirtualKeyboard_Close();
} }

View File

@ -378,10 +378,6 @@ void OnscreenKeyboard_SetText(const cc_string* text) {
VirtualKeyboard_SetText(text); VirtualKeyboard_SetText(text);
} }
void OnscreenKeyboard_Draw3D(void) {
VirtualKeyboard_Display3D();
}
void OnscreenKeyboard_Close(void) { void OnscreenKeyboard_Close(void) {
VirtualKeyboard_Close(); VirtualKeyboard_Close();
} }

View File

@ -179,10 +179,6 @@ void OnscreenKeyboard_SetText(const cc_string* text) {
VirtualKeyboard_SetText(text); VirtualKeyboard_SetText(text);
} }
void OnscreenKeyboard_Draw3D(void) {
VirtualKeyboard_Display3D();
}
void OnscreenKeyboard_Close(void) { void OnscreenKeyboard_Close(void) {
VirtualKeyboard_Close(); VirtualKeyboard_Close();
} }

View File

@ -351,7 +351,6 @@ void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) {
/* TODO implement */ /* TODO implement */
} }
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { /* TODO implement */ } void OnscreenKeyboard_Close(void) { /* TODO implement */ }

View File

@ -445,7 +445,6 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { SDL_StartTextInput(); } void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { SDL_StartTextInput(); }
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { SDL_StopTextInput(); } void OnscreenKeyboard_Close(void) { SDL_StopTextInput(); }
void Window_EnableRawMouse(void) { void Window_EnableRawMouse(void) {

View File

@ -477,7 +477,6 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { SDL_StartTextInput(win_handle); } void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { SDL_StartTextInput(win_handle); }
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { SDL_StopTextInput(win_handle); } void OnscreenKeyboard_Close(void) { SDL_StopTextInput(win_handle); }
void Window_EnableRawMouse(void) { void Window_EnableRawMouse(void) {

View File

@ -233,7 +233,6 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
*#########################################################################################################################*/ *#########################################################################################################################*/
void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { /* TODO implement */ } void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { /* TODO implement */ }
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { /* TODO implement */ } void OnscreenKeyboard_Close(void) { /* TODO implement */ }

View File

@ -291,7 +291,6 @@ void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) {
swkbdClose(&kbd); swkbdClose(&kbd);
} }
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { /* TODO implement */ } void OnscreenKeyboard_Close(void) { /* TODO implement */ }

View File

@ -540,7 +540,6 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { } void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { }
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { } void OnscreenKeyboard_Close(void) { }
void Window_EnableRawMouse(void) { void Window_EnableRawMouse(void) {

View File

@ -724,8 +724,6 @@ void OnscreenKeyboard_SetText(const cc_string* text) {
interop_SetKeyboardText(str); interop_SetKeyboardText(str);
} }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { void OnscreenKeyboard_Close(void) {
keyboardOpen = false; keyboardOpen = false;
if (!Input_TouchMode) return; if (!Input_TouchMode) return;

View File

@ -602,7 +602,6 @@ static void OnscreenKeyboard_DrawDRC(void) {
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { void OnscreenKeyboard_Close(void) {
if (!keyboardOpen) return; if (!keyboardOpen) return;

View File

@ -754,7 +754,6 @@ static void InitRawMouse(void) {
void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { } void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { }
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { } void OnscreenKeyboard_Close(void) { }
void Window_EnableRawMouse(void) { void Window_EnableRawMouse(void) {

View File

@ -1198,8 +1198,6 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { } void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { }
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw2D(Rect2D* r, struct Bitmap* bmp) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { } void OnscreenKeyboard_Close(void) { }
static cc_bool rawMouseInited, rawMouseSupported; static cc_bool rawMouseInited, rawMouseSupported;

View File

@ -231,10 +231,6 @@ void OnscreenKeyboard_SetText(const cc_string* text) {
VirtualKeyboard_SetText(text); VirtualKeyboard_SetText(text);
} }
void OnscreenKeyboard_Draw3D(void) {
VirtualKeyboard_Display3D();
}
void OnscreenKeyboard_Close(void) { void OnscreenKeyboard_Close(void) {
VirtualKeyboard_Close(); VirtualKeyboard_Close();
} }

View File

@ -193,10 +193,6 @@ void OnscreenKeyboard_SetText(const cc_string* text) {
VirtualKeyboard_SetText(text); VirtualKeyboard_SetText(text);
} }
void OnscreenKeyboard_Draw3D(void) {
VirtualKeyboard_Display3D();
}
void OnscreenKeyboard_Close(void) { void OnscreenKeyboard_Close(void) {
VirtualKeyboard_Close(); VirtualKeyboard_Close();
} }

View File

@ -761,7 +761,6 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { } void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { }
void OnscreenKeyboard_SetText(const cc_string* text) { } void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { } void OnscreenKeyboard_Close(void) { }

View File

@ -539,8 +539,6 @@ void OnscreenKeyboard_SetText(const cc_string* text) {
text_input.text = str; text_input.text = str;
} }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { void OnscreenKeyboard_Close(void) {
DisplayInfo.ShowingSoftKeyboard = false; DisplayInfo.ShowingSoftKeyboard = false;
[text_input resignFirstResponder]; [text_input resignFirstResponder];