Use euclid::Scale to convert between physical and logical coord spaces
This commit is contained in:
1 parent
8ba72fd7df
commit
8d17f8e64f
12 files changed
+70
-155
No files matched your search
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
color::Srgba,
|
||||
dpi::{ConvertToLogical, ConvertToPhysical, LogicalPoint},
|
||||
dpi::LogicalPoint,
|
||||
fonts::{Alignment, FontStyle, LayoutJob},
|
||||
math::{Point, Quad, Rect, Size},
|
||||
pob::Context,
|
||||
@@ -357,13 +357,10 @@ unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int {
|
||||
}
|
||||
|
||||
// Align layout origin with the physical pixel grid to reduce blurriness
|
||||
let pixels_per_point = ctx.window_state.scale_factor();
|
||||
let position = position
|
||||
.to_physical::<f32, _>(pixels_per_point)
|
||||
.round()
|
||||
.to_logical(pixels_per_point);
|
||||
let scale_factor = ctx.window_state.scale_factor();
|
||||
let position = (position * scale_factor).round() / scale_factor;
|
||||
|
||||
let layout = ctx.fonts.borrow_mut().layout(job, pixels_per_point);
|
||||
let layout = ctx.fonts.borrow_mut().layout(job, scale_factor);
|
||||
for glyph in &layout.glyphs {
|
||||
ctx.recorder.draw_glyph(
|
||||
glyph.rect.translate(position.to_vector()),
|
||||
|
||||
@@ -10,7 +10,7 @@ pub fn get_screen_size(l: &Lua, _: ()) -> LuaResult<(u32, u32)> {
|
||||
let PhysicalSize { width, height, .. } = ctx.window_state.size;
|
||||
(width, height)
|
||||
} else {
|
||||
let LogicalSize { width, height, .. } = ctx.window_state.logical_size();
|
||||
let LogicalSize { width, height, .. } = ctx.window_state.logical_size().cast();
|
||||
(width, height)
|
||||
};
|
||||
Ok(size)
|
||||
@@ -19,7 +19,7 @@ pub fn get_screen_size(l: &Lua, _: ()) -> LuaResult<(u32, u32)> {
|
||||
pub fn get_screen_scale(l: &Lua, _: ()) -> LuaResult<f32> {
|
||||
let ctx = l.app_data_ref::<Context>().unwrap();
|
||||
let scale_factor = ctx.window_state.scale_factor();
|
||||
Ok(scale_factor)
|
||||
Ok(scale_factor.get())
|
||||
}
|
||||
|
||||
pub fn set_window_title(l: &Lua, title: String) -> LuaResult<()> {
|
||||
@@ -37,8 +37,10 @@ pub fn set_foreground(l: &Lua, _: ()) -> LuaResult<()> {
|
||||
pub fn set_dpi_scale_override(l: &Lua, percent: i32) -> LuaResult<()> {
|
||||
let mut ctx = l.app_data_mut::<Context>().unwrap();
|
||||
match percent {
|
||||
0 => ctx.window_state.scale_factor_override = None,
|
||||
p if p > 0 => ctx.window_state.scale_factor_override = Some(p as f32 / 100.0),
|
||||
0 => ctx.window_state.set_scale_factor_override(None),
|
||||
p if p > 0 => ctx
|
||||
.window_state
|
||||
.set_scale_factor_override(Some(p as f32 / 100.0)),
|
||||
_ => {}
|
||||
}
|
||||
Ok(())
|
||||
@@ -46,7 +48,7 @@ pub fn set_dpi_scale_override(l: &Lua, percent: i32) -> LuaResult<()> {
|
||||
|
||||
pub fn get_dpi_scale_override(l: &Lua, _: ()) -> LuaResult<i32> {
|
||||
let ctx = l.app_data_ref::<Context>().unwrap();
|
||||
match ctx.window_state.scale_factor_override {
|
||||
match ctx.window_state.scale_factor_override() {
|
||||
Some(scale_factor) => Ok((scale_factor * 100.0) as i32),
|
||||
None => Ok(0),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user