mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-08 09:40:10 +00:00
path-tool: Add a --point-color option
This commit is contained in:
parent
9bd9b6f2ca
commit
1e9e8d24c3
@ -37,7 +37,8 @@ show_path_fill (GskPath *path,
|
||||
const GdkRGBA *fg_color,
|
||||
const GdkRGBA *bg_color,
|
||||
gboolean show_points,
|
||||
gboolean show_controls)
|
||||
gboolean show_controls,
|
||||
const GdkRGBA *point_color)
|
||||
{
|
||||
GtkWidget *window, *sw, *child;
|
||||
|
||||
@ -59,6 +60,7 @@ show_path_fill (GskPath *path,
|
||||
"bg-color", bg_color,
|
||||
"show-points", show_points,
|
||||
"show-controls", show_controls,
|
||||
"point-color", point_color,
|
||||
NULL);
|
||||
|
||||
gtk_widget_set_hexpand (child, TRUE);
|
||||
@ -77,7 +79,8 @@ show_path_stroke (GskPath *path,
|
||||
const GdkRGBA *fg_color,
|
||||
const GdkRGBA *bg_color,
|
||||
gboolean show_points,
|
||||
gboolean show_controls)
|
||||
gboolean show_controls,
|
||||
const GdkRGBA *point_color)
|
||||
{
|
||||
GtkWidget *window, *sw, *child;
|
||||
|
||||
@ -99,6 +102,7 @@ show_path_stroke (GskPath *path,
|
||||
"bg-color", bg_color,
|
||||
"show-points", show_points,
|
||||
"show-controls", show_controls,
|
||||
"point-color", point_color,
|
||||
NULL);
|
||||
|
||||
gtk_widget_set_hexpand (child, TRUE);
|
||||
@ -122,6 +126,7 @@ do_show (int *argc,
|
||||
const char *fill = "winding";
|
||||
const char *fg_color = "black";
|
||||
const char *bg_color = "white";
|
||||
const char *point_color = "red";
|
||||
double line_width = 1;
|
||||
const char *cap = "butt";
|
||||
const char *join = "miter";
|
||||
@ -134,10 +139,11 @@ do_show (int *argc,
|
||||
const GOptionEntry entries[] = {
|
||||
{ "fill", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &do_stroke, N_("Fill the path (the default)"), NULL },
|
||||
{ "stroke", 0, 0, G_OPTION_ARG_NONE, &do_stroke, N_("Stroke the path"), NULL },
|
||||
{ "points", 0, 0, G_OPTION_ARG_NONE, &show_points, N_("Show points"), NULL },
|
||||
{ "controls", 0, 0, G_OPTION_ARG_NONE, &show_controls, N_("Show controls"), NULL },
|
||||
{ "points", 0, 0, G_OPTION_ARG_NONE, &show_points, N_("Show path points"), NULL },
|
||||
{ "controls", 0, 0, G_OPTION_ARG_NONE, &show_controls, N_("Show control points"), NULL },
|
||||
{ "fg-color", 0, 0, G_OPTION_ARG_STRING, &fg_color, N_("Foreground color"), N_("COLOR") },
|
||||
{ "bg-color", 0, 0, G_OPTION_ARG_STRING, &bg_color, N_("Background color"), N_("COLOR") },
|
||||
{ "point-color", 0, 0, G_OPTION_ARG_STRING, &point_color, N_("Point color"), N_("COLOR") },
|
||||
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &args, NULL, N_("PATH") },
|
||||
{ NULL, }
|
||||
};
|
||||
@ -156,8 +162,7 @@ do_show (int *argc,
|
||||
};
|
||||
GskPath *path;
|
||||
GskFillRule fill_rule;
|
||||
GdkRGBA fg;
|
||||
GdkRGBA bg;
|
||||
GdkRGBA fg, bg, pc;
|
||||
GskLineCap line_cap;
|
||||
GskLineJoin line_join;
|
||||
GskStroke *stroke;
|
||||
@ -216,6 +221,7 @@ do_show (int *argc,
|
||||
fill_rule = get_enum_value (GSK_TYPE_FILL_RULE, _("fill rule"), fill);
|
||||
get_color (&fg, fg_color);
|
||||
get_color (&bg, bg_color);
|
||||
get_color (&pc, point_color);
|
||||
|
||||
line_cap = get_enum_value (GSK_TYPE_LINE_CAP, _("line cap"), cap);
|
||||
line_join = get_enum_value (GSK_TYPE_LINE_JOIN, _("line join"), join);
|
||||
@ -228,9 +234,9 @@ do_show (int *argc,
|
||||
_gsk_stroke_set_dashes (stroke, dashes);
|
||||
|
||||
if (do_stroke)
|
||||
show_path_stroke (path, stroke, &fg, &bg, show_points, show_controls);
|
||||
show_path_stroke (path, stroke, &fg, &bg, show_points, show_controls, &pc);
|
||||
else
|
||||
show_path_fill (path, fill_rule, &fg, &bg, show_points, show_controls);
|
||||
show_path_fill (path, fill_rule, &fg, &bg, show_points, show_controls, &pc);
|
||||
|
||||
gsk_path_unref (path);
|
||||
|
||||
|
@ -37,6 +37,7 @@ struct _PathView
|
||||
gboolean show_controls;
|
||||
GskPath *line_path;
|
||||
GskPath *point_path;
|
||||
GdkRGBA point_color;
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -46,6 +47,7 @@ enum {
|
||||
PROP_FILL_RULE,
|
||||
PROP_FG_COLOR,
|
||||
PROP_BG_COLOR,
|
||||
PROP_POINT_COLOR,
|
||||
PROP_SHOW_POINTS,
|
||||
PROP_SHOW_CONTROLS,
|
||||
N_PROPERTIES
|
||||
@ -68,6 +70,7 @@ path_view_init (PathView *self)
|
||||
self->fill_rule = GSK_FILL_RULE_WINDING;
|
||||
self->fg = (GdkRGBA) { 0, 0, 0, 1};
|
||||
self->bg = (GdkRGBA) { 1, 1, 1, 1};
|
||||
self->point_color = (GdkRGBA) { 1, 0, 0, 1};
|
||||
self->padding = 10;
|
||||
}
|
||||
|
||||
@ -126,6 +129,10 @@ path_view_get_property (GObject *object,
|
||||
g_value_set_boolean (value, self->show_controls);
|
||||
break;
|
||||
|
||||
case PROP_POINT_COLOR:
|
||||
g_value_set_boxed (value, &self->point_color);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@ -155,6 +162,8 @@ update_bounds (PathView *self)
|
||||
gsk_path_get_stroke_bounds (self->point_path, self->stroke, &bounds);
|
||||
graphene_rect_union (&bounds, &self->bounds, &self->bounds);
|
||||
}
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
typedef struct
|
||||
@ -274,21 +283,17 @@ path_view_set_property (GObject *object,
|
||||
g_clear_pointer (&self->path, gsk_path_unref);
|
||||
self->path = g_value_dup_boxed (value);
|
||||
update_controls (self);
|
||||
update_bounds (self);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
break;
|
||||
|
||||
case PROP_DO_FILL:
|
||||
self->do_fill = g_value_get_boolean (value);
|
||||
update_bounds (self);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
break;
|
||||
|
||||
case PROP_STROKE:
|
||||
gsk_stroke_free (self->stroke);
|
||||
self->stroke = g_value_get_boxed (value);
|
||||
update_bounds (self);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
break;
|
||||
|
||||
case PROP_FILL_RULE:
|
||||
@ -309,12 +314,15 @@ path_view_set_property (GObject *object,
|
||||
case PROP_SHOW_POINTS:
|
||||
self->show_points = g_value_get_boolean (value);
|
||||
update_controls (self);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
break;
|
||||
|
||||
case PROP_SHOW_CONTROLS:
|
||||
self->show_controls = g_value_get_boolean (value);
|
||||
update_controls (self);
|
||||
break;
|
||||
|
||||
case PROP_POINT_COLOR:
|
||||
self->point_color = *(GdkRGBA *) g_value_get_boxed (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
break;
|
||||
|
||||
@ -352,8 +360,7 @@ path_view_snapshot (GtkWidget *widget,
|
||||
|
||||
gtk_snapshot_save (snapshot);
|
||||
|
||||
gtk_snapshot_append_color (snapshot, &self->bg, &self->bounds);
|
||||
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (self->padding, self->padding));
|
||||
gtk_snapshot_append_color (snapshot, &self->bg, &bounds);
|
||||
|
||||
if (self->do_fill)
|
||||
gtk_snapshot_append_fill (snapshot, self->path, self->fill_rule, &self->fg);
|
||||
@ -363,19 +370,17 @@ path_view_snapshot (GtkWidget *widget,
|
||||
if (self->line_path)
|
||||
{
|
||||
GskStroke *stroke = gsk_stroke_new (1);
|
||||
GdkRGBA gray = (GdkRGBA) { 0, 0, 0, 0.5 };
|
||||
|
||||
gtk_snapshot_append_stroke (snapshot, self->line_path, stroke, &gray);
|
||||
gsk_stroke_set_dash (stroke, (const float[]) { 1, 1 }, 2);
|
||||
gtk_snapshot_append_stroke (snapshot, self->line_path, stroke, &self->fg);
|
||||
}
|
||||
|
||||
if (self->point_path)
|
||||
{
|
||||
GskStroke *stroke = gsk_stroke_new (1);
|
||||
GdkRGBA purple = (GdkRGBA) { 1, 0, 1, 1 };
|
||||
GdkRGBA black = (GdkRGBA) { 0, 0, 0, 1 };
|
||||
|
||||
gtk_snapshot_append_fill (snapshot, self->point_path, GSK_FILL_RULE_WINDING, &purple);
|
||||
gtk_snapshot_append_stroke (snapshot, self->point_path, stroke, &black);
|
||||
gtk_snapshot_append_fill (snapshot, self->point_path, GSK_FILL_RULE_WINDING, &self->point_color);
|
||||
gtk_snapshot_append_stroke (snapshot, self->point_path, stroke, &self->fg);
|
||||
}
|
||||
|
||||
gtk_snapshot_restore (snapshot);
|
||||
@ -435,6 +440,11 @@ path_view_class_init (PathViewClass *class)
|
||||
FALSE,
|
||||
G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
properties[PROP_POINT_COLOR]
|
||||
= g_param_spec_boxed ("point-color", NULL, NULL,
|
||||
GDK_TYPE_RGBA,
|
||||
G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user