Fix attempt for screen scaling
This commit is contained in:
49
src/gui.rs
49
src/gui.rs
@@ -25,7 +25,7 @@ pub struct PluginGui {
|
||||
_gui_context: Arc<dyn GuiContext>,
|
||||
scaling_factor: f32,
|
||||
|
||||
freshener_bounds: Rect<f32>,
|
||||
freshener_screen_bounds: Rect<f32>,
|
||||
|
||||
freshener_image: Result<ImageId, String>,
|
||||
not_so_fresh_image: Result<ImageId, String>,
|
||||
@@ -72,7 +72,7 @@ impl PluginGui {
|
||||
freshener_image: Err("Not loaded".to_owned()),
|
||||
fresh_dumbledore_image: Err("Not loaded".to_owned()),
|
||||
not_so_fresh_image: Err("Not loaded".to_owned()),
|
||||
freshener_bounds: Rect::default()
|
||||
freshener_screen_bounds: Rect::default()
|
||||
};
|
||||
|
||||
if let Some(context) = window.gl_context() {
|
||||
@@ -118,8 +118,6 @@ impl PluginGui {
|
||||
|
||||
impl WindowHandler for PluginGui {
|
||||
fn on_frame(&mut self, window: &mut baseview::Window) {
|
||||
const WINDOW_WIDTH: f32 = EditorWindow::WINDOW_SIZE.0 as f32;
|
||||
const WINDOW_HEIGHT: f32 = EditorWindow::WINDOW_SIZE.1 as f32;
|
||||
if self.canvas.is_none() {
|
||||
return;
|
||||
}
|
||||
@@ -130,7 +128,7 @@ impl WindowHandler for PluginGui {
|
||||
}
|
||||
|
||||
let font_size = 12.0 * self.scaling_factor;
|
||||
self.freshener_bounds = Rect {
|
||||
self.freshener_screen_bounds = Rect {
|
||||
x: 120.0 * self.scaling_factor,
|
||||
y: 20.0 * self.scaling_factor,
|
||||
width: FRESHENER_FRAME_WIDTH * self.scaling_factor,
|
||||
@@ -147,29 +145,34 @@ impl WindowHandler for PluginGui {
|
||||
unsafe {
|
||||
context.make_current();
|
||||
}
|
||||
let (width, height) = (canvas.width(), canvas.height());
|
||||
let (width, height) = (canvas.width() as f32, canvas.height() as f32);
|
||||
canvas.reset();
|
||||
canvas.clear_rect(0, 0, width, height, Color::rgbaf(0.5, 0.5, 0.6, 1.0));
|
||||
canvas.clear_rect(0, 0, width as u32, height as u32, Color::rgbaf(0.5, 0.5, 0.6, 1.0));
|
||||
|
||||
let mut full_window_path = Path::new();
|
||||
full_window_path.rect(0.0, 0.0, width as f32, height as f32);
|
||||
full_window_path.rect(0.0, 0.0, width, height);
|
||||
|
||||
let mut freshener_path = Path::new();
|
||||
freshener_path.rect(
|
||||
self.freshener_bounds.x,
|
||||
self.freshener_bounds.y,
|
||||
self.freshener_bounds.width,
|
||||
self.freshener_bounds.height,
|
||||
self.freshener_screen_bounds.x,
|
||||
self.freshener_screen_bounds.y,
|
||||
self.freshener_screen_bounds.width,
|
||||
self.freshener_screen_bounds.height,
|
||||
);
|
||||
|
||||
let bbox = canvas.path_bbox(&freshener_path);
|
||||
|
||||
let frame_index = (self.params.freshness.unmodulated_normalized_value()
|
||||
* (FRESHENER_FRAMES - 1) as f32)
|
||||
.floor();
|
||||
let frame_x = (frame_index % FRESHENER_FRAMES_X as f32).floor();
|
||||
let frame_y = (frame_index / FRESHENER_FRAMES_X as f32).floor();
|
||||
|
||||
let freshener_image_source_rect = Rect {
|
||||
x: self.freshener_screen_bounds.x - frame_x * FRESHENER_FRAME_WIDTH,
|
||||
y: self.freshener_screen_bounds.y - frame_y * FRESHENER_FRAME_HEIGHT,
|
||||
width: FRESHENER_FRAME_WIDTH * FRESHENER_FRAMES_X as f32,
|
||||
height: FRESHENER_FRAME_HEIGHT * FRESHENER_FRAMES_Y as f32,
|
||||
};
|
||||
|
||||
if let Ok(not_so_fresh) = self.not_so_fresh_image {
|
||||
canvas.fill_path(
|
||||
&full_window_path,
|
||||
@@ -177,8 +180,8 @@ impl WindowHandler for PluginGui {
|
||||
not_so_fresh,
|
||||
0.0,
|
||||
0.0,
|
||||
WINDOW_WIDTH,
|
||||
WINDOW_HEIGHT,
|
||||
width,
|
||||
height,
|
||||
0.0,
|
||||
1.0,
|
||||
),
|
||||
@@ -191,8 +194,8 @@ impl WindowHandler for PluginGui {
|
||||
fresh_dumbledore,
|
||||
0.0,
|
||||
0.0,
|
||||
WINDOW_WIDTH,
|
||||
WINDOW_HEIGHT,
|
||||
width,
|
||||
height,
|
||||
0.0,
|
||||
self.params.freshness.unmodulated_normalized_value(),
|
||||
),
|
||||
@@ -204,10 +207,10 @@ impl WindowHandler for PluginGui {
|
||||
&freshener_path,
|
||||
&Paint::image(
|
||||
freshener,
|
||||
bbox.minx - frame_x * FRESHENER_FRAME_WIDTH,
|
||||
bbox.miny - frame_y * FRESHENER_FRAME_HEIGHT,
|
||||
self.freshener_bounds.width * FRESHENER_FRAMES_X as f32,
|
||||
self.freshener_bounds.height * FRESHENER_FRAMES_Y as f32,
|
||||
freshener_image_source_rect.x,
|
||||
freshener_image_source_rect.y,
|
||||
freshener_image_source_rect.width,
|
||||
freshener_image_source_rect.height,
|
||||
0.0,
|
||||
1.0,
|
||||
),
|
||||
@@ -281,7 +284,7 @@ impl WindowHandler for PluginGui {
|
||||
self.dirty = true;
|
||||
}
|
||||
Event::Mouse(MouseEvent::ButtonPressed { button, .. }) => {
|
||||
self.dragging = self.freshener_bounds.contains(self.mouse_position)
|
||||
self.dragging = self.freshener_screen_bounds.contains(self.mouse_position)
|
||||
&& button == MouseButton::Left;
|
||||
if self.dragging {
|
||||
setter.begin_set_parameter(&self.params.freshness);
|
||||
|
||||
Reference in New Issue
Block a user