Skip to content

Commit

Permalink
Use sRGBA picker for sphere utility opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
cohaereo committed Jan 13, 2024
1 parent 1963ca6 commit 3a06df4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
12 changes: 1 addition & 11 deletions src/ecs/component_panels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
});
}
}
6 changes: 2 additions & 4 deletions src/ecs/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,15 @@ impl Ruler {

pub struct Sphere {
pub detail: u8,
pub color: [u8; 3],
pub opacity: u8,
pub color: [u8; 4],
pub rainbow: bool,
}

impl Default for Sphere {
fn default() -> Self {
Self {
detail: 4,
color: [255, 255, 255],
opacity: 80,
color: [255, 255, 255, 80],
rainbow: false,
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 3a06df4

Please sign in to comment.