11use crate :: { draw_pill, utils} ;
22use macroquad:: {
3- prelude:: { mouse_position, Color , IVec2 , BLACK , GREEN , MAGENTA , ORANGE , WHITE , YELLOW } ,
3+ prelude:: { mouse_position, Color , IVec2 , Vec4 , BLACK , GREEN , MAGENTA , YELLOW } ,
44 shapes:: { draw_circle, draw_circle_lines, draw_line, draw_triangle} ,
55 text:: { draw_text, get_text_center, measure_text} ,
66} ;
@@ -19,14 +19,13 @@ pub(crate) struct Graph {
1919 pub ( crate ) end : Option < u8 > ,
2020
2121 /// This is the id of the point that the mouse is currently hovering over
22- pub hovered_point_id : Option < u8 > ,
22+ pub ( crate ) hovered_point_id : Option < u8 > ,
2323
2424 /// This is the id of the point the mouse is currently hovering over and mouse 1 is pressed
2525 pub ( crate ) selected_point_id : Option < u8 > ,
2626
2727 has_hovered_point_been_checked : bool ,
2828 max_amount_of_points : u16 ,
29- pub radius : u8 ,
3029 padding : u8 ,
3130
3231 /// Contains all data for the points
@@ -48,8 +47,16 @@ pub(crate) struct Graph {
4847 /// The 0th element is the start, the last element is the end
4948 path : Option < Vec < u8 > > ,
5049
51- pub angle : f32 ,
52- pub arrow_head_length : f32 ,
50+ /// User adjustable visuals
51+ pub ( crate ) angle : f32 ,
52+ pub ( crate ) arrow_head_length : f32 ,
53+ pub ( crate ) radius : u8 ,
54+ pub ( crate ) line_length : u16 ,
55+ pub ( crate ) path_thickness : f32 ,
56+ pub ( crate ) base_point : f32 ,
57+ pub ( crate ) path_color : [ f32 ; 3 ] ,
58+ pub ( crate ) line_color : [ f32 ; 3 ] ,
59+ pub ( crate ) point_color : [ f32 ; 3 ] ,
5360}
5461
5562impl Default for Graph {
@@ -67,7 +74,13 @@ impl Default for Graph {
6774 lines : HashMap :: < Line , u16 > :: new ( ) ,
6875 path : None ,
6976 angle : 0.436 ,
70- arrow_head_length : 20.0 ,
77+ arrow_head_length : 20. ,
78+ line_length : 1 ,
79+ path_thickness : 2. ,
80+ base_point : 15. ,
81+ path_color : [ 0. , 1. , 0. ] ,
82+ point_color : [ 1. , 0.5 , 0. ] ,
83+ line_color : [ 0. , 1. , 1. ] ,
7184 } ;
7285 }
7386}
@@ -135,7 +148,7 @@ impl Graph {
135148 }
136149
137150 /// Adds a line; if it already exists, the length gets updated
138- pub fn add_line ( & mut self , from_id : u8 , to_id : u8 , line_length : u16 ) {
151+ pub fn add_line ( & mut self , from_id : u8 , to_id : u8 ) {
139152 let new_line = Line {
140153 from : from_id,
141154 to : to_id,
@@ -145,11 +158,11 @@ impl Graph {
145158 . lines
146159 . get_mut ( & new_line)
147160 {
148- Some ( length) => * length = line_length,
161+ Some ( length) => * length = self . line_length ,
149162 None => {
150163 _ = self
151164 . lines
152- . insert ( new_line, line_length)
165+ . insert ( new_line, self . line_length )
153166 } ,
154167 }
155168
@@ -395,8 +408,8 @@ impl Graph {
395408 to_point
396409 . position
397410 . y as f32 ,
398- 2.0 ,
399- WHITE ,
411+ self . path_thickness ,
412+ Color :: from_vec ( Vec4 :: new ( self . path_color [ 0 ] , self . path_color [ 1 ] , self . path_color [ 2 ] , 1. ) ) ,
400413 ) ;
401414 }
402415 }
@@ -416,7 +429,11 @@ impl Graph {
416429 . position
417430 . y as f32 ,
418431 self . radius as f32 ,
419- if self . selected_point_id == Some ( * id) { YELLOW } else { ORANGE } ,
432+ if self . selected_point_id == Some ( * id) {
433+ YELLOW
434+ } else {
435+ Color :: from_vec ( Vec4 :: new ( self . point_color [ 0 ] , self . point_color [ 1 ] , self . point_color [ 2 ] , 1. ) )
436+ } ,
420437 ) ;
421438
422439 let text_center = get_text_center (
@@ -529,26 +546,20 @@ impl Graph {
529546 . position
530547 . x
531548 + ( direction. x as f32
532- * ( ( self . radius + 15 ) as f32
549+ * ( ( self . radius as f32 + self . base_point )
533550 / direction
534551 . as_vec2 ( )
535552 . length ( ) ) ) as i32 ,
536553 y : to_point
537554 . position
538555 . y
539556 + ( direction. y as f32
540- * ( ( self . radius + 15 ) as f32
557+ * ( ( self . radius as f32 + self . base_point )
541558 / direction
542559 . as_vec2 ( )
543560 . length ( ) ) ) as i32 ,
544561 } ;
545562
546- /*
547- // The angle is in radians
548- let angle: f32 = 0.436;
549- let arrow_head_length = 20.0;
550- */
551-
552563 // Calculating the tip of the triangle that touches the node (position + (direction * (radius / length)))
553564 draw_line (
554565 from_point
@@ -570,7 +581,7 @@ impl Graph {
570581 arrow_head_location. x as f32 ,
571582 arrow_head_location. y as f32 ,
572583 1.0 ,
573- Color :: from_rgba ( 0 , 255 , 255 , 255 ) ,
584+ Color :: from_vec ( Vec4 :: new ( self . line_color [ 0 ] , self . line_color [ 1 ] , self . line_color [ 2 ] , 1. ) ) ,
574585 ) ;
575586
576587 /*
@@ -640,7 +651,7 @@ impl Graph {
640651 . sin ( ) ) ) ) as i32 ,
641652 }
642653 . as_vec2 ( ) ,
643- Color :: from_rgba ( 0 , 255 , 255 , 255 ) ,
654+ Color :: from_vec ( Vec4 :: new ( self . line_color [ 0 ] , self . line_color [ 1 ] , self . line_color [ 2 ] , 1. ) ) ,
644655 ) ;
645656
646657 // Right arrow head wing
@@ -696,7 +707,7 @@ impl Graph {
696707 . sin ( ) ) ) ) as i32 ,
697708 }
698709 . as_vec2 ( ) ,
699- Color :: from_rgba ( 0 , 255 , 255 , 255 ) ,
710+ Color :: from_vec ( Vec4 :: new ( self . line_color [ 0 ] , self . line_color [ 1 ] , self . line_color [ 2 ] , 1. ) ) ,
700711 ) ;
701712 } ,
702713
@@ -772,7 +783,7 @@ impl Graph {
772783 + self
773784 . padding
774785 . mul ( 2 ) as f32 ,
775- Color :: from_rgba ( 0 , 255 , 255 , 255 ) ,
786+ Color :: from_vec ( Vec4 :: new ( self . line_color [ 0 ] , self . line_color [ 1 ] , self . line_color [ 2 ] , 1. ) ) ,
776787 ) ;
777788
778789 draw_text (
0 commit comments