mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-21 07:28:12 +08:00
Record mouse movement (#51)
* Record mouse movement * Use get for last_point and first_point * Use first and las for first_point and last_point * Remove unnecessary comment * Derive Default for Trace Co-authored-by: RustyNixieTube <RustyNixieTube@users.noreply.github.com>
This commit is contained in:
co-authored by
RustyNixieTube
parent
5ca9c715e5
commit
ea1f9f30f0
@@ -16,8 +16,26 @@ pub enum Response {
|
||||
UpdateCanvas,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct Trace(Vec<MouseState>);
|
||||
|
||||
impl Trace {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
pub fn first_point(&self) -> Option<&MouseState> {
|
||||
self.0.first()
|
||||
}
|
||||
pub fn last_point(&self) -> Option<&MouseState> {
|
||||
self.0.last()
|
||||
}
|
||||
pub fn append_point(&mut self, x: u32, y: u32) {
|
||||
self.0.push(MouseState::from_pos(x, y))
|
||||
}
|
||||
pub fn clear(&mut self) {
|
||||
self.0.clear()
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct MouseState {
|
||||
x: u32,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use crate::Color;
|
||||
use crate::{events::Trace, Color};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct ToolState {
|
||||
pub mouse_is_clicked: bool,
|
||||
pub trace: Trace,
|
||||
pub primary_color: Color,
|
||||
pub secondary_color: Color,
|
||||
pub active_tool: ToolType,
|
||||
@@ -11,6 +13,8 @@ pub struct ToolState {
|
||||
impl ToolState {
|
||||
pub fn new() -> Self {
|
||||
ToolState {
|
||||
mouse_is_clicked: false,
|
||||
trace: Trace::new(),
|
||||
primary_color: Color::BLACK,
|
||||
secondary_color: Color::WHITE,
|
||||
active_tool: ToolType::Select,
|
||||
|
||||
Reference in New Issue
Block a user