From 064e11640c7669316a28d880197a12813f686873 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 18 May 2022 18:48:19 +0200 Subject: [PATCH] Create a path we can use to run hour names along --- src/main.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index bca2020..700fc51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use sctk::reexports::client::protocol::{wl_shm, wl_surface}; use sctk::shm::AutoMemPool; use sctk::window::{Event as WEvent, FallbackFrame}; use svg::node::element::path::Data as PathData; -use svg::node::element::{Circle, Group, Line, Path, Rectangle, Style, Text}; +use svg::node::element::{Circle, Definitions, Group, Line, Path, Rectangle, Style, Text}; use svg::node::Text as TextNode; use svg::Document; @@ -24,6 +24,26 @@ fn time_to_degrees(timestamp: i32, // should be time/timestamp seconds_to_degrees(timestamp) } +fn hour_name_path(image_width: u32, outer_r: f32, ring_width: f32) -> Path { + let radius = outer_r - ring_width / 2.0; + let delta_x = radius * (15.0_f32.to_radians() / 2.0).sin(); + let delta_y = radius * (1.0 - (15.0_f32.to_radians() / 2.0).cos()); + let x1 = (image_width as f32) / 2.0 - delta_x; + let y1 = ((image_width as f32) / 2.0 - radius) + delta_y; + + let path_data = PathData::new().move_to((x1, y1)).elliptical_arc_by(( + radius, + radius, + 15, + 0, + 1, + 2.0 * delta_x, + 0, + )); + + Path::new().set("id", "hour-name-path").set("d", path_data) +} + fn hour_marker( hour: i32, image_width: u32, @@ -221,6 +241,8 @@ fn gen_svg() -> Document { .mid-marker {stroke: red;} .dial {stroke-width: 2px; stroke: rgb(238, 187, 85);}", ); + + let definitions = Definitions::new().add(hour_name_path(image_width, outer_r, ring_width)); let mut local_clock = Group::new().set("id", "local-clock"); for hour in 0i32..24 { @@ -392,6 +414,7 @@ fn gen_svg() -> Document { .set("height", 700i32) .set("xmlns:xlink", "http://www.w3.org/1999/xlink") .add(stylesheet) + .add(definitions) .add(border) .add(local_clock) .add(day_parts_group)