Skip to content

Commit

Permalink
[WIP] mouse shader example on android w/ touch
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Apr 15, 2023
1 parent eed3e7b commit 545f3af
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
40 changes: 38 additions & 2 deletions examples/runners/wgpu/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use crate::maybe_watch;
use super::Options;
use shared::ShaderConstants;
use winit::{
event::{ElementState, Event, KeyboardInput, MouseButton, VirtualKeyCode, WindowEvent},
event::{
ElementState, Event, KeyboardInput, MouseButton, Touch, TouchPhase, VirtualKeyCode,
WindowEvent,
},
event_loop::{ControlFlow, EventLoop, EventLoopBuilder},
window::Window,
};
Expand Down Expand Up @@ -297,7 +300,40 @@ async fn run(
}
}
Event::WindowEvent {
event: WindowEvent::CursorMoved { position, .. },
event:
WindowEvent::Touch(Touch {
phase: phase @ (TouchPhase::Started | TouchPhase::Ended | TouchPhase::Cancelled),
..
}),
..
} => {
// FIXME(eddyb) deduplicate!
let button = MouseButton::Left;
let mask = 1 << mouse_button_index(button);
match phase {
TouchPhase::Started => {
mouse_button_pressed |= mask;
mouse_button_press_since_last_frame |= mask;

if button == MouseButton::Left {
drag_start_x = cursor_x;
drag_start_y = cursor_y;
drag_end_x = cursor_x;
drag_end_y = cursor_y;
}
}
TouchPhase::Moved => unreachable!(),
TouchPhase::Ended | TouchPhase::Cancelled => mouse_button_pressed &= !mask,
}
}
Event::WindowEvent {
event:
WindowEvent::CursorMoved { position, .. }
| WindowEvent::Touch(Touch {
phase: TouchPhase::Moved,
location: position,
..
}),
..
} => {
cursor_x = position.x as f32;
Expand Down
2 changes: 1 addition & 1 deletion examples/runners/wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn maybe_watch(
#[derive(StructOpt)]
#[structopt(name = "example-runner-wgpu")]
pub struct Options {
#[structopt(short, long, default_value = "Sky")]
#[structopt(short, long, default_value = "Mouse")]
shader: RustGPUShader,
}

Expand Down

0 comments on commit 545f3af

Please sign in to comment.