From 3a06df4df9afd90679481f6c77426d821cd5de3b Mon Sep 17 00:00:00 2001 From: cohaereo Date: Sun, 14 Jan 2024 00:52:11 +0100 Subject: [PATCH] Use sRGBA picker for sphere utility opacity --- src/ecs/component_panels.rs | 12 +----------- src/ecs/components.rs | 6 ++---- src/main.rs | 7 ++++--- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/ecs/component_panels.rs b/src/ecs/component_panels.rs index 96a19911..690591d9 100644 --- a/src/ecs/component_panels.rs +++ b/src/ecs/component_panels.rs @@ -579,23 +579,13 @@ impl ComponentPanel for Sphere { ) }); - ui.separator(); - ui.horizontal(|ui| { - ui.color_edit_button_srgb(&mut self.color) + ui.color_edit_button_srgba_unmultiplied(&mut self.color) .context_menu(|ui| { ui.checkbox(&mut self.rainbow, "Rainbow mode"); }); ui.label("Color"); }); - ui.horizontal(|ui| { - ui.strong("Opacity"); - ui.add( - egui::DragValue::new(&mut self.opacity) - .speed(0.1) - .clamp_range(0u8..=u8::MAX), - ) - }); } } diff --git a/src/ecs/components.rs b/src/ecs/components.rs index 4469a2dc..dccce1a0 100644 --- a/src/ecs/components.rs +++ b/src/ecs/components.rs @@ -133,8 +133,7 @@ impl Ruler { pub struct Sphere { pub detail: u8, - pub color: [u8; 3], - pub opacity: u8, + pub color: [u8; 4], pub rainbow: bool, } @@ -142,8 +141,7 @@ impl Default for Sphere { fn default() -> Self { Self { detail: 4, - color: [255, 255, 255], - opacity: 80, + color: [255, 255, 255, 80], rainbow: false, } } diff --git a/src/main.rs b/src/main.rs index 8cd3bf66..6602069d 100755 --- a/src/main.rs +++ b/src/main.rs @@ -1064,12 +1064,14 @@ fn draw_sphere( start_time: Instant, ) { let color = if sphere.rainbow { - get_rainbow_color(start_time) + let c = get_rainbow_color(start_time); + [c[0], c[1], c[2], sphere.color[3]] } else { sphere.color }; - let cross_color = keep_color_bright(invert_color(color)); + let color_opaque = [color[0], color[1], color[2]]; + let cross_color = keep_color_bright(invert_color(color_opaque)); debugshapes.cross( transform.translation, 0.25 * transform.radius(), @@ -1101,7 +1103,6 @@ fn draw_sphere( egui::Align2::CENTER_BOTTOM, [255, 255, 255], ); - let color = [color[0], color[1], color[2], sphere.opacity]; debugshapes.sphere(transform.translation, transform.radius(), color); }