scale: implement rendering for marks gadgets

This completes the conversion of scale marks to gadgets.
This commit is contained in:
Cosimo Cecchi 2016-02-28 09:23:14 -08:00
parent 1a8eb9fefa
commit cdd7a7bdcd

View File

@ -1324,32 +1324,18 @@ find_next_pos (GtkWidget *widget,
} }
static gboolean static gboolean
gtk_scale_draw (GtkWidget *widget, gtk_scale_render_marks (GtkCssGadget *gadget,
cairo_t *cr) cairo_t *cr,
int x,
int y,
int width,
int height,
gpointer user_data)
{ {
GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
GtkScale *scale = GTK_SCALE (widget); GtkScale *scale = GTK_SCALE (widget);
GtkScalePrivate *priv = scale->priv; GtkScalePrivate *priv = scale->priv;
GtkRange *range = GTK_RANGE (scale);
GtkStyleContext *context;
gint *marks;
gint value_spacing;
gint min_sep = 4;
GtkCssGadget *slider_gadget;
GtkAllocation slider_alloc;
context = gtk_widget_get_style_context (widget);
slider_gadget = gtk_range_get_slider_gadget (range);
gtk_css_gadget_get_content_allocation (slider_gadget,
&slider_alloc, NULL);
gtk_widget_style_get (widget,
"value-spacing", &value_spacing,
NULL);
if (priv->marks)
{
GtkOrientation orientation; GtkOrientation orientation;
GdkRectangle range_rect, marks_alloc;
gint i; gint i;
gint x1, x2, x3, y1, y2, y3; gint x1, x2, x3, y1, y2, y3;
PangoLayout *layout; PangoLayout *layout;
@ -1357,12 +1343,27 @@ gtk_scale_draw (GtkWidget *widget,
GSList *m; GSList *m;
gint min_pos_before, min_pos_after; gint min_pos_before, min_pos_after;
gint min_pos, max_pos; gint min_pos, max_pos;
GtkCssGadget *slider_gadget;
GtkAllocation slider_alloc;
gint value_spacing;
gint min_sep = 4;
gint *marks;
GtkStyleContext *context;
GtkRange *range = GTK_RANGE (scale);
context = gtk_widget_get_style_context (widget);
gtk_widget_style_get (widget,
"value-spacing", &value_spacing,
NULL);
slider_gadget = gtk_range_get_slider_gadget (range);
gtk_css_gadget_get_content_allocation (slider_gadget,
&slider_alloc, NULL);
orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (range)); orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (range));
_gtk_range_get_stop_positions (range, &marks); _gtk_range_get_stop_positions (range, &marks);
layout = gtk_widget_create_pango_layout (widget, NULL); layout = gtk_widget_create_pango_layout (widget, NULL);
gtk_range_get_range_rect (range, &range_rect);
min_pos_before = min_pos_after = 0; min_pos_before = min_pos_after = 0;
@ -1370,6 +1371,10 @@ gtk_scale_draw (GtkWidget *widget,
{ {
GtkScaleMark *mark = m->data; GtkScaleMark *mark = m->data;
if ((mark->position == GTK_POS_TOP && gadget == priv->bottom_marks_gadget) ||
(mark->position == GTK_POS_BOTTOM && gadget == priv->top_marks_gadget))
continue;
gtk_style_context_save_to_node (context, mark->node); gtk_style_context_save_to_node (context, mark->node);
if (orientation == GTK_ORIENTATION_HORIZONTAL) if (orientation == GTK_ORIENTATION_HORIZONTAL)
@ -1377,17 +1382,15 @@ gtk_scale_draw (GtkWidget *widget,
x1 = marks[i]; x1 = marks[i];
if (mark->position == GTK_POS_TOP) if (mark->position == GTK_POS_TOP)
{ {
gtk_css_gadget_get_content_box (priv->top_marks_gadget, &marks_alloc); y1 = y + height;
y1 = marks_alloc.y + marks_alloc.height; y2 = y + height - slider_alloc.height / 4;
y2 = marks_alloc.y + marks_alloc.height - slider_alloc.height / 4;
min_pos = min_pos_before; min_pos = min_pos_before;
max_pos = find_next_pos (widget, m, marks + i, GTK_POS_TOP) - min_sep; max_pos = find_next_pos (widget, m, marks + i, GTK_POS_TOP) - min_sep;
} }
else else
{ {
gtk_css_gadget_get_content_box (priv->bottom_marks_gadget, &marks_alloc); y1 = y;
y1 = marks_alloc.y; y2 = y + slider_alloc.height / 4;
y2 = marks_alloc.y + slider_alloc.height / 4;
min_pos = min_pos_after; min_pos = min_pos_after;
max_pos = find_next_pos (widget, m, marks + i, GTK_POS_BOTTOM) - min_sep; max_pos = find_next_pos (widget, m, marks + i, GTK_POS_BOTTOM) - min_sep;
} }
@ -1424,17 +1427,15 @@ gtk_scale_draw (GtkWidget *widget,
{ {
if (mark->position == GTK_POS_TOP) if (mark->position == GTK_POS_TOP)
{ {
gtk_css_gadget_get_content_box (priv->top_marks_gadget, &marks_alloc); x1 = x + width;
x1 = marks_alloc.x + slider_alloc.width / 4; x2 = x + width - slider_alloc.width / 4;
x2 = marks_alloc.x;
min_pos = min_pos_before; min_pos = min_pos_before;
max_pos = find_next_pos (widget, m, marks + i, GTK_POS_TOP) - min_sep; max_pos = find_next_pos (widget, m, marks + i, GTK_POS_TOP) - min_sep;
} }
else else
{ {
gtk_css_gadget_get_content_box (priv->bottom_marks_gadget, &marks_alloc); x1 = x;
x1 = marks_alloc.x; x2 = x + slider_alloc.width / 4;
x2 = marks_alloc.x + slider_alloc.width / 4;
min_pos = min_pos_after; min_pos = min_pos_after;
max_pos = find_next_pos (widget, m, marks + i, GTK_POS_BOTTOM) - min_sep; max_pos = find_next_pos (widget, m, marks + i, GTK_POS_BOTTOM) - min_sep;
} }
@ -1474,17 +1475,32 @@ gtk_scale_draw (GtkWidget *widget,
g_object_unref (layout); g_object_unref (layout);
g_free (marks); g_free (marks);
}
return FALSE;
}
static gboolean
gtk_scale_draw (GtkWidget *widget,
cairo_t *cr)
{
GtkScale *scale = GTK_SCALE (widget);
GtkScalePrivate *priv = scale->priv;
if (priv->top_marks_gadget)
gtk_css_gadget_draw (priv->top_marks_gadget, cr);
if (priv->bottom_marks_gadget)
gtk_css_gadget_draw (priv->bottom_marks_gadget, cr);
GTK_WIDGET_CLASS (gtk_scale_parent_class)->draw (widget, cr); GTK_WIDGET_CLASS (gtk_scale_parent_class)->draw (widget, cr);
if (priv->draw_value) if (priv->draw_value)
{ {
GtkAllocation allocation; GtkAllocation allocation;
GtkStyleContext *context;
PangoLayout *layout; PangoLayout *layout;
gint x, y; gint x, y;
context = gtk_widget_get_style_context (widget);
layout = gtk_scale_get_layout (scale); layout = gtk_scale_get_layout (scale);
gtk_scale_get_layout_offsets (scale, &x, &y); gtk_scale_get_layout_offsets (scale, &x, &y);
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_allocation (widget, &allocation);
@ -1812,7 +1828,7 @@ gtk_scale_add_mark (GtkScale *scale,
GTK_WIDGET (scale), NULL, NULL, GTK_WIDGET (scale), NULL, NULL,
gtk_scale_measure_marks, gtk_scale_measure_marks,
NULL, NULL,
NULL, gtk_scale_render_marks,
NULL, NULL); NULL, NULL);
gtk_css_node_insert_after (widget_node, gtk_css_gadget_get_node (priv->top_marks_gadget), NULL); gtk_css_node_insert_after (widget_node, gtk_css_gadget_get_node (priv->top_marks_gadget), NULL);
gtk_css_gadget_add_class (priv->top_marks_gadget, GTK_STYLE_CLASS_TOP); gtk_css_gadget_add_class (priv->top_marks_gadget, GTK_STYLE_CLASS_TOP);
@ -1829,7 +1845,7 @@ gtk_scale_add_mark (GtkScale *scale,
GTK_WIDGET (scale), NULL, NULL, GTK_WIDGET (scale), NULL, NULL,
gtk_scale_measure_marks, gtk_scale_measure_marks,
NULL, NULL,
NULL, gtk_scale_render_marks,
NULL, NULL); NULL, NULL);
gtk_css_node_insert_before (widget_node, gtk_css_gadget_get_node (priv->bottom_marks_gadget), NULL); gtk_css_node_insert_before (widget_node, gtk_css_gadget_get_node (priv->bottom_marks_gadget), NULL);
gtk_css_gadget_add_class (priv->bottom_marks_gadget, GTK_STYLE_CLASS_BOTTOM); gtk_css_gadget_add_class (priv->bottom_marks_gadget, GTK_STYLE_CLASS_BOTTOM);