@@ -294,6 +294,147 @@ impl OverlayContext {
294294 self . end_dpi_aware_transform ( ) ;
295295 }
296296
297+ #[ allow( clippy:: too_many_arguments) ]
298+ pub fn dashed_ellipse (
299+ & mut self ,
300+ center : DVec2 ,
301+ radius_x : f64 ,
302+ radius_y : f64 ,
303+ rotation : Option < f64 > ,
304+ start_angle : Option < f64 > ,
305+ end_angle : Option < f64 > ,
306+ counterclockwise : Option < bool > ,
307+ color_fill : Option < & str > ,
308+ color_stroke : Option < & str > ,
309+ dash_width : Option < f64 > ,
310+ dash_gap_width : Option < f64 > ,
311+ dash_offset : Option < f64 > ,
312+ ) {
313+ let color_stroke = color_stroke. unwrap_or ( COLOR_OVERLAY_BLUE ) ;
314+ let center = center. round ( ) ;
315+
316+ self . start_dpi_aware_transform ( ) ;
317+
318+ if let Some ( dash_width) = dash_width {
319+ let dash_gap_width = dash_gap_width. unwrap_or ( 1. ) ;
320+ let array = js_sys:: Array :: new ( ) ;
321+ array. push ( & JsValue :: from ( dash_width) ) ;
322+ array. push ( & JsValue :: from ( dash_gap_width) ) ;
323+
324+ if let Some ( dash_offset) = dash_offset {
325+ if dash_offset != 0. {
326+ self . render_context . set_line_dash_offset ( dash_offset) ;
327+ }
328+ }
329+
330+ self . render_context
331+ . set_line_dash ( & JsValue :: from ( array) )
332+ . map_err ( |error| log:: warn!( "Error drawing dashed line: {:?}" , error) )
333+ . ok ( ) ;
334+ }
335+
336+ self . render_context . begin_path ( ) ;
337+ self . render_context
338+ . ellipse_with_anticlockwise (
339+ center. x ,
340+ center. y ,
341+ radius_x,
342+ radius_y,
343+ rotation. unwrap_or_default ( ) ,
344+ start_angle. unwrap_or_default ( ) ,
345+ end_angle. unwrap_or ( TAU ) ,
346+ counterclockwise. unwrap_or_default ( ) ,
347+ )
348+ . expect ( "Failed to draw ellipse" ) ;
349+ self . render_context . set_stroke_style_str ( color_stroke) ;
350+
351+ if let Some ( fill_color) = color_fill {
352+ self . render_context . set_fill_style_str ( fill_color) ;
353+ self . render_context . fill ( ) ;
354+ }
355+ self . render_context . stroke ( ) ;
356+
357+ // Reset the dash pattern back to solid
358+ if dash_width. is_some ( ) {
359+ self . render_context
360+ . set_line_dash ( & JsValue :: from ( js_sys:: Array :: new ( ) ) )
361+ . map_err ( |error| log:: warn!( "Error drawing dashed line: {:?}" , error) )
362+ . ok ( ) ;
363+ }
364+ if dash_offset. is_some ( ) && dash_offset != Some ( 0. ) {
365+ self . render_context . set_line_dash_offset ( 0. ) ;
366+ }
367+
368+ self . end_dpi_aware_transform ( ) ;
369+ }
370+
371+ pub fn dashed_circle (
372+ & mut self ,
373+ position : DVec2 ,
374+ radius : f64 ,
375+ color_fill : Option < & str > ,
376+ color_stroke : Option < & str > ,
377+ dash_width : Option < f64 > ,
378+ dash_gap_width : Option < f64 > ,
379+ dash_offset : Option < f64 > ,
380+ transform : Option < DAffine2 > ,
381+ ) {
382+ let color_stroke = color_stroke. unwrap_or ( COLOR_OVERLAY_BLUE ) ;
383+ let position = position. round ( ) ;
384+
385+ self . start_dpi_aware_transform ( ) ;
386+
387+ if let Some ( transform) = transform {
388+ let [ a, b, c, d, e, f] = transform. to_cols_array ( ) ;
389+ self . render_context . transform ( a, b, c, d, e, f) . expect ( "Failed to transform circle" ) ;
390+ }
391+
392+ if let Some ( dash_width) = dash_width {
393+ let dash_gap_width = dash_gap_width. unwrap_or ( 1. ) ;
394+ let array = js_sys:: Array :: new ( ) ;
395+ array. push ( & JsValue :: from ( dash_width) ) ;
396+ array. push ( & JsValue :: from ( dash_gap_width) ) ;
397+
398+ if let Some ( dash_offset) = dash_offset {
399+ if dash_offset != 0. {
400+ self . render_context . set_line_dash_offset ( dash_offset) ;
401+ }
402+ }
403+
404+ self . render_context
405+ . set_line_dash ( & JsValue :: from ( array) )
406+ . map_err ( |error| log:: warn!( "Error drawing dashed line: {:?}" , error) )
407+ . ok ( ) ;
408+ }
409+
410+ self . render_context . begin_path ( ) ;
411+ self . render_context . arc ( position. x , position. y , radius, 0. , TAU ) . expect ( "Failed to draw the circle" ) ;
412+ self . render_context . set_stroke_style_str ( color_stroke) ;
413+
414+ if let Some ( fill_color) = color_fill {
415+ self . render_context . set_fill_style_str ( fill_color) ;
416+ self . render_context . fill ( ) ;
417+ }
418+ self . render_context . stroke ( ) ;
419+
420+ // Reset the dash pattern back to solid
421+ if dash_width. is_some ( ) {
422+ self . render_context
423+ . set_line_dash ( & JsValue :: from ( js_sys:: Array :: new ( ) ) )
424+ . map_err ( |error| log:: warn!( "Error drawing dashed line: {:?}" , error) )
425+ . ok ( ) ;
426+ }
427+ if dash_offset. is_some ( ) && dash_offset != Some ( 0. ) {
428+ self . render_context . set_line_dash_offset ( 0. ) ;
429+ }
430+
431+ self . end_dpi_aware_transform ( ) ;
432+ }
433+
434+ pub fn circle ( & mut self , position : DVec2 , radius : f64 , color_fill : Option < & str > , color_stroke : Option < & str > ) {
435+ self . dashed_circle ( position, radius, color_fill, color_stroke, None , None , None , None ) ;
436+ }
437+
297438 pub fn manipulator_handle ( & mut self , position : DVec2 , selected : bool , color : Option < & str > ) {
298439 self . start_dpi_aware_transform ( ) ;
299440
@@ -374,23 +515,6 @@ impl OverlayContext {
374515 self . end_dpi_aware_transform ( ) ;
375516 }
376517
377- pub fn circle ( & mut self , position : DVec2 , radius : f64 , color_fill : Option < & str > , color_stroke : Option < & str > ) {
378- let color_fill = color_fill. unwrap_or ( COLOR_OVERLAY_WHITE ) ;
379- let color_stroke = color_stroke. unwrap_or ( COLOR_OVERLAY_BLUE ) ;
380- let position = position. round ( ) ;
381-
382- self . start_dpi_aware_transform ( ) ;
383-
384- self . render_context . begin_path ( ) ;
385- self . render_context . arc ( position. x , position. y , radius, 0. , TAU ) . expect ( "Failed to draw the circle" ) ;
386- self . render_context . set_fill_style_str ( color_fill) ;
387- self . render_context . set_stroke_style_str ( color_stroke) ;
388- self . render_context . fill ( ) ;
389- self . render_context . stroke ( ) ;
390-
391- self . end_dpi_aware_transform ( ) ;
392- }
393-
394518 pub fn draw_arc ( & mut self , center : DVec2 , radius : f64 , start_from : f64 , end_at : f64 ) {
395519 let segments = ( ( end_at - start_from) . abs ( ) / ( std:: f64:: consts:: PI / 4. ) ) . ceil ( ) as usize ;
396520 let step = ( end_at - start_from) / segments as f64 ;
@@ -591,7 +715,7 @@ impl OverlayContext {
591715 }
592716
593717 pub fn arc_sweep_angle ( & mut self , offset_angle : f64 , angle : f64 , end_point_position : DVec2 , bold_radius : f64 , pivot : DVec2 , text : & str , transform : DAffine2 ) {
594- self . manipulator_handle ( end_point_position, true , Some ( COLOR_OVERLAY_RED ) ) ;
718+ self . manipulator_handle ( end_point_position, true , None ) ;
595719 self . draw_arc_gizmo_angle ( pivot, bold_radius, ARC_SWEEP_GIZMO_RADIUS , offset_angle, angle. to_radians ( ) ) ;
596720 self . text ( & text, COLOR_OVERLAY_BLUE , None , transform, 16. , [ Pivot :: Middle , Pivot :: Middle ] ) ;
597721 }
0 commit comments