Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: laser tool #1277

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/rnote-compose/src/builders/arrowbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl Buildable for ArrowBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/rnote-compose/src/builders/coordsystem2dbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl Buildable for CoordSystem2DBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/rnote-compose/src/builders/coordsystem3dbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl Buildable for CoordSystem3DBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/rnote-compose/src/builders/cubbezbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ impl Buildable for CubBezBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/rnote-compose/src/builders/ellipsebuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl Buildable for EllipseBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/rnote-compose/src/builders/fociellipsebuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl Buildable for FociEllipseBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/rnote-compose/src/builders/gridbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl Buildable for GridBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/rnote-compose/src/builders/linebuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl Buildable for LineBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/rnote-compose/src/builders/penpathcurvedbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ impl Buildable for PenPathCurvedBuilder {
}
(_, PenEvent::Proximity { .. })
| (_, PenEvent::KeyPressed { .. })
| (_, PenEvent::Text { .. }) => BuilderProgress::InProgress,
| (_, PenEvent::Text { .. })
| (_, PenEvent::AnimationFrame) => BuilderProgress::InProgress,
(_, PenEvent::Cancel) => {
self.reset();

Expand All @@ -87,6 +88,7 @@ impl Buildable for PenPathCurvedBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
8 changes: 5 additions & 3 deletions crates/rnote-compose/src/builders/penpathmodeledbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,18 @@ impl Buildable for PenPathModeledBuilder {

BuilderProgress::Finished(segments)
}
PenEvent::Proximity { .. } | PenEvent::KeyPressed { .. } | PenEvent::Text { .. } => {
BuilderProgress::InProgress
}
PenEvent::Proximity { .. }
| PenEvent::KeyPressed { .. }
| PenEvent::Text { .. }
| PenEvent::AnimationFrame => BuilderProgress::InProgress,
PenEvent::Cancel => BuilderProgress::Finished(vec![]),
};

EventResult {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
8 changes: 5 additions & 3 deletions crates/rnote-compose/src/builders/penpathsimplebuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ impl Buildable for PenPathSimpleBuilder {

BuilderProgress::Finished(segments)
}
PenEvent::Proximity { .. } | PenEvent::KeyPressed { .. } | PenEvent::Text { .. } => {
BuilderProgress::InProgress
}
PenEvent::Proximity { .. }
| PenEvent::KeyPressed { .. }
| PenEvent::Text { .. }
| PenEvent::AnimationFrame => BuilderProgress::InProgress,
PenEvent::Cancel => {
self.reset();
BuilderProgress::Finished(vec![])
Expand All @@ -62,6 +63,7 @@ impl Buildable for PenPathSimpleBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/rnote-compose/src/builders/polygonbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Buildable for PolygonBuilder {
}
_ => BuilderProgress::InProgress,
},
PenEvent::Text { .. } => BuilderProgress::InProgress,
PenEvent::Text { .. } | PenEvent::AnimationFrame => BuilderProgress::InProgress,
PenEvent::Cancel => {
self.pen_state = PenState::Up;
self.finish = false;
Expand All @@ -103,6 +103,7 @@ impl Buildable for PolygonBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/rnote-compose/src/builders/polylinebuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Buildable for PolylineBuilder {
}
_ => BuilderProgress::InProgress,
},
PenEvent::Text { .. } => BuilderProgress::InProgress,
PenEvent::Text { .. } | PenEvent::AnimationFrame => BuilderProgress::InProgress,
PenEvent::Cancel => {
self.pen_state = PenState::Up;
self.finish = false;
Expand All @@ -103,6 +103,7 @@ impl Buildable for PolylineBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/rnote-compose/src/builders/quadbezbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl Buildable for QuadBezBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl Buildable for QuadrantCoordSystem2DBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/rnote-compose/src/builders/rectanglebuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl Buildable for RectangleBuilder {
handled: true,
propagate: EventPropagation::Stop,
progress,
request_animation_frame: false,
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/rnote-compose/src/eventresult.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ where
pub propagate: EventPropagation,
/// The pen progress.
pub progress: T,
/// Whether an animated frame should be requested.
pub request_animation_frame: bool,
}

/// Whether the event should be propagated further.
Expand Down
2 changes: 2 additions & 0 deletions crates/rnote-compose/src/penevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pub enum PenEvent {
/// The committed text.
text: String,
},
/// Animation frame event.
AnimationFrame,
/// Cancel event when the pen vanishes unexpected.
///
/// Should finish all current actions and reset all state.
Expand Down
42 changes: 40 additions & 2 deletions crates/rnote-engine/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Instant;
use tracing::error;
use tracing::{debug, error};

/// An immutable view into the engine, excluding the penholder.
#[derive(Debug)]
Expand All @@ -45,6 +45,7 @@ pub struct EngineView<'a> {
pub store: &'a StrokeStore,
pub camera: &'a Camera,
pub audioplayer: &'a Option<AudioPlayer>,
pub animation: &'a Animation,
}

/// Constructs an `EngineView` from an identifier containing an `Engine` instance.
Expand All @@ -58,6 +59,7 @@ macro_rules! engine_view {
store: &$engine.store,
camera: &$engine.camera,
audioplayer: &$engine.audioplayer,
animation: &$engine.animation,
}
};
}
Expand All @@ -71,6 +73,7 @@ pub struct EngineViewMut<'a> {
pub store: &'a mut StrokeStore,
pub camera: &'a mut Camera,
pub audioplayer: &'a mut Option<AudioPlayer>,
pub animation: &'a mut Animation,
}

/// Constructs an `EngineViewMut` from an identifier containing an `Engine` instance.
Expand All @@ -84,6 +87,7 @@ macro_rules! engine_view_mut {
store: &mut $engine.store,
camera: &mut $engine.camera,
audioplayer: &mut $engine.audioplayer,
animation: &mut $engine.animation,
}
};
}
Expand All @@ -98,6 +102,7 @@ impl<'a> EngineViewMut<'a> {
store: self.store,
camera: self.camera,
audioplayer: self.audioplayer,
animation: self.animation,
}
}
}
Expand Down Expand Up @@ -129,6 +134,8 @@ pub enum EngineTask {
},
/// Requests that the typewriter cursor should be blinked/toggled
BlinkTypewriterCursor,
/// Emits an animation frame event.
// EmitAnimationFrame,
/// Change the permanent zoom to the given value
Zoom(f64),
/// Indicates that the application is quitting. Sent to quit the handler which receives the tasks.
Expand Down Expand Up @@ -179,6 +186,27 @@ impl EngineTaskReceiver {
}
}

#[derive(Debug, Clone, Default)]
pub struct Animation {
frame_in_flight: bool,
}

impl Animation {
pub fn claim_frame(&mut self) -> bool {
if self.frame_in_flight {
debug!("Animation frame already in flight, skipping");
false
} else {
self.frame_in_flight = true;
true
}
}

pub fn reset(&mut self) {
self.frame_in_flight = false;
}
}

/// The engine.
#[derive(Debug, Serialize, Deserialize)]
#[serde(default, rename = "engine")]
Expand All @@ -205,6 +233,8 @@ pub struct Engine {
#[serde(skip)]
audioplayer: Option<AudioPlayer>,
#[serde(skip)]
pub animation: Animation,
#[serde(skip)]
visual_debug: bool,
// the task sender. Must not be modified, only cloned.
#[serde(skip)]
Expand Down Expand Up @@ -241,6 +271,7 @@ impl Default for Engine {
optimize_epd: false,

audioplayer: None,
animation: Animation::default(),
visual_debug: false,
tasks_tx: EngineTaskSender(tasks_tx),
tasks_rx: Some(EngineTaskReceiver(tasks_rx)),
Expand Down Expand Up @@ -457,6 +488,13 @@ impl Engine {
widget_flags.redraw = true;
}
}
// EngineTask::EmitAnimationFrame => {
// self.animation.reset();

// widget_flags |= self
// .handle_pen_event(PenEvent::AnimationFrame, None, Instant::now())
// .1;
// }
EngineTask::Zoom(zoom) => {
widget_flags |= self.camera.zoom_temporarily_to(1.0) | self.camera.zoom_to(zoom);

Expand All @@ -481,7 +519,7 @@ impl Engine {
event: PenEvent,
pen_mode: Option<PenMode>,
now: Instant,
) -> (EventPropagation, WidgetFlags) {
) -> (EventPropagation, WidgetFlags, bool) {
self.penholder
.handle_pen_event(event, pen_mode, now, &mut engine_view_mut!(self))
}
Expand Down
5 changes: 5 additions & 0 deletions crates/rnote-engine/src/pens/brush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,22 @@ impl PenBehaviour for Brush {
handled: true,
propagate: EventPropagation::Stop,
progress: PenProgress::InProgress,
request_animation_frame: false,
}
} else {
EventResult {
handled: false,
propagate: EventPropagation::Proceed,
progress: PenProgress::Idle,
request_animation_frame: false,
}
}
}
(BrushState::Idle, _) => EventResult {
handled: false,
propagate: EventPropagation::Proceed,
progress: PenProgress::Idle,
request_animation_frame: false,
},
(
BrushState::Drawing {
Expand Down Expand Up @@ -161,6 +164,7 @@ impl PenBehaviour for Brush {
handled: true,
propagate: EventPropagation::Stop,
progress: PenProgress::Finished,
request_animation_frame: false,
}
}
(
Expand Down Expand Up @@ -256,6 +260,7 @@ impl PenBehaviour for Brush {
handled,
propagate,
progress,
request_animation_frame: false,
}
}
};
Expand Down
Loading