mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-20 11:28:30 +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,22 +16,35 @@ pub fn select_tool(tool: String) -> Result<(), JsValue> {
|
||||
})
|
||||
}
|
||||
|
||||
static mut POS: (u32, u32) = (0, 0);
|
||||
|
||||
/// Mouse movement with the bounds of the canvas
|
||||
#[wasm_bindgen]
|
||||
pub fn on_mouse_move(x: u32, y: u32) {
|
||||
// SAFETY: This is safe because the code can only ever run in a single thread
|
||||
unsafe {
|
||||
POS = (x, y);
|
||||
}
|
||||
EDITOR_STATE.with(|editor| {
|
||||
let mut editor = editor.borrow_mut();
|
||||
if editor.tools.mouse_is_clicked {
|
||||
editor.tools.trace.append_point(x, y)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Mouse click within the bounds of the canvas
|
||||
#[wasm_bindgen]
|
||||
pub fn on_mouse_click(x: u32, y: u32) -> Result<(), JsValue> {
|
||||
let ev = events::Event::Click(events::MouseState::from_pos(x, y));
|
||||
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_event(ev)).map_err(|err| Error::new(&err.to_string()).into())
|
||||
EDITOR_STATE
|
||||
.with(|editor| {
|
||||
let mut editor = editor.borrow_mut();
|
||||
editor.tools.mouse_is_clicked = true;
|
||||
editor.tools.trace.clear();
|
||||
editor.handle_event(ev)
|
||||
})
|
||||
.map_err(|err| Error::new(&err.to_string()).into())
|
||||
}
|
||||
|
||||
/// Mouse released
|
||||
#[wasm_bindgen]
|
||||
pub fn on_mouse_release() {
|
||||
EDITOR_STATE.with(|editor| editor.borrow_mut().tools.mouse_is_clicked = false)
|
||||
}
|
||||
|
||||
/// Update working colors
|
||||
|
||||
Reference in New Issue
Block a user