Skip to content

Commit 0743f2a

Browse files
committed
fix after version bump, bring in touch hacks
1 parent 29564cb commit 0743f2a

File tree

15 files changed

+111
-49
lines changed

15 files changed

+111
-49
lines changed

Cargo.lock

Lines changed: 12 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ opt-level = 's'
2222
[profile.dev]
2323
opt-level = 1
2424

25-
25+
[patch.crates-io]
26+
# winit = { git = "https://github.com/johanhelsing/winit/", branch = "web-touch-pr" }
27+
winit = { git = "https://github.com/yjpark/winit/", branch = "touch-input_0.24.0" }

crates/notation_bevy/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ native = [
3535
]
3636

3737
[dependencies]
38-
notation_bevy_utils = { version = "0.1.0", path = "../notation_bevy_utils" }
38+
notation_bevy_utils = { version = "0.2.0", path = "../notation_bevy_utils" }
3939

40-
notation_model = { version = "0.1.0", path = "../notation_model" }
41-
notation_midi = { version = "0.1.0", path = "../notation_midi" }
40+
notation_model = { version = "0.2.0", path = "../notation_model" }
41+
notation_midi = { version = "0.2.0", path = "../notation_midi" }
4242

4343
serde = {version = "1.0.126", features = ["derive"]}
4444
# https://github.com/serde-rs/serde/issues/1937
@@ -48,8 +48,7 @@ ron = "0.6"
4848
float_eq = "0.6"
4949

5050
bevy = { version = "0.5.0", default-features = false }
51-
winit = "0.24.0"
52-
# winit = { git = "https://github.com/yjpark/winit/", branch = "touch-input_0.24.0", features = [ "web-sys" ] }
51+
5352
rand = "0.8"
5453
getrandom = {version="0.2", features=["wasm-bindgen"]}
5554

crates/notation_bevy/src/app/app.rs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ fn handle_keyboard_inputs(
180180
fn handle_mouse_inputs(
181181
windows: Res<Windows>,
182182
mouse_input: Res<Input<MouseButton>>,
183-
settings: ResMut<NotationSettings>,
183+
settings: Res<NotationSettings>,
184184
mut mouse_motion_events: EventReader<MouseMotion>,
185185
mut mouse_wheel_input: EventReader<bevy::input::mouse::MouseWheel>,
186186
mut mouse_clicked: EventWriter<MouseClickedEvent>,
@@ -218,22 +218,40 @@ fn handle_mouse_inputs(
218218
}
219219

220220
fn handle_touch_inputs(
221+
windows: Res<Windows>,
221222
touch_input: Res<Touches>,
223+
mut app_state: ResMut<NotationAppState>,
222224
mut mouse_clicked: EventWriter<MouseClickedEvent>,
223-
mut mouse_dragged: EventWriter<MouseDraggedEvent>,
225+
//mut mouse_dragged: EventWriter<MouseDraggedEvent>,
224226
) {
225-
for (index, finger) in touch_input.iter().enumerate() {
226-
if index == 0 {
227-
if touch_input.just_pressed(finger.id()) {
228-
mouse_clicked.send(MouseClickedEvent { cursor_position: finger.position() });
229-
}
230-
} else if index == 1 {
231-
if touch_input.just_pressed(finger.id()) {
232-
} else if touch_input.just_released(finger.id()) {
233-
} else {
234-
let delta = finger.position() - finger.previous_position();
235-
mouse_dragged.send(MouseDraggedEvent { delta: delta });
236-
}
227+
for (_index, finger) in touch_input.iter().enumerate() {
228+
if touch_input.just_pressed(finger.id()) {
229+
windows
230+
.get_primary()
231+
.map(|w| (w.physical_width() as f32, w.physical_height() as f32))
232+
.map(| (physical_width, physical_height) | {
233+
/*
234+
Super hacky way to get the touch input in mobile browsers (WASM).
235+
winit not support it yet, using a pull request version, which seems to have some issues
236+
as well, also the touch event triggering is very unreliable during my test, but at least
237+
it's better than no touch at all.
238+
*/
239+
let dpi_x = physical_width / app_state.window_width;
240+
let dpi_y = physical_height / app_state.window_height;
241+
let x = finger.position().x * dpi_x;
242+
let y = app_state.window_height - finger.position().y * dpi_y;
243+
app_state.debug_str = Some(format!("Touch: {} {:?} -> {} {}", _index, finger.position(), x, y));
244+
mouse_clicked.send(MouseClickedEvent { cursor_position: Vec2::new(x, y) });
245+
});
246+
} else if touch_input.just_released(finger.id()) {
247+
app_state.debug_str = None;
248+
} else {
249+
app_state.debug_str = Some(format!("Touch: {} - {:?}", _index, finger.position()));
250+
/*
251+
let delta = finger.position() - finger.previous_position();
252+
app_state.debug_str = Some(format!("Dragged: {}, {:?}", _index, delta));
253+
mouse_dragged.send(MouseDraggedEvent { delta: delta });
254+
*/
237255
}
238256
}
239257
}
@@ -268,6 +286,7 @@ fn on_window_resized(
268286
window.height = evt.height;
269287
app_state.window_width = evt.width;
270288
app_state.window_height = evt.height;
289+
app_state.scale_factor_override = window.scale_factor_override;
271290
window_resized_evts.send(WindowResizedEvent());
272291
}
273292
}

crates/notation_bevy/src/app/app_state.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ pub struct TabPathes(pub Vec<String>);
1010
pub struct NotationAppState {
1111
pub window_width: f32,
1212
pub window_height: f32,
13+
pub scale_factor_override: Option<f64>,
1314
pub tab_path: String,
1415
pub tab_asset: Handle<TabAsset>,
1516
pub tab: Option<Arc<Tab>>,
1617
pub hide_control: bool,
1718
pub viewer_uuid: Uuid,
1819
pub parse_error: Option<ParseError>,
20+
pub debug_str: Option<String>,
1921
}
2022

2123
impl NotationAppState {
@@ -24,12 +26,14 @@ impl NotationAppState {
2426
Self {
2527
window_width: 0.0,
2628
window_height: 0.0,
29+
scale_factor_override: None,
2730
tab_path,
2831
tab_asset,
2932
tab: None,
3033
hide_control: true,
3134
viewer_uuid: Uuid::new_v4(),
3235
parse_error: None,
36+
debug_str: None,
3337
}
3438
}
3539
pub fn change_tab(&mut self, asset_server: &AssetServer, tab_path: String) {

crates/notation_bevy/src/mini/mini_map.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl MiniMap {
7575
) -> Entity {
7676
let minimap = MiniMap::new(tab.clone());
7777
let map_entity = BevyUtil::spawn_child_bundle(commands, entity, ViewBundle::from(minimap));
78-
ColorBackground::spawn(
78+
let background_entity = ColorBackground::spawn(
7979
commands,
8080
map_entity,
8181
theme.core.mini_map_z,
@@ -84,6 +84,8 @@ impl MiniMap {
8484
for bar in tab.bars.iter() {
8585
MiniBar::spawn(commands, assets, theme, map_entity, bar);
8686
}
87+
theme.texts.mini_map
88+
.spawn_debug_text(commands, background_entity, &assets, "");
8789
map_entity
8890
}
8991
pub fn do_layout(
@@ -107,4 +109,20 @@ impl MiniMap {
107109
)
108110
}
109111
}
112+
pub fn update_debug_str(
113+
app_state: Res<NotationAppState>,
114+
background_query: Query<&ColorBackground>,
115+
mut font_query: Query<(&Parent, &mut Text)>,
116+
) {
117+
for (parent, mut text) in font_query.iter_mut() {
118+
if let Ok(_) = background_query.get(parent.0) {
119+
let str = if let Some(debug_str) = &app_state.debug_str {
120+
debug_str.to_string()
121+
} else {
122+
"".to_string()
123+
};
124+
BevyUtil::set_text_value(&mut text, str);
125+
}
126+
}
127+
}
110128
}

crates/notation_bevy/src/mini/mini_plugin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ impl Plugin for MiniPlugin {
1919
SystemSet::on_update(NotationAssetsStates::Loaded)
2020
.with_system(on_bar_playing_changed.system())
2121
.with_system(MiniMap::do_layout.system())
22-
.with_system(MiniBar::on_layout_changed.system()),
22+
.with_system(MiniMap::update_debug_str.system())
23+
.with_system(MiniBar::on_layout_changed.system())
2324
);
2425
}
2526
}

crates/notation_bevy/src/theme/theme_texts.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,26 @@ impl MiniMapTexts {
188188
1.0,
189189
);
190190
}
191+
pub fn spawn_debug_text(
192+
&self,
193+
commands: &mut Commands,
194+
entity: Entity,
195+
assets: &NotationAssets,
196+
text: &str,
197+
) {
198+
//NOTE: not sure why, using HorizontalAlign::Right here got the left behaviour
199+
BevyUtil::spawn_text(
200+
commands,
201+
entity,
202+
text,
203+
assets.en_font.clone(),
204+
24.0,
205+
ThemeColors::hex_linear("000000"),
206+
HorizontalAlign::Center,
207+
VerticalAlign::Center,
208+
0.0,
209+
0.0,
210+
10.0,
211+
);
212+
}
191213
}

crates/notation_bevy_utils/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ ron = "0.6"
3535
float_eq = "0.6"
3636

3737
bevy = { version = "0.5.0", default-features = false }
38-
winit = "0.24.0"
39-
# winit = { git = "https://github.com/yjpark/winit/", branch = "touch-input_0.24.0", features = [ "web-sys" ] }
38+
4039
rand = "0.8"
4140
getrandom = { version="0.2", features=["wasm-bindgen"] }
4241

4342
bevy_prototype_lyon = "0.3.1"
4443
bevy_egui = "0.6"
4544
bevy_easings = "0.4.1"
4645

47-
bevy-inspector-egui = { version = "0.5.1", optional = true }
46+
bevy-inspector-egui = { version = "0.5.1", optional = true }

crates/notation_dsl/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ description = "Fun notation - DSL to create notation files"
1313
proc-macro = true
1414

1515
[dependencies]
16-
notation_proto = { version = "0.1.0", path = "../notation_proto" }
16+
notation_proto = { version = "0.2.0", path = "../notation_proto" }
1717

1818
syn = { version = "1.0", features = ["full"] }
1919
quote = "1.0"

0 commit comments

Comments
 (0)