lazer pointer wao

Compare changes

Choose any two refs to compare.

Changed files
+42 -16
.cargo
src
+2 -2
.cargo/config.toml
··· 6 6 rustdocflags = ["-Clinker=rust-lld.exe"] 7 7 rustflags = ["-Ctarget-cpu=haswell"] 8 8 9 - # [target.wasm32-unknown-unknown] 10 - # rustflags = ["-Ctarget-feature=+atomics,+bulk-memory,+mutable-globals"] 9 + [target.wasm32-unknown-unknown] 10 + rustflags = ["-Ctarget-feature=+simd128"]
+4 -1
Cargo.toml
··· 45 45 ahash = { version = "0.8", default-features = false, features = ["runtime-rng"] } 46 46 47 47 [profile.release] 48 - debug = true 48 + opt-level = 3 49 + lto = "fat" 50 + codegen-units = 1 51 + panic = "abort"
+5 -1
README.md
··· 1 - lazer pointer wao 1 + app that you can run on your desktop to have people be able to draw over your screen with a lazer pointer. uses `tiny-skia` and `softbuffer`. 2 + 3 + compile with `server` feature on and run that on your desktop, and compile with `client` feature and give that to your friends / host it on your website (it supports WASM, see `build.nu`). set `SERVER_URL` to configure the server URL for clients when building. 4 + 5 + see https://gaze.systems/annoy for a "demo".
+31 -12
src/main.rs
··· 9 9 use tokio::sync::{OnceCell, mpsc}; 10 10 use winit::{ 11 11 application::ApplicationHandler, 12 - event::{ElementState, MouseButton, WindowEvent}, 12 + event::{ElementState, MouseButton, TouchPhase, WindowEvent}, 13 13 event_loop::{ActiveEventLoop, ControlFlow, EventLoop}, 14 14 window::{Window, WindowAttributes, WindowId}, 15 15 }; ··· 199 199 let dy = position.1 - self.mouse_pos.1; 200 200 let distance = (dx * dx + dy * dy).sqrt(); 201 201 202 - if distance > 3.0 { 203 - self.mouse_pos = position; 204 - self.needs_redraw = true; 205 - let msg = WsMessage::Laser(LaserMessage { 206 - x: position.0 as u32, 207 - y: position.1 as u32, 208 - id: self.client_id, 209 - line_id: self.current_line_id, 210 - }); 211 - let _ = self.in_chan.0.try_send(msg); 212 - let _ = self.out_tx.try_send(msg); 202 + if distance < 1.0 { 203 + return; 213 204 } 205 + 206 + self.mouse_pos = position; 207 + self.needs_redraw = true; 208 + let msg = WsMessage::Laser(LaserMessage { 209 + x: position.0 as u32, 210 + y: position.1 as u32, 211 + id: self.client_id, 212 + line_id: self.current_line_id, 213 + }); 214 + let _ = self.in_chan.0.try_send(msg); 215 + let _ = self.out_tx.try_send(msg); 214 216 } 215 217 216 218 fn handle_mouse_release(&mut self) { ··· 284 286 .push(LaserPoint::new(msg, self.clock.now())); 285 287 has_any_points = true; 286 288 } 289 + #[cfg(feature = "client")] 287 290 WsMessage::Mouse(msg) => { 288 291 self.server_mouse_pos = (msg.x as f32, msg.y as f32); 289 292 self.needs_redraw = true; 290 293 } 294 + #[cfg(not(feature = "client"))] 295 + WsMessage::Mouse(_) => {} 291 296 } 292 297 } 293 298 ··· 467 472 WindowEvent::CloseRequested => { 468 473 event_loop.exit(); 469 474 return; 475 + } 476 + WindowEvent::Touch(touch) => { 477 + let pos = (touch.location.x as f32, touch.location.y as f32); 478 + match touch.phase { 479 + TouchPhase::Started => { 480 + self.handle_mouse_press(pos); 481 + } 482 + TouchPhase::Moved => { 483 + self.handle_mouse_move(pos); 484 + } 485 + TouchPhase::Ended | TouchPhase::Cancelled => { 486 + self.handle_mouse_release(); 487 + } 488 + } 470 489 } 471 490 WindowEvent::MouseInput { state, button, .. } => { 472 491 if button == MouseButton::Left {