agg_gui/widget/app/
touch.rs1use super::super::keyboard_scroll;
12use crate::event::Modifiers;
13use crate::touch_emulation::EmuCmd;
14use crate::widget::App;
15
16impl App {
17 pub fn on_touch_start(
18 &mut self,
19 device: crate::touch_state::TouchDeviceId,
20 id: crate::touch_state::TouchId,
21 screen_x: f64,
22 screen_y: f64,
23 force: Option<f32>,
24 ) {
25 let pos = keyboard_scroll::lift_to_world(self.flip_y(screen_x, screen_y));
26 self.touch_state.on_start(device, id, pos, force);
27 crate::touch_points::publish(self.touch_state.active_points());
28 crate::touch_state::note_touch_event();
29 let cmds = self
30 .touch_mouse_emu
31 .on_start(device, id, screen_x, screen_y);
32 self.apply_emu_cmds(cmds);
33 }
34 pub fn on_touch_move(
35 &mut self,
36 device: crate::touch_state::TouchDeviceId,
37 id: crate::touch_state::TouchId,
38 screen_x: f64,
39 screen_y: f64,
40 force: Option<f32>,
41 ) {
42 let pos = keyboard_scroll::lift_to_world(self.flip_y(screen_x, screen_y));
43 self.touch_state.on_move(device, id, pos, force);
44 crate::touch_points::publish(self.touch_state.active_points());
45 crate::touch_state::note_touch_event();
46 let cmds = self.touch_mouse_emu.on_move(device, id, screen_x, screen_y);
47 self.apply_emu_cmds(cmds);
48 }
49 pub fn on_touch_end(
50 &mut self,
51 device: crate::touch_state::TouchDeviceId,
52 id: crate::touch_state::TouchId,
53 ) {
54 self.touch_state.on_end_or_cancel(device, id);
55 crate::touch_points::publish(self.touch_state.active_points());
56 crate::touch_state::note_touch_event();
57 let cmds = self.touch_mouse_emu.on_end(device, id);
58 self.apply_emu_cmds(cmds);
59 }
60 pub fn on_touch_cancel(
61 &mut self,
62 device: crate::touch_state::TouchDeviceId,
63 id: crate::touch_state::TouchId,
64 ) {
65 self.touch_state.on_end_or_cancel(device, id);
66 crate::touch_points::publish(self.touch_state.active_points());
67 crate::touch_state::note_touch_event();
68 let cmds = self.touch_mouse_emu.on_cancel(device, id);
69 self.apply_emu_cmds(cmds);
70 }
71
72 fn apply_emu_cmds(&mut self, cmds: Vec<EmuCmd>) {
77 for cmd in cmds {
78 match cmd {
79 EmuCmd::MouseMove(x, y) => self.on_mouse_move(x, y),
80 EmuCmd::MouseDown(x, y, btn) => self.on_mouse_down(x, y, btn, Modifiers::default()),
81 EmuCmd::MouseUp(x, y, btn) => self.on_mouse_up(x, y, btn, Modifiers::default()),
82 EmuCmd::MouseLeave => self.on_mouse_leave(),
83 }
84 }
85 }
86
87 pub fn active_touch_count(&self) -> usize {
92 self.touch_state.active_count()
93 }
94}