Skip to content

Commit 528aa4b

Browse files
committed
desktop: Map window to movie position explicitly
This refactors moves the logic of mapping window position to movie position into one common method.
1 parent eb1366e commit 528aa4b

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

desktop/src/app.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ impl MainWindow {
6464
// Event consumed by GUI.
6565
return;
6666
}
67-
let height_offset = if self.gui.window().fullscreen().is_some() || self.no_gui {
68-
0.0
69-
} else {
70-
MENU_HEIGHT as f64 * self.gui.window().scale_factor()
71-
};
7267
match event {
7368
WindowEvent::CloseRequested => {
7469
event_loop.exit();
@@ -81,7 +76,7 @@ impl MainWindow {
8176
let viewport_scale_factor = self.gui.window().scale_factor();
8277
player.set_viewport_dimensions(ViewportDimensions {
8378
width: size.width,
84-
height: size.height.saturating_sub(height_offset as u32),
79+
height: size.height.saturating_sub(self.gui.height_offset() as u32),
8580
scale_factor: viewport_scale_factor,
8681
});
8782
}
@@ -96,10 +91,8 @@ impl MainWindow {
9691
}
9792

9893
self.mouse_pos = position;
99-
let event = PlayerEvent::MouseMove {
100-
x: position.x,
101-
y: position.y - height_offset,
102-
};
94+
let (x, y) = self.gui.window_to_movie_position(position);
95+
let event = PlayerEvent::MouseMove { x, y };
10396
self.player.handle_event(event);
10497
self.check_redraw();
10598
}
@@ -125,8 +118,7 @@ impl MainWindow {
125118

126119
use ruffle_core::events::MouseButton as RuffleMouseButton;
127120
use winit::event::MouseButton;
128-
let x = self.mouse_pos.x;
129-
let y = self.mouse_pos.y - height_offset;
121+
let (x, y) = self.gui.window_to_movie_position(self.mouse_pos);
130122
let button = match button {
131123
MouseButton::Left => RuffleMouseButton::Left,
132124
MouseButton::Right => RuffleMouseButton::Right,

desktop/src/gui/controller.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::time::{Duration, Instant};
1717
use unic_langid::LanguageIdentifier;
1818
use url::Url;
1919
use wgpu::SurfaceError;
20-
use winit::dpi::PhysicalSize;
20+
use winit::dpi::{PhysicalPosition, PhysicalSize};
2121
use winit::event::WindowEvent;
2222
use winit::event_loop::EventLoopProxy;
2323
use winit::keyboard::{Key, NamedKey};
@@ -255,6 +255,20 @@ impl GuiController {
255255
);
256256
}
257257

258+
pub fn height_offset(&self) -> f64 {
259+
if self.window.fullscreen().is_some() || self.no_gui {
260+
0.0
261+
} else {
262+
MENU_HEIGHT as f64 * self.window.scale_factor()
263+
}
264+
}
265+
266+
pub fn window_to_movie_position(&self, position: PhysicalPosition<f64>) -> (f64, f64) {
267+
let x = position.x;
268+
let y = position.y - self.height_offset();
269+
(x, y)
270+
}
271+
258272
pub fn render(&mut self, mut player: Option<MutexGuard<Player>>) {
259273
let surface_texture = match self.surface.get_current_texture() {
260274
Ok(surface_texture) => surface_texture,

0 commit comments

Comments
 (0)