Create a path we can use to run hour names along

This commit is contained in:
Gergely Polonkai 2022-05-18 18:48:19 +02:00
parent c6eee17618
commit 064e11640c
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4

View File

@ -9,7 +9,7 @@ use sctk::reexports::client::protocol::{wl_shm, wl_surface};
use sctk::shm::AutoMemPool; use sctk::shm::AutoMemPool;
use sctk::window::{Event as WEvent, FallbackFrame}; use sctk::window::{Event as WEvent, FallbackFrame};
use svg::node::element::path::Data as PathData; 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::node::Text as TextNode;
use svg::Document; use svg::Document;
@ -24,6 +24,26 @@ fn time_to_degrees(timestamp: i32, // should be time/timestamp
seconds_to_degrees(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( fn hour_marker(
hour: i32, hour: i32,
image_width: u32, image_width: u32,
@ -221,6 +241,8 @@ fn gen_svg() -> Document {
.mid-marker {stroke: red;} .mid-marker {stroke: red;}
.dial {stroke-width: 2px; stroke: rgb(238, 187, 85);}", .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"); let mut local_clock = Group::new().set("id", "local-clock");
for hour in 0i32..24 { for hour in 0i32..24 {
@ -392,6 +414,7 @@ fn gen_svg() -> Document {
.set("height", 700i32) .set("height", 700i32)
.set("xmlns:xlink", "http://www.w3.org/1999/xlink") .set("xmlns:xlink", "http://www.w3.org/1999/xlink")
.add(stylesheet) .add(stylesheet)
.add(definitions)
.add(border) .add(border)
.add(local_clock) .add(local_clock)
.add(day_parts_group) .add(day_parts_group)