Add bounded presentation toolbox
This commit is contained in:
parent
0aec6c10c5
commit
3df1300b07
|
|
@ -2245,7 +2245,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pdf-presenter"
|
||||
version = "0.1.66"
|
||||
version = "0.1.67"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"chrono",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ default-members = ["crates/pdf-presenter"]
|
|||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.66"
|
||||
version = "0.1.67"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "https://proxy.dandaedre.com/gitea/idle-org/pdf-presenter"
|
||||
|
|
|
|||
|
|
@ -88,6 +88,9 @@ mod artwork;
|
|||
/// Monotonic elapsed/countdown timer.
|
||||
pub mod timer;
|
||||
|
||||
/// Bounded vector pointer and presentation annotations.
|
||||
pub mod tools;
|
||||
|
||||
/// Editable presentation notes sidecars.
|
||||
pub mod notes;
|
||||
|
||||
|
|
|
|||
|
|
@ -96,6 +96,17 @@ pub fn tr<'a>(ctx: &egui::Context, text: &'a str) -> &'a str {
|
|||
"No slide" => "Aucune diapositive",
|
||||
"End of slides" => "Fin des diapositives",
|
||||
"Size" => "Taille",
|
||||
"Tools" => "Outils",
|
||||
"Off" => "Désactivé",
|
||||
"Pointer" => "Pointeur",
|
||||
"Arrow" => "Flèche",
|
||||
"Highlighter" => "Surligneur",
|
||||
"Color" => "Couleur",
|
||||
"Undo" => "Annuler",
|
||||
"Clear" => "Effacer",
|
||||
"Pointer follows the current slide. Drag to place arrows or highlights. Up to 64 vector marks; slide images are never rerendered." => {
|
||||
"Le pointeur suit la diapositive actuelle. Glissez pour placer des flèches ou des surlignages. Jusqu’à 64 tracés vectoriels ; les images ne sont jamais recalculées."
|
||||
}
|
||||
"Keep header visible" => "Garder l’en-tête visible",
|
||||
"Keep footer visible" => "Garder le pied de page visible",
|
||||
"Show both" => "Afficher les deux",
|
||||
|
|
|
|||
|
|
@ -267,6 +267,15 @@ impl NativeWindow {
|
|||
..setup.map(|s| s.zoom).unwrap_or_default()
|
||||
},
|
||||
);
|
||||
if let Some(setup) = setup {
|
||||
let (target, uv) = presenter_ui::zoom_geometry(
|
||||
ui.max_rect(),
|
||||
[frame.info.width, frame.info.height],
|
||||
view,
|
||||
setup.zoom.keep_fitted_area,
|
||||
);
|
||||
crate::tools::paint(ui.painter(), target, uv, &setup.overlay);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -715,12 +724,36 @@ impl App {
|
|||
if s.browser_preview.take().is_none() {
|
||||
s.execute(Action::CloseBrowser);
|
||||
}
|
||||
} else if s.layout_open || s.displays_open || s.menu_open {
|
||||
} else if s.layout_open || s.displays_open || s.menu_open || s.toolbox.open {
|
||||
s.layout_open = false;
|
||||
s.displays_open = false;
|
||||
s.menu_open = false;
|
||||
s.toolbox.open = false;
|
||||
}
|
||||
}
|
||||
Key::Character(c) if c.eq_ignore_ascii_case("p") => {
|
||||
let tool = if s.toolbox.tool == crate::tools::Tool::Pointer {
|
||||
crate::tools::Tool::Off
|
||||
} else {
|
||||
crate::tools::Tool::Pointer
|
||||
};
|
||||
if s.toolbox.select(tool) {
|
||||
s.new_overlay = true;
|
||||
}
|
||||
s.toolbox.open = true;
|
||||
}
|
||||
Key::Character(c) if c.eq_ignore_ascii_case("a") => {
|
||||
if s.toolbox.select(crate::tools::Tool::Arrow) {
|
||||
s.new_overlay = true;
|
||||
}
|
||||
s.toolbox.open = true;
|
||||
}
|
||||
Key::Character(c) if c.eq_ignore_ascii_case("h") => {
|
||||
if s.toolbox.select(crate::tools::Tool::Highlighter) {
|
||||
s.new_overlay = true;
|
||||
}
|
||||
s.toolbox.open = true;
|
||||
}
|
||||
Key::Character(c) if c.eq_ignore_ascii_case("b") => s.execute(Action::Blank),
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -729,7 +762,7 @@ impl App {
|
|||
fn poll(&mut self, el: &ActiveEventLoop) {
|
||||
let mut repaint = false;
|
||||
if let Some(s) = &mut self.studio {
|
||||
repaint |= s.new_zoom;
|
||||
repaint |= s.new_zoom || s.new_overlay;
|
||||
let before = (
|
||||
s.generation,
|
||||
s.frames.len(),
|
||||
|
|
@ -840,6 +873,7 @@ impl App {
|
|||
s.output_sequence += 1;
|
||||
let state = HostState {
|
||||
zoom: s.zoom,
|
||||
overlay: s.toolbox.overlay.clone(),
|
||||
setup_controls: !s.presentation_started,
|
||||
route_trial: s.route_trial.as_ref().map(|t| t.id),
|
||||
sequence: s.output_sequence,
|
||||
|
|
@ -869,24 +903,28 @@ impl App {
|
|||
if output.tx.try_send(state).is_ok() {
|
||||
s.new_output = false;
|
||||
s.new_zoom = false;
|
||||
s.new_overlay = false;
|
||||
} else {
|
||||
s.output_sequence -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if s.new_zoom
|
||||
if (s.new_zoom || s.new_overlay)
|
||||
&& !s.new_output
|
||||
&& let Some(output) = &self.output
|
||||
{
|
||||
let state = HostState {
|
||||
zoom_only: true,
|
||||
zoom_only: s.new_zoom,
|
||||
zoom: s.zoom,
|
||||
overlay_only: s.new_overlay,
|
||||
overlay: s.toolbox.overlay.clone(),
|
||||
generation: s.buffer_generation(),
|
||||
page: s.requested,
|
||||
..Default::default()
|
||||
};
|
||||
if output.tx.try_send(state).is_ok() {
|
||||
s.new_zoom = false;
|
||||
s.new_overlay = false;
|
||||
}
|
||||
}
|
||||
if s.close_requested {
|
||||
|
|
@ -915,18 +953,26 @@ impl App {
|
|||
break;
|
||||
}
|
||||
};
|
||||
if state.zoom_only {
|
||||
if state.zoom_only || state.overlay_only {
|
||||
if state.generation == host.state.generation && state.page == host.state.page {
|
||||
let before = host.state.zoom;
|
||||
host.state.zoom.accept_presenter(state.zoom);
|
||||
host.zoom_pending = host.state.zoom != state.zoom.normalized();
|
||||
repaint |= before != host.state.zoom;
|
||||
if state.zoom_only {
|
||||
let before = host.state.zoom;
|
||||
host.state.zoom.accept_presenter(state.zoom);
|
||||
host.zoom_pending = host.state.zoom != state.zoom.normalized();
|
||||
repaint |= before != host.state.zoom;
|
||||
}
|
||||
if state.overlay_only {
|
||||
let overlay = state.overlay.normalized();
|
||||
repaint |= host.state.overlay != overlay;
|
||||
host.state.overlay = overlay;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
host.state.zoom.accept_presenter(state.zoom);
|
||||
host.zoom_pending = host.state.zoom != state.zoom.normalized();
|
||||
state.zoom = host.state.zoom;
|
||||
state.overlay = state.overlay.normalized();
|
||||
if !state.blanked {
|
||||
host.close_requested = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ pub struct HostState {
|
|||
#[serde(default)]
|
||||
pub zoom_only: bool,
|
||||
#[serde(default)]
|
||||
pub overlay: crate::tools::Overlay,
|
||||
#[serde(default)]
|
||||
pub overlay_only: bool,
|
||||
#[serde(default)]
|
||||
pub slide_colors: crate::settings::SlideColors,
|
||||
#[serde(default)]
|
||||
pub setup_controls: bool,
|
||||
|
|
@ -77,13 +81,21 @@ pub struct Ack {
|
|||
#[serde(default)]
|
||||
pub buffered: usize,
|
||||
}
|
||||
/// A lightweight crop update must never discard queued frame/routing state.
|
||||
/// Lightweight crop/annotation updates must never discard queued frame/routing state.
|
||||
pub fn coalesce(latest: &mut Option<HostState>, command: HostState) {
|
||||
if command.zoom_only
|
||||
if (command.zoom_only || command.overlay_only)
|
||||
&& let Some(previous) = latest
|
||||
{
|
||||
if previous.generation == command.generation && previous.page == command.page {
|
||||
previous.zoom.accept_presenter(command.zoom);
|
||||
let previous_is_lightweight = previous.zoom_only || previous.overlay_only;
|
||||
if command.zoom_only {
|
||||
previous.zoom.accept_presenter(command.zoom);
|
||||
previous.zoom_only |= previous_is_lightweight;
|
||||
}
|
||||
if command.overlay_only {
|
||||
previous.overlay = command.overlay.normalized();
|
||||
previous.overlay_only |= previous_is_lightweight;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
*latest = Some(command);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use crate::localization::tr;
|
|||
use crate::{
|
||||
settings::{Layout, TimerMode, TimerPosition},
|
||||
studio::{Action, SlideLoadState, Studio},
|
||||
tools::Tool,
|
||||
};
|
||||
use egui::{Color32, Context, FontId, Pos2, Rect, Sense, TextureHandle, TextureOptions, Ui, Vec2};
|
||||
use std::{
|
||||
|
|
@ -325,6 +326,143 @@ fn fullscreen_button(ui: &mut Ui, s: &mut Studio) {
|
|||
}
|
||||
}
|
||||
|
||||
fn tool_button(ui: &mut Ui, toolbox: &mut crate::tools::Toolbox, tool: Tool, label: &str) {
|
||||
if ui.selectable_label(toolbox.tool == tool, label).clicked() {
|
||||
toolbox.select(tool);
|
||||
}
|
||||
}
|
||||
|
||||
fn toolbox_window(ctx: &Context, s: &mut Studio) {
|
||||
if !s.toolbox.open {
|
||||
return;
|
||||
}
|
||||
let mut open = true;
|
||||
let before = (s.toolbox.overlay.pointer, s.toolbox.overlay.marks.len());
|
||||
egui::Window::new(tr(ctx, "Tools"))
|
||||
.id(egui::Id::new("presentation-tools"))
|
||||
.open(&mut open)
|
||||
.default_pos(ctx.content_rect().right_top() + Vec2::new(-330., 72.))
|
||||
.default_width(300.)
|
||||
.resizable(false)
|
||||
.show(ctx, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
tool_button(ui, &mut s.toolbox, Tool::Off, tr(ctx, "Off"));
|
||||
tool_button(ui, &mut s.toolbox, Tool::Pointer, tr(ctx, "Pointer"));
|
||||
tool_button(ui, &mut s.toolbox, Tool::Arrow, tr(ctx, "Arrow"));
|
||||
tool_button(
|
||||
ui,
|
||||
&mut s.toolbox,
|
||||
Tool::Highlighter,
|
||||
tr(ctx, "Highlighter"),
|
||||
);
|
||||
});
|
||||
ui.separator();
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(tr(ctx, "Color"));
|
||||
for color in [
|
||||
[244, 67, 54],
|
||||
[255, 214, 0],
|
||||
[0, 210, 255],
|
||||
[255, 255, 255],
|
||||
] {
|
||||
let (rect, response) = ui.allocate_exact_size(Vec2::splat(28.), Sense::click());
|
||||
ui.painter().circle_filled(
|
||||
rect.center(),
|
||||
9.,
|
||||
Color32::from_rgb(color[0], color[1], color[2]),
|
||||
);
|
||||
if color == s.toolbox.color {
|
||||
ui.painter().circle_stroke(
|
||||
rect.center(),
|
||||
12.,
|
||||
egui::Stroke::new(2_f32, ui.visuals().hyperlink_color),
|
||||
);
|
||||
}
|
||||
if response.clicked() {
|
||||
s.toolbox.color = color;
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.add(egui::Slider::new(&mut s.toolbox.size, 4. ..=32.).text(tr(ctx, "Size")));
|
||||
ui.horizontal(|ui| {
|
||||
if ui
|
||||
.add_enabled(!s.toolbox.overlay.marks.is_empty(), egui::Button::new(tr(ctx, "Undo")))
|
||||
.clicked()
|
||||
{
|
||||
s.toolbox.undo();
|
||||
}
|
||||
if ui
|
||||
.add_enabled(
|
||||
s.toolbox.overlay.pointer.is_some() || !s.toolbox.overlay.marks.is_empty(),
|
||||
egui::Button::new(tr(ctx, "Clear")),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
s.toolbox.clear();
|
||||
}
|
||||
});
|
||||
ui.small(tr(
|
||||
ctx,
|
||||
"Pointer follows the current slide. Drag to place arrows or highlights. Up to 64 vector marks; slide images are never rerendered.",
|
||||
));
|
||||
});
|
||||
s.toolbox.open = open;
|
||||
if (s.toolbox.overlay.pointer, s.toolbox.overlay.marks.len()) != before {
|
||||
s.new_overlay = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn slide_tools(ui: &mut Ui, s: &mut Studio, area: Rect, dimensions: [u32; 2]) {
|
||||
let (target, uv) = zoom_geometry(area, dimensions, s.zoom.view, s.zoom.keep_fitted_area);
|
||||
let sense = match s.toolbox.tool {
|
||||
Tool::Arrow | Tool::Highlighter => Sense::click_and_drag(),
|
||||
Tool::Pointer => Sense::hover(),
|
||||
Tool::Off => Sense::hover(),
|
||||
};
|
||||
let response = ui.interact(target, ui.id().with("slide-tools"), sense);
|
||||
let mut changed = false;
|
||||
match s.toolbox.tool {
|
||||
Tool::Off => changed |= s.toolbox.set_pointer(None),
|
||||
Tool::Pointer => {
|
||||
let point = response
|
||||
.hover_pos()
|
||||
.map(|point| crate::tools::screen_to_page(target, uv, point));
|
||||
changed |= s.toolbox.set_pointer(point);
|
||||
if response.hovered() {
|
||||
ui.ctx().set_cursor_icon(egui::CursorIcon::Crosshair);
|
||||
}
|
||||
}
|
||||
Tool::Arrow | Tool::Highlighter => {
|
||||
changed |= s.toolbox.set_pointer(None);
|
||||
if response.drag_started()
|
||||
&& let Some(point) = response.interact_pointer_pos()
|
||||
{
|
||||
changed |= s
|
||||
.toolbox
|
||||
.begin_mark(crate::tools::screen_to_page(target, uv, point));
|
||||
}
|
||||
if response.dragged()
|
||||
&& let Some(point) = response.interact_pointer_pos()
|
||||
{
|
||||
changed |= s
|
||||
.toolbox
|
||||
.update_mark(crate::tools::screen_to_page(target, uv, point));
|
||||
}
|
||||
if response.drag_stopped() {
|
||||
s.toolbox.end_mark();
|
||||
}
|
||||
if response.hovered() || response.dragged() {
|
||||
ui.ctx().set_cursor_icon(egui::CursorIcon::Crosshair);
|
||||
}
|
||||
}
|
||||
}
|
||||
crate::tools::paint(ui.painter(), target, uv, &s.toolbox.overlay);
|
||||
if changed {
|
||||
s.presentation_action();
|
||||
s.new_overlay = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn button(ui: &mut Ui, label: &str, action: Action, actions: &mut Vec<Action>) {
|
||||
if ui.button(label).clicked() {
|
||||
actions.push(action);
|
||||
|
|
@ -860,7 +998,11 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
|
|||
);
|
||||
if let Some(page) = page {
|
||||
let area = Rect::from_min_max(rect.min + Vec2::new(0., 24.), rect.max);
|
||||
if index == 1 && s.settings.zoom_enabled {
|
||||
if index == 1
|
||||
&& (s.settings.zoom_enabled
|
||||
|| s.toolbox.tool != Tool::Off
|
||||
|| !s.toolbox.overlay.marks.is_empty())
|
||||
{
|
||||
// Mirror the output aspect, not the independently sized presenter pane.
|
||||
// This makes the shared zoom/center produce the same visible page crop.
|
||||
let area = s
|
||||
|
|
@ -870,20 +1012,24 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
|
|||
if s.route_trial.is_none()
|
||||
&& let Some(frame) = s.frame(page)
|
||||
{
|
||||
let (view, response) = zoom_gestures_in(
|
||||
ui,
|
||||
area,
|
||||
[frame.info.width, frame.info.height],
|
||||
s.zoom.view,
|
||||
s.zoom.keep_fitted_area,
|
||||
);
|
||||
response.on_hover_text(tr(
|
||||
&locale,
|
||||
"Scroll to zoom · drag to pan · double-click to fit width / reset",
|
||||
));
|
||||
if view != s.zoom.view {
|
||||
s.set_zoom_from_action(view);
|
||||
let dimensions = [frame.info.width, frame.info.height];
|
||||
if s.toolbox.tool == Tool::Off && s.settings.zoom_enabled {
|
||||
let (view, response) = zoom_gestures_in(
|
||||
ui,
|
||||
area,
|
||||
dimensions,
|
||||
s.zoom.view,
|
||||
s.zoom.keep_fitted_area,
|
||||
);
|
||||
response.on_hover_text(tr(
|
||||
&locale,
|
||||
"Scroll to zoom · drag to pan · double-click to fit width / reset",
|
||||
));
|
||||
if view != s.zoom.view {
|
||||
s.set_zoom_from_action(view);
|
||||
}
|
||||
}
|
||||
slide_tools(ui, s, area, dimensions);
|
||||
}
|
||||
} else {
|
||||
native.image(ui, s, page, area);
|
||||
|
|
@ -1033,6 +1179,9 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
|
|||
if ui.button(tr(&locale, "Layout")).clicked() {
|
||||
s.layout_open = !s.layout_open;
|
||||
}
|
||||
if ui.button(tr(&locale, "Tools")).clicked() {
|
||||
s.toolbox.open = !s.toolbox.open;
|
||||
}
|
||||
fullscreen_button(ui, s);
|
||||
timer_buttons(ui, s);
|
||||
let inactive = s.blanked || s.routes.presentation.is_empty() || s.count() == 0;
|
||||
|
|
@ -1547,6 +1696,7 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
|
|||
});
|
||||
s.displays_open &= open;
|
||||
}
|
||||
toolbox_window(&ctx, s);
|
||||
if s.settings.zoom_enabled && s.zoom_warning && !s.zoom_warning_dismissed {
|
||||
egui::Window::new(tr(&ctx, "Zoom performance"))
|
||||
.collapsible(false).resizable(false).show(&ctx, |ui| {
|
||||
|
|
|
|||
|
|
@ -140,6 +140,8 @@ pub struct Studio {
|
|||
pub new_zoom: bool,
|
||||
pub zoom_warning: bool,
|
||||
pub zoom_warning_dismissed: bool,
|
||||
pub toolbox: crate::tools::Toolbox,
|
||||
pub new_overlay: bool,
|
||||
pub new_output: bool,
|
||||
pub close_requested: bool,
|
||||
failed: HashSet<(usize, u32)>,
|
||||
|
|
@ -242,6 +244,8 @@ impl Studio {
|
|||
new_zoom: false,
|
||||
zoom_warning: false,
|
||||
zoom_warning_dismissed: false,
|
||||
toolbox: Default::default(),
|
||||
new_overlay: false,
|
||||
new_output: true,
|
||||
close_requested: false,
|
||||
failed: HashSet::new(),
|
||||
|
|
@ -460,6 +464,8 @@ impl Studio {
|
|||
self.presentation_started = true;
|
||||
if self.requested != page {
|
||||
self.set_zoom(crate::zoom::View::default());
|
||||
self.toolbox.clear();
|
||||
self.new_overlay = true;
|
||||
self.presentation_action();
|
||||
}
|
||||
self.requested = page;
|
||||
|
|
@ -898,6 +904,8 @@ impl Studio {
|
|||
self.ram_blocked = false;
|
||||
self.failed.clear();
|
||||
self.set_zoom(crate::zoom::View::default());
|
||||
self.toolbox.clear();
|
||||
self.new_overlay = true;
|
||||
self.requested = 0;
|
||||
self.presentation_started = false;
|
||||
self.timer = crate::timer::Timer::default();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,239 @@
|
|||
//! Bounded, resolution-independent presentation annotations.
|
||||
use egui::{Color32, Pos2, Rect, Stroke, Vec2};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const MAX_MARKS: usize = 64;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum Tool {
|
||||
#[default]
|
||||
Off,
|
||||
Pointer,
|
||||
Arrow,
|
||||
Highlighter,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum MarkKind {
|
||||
Arrow,
|
||||
Highlighter,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Mark {
|
||||
pub kind: MarkKind,
|
||||
pub from: [f32; 2],
|
||||
pub to: [f32; 2],
|
||||
pub color: [u8; 3],
|
||||
pub width: f32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Overlay {
|
||||
#[serde(default)]
|
||||
pub pointer: Option<[f32; 2]>,
|
||||
#[serde(default)]
|
||||
pub pointer_color: [u8; 3],
|
||||
#[serde(default)]
|
||||
pub pointer_size: f32,
|
||||
#[serde(default)]
|
||||
pub marks: Vec<Mark>,
|
||||
}
|
||||
|
||||
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.marks.truncate(MAX_MARKS);
|
||||
self.marks.retain_mut(|mark| {
|
||||
let Some(from) = normalized_point(mark.from) else {
|
||||
return false;
|
||||
};
|
||||
let Some(to) = normalized_point(mark.to) else {
|
||||
return false;
|
||||
};
|
||||
mark.from = from;
|
||||
mark.to = to;
|
||||
mark.width = finite_clamp(mark.width, 2., 48., 8.);
|
||||
true
|
||||
});
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn finite_clamp(value: f32, min: f32, max: f32, fallback: f32) -> f32 {
|
||||
if value.is_finite() {
|
||||
value.clamp(min, max)
|
||||
} else {
|
||||
fallback
|
||||
}
|
||||
}
|
||||
|
||||
fn normalized_point(point: [f32; 2]) -> Option<[f32; 2]> {
|
||||
point
|
||||
.iter()
|
||||
.all(|value| value.is_finite())
|
||||
.then(|| point.map(|value| value.clamp(0., 1.)))
|
||||
}
|
||||
|
||||
pub struct Toolbox {
|
||||
pub open: bool,
|
||||
pub tool: Tool,
|
||||
pub color: [u8; 3],
|
||||
pub size: f32,
|
||||
pub overlay: Overlay,
|
||||
drag_mark: Option<usize>,
|
||||
}
|
||||
|
||||
impl Default for Toolbox {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
open: false,
|
||||
tool: Tool::Off,
|
||||
color: [244, 67, 54],
|
||||
size: 10.,
|
||||
overlay: Overlay {
|
||||
pointer_color: [244, 67, 54],
|
||||
pointer_size: 10.,
|
||||
..Default::default()
|
||||
},
|
||||
drag_mark: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Toolbox {
|
||||
pub fn select(&mut self, tool: Tool) -> bool {
|
||||
self.tool = tool;
|
||||
self.drag_mark = None;
|
||||
tool != Tool::Pointer && self.overlay.pointer.take().is_some()
|
||||
}
|
||||
|
||||
pub fn set_pointer(&mut self, point: Option<[f32; 2]>) -> bool {
|
||||
let point = point.and_then(normalized_point);
|
||||
let changed = self.overlay.pointer != point
|
||||
|| self.overlay.pointer_color != self.color
|
||||
|| self.overlay.pointer_size != self.size;
|
||||
self.overlay.pointer = point;
|
||||
self.overlay.pointer_color = self.color;
|
||||
self.overlay.pointer_size = self.size;
|
||||
changed
|
||||
}
|
||||
|
||||
pub fn begin_mark(&mut self, point: [f32; 2]) -> bool {
|
||||
let kind = match self.tool {
|
||||
Tool::Arrow => MarkKind::Arrow,
|
||||
Tool::Highlighter => MarkKind::Highlighter,
|
||||
_ => return false,
|
||||
};
|
||||
if self.overlay.marks.len() == MAX_MARKS {
|
||||
self.overlay.marks.remove(0);
|
||||
}
|
||||
self.overlay.marks.push(Mark {
|
||||
kind,
|
||||
from: point,
|
||||
to: point,
|
||||
color: self.color,
|
||||
width: self.size,
|
||||
});
|
||||
self.drag_mark = Some(self.overlay.marks.len() - 1);
|
||||
true
|
||||
}
|
||||
|
||||
pub fn update_mark(&mut self, point: [f32; 2]) -> bool {
|
||||
let Some(mark) = self
|
||||
.drag_mark
|
||||
.and_then(|index| self.overlay.marks.get_mut(index))
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
let Some(point) = normalized_point(point) else {
|
||||
return false;
|
||||
};
|
||||
if mark.to == point {
|
||||
return false;
|
||||
}
|
||||
mark.to = point;
|
||||
true
|
||||
}
|
||||
|
||||
pub fn end_mark(&mut self) {
|
||||
self.drag_mark = None;
|
||||
}
|
||||
|
||||
pub fn undo(&mut self) -> bool {
|
||||
self.drag_mark = None;
|
||||
self.overlay.marks.pop().is_some()
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) -> bool {
|
||||
self.drag_mark = None;
|
||||
let changed = self.overlay.pointer.take().is_some() || !self.overlay.marks.is_empty();
|
||||
self.overlay.marks.clear();
|
||||
changed
|
||||
}
|
||||
}
|
||||
|
||||
pub fn screen_to_page(target: Rect, uv: Rect, point: Pos2) -> [f32; 2] {
|
||||
let local = (point - target.min) / target.size().max(Vec2::splat(1.));
|
||||
let page = uv.min + local * uv.size();
|
||||
[page.x.clamp(0., 1.), page.y.clamp(0., 1.)]
|
||||
}
|
||||
|
||||
fn page_to_screen(target: Rect, uv: Rect, point: [f32; 2]) -> Option<Pos2> {
|
||||
let point = Pos2::new(point[0], point[1]);
|
||||
uv.contains(point).then(|| {
|
||||
target.min + (point - uv.min) / uv.size().max(Vec2::splat(f32::EPSILON)) * target.size()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn paint(painter: &egui::Painter, target: Rect, uv: Rect, overlay: &Overlay) {
|
||||
for mark in overlay.marks.iter().take(MAX_MARKS) {
|
||||
let (Some(from), Some(to)) = (
|
||||
page_to_screen(target, uv, mark.from),
|
||||
page_to_screen(target, uv, mark.to),
|
||||
) else {
|
||||
continue;
|
||||
};
|
||||
let color = match mark.kind {
|
||||
MarkKind::Arrow => Color32::from_rgb(mark.color[0], mark.color[1], mark.color[2]),
|
||||
MarkKind::Highlighter => {
|
||||
Color32::from_rgba_unmultiplied(mark.color[0], mark.color[1], mark.color[2], 105)
|
||||
}
|
||||
};
|
||||
let width = mark.width * painter.ctx().pixels_per_point().sqrt().clamp(1., 2.);
|
||||
painter.line_segment([from, to], Stroke::new(width, color));
|
||||
if mark.kind == MarkKind::Arrow {
|
||||
let direction = to - from;
|
||||
if direction.length_sq() > 4. {
|
||||
let direction = direction.normalized();
|
||||
let normal = Vec2::new(-direction.y, direction.x);
|
||||
let length = (width * 2.8).clamp(12., 42.);
|
||||
painter.line_segment(
|
||||
[to, to - direction * length + normal * length * 0.45],
|
||||
Stroke::new(width, color),
|
||||
);
|
||||
painter.line_segment(
|
||||
[to, to - direction * length - normal * length * 0.45],
|
||||
Stroke::new(width, color),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(point) = overlay
|
||||
.pointer
|
||||
.and_then(|point| page_to_screen(target, uv, point))
|
||||
{
|
||||
let color = Color32::from_rgb(
|
||||
overlay.pointer_color[0],
|
||||
overlay.pointer_color[1],
|
||||
overlay.pointer_color[2],
|
||||
);
|
||||
painter.circle_filled(point, overlay.pointer_size, color);
|
||||
painter.circle_stroke(
|
||||
point,
|
||||
overlay.pointer_size + 2.,
|
||||
Stroke::new(2_f32, Color32::WHITE),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
use egui::{Pos2, Rect, Vec2};
|
||||
use pdf_presenter::{
|
||||
output::{HostState, coalesce},
|
||||
tools::{MAX_MARKS, Mark, MarkKind, Overlay, Toolbox, screen_to_page},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn overlay_input_is_bounded_and_normalized() {
|
||||
let marks = (0..MAX_MARKS + 10)
|
||||
.map(|_| Mark {
|
||||
kind: MarkKind::Arrow,
|
||||
from: [-1., 0.25],
|
||||
to: [2., 0.75],
|
||||
color: [255, 0, 0],
|
||||
width: 500.,
|
||||
})
|
||||
.collect();
|
||||
let overlay = Overlay {
|
||||
pointer: Some([f32::NAN, 0.]),
|
||||
pointer_size: f32::INFINITY,
|
||||
marks,
|
||||
..Default::default()
|
||||
}
|
||||
.normalized();
|
||||
assert_eq!(overlay.marks.len(), MAX_MARKS);
|
||||
assert_eq!(overlay.marks[0].from, [0., 0.25]);
|
||||
assert_eq!(overlay.marks[0].to, [1., 0.75]);
|
||||
assert_eq!(overlay.marks[0].width, 48.);
|
||||
assert_eq!(overlay.pointer, None);
|
||||
assert_eq!(overlay.pointer_size, 12.);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toolbox_discards_oldest_mark_and_maps_visible_crop() {
|
||||
let mut tools = Toolbox::default();
|
||||
tools.select(pdf_presenter::tools::Tool::Arrow);
|
||||
for index in 0..MAX_MARKS + 1 {
|
||||
assert!(tools.begin_mark([index as f32 / 100., 0.5]));
|
||||
tools.end_mark();
|
||||
}
|
||||
assert_eq!(tools.overlay.marks.len(), MAX_MARKS);
|
||||
assert_eq!(tools.overlay.marks[0].from[0], 0.01);
|
||||
|
||||
let target = Rect::from_min_size(Pos2::new(10., 20.), Vec2::new(200., 100.));
|
||||
let uv = Rect::from_min_max(Pos2::new(0.25, 0.25), Pos2::new(0.75, 0.75));
|
||||
assert_eq!(screen_to_page(target, uv, target.center()), [0.5, 0.5]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overlay_update_coalesces_without_losing_full_output_state() {
|
||||
let mut pending = Some(HostState {
|
||||
generation: 9,
|
||||
page: 3,
|
||||
sequence: 22,
|
||||
monitors: vec!["projector".into()],
|
||||
..Default::default()
|
||||
});
|
||||
let overlay = Overlay {
|
||||
pointer: Some([0.2, 0.7]),
|
||||
pointer_size: 14.,
|
||||
..Default::default()
|
||||
};
|
||||
coalesce(
|
||||
&mut pending,
|
||||
HostState {
|
||||
generation: 9,
|
||||
page: 3,
|
||||
overlay_only: true,
|
||||
overlay: overlay.clone(),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let pending = pending.unwrap();
|
||||
assert_eq!(pending.sequence, 22);
|
||||
assert_eq!(pending.monitors, vec!["projector"]);
|
||||
assert!(!pending.overlay_only);
|
||||
assert_eq!(pending.overlay, overlay.clone().normalized());
|
||||
|
||||
let mut lightweight = Some(HostState {
|
||||
generation: 9,
|
||||
page: 3,
|
||||
overlay_only: true,
|
||||
overlay: overlay.clone(),
|
||||
..Default::default()
|
||||
});
|
||||
coalesce(
|
||||
&mut lightweight,
|
||||
HostState {
|
||||
generation: 9,
|
||||
page: 3,
|
||||
zoom_only: true,
|
||||
zoom: pdf_presenter::zoom::Sync {
|
||||
enabled: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let lightweight = lightweight.unwrap();
|
||||
assert!(lightweight.overlay_only && lightweight.zoom_only);
|
||||
assert_eq!(lightweight.overlay, overlay.normalized());
|
||||
}
|
||||
|
|
@ -2,6 +2,16 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
### 0.1.67
|
||||
|
||||
- Add a presenter toolbox with a low-latency pointer, straight arrows and
|
||||
translucent highlighter strokes. Send normalized vector overlays through a
|
||||
bounded, coalesced output update without rerendering slides or reading files;
|
||||
cap each slide view at 64 marks and provide size, color, undo and clear controls.
|
||||
Pointer/mark activity can start an armed presentation timer. Linux checks pass
|
||||
with 84.30% whole-application coverage; the release binary is rebuilt. Physical
|
||||
output latency and appearance remain separate acceptance checks.
|
||||
|
||||
### 0.1.66
|
||||
|
||||
- Run the optional Linux desktop-launcher installation test only on Linux workers;
|
||||
|
|
|
|||
|
|
@ -171,6 +171,23 @@ The performance watcher counts three consecutive zoomed window draws above 33 ms
|
|||
including software drawing/presentation. The presenter shows the warning locally;
|
||||
output hosts report only a boolean. It does not alter visibility or navigation.
|
||||
|
||||
## Bounded presentation overlays in 0.1.67
|
||||
|
||||
HostState adds `overlay` and default-false `overlay_only`. The overlay contains an
|
||||
optional normalized page-coordinate pointer and at most 64 normalized straight
|
||||
arrow/highlighter marks with RGB color and bounded logical width. Invalid points are
|
||||
dropped, coordinates and widths are clamped, and excess marks are discarded. No
|
||||
notes, source paths or operator UI text enter this payload.
|
||||
|
||||
Overlay-only messages carry page/generation identity and absolute current overlay
|
||||
state. They share the two-slot presenter queue with zoom updates: coalescing merges
|
||||
same-page overlay and zoom fields into a pending full state without replacing frame,
|
||||
preload, routing, fullscreen or visibility data. The host rejects stale page or
|
||||
generation updates. Full state carries the overlay for host recovery. Drawing uses
|
||||
the existing buffered texture plus bounded vector shapes; it performs no PDF render,
|
||||
image decode, texture upload or slide-file access. This remains private same-build
|
||||
IPC.
|
||||
|
||||
|
||||
Since 0.1.60, output heartbeats may include `viewport {monitor, size, fullscreen}`.
|
||||
`size` is the actual reference output window’s physical client size `[width, height]`.
|
||||
|
|
|
|||
|
|
@ -85,6 +85,23 @@ editors and Ctrl/Alt/Command combinations retain keyboard priority. Type a 1-bas
|
|||
number then Enter to jump; Backspace edits and Escape cancels. Out-of-range numbers
|
||||
do not navigate. Output windows accept B/Escape for emergency blanking.
|
||||
|
||||
## Pointer and drawing tools
|
||||
|
||||
Choose **Tools** in the presenter header. **Pointer** follows the mouse over the
|
||||
current-slide preview and appears at the same normalized page position on every
|
||||
presentation output. **Arrow** and **Highlighter** add one straight vector mark per
|
||||
drag. Choose a color and size, then use **Undo** or **Clear** as needed. P toggles the
|
||||
pointer, A selects the arrow and H selects the highlighter when no text editor or
|
||||
modified shortcut has priority. Marks clear when you change slides and are not saved
|
||||
to the source document or settings.
|
||||
|
||||
The toolbox is off by default. It keeps at most 64 marks and draws them over the
|
||||
already buffered slide texture. Pointer movement uses the bounded output-state queue;
|
||||
it does not rerender the PDF, decode an image or read a slide from disk. Selecting a
|
||||
drawing tool temporarily gives dragging to that tool; select **Off** to pan a
|
||||
zoomed slide again. A first pointer or drawing action starts an armed timer just like
|
||||
navigation or zoom.
|
||||
|
||||
## Layout and notes
|
||||
|
||||
Layout independently enables and sizes previous/current/next slides, notes, elapsed
|
||||
|
|
|
|||
Loading…
Reference in New Issue