142 lines
5.4 KiB
Rust
142 lines
5.4 KiB
Rust
use bevy::ecs::schedule::ShouldRun;
|
|
use bevy::{prelude::*, window::PresentMode, winit::WinitSettings};
|
|
use bevy_egui::{egui, EguiContext, EguiPlugin};
|
|
use bevy_prototype_lyon::prelude::*;
|
|
|
|
use shape_maker::*;
|
|
|
|
fn main() {
|
|
let mut app = App::new();
|
|
|
|
app
|
|
.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())
|
|
;
|
|
|
|
app
|
|
.add_plugins(DefaultPlugins)
|
|
.add_plugin(EguiPlugin)
|
|
.add_plugin(ShapePlugin)
|
|
;
|
|
app
|
|
.add_startup_system(configure_visuals)
|
|
.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 }
|
|
))
|
|
.add_system(action_bar_sys)
|
|
;
|
|
|
|
app.run();
|
|
}
|
|
|
|
fn basic_setup_sys(
|
|
mut coms: Commands,
|
|
) {
|
|
coms.spawn_bundle(OrthographicCameraBundle::new_2d())
|
|
.insert(MainCamera);
|
|
}
|
|
|
|
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| {
|
|
let m = hui.button(egui::RichText::new("M").color(state.current_action_color(&colors, Action::Modify)))
|
|
.on_hover_text("Modify");
|
|
if m.clicked() {
|
|
state.current_action = Action::Modify;
|
|
}
|
|
let c = hui.button(egui::RichText::new("C").color(state.current_action_color(&colors, Action::Create)))
|
|
.on_hover_text("Create");
|
|
if c.clicked() {
|
|
state.current_action = Action::Create;
|
|
}
|
|
let d = hui.button(egui::RichText::new("D").color(state.current_action_color(&colors, Action::Delete)))
|
|
.on_hover_text("Delete");
|
|
if d.clicked() {
|
|
state.current_action = Action::Delete;
|
|
}
|
|
hui.label(" | ");
|
|
|
|
if hui.button(" I ").on_hover_text("Import Image").clicked() {
|
|
println!("Importing Images is still not supported!");
|
|
}
|
|
|
|
hui.label(": :");
|
|
});
|
|
|
|
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;
|
|
// }
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
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 {
|
|
|
|
}
|
|
}
|
|
|