[shotwell/wip/gtk4: 125/154] Fix faces tool (more or less)
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell/wip/gtk4: 125/154] Fix faces tool (more or less)
- Date: Sat, 1 Oct 2022 17:53:18 +0000 (UTC)
commit b4f73a86992be42b1944cfb0b155233c44930e9a
Author: Jens Georg <mail jensge org>
Date: Mon Apr 18 19:26:31 2022 +0200
Fix faces tool (more or less)
Drawing the boxes is still broken
src/editing_tools/EditingToolWindow.vala | 4 --
src/editing_tools/PhotoCanvas.vala | 2 +-
src/faces/Face.vala | 1 +
src/faces/FaceShape.vala | 36 ++++++-------
src/faces/FacesTool.vala | 86 ++++++++++++++++----------------
src/meson.build | 6 +--
6 files changed, 67 insertions(+), 68 deletions(-)
---
diff --git a/src/editing_tools/EditingToolWindow.vala b/src/editing_tools/EditingToolWindow.vala
index 068e8b78..268d3be0 100644
--- a/src/editing_tools/EditingToolWindow.vala
+++ b/src/editing_tools/EditingToolWindow.vala
@@ -49,8 +49,4 @@ public abstract class EditingTools.EditingToolWindow : Gtk.Window {
return true;
}
#endif
-
- private void suppress_warnings(string? log_domain, LogLevelFlags log_levels, string message) {
- // do nothing.
- }
}
diff --git a/src/editing_tools/PhotoCanvas.vala b/src/editing_tools/PhotoCanvas.vala
index be34f289..2a44cca0 100644
--- a/src/editing_tools/PhotoCanvas.vala
+++ b/src/editing_tools/PhotoCanvas.vala
@@ -332,7 +332,7 @@ public abstract class EditingTools.PhotoCanvas {
rect.x += scaled_position.x;
rect.y += scaled_position.y;
- //drawing_window.invalidate_rect(rect, false);
+ container.queue_draw();
}
public void set_cursor(string? cursor_type) {
diff --git a/src/faces/Face.vala b/src/faces/Face.vala
index b2249076..934e95fa 100644
--- a/src/faces/Face.vala
+++ b/src/faces/Face.vala
@@ -380,6 +380,7 @@ public class Face : DataSource, ContainerSource, Proxyable, Indexable {
#if ENABLE_FACES
private static void start_facedetect_process() {
message("Launching facedetect process: %s", AppDirs.get_facedetect_bin().get_path());
+ message("Using dnn from %s", AppDirs.get_openface_dnn_dir().get_path());
// Start the watcher, process started via DBus service
FaceDetect.init(AppDirs.get_openface_dnn_dir().get_path());
}
diff --git a/src/faces/FaceShape.vala b/src/faces/FaceShape.vala
index 57198416..a1764416 100644
--- a/src/faces/FaceShape.vala
+++ b/src/faces/FaceShape.vala
@@ -38,7 +38,7 @@ public abstract class FaceShape : Object {
face_window = new FacesTool.EditingFaceToolWindow(this.canvas.get_container());
face_window.key_pressed.connect(key_press_event);
- face_window.show_all();
+ face_window.show();
face_window.hide();
this.face_vec = vec;
@@ -54,7 +54,7 @@ public abstract class FaceShape : Object {
canvas.new_surface.disconnect(prepare_ctx);
// make sure the cursor isn't set to a modify indicator
- canvas.set_cursor(Gdk.CursorType.LEFT_PTR);
+ canvas.set_cursor(null);
}
public static FaceShape from_serialized(EditingTools.PhotoCanvas canvas, string serialized)
@@ -120,7 +120,7 @@ public abstract class FaceShape : Object {
face_window.hide();
// make sure the cursor isn't set to a modify indicator
- canvas.set_cursor(Gdk.CursorType.LEFT_PTR);
+ canvas.set_cursor(null);
}
public void show() {
@@ -157,8 +157,8 @@ public abstract class FaceShape : Object {
this.editable = editable;
}
- public bool key_press_event(Gdk.EventKey event) {
- switch (Gdk.keyval_name(event.keyval)) {
+ public bool key_press_event(Gtk.EventControllerKey event, uint keyval, uint keycode, Gdk.ModifierType
modifiers) {
+ switch (Gdk.keyval_name(keyval)) {
case "Escape":
delete_me_requested();
break;
@@ -315,6 +315,7 @@ public class FaceRectangle : FaceShape {
int x = 0;
int y = 0;
+ #if 0
if (canvas.get_container() == appWindow) {
appWindow.get_current_page().get_window().get_origin(out x, out y);
} else assert(canvas.get_container() is FullscreenWindow);
@@ -325,6 +326,7 @@ public class FaceRectangle : FaceShape {
y += scaled_pixbuf_pos.y + box.bottom + FACE_WINDOW_MARGIN;
face_window.move(x, y);
+ #endif
}
protected override void paint() {
@@ -701,49 +703,49 @@ public class FaceRectangle : FaceShape {
Gdk.Rectangle scaled_pos = canvas.get_scaled_pixbuf_position();
Box offset_scaled_box = box.get_offset(scaled_pos.x, scaled_pos.y);
- Gdk.CursorType cursor_type = Gdk.CursorType.LEFT_PTR;
+ string? cursor_type = null;
switch (offset_scaled_box.approx_location(x, y)) {
case BoxLocation.LEFT_SIDE:
- cursor_type = Gdk.CursorType.LEFT_SIDE;
+ cursor_type = "w-resize";
break;
case BoxLocation.TOP_SIDE:
- cursor_type = Gdk.CursorType.TOP_SIDE;
+ cursor_type = "n-resize";
break;
case BoxLocation.RIGHT_SIDE:
- cursor_type = Gdk.CursorType.RIGHT_SIDE;
+ cursor_type = "e-resize";
break;
case BoxLocation.BOTTOM_SIDE:
- cursor_type = Gdk.CursorType.BOTTOM_SIDE;
+ cursor_type = "s-resize";
break;
case BoxLocation.TOP_LEFT:
- cursor_type = Gdk.CursorType.TOP_LEFT_CORNER;
+ cursor_type = "nw-resize";
break;
case BoxLocation.BOTTOM_LEFT:
- cursor_type = Gdk.CursorType.BOTTOM_LEFT_CORNER;
+ cursor_type = "sw-resize";
break;
case BoxLocation.TOP_RIGHT:
- cursor_type = Gdk.CursorType.TOP_RIGHT_CORNER;
+ cursor_type = "ne-resize";
break;
case BoxLocation.BOTTOM_RIGHT:
- cursor_type = Gdk.CursorType.BOTTOM_RIGHT_CORNER;
+ cursor_type = "se-resize";
break;
case BoxLocation.INSIDE:
- cursor_type = Gdk.CursorType.FLEUR;
+ cursor_type = "move";
break;
-
+
default:
// use Gdk.CursorType.LEFT_PTR
break;
}
-
+
if (cursor_type != current_cursor_type) {
canvas.set_cursor(cursor_type);
current_cursor_type = cursor_type;
diff --git a/src/faces/FacesTool.vala b/src/faces/FacesTool.vala
index b15390a4..dc4bb321 100644
--- a/src/faces/FacesTool.vala
+++ b/src/faces/FacesTool.vala
@@ -56,45 +56,45 @@ public class FacesTool : EditingTools.EditingTool {
label.ellipsize = Pango.EllipsizeMode.END;
label.width_chars = FACE_LABEL_MAX_CHARS;
- pack_start(label, true);
- pack_start(edit_button, false);
- pack_start(delete_button, false);
+ append(label);
+ append(edit_button);
+ append(delete_button);
this.face_shape = face_shape;
face_shape.set_widget(this);
}
- public bool on_enter_notify_event() {
+ public void on_enter_notify_event() {
activate_label();
if (face_shape.is_editable())
- return false;
+ return;
// This check is necessary to avoid painting the face twice --see
// note in on_leave_notify_event.
if (!face_shape.is_visible())
face_shape.show();
-
- return true;
}
- public bool on_leave_notify_event() {
+ public void on_leave_notify_event() {
// This check is necessary because GTK+ will throw enter/leave_notify
// events when the pointer passes though windows, even if one window
// belongs to a widget that is a child of the widget that throws this
// signal. So, this check is necessary to avoid "deactivation" of
// the label if the pointer enters one of the buttons in this FaceWidget.
+ #if 0
if (!is_pointer_over(get_window())) {
deactivate_label();
if (face_shape.is_editable())
- return false;
+ return;
face_shape.hide();
face_hidden();
}
+ #endif
- return true;
+ return;
}
public void activate_label() {
@@ -140,32 +140,28 @@ public class FacesTool : EditingTools.EditingTool {
detection_button.set_tooltip_text(_("Detect faces on this photo"));
cancel_detection_button.set_tooltip_text(_("Cancel face detection"));
- cancel_detection_button.set_image_position(Gtk.PositionType.LEFT);
cancel_detection_button.clicked.connect(on_cancel_detection);
cancel_button.set_tooltip_text(_("Close the Faces tool without saving changes"));
- cancel_button.set_image_position(Gtk.PositionType.LEFT);
-
- ok_button.set_image_position(Gtk.PositionType.LEFT);
face_widgets_layout = new Gtk.Box(Gtk.Orientation.VERTICAL, CONTROL_SPACING);
help_text = new Gtk.Label(_("Click and drag to tag a face"));
help_layout = new Gtk.Box(Gtk.Orientation.HORIZONTAL, CONTROL_SPACING);
- help_layout.pack_start(help_text, true);
+ help_layout.append(help_text);
response_layout = new Gtk.Box(Gtk.Orientation.HORIZONTAL, CONTROL_SPACING);
- response_layout.add(detection_button);
- response_layout.add(cancel_button);
- response_layout.add(ok_button);
+ response_layout.append(detection_button);
+ response_layout.append(cancel_button);
+ response_layout.append(ok_button);
layout = new Gtk.Box(Gtk.Orientation.VERTICAL, CONTROL_SPACING);
- layout.pack_start(face_widgets_layout, false);
- layout.pack_start(help_layout, false);
- layout.pack_start(new Gtk.Separator(Gtk.Orientation.HORIZONTAL), false);
- layout.pack_start(response_layout, false);
+ layout.append(face_widgets_layout);
+ layout.append(help_layout);
+ layout.append(new Gtk.Separator(Gtk.Orientation.HORIZONTAL));
+ layout.append(response_layout);
- add(layout);
+ set_child(layout);
}
public void set_editing_phase(EditingPhase phase, FaceShape? face_shape = null) {
@@ -201,7 +197,7 @@ public class FacesTool : EditingTools.EditingTool {
help_text.set_text(_("Detecting faces"));
if (cancel_detection_button.get_parent() == null)
- help_layout.pack_start(cancel_detection_button, false);
+ help_layout.append(cancel_detection_button);
detection_button.set_sensitive(false);
cancel_detection_button.set_sensitive(true);
@@ -244,20 +240,18 @@ public class FacesTool : EditingTools.EditingTool {
face_widget.edit_button.clicked.connect(edit_face);
face_widget.delete_button.clicked.connect(delete_face);
- Gtk.EventBox event_box = new Gtk.EventBox();
- event_box.add(face_widget);
- event_box.add_events(Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK);
- event_box.enter_notify_event.connect(face_widget.on_enter_notify_event);
- event_box.leave_notify_event.connect(face_widget.on_leave_notify_event);
-
- face_widgets_layout.pack_start(event_box, false);
+ face_widgets_layout.append(face_widget);
+ var focus = new Gtk.EventControllerFocus();
+ focus.enter.connect(face_widget.on_enter_notify_event);
+ focus.leave.connect(face_widget.on_leave_notify_event);
+ face_widget.add_controller(focus);
if (buttons_text_separator == null) {
buttons_text_separator = new Gtk.Separator(Gtk.Orientation.HORIZONTAL);
- face_widgets_layout.pack_end(buttons_text_separator, false);
+ face_widgets_layout.append(buttons_text_separator);
}
- face_widgets_layout.show_all();
+ face_widgets_layout.show();
}
private void edit_face(Gtk.Button button) {
@@ -273,10 +267,12 @@ public class FacesTool : EditingTools.EditingTool {
widget.get_parent().destroy();
+ #if 0
if (face_widgets_layout.get_children().length() == 1) {
buttons_text_separator.destroy();
buttons_text_separator = null;
}
+ #endif
}
private void on_face_hidden() {
@@ -289,7 +285,7 @@ public class FacesTool : EditingTools.EditingTool {
}
public class EditingFaceToolWindow : EditingTools.EditingToolWindow {
- public signal bool key_pressed(Gdk.EventKey event);
+ public signal bool key_pressed(Gtk.EventControllerKey event, uint keyval, uint keycode,
Gdk.ModifierType modifiers);
public Gtk.Entry entry;
@@ -301,13 +297,17 @@ public class FacesTool : EditingTools.EditingTool {
entry = new Gtk.Entry();
layout = new Gtk.Box(Gtk.Orientation.HORIZONTAL, CONTROL_SPACING);
- layout.add(entry);
+ layout.append(entry);
+
+ set_child(layout);
- add(layout);
+ var controller = new Gtk.EventControllerKey();
+ ((Gtk.Widget)this).add_controller(controller);
+ controller.key_pressed.connect(on_keypress);
}
- public override bool key_press_event(Gdk.EventKey event) {
- return key_pressed(event) || base.key_press_event(event);
+ public bool on_keypress(Gtk.EventControllerKey event, uint keyval, uint keycode, Gdk.ModifierType
modifiers) {
+ return key_pressed(event, keyval, keycode, modifiers);
}
}
@@ -469,7 +469,6 @@ public class FacesTool : EditingTools.EditingTool {
}
private void bind_window_handlers() {
- faces_tool_window.key_press_event.connect(on_keypress);
faces_tool_window.ok_button.clicked.connect(on_faces_ok);
faces_tool_window.cancel_button.clicked.connect(notify_cancel);
faces_tool_window.detection_button.clicked.connect(detect_faces);
@@ -480,7 +479,6 @@ public class FacesTool : EditingTools.EditingTool {
}
private void unbind_window_handlers() {
- faces_tool_window.key_press_event.disconnect(on_keypress);
faces_tool_window.ok_button.clicked.disconnect(on_faces_ok);
faces_tool_window.cancel_button.clicked.disconnect(notify_cancel);
faces_tool_window.detection_button.clicked.disconnect(detect_faces);
@@ -512,15 +510,15 @@ public class FacesTool : EditingTools.EditingTool {
face_shape.on_resized_pixbuf(old_dim, scaled);
}
- public override bool on_keypress(Gdk.EventKey event) {
- string event_keyval = Gdk.keyval_name(event.keyval);
+ public override bool on_keypress(Gtk.EventControllerKey event, uint keyval, uint keycode,
Gdk.ModifierType modifiers) {
+ string event_keyval = Gdk.keyval_name(keyval);
if (event_keyval == "Return" || event_keyval == "KP_Enter") {
on_faces_ok();
return true;
}
- return base.on_keypress(event);
+ return base.on_keypress(event, keyval, keycode, modifiers);
}
public override void on_left_click(int x, int y) {
@@ -597,10 +595,12 @@ public class FacesTool : EditingTools.EditingTool {
}
public override bool on_leave_notify_event() {
+ #if 0
// This check is a workaround for bug #3896.
if (is_pointer_over(canvas.get_drawing_window()) &&
!is_pointer_over(faces_tool_window.get_window()))
return false;
+ #endif
if (editing_face_shape != null)
return base.on_leave_notify_event();
diff --git a/src/meson.build b/src/meson.build
index 0df814c4..3d63238b 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -26,10 +26,10 @@ if get_option('face_detection')
face_sources = [
'faces/FacesBranch.vala',
'faces/FacePage.vala',
- #'faces/FaceShape.vala',
+ 'faces/FaceShape.vala',
'faces/FaceDetect.vala',
- 'faces/Faces.vala'
- #'faces/FacesTool.vala'
+ 'faces/Faces.vala',
+ 'faces/FacesTool.vala'
]
endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]