From 3a62c53009b457c772f2486f047a4676d9959d70 Mon Sep 17 00:00:00 2001 From: Ell Date: Fri, 15 May 2020 00:12:26 +0300 Subject: [PATCH] app: add FOCUS prop-gui controller ... based on GimpToolFocus. --- app/propgui/propgui-types.h | 13 ++- app/tools/gimpfiltertool-widgets.c | 122 +++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 1 deletion(-) diff --git a/app/propgui/propgui-types.h b/app/propgui/propgui-types.h index 910027a160..11bbc06684 100644 --- a/app/propgui/propgui-types.h +++ b/app/propgui/propgui-types.h @@ -32,7 +32,8 @@ typedef enum GIMP_CONTROLLER_TYPE_SLIDER_LINE, GIMP_CONTROLLER_TYPE_TRANSFORM_GRID, GIMP_CONTROLLER_TYPE_TRANSFORM_GRIDS, - GIMP_CONTROLLER_TYPE_GYROSCOPE + GIMP_CONTROLLER_TYPE_GYROSCOPE, + GIMP_CONTROLLER_TYPE_FOCUS } GimpControllerType; @@ -113,6 +114,16 @@ typedef void (* GimpControllerGyroscopeCallback) (gpointer gdouble roll, gdouble zoom, gboolean invert); +typedef void (* GimpControllerFocusCallback) (gpointer data, + GeglRectangle *area, + GimpLimitType type, + gdouble x, + gdouble y, + gdouble radius, + gdouble aspect_ratio, + gdouble angle, + gdouble inner_limit, + gdouble midpoint); typedef GtkWidget * (* GimpCreatePickerFunc) (gpointer creator, diff --git a/app/tools/gimpfiltertool-widgets.c b/app/tools/gimpfiltertool-widgets.c index 051679c320..d5cf6fe4b4 100644 --- a/app/tools/gimpfiltertool-widgets.c +++ b/app/tools/gimpfiltertool-widgets.c @@ -32,6 +32,7 @@ #include "core/gimpitem.h" #include "display/gimpdisplay.h" +#include "display/gimptoolfocus.h" #include "display/gimptoolgyroscope.h" #include "display/gimptoolline.h" #include "display/gimptooltransformgrid.h" @@ -102,6 +103,19 @@ static void gimp_filter_tool_set_gyroscope (Controller static void gimp_filter_tool_gyroscope_changed (GimpToolWidget *widget, Controller *controller); +static void gimp_filter_tool_set_focus (Controller *controller, + GeglRectangle *area, + GimpLimitType type, + gdouble x, + gdouble y, + gdouble radius, + gdouble aspect_ratio, + gdouble angle, + gdouble inner_limit, + gdouble midpoint); +static void gimp_filter_tool_focus_changed (GimpToolWidget *widget, + Controller *controller); + /* public functions */ @@ -246,6 +260,17 @@ gimp_filter_tool_create_widget (GimpFilterTool *filter_tool, *set_func_data = controller; } break; + + case GIMP_CONTROLLER_TYPE_FOCUS: + controller->widget = gimp_tool_focus_new (shell); + + g_signal_connect (controller->widget, "changed", + G_CALLBACK (gimp_filter_tool_focus_changed), + controller); + + *set_func = (GCallback) gimp_filter_tool_set_focus; + *set_func_data = controller; + break; } g_object_add_weak_pointer (G_OBJECT (controller->widget), @@ -840,3 +865,100 @@ gimp_filter_tool_gyroscope_changed (GimpToolWidget *widget, gyroscope_callback (controller->creator_data, &area, yaw, pitch, roll, zoom, invert); } + +static void +gimp_filter_tool_set_focus (Controller *controller, + GeglRectangle *area, + GimpLimitType type, + gdouble x, + gdouble y, + gdouble radius, + gdouble aspect_ratio, + gdouble angle, + gdouble inner_limit, + gdouble midpoint) +{ + GimpTool *tool; + GimpDrawable *drawable; + + if (! controller->widget) + return; + + tool = GIMP_TOOL (controller->filter_tool); + drawable = tool->drawable; + + if (drawable) + { + gint off_x, off_y; + + gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); + + x += off_x + area->x; + y += off_y + area->y; + } + + g_signal_handlers_block_by_func (controller->widget, + gimp_filter_tool_focus_changed, + controller); + + g_object_set (controller->widget, + "type", type, + "x", x, + "y", y, + "radius", radius, + "aspect-ratio", aspect_ratio, + "angle", angle, + "inner-limit", inner_limit, + "midpoint", midpoint, + NULL); + + g_signal_handlers_unblock_by_func (controller->widget, + gimp_filter_tool_focus_changed, + controller); +} + +static void +gimp_filter_tool_focus_changed (GimpToolWidget *widget, + Controller *controller) +{ + GimpFilterTool *filter_tool = controller->filter_tool; + GimpControllerFocusCallback focus_callback; + GimpLimitType type; + gdouble x, y; + gdouble radius; + gdouble aspect_ratio; + gdouble angle; + gdouble inner_limit; + gdouble midpoint; + gint off_x, off_y; + GeglRectangle area; + + focus_callback = (GimpControllerFocusCallback) controller->creator_callback; + + g_object_get (widget, + "type", &type, + "x", &x, + "y", &y, + "radius", &radius, + "aspect-ratio", &aspect_ratio, + "angle", &angle, + "inner-limit", &inner_limit, + "midpoint", &midpoint, + NULL); + + gimp_filter_tool_get_drawable_area (filter_tool, &off_x, &off_y, &area); + + x -= off_x + area.x; + y -= off_y + area.y; + + focus_callback (controller->creator_data, + &area, + type, + x, + y, + radius, + aspect_ratio, + angle, + inner_limit, + midpoint); +}