default color for making shapes

This commit is contained in:
RustyStriker 2022-09-03 13:46:35 +03:00
parent a7eb757a8f
commit 0ddb8bdba4
5 changed files with 18 additions and 4 deletions

View file

@ -12,7 +12,7 @@ When an item is selected in the items tree window(will be written in gold), clic
## TODO ## TODO
- [ ] Pick default color for shapes - [x] Pick default color for shapes
- [ ] Undo/Redo history - [ ] Undo/Redo history
- [ ] Select item by clicking/double clicking on the relevant shape/image - [ ] Select item by clicking/double clicking on the relevant shape/image

View file

@ -6,6 +6,7 @@ use bevy_prototype_lyon::prelude::*;
pub fn create_sys( pub fn create_sys(
mut coms: Commands, mut coms: Commands,
p_size: Res<PointSize>, p_size: Res<PointSize>,
default_color: Res<DefaultColor>,
state: Res<UiState>, state: Res<UiState>,
mouse: Res<Input<MouseButton>>, mouse: Res<Input<MouseButton>>,
wnds: Res<Windows>, wnds: Res<Windows>,
@ -76,7 +77,7 @@ pub fn create_sys(
else if mouse.just_released(MouseButton::Left) { else if mouse.just_released(MouseButton::Left) {
// We can now spawn a shape in the current mouse position... // We can now spawn a shape in the current mouse position...
// Spawn the first point // Spawn the first point
*shape = Some(create_new_shape(&mut coms, mouse_pos, state.create_shape, p_size.0)); *shape = Some(create_new_shape(&mut coms, mouse_pos, state.create_shape, p_size.0, **default_color));
} }
} }
} }
@ -275,10 +276,10 @@ fn update_main_shape_creation(
} }
} }
fn create_new_shape(coms: &mut Commands, pos: Vec2, create_shape: CreateShape, p_size: f32) -> ShapeData { fn create_new_shape(coms: &mut Commands, pos: Vec2, create_shape: CreateShape, p_size: f32, color: Color) -> ShapeData {
// Shape draw mode... // Shape draw mode...
let draw_mode = DrawMode::Outlined { let draw_mode = DrawMode::Outlined {
fill_mode: FillMode::color(Color::rgba(0.0, 0.5, 0.5, 0.4)), fill_mode: FillMode::color(color),
outline_mode: StrokeMode::new(Color::rgba(0.0, 0.5, 0.5, 0.6), 3.0), outline_mode: StrokeMode::new(Color::rgba(0.0, 0.5, 0.5, 0.6), 3.0),
}; };

View file

@ -13,6 +13,9 @@ pub use modify::modify_sys;
pub use create::create_sys; pub use create::create_sys;
pub use helpers::*; pub use helpers::*;
#[derive(Debug, Clone, Deref, DerefMut)]
pub struct DefaultColor(pub Color);
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct SnapGrid { pub struct SnapGrid {
pub width: f32, pub width: f32,

View file

@ -28,6 +28,7 @@ fn main() {
.insert_resource(SnapGrid::default()) .insert_resource(SnapGrid::default())
.insert_resource(ui::SelectedItem::default()) .insert_resource(ui::SelectedItem::default())
.insert_resource(ShouldImportExport::default()) .insert_resource(ShouldImportExport::default())
.insert_resource(DefaultColor(Color::rgba(0.0, 0.5, 0.5, 0.4)))
; ;
app app

View file

@ -12,6 +12,7 @@ pub fn action_bar_sys(
assets: Res<AssetServer>, assets: Res<AssetServer>,
mut egui_ctx: ResMut<EguiContext>, mut egui_ctx: ResMut<EguiContext>,
mut state: ResMut<UiState>, mut state: ResMut<UiState>,
mut default_color: ResMut<DefaultColor>,
colors: Res<ButtonsColors>, colors: Res<ButtonsColors>,
) { ) {
egui::Window::new("buttons_float") egui::Window::new("buttons_float")
@ -76,6 +77,14 @@ pub fn action_bar_sys(
// state.create_shape = CreateShape::Capsule; // state.create_shape = CreateShape::Capsule;
// } // }
}); });
ui.horizontal(|hui| {
hui.label("Color: ");
let c = **default_color;
let mut color = [c.r(), c.g(), c.b(), c.a()];
if hui.color_edit_button_rgba_unmultiplied(&mut color).changed() {
**default_color = Color::from(color);
}
});
} }
}); });
} }