From 1268e86b454fbfa22c9c20427e4e9d90ab07b951 Mon Sep 17 00:00:00 2001 From: schaumtier Date: Thu, 19 Dec 2024 14:56:23 +0000 Subject: [PATCH 1/5] added option to specify the "corner roundness" --- README.md | 2 ++ src/command_line.rs | 5 +++++ src/configuration.rs | 13 +++++++++++++ src/style.rs | 18 ++++++++++++++---- src/tools/blur.rs | 12 +++--------- src/tools/highlight.rs | 10 ++-------- src/tools/rectangle.rs | 4 ++-- 7 files changed, 41 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index f1fb2dc..383ac84 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ All configuration is done either at the config file in `XDG_CONFIG_DIR/.config/s fullscreen = true # Exit directly after copy/save action early-exit = true +# Draw corners of rectangles round if the value is greater than 0 (0 disabled rounded corners) +corner_roundness = 12, # Select the tool on startup [possible values: pointer, crop, line, arrow, rectangle, text, marker, blur, brush] initial-tool = "brush" # Configure the command to be called on copy, for example `wl-copy` diff --git a/src/command_line.rs b/src/command_line.rs index c7b505f..7ad36a1 100644 --- a/src/command_line.rs +++ b/src/command_line.rs @@ -24,6 +24,11 @@ pub struct CommandLine { #[arg(long)] pub early_exit: bool, + /// Draw corners of rectangles round if the value is greater than 0 + /// (Defaults to 12) (0 disables rounded corners) + #[arg(long)] + pub corner_roundness: Option, + /// Select the tool on startup #[arg(long, value_name = "TOOL", visible_alias = "init-tool")] pub initial_tool: Option, diff --git a/src/configuration.rs b/src/configuration.rs index 214a682..59c3f6c 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -36,6 +36,7 @@ pub struct Configuration { output_filename: Option, fullscreen: bool, early_exit: bool, + corner_roundness: f32, initial_tool: Tools, copy_command: Option, annotation_size_factor: f32, @@ -158,6 +159,9 @@ impl Configuration { if let Some(v) = general.early_exit { self.early_exit = v; } + if let Some(v) = general.corner_roundness { + self.corner_roundness = v; + } if let Some(v) = general.initial_tool { self.initial_tool = v; } @@ -207,6 +211,9 @@ impl Configuration { if command_line.early_exit { self.early_exit = command_line.early_exit; } + if let Some(v) = command_line.corner_roundness { + self.corner_roundness = v; + } if command_line.default_hide_toolbars { self.default_hide_toolbars = command_line.default_hide_toolbars; } @@ -244,6 +251,10 @@ impl Configuration { self.early_exit } + pub fn corner_roundness(&self) -> f32 { + self.corner_roundness + } + pub fn initial_tool(&self) -> Tools { self.initial_tool } @@ -298,6 +309,7 @@ impl Default for Configuration { output_filename: None, fullscreen: false, early_exit: false, + corner_roundness: 12.0, initial_tool: Tools::Pointer, copy_command: None, annotation_size_factor: 1.0, @@ -344,6 +356,7 @@ struct FontFile { struct ConfigurationFileGeneral { fullscreen: Option, early_exit: Option, + corner_roundness: Option, initial_tool: Option, copy_command: Option, annotation_size_factor: Option, diff --git a/src/style.rs b/src/style.rs index e6ca799..d9271c6 100644 --- a/src/style.rs +++ b/src/style.rs @@ -18,6 +18,9 @@ pub struct Style { pub fill: bool, } +#[derive(Clone, Copy, Debug, Default)] +pub struct Properties {} + #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct Color { pub r: u8, @@ -176,6 +179,12 @@ impl FromVariant for Size { } } +impl Properties { + pub fn corner_roundness() -> f32 { + return APP_CONFIG.read().corner_roundness(); + } +} + impl Size { pub fn to_text_size(self) -> i32 { let size_factor = APP_CONFIG.read().annotation_size_factor(); @@ -215,11 +224,12 @@ impl Size { } } - pub fn to_corner_radius(self) -> f32 { + pub fn to_corner_roundness(self) -> f32 { + let corner_roundness = APP_CONFIG.read().corner_roundness(); match self { - Size::Small => 12.0, - Size::Medium => 12.0, - Size::Large => 12.0, + Size::Small => corner_roundness, + Size::Medium => corner_roundness, + Size::Large => corner_roundness, } } } diff --git a/src/tools/blur.rs b/src/tools/blur.rs index 01256fd..c6c74fd 100644 --- a/src/tools/blur.rs +++ b/src/tools/blur.rs @@ -8,7 +8,7 @@ use relm4::gtk::gdk::Key; use crate::{ math::{self, Vec2D}, sketch_board::{MouseEventMsg, MouseEventType}, - style::{Size, Style}, + style::{Properties, Size, Style}, }; use super::{Drawable, DrawableClone, Tool, ToolUpdateResult}; @@ -84,7 +84,7 @@ impl Drawable for Blur { self.top_left.y, size.x, size.y, - Size::Medium.to_corner_radius(), + Properties::corner_roundness(), ); // draw @@ -103,13 +103,7 @@ impl Drawable for Blur { } let mut path = Path::new(); - path.rounded_rect( - pos.x, - pos.y, - size.x, - size.y, - Size::Medium.to_corner_radius(), - ); + path.rounded_rect(pos.x, pos.y, size.x, size.y, Properties::corner_roundness()); canvas.fill_path( &path, diff --git a/src/tools/highlight.rs b/src/tools/highlight.rs index eb35604..3105868 100644 --- a/src/tools/highlight.rs +++ b/src/tools/highlight.rs @@ -11,7 +11,7 @@ use crate::{ configuration::APP_CONFIG, math::{self, Vec2D}, sketch_board::{MouseEventMsg, MouseEventType}, - style::{Size, Style}, + style::{Properties, Style}, tools::DrawableClone, }; @@ -99,13 +99,7 @@ impl Highlight for Highlighter { let (pos, size) = math::rect_ensure_positive_size(self.data.top_left, size); let mut shadow_path = Path::new(); - shadow_path.rounded_rect( - pos.x, - pos.y, - size.x, - size.y, - Size::Medium.to_corner_radius(), - ); + shadow_path.rounded_rect(pos.x, pos.y, size.x, size.y, Properties::corner_roundness()); let shadow_paint = Paint::color(femtovg::Color::rgba( self.style.color.r, diff --git a/src/tools/rectangle.rs b/src/tools/rectangle.rs index 8662d03..ee64758 100644 --- a/src/tools/rectangle.rs +++ b/src/tools/rectangle.rs @@ -5,7 +5,7 @@ use relm4::gtk::gdk::{Key, ModifierType}; use crate::{ math::Vec2D, sketch_board::{MouseEventMsg, MouseEventType}, - style::{Size, Style}, + style::{Properties, Style}, }; use super::{Drawable, DrawableClone, Tool, ToolUpdateResult}; @@ -35,7 +35,7 @@ impl Drawable for Rectangle { self.top_left.y, size.x, size.y, - Size::Medium.to_corner_radius(), + Properties::corner_roundness(), ); if self.style.fill { From 475e946b2cb04419f6024356f663bfd3efb65dcd Mon Sep 17 00:00:00 2001 From: schaumtier Date: Thu, 19 Dec 2024 15:16:04 +0000 Subject: [PATCH 2/5] added documentation --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 383ac84..60d1293 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ fullscreen = true # Exit directly after copy/save action early-exit = true # Draw corners of rectangles round if the value is greater than 0 (0 disabled rounded corners) -corner_roundness = 12, +corner-roundness = 12 # Select the tool on startup [possible values: pointer, crop, line, arrow, rectangle, text, marker, blur, brush] initial-tool = "brush" # Configure the command to be called on copy, for example `wl-copy` @@ -117,6 +117,8 @@ Options: Filename to use for saving action. Omit to disable saving to file. Might contain format specifiers: --early-exit Exit directly after copy/save action + --corner-roundness + Draw corners of rectangles round if the value is greater than 0 (0 disabled rounded corners) --initial-tool Select the tool on startup [aliases: init-tool] [possible values: pointer, crop, line, arrow, rectangle, text, marker, blur, brush] --copy-command From 719ed7f3fb5d0a4ed5abc40690a61506fa4d27fc Mon Sep 17 00:00:00 2001 From: schaumtier Date: Thu, 19 Dec 2024 15:17:33 +0000 Subject: [PATCH 3/5] documentation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 60d1293..1667513 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ All configuration is done either at the config file in `XDG_CONFIG_DIR/.config/s fullscreen = true # Exit directly after copy/save action early-exit = true -# Draw corners of rectangles round if the value is greater than 0 (0 disabled rounded corners) +# Draw corners of rectangles round if the value is greater than 0 (0 disables rounded corners) corner-roundness = 12 # Select the tool on startup [possible values: pointer, crop, line, arrow, rectangle, text, marker, blur, brush] initial-tool = "brush" @@ -118,7 +118,7 @@ Options: --early-exit Exit directly after copy/save action --corner-roundness - Draw corners of rectangles round if the value is greater than 0 (0 disabled rounded corners) + Draw corners of rectangles round if the value is greater than 0 (0 disables rounded corners) --initial-tool Select the tool on startup [aliases: init-tool] [possible values: pointer, crop, line, arrow, rectangle, text, marker, blur, brush] --copy-command From 37f002a87646ba74dd97407ac6c0e467b2939182 Mon Sep 17 00:00:00 2001 From: schaumtier Date: Thu, 19 Dec 2024 15:26:22 +0000 Subject: [PATCH 4/5] removed unused method --- src/style.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/style.rs b/src/style.rs index d9271c6..62d3966 100644 --- a/src/style.rs +++ b/src/style.rs @@ -223,13 +223,4 @@ impl Size { Size::Large => 45.0 * size_factor, } } - - pub fn to_corner_roundness(self) -> f32 { - let corner_roundness = APP_CONFIG.read().corner_roundness(); - match self { - Size::Small => corner_roundness, - Size::Medium => corner_roundness, - Size::Large => corner_roundness, - } - } } From fba26a10b32b0a277be07323e2b2a86c6d1f8045 Mon Sep 17 00:00:00 2001 From: schaumtier Date: Thu, 19 Dec 2024 15:46:25 +0000 Subject: [PATCH 5/5] removed parts and reference APP_CONFIG directly --- src/style.rs | 9 --------- src/tools/blur.rs | 13 ++++++++++--- src/tools/highlight.rs | 10 ++++++++-- src/tools/rectangle.rs | 5 +++-- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/style.rs b/src/style.rs index 62d3966..a0203b5 100644 --- a/src/style.rs +++ b/src/style.rs @@ -18,9 +18,6 @@ pub struct Style { pub fill: bool, } -#[derive(Clone, Copy, Debug, Default)] -pub struct Properties {} - #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct Color { pub r: u8, @@ -179,12 +176,6 @@ impl FromVariant for Size { } } -impl Properties { - pub fn corner_roundness() -> f32 { - return APP_CONFIG.read().corner_roundness(); - } -} - impl Size { pub fn to_text_size(self) -> i32 { let size_factor = APP_CONFIG.read().annotation_size_factor(); diff --git a/src/tools/blur.rs b/src/tools/blur.rs index c6c74fd..ec5f97a 100644 --- a/src/tools/blur.rs +++ b/src/tools/blur.rs @@ -6,9 +6,10 @@ use femtovg::{imgref::Img, Color, ImageFilter, ImageFlags, ImageId, Paint, Path} use relm4::gtk::gdk::Key; use crate::{ + configuration::APP_CONFIG, math::{self, Vec2D}, sketch_board::{MouseEventMsg, MouseEventType}, - style::{Properties, Size, Style}, + style::{Size, Style}, }; use super::{Drawable, DrawableClone, Tool, ToolUpdateResult}; @@ -84,7 +85,7 @@ impl Drawable for Blur { self.top_left.y, size.x, size.y, - Properties::corner_roundness(), + APP_CONFIG.read().corner_roundness(), ); // draw @@ -103,7 +104,13 @@ impl Drawable for Blur { } let mut path = Path::new(); - path.rounded_rect(pos.x, pos.y, size.x, size.y, Properties::corner_roundness()); + path.rounded_rect( + pos.x, + pos.y, + size.x, + size.y, + APP_CONFIG.read().corner_roundness(), + ); canvas.fill_path( &path, diff --git a/src/tools/highlight.rs b/src/tools/highlight.rs index 3105868..0162a1d 100644 --- a/src/tools/highlight.rs +++ b/src/tools/highlight.rs @@ -11,7 +11,7 @@ use crate::{ configuration::APP_CONFIG, math::{self, Vec2D}, sketch_board::{MouseEventMsg, MouseEventType}, - style::{Properties, Style}, + style::Style, tools::DrawableClone, }; @@ -99,7 +99,13 @@ impl Highlight for Highlighter { let (pos, size) = math::rect_ensure_positive_size(self.data.top_left, size); let mut shadow_path = Path::new(); - shadow_path.rounded_rect(pos.x, pos.y, size.x, size.y, Properties::corner_roundness()); + shadow_path.rounded_rect( + pos.x, + pos.y, + size.x, + size.y, + APP_CONFIG.read().corner_roundness(), + ); let shadow_paint = Paint::color(femtovg::Color::rgba( self.style.color.r, diff --git a/src/tools/rectangle.rs b/src/tools/rectangle.rs index ee64758..e8220fc 100644 --- a/src/tools/rectangle.rs +++ b/src/tools/rectangle.rs @@ -3,9 +3,10 @@ use femtovg::{FontId, Path}; use relm4::gtk::gdk::{Key, ModifierType}; use crate::{ + configuration::APP_CONFIG, math::Vec2D, sketch_board::{MouseEventMsg, MouseEventType}, - style::{Properties, Style}, + style::Style, }; use super::{Drawable, DrawableClone, Tool, ToolUpdateResult}; @@ -35,7 +36,7 @@ impl Drawable for Rectangle { self.top_left.y, size.x, size.y, - Properties::corner_roundness(), + APP_CONFIG.read().corner_roundness(), ); if self.style.fill {