mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 11:26:18 -04:00
fix mouse mispositioning when letterboxed (#2818)
Not sure if this is the best way to go about it. Fixes #2259
This commit is contained in:
parent
40e2f113e6
commit
4185123bd8
|
@ -541,6 +541,9 @@ void GLDisplay::render() {
|
|||
game_res_w = 640;
|
||||
game_res_h = 480;
|
||||
}
|
||||
// set the size of the visible/playable portion of the game in the window
|
||||
get_display_manager()->set_game_size(Gfx::g_global_settings.lbox_w,
|
||||
Gfx::g_global_settings.lbox_h);
|
||||
render_game_frame(
|
||||
game_res_w, game_res_h, fbuf_w, fbuf_h, Gfx::g_global_settings.lbox_w,
|
||||
Gfx::g_global_settings.lbox_h, Gfx::g_global_settings.msaa_samples,
|
||||
|
|
|
@ -468,10 +468,16 @@ u32 MouseGetData(u32 _mouse) {
|
|||
// TODO - probably factor in scaling as well
|
||||
auto win_width = 0;
|
||||
auto win_height = 0;
|
||||
auto game_width = 0;
|
||||
auto game_height = 0;
|
||||
if (Display::GetMainDisplay()) {
|
||||
win_width = Display::GetMainDisplay()->get_display_manager()->get_window_width();
|
||||
win_height = Display::GetMainDisplay()->get_display_manager()->get_window_height();
|
||||
game_width = Display::GetMainDisplay()->get_display_manager()->get_window_game_width();
|
||||
game_height = Display::GetMainDisplay()->get_display_manager()->get_window_game_height();
|
||||
}
|
||||
xpos -= (win_width - game_width) / 2;
|
||||
ypos -= (win_height - game_height) / 2;
|
||||
|
||||
// These are used to calculate the speed at which to move the mouse to it's new coordinates
|
||||
// zero'd out so they are ignored and don't impact the position we are about to set
|
||||
|
@ -482,8 +488,8 @@ u32 MouseGetData(u32 _mouse) {
|
|||
// - [-208.0, 208.0] for height
|
||||
// (then 208 or 256 is always added to them to get the final screen coordinate)
|
||||
// So just normalize the actual window's values to this range
|
||||
double width_per = xpos / double(win_width);
|
||||
double height_per = ypos / double(win_height);
|
||||
double width_per = xpos / double(game_width);
|
||||
double height_per = ypos / double(game_height);
|
||||
mouse->posx = (512.0 * width_per) - 256.0;
|
||||
mouse->posy = (416.0 * height_per) - 208.0;
|
||||
// fmt::print("Mouse - X:{}({}), Y:{}({})\n", xpos, mouse->posx, ypos, mouse->posy);
|
||||
|
|
|
@ -14,11 +14,11 @@ struct ActiveMouseAction {
|
|||
class MouseDevice : public InputDevice {
|
||||
public:
|
||||
struct MouseButtonStatus {
|
||||
bool left;
|
||||
bool right;
|
||||
bool middle;
|
||||
bool mouse4;
|
||||
bool mouse5;
|
||||
bool left = false;
|
||||
bool right = false;
|
||||
bool middle = false;
|
||||
bool mouse4 = false;
|
||||
bool mouse5 = false;
|
||||
};
|
||||
|
||||
MouseDevice(){};
|
||||
|
|
|
@ -74,6 +74,8 @@ class DisplayManager {
|
|||
bool is_minimized() { return m_window_state == WindowState::Minimized; }
|
||||
int get_window_width() { return m_window_width; }
|
||||
int get_window_height() { return m_window_height; }
|
||||
int get_window_game_width() { return m_window_game_width; }
|
||||
int get_window_game_height() { return m_window_game_height; }
|
||||
float get_window_scale_x() { return m_window_scale_x; }
|
||||
float get_window_scale_y() { return m_window_scale_y; }
|
||||
int num_connected_displays() { return m_current_display_modes.size(); }
|
||||
|
@ -90,6 +92,11 @@ class DisplayManager {
|
|||
void enqueue_set_window_display_mode(WindowDisplayMode mode);
|
||||
void enqueue_set_fullscreen_display_id(int display_id);
|
||||
|
||||
void set_game_size(int width, int height) {
|
||||
m_window_game_width = width;
|
||||
m_window_game_height = height;
|
||||
}
|
||||
|
||||
void set_input_manager(std::shared_ptr<InputManager> input_manager) {
|
||||
m_input_manager = input_manager;
|
||||
}
|
||||
|
@ -112,6 +119,8 @@ class DisplayManager {
|
|||
int m_window_ypos = 0;
|
||||
int m_window_width = 0;
|
||||
int m_window_height = 0;
|
||||
int m_window_game_width = 0;
|
||||
int m_window_game_height = 0;
|
||||
float m_window_scale_x = 1.0;
|
||||
float m_window_scale_y = 1.0;
|
||||
WindowState m_window_state = WindowState::Restored;
|
||||
|
|
|
@ -585,6 +585,10 @@ The cpad-set-buzz! function can be used for vibration.
|
|||
)
|
||||
|
||||
(define *mouse* (new 'global 'mouse-info))
|
||||
(#when PC_PORT
|
||||
;; added so we can hide the mouse
|
||||
(define *disable-mouse* #f)
|
||||
)
|
||||
|
||||
;; WARN: Return type mismatch mouse-info vs none.
|
||||
(defun service-mouse ()
|
||||
|
@ -619,7 +623,7 @@ The cpad-set-buzz! function can be used for vibration.
|
|||
(set! (-> gp-0 button0-rel 0) (logclear (-> gp-0 button0-abs 0) (-> gp-0 button0-abs 1)))
|
||||
)
|
||||
)
|
||||
(if (and (-> gp-0 active) (-> gp-0 valid) (-> gp-0 cursor))
|
||||
(if (and (-> gp-0 active) (-> gp-0 valid) (-> gp-0 cursor) (#if PC_PORT (not *disable-mouse*) #t))
|
||||
(add-debug-cursor
|
||||
#t
|
||||
(bucket-id debug-no-zbuf2)
|
||||
|
|
Loading…
Reference in a new issue