Update scale factor when resizing window
This commit is contained in:
@@ -11,7 +11,8 @@ const DROID_SANS_FONT: &'static [u8] = include_bytes!("../../assets/DroidSans.tt
|
|||||||
|
|
||||||
const FRESHENER_IMAGE: &'static [u8] = include_bytes!("../../assets/AirFreshener/sheet.png");
|
const FRESHENER_IMAGE: &'static [u8] = include_bytes!("../../assets/AirFreshener/sheet.png");
|
||||||
const NOT_SO_FRESH_BG_IMAGE: &'static [u8] = include_bytes!("../../assets/AirFreshener/bg0.png");
|
const NOT_SO_FRESH_BG_IMAGE: &'static [u8] = include_bytes!("../../assets/AirFreshener/bg0.png");
|
||||||
const FRESH_DUMBLEDORE_BG_IMAGE: &'static [u8] = include_bytes!("../../assets/AirFreshener/bg1.png");
|
const FRESH_DUMBLEDORE_BG_IMAGE: &'static [u8] =
|
||||||
|
include_bytes!("../../assets/AirFreshener/bg1.png");
|
||||||
const FRESHENER_FRAMES: usize = 256;
|
const FRESHENER_FRAMES: usize = 256;
|
||||||
const FRESHENER_FRAME_WIDTH: usize = 73;
|
const FRESHENER_FRAME_WIDTH: usize = 73;
|
||||||
const FRESHENER_FRAME_HEIGHT: usize = 144;
|
const FRESHENER_FRAME_HEIGHT: usize = 144;
|
||||||
@@ -100,12 +101,6 @@ impl PluginGui {
|
|||||||
this.not_so_fresh_image =
|
this.not_so_fresh_image =
|
||||||
Sprite::new(&mut canvas, NOT_SO_FRESH_BG_IMAGE, scaling_factor.clone());
|
Sprite::new(&mut canvas, NOT_SO_FRESH_BG_IMAGE, scaling_factor.clone());
|
||||||
|
|
||||||
let canvas_width = canvas.width();
|
|
||||||
let editor_width = params.editor_state.size.load().0;
|
|
||||||
if canvas_width != editor_width {
|
|
||||||
this.scaling_factor
|
|
||||||
.store(canvas_width as f32 / editor_width as f32, Ordering::Release);
|
|
||||||
}
|
|
||||||
this.canvas = Some(canvas);
|
this.canvas = Some(canvas);
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -179,6 +174,8 @@ impl WindowHandler for PluginGui {
|
|||||||
{
|
{
|
||||||
use femtovg::Baseline;
|
use femtovg::Baseline;
|
||||||
if let Ok(font) = self.font {
|
if let Ok(font) = self.font {
|
||||||
|
use crate::window::EditorWindow;
|
||||||
|
|
||||||
let mut y = 5.0;
|
let mut y = 5.0;
|
||||||
let mut print = |str: &str| {
|
let mut print = |str: &str| {
|
||||||
for s in str.lines() {
|
for s in str.lines() {
|
||||||
@@ -201,6 +198,8 @@ impl WindowHandler for PluginGui {
|
|||||||
print(&format!("scaling_factor {:?}", scaling_factor));
|
print(&format!("scaling_factor {:?}", scaling_factor));
|
||||||
print(&format!("mouse_pos {:?}", self.mouse_position));
|
print(&format!("mouse_pos {:?}", self.mouse_position));
|
||||||
print(&format!("frame_index {:?}", frame_index));
|
print(&format!("frame_index {:?}", frame_index));
|
||||||
|
print(&format!("windows_size {:?}", EditorWindow::WINDOW_SIZE));
|
||||||
|
print(&format!("canvas_size {:?}", (width, height)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,12 +217,18 @@ impl WindowHandler for PluginGui {
|
|||||||
event: baseview::Event,
|
event: baseview::Event,
|
||||||
) -> baseview::EventStatus {
|
) -> baseview::EventStatus {
|
||||||
let setter = ParamSetter::new(self._gui_context.as_ref());
|
let setter = ParamSetter::new(self._gui_context.as_ref());
|
||||||
let scaling_factor = self.scaling_factor.load(Ordering::Acquire);
|
|
||||||
match event {
|
match event {
|
||||||
Event::Window(WindowEvent::Resized(size)) => {
|
Event::Window(WindowEvent::Resized(size)) => {
|
||||||
let phys_size = size.physical_size();
|
let phys_size = size.physical_size();
|
||||||
if let Some(canvas) = self.canvas.as_mut() {
|
if let Some(canvas) = self.canvas.as_mut() {
|
||||||
canvas.set_size(phys_size.width, phys_size.height, scaling_factor);
|
let canvas_width = canvas.width();
|
||||||
|
let editor_width = self.params.editor_state.size.load().0;
|
||||||
|
let new_scale_factor = canvas_width as f32 / editor_width as f32;
|
||||||
|
|
||||||
|
self.scaling_factor
|
||||||
|
.store(new_scale_factor, Ordering::Release);
|
||||||
|
|
||||||
|
canvas.set_size(phys_size.width, phys_size.height, new_scale_factor);
|
||||||
}
|
}
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user