mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-15 23:00:08 +00:00
GtkThemingEngine: draw resize grip through render_handle().
GtkJunctionSides is used instead of GdkWindowEdge, GtkStyle implementation has changed to use GtkStyleContext's.
This commit is contained in:
parent
227294a6aa
commit
af1f8701dc
311
gtk/gtkstyle.c
311
gtk/gtkstyle.c
@ -3323,284 +3323,83 @@ gtk_default_draw_resize_grip (GtkStyle *style,
|
||||
gint width,
|
||||
gint height)
|
||||
{
|
||||
gint skip;
|
||||
GtkStyleContext *context;
|
||||
GtkStylePrivate *priv;
|
||||
GtkStateFlags flags = 0;
|
||||
GtkJunctionSides sides = 0;
|
||||
|
||||
cairo_rectangle (cr, x, y, width, height);
|
||||
cairo_clip (cr);
|
||||
if (widget)
|
||||
context = gtk_widget_get_style_context (widget);
|
||||
else
|
||||
{
|
||||
priv = GTK_STYLE_GET_PRIVATE (style);
|
||||
context = priv->context;
|
||||
}
|
||||
|
||||
cairo_set_line_width (cr, 1.0);
|
||||
gtk_style_context_save (context);
|
||||
|
||||
if (detail)
|
||||
transform_detail_string (detail, context);
|
||||
|
||||
gtk_style_context_add_class (context, "grip");
|
||||
|
||||
switch (state_type)
|
||||
{
|
||||
case GTK_STATE_PRELIGHT:
|
||||
flags |= GTK_STATE_FLAG_PRELIGHT;
|
||||
break;
|
||||
case GTK_STATE_SELECTED:
|
||||
flags |= GTK_STATE_FLAG_SELECTED;
|
||||
break;
|
||||
case GTK_STATE_INSENSITIVE:
|
||||
flags |= GTK_STATE_FLAG_INSENSITIVE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
gtk_style_context_set_state (context, flags);
|
||||
|
||||
skip = -1;
|
||||
switch (edge)
|
||||
{
|
||||
case GDK_WINDOW_EDGE_NORTH_WEST:
|
||||
/* make it square */
|
||||
if (width < height)
|
||||
height = width;
|
||||
else if (height < width)
|
||||
width = height;
|
||||
skip = 2;
|
||||
sides = GTK_JUNCTION_TOP | GTK_JUNCTION_LEFT;
|
||||
break;
|
||||
case GDK_WINDOW_EDGE_NORTH:
|
||||
if (width < height)
|
||||
height = width;
|
||||
sides = GTK_JUNCTION_TOP;
|
||||
break;
|
||||
case GDK_WINDOW_EDGE_NORTH_EAST:
|
||||
/* make it square, aligning to top right */
|
||||
if (width < height)
|
||||
height = width;
|
||||
else if (height < width)
|
||||
{
|
||||
x += (width - height);
|
||||
width = height;
|
||||
}
|
||||
skip = 3;
|
||||
sides = GTK_JUNCTION_TOP | GTK_JUNCTION_RIGHT;
|
||||
break;
|
||||
case GDK_WINDOW_EDGE_WEST:
|
||||
if (height < width)
|
||||
width = height;
|
||||
sides = GTK_JUNCTION_LEFT;
|
||||
break;
|
||||
case GDK_WINDOW_EDGE_EAST:
|
||||
/* aligning to right */
|
||||
if (height < width)
|
||||
{
|
||||
x += (width - height);
|
||||
width = height;
|
||||
}
|
||||
sides = GTK_JUNCTION_RIGHT;
|
||||
break;
|
||||
case GDK_WINDOW_EDGE_SOUTH_WEST:
|
||||
/* make it square, aligning to bottom left */
|
||||
if (width < height)
|
||||
{
|
||||
y += (height - width);
|
||||
height = width;
|
||||
}
|
||||
else if (height < width)
|
||||
width = height;
|
||||
skip = 1;
|
||||
sides = GTK_JUNCTION_BOTTOM | GTK_JUNCTION_LEFT;
|
||||
break;
|
||||
case GDK_WINDOW_EDGE_SOUTH:
|
||||
/* align to bottom */
|
||||
if (width < height)
|
||||
{
|
||||
y += (height - width);
|
||||
height = width;
|
||||
}
|
||||
sides = GTK_JUNCTION_BOTTOM;
|
||||
break;
|
||||
case GDK_WINDOW_EDGE_SOUTH_EAST:
|
||||
/* make it square, aligning to bottom right */
|
||||
if (width < height)
|
||||
{
|
||||
y += (height - width);
|
||||
height = width;
|
||||
}
|
||||
else if (height < width)
|
||||
{
|
||||
x += (width - height);
|
||||
width = height;
|
||||
}
|
||||
skip = 0;
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
switch (edge)
|
||||
{
|
||||
case GDK_WINDOW_EDGE_WEST:
|
||||
case GDK_WINDOW_EDGE_EAST:
|
||||
{
|
||||
gint xi;
|
||||
|
||||
xi = x;
|
||||
|
||||
while (xi < x + width)
|
||||
{
|
||||
_cairo_draw_line (cr,
|
||||
&style->light[state_type],
|
||||
xi, y,
|
||||
xi, y + height);
|
||||
|
||||
xi++;
|
||||
_cairo_draw_line (cr,
|
||||
&style->dark[state_type],
|
||||
xi, y,
|
||||
xi, y + height);
|
||||
|
||||
xi += 2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GDK_WINDOW_EDGE_NORTH:
|
||||
case GDK_WINDOW_EDGE_SOUTH:
|
||||
{
|
||||
gint yi;
|
||||
|
||||
yi = y;
|
||||
|
||||
while (yi < y + height)
|
||||
{
|
||||
_cairo_draw_line (cr,
|
||||
&style->light[state_type],
|
||||
x, yi,
|
||||
x + width, yi);
|
||||
|
||||
yi++;
|
||||
_cairo_draw_line (cr,
|
||||
&style->dark[state_type],
|
||||
x, yi,
|
||||
x + width, yi);
|
||||
|
||||
yi+= 2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GDK_WINDOW_EDGE_NORTH_WEST:
|
||||
{
|
||||
gint xi, yi;
|
||||
|
||||
xi = x + width;
|
||||
yi = y + height;
|
||||
|
||||
while (xi > x + 3)
|
||||
{
|
||||
_cairo_draw_line (cr,
|
||||
&style->dark[state_type],
|
||||
xi, y,
|
||||
x, yi);
|
||||
|
||||
--xi;
|
||||
--yi;
|
||||
|
||||
_cairo_draw_line (cr,
|
||||
&style->dark[state_type],
|
||||
xi, y,
|
||||
x, yi);
|
||||
|
||||
--xi;
|
||||
--yi;
|
||||
|
||||
_cairo_draw_line (cr,
|
||||
&style->light[state_type],
|
||||
xi, y,
|
||||
x, yi);
|
||||
|
||||
xi -= 3;
|
||||
yi -= 3;
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GDK_WINDOW_EDGE_NORTH_EAST:
|
||||
{
|
||||
gint xi, yi;
|
||||
|
||||
xi = x;
|
||||
yi = y + height;
|
||||
|
||||
while (xi < (x + width - 3))
|
||||
{
|
||||
_cairo_draw_line (cr,
|
||||
&style->light[state_type],
|
||||
xi, y,
|
||||
x + width, yi);
|
||||
|
||||
++xi;
|
||||
--yi;
|
||||
|
||||
_cairo_draw_line (cr,
|
||||
&style->dark[state_type],
|
||||
xi, y,
|
||||
x + width, yi);
|
||||
|
||||
++xi;
|
||||
--yi;
|
||||
|
||||
_cairo_draw_line (cr,
|
||||
&style->dark[state_type],
|
||||
xi, y,
|
||||
x + width, yi);
|
||||
|
||||
xi += 3;
|
||||
yi -= 3;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GDK_WINDOW_EDGE_SOUTH_WEST:
|
||||
{
|
||||
gint xi, yi;
|
||||
|
||||
xi = x + width;
|
||||
yi = y;
|
||||
|
||||
while (xi > x + 3)
|
||||
{
|
||||
_cairo_draw_line (cr,
|
||||
&style->dark[state_type],
|
||||
x, yi,
|
||||
xi, y + height);
|
||||
|
||||
--xi;
|
||||
++yi;
|
||||
|
||||
_cairo_draw_line (cr,
|
||||
&style->dark[state_type],
|
||||
x, yi,
|
||||
xi, y + height);
|
||||
|
||||
--xi;
|
||||
++yi;
|
||||
|
||||
_cairo_draw_line (cr,
|
||||
&style->light[state_type],
|
||||
x, yi,
|
||||
xi, y + height);
|
||||
|
||||
xi -= 3;
|
||||
yi += 3;
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GDK_WINDOW_EDGE_SOUTH_EAST:
|
||||
{
|
||||
gint xi, yi;
|
||||
|
||||
xi = x;
|
||||
yi = y;
|
||||
|
||||
while (xi < (x + width - 3))
|
||||
{
|
||||
_cairo_draw_line (cr,
|
||||
&style->light[state_type],
|
||||
xi, y + height,
|
||||
x + width, yi);
|
||||
|
||||
++xi;
|
||||
++yi;
|
||||
|
||||
_cairo_draw_line (cr,
|
||||
&style->dark[state_type],
|
||||
xi, y + height,
|
||||
x + width, yi);
|
||||
|
||||
++xi;
|
||||
++yi;
|
||||
|
||||
_cairo_draw_line (cr,
|
||||
&style->dark[state_type],
|
||||
xi, y + height,
|
||||
x + width, yi);
|
||||
|
||||
xi += 3;
|
||||
yi += 3;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
sides = GTK_JUNCTION_BOTTOM | GTK_JUNCTION_RIGHT;
|
||||
break;
|
||||
}
|
||||
|
||||
gtk_style_context_set_junction_sides (context, sides);
|
||||
|
||||
cairo_save (cr);
|
||||
|
||||
gtk_render_handle (context, cr,
|
||||
(gdouble) x,
|
||||
(gdouble) y,
|
||||
(gdouble) width,
|
||||
(gdouble) height);
|
||||
|
||||
cairo_restore (cr);
|
||||
gtk_style_context_restore (context);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -2426,7 +2426,272 @@ gtk_theming_engine_render_handle (GtkThemingEngine *engine,
|
||||
cairo_rectangle (cr, x, y, width, height);
|
||||
cairo_fill (cr);
|
||||
|
||||
if (gtk_theming_engine_has_class (engine, "paned"))
|
||||
if (gtk_theming_engine_has_class (engine, "grip"))
|
||||
{
|
||||
GtkJunctionSides sides;
|
||||
gint skip = -1;
|
||||
|
||||
cairo_save (cr);
|
||||
|
||||
cairo_set_line_width (cr, 1.0);
|
||||
sides = gtk_theming_engine_get_junction_sides (engine);
|
||||
|
||||
/* reduce confusing values to a meaningful state */
|
||||
if (sides & (GTK_JUNCTION_LEFT | GTK_JUNCTION_RIGHT))
|
||||
sides &= ~(GTK_JUNCTION_LEFT);
|
||||
|
||||
if (sides & (GTK_JUNCTION_TOP | GTK_JUNCTION_BOTTOM))
|
||||
sides &= ~(GTK_JUNCTION_TOP);
|
||||
|
||||
if (sides == 0)
|
||||
sides = (GTK_JUNCTION_BOTTOM | GTK_JUNCTION_RIGHT);
|
||||
|
||||
/* align drawing area to the connected side */
|
||||
if (sides == GTK_JUNCTION_LEFT)
|
||||
{
|
||||
if (height < width)
|
||||
width = height;
|
||||
}
|
||||
else if (sides & (GTK_JUNCTION_LEFT | GTK_JUNCTION_TOP))
|
||||
{
|
||||
if (width < height)
|
||||
height = width;
|
||||
else if (height < width)
|
||||
width = height;
|
||||
|
||||
skip = 2;
|
||||
}
|
||||
else if (sides & (GTK_JUNCTION_LEFT | GTK_JUNCTION_BOTTOM))
|
||||
{
|
||||
/* make it square, aligning to bottom left */
|
||||
if (width < height)
|
||||
{
|
||||
y += (height - width);
|
||||
height = width;
|
||||
}
|
||||
else if (height < width)
|
||||
width = height;
|
||||
|
||||
skip = 1;
|
||||
}
|
||||
if (sides == GTK_JUNCTION_RIGHT)
|
||||
{
|
||||
/* aligning to right */
|
||||
if (height < width)
|
||||
{
|
||||
x += (width - height);
|
||||
width = height;
|
||||
}
|
||||
}
|
||||
else if (sides & (GTK_JUNCTION_RIGHT | GTK_JUNCTION_TOP))
|
||||
{
|
||||
if (width < height)
|
||||
height = width;
|
||||
else if (height < width)
|
||||
{
|
||||
x += (width - height);
|
||||
width = height;
|
||||
}
|
||||
|
||||
skip = 3;
|
||||
}
|
||||
else if (sides & (GTK_JUNCTION_RIGHT | GTK_JUNCTION_BOTTOM))
|
||||
{
|
||||
/* make it square, aligning to bottom right */
|
||||
if (width < height)
|
||||
{
|
||||
y += (height - width);
|
||||
height = width;
|
||||
}
|
||||
else if (height < width)
|
||||
{
|
||||
x += (width - height);
|
||||
width = height;
|
||||
}
|
||||
|
||||
skip = 0;
|
||||
}
|
||||
else if (sides == GTK_JUNCTION_TOP)
|
||||
{
|
||||
if (width < height)
|
||||
height = width;
|
||||
}
|
||||
else if (sides == GTK_JUNCTION_BOTTOM)
|
||||
{
|
||||
/* align to bottom */
|
||||
if (width < height)
|
||||
{
|
||||
y += (height - width);
|
||||
height = width;
|
||||
}
|
||||
}
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
||||
if (sides == GTK_JUNCTION_LEFT ||
|
||||
sides == GTK_JUNCTION_RIGHT)
|
||||
{
|
||||
gint xi;
|
||||
|
||||
xi = x;
|
||||
|
||||
while (xi < x + width)
|
||||
{
|
||||
gdk_cairo_set_source_rgba (cr, &lighter);
|
||||
add_path_line (cr, x, y, x, y + height);
|
||||
cairo_stroke (cr);
|
||||
xi++;
|
||||
|
||||
gdk_cairo_set_source_rgba (cr, &darker);
|
||||
add_path_line (cr, xi, y, xi, y + height);
|
||||
cairo_stroke (cr);
|
||||
xi += 2;
|
||||
}
|
||||
}
|
||||
else if (sides == GTK_JUNCTION_TOP ||
|
||||
sides == GTK_JUNCTION_BOTTOM)
|
||||
{
|
||||
gint yi;
|
||||
|
||||
yi = y;
|
||||
|
||||
while (yi < y + height)
|
||||
{
|
||||
gdk_cairo_set_source_rgba (cr, &lighter);
|
||||
add_path_line (cr, x, yi, x + width, yi);
|
||||
cairo_stroke (cr);
|
||||
yi++;
|
||||
|
||||
gdk_cairo_set_source_rgba (cr, &darker);
|
||||
add_path_line (cr, x, yi, x + width, yi);
|
||||
cairo_stroke (cr);
|
||||
yi+= 2;
|
||||
}
|
||||
}
|
||||
else if (sides == (GTK_JUNCTION_TOP | GTK_JUNCTION_LEFT))
|
||||
{
|
||||
gint xi, yi;
|
||||
|
||||
xi = x + width;
|
||||
yi = y + height;
|
||||
|
||||
while (xi > x + 3)
|
||||
{
|
||||
gdk_cairo_set_source_rgba (cr, &darker);
|
||||
add_path_line (cr, xi, y, x, yi);
|
||||
cairo_stroke (cr);
|
||||
|
||||
--xi;
|
||||
--yi;
|
||||
|
||||
add_path_line (cr, xi, y, x, yi);
|
||||
cairo_stroke (cr);
|
||||
|
||||
--xi;
|
||||
--yi;
|
||||
|
||||
gdk_cairo_set_source_rgba (cr, &lighter);
|
||||
add_path_line (cr, xi, y, x, yi);
|
||||
cairo_stroke (cr);
|
||||
|
||||
xi -= 3;
|
||||
yi -= 3;
|
||||
}
|
||||
}
|
||||
else if (sides == (GTK_JUNCTION_TOP | GTK_JUNCTION_RIGHT))
|
||||
{
|
||||
gint xi, yi;
|
||||
|
||||
xi = x;
|
||||
yi = y + height;
|
||||
|
||||
while (xi < (x + width - 3))
|
||||
{
|
||||
gdk_cairo_set_source_rgba (cr, &lighter);
|
||||
add_path_line (cr, xi, y, x + width, yi);
|
||||
cairo_stroke (cr);
|
||||
|
||||
++xi;
|
||||
--yi;
|
||||
|
||||
gdk_cairo_set_source_rgba (cr, &darker);
|
||||
add_path_line (cr, xi, y, x + width, yi);
|
||||
cairo_stroke (cr);
|
||||
|
||||
++xi;
|
||||
--yi;
|
||||
|
||||
add_path_line (cr, xi, y, x + width, yi);
|
||||
cairo_stroke (cr);
|
||||
|
||||
xi += 3;
|
||||
yi -= 3;
|
||||
}
|
||||
}
|
||||
else if (sides == (GTK_JUNCTION_BOTTOM | GTK_JUNCTION_LEFT))
|
||||
{
|
||||
gint xi, yi;
|
||||
|
||||
xi = x + width;
|
||||
yi = y;
|
||||
|
||||
while (xi > x + 3)
|
||||
{
|
||||
gdk_cairo_set_source_rgba (cr, &darker);
|
||||
add_path_line (cr, x, yi, xi, y + height);
|
||||
cairo_stroke (cr);
|
||||
|
||||
--xi;
|
||||
++yi;
|
||||
|
||||
add_path_line (cr, x, yi, xi, y + height);
|
||||
cairo_stroke (cr);
|
||||
|
||||
--xi;
|
||||
++yi;
|
||||
|
||||
gdk_cairo_set_source_rgba (cr, &lighter);
|
||||
add_path_line (cr, x, yi, xi, y + height);
|
||||
cairo_stroke (cr);
|
||||
|
||||
xi -= 3;
|
||||
yi += 3;
|
||||
}
|
||||
}
|
||||
else if (sides == (GTK_JUNCTION_BOTTOM | GTK_JUNCTION_RIGHT))
|
||||
{
|
||||
gint xi, yi;
|
||||
|
||||
xi = x;
|
||||
yi = y;
|
||||
|
||||
while (xi < (x + width - 3))
|
||||
{
|
||||
gdk_cairo_set_source_rgba (cr, &lighter);
|
||||
add_path_line (cr, xi, y + height, x + width, yi);
|
||||
cairo_stroke (cr);
|
||||
|
||||
++xi;
|
||||
++yi;
|
||||
|
||||
gdk_cairo_set_source_rgba (cr, &darker);
|
||||
add_path_line (cr, xi, y + height, x + width, yi);
|
||||
cairo_stroke (cr);
|
||||
|
||||
++xi;
|
||||
++yi;
|
||||
|
||||
add_path_line (cr, xi, y + height, x + width, yi);
|
||||
cairo_stroke (cr);
|
||||
|
||||
xi += 3;
|
||||
yi += 3;
|
||||
}
|
||||
}
|
||||
|
||||
cairo_restore (cr);
|
||||
}
|
||||
else if (gtk_theming_engine_has_class (engine, "paned"))
|
||||
{
|
||||
if (width > height)
|
||||
for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
|
||||
|
Loading…
Reference in New Issue
Block a user