spinbutton: rework GtkSpinButton drawing handler

Make the arrows bigger, and position them according to the mockups.
This commit is contained in:
Cosimo Cecchi 2011-02-28 15:44:53 -05:00
parent cae7b93729
commit 6a423a99ad

View File

@ -988,14 +988,9 @@ gtk_spin_button_draw_arrow (GtkSpinButton *spin_button,
GtkJunctionSides junction; GtkJunctionSides junction;
GtkStateFlags state; GtkStateFlags state;
GtkWidget *widget; GtkWidget *widget;
GtkBorder padding;
gdouble angle; gdouble angle;
gint x;
gint y;
gint panel_height; gint panel_height;
gint height; gdouble size, width, height, actual_width, x, y;
gint width;
gint h, w;
g_return_if_fail (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN); g_return_if_fail (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN);
@ -1008,25 +1003,6 @@ gtk_spin_button_draw_arrow (GtkSpinButton *spin_button,
panel_height = gdk_window_get_height (priv->panel); panel_height = gdk_window_get_height (priv->panel);
if (arrow_type == GTK_ARROW_UP)
{
x = 0;
y = 0;
height = panel_height / 2;
angle = 0;
junction |= GTK_JUNCTION_BOTTOM;
}
else
{
x = 0;
y = panel_height / 2;
height = (panel_height + 1) / 2;
angle = G_PI;
junction |= GTK_JUNCTION_TOP;
}
if (spin_button_at_limit (spin_button, arrow_type)) if (spin_button_at_limit (spin_button, arrow_type))
state = GTK_STATE_FLAG_INSENSITIVE; state = GTK_STATE_FLAG_INSENSITIVE;
else else
@ -1043,47 +1019,52 @@ gtk_spin_button_draw_arrow (GtkSpinButton *spin_button,
} }
} }
gtk_style_context_get_padding (context, state, &padding); /* first, draw the background and the frame */
if (arrow_type == GTK_ARROW_UP)
{
x = 0;
y = 0;
junction |= GTK_JUNCTION_BOTTOM;
}
else if (arrow_type == GTK_ARROW_DOWN)
{
x = 0;
y = panel_height / 2.0;
junction |= GTK_JUNCTION_TOP;
}
gtk_style_context_set_junction_sides (context, junction); gtk_style_context_set_junction_sides (context, junction);
gtk_style_context_set_state (context, state); gtk_style_context_set_state (context, state);
width = spin_button_get_arrow_size (spin_button) + padding.left + padding.right; height = panel_height / 2.0;
width = gdk_window_get_width (priv->panel);
gtk_render_background (context, cr,
x, y, width, height);
gtk_render_frame (context, cr,
x, y, width, height);
gtk_render_background (context, cr, x, y, width, height); /* make the actual rendered arrow smaller than text size */
gtk_render_frame (context, cr, x, y, width, height); size = spin_button_get_arrow_size (spin_button);
size = MIN (size, width);
size *= 0.8;
height = panel_height; x = (width - size) / 2.0;
if (arrow_type == GTK_ARROW_DOWN) if (arrow_type == GTK_ARROW_UP)
{ {
y = height / 2; y = (height - size / 2.0) / 2.0;
height = height - y - 2; angle = 0;
} }
else else if (arrow_type == GTK_ARROW_DOWN)
{ {
y = 2; y = height + ((height - size / 2.0) / 2.0) - size / 2.0;
height = height / 2 - 2; angle = G_PI;
} }
width -= 3;
if (widget && gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
x = 2;
else
x = 1;
w = width / 2;
w -= w % 2 - 1; /* force odd */
h = (w + 1) / 2;
x += (width - w) / 2;
y += (height - h) / 2;
height = h;
width = w;
gtk_render_arrow (context, cr, gtk_render_arrow (context, cr,
angle, x, y, width); angle, x, y, size);
gtk_style_context_restore (context); gtk_style_context_restore (context);
} }