ntoes for shapes and grid fills screen
This commit is contained in:
parent
ad05e6d1f2
commit
38261fbf54
7 changed files with 54 additions and 57 deletions
|
@ -328,5 +328,5 @@ fn create_new_shape(coms: &mut Commands, pos: Vec2, create_shape: CreateShape, p
|
|||
};
|
||||
let edges = if center.is_none() { Vec::from([fp]) } else { Vec::new() };
|
||||
|
||||
ShapeData { shape: create_shape, main_shape, edges, center, name: "shape".to_string() }
|
||||
ShapeData { shape: create_shape, main_shape, edges, center, name: "shape".to_string(), note: String::new() }
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy::reflect::TypeUuid;
|
||||
use bevy::render::render_resource::AsBindGroup;
|
||||
use bevy::sprite::{MaterialMesh2dBundle, Material2d};
|
||||
use bevy::sprite::{MaterialMesh2dBundle, Material2d, Mesh2dHandle};
|
||||
|
||||
use crate::MainCamera;
|
||||
|
||||
|
@ -29,8 +29,7 @@ pub fn spawn_grid(
|
|||
) {
|
||||
|
||||
coms.spawn().insert_bundle(MaterialMesh2dBundle {
|
||||
mesh: meshes.add(Mesh::from(shape::Plane { size: 1000.0 })).into(),
|
||||
transform: Transform::from_rotation(Quat::from_rotation_x(std::f32::consts::FRAC_PI_2)),
|
||||
mesh: meshes.add(Mesh::from(shape::Quad::new(Vec2::splat(100.0)))).into(),
|
||||
material: mats.add(GridMaterial { width: 2.0, size: Vec2::splat(15.0), visible: 1 }),
|
||||
..default()
|
||||
});
|
||||
|
@ -62,4 +61,27 @@ pub fn update_grid_position(
|
|||
for mut t in grid.iter_mut() {
|
||||
t.translation = cam_pos;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_grid_size(
|
||||
mut last_size: Local<Vec2>,
|
||||
windows: Res<Windows>,
|
||||
projection: Query<&OrthographicProjection, With<MainCamera>>,
|
||||
grid: Query<&Mesh2dHandle, With<Handle<GridMaterial>>>,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
) {
|
||||
let size = windows.get_primary().map(|w| Vec2::new(w.width(), w.height())).unwrap_or(Vec2::splat(100.0));
|
||||
let zoom = projection.get_single().map(|p| p.scale).unwrap_or(1.0);
|
||||
|
||||
let size = size * zoom * Vec2::new(0.9, 1.0);
|
||||
|
||||
if size != *last_size {
|
||||
for h in grid.iter() {
|
||||
if let Some(m) = meshes.get_mut(&h.0) {
|
||||
*m = Mesh::from(shape::Quad::new(size));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*last_size = size;
|
||||
}
|
|
@ -33,7 +33,7 @@ impl SnapGrid {
|
|||
}
|
||||
impl Default for SnapGrid {
|
||||
fn default() -> Self {
|
||||
Self { width: 15.0, height: 15.0, snap: false, offset: Vec2::ZERO, visible: true }
|
||||
Self { width: 50.0, height: 50.0, snap: false, offset: Vec2::ZERO, visible: true }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,7 @@ pub struct ShapeData {
|
|||
pub main_shape: Entity,
|
||||
pub edges: Vec<Entity>,
|
||||
pub center: Option<Entity>,
|
||||
pub note: String,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -7,6 +7,7 @@ use bevy_egui::{egui, EguiContext, EguiPlugin};
|
|||
use bevy_prototype_lyon::prelude::*;
|
||||
|
||||
use shape_maker::*;
|
||||
use shape_maker::ui::SelectedItem;
|
||||
|
||||
fn main() {
|
||||
let mut app = App::new();
|
||||
|
@ -59,6 +60,10 @@ fn main() {
|
|||
.add_system(scale_points)
|
||||
.add_system(infinite_grid::update_grid_shader)
|
||||
.add_system(infinite_grid::update_grid_position)
|
||||
.add_system(infinite_grid::update_grid_size)
|
||||
.add_system(delete_selected_item_on_del_sys.with_run_criteria(|mut ec: ResMut<EguiContext>|
|
||||
if ec.ctx_mut().wants_keyboard_input() { ShouldRun::No } else { ShouldRun::Yes }
|
||||
))
|
||||
;
|
||||
|
||||
app.run();
|
||||
|
@ -73,11 +78,24 @@ fn basic_setup_sys(
|
|||
|
||||
fn configure_visuals(mut egui_ctx: ResMut<EguiContext>) {
|
||||
egui_ctx.ctx_mut().set_visuals(egui::Visuals {
|
||||
window_rounding: 0.0.into(),
|
||||
window_rounding: 0.5.into(),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
fn delete_selected_item_on_del_sys(
|
||||
mut coms: Commands,
|
||||
mut selected: ResMut<SelectedItem>,
|
||||
keyboard: Res<Input<KeyCode>>,
|
||||
) {
|
||||
if keyboard.just_pressed(KeyCode::Delete) || keyboard.just_pressed(KeyCode::X) {
|
||||
if let Some(e) = selected.0 {
|
||||
coms.entity(e).despawn_recursive();
|
||||
selected.0 = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn zoom_camera_sys(
|
||||
mut mouse_scroll: EventReader<MouseWheel>,
|
||||
mut cam: Query<&mut OrthographicProjection, With<MainCamera>>,
|
||||
|
|
|
@ -200,7 +200,7 @@ pub fn inspector_sys(
|
|||
let mut open = true;
|
||||
|
||||
egui::Window::new("Inspector")
|
||||
.default_pos((350.0, 350.0))
|
||||
.default_pos((20.0, 350.0))
|
||||
.fixed_size((150.0, f32::INFINITY))
|
||||
.title_bar(true)
|
||||
.collapsible(false)
|
||||
|
@ -280,6 +280,9 @@ pub fn inspector_sys(
|
|||
});
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
ui.label("Notes");
|
||||
ui.text_edit_multiline(&mut sd.note);
|
||||
|
||||
|
||||
ui.separator();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue