2022-07-27 16:51:02 +00:00
|
|
|
use bevy::ecs::schedule::ShouldRun;
|
2022-07-27 09:19:45 +00:00
|
|
|
use bevy::{prelude::*, window::PresentMode, winit::WinitSettings};
|
|
|
|
use bevy_egui::{egui, EguiContext, EguiPlugin};
|
|
|
|
use bevy_prototype_lyon::prelude::*;
|
|
|
|
|
|
|
|
use shape_maker::*;
|
|
|
|
|
|
|
|
fn main() {
|
2022-07-27 16:51:02 +00:00
|
|
|
let mut app = App::new();
|
|
|
|
|
|
|
|
app
|
2022-07-27 09:19:45 +00:00
|
|
|
.insert_resource(ClearColor(Color::rgb(0.1, 0.1, 0.12)))
|
|
|
|
.insert_resource(Msaa { samples: 4 })
|
|
|
|
// Optimal power saving and present mode settings for desktop apps.
|
|
|
|
.insert_resource(WinitSettings::desktop_app())
|
|
|
|
.insert_resource(WindowDescriptor {
|
|
|
|
present_mode: PresentMode::Mailbox,
|
|
|
|
title: "Shape Maker".to_string(),
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.insert_resource(ButtonsColors::default())
|
|
|
|
.insert_resource(UiState::default())
|
2022-07-27 16:51:02 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
app
|
2022-07-27 09:19:45 +00:00
|
|
|
.add_plugins(DefaultPlugins)
|
|
|
|
.add_plugin(EguiPlugin)
|
|
|
|
.add_plugin(ShapePlugin)
|
2022-07-27 16:51:02 +00:00
|
|
|
;
|
|
|
|
app
|
2022-07-27 09:19:45 +00:00
|
|
|
.add_startup_system(configure_visuals)
|
2022-07-27 16:51:02 +00:00
|
|
|
.add_startup_system(basic_setup_sys)
|
|
|
|
.add_system(create_sys.with_run_criteria(|state: Res<UiState>, mut ec: ResMut<EguiContext>|
|
|
|
|
if !ec.ctx_mut().is_pointer_over_area() && state.current_action == Action::Create { ShouldRun::Yes } else { ShouldRun::No }
|
|
|
|
))
|
|
|
|
.add_system(modify_sys.with_run_criteria(|state: Res<UiState>, mut ec: ResMut<EguiContext>|
|
|
|
|
if !ec.ctx_mut().is_pointer_over_area() && state.current_action == Action::Modify { ShouldRun::Yes } else { ShouldRun::No }
|
|
|
|
))
|
2022-07-27 09:19:45 +00:00
|
|
|
.add_system(action_bar_sys)
|
2022-07-27 16:51:02 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
app.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn basic_setup_sys(
|
|
|
|
mut coms: Commands,
|
|
|
|
) {
|
|
|
|
coms.spawn_bundle(OrthographicCameraBundle::new_2d())
|
|
|
|
.insert(MainCamera);
|
2022-07-27 09:19:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn configure_visuals(mut egui_ctx: ResMut<EguiContext>) {
|
|
|
|
egui_ctx.ctx_mut().set_visuals(egui::Visuals {
|
|
|
|
window_rounding: 0.0.into(),
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn action_bar_sys(
|
|
|
|
mut egui_ctx: ResMut<EguiContext>,
|
|
|
|
mut state: ResMut<UiState>,
|
|
|
|
colors: Res<ButtonsColors>,
|
|
|
|
) {
|
|
|
|
egui::Window::new("buttons_float")
|
|
|
|
.default_pos((50.0, 20.0))
|
|
|
|
.title_bar(false)
|
|
|
|
.resizable(false)
|
|
|
|
.show(egui_ctx.ctx_mut(), |ui| {
|
|
|
|
ui.horizontal(|hui| {
|
2022-07-27 16:51:02 +00:00
|
|
|
let m = hui.button(egui::RichText::new("M").color(state.current_action_color(&colors, Action::Modify)))
|
|
|
|
.on_hover_text("Modify");
|
|
|
|
if m.clicked() {
|
2022-07-27 09:19:45 +00:00
|
|
|
state.current_action = Action::Modify;
|
|
|
|
}
|
2022-07-27 16:51:02 +00:00
|
|
|
let c = hui.button(egui::RichText::new("C").color(state.current_action_color(&colors, Action::Create)))
|
|
|
|
.on_hover_text("Create");
|
|
|
|
if c.clicked() {
|
2022-07-27 09:19:45 +00:00
|
|
|
state.current_action = Action::Create;
|
|
|
|
}
|
2022-07-27 16:51:02 +00:00
|
|
|
let d = hui.button(egui::RichText::new("D").color(state.current_action_color(&colors, Action::Delete)))
|
|
|
|
.on_hover_text("Delete");
|
|
|
|
if d.clicked() {
|
2022-07-27 09:19:45 +00:00
|
|
|
state.current_action = Action::Delete;
|
|
|
|
}
|
|
|
|
hui.label(" | ");
|
|
|
|
|
2022-07-27 16:51:02 +00:00
|
|
|
if hui.button(" I ").on_hover_text("Import Image").clicked() {
|
|
|
|
println!("Importing Images is still not supported!");
|
2022-07-27 09:19:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hui.label(": :");
|
|
|
|
});
|
2022-07-27 16:51:02 +00:00
|
|
|
|
|
|
|
if state.current_action == Action::Create {
|
|
|
|
ui.horizontal(|hui| {
|
|
|
|
let tri = hui.button(egui::RichText::new("Tri").color(state.create_shape_color(&colors, CreateShape::Triangle)))
|
|
|
|
.on_hover_text("Triangle - from 3 edges");
|
|
|
|
if tri.clicked() {
|
|
|
|
state.create_shape = CreateShape::Triangle;
|
|
|
|
}
|
|
|
|
let squ = hui.button(egui::RichText::new("Squ").color(state.create_shape_color(&colors, CreateShape::Square)))
|
|
|
|
.on_hover_text("Square - from 2 opposing edges");
|
|
|
|
if squ.clicked() {
|
|
|
|
state.create_shape = CreateShape::Square;
|
|
|
|
}
|
|
|
|
let sce = hui.button(egui::RichText::new("SqC").color(state.create_shape_color(&colors, CreateShape::SquareCenter)))
|
|
|
|
.on_hover_text("Square - from center point and edge");
|
|
|
|
if sce.clicked() {
|
|
|
|
state.create_shape = CreateShape::SquareCenter;
|
|
|
|
}
|
|
|
|
let cir = hui.button(egui::RichText::new("Cir").color(state.create_shape_color(&colors, CreateShape::Circle)))
|
|
|
|
.on_hover_text("Circle - center point and radius");
|
|
|
|
if cir.clicked() {
|
|
|
|
state.create_shape = CreateShape::Circle;
|
|
|
|
}
|
|
|
|
// let cap = hui.button(egui::RichText::new("Cap").color(state.create_shape_color(&colors, CreateShape::Capsule)))
|
|
|
|
// .on_hover_text("Capsule - from 2 center points and a radius");
|
|
|
|
// if cap.clicked() {
|
|
|
|
// state.create_shape = CreateShape::Capsule;
|
|
|
|
// }
|
|
|
|
});
|
|
|
|
}
|
2022-07-27 09:19:45 +00:00
|
|
|
});
|
2022-07-27 16:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn modify_sys(
|
|
|
|
mouse: Res<Input<MouseButton>>,
|
|
|
|
wnds: Res<Windows>,
|
|
|
|
q_cam: Query<(&Camera, &GlobalTransform), With<MainCamera>>,
|
|
|
|
mut paths: Query<&mut Path>,
|
|
|
|
mut transforms: Query<&mut Transform>,
|
|
|
|
shapes: Query<&ShapeData>,
|
|
|
|
) {
|
|
|
|
let mouse_pos = get_mouse_pos(&q_cam, &wnds);
|
|
|
|
|
|
|
|
if let Some(mouse_pos) = mouse_pos {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|