aboutsummaryrefslogtreecommitdiff
path: root/src/map/wall.rs
diff options
context:
space:
mode:
authorArne Dußin2020-12-16 13:34:56 +0100
committerArne Dußin2020-12-16 13:34:56 +0100
commit82d11b7d3e15d8175accf7579db1fbe528fc6583 (patch)
treebe9a5601e99608966d4ccd146c3bfb3a70c7fc02 /src/map/wall.rs
parent9799d3c6a8f0c242668203a1c70d7b6cfed3e855 (diff)
downloadgraf_karto-82d11b7d3e15d8175accf7579db1fbe528fc6583.tar.gz
graf_karto-82d11b7d3e15d8175accf7579db1fbe528fc6583.zip
Add constant for default colours and selection tool
Diffstat (limited to 'src/map/wall.rs')
-rw-r--r--src/map/wall.rs43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/map/wall.rs b/src/map/wall.rs
index 6c90fda..22393bb 100644
--- a/src/map/wall.rs
+++ b/src/map/wall.rs
@@ -1,15 +1,16 @@
use super::Mappable;
-use crate::math::{LineSegment, Vec2, Rect};
+use crate::colours::DEFAULT_COLOURS;
+use crate::math::{LineSegment, Rect, Vec2};
use crate::scaleable::Scaleable;
use crate::transform::Transform;
use raylib::drawing::{RaylibDraw, RaylibDrawHandle};
-use raylib::ffi::Color;
use std::ops::{Deref, DerefMut};
pub type WallData = LineSegment<f64>;
pub struct Wall {
data: WallData,
+ selected: bool,
round_start: bool,
round_end: bool,
}
@@ -18,6 +19,7 @@ impl Wall {
pub fn from_data(data: WallData, round_start: bool, round_end: bool) -> Self {
Self {
data,
+ selected: false,
round_start,
round_end,
}
@@ -28,15 +30,19 @@ impl Wall {
}
}
-fn draw_round_corner(rld: &mut RaylibDrawHandle, pos_px: Vec2<f64>, transform: &Transform) {
+fn draw_round_corner(
+ rld: &mut RaylibDrawHandle,
+ pos_px: Vec2<f64>,
+ transform: &Transform,
+ selected: bool,
+) {
rld.draw_circle_v(
pos_px,
transform.length_m_to_px(0.05) as f32,
- Color {
- r: 200,
- g: 120,
- b: 120,
- a: 255,
+ if selected {
+ DEFAULT_COLOURS.wall_selected
+ } else {
+ DEFAULT_COLOURS.wall_normal
},
);
}
@@ -49,22 +55,29 @@ impl Mappable for Wall {
start_px,
end_px,
transform.length_m_to_px(0.1) as f32,
- Color {
- r: 200,
- g: 120,
- b: 120,
- a: 255,
+ if self.selected() {
+ DEFAULT_COLOURS.wall_selected
+ } else {
+ DEFAULT_COLOURS.wall_normal
},
);
if self.round_start {
- draw_round_corner(rld, start_px, transform);
+ draw_round_corner(rld, start_px, transform, self.selected());
}
if self.round_end {
- draw_round_corner(rld, end_px, transform);
+ draw_round_corner(rld, end_px, transform, self.selected());
}
}
+ fn set_selected(&mut self, selected: bool) {
+ self.selected = selected;
+ }
+
+ fn selected(&self) -> bool {
+ self.selected
+ }
+
fn bounding_rect(&self) -> Rect<f64> {
Rect::bounding_rect(self.data.start, self.data.end)
}