diff --git a/README.md b/README.md
index 5df18fe..47a83c7 100644
--- a/README.md
+++ b/README.md
@@ -70,6 +70,7 @@ Default single-key shortcuts:
- t: Text tool
- m: Numbered Marker tool
- u: Blur tool
+- x: Pixelate tool
- g: Highlight tool
### Tool Modifiers and Keys
@@ -79,6 +80,7 @@ Default single-key shortcuts:
- Highlight: Hold Ctrl to switch between block and freehand mode (default configurable, see below), hold Shift for a square (if the default mode is block) or a straight line (if the default mode is freehand)
- Line: Hold Shift to make line snap to 15° steps
- Rectangle: Hold Alt to center the rectangle around origin, hold Shift for a square
+- Pixelate: Hold Alt to use pixelation that takes data from outside the selection as a source. NEXTRELEASE
- Text:
- Press Shift+Enter to insert line break.
- Combine Ctrl with Left or Right for word jump or Ctrl with Backspace or Delete for word delete.
@@ -120,7 +122,7 @@ early-exit = true
early-exit-save-as = true
# 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]
+# Select the tool on startup [possible values: pointer, crop, line, arrow, rectangle, text, marker, blur, pixelate, brush]
initial-tool = "brush"
# Configure the command to be called on copy, for example `wl-copy`
copy-command = "wl-copy"
@@ -189,6 +191,8 @@ ellipse = "e"
text = "t"
marker = "m"
blur = "u"
+# NEXTRELEASE
+pixelate = "x"
highlight = "g"
# Font to use for text annotations
@@ -266,7 +270,7 @@ Options:
--corner-roundness
Draw corners of rectangles round if the value is greater than 0 (Defaults to 12) (0 disables rounded corners)
--initial-tool
- Select the tool on startup [aliases: --init-tool] [possible values: pointer, crop, line, arrow, rectangle, ellipse, text, marker, blur, highlight, brush]
+ Select the tool on startup [aliases: --init-tool] [possible values: pointer, crop, line, arrow, rectangle, ellipse, text, marker, blur, pixelate, highlight, brush]
--copy-command
Configure the command to be called on copy, for example `wl-copy`
--annotation-size-factor
@@ -444,3 +448,8 @@ Made with [contrib.rocks](https://contrib.rocks).
The source code is released under the MPL-2.0 license.
The Font 'Roboto Regular' from Google is released under Apache-2.0 license.
+
+## Credits
+
+- Pixelate "independent mode" was inspired by https://github.com/flameshot-org/flameshot/pull/3765/changes
+
diff --git a/build.rs b/build.rs
index 5afd94b..d521f92 100644
--- a/build.rs
+++ b/build.rs
@@ -73,6 +73,7 @@ fn main() -> Result<(), io::Error> {
"paint-bucket-regular",
"page-fit-regular",
"resize-large-regular",
+ "tetris-app-regular",
],
);
diff --git a/cli/src/command_line.rs b/cli/src/command_line.rs
index cdc5eec..ab66ef9 100644
--- a/cli/src/command_line.rs
+++ b/cli/src/command_line.rs
@@ -221,6 +221,7 @@ pub enum Tools {
Text,
Marker,
Blur,
+ Pixelate,
Highlight,
Brush,
}
@@ -254,6 +255,7 @@ impl std::fmt::Display for Tools {
Text => "text",
Marker => "marker",
Blur => "blur",
+ Pixelate => "pixelate",
Highlight => "highlight",
Brush => "brush",
};
diff --git a/src/configuration.rs b/src/configuration.rs
index 9948762..c10f146 100644
--- a/src/configuration.rs
+++ b/src/configuration.rs
@@ -124,6 +124,7 @@ impl Keybinds {
self.update_keybind(file_keybinds.text, Tools::Text);
self.update_keybind(file_keybinds.marker, Tools::Marker);
self.update_keybind(file_keybinds.blur, Tools::Blur);
+ self.update_keybind(file_keybinds.pixelate, Tools::Pixelate);
self.update_keybind(file_keybinds.highlight, Tools::Highlight);
}
}
@@ -141,6 +142,7 @@ impl Default for Keybinds {
shortcuts.insert('t', Tools::Text);
shortcuts.insert('m', Tools::Marker);
shortcuts.insert('u', Tools::Blur);
+ shortcuts.insert('x', Tools::Pixelate);
shortcuts.insert('g', Tools::Highlight);
Self { shortcuts }
@@ -735,6 +737,7 @@ struct KeybindsFile {
text: Option,
marker: Option,
blur: Option,
+ pixelate: Option,
highlight: Option,
}
diff --git a/src/tools/mod.rs b/src/tools/mod.rs
index 90fd548..47c2db3 100644
--- a/src/tools/mod.rs
+++ b/src/tools/mod.rs
@@ -36,6 +36,7 @@ mod ellipse;
mod highlight;
mod line;
mod marker;
+mod pixelate;
mod pointer;
mod rectangle;
mod text;
@@ -167,6 +168,7 @@ pub use crop::CropTool;
pub use ellipse::EllipseTool;
pub use highlight::{HighlightTool, Highlighters};
pub use line::LineTool;
+pub use pixelate::PixelateTool;
pub use rectangle::RectangleTool;
pub use text::TextTool;
@@ -186,6 +188,7 @@ pub enum Tools {
Blur = 8,
Highlight = 9,
Brush = 10,
+ Pixelate = 11,
}
impl Tools {
@@ -202,6 +205,7 @@ impl Tools {
Tools::Marker => "Numbered Marker",
Tools::Blur => "Blur",
Tools::Highlight => "Highlight",
+ Tools::Pixelate => "Pixelate",
}
}
}
@@ -221,6 +225,7 @@ impl Display for Tools {
Self::Blur => write!(f, "blur"),
Self::Highlight => write!(f, "highlight"),
Self::Brush => write!(f, "brush"),
+ Self::Pixelate => write!(f, "pixelate"),
}
}
}
@@ -250,6 +255,10 @@ impl ToolsManager {
);
tools.insert(Tools::Text, Rc::new(RefCell::new(TextTool::default())));
tools.insert(Tools::Blur, Rc::new(RefCell::new(BlurTool::default())));
+ tools.insert(
+ Tools::Pixelate,
+ Rc::new(RefCell::new(PixelateTool::default())),
+ );
tools.insert(
Tools::Highlight,
Rc::new(RefCell::new(HighlightTool::default())),
@@ -305,6 +314,7 @@ impl FromVariant for Tools {
8 => Some(Tools::Blur),
9 => Some(Tools::Highlight),
10 => Some(Tools::Brush),
+ 11 => Some(Tools::Pixelate),
_ => None,
})
}
@@ -322,6 +332,7 @@ impl From for Tools {
command_line::Tools::Text => Self::Text,
command_line::Tools::Marker => Self::Marker,
command_line::Tools::Blur => Self::Blur,
+ command_line::Tools::Pixelate => Self::Pixelate,
command_line::Tools::Highlight => Self::Highlight,
command_line::Tools::Brush => Self::Brush,
}
diff --git a/src/tools/pixelate.rs b/src/tools/pixelate.rs
new file mode 100644
index 0000000..fb22c9a
--- /dev/null
+++ b/src/tools/pixelate.rs
@@ -0,0 +1,366 @@
+use std::cell::RefCell;
+
+use crate::{
+ math::{self, Vec2D},
+ sketch_board::{MouseButton, MouseEventMsg, MouseEventType, SketchBoardInput},
+ style::Style,
+ tools::Cow,
+};
+use anyhow::Result;
+use femtovg::imgref::Img;
+use femtovg::rgb::RGBA8;
+use femtovg::{Color, ImageFlags, ImageId, Paint, Path, rgb::Rgba};
+use relm4::gtk::gdk::ModifierType;
+use relm4::{Sender, gtk::gdk::Key};
+
+use super::{Drawable, DrawableClone, Tool, ToolUpdateResult, Tools};
+
+static BLOCKSIZE: usize = 32;
+
+#[derive(Clone, Debug)]
+pub struct Pixelate {
+ top_left: Vec2D,
+ size: Option,
+ editing: bool,
+ independent_mode: bool,
+ cached_image: RefCell