Skip to content

Commit

Permalink
fix: path move when window extern
Browse files Browse the repository at this point in the history
  • Loading branch information
Horbin-Magician committed Jan 10, 2025
1 parent 5af1d64 commit 0a3597e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/module/screen_shotter/pin_win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ impl PinWin {
pin_window_clone.set_img_width(img_width);
pin_window_clone.set_img_height(img_height);
pin_window_clone.window().set_position(slint::LogicalPosition::new(change_pos_x, change_pos_y));
if mouse_direction != Direction::Center {
pin_window_clone.set_path_offset_x(pin_window_clone.get_path_offset_x() + (delta_x / zoom_factor * scale_factor) as i32);
pin_window_clone.set_path_offset_y(pin_window_clone.get_path_offset_y() + (delta_y / zoom_factor * scale_factor) as i32);
}
let _ = message_sender_clone.send(ShotterMessage::Move(id));
}
});
Expand Down
10 changes: 8 additions & 2 deletions src/ui/screen_shotter/pin_win.slint
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export component PinWindow inherits BaseWindow {
in property <float> scale_factor;
in property <int> img_x;
in property <int> img_y;
in property <int> path_offset_x: 0;
in property <int> path_offset_y: 0;
in-out property <int> img_width;
in-out property <int> img_height;
in-out property <int> zoom_factor: 100; // neet to be divided by one hundred
Expand Down Expand Up @@ -74,9 +76,9 @@ export component PinWindow inherits BaseWindow {
root.win_move(self.mouse-x - self.pressed-x, self.mouse-y - self.pressed-y, mouse_direction);
} else if root.state == PinState.DrawFree { // draw line
if root.drawing_path == "" {
root.drawing_path = @tr("M {} {}", self.mouse-x / zoom_factor * 100 / 1px * scale_factor, self.mouse-y / zoom_factor * 100 / 1px * scale_factor);
root.drawing_path = @tr("M {} {}", self.mouse-x / zoom_factor * 100 / 1px * scale_factor + path_offset_x, self.mouse-y / zoom_factor * 100 / 1px * scale_factor + path_offset_y);
} else {
root.drawing_path = @tr("{} L {} {}", root.drawing_path, self.mouse-x / zoom_factor * 100 / 1px * scale_factor, self.mouse-y / zoom_factor * 100 / 1px * scale_factor);
root.drawing_path = @tr("{} L {} {}", root.drawing_path, self.mouse-x / zoom_factor * 100 / 1px * scale_factor + path_offset_x, self.mouse-y / zoom_factor * 100 / 1px * scale_factor + path_offset_y);
}
}
}
Expand Down Expand Up @@ -161,6 +163,8 @@ export component PinWindow inherits BaseWindow {

for path in root.pathes:
Path {
viewbox-x: path_offset_x;
viewbox-y: path_offset_y;
viewbox-width: root.width / zoom_factor * 100 / 1phx;
viewbox-height: root.height / zoom_factor * 100 / 1phx;
commands: path;
Expand All @@ -169,6 +173,8 @@ export component PinWindow inherits BaseWindow {
}

Path {
viewbox-x: path_offset_x;
viewbox-y: path_offset_y;
viewbox-width: root.width / zoom_factor * 100 / 1phx;
viewbox-height: root.height / zoom_factor * 100 / 1phx;
commands: drawing_path;
Expand Down

0 comments on commit 0a3597e

Please sign in to comment.