@@ -3,8 +3,8 @@ use crate::messages::portfolio::document::overlays::utility_types::OverlayContex
33use crate :: messages:: portfolio:: document:: utility_types:: misc:: { GridSnapping , GridType } ;
44use crate :: messages:: prelude:: * ;
55use glam:: DVec2 ;
6- use graphene_core:: renderer:: Quad ;
76use graphene_core:: raster:: color:: Color ;
7+ use graphene_core:: renderer:: Quad ;
88
99fn grid_overlay_rectangular ( document : & DocumentMessageHandler , overlay_context : & mut OverlayContext , spacing : DVec2 ) {
1010 let origin = document. snapping_state . grid . origin ;
@@ -34,7 +34,11 @@ fn grid_overlay_rectangular(document: &DocumentMessageHandler, overlay_context:
3434 } else {
3535 DVec2 :: new ( secondary_pos, primary_end)
3636 } ;
37- overlay_context. line ( document_to_viewport. transform_point2 ( start) , document_to_viewport. transform_point2 ( end) , Some ( & grid_color. rgb_hex_prefixed ( ) ) ) ;
37+ overlay_context. line (
38+ document_to_viewport. transform_point2 ( start) ,
39+ document_to_viewport. transform_point2 ( end) ,
40+ Some ( & ( "#" . to_owned ( ) + & grid_color. rgb_hex ( ) ) ) ,
41+ ) ;
3842 }
3943 }
4044}
@@ -62,7 +66,11 @@ fn grid_overlay_isometric(document: &DocumentMessageHandler, overlay_context: &m
6266 let x_pos = ( ( ( min_x - origin. x ) / spacing) . ceil ( ) + line_index as f64 ) * spacing + origin. x ;
6367 let start = DVec2 :: new ( x_pos, min_y) ;
6468 let end = DVec2 :: new ( x_pos, max_y) ;
65- overlay_context. line ( document_to_viewport. transform_point2 ( start) , document_to_viewport. transform_point2 ( end) , Some ( & grid_color. rgb_hex_prefixed ( ) ) ) ;
69+ overlay_context. line (
70+ document_to_viewport. transform_point2 ( start) ,
71+ document_to_viewport. transform_point2 ( end) ,
72+ Some ( & ( "#" . to_owned ( ) + & grid_color. rgb_hex ( ) ) ) ,
73+ ) ;
6674 }
6775
6876 for ( tan, multiply) in [ ( tan_a, -1. ) , ( tan_b, 1. ) ] {
@@ -76,7 +84,11 @@ fn grid_overlay_isometric(document: &DocumentMessageHandler, overlay_context: &m
7684 let y_pos = ( ( ( inverse_project ( & min_y) - origin. y ) / spacing) . ceil ( ) + line_index as f64 ) * spacing + origin. y ;
7785 let start = DVec2 :: new ( min_x, project ( & DVec2 :: new ( min_x, y_pos) ) ) ;
7886 let end = DVec2 :: new ( max_x, project ( & DVec2 :: new ( max_x, y_pos) ) ) ;
79- overlay_context. line ( document_to_viewport. transform_point2 ( start) , document_to_viewport. transform_point2 ( end) , Some ( & grid_color. rgb_hex_prefixed ( ) ) ) ;
87+ overlay_context. line (
88+ document_to_viewport. transform_point2 ( start) ,
89+ document_to_viewport. transform_point2 ( end) ,
90+ Some ( & ( "#" . to_owned ( ) + & grid_color. rgb_hex ( ) ) ) ,
91+ ) ;
8092 }
8193 }
8294}
@@ -99,17 +111,27 @@ fn grid_overlay_dot(document: &DocumentMessageHandler, overlay_context: &mut Ove
99111 let x_pos = ( ( ( min_x - origin. x ) / spacing. x ) . ceil ( ) + line_index as f64 ) * spacing. x + origin. x ;
100112 for line_index in 0 ..=( ( max_y - min_y) / spacing. y ) . ceil ( ) as i32 {
101113 let y_pos = ( ( ( min_y - origin. y ) / spacing. y ) . ceil ( ) + line_index as f64 ) * spacing. y + origin. y ;
102- let circle_pos = DVec2 :: new ( x_pos, y_pos) ;
103- overlay_context. circle ( document_to_viewport. transform_point2 ( circle_pos) , 1. , Some ( & grid_color. rgb_hex_prefixed ( ) ) , Some ( & grid_color. rgb_hex_prefixed ( ) ) ) ;
114+ let circle_pos = DVec2 :: new ( x_pos, y_pos) ;
115+ overlay_context. circle (
116+ document_to_viewport. transform_point2 ( circle_pos) ,
117+ 1. ,
118+ Some ( & ( "#" . to_owned ( ) + & grid_color. rgb_hex ( ) ) ) ,
119+ Some ( & ( "#" . to_owned ( ) + & grid_color. rgb_hex ( ) ) ) ,
120+ ) ;
104121 }
105- }
122+ }
106123}
107124
108125pub fn grid_overlay ( document : & DocumentMessageHandler , overlay_context : & mut OverlayContext ) {
109126 match document. snapping_state . grid . grid_type {
110- GridType :: Rectangle { spacing } => grid_overlay_rectangular ( document, overlay_context, spacing) ,
127+ GridType :: Rectangle { spacing } => {
128+ if document. snapping_state . grid . dot_display {
129+ grid_overlay_dot ( document, overlay_context, spacing)
130+ } else {
131+ grid_overlay_rectangular ( document, overlay_context, spacing)
132+ }
133+ }
111134 GridType :: Isometric { y_axis_spacing, angle_a, angle_b } => grid_overlay_isometric ( document, overlay_context, y_axis_spacing, angle_a, angle_b) ,
112- GridType :: Dot { spacing } => grid_overlay_dot ( document, overlay_context, spacing) ,
113135 }
114136}
115137
@@ -141,6 +163,14 @@ pub fn overlay_options(grid: &GridSnapping) -> Vec<LayoutGroup> {
141163 }
142164 } )
143165 } ;
166+ let update_display = |grid, update : fn ( & mut GridSnapping ) -> Option < & mut bool > | {
167+ update_val :: < CheckboxInput > ( grid, move |grid, val| {
168+ if let Some ( update) = update ( grid) {
169+ * update = val. checked ;
170+ }
171+ } )
172+ } ;
173+
144174 widgets. push ( LayoutGroup :: Row {
145175 widgets : vec ! [
146176 TextLabel :: new( "Origin" ) . table_align( true ) . widget_holder( ) ,
@@ -171,15 +201,11 @@ pub fn overlay_options(grid: &GridSnapping) -> Vec<LayoutGroup> {
171201 RadioEntryData :: new( "isometric" )
172202 . label( "Isometric" )
173203 . on_update( update_val( grid, |grid, _| grid. grid_type = GridType :: ISOMETRIC ) ) ,
174- RadioEntryData :: new( "dot" )
175- . label( "Dot" )
176- . on_update( update_val( grid, |grid, _| grid. grid_type = GridType :: DOT ) ) ,
177204 ] )
178205 . min_width( 200 )
179206 . selected_index( Some ( match grid. grid_type {
180207 GridType :: Rectangle { .. } => 0 ,
181208 GridType :: Isometric { .. } => 1 ,
182- GridType :: Dot { .. } => 2 ,
183209 } ) )
184210 . widget_holder( ) ,
185211 ] ,
@@ -237,38 +263,25 @@ pub fn overlay_options(grid: &GridSnapping) -> Vec<LayoutGroup> {
237263 . widget_holder( ) ,
238264 ] ,
239265 } ) ;
240- } ,
241- GridType :: Dot { spacing } => widgets. push ( LayoutGroup :: Row {
266+ }
267+ }
268+ match grid. grid_type {
269+ GridType :: Rectangle { spacing } => widgets. push ( LayoutGroup :: Row {
242270 widgets : vec ! [
243- TextLabel :: new( "Spacing " ) . table_align( true ) . widget_holder( ) ,
271+ TextLabel :: new( "Dot display " ) . table_align( true ) . widget_holder( ) ,
244272 Separator :: new( SeparatorType :: Unrelated ) . widget_holder( ) ,
245- NumberInput :: new( Some ( spacing. x) )
246- . label( "X" )
247- . unit( " px" )
248- . min( 0. )
249- . min_width( 98 )
250- . on_update( update_origin( grid, |grid| grid. grid_type. dot_spacing( ) . map( |spacing| & mut spacing. x) ) )
251- . widget_holder( ) ,
252- Separator :: new( SeparatorType :: Related ) . widget_holder( ) ,
253- NumberInput :: new( Some ( spacing. y) )
254- . label( "Y" )
255- . unit( " px" )
256- . min( 0. )
257- . min_width( 98 )
258- . on_update( update_origin( grid, |grid| grid. grid_type. dot_spacing( ) . map( |spacing| & mut spacing. y) ) )
259- . widget_holder( ) ,
273+ CheckboxInput :: new( grid. dot_display) . on_update( update_display( grid, |grid| Some ( & mut grid. dot_display) ) ) . widget_holder( ) ,
260274 ] ,
261275 } ) ,
276+ GridType :: Isometric { y_axis_spacing, angle_a, angle_b } => { }
262277 }
263-
264- widgets. push ( LayoutGroup :: Row {
265- widgets : vec ! [
278+ widgets. push ( LayoutGroup :: Row {
279+ widgets : vec ! [
266280 TextLabel :: new( "Color" ) . table_align( true ) . widget_holder( ) ,
267281 Separator :: new( SeparatorType :: Unrelated ) . widget_holder( ) ,
268- ColorButton :: new( Some ( grid. grid_color) )
269- . on_update( update_color( grid, |grid| Some ( & mut grid. grid_color) ) )
270- . widget_holder( ) ,
271- ] } ) ;
282+ ColorButton :: new( Some ( grid. grid_color) ) . on_update( update_color( grid, |grid| Some ( & mut grid. grid_color) ) ) . widget_holder( ) ,
283+ ] ,
284+ } ) ;
272285
273286 widgets
274287}
0 commit comments