Bug 770689 - Custom transparency controller for dark...
...outside area of Crop Tool -> Highlight option Add "highlight-opacity" property and turn the controlling GUI into an expanding toggle that reveals an opacity slider.
This commit is contained in:

committed by
Michael Natterer

parent
7ac7b9519f
commit
423ce6fca3
@ -83,7 +83,7 @@ static const GimpRGB vectors_active_fg = { 1.0, 0.0, 0.0, 0.8 };
|
||||
static const GimpRGB outline_bg = { 1.0, 1.0, 1.0, 0.6 };
|
||||
static const GimpRGB outline_fg = { 0.0, 0.0, 0.0, 0.8 };
|
||||
|
||||
static const GimpRGB passe_partout = { 0.0, 0.0, 0.0, 0.5 };
|
||||
static const GimpRGB passe_partout = { 0.0, 0.0, 0.0, 1.0 };
|
||||
|
||||
static const GimpRGB tool_bg = { 0.0, 0.0, 0.0, 0.4 };
|
||||
static const GimpRGB tool_fg = { 1.0, 1.0, 1.0, 0.8 };
|
||||
|
@ -31,13 +31,41 @@
|
||||
#include "gimpdisplayshell-scale.h"
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_OPACITY,
|
||||
};
|
||||
|
||||
|
||||
typedef struct _GimpCanvasPassePartoutPrivate GimpCanvasPassePartoutPrivate;
|
||||
|
||||
struct _GimpCanvasPassePartoutPrivate
|
||||
{
|
||||
gdouble opacity;
|
||||
};
|
||||
|
||||
#define GET_PRIVATE(item) \
|
||||
G_TYPE_INSTANCE_GET_PRIVATE (item, \
|
||||
GIMP_TYPE_CANVAS_PASSE_PARTOUT, \
|
||||
GimpCanvasPassePartoutPrivate)
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
static void gimp_canvas_passe_partout_draw (GimpCanvasItem *item,
|
||||
cairo_t *cr);
|
||||
static cairo_region_t * gimp_canvas_passe_partout_get_extents (GimpCanvasItem *item);
|
||||
static void gimp_canvas_passe_partout_fill (GimpCanvasItem *item,
|
||||
cairo_t *cr);
|
||||
static void gimp_canvas_passe_partout_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gimp_canvas_passe_partout_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gimp_canvas_passe_partout_draw (GimpCanvasItem *item,
|
||||
cairo_t *cr);
|
||||
static cairo_region_t * gimp_canvas_passe_partout_get_extents (GimpCanvasItem *item);
|
||||
static void gimp_canvas_passe_partout_fill (GimpCanvasItem *item,
|
||||
cairo_t *cr);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GimpCanvasPassePartout, gimp_canvas_passe_partout,
|
||||
@ -49,11 +77,23 @@ G_DEFINE_TYPE (GimpCanvasPassePartout, gimp_canvas_passe_partout,
|
||||
static void
|
||||
gimp_canvas_passe_partout_class_init (GimpCanvasPassePartoutClass *klass)
|
||||
{
|
||||
GimpCanvasItemClass *item_class = GIMP_CANVAS_ITEM_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GimpCanvasItemClass *item_class = GIMP_CANVAS_ITEM_CLASS (klass);
|
||||
|
||||
item_class->draw = gimp_canvas_passe_partout_draw;
|
||||
item_class->get_extents = gimp_canvas_passe_partout_get_extents;
|
||||
item_class->fill = gimp_canvas_passe_partout_fill;
|
||||
object_class->set_property = gimp_canvas_passe_partout_set_property;
|
||||
object_class->get_property = gimp_canvas_passe_partout_get_property;
|
||||
|
||||
item_class->draw = gimp_canvas_passe_partout_draw;
|
||||
item_class->get_extents = gimp_canvas_passe_partout_get_extents;
|
||||
item_class->fill = gimp_canvas_passe_partout_fill;
|
||||
|
||||
g_object_class_install_property (object_class, PROP_OPACITY,
|
||||
g_param_spec_double ("opacity", NULL, NULL,
|
||||
0.0,
|
||||
1.0, 0.5,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
g_type_class_add_private (klass, sizeof (GimpCanvasPassePartoutPrivate));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -61,6 +101,46 @@ gimp_canvas_passe_partout_init (GimpCanvasPassePartout *passe_partout)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_canvas_passe_partout_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpCanvasPassePartoutPrivate *priv = GET_PRIVATE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_OPACITY:
|
||||
priv->opacity = g_value_get_double (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_canvas_passe_partout_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpCanvasPassePartoutPrivate *priv = GET_PRIVATE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_OPACITY:
|
||||
g_value_set_double (value, priv->opacity);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_canvas_passe_partout_draw (GimpCanvasItem *item,
|
||||
cairo_t *cr)
|
||||
@ -101,11 +181,13 @@ static void
|
||||
gimp_canvas_passe_partout_fill (GimpCanvasItem *item,
|
||||
cairo_t *cr)
|
||||
{
|
||||
GimpCanvasPassePartoutPrivate *priv = GET_PRIVATE (item);
|
||||
|
||||
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
|
||||
cairo_clip (cr);
|
||||
|
||||
gimp_canvas_set_passe_partout_style (gimp_canvas_item_get_canvas (item), cr);
|
||||
cairo_paint (cr);
|
||||
cairo_paint_with_alpha (cr, priv->opacity);
|
||||
}
|
||||
|
||||
GimpCanvasItem *
|
||||
|
@ -1881,6 +1881,7 @@ gimp_display_shell_resume (GimpDisplayShell *shell)
|
||||
* gimp_display_shell_set_highlight:
|
||||
* @shell: a #GimpDisplayShell
|
||||
* @highlight: a rectangle in image coordinates that should be brought out
|
||||
* @opacity: how much to hide the unselected area
|
||||
*
|
||||
* This function sets an area of the image that should be
|
||||
* accentuated. The actual implementation is to dim all pixels outside
|
||||
@ -1888,7 +1889,8 @@ gimp_display_shell_resume (GimpDisplayShell *shell)
|
||||
**/
|
||||
void
|
||||
gimp_display_shell_set_highlight (GimpDisplayShell *shell,
|
||||
const GdkRectangle *highlight)
|
||||
const GdkRectangle *highlight,
|
||||
gdouble opacity)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
||||
|
||||
@ -1901,6 +1903,7 @@ gimp_display_shell_set_highlight (GimpDisplayShell *shell,
|
||||
highlight->y,
|
||||
highlight->width,
|
||||
highlight->height);
|
||||
g_object_set (shell->passe_partout, "opacity", opacity, NULL);
|
||||
|
||||
gimp_canvas_item_set_visible (shell->passe_partout, TRUE);
|
||||
|
||||
|
@ -294,7 +294,8 @@ void gimp_display_shell_pause (GimpDisplayShell *shell);
|
||||
void gimp_display_shell_resume (GimpDisplayShell *shell);
|
||||
|
||||
void gimp_display_shell_set_highlight (GimpDisplayShell *shell,
|
||||
const GdkRectangle *highlight);
|
||||
const GdkRectangle *highlight,
|
||||
double opacity);
|
||||
void gimp_display_shell_set_mask (GimpDisplayShell *shell,
|
||||
GeglBuffer *mask,
|
||||
gint offset_x,
|
||||
|
@ -82,6 +82,7 @@ enum
|
||||
PROP_STATUS_TITLE,
|
||||
|
||||
PROP_HIGHLIGHT,
|
||||
PROP_HIGHLIGHT_OPACITY,
|
||||
PROP_GUIDE,
|
||||
PROP_X,
|
||||
PROP_Y,
|
||||
@ -239,6 +240,7 @@ struct _GimpToolRectanglePrivate
|
||||
/* The following values are externally synced with GimpRectangleOptions */
|
||||
|
||||
gboolean highlight;
|
||||
gdouble highlight_opacity;
|
||||
GimpGuidesType guide;
|
||||
|
||||
gdouble x;
|
||||
@ -561,6 +563,13 @@ gimp_tool_rectangle_class_init (GimpToolRectangleClass *klass)
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_HIGHLIGHT_OPACITY,
|
||||
g_param_spec_double ("highlight-opacity",
|
||||
NULL, NULL,
|
||||
0.0, 1.0, 0.5,
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_GUIDE,
|
||||
g_param_spec_enum ("guide",
|
||||
NULL, NULL,
|
||||
@ -869,6 +878,9 @@ gimp_tool_rectangle_set_property (GObject *object,
|
||||
case PROP_HIGHLIGHT:
|
||||
private->highlight = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_HIGHLIGHT_OPACITY:
|
||||
private->highlight_opacity = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_GUIDE:
|
||||
private->guide = g_value_get_enum (value);
|
||||
break;
|
||||
@ -975,6 +987,9 @@ gimp_tool_rectangle_get_property (GObject *object,
|
||||
case PROP_HIGHLIGHT:
|
||||
g_value_set_boolean (value, private->highlight);
|
||||
break;
|
||||
case PROP_HIGHLIGHT_OPACITY:
|
||||
g_value_set_double (value, private->highlight_opacity);
|
||||
break;
|
||||
case PROP_GUIDE:
|
||||
g_value_set_enum (value, private->guide);
|
||||
break;
|
||||
@ -1367,11 +1382,11 @@ gimp_tool_rectangle_changed (GimpToolWidget *widget)
|
||||
rect.width = x2 - x1;
|
||||
rect.height = y2 - y1;
|
||||
|
||||
gimp_display_shell_set_highlight (shell, &rect);
|
||||
gimp_display_shell_set_highlight (shell, &rect, private->highlight_opacity);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_display_shell_set_highlight (shell, NULL);
|
||||
gimp_display_shell_set_highlight (shell, NULL, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,14 @@ gimp_crop_options_class_init (GimpCropOptionsClass *klass)
|
||||
TRUE,
|
||||
GIMP_PARAM_STATIC_STRINGS);
|
||||
|
||||
GIMP_CONFIG_PROP_DOUBLE (object_class,
|
||||
GIMP_RECTANGLE_OPTIONS_PROP_HIGHLIGHT_OPACITY,
|
||||
"highlight-opacity",
|
||||
_("Highlight opacity"),
|
||||
_("How much to dim everything outside selection"),
|
||||
0.0, 1.0, 0.5,
|
||||
GIMP_PARAM_STATIC_STRINGS);
|
||||
|
||||
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_LAYER_ONLY,
|
||||
"layer-only",
|
||||
_("Current layer only"),
|
||||
|
@ -335,6 +335,7 @@ gimp_crop_tool_start (GimpCropTool *crop_tool,
|
||||
static const gchar *properties[] =
|
||||
{
|
||||
"highlight",
|
||||
"highlight-opacity",
|
||||
"guide",
|
||||
"x",
|
||||
"y",
|
||||
@ -474,7 +475,7 @@ gimp_crop_tool_halt (GimpCropTool *crop_tool)
|
||||
{
|
||||
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
||||
|
||||
gimp_display_shell_set_highlight (shell, NULL);
|
||||
gimp_display_shell_set_highlight (shell, NULL, 0.0);
|
||||
|
||||
gimp_rectangle_options_disconnect (GIMP_RECTANGLE_OPTIONS (options),
|
||||
G_CALLBACK (gimp_crop_tool_auto_shrink),
|
||||
|
@ -491,6 +491,9 @@ gimp_rectangle_options_set_property (GObject *object,
|
||||
case GIMP_RECTANGLE_OPTIONS_PROP_HIGHLIGHT:
|
||||
private->highlight = g_value_get_boolean (value);
|
||||
break;
|
||||
case GIMP_RECTANGLE_OPTIONS_PROP_HIGHLIGHT_OPACITY:
|
||||
private->highlight_opacity = g_value_get_double (value);
|
||||
break;
|
||||
case GIMP_RECTANGLE_OPTIONS_PROP_GUIDE:
|
||||
private->guide = g_value_get_enum (value);
|
||||
break;
|
||||
@ -595,6 +598,9 @@ gimp_rectangle_options_get_property (GObject *object,
|
||||
case GIMP_RECTANGLE_OPTIONS_PROP_HIGHLIGHT:
|
||||
g_value_set_boolean (value, private->highlight);
|
||||
break;
|
||||
case GIMP_RECTANGLE_OPTIONS_PROP_HIGHLIGHT_OPACITY:
|
||||
g_value_set_double (value, private->highlight_opacity);
|
||||
break;
|
||||
case GIMP_RECTANGLE_OPTIONS_PROP_GUIDE:
|
||||
g_value_set_enum (value, private->guide);
|
||||
break;
|
||||
@ -1036,10 +1042,18 @@ gimp_rectangle_options_gui (GimpToolOptions *tool_options)
|
||||
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
||||
gtk_widget_show (frame);
|
||||
|
||||
/* Highlight */
|
||||
button = gimp_prop_check_button_new (config, "highlight", NULL);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
|
||||
gtk_widget_show (button);
|
||||
/* the Highlight frame */
|
||||
{
|
||||
GtkWidget *scale;
|
||||
|
||||
scale = gimp_prop_spin_scale_new (config, "highlight-opacity", NULL,
|
||||
0.01, 0.1, 2);
|
||||
|
||||
frame = gimp_prop_expanding_frame_new (config, "highlight", NULL,
|
||||
scale, NULL);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
||||
gtk_widget_show (frame);
|
||||
}
|
||||
|
||||
/* Guide */
|
||||
combo = gimp_prop_enum_combo_box_new (config, "guide",
|
||||
|
@ -26,6 +26,7 @@ typedef enum
|
||||
GIMP_RECTANGLE_OPTIONS_PROP_AUTO_SHRINK,
|
||||
GIMP_RECTANGLE_OPTIONS_PROP_SHRINK_MERGED,
|
||||
GIMP_RECTANGLE_OPTIONS_PROP_HIGHLIGHT,
|
||||
GIMP_RECTANGLE_OPTIONS_PROP_HIGHLIGHT_OPACITY,
|
||||
GIMP_RECTANGLE_OPTIONS_PROP_GUIDE,
|
||||
|
||||
GIMP_RECTANGLE_OPTIONS_PROP_X,
|
||||
@ -80,6 +81,7 @@ struct _GimpRectangleOptionsPrivate
|
||||
gboolean shrink_merged;
|
||||
|
||||
gboolean highlight;
|
||||
gdouble highlight_opacity;
|
||||
GimpGuidesType guide;
|
||||
|
||||
gdouble x;
|
||||
|
@ -80,6 +80,14 @@ gimp_rectangle_select_options_class_init (GimpRectangleSelectOptionsClass *klass
|
||||
FALSE,
|
||||
GIMP_PARAM_STATIC_STRINGS);
|
||||
|
||||
GIMP_CONFIG_PROP_DOUBLE (object_class,
|
||||
GIMP_RECTANGLE_OPTIONS_PROP_HIGHLIGHT_OPACITY,
|
||||
"highlight-opacity",
|
||||
_("Highlight opacity"),
|
||||
_("How much to dim everything outside selection"),
|
||||
0.0, 1.0, 0.5,
|
||||
GIMP_PARAM_STATIC_STRINGS);
|
||||
|
||||
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_ROUND_CORNERS,
|
||||
"round-corners",
|
||||
_("Rounded corners"),
|
||||
|
@ -688,6 +688,7 @@ gimp_rectangle_select_tool_start (GimpRectangleSelectTool *rect_tool,
|
||||
static const gchar *properties[] =
|
||||
{
|
||||
"highlight",
|
||||
"highlight-opacity",
|
||||
"guide",
|
||||
"round-corners",
|
||||
"corner-radius",
|
||||
@ -878,7 +879,7 @@ gimp_rectangle_select_tool_halt (GimpRectangleSelectTool *rect_tool)
|
||||
{
|
||||
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
||||
|
||||
gimp_display_shell_set_highlight (shell, NULL);
|
||||
gimp_display_shell_set_highlight (shell, NULL, 0.0);
|
||||
|
||||
gimp_rectangle_options_disconnect (GIMP_RECTANGLE_OPTIONS (options),
|
||||
G_CALLBACK (gimp_rectangle_select_tool_auto_shrink),
|
||||
|
Reference in New Issue
Block a user