Scale tool sizes with slide resolution
This commit is contained in:
parent
8d7fee6984
commit
3aa4f16bd1
|
|
@ -521,7 +521,15 @@ impl NativeWindow {
|
|||
screen_rect: Some(screen),
|
||||
..Default::default()
|
||||
},
|
||||
|ui| crate::tools::paint(ui.painter(), target, uv, &setup.overlay),
|
||||
|ui| {
|
||||
crate::tools::paint_scaled(
|
||||
ui.painter(),
|
||||
target,
|
||||
uv,
|
||||
&setup.overlay,
|
||||
crate::tools::slide_paint_scale(target),
|
||||
)
|
||||
},
|
||||
);
|
||||
let overlay_primitives = self
|
||||
.overlay_ctx
|
||||
|
|
@ -1733,7 +1741,6 @@ impl ApplicationHandler for App {
|
|||
monitor: id.clone(),
|
||||
size: [size.width, size.height],
|
||||
fullscreen: host.state.fullscreen,
|
||||
pixels_per_point: w.window.scale_factor() as f32,
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
|
|||
|
|
@ -58,13 +58,6 @@ pub struct OutputViewport {
|
|||
pub monitor: String,
|
||||
pub size: [u32; 2],
|
||||
pub fullscreen: bool,
|
||||
/// Native pixels per egui point on this Slides window.
|
||||
#[serde(default = "default_pixels_per_point")]
|
||||
pub pixels_per_point: f32,
|
||||
}
|
||||
|
||||
fn default_pixels_per_point() -> f32 {
|
||||
1.
|
||||
}
|
||||
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
|
||||
pub struct Ack {
|
||||
|
|
|
|||
|
|
@ -385,7 +385,13 @@ fn toolbox_window(ctx: &Context, s: &mut Studio) {
|
|||
}
|
||||
}
|
||||
});
|
||||
ui.add(egui::Slider::new(&mut s.toolbox.size, 4. ..=32.).text(tr(ctx, "Size")));
|
||||
ui.add(
|
||||
egui::Slider::new(
|
||||
&mut s.toolbox.size,
|
||||
crate::tools::MIN_TOOL_SIZE..=crate::tools::MAX_TOOL_SIZE,
|
||||
)
|
||||
.text(tr(ctx, "Size")),
|
||||
);
|
||||
ui.horizontal(|ui| {
|
||||
if ui
|
||||
.add_enabled(!s.toolbox.overlay.marks.is_empty(), egui::Button::new(tr(ctx, "Undo")))
|
||||
|
|
@ -458,12 +464,7 @@ fn slide_tools(ui: &mut Ui, s: &mut Studio, area: Rect, dimensions: [u32; 2]) {
|
|||
}
|
||||
}
|
||||
}
|
||||
let paint_scale = s.presentation_viewport_points().map_or(1., |size| {
|
||||
let slides = Rect::from_min_size(Pos2::ZERO, Vec2::new(size[0], size[1]));
|
||||
let (slides_target, _) =
|
||||
zoom_geometry(slides, dimensions, s.zoom.view, s.zoom.keep_fitted_area);
|
||||
crate::tools::preview_paint_scale(target, slides_target)
|
||||
});
|
||||
let paint_scale = crate::tools::slide_paint_scale(target);
|
||||
crate::tools::paint_scaled(ui.painter(), target, uv, &s.toolbox.overlay, paint_scale);
|
||||
if changed {
|
||||
s.presentation_action();
|
||||
|
|
|
|||
|
|
@ -1474,27 +1474,6 @@ impl Studio {
|
|||
}
|
||||
Some([monitor.size.0.max(1), monitor.size.1.max(1)])
|
||||
}
|
||||
/// Logical Slides viewport used to scale annotation widths in Presenter previews.
|
||||
pub fn presentation_viewport_points(&self) -> Option<[f32; 2]> {
|
||||
let monitor = self
|
||||
.routes
|
||||
.presentation
|
||||
.iter()
|
||||
.find_map(|id| self.monitors.iter().find(|m| &m.id == id))?;
|
||||
if let Some(viewport) = &self.output_viewport
|
||||
&& viewport.monitor == monitor.id
|
||||
&& viewport.fullscreen == self.presentation_fullscreen()
|
||||
&& viewport.size.iter().all(|v| *v > 0)
|
||||
{
|
||||
let scale = if viewport.pixels_per_point.is_finite() && viewport.pixels_per_point > 0. {
|
||||
viewport.pixels_per_point
|
||||
} else {
|
||||
1.
|
||||
};
|
||||
return Some(viewport.size.map(|value| value as f32 / scale));
|
||||
}
|
||||
Some([monitor.size.0.max(1) as f32, monitor.size.1.max(1) as f32])
|
||||
}
|
||||
pub fn set_zoom(&mut self, view: crate::zoom::View) {
|
||||
self.zoom.keep_fitted_area = self.settings.zoom_keep_fitted_area;
|
||||
self.zoom.set(self.settings.zoom_enabled, view);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ use egui::{Color32, Pos2, Rect, Stroke, Vec2};
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const MAX_MARKS: usize = 64;
|
||||
pub const MIN_TOOL_SIZE: f32 = 4.;
|
||||
pub const MAX_TOOL_SIZE: f32 = 48.;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum Tool {
|
||||
|
|
@ -43,7 +45,7 @@ pub struct Overlay {
|
|||
impl Overlay {
|
||||
pub fn normalized(mut self) -> Self {
|
||||
self.pointer = self.pointer.and_then(normalized_point);
|
||||
self.pointer_size = finite_clamp(self.pointer_size, 4., 48., 12.);
|
||||
self.pointer_size = finite_clamp(self.pointer_size, MIN_TOOL_SIZE, MAX_TOOL_SIZE, 12.);
|
||||
self.marks.truncate(MAX_MARKS);
|
||||
self.marks.retain_mut(|mark| {
|
||||
let Some(from) = normalized_point(mark.from) else {
|
||||
|
|
@ -54,7 +56,7 @@ impl Overlay {
|
|||
};
|
||||
mark.from = from;
|
||||
mark.to = to;
|
||||
mark.width = finite_clamp(mark.width, 2., 48., 8.);
|
||||
mark.width = finite_clamp(mark.width, 2., MAX_TOOL_SIZE, 8.);
|
||||
true
|
||||
});
|
||||
self
|
||||
|
|
@ -245,10 +247,11 @@ pub fn paint_scaled(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn preview_paint_scale(target: Rect, slides_target: Rect) -> f32 {
|
||||
let ratio = (target.width() / slides_target.width().max(f32::EPSILON))
|
||||
.min(target.height() / slides_target.height().max(f32::EPSILON));
|
||||
finite_clamp(ratio, 0.05, 4., 1.)
|
||||
/// Make a tool size occupy the same share of the slide at every output resolution.
|
||||
/// egui points account for monitor DPI, so 1080 logical points is also the correct
|
||||
/// baseline for a 4K screen using 200% display scaling.
|
||||
pub fn slide_paint_scale(target: Rect) -> f32 {
|
||||
finite_clamp(target.height() / 1080., 0.05, 4., 1.)
|
||||
}
|
||||
|
||||
/// A filled head avoids the three overlapping thick strokes that deform large arrows.
|
||||
|
|
@ -298,10 +301,15 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn preview_scale_keeps_arrow_head_proportional() {
|
||||
let slides = Rect::from_min_size(Pos2::ZERO, Vec2::new(1600., 900.));
|
||||
let preview = Rect::from_min_size(Pos2::ZERO, Vec2::new(400., 225.));
|
||||
assert_eq!(preview_paint_scale(preview, slides), 0.25);
|
||||
fn screen_scale_keeps_tools_and_arrow_heads_proportional() {
|
||||
let hd = Rect::from_min_size(Pos2::ZERO, Vec2::new(1920., 1080.));
|
||||
let uhd = Rect::from_min_size(Pos2::ZERO, Vec2::new(3840., 2160.));
|
||||
let preview = Rect::from_min_size(Pos2::ZERO, Vec2::new(480., 270.));
|
||||
assert_eq!(slide_paint_scale(hd), 1.);
|
||||
assert_eq!(slide_paint_scale(uhd), 2.);
|
||||
assert_eq!(slide_paint_scale(preview), 0.25);
|
||||
assert_eq!(MAX_TOOL_SIZE * slide_paint_scale(hd), 48.);
|
||||
assert_eq!(MAX_TOOL_SIZE * slide_paint_scale(uhd), 96.);
|
||||
|
||||
let (_, full) = arrow_geometry(Pos2::ZERO, Pos2::new(400., 0.), 32., 1.).unwrap();
|
||||
let (_, small) = arrow_geometry(Pos2::ZERO, Pos2::new(100., 0.), 32., 0.25).unwrap();
|
||||
|
|
|
|||
|
|
@ -1361,13 +1361,8 @@ fn zoom_preview_matches_reference_output_crop_and_tracks_window_shape() {
|
|||
monitor: "two".into(),
|
||||
size,
|
||||
fullscreen: s.presentation_fullscreen(),
|
||||
pixels_per_point: 1.,
|
||||
});
|
||||
assert_eq!(s.presentation_viewport(), Some(size));
|
||||
assert_eq!(
|
||||
s.presentation_viewport_points(),
|
||||
Some([size[0] as f32, size[1] as f32])
|
||||
);
|
||||
let output = ctx.run_ui(input(Vec2::new(1280., 900.)), |ui| {
|
||||
presenter_ui::presenter(ui, &mut s, &mut native);
|
||||
});
|
||||
|
|
@ -1391,8 +1386,6 @@ fn zoom_preview_matches_reference_output_crop_and_tracks_window_shape() {
|
|||
);
|
||||
assert!((actual.max - expected.max).length() < 0.0001);
|
||||
}
|
||||
s.output_viewport.as_mut().unwrap().pixels_per_point = 2.;
|
||||
assert_eq!(s.presentation_viewport_points(), Some([450., 600.]));
|
||||
// Stale route/fullscreen reports and minimized windows cannot distort the preview.
|
||||
s.output_viewport.as_mut().unwrap().fullscreen = !s.presentation_fullscreen();
|
||||
assert_eq!(s.presentation_viewport(), Some([1920, 1080]));
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@
|
|||
|
||||
### 0.1.83
|
||||
|
||||
- Scale pointers, highlights, arrow shafts and arrow heads in Presenter previews to
|
||||
match their relative size on the reference Slides screen. Account for the Slides
|
||||
window's DPI scale and preserve the lightweight vector overlay path.
|
||||
- Scale pointers, highlights, arrow shafts and arrow heads against the visible slide
|
||||
height so they occupy a comparable share of Presenter previews, 1080p Slides and
|
||||
4K Slides, including mixed-DPI screens. Raise the selectable maximum from 32 to 48
|
||||
while preserving the lightweight vector overlay path.
|
||||
|
||||
### 0.1.82
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue