summaryrefslogtreecommitdiff
path: root/src/editing_tools/EditingTools.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-06-14 20:35:58 +0200
committerJörg Frings-Fürst <debian@jff.email>2023-06-14 20:35:58 +0200
commitd443a3c2509889533ca812c163056bace396b586 (patch)
treee94ffc0d9c054ca4efb8fb327e18dfac88e15dc7 /src/editing_tools/EditingTools.vala
parentbb9797c14470641b082ebf635e2ae3cfd5f27a3b (diff)
New upstream version 0.32.1upstream/0.32.1
Diffstat (limited to 'src/editing_tools/EditingTools.vala')
-rw-r--r--src/editing_tools/EditingTools.vala81
1 files changed, 46 insertions, 35 deletions
diff --git a/src/editing_tools/EditingTools.vala b/src/editing_tools/EditingTools.vala
index 82fef0f..0042d57 100644
--- a/src/editing_tools/EditingTools.vala
+++ b/src/editing_tools/EditingTools.vala
@@ -87,7 +87,8 @@ public abstract class EditingToolWindow : Gtk.Window {
}
public override void realize() {
- (this as Gtk.Widget).set_opacity(Resources.TRANSIENT_WINDOW_OPACITY);
+ // Force the use of gtk_widget_set_opacity; gtk_window_set_opacity is deprecated
+ ((Gtk.Widget) this).set_opacity(Resources.TRANSIENT_WINDOW_OPACITY);
base.realize();
}
@@ -381,12 +382,13 @@ public abstract class PhotoCanvas {
}
public void erase_horizontal_line(int x, int y, int width) {
+ var scale = Application.get_scale();
default_ctx.save();
default_ctx.set_operator(Cairo.Operator.SOURCE);
default_ctx.set_source_surface(scaled, scaled_position.x, scaled_position.y);
default_ctx.rectangle(scaled_position.x + x, scaled_position.y + y,
- width - 1, 1);
+ width - 1, 1 * scale);
default_ctx.fill();
default_ctx.restore();
@@ -404,6 +406,8 @@ public abstract class PhotoCanvas {
public void erase_vertical_line(int x, int y, int height) {
default_ctx.save();
+ var scale = Application.get_scale();
+
// Ticket #3146 - artifacting when moving the crop box or
// enlarging it from the lower right.
// We now no longer subtract one from the height before choosing
@@ -411,7 +415,7 @@ public abstract class PhotoCanvas {
default_ctx.set_operator(Cairo.Operator.SOURCE);
default_ctx.set_source_surface(scaled, scaled_position.x, scaled_position.y);
default_ctx.rectangle(scaled_position.x + x, scaled_position.y + y,
- 1, height);
+ 1 * scale, height);
default_ctx.fill();
default_ctx.restore();
@@ -427,12 +431,19 @@ public abstract class PhotoCanvas {
public void invalidate_area(Box area) {
Gdk.Rectangle rect = area.get_rectangle();
+
rect.x += scaled_position.x;
rect.y += scaled_position.y;
drawing_window.invalidate_rect(rect, false);
}
+ public void set_cursor(Gdk.CursorType cursor_type) {
+ var display = get_drawing_window().get_display();
+ var cursor = new Gdk.Cursor.for_display (display, cursor_type);
+ get_drawing_window().set_cursor(cursor);
+ }
+
private Cairo.Surface pixbuf_to_surface(Cairo.Context default_ctx, Gdk.Pixbuf pixbuf,
Gdk.Rectangle pos) {
Cairo.Surface surface = new Cairo.Surface.similar(default_ctx.get_target(),
@@ -1220,11 +1231,7 @@ public class CropTool : EditingTool {
// make sure the cursor isn't set to a modify indicator
if (canvas != null) {
- var drawing_window = canvas.get_drawing_window ();
- var display = drawing_window.get_display ();
- var cursor = new Gdk.Cursor.for_display (display,
- Gdk.CursorType.LEFT_PTR);
- drawing_window.set_cursor (cursor);
+ canvas.set_cursor (Gdk.CursorType.LEFT_PTR);
}
crop_surface = null;
@@ -1244,20 +1251,22 @@ public class CropTool : EditingTool {
}
private void prepare_ctx(Cairo.Context ctx, Dimensions dim) {
+ var scale = Application.get_scale();
wide_black_ctx = new Cairo.Context(ctx.get_target());
set_source_color_from_string(wide_black_ctx, "#000");
- wide_black_ctx.set_line_width(1);
+ wide_black_ctx.set_line_width(1 * scale);
wide_white_ctx = new Cairo.Context(ctx.get_target());
set_source_color_from_string(wide_white_ctx, "#FFF");
- wide_white_ctx.set_line_width(1);
+ wide_white_ctx.set_line_width(1 * scale);
thin_white_ctx = new Cairo.Context(ctx.get_target());
set_source_color_from_string(thin_white_ctx, "#FFF");
- thin_white_ctx.set_line_width(0.5);
+ thin_white_ctx.set_line_width(0.5 * scale);
text_ctx = new Cairo.Context(ctx.get_target());
text_ctx.select_font_face("Sans", Cairo.FontSlant.NORMAL, Cairo.FontWeight.NORMAL);
+ text_ctx.set_font_size(10.0 * scale);
}
private void on_resized_pixbuf(Dimensions old_dim, Gdk.Pixbuf scaled, Gdk.Rectangle scaled_position) {
@@ -1286,7 +1295,8 @@ public class CropTool : EditingTool {
Box offset_scaled_crop = scaled_crop.get_offset(scaled_pixbuf_pos.x, scaled_pixbuf_pos.y);
// determine where the mouse down landed and store for future events
- in_manipulation = offset_scaled_crop.approx_location(x, y);
+ in_manipulation = offset_scaled_crop.approx_location((int)Math.lround(x * Application.get_scale()),
+ (int)Math.lround(y * Application.get_scale()));
last_grab_x = x -= scaled_pixbuf_pos.x;
last_grab_y = y -= scaled_pixbuf_pos.y;
@@ -1314,19 +1324,21 @@ public class CropTool : EditingTool {
// only deal with manipulating the crop tool when click-and-dragging one of the edges
// or the interior
if (in_manipulation != BoxLocation.OUTSIDE)
- on_canvas_manipulation(x, y);
+ on_canvas_manipulation((int)Math.lround(x * Application.get_scale()),
+ (int)Math.lround(y * Application.get_scale()));
update_cursor(x, y);
canvas.repaint();
}
public override void paint(Cairo.Context default_ctx) {
+ var scale = Application.get_scale();
// fill region behind the crop surface with neutral color
int w = canvas.get_drawing_window().get_width();
int h = canvas.get_drawing_window().get_height();
default_ctx.set_source_rgba(0.0, 0.0, 0.0, 1.0);
- default_ctx.rectangle(0, 0, w, h);
+ default_ctx.rectangle(0, 0, w * scale, h * scale);
default_ctx.fill();
default_ctx.paint();
@@ -1376,7 +1388,8 @@ public class CropTool : EditingTool {
Box offset_scaled_crop = scaled_crop.get_offset(scaled_pos.x, scaled_pos.y);
Gdk.CursorType cursor_type = Gdk.CursorType.LEFT_PTR;
- switch (offset_scaled_crop.approx_location(x, y)) {
+ switch (offset_scaled_crop.approx_location((int)Math.lround(x * Application.get_scale()),
+ (int)Math.lround(y * Application.get_scale()))) {
case BoxLocation.LEFT_SIDE:
cursor_type = Gdk.CursorType.LEFT_SIDE;
break;
@@ -1419,10 +1432,7 @@ public class CropTool : EditingTool {
}
if (cursor_type != current_cursor_type) {
- var drawing_window = canvas.get_drawing_window ();
- var display = drawing_window.get_display ();
- var cursor = new Gdk.Cursor.for_display (display, cursor_type);
- drawing_window.set_cursor (cursor);
+ canvas.set_cursor(cursor_type);
current_cursor_type = cursor_type;
}
}
@@ -1893,8 +1903,6 @@ public class RedeyeTool : EditingTool {
private bool is_reticle_move_in_progress = false;
private Gdk.Point reticle_move_mouse_start_point;
private Gdk.Point reticle_move_anchor;
- private Gdk.Cursor cached_arrow_cursor;
- private Gdk.Cursor cached_grab_cursor;
private Gdk.Rectangle old_scaled_pixbuf_position;
private Gdk.Pixbuf current_pixbuf = null;
@@ -1928,13 +1936,14 @@ public class RedeyeTool : EditingTool {
}
private void prepare_ctx(Cairo.Context ctx, Dimensions dim) {
+ var scale = Application.get_scale();
wider_gray_ctx = new Cairo.Context(ctx.get_target());
set_source_color_from_string(wider_gray_ctx, "#111");
- wider_gray_ctx.set_line_width(3);
+ wider_gray_ctx.set_line_width(3 * scale);
thin_white_ctx = new Cairo.Context(ctx.get_target());
set_source_color_from_string(thin_white_ctx, "#FFF");
- thin_white_ctx.set_line_width(1);
+ thin_white_ctx.set_line_width(1 * scale);
}
private void draw_redeye_instance(RedeyeInstance inst) {
@@ -2044,10 +2053,6 @@ public class RedeyeTool : EditingTool {
bind_window_handlers();
- var display = canvas.get_drawing_window().get_display();
- cached_arrow_cursor = new Gdk.Cursor.for_display(display, Gdk.CursorType.LEFT_PTR);
- cached_grab_cursor = new Gdk.Cursor.for_display(display, Gdk.CursorType.FLEUR);
-
DataCollection? owner = canvas.get_photo().get_membership();
if (owner != null)
owner.items_altered.connect(on_photos_altered);
@@ -2112,13 +2117,17 @@ public class RedeyeTool : EditingTool {
}
public override void on_left_click(int x, int y) {
+ var scale = Application.get_scale();
+
Gdk.Rectangle bounds_rect =
RedeyeInstance.to_bounds_rect(user_interaction_instance);
- if (coord_in_rectangle(x, y, bounds_rect)) {
+
+ if (coord_in_rectangle((int)Math.lround(x * scale), (int)Math.lround(y * scale), bounds_rect)) {
+ print("Motion in progress!!\n");
is_reticle_move_in_progress = true;
- reticle_move_mouse_start_point.x = x;
- reticle_move_mouse_start_point.y = y;
+ reticle_move_mouse_start_point.x = (int)Math.lround(x * scale);
+ reticle_move_mouse_start_point.y = (int)Math.lround(y * scale);
reticle_move_anchor = user_interaction_instance.center;
}
}
@@ -2128,6 +2137,8 @@ public class RedeyeTool : EditingTool {
}
public override void on_motion(int x, int y, Gdk.ModifierType mask) {
+ var scale = Application.get_scale();
+
if (is_reticle_move_in_progress) {
Gdk.Rectangle active_region_rect =
@@ -2144,8 +2155,8 @@ public class RedeyeTool : EditingTool {
active_region_rect.y + active_region_rect.height -
user_interaction_instance.radius - 1;
- int delta_x = x - reticle_move_mouse_start_point.x;
- int delta_y = y - reticle_move_mouse_start_point.y;
+ int delta_x = (int)Math.lround(x * scale) - reticle_move_mouse_start_point.x;
+ int delta_y = (int)Math.lround(y * scale) - reticle_move_mouse_start_point.y;
user_interaction_instance.center.x = reticle_move_anchor.x +
delta_x;
@@ -2164,10 +2175,10 @@ public class RedeyeTool : EditingTool {
Gdk.Rectangle bounds =
RedeyeInstance.to_bounds_rect(user_interaction_instance);
- if (coord_in_rectangle(x, y, bounds)) {
- canvas.get_drawing_window().set_cursor(cached_grab_cursor);
+ if (coord_in_rectangle((int)Math.lround(x * scale), (int)Math.lround(y * scale), bounds)) {
+ canvas.set_cursor(Gdk.CursorType.FLEUR);
} else {
- canvas.get_drawing_window().set_cursor(cached_arrow_cursor);
+ canvas.set_cursor(Gdk.CursorType.LEFT_PTR);
}
}
}