Skip to content

Commit

Permalink
Merge pull request #227 from StaffEngineer/fix_drawing_interaction
Browse files Browse the repository at this point in the history
Do not draw outside of main viewport
  • Loading branch information
Dimchikkk committed Sep 20, 2023
2 parents b75fa7c + 6257308 commit 29206c8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
with:
toolchain: stable
target: wasm32-unknown-unknown
- name: Update
run: sudo apt-get update
- name: Deps
run: sudo apt-get install g++ pkg-config libx11-dev libasound2-dev libudev-dev
- name: Cache
Expand Down Expand Up @@ -51,6 +53,8 @@ jobs:
with:
toolchain: stable
components: rustfmt, clippy
- name: Update
run: sudo apt-get update
- name: Deps
run: sudo apt-get install g++ pkg-config libx11-dev libasound2-dev libudev-dev
- name: Cache
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ license = "MIT OR Apache-2.0"
description = "App for brainstorming & sharing ideas 🦀 Learning Project"
repository = "https://github.com/StaffEngineer/velo.git"
readme = "Readme.md"
version = "0.9.1"
version = "0.9.2"
edition = "2021"

exclude = ["assets/fonts/*", "velo.gif", "velo.png"]
Expand Down
18 changes: 10 additions & 8 deletions src/ui_plugin/systems/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ pub fn drawing_two_points(
mut app_state: ResMut<AppState>,
mut z_index_local: Local<f32>,
theme: Res<Theme>,
buttons: Res<Input<MouseButton>>,
mut start: Local<Option<Vec2>>,
mut end: Local<Option<Vec2>>,
mut drawing_entity: Local<Option<Entity>>,
Expand All @@ -91,6 +90,7 @@ pub fn drawing_two_points(
(&mut Path, &mut Drawing<(String, Color)>),
With<Drawing<(String, Color)>>,
>,
interaction_query: Query<&Interaction, (Changed<Interaction>, With<MainPanel>)>,
) {
if *previous_draw_mode != ui_state.drawing_two_points_mode.clone()
|| ui_state.entity_to_draw_selected.is_some()
Expand All @@ -105,13 +105,15 @@ pub fn drawing_two_points(
let (camera, camera_transform) = camera_q.single();
let primary_window = windows.single_mut();

if buttons.just_pressed(MouseButton::Left) {
if let Some(pos) = primary_window.cursor_position() {
if let Some(pos) = camera.viewport_to_world_2d(camera_transform, pos) {
if start.is_none() {
*start = Some(pos)
} else if end.is_none() {
*end = Some(pos)
for interaction in interaction_query.iter() {
if *interaction == Interaction::Pressed {
if let Some(pos) = primary_window.cursor_position() {
if let Some(pos) = camera.viewport_to_world_2d(camera_transform, pos) {
if start.is_none() {
*start = Some(pos)
} else if end.is_none() {
*end = Some(pos)
}
}
}
}
Expand Down

0 comments on commit 29206c8

Please sign in to comment.