From 82d11b7d3e15d8175accf7579db1fbe528fc6583 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Wed, 16 Dec 2020 13:34:56 +0100 Subject: Add constant for default colours and selection tool --- src/map/wall.rs | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'src/map/wall.rs') 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; 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, transform: &Transform) { +fn draw_round_corner( + rld: &mut RaylibDrawHandle, + pos_px: Vec2, + 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 { Rect::bounding_rect(self.data.start, self.data.end) } -- cgit v1.2.3-70-g09d2