#include <gtk/gtkstylecontext.h>
#include <gtk/gtkintl.h>
+#include "gtkprivate.h"
#include "gtk9slice.h"
#include "gtkpango.h"
* must be created, alongside the CSS file that will reference it, the
* theming engine would be created as an .so library, and installed in
* $(gtk-modules-dir)/theming-engines/.
+ *
+ * #GtkThemingEngine<!-- -->s have limited access to the object they are
+ * rendering, the #GtkThemingEngine API has read-only accessors to the
+ * style information contained in the rendered object's #GtkStyleContext.
*/
typedef struct GtkThemingEnginePrivate GtkThemingEnginePrivate;
SIDE_ALL = 0xF
};
+enum {
+ PROP_0,
+ PROP_NAME
+};
+
struct GtkThemingEnginePrivate
{
GtkStyleContext *context;
+ gchar *name;
};
#define GTK_THEMING_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_THEMING_ENGINE, GtkThemingEnginePrivate))
+static void gtk_theming_engine_finalize (GObject *object);
+static void gtk_theming_engine_impl_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_theming_engine_impl_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+
static void gtk_theming_engine_render_check (GtkThemingEngine *engine,
cairo_t *cr,
gdouble x,
gdouble y,
gdouble width,
gdouble height);
+static void gtk_theming_engine_render_activity (GtkThemingEngine *engine,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height);
+static GdkPixbuf * gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
+ const GtkIconSource *source,
+ GtkIconSize size);
G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = gtk_theming_engine_finalize;
+ object_class->set_property = gtk_theming_engine_impl_set_property;
+ object_class->get_property = gtk_theming_engine_impl_get_property;
+
klass->render_check = gtk_theming_engine_render_check;
klass->render_option = gtk_theming_engine_render_option;
klass->render_arrow = gtk_theming_engine_render_arrow;
klass->render_frame_gap = gtk_theming_engine_render_frame_gap;
klass->render_extension = gtk_theming_engine_render_extension;
klass->render_handle = gtk_theming_engine_render_handle;
+ klass->render_activity = gtk_theming_engine_render_activity;
+ klass->render_icon_pixbuf = gtk_theming_engine_render_icon_pixbuf;
+
+ /**
+ * GtkThemingEngine:name:
+ *
+ * The theming engine name, this name will be used when registering
+ * custom properties, for a theming engine named "Clearlooks" registering
+ * a "glossy" custom property, it could be referenced in the CSS file as
+ *
+ * <programlisting>
+ * -Clearlooks-glossy: true;
+ * </programlisting>
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (object_class,
+ PROP_NAME,
+ g_param_spec_string ("name",
+ P_("Name"),
+ P_("Theming engine name"),
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY | GTK_PARAM_READWRITE));
g_type_class_add_private (object_class, sizeof (GtkThemingEnginePrivate));
}
engine->priv = GTK_THEMING_ENGINE_GET_PRIVATE (engine);
}
+static void
+gtk_theming_engine_finalize (GObject *object)
+{
+ GtkThemingEnginePrivate *priv;
+
+ priv = GTK_THEMING_ENGINE (object)->priv;
+ g_free (priv->name);
+
+ G_OBJECT_GET_CLASS (gtk_theming_engine_parent_class)->finalize (object);
+}
+
+static void
+gtk_theming_engine_impl_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkThemingEnginePrivate *priv;
+
+ priv = GTK_THEMING_ENGINE (object)->priv;
+
+ switch (prop_id)
+ {
+ case PROP_NAME:
+ if (priv->name)
+ g_free (priv->name);
+
+ priv->name = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_theming_engine_impl_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkThemingEnginePrivate *priv;
+
+ priv = GTK_THEMING_ENGINE (object)->priv;
+
+ switch (prop_id)
+ {
+ case PROP_NAME:
+ g_value_set_string (value, priv->name);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
void
_gtk_theming_engine_set_context (GtkThemingEngine *engine,
GtkStyleContext *context)
}
/**
- * gtk_theming_engine_register_property:
- * @engine: a #GtkThemingEngine
- * @property_name: property name to register
- * @type: #GType the property will hold
- * @default_value: default value for this property
+ * gtk_theming_engine_register_property: (skip)
+ * @name_space: namespace for the property name
* @parse_func: parsing function to use, or %NULL
+ * @pspec: the #GParamSpec for the new property
*
* Registers a property so it can be used in the CSS file format,
* on the CSS file the property will look like
- * "-${engine-object-name}-${@property_name}". being
- * ${engine-object-name} the same than G_OBJECT_TYPE_NAME(engine)
- * would return.
+ * "-${@name_space}-${property_name}". being
+ * ${property_name} the given to @pspec. @name_space will usually
+ * be the theme engine name.
*
* For any type a @parse_func may be provided, being this function
* used for turning any property value (between ':' and ';') in
* cases.
*
* <note>
- * This function needs to be called only once during theming
- * engine object initialization.
+ * Engines must ensure property registration happens exactly once,
+ * usually GTK+ deals with theming engines as singletons, so this
+ * should be guaranteed to happen once, but bear this in mind
+ * when creating #GtkThemeEngine<!-- -->s yourself.
* </note>
*
* <note>
* In order to make use of the custom registered properties in
- * the CSS file, make sure the engine is loaded first either in
- * a previous rule or within the same one.
+ * the CSS file, make sure the engine is loaded first by specifying
+ * the engine property, either in a previous rule or within the same
+ * one.
* <programlisting>
* * {
* engine: someengine;
- * SomeEngine-custom-property: 2;
+ * -SomeEngine-custom-property: 2;
* }
* </programlisting>
* </note>
* Since: 3.0
**/
void
-gtk_theming_engine_register_property (GtkThemingEngine *engine,
- const gchar *property_name,
- GType type,
- const GValue *default_value,
- GtkStylePropertyParser parse_func)
+gtk_theming_engine_register_property (const gchar *name_space,
+ GtkStylePropertyParser parse_func,
+ GParamSpec *pspec)
{
gchar *name;
- g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
- g_return_if_fail (property_name != NULL);
- g_return_if_fail (type != G_TYPE_INVALID);
- g_return_if_fail (default_value != NULL && G_IS_VALUE (default_value));
+ g_return_if_fail (name_space != NULL);
+ g_return_if_fail (strchr (name_space, ' ') == NULL);
+ g_return_if_fail (G_IS_PARAM_SPEC (pspec));
- name = g_strdup_printf ("-%s-%s", G_OBJECT_TYPE_NAME (engine), property_name);
- gtk_style_set_register_property (name, type, default_value, parse_func);
- g_free (name);
+ /* FIXME: hack hack hack, replacing pspec->name to include namespace */
+ name = g_strdup_printf ("-%s-%s", name_space, pspec->name);
+ g_free (pspec->name);
+ pspec->name = name;
+
+ gtk_style_properties_register_property (parse_func, pspec);
}
/**
* gtk_theming_engine_get_style_property:
* @engine: a #GtkThemingEngine
* @property_name: the name of the widget style property
- * @value: (out) (transfer full): Return location for the property value, free with
+ * @value: Return location for the property value, free with
* g_value_unset() after use.
*
* Gets the value for a widget style property.
va_end (args);
}
+/**
+ * gtk_theming_engine_lookup_color:
+ * @engine: a #GtkThemingEngine
+ * @color_name: color name to lookup
+ * @color: (out): Return location for the looked up color
+ *
+ * Looks up and resolves a color name in the current style's color map.
+ *
+ * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
+ **/
+gboolean
+gtk_theming_engine_lookup_color (GtkThemingEngine *engine,
+ const gchar *color_name,
+ GdkRGBA *color)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
+ g_return_val_if_fail (color_name != NULL, FALSE);
+
+ priv = engine->priv;
+ return gtk_style_context_lookup_color (priv->context, color_name, color);
+}
+
/**
* gtk_theming_engine_get_state:
* @engine: a #GtkThemingEngine
return gtk_style_context_get_junction_sides (priv->context);
}
+/**
+ * gtk_theming_engine_get_color:
+ * @engine: a #GtkThemingEngine
+ * @state: state to retrieve the color for
+ * @color: (out): return value for the foreground color
+ *
+ * Gets the foreground color for a given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_color (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GdkRGBA *color)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+ priv = engine->priv;
+ gtk_style_context_get_color (priv->context, state, color);
+}
+
+/**
+ * gtk_theming_engine_get_background_color:
+ * @engine: a #GtkThemingEngine
+ * @state: state to retrieve the color for
+ * @color: (out): return value for the background color
+ *
+ * Gets the background color for a given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_background_color (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GdkRGBA *color)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+ priv = engine->priv;
+ gtk_style_context_get_background_color (priv->context, state, color);
+}
+
+/**
+ * gtk_theming_engine_get_border_color:
+ * @engine: a #GtkThemingEngine
+ * @state: state to retrieve the color for
+ * @color: (out): return value for the border color
+ *
+ * Gets the border color for a given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_border_color (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GdkRGBA *color)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+ priv = engine->priv;
+ gtk_style_context_get_border_color (priv->context, state, color);
+}
+
+/**
+ * gtk_theming_engine_get_border:
+ * @engine: a #GtkthemingEngine
+ * @state: state to retrieve the border for
+ * @border: (out): return value for the border settings
+ *
+ * Gets the border for a given state as a #GtkBorder.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_border (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GtkBorder *border)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+ priv = engine->priv;
+ gtk_style_context_get_border (priv->context, state, border);
+}
+
+/**
+ * gtk_theming_engine_get_padding:
+ * @engine: a #GtkthemingEngine
+ * @state: state to retrieve the padding for
+ * @padding: (out): return value for the padding settings
+ *
+ * Gets the padding for a given state as a #GtkBorder.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_padding (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GtkBorder *padding)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+ priv = engine->priv;
+ gtk_style_context_get_padding (priv->context, state, padding);
+}
+
+/**
+ * gtk_theming_engine_get_margin:
+ * @engine: a #GtkThemingEngine
+ * @state: state to retrieve the border for
+ * @margin: (out): return value for the margin settings
+ *
+ * Gets the margin for a given state as a #GtkBorder.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_margin (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GtkBorder *margin)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+ priv = engine->priv;
+ gtk_style_context_get_margin (priv->context, state, margin);
+}
+
+/**
+ * gtk_theming_engine_get_font:
+ * @engine: a #GtkThemingEngine
+ * @state: state to retrieve the font for
+ *
+ * Returns the font description for a given state.
+ *
+ * Returns: (transfer none): the #PangoFontDescription for the given
+ * state. This object is owned by GTK+ and should not be
+ * freed.
+ *
+ * Since: 3.0
+ **/
+const PangoFontDescription *
+gtk_theming_engine_get_font (GtkThemingEngine *engine,
+ GtkStateFlags state)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
+
+ priv = engine->priv;
+ return gtk_style_context_get_font (priv->context, state);
+}
+
/* GtkThemingModule */
static gboolean
module_path = _gtk_find_module (name, "theming-engines");
if (!module_path)
- {
- g_warning (_("Unable to locate theme engine in module path: \"%s\","), name);
- return FALSE;
- }
+ return FALSE;
module = g_module_open (module_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
g_free (module_path);
if (!module)
- {
- g_warning ("%s", g_module_error ());
- return FALSE;
- }
+ return FALSE;
if (!g_module_symbol (module, "theme_init",
(gpointer *) &theming_module->init) ||
!g_module_symbol (module, "create_engine",
(gpointer *) &theming_module->create_engine))
{
- g_warning ("%s", g_module_error ());
g_module_close (module);
return FALSE;
theming_module->module = module;
- theming_module->init (theming_module);
+ theming_module->init (G_TYPE_MODULE (theming_module));
return TRUE;
}
*
* Returns the #GdkScreen to which @engine currently rendering to.
*
- * Returns: a #GdkScreen, or %NULL.
+ * Returns: (transfer none): a #GdkScreen, or %NULL.
**/
GdkScreen *
gtk_theming_engine_get_screen (GtkThemingEngine *engine)
gdouble width,
gdouble height)
{
- GdkColor *fg_color, *base_color, *text_color;
- const GtkWidgetPath *path;
+ GdkRGBA *fg_color, *bg_color, *border_color;
GtkStateFlags flags;
gint exterior_size, interior_size, thickness, pad;
+ GtkBorderStyle border_style;
+ GtkBorder *border;
+ gint border_width;
flags = gtk_theming_engine_get_state (engine);
- path = gtk_theming_engine_get_path (engine);
cairo_save (cr);
gtk_theming_engine_get (engine, flags,
- "foreground-color", &fg_color,
- "base-color", &base_color,
- "text-color", &text_color,
+ "color", &fg_color,
+ "background-color", &bg_color,
+ "border-color", &border_color,
+ "border-style", &border_style,
+ "border-width", &border,
NULL);
+ border_width = MIN (MIN (border->top, border->bottom),
+ MIN (border->left, border->right));
exterior_size = MIN (width, height);
if (exterior_size % 2 == 0) /* Ensure odd */
x -= (1 + exterior_size - (gint) width) / 2;
y -= (1 + exterior_size - (gint) height) / 2;
- if (!gtk_theming_engine_has_class (engine, "menu"))
+ if (border_style == GTK_BORDER_STYLE_SOLID)
{
- cairo_set_line_width (cr, 1.0);
+ cairo_set_line_width (cr, border_width);
cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
- gdk_cairo_set_source_color (cr, base_color);
+ gdk_cairo_set_source_rgba (cr, bg_color);
cairo_fill_preserve (cr);
- if (gtk_theming_engine_has_class (engine, "cell"))
- gdk_cairo_set_source_color (cr, text_color);
+ if (border_color)
+ gdk_cairo_set_source_rgba (cr, border_color);
else
- gdk_cairo_set_source_color (cr, fg_color);
+ gdk_cairo_set_source_rgba (cr, fg_color);
cairo_stroke (cr);
}
- if (gtk_theming_engine_has_class (engine, "menu"))
- gdk_cairo_set_source_color (cr, fg_color);
- else
- gdk_cairo_set_source_color (cr, text_color);
+ gdk_cairo_set_source_rgba (cr, fg_color);
if (flags & GTK_STATE_FLAG_INCONSISTENT)
{
cairo_restore (cr);
- gdk_color_free (fg_color);
- gdk_color_free (base_color);
- gdk_color_free (text_color);
+ gdk_rgba_free (fg_color);
+ gdk_rgba_free (bg_color);
+ gdk_rgba_free (border_color);
+ gtk_border_free (border);
}
static void
gdouble height)
{
GtkStateFlags flags;
- GdkColor *base_color, *fg_color, *text_color;
- const GtkWidgetPath *path;
- gint exterior_size, interior_size, pad, thickness;
- gdouble radius;
+ GdkRGBA *fg_color, *bg_color, *border_color;
+ gint exterior_size, interior_size, pad, thickness, border_width;
+ GtkBorderStyle border_style;
+ GtkBorder *border;
flags = gtk_theming_engine_get_state (engine);
- path = gtk_theming_engine_get_path (engine);
- radius = MIN (width, height) / 2 - 0.5;
cairo_save (cr);
gtk_theming_engine_get (engine, flags,
- "foreground-color", &fg_color,
- "base-color", &base_color,
- "text-color", &text_color,
+ "color", &fg_color,
+ "background-color", &bg_color,
+ "border-color", &border_color,
+ "border-style", &border_style,
+ "border-width", &border,
NULL);
exterior_size = MIN (width, height);
+ border_width = MIN (MIN (border->top, border->bottom),
+ MIN (border->left, border->right));
if (exterior_size % 2 == 0) /* Ensure odd */
exterior_size -= 1;
x -= (1 + exterior_size - width) / 2;
y -= (1 + exterior_size - height) / 2;
- if (!gtk_theming_engine_has_class (engine, "menu"))
+ if (border_style == GTK_BORDER_STYLE_SOLID)
{
- gdk_cairo_set_source_color (cr, base_color);
+ cairo_set_line_width (cr, border_width);
+ cairo_new_sub_path (cr);
cairo_arc (cr,
- x + exterior_size / 2.,
- y + exterior_size / 2.,
- (exterior_size - 1) / 2.,
- 0, 2 * G_PI);
+ x + exterior_size / 2.,
+ y + exterior_size / 2.,
+ (exterior_size - 1) / 2.,
+ 0, 2 * G_PI);
+ gdk_cairo_set_source_rgba (cr, bg_color);
cairo_fill_preserve (cr);
- if (gtk_theming_engine_has_class (engine, "cell"))
- gdk_cairo_set_source_color (cr, text_color);
+ if (border_color)
+ gdk_cairo_set_source_rgba (cr, border_color);
else
- gdk_cairo_set_source_color (cr, fg_color);
+ gdk_cairo_set_source_rgba (cr, fg_color);
- cairo_set_line_width (cr, 1.);
cairo_stroke (cr);
}
- if (gtk_theming_engine_has_class (engine, "menu"))
- gdk_cairo_set_source_color (cr, fg_color);
- else
- gdk_cairo_set_source_color (cr, text_color);
+ gdk_cairo_set_source_rgba (cr, fg_color);
/* FIXME: thickness */
thickness = 1;
line_thickness = MAX (1, (3 + interior_size * 2) / 7);
cairo_rectangle (cr,
- x + pad,
- y + pad + (interior_size - line_thickness) / 2.,
- interior_size,
- line_thickness);
+ x + pad,
+ y + pad + (interior_size - line_thickness) / 2.,
+ interior_size,
+ line_thickness);
cairo_fill (cr);
}
if (flags & GTK_STATE_FLAG_ACTIVE)
interior_size = MAX (1, exterior_size - 2 * pad);
if (interior_size < 5)
- {
- interior_size = 7;
- pad = MAX (0, (exterior_size - interior_size) / 2);
- }
+ {
+ interior_size = 7;
+ pad = MAX (0, (exterior_size - interior_size) / 2);
+ }
+ cairo_new_sub_path (cr);
cairo_arc (cr,
- x + pad + interior_size / 2.,
- y + pad + interior_size / 2.,
- interior_size / 2.,
- 0, 2 * G_PI);
+ x + pad + interior_size / 2.,
+ y + pad + interior_size / 2.,
+ interior_size / 2.,
+ 0, 2 * G_PI);
cairo_fill (cr);
}
cairo_restore (cr);
- gdk_color_free (fg_color);
- gdk_color_free (base_color);
- gdk_color_free (text_color);
+ gdk_rgba_free (fg_color);
+ gdk_rgba_free (bg_color);
+ gdk_rgba_free (border_color);
+ gtk_border_free (border);
}
static void
gdouble size)
{
GtkStateFlags flags;
- GdkColor *fg_color;
+ GdkRGBA *fg_color;
cairo_save (cr);
flags = gtk_theming_engine_get_state (engine);
gtk_theming_engine_get (engine, flags,
- "foreground-color", &fg_color,
+ "color", &fg_color,
NULL);
if (flags & GTK_STATE_FLAG_INSENSITIVE)
}
add_path_arrow (cr, angle, x, y, size);
- gdk_cairo_set_source_color (cr, fg_color);
+ gdk_cairo_set_source_rgba (cr, fg_color);
cairo_fill (cr);
cairo_restore (cr);
- gdk_color_free (fg_color);
+ gdk_rgba_free (fg_color);
}
static void
}
static void
-add_path_rectangle_sides (cairo_t *cr,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height,
- guint sides)
+color_shade (const GdkRGBA *color,
+ gdouble factor,
+ GdkRGBA *color_return)
{
- if (sides & SIDE_TOP)
- {
- cairo_move_to (cr, x, y + 0.5);
- cairo_line_to (cr, x + width, y + 0.5);
- }
-
- if (sides & SIDE_RIGHT)
- {
- cairo_move_to (cr, x + width - 0.5, y);
- cairo_line_to (cr, x + width - 0.5, y + height);
- }
-
- if (sides & SIDE_BOTTOM)
- {
- cairo_move_to (cr, x, y + height - 0.5);
- cairo_line_to (cr, x + width, y + height - 0.5);
- }
-
- if (sides & SIDE_LEFT)
- {
- cairo_move_to (cr, x + 0.5, y + height);
- cairo_line_to (cr, x + 0.5, y);
- }
-}
+ GtkSymbolicColor *literal, *shade;
-static void
-add_path_gap_side (cairo_t *cr,
- GtkPositionType gap_side,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height,
- gdouble xy0_gap,
- gdouble xy1_gap)
-{
- switch (gap_side)
- {
- case GTK_POS_TOP:
- add_path_line (cr, x, y, x + xy0_gap, y);
- add_path_line (cr, x + xy1_gap, y, x + width, y);
- break;
- case GTK_POS_BOTTOM:
- add_path_line (cr, x, y + height, x + xy0_gap, y + height);
- add_path_line (cr, x + xy1_gap, y + height, x + width, y + height);
- break;
- case GTK_POS_LEFT:
- add_path_line (cr, x, y, x, y + xy0_gap);
- add_path_line (cr, x, y + xy1_gap, x, y + height);
- break;
- case GTK_POS_RIGHT:
- add_path_line (cr, x + width, y, x + width, y + xy0_gap);
- add_path_line (cr, x + width, y + xy1_gap, x + width, y + height);
- break;
- }
-}
+ literal = gtk_symbolic_color_new_literal (color);
+ shade = gtk_symbolic_color_new_shade (literal, factor);
+ gtk_symbolic_color_unref (literal);
-static void
-color_shade (const GdkColor *color,
- gdouble factor,
- GdkColor *color_return)
-{
- color_return->red = CLAMP (color->red * factor, 0, 65535);
- color_return->green = CLAMP (color->green * factor, 0, 65535);
- color_return->blue = CLAMP (color->blue * factor, 0, 65535);
+ gtk_symbolic_color_resolve (shade, NULL, color_return);
+ gtk_symbolic_color_unref (shade);
}
static void
if (sides & SIDE_RIGHT)
{
if (radius == 0 ||
- (junction & GTK_JUNCTION_TOP) ||
- (junction & GTK_JUNCTION_RIGHT))
+ (junction & GTK_JUNCTION_CORNER_TOPRIGHT))
cairo_move_to (cr, x + width, y);
else
{
}
if (radius == 0 ||
- (junction & GTK_JUNCTION_BOTTOM) ||
- (junction & GTK_JUNCTION_RIGHT))
+ (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT))
cairo_line_to (cr, x + width, y + height);
else
cairo_arc (cr, x + width - radius, y + height - radius, radius, 0, G_PI / 4);
if (sides & SIDE_BOTTOM)
{
if (radius != 0 &&
- ! (junction & GTK_JUNCTION_RIGHT) &&
- ! (junction & GTK_JUNCTION_BOTTOM))
+ ! (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT))
{
if ((sides & SIDE_RIGHT) == 0)
cairo_new_sub_path (cr);
cairo_arc (cr, x + width - radius, y + height - radius, radius, G_PI / 4, G_PI / 2);
}
+ else if ((sides & SIDE_RIGHT) == 0)
+ cairo_move_to (cr, x + width, y + height);
if (radius == 0 ||
- (junction & GTK_JUNCTION_BOTTOM) ||
- (junction & GTK_JUNCTION_LEFT))
+ (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT))
cairo_line_to (cr, x, y + height);
else
cairo_arc (cr, x + radius, y + height - radius, radius, G_PI / 2, 3 * (G_PI / 4));
if (sides & SIDE_LEFT)
{
if (radius != 0 &&
- ! (junction & GTK_JUNCTION_LEFT) &&
- ! (junction & GTK_JUNCTION_BOTTOM))
+ ! (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT))
{
if ((sides & SIDE_BOTTOM) == 0)
cairo_new_sub_path (cr);
cairo_arc (cr, x + radius, y + height - radius, radius, 3 * (G_PI / 4), G_PI);
}
+ else if ((sides & SIDE_BOTTOM) == 0)
+ cairo_move_to (cr, x, y + height);
if (radius == 0 ||
- (junction & GTK_JUNCTION_TOP) ||
- (junction & GTK_JUNCTION_LEFT))
+ (junction & GTK_JUNCTION_CORNER_TOPLEFT))
cairo_line_to (cr, x, y);
else
cairo_arc (cr, x + radius, y + radius, radius, G_PI, G_PI + G_PI / 4);
if (sides & SIDE_TOP)
{
if (radius != 0 &&
- ! (junction & GTK_JUNCTION_TOP) &&
- ! (junction & GTK_JUNCTION_LEFT))
+ ! (junction & GTK_JUNCTION_CORNER_TOPLEFT))
{
- if ((sides & SIDE_TOP) == 0)
+ if ((sides & SIDE_LEFT) == 0)
cairo_new_sub_path (cr);
cairo_arc (cr, x + radius, y + radius, radius, 5 * (G_PI / 4), 3 * (G_PI / 2));
}
+ else if ((sides & SIDE_LEFT) == 0)
+ cairo_move_to (cr, x, y);
if (radius == 0 ||
- (junction & GTK_JUNCTION_TOP) ||
- (junction & GTK_JUNCTION_RIGHT))
+ (junction & GTK_JUNCTION_CORNER_TOPRIGHT))
cairo_line_to (cr, x + width, y);
else
cairo_arc (cr, x + width - radius, y + radius, radius, 3 * (G_PI / 2), - G_PI / 4);
}
}
+/* Set the appropriate matrix for
+ * patterns coming from the style context
+ */
static void
-gtk_theming_engine_render_background (GtkThemingEngine *engine,
- cairo_t *cr,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height)
+style_pattern_set_matrix (cairo_pattern_t *pattern,
+ gdouble width,
+ gdouble height)
+{
+ cairo_matrix_t matrix;
+ gint w, h;
+
+ if (cairo_pattern_get_type (pattern) == CAIRO_PATTERN_TYPE_SURFACE)
+ {
+ cairo_surface_t *surface;
+
+ cairo_pattern_get_surface (pattern, &surface);
+ w = cairo_image_surface_get_width (surface);
+ h = cairo_image_surface_get_height (surface);
+ }
+ else
+ w = h = 1;
+
+ cairo_matrix_init_scale (&matrix, (gdouble) w / width, (gdouble) h / height);
+ cairo_pattern_set_matrix (pattern, &matrix);
+}
+
+static void
+render_background_internal (GtkThemingEngine *engine,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height,
+ GtkJunctionSides junction)
{
- GdkColor *bg_color, *base_color;
+ GdkRGBA *bg_color;
cairo_pattern_t *pattern;
GtkStateFlags flags;
gboolean running;
gdouble progress, alpha = 1;
- GtkJunctionSides junction;
- gint radius;
+ GtkBorder *border;
+ gint radius, border_width;
+ GtkBorderStyle border_style;
+ gdouble mat_w, mat_h;
+ cairo_matrix_t identity;
+
+ /* Use unmodified size for pattern scaling */
+ mat_w = width;
+ mat_h = height;
flags = gtk_theming_engine_get_state (engine);
- junction = gtk_theming_engine_get_junction_sides (engine);
- cairo_save (cr);
- if (gtk_theming_engine_has_class (engine, "spinbutton") &&
- gtk_theming_engine_has_class (engine, "button"))
- {
- x += 2;
- y += 2;
- width -= 4;
- height -= 4;
- }
+ cairo_matrix_init_identity (&identity);
gtk_theming_engine_get (engine, flags,
"background-image", &pattern,
"background-color", &bg_color,
- "base-color", &base_color,
"border-radius", &radius,
+ "border-width", &border,
+ "border-style", &border_style,
NULL);
- running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
+ border_width = MIN (MIN (border->top, border->bottom),
+ MIN (border->left, border->right));
- _cairo_round_rectangle_sides (cr, (gdouble) radius,
- x, y, width, height,
- SIDE_ALL, junction);
- cairo_clip (cr);
+ if (border_width > 1 &&
+ border_style == GTK_BORDER_STYLE_NONE)
+ {
+ cairo_set_line_width (cr, border_width);
+
+ x += (gdouble) border_width / 2;
+ y += (gdouble) border_width / 2;
+ width -= border_width;
+ height -= border_width;
+ }
+ else
+ {
+ x += border->left;
+ y += border->top;
+ width -= border->left + border->right;
+ height -= border->top + border->bottom;
+ }
+
+ if (width <= 0 || height <= 0)
+ return;
+ cairo_save (cr);
cairo_translate (cr, x, y);
- cairo_scale (cr, width, height);
+
+ running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
+
+ if (gtk_theming_engine_has_class (engine, "background"))
+ {
+ cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); /* transparent */
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_paint (cr);
+ }
if (running)
{
cairo_pattern_t *other_pattern;
GtkStateFlags other_flags;
- GdkColor *other_bg, *other_base;
+ GdkRGBA *other_bg;
cairo_pattern_t *new_pattern = NULL;
if (flags & GTK_STATE_FLAG_PRELIGHT)
gtk_theming_engine_get (engine, other_flags,
"background-image", &other_pattern,
"background-color", &other_bg,
- "base-color", &other_base,
NULL);
if (pattern && other_pattern)
/* Different pattern types, or different color
* stop counts, alpha blend both patterns.
*/
- cairo_rectangle (cr, 0, 0, 1, 1);
+ _cairo_round_rectangle_sides (cr, (gdouble) radius,
+ 0, 0, width, height,
+ SIDE_ALL, junction);
+
+ style_pattern_set_matrix (other_pattern, mat_w, mat_h);
cairo_set_source (cr, other_pattern);
cairo_fill_preserve (cr);
+ cairo_pattern_set_matrix (other_pattern, &identity);
+
/* Set alpha for posterior drawing
* of the target pattern
*/
else if (pattern || other_pattern)
{
cairo_pattern_t *p;
- GdkColor *c;
+ const GdkRGBA *c;
gdouble x0, y0, x1, y1, r0, r1;
- gdouble red0, green0, blue0;
- gdouble red1, green1, blue1;
gint n, i;
/* Blend a pattern with a color */
if (pattern)
{
p = pattern;
- c = gtk_theming_engine_has_class (engine, "entry") ? other_base : other_bg;
+ c = other_bg;
progress = 1 - progress;
}
else
{
p = other_pattern;
- c = gtk_theming_engine_has_class (engine, "entry") ? base_color : bg_color;
+ c = bg_color;
}
if (cairo_pattern_get_type (p) == CAIRO_PATTERN_TYPE_LINEAR)
cairo_pattern_get_color_stop_count (p, &n);
- red0 = c->red / 65535.;
- green0 = c->green / 65535.;
- blue0 = c->blue / 65535.;
-
for (i = 0; i < n; i++)
{
- gdouble offset, alpha;
+ gdouble red1, green1, blue1, alpha1;
+ gdouble offset;
cairo_pattern_get_color_stop_rgba (p, i,
&offset,
&red1, &green1, &blue1,
- &alpha);
+ &alpha1);
cairo_pattern_add_color_stop_rgba (new_pattern, offset,
- red0 + ((red1 - red0) * progress),
- green0 + ((green1 - green0) * progress),
- blue0 + ((blue1 - blue0) * progress),
- alpha + ((1 - alpha) * progress));
+ c->red + ((red1 - c->red) * progress),
+ c->green + ((green1 - c->green) * progress),
+ c->blue + ((blue1 - c->blue) * progress),
+ c->alpha + ((alpha1 - c->alpha) * progress));
}
}
else
{
- const GdkColor *color, *other_color;
+ const GdkRGBA *color, *other_color;
/* Merge just colors */
- if (gtk_theming_engine_has_class (engine, "entry"))
- {
- color = base_color;
- other_color = other_base;
- }
- else
- {
- color = bg_color;
- other_color = other_bg;
- }
+ color = bg_color;
+ other_color = other_bg;
- new_pattern = cairo_pattern_create_rgb ((gdouble) (color->red + ((other_color->red - color->red) * progress)) / 65535.,
- (gdouble) (color->green + ((other_color->green - color->green) * progress)) / 65535.,
- (gdouble) (color->blue + ((other_color->blue - color->blue) * progress)) / 65535.);
+ new_pattern = cairo_pattern_create_rgba (CLAMP (color->red + ((other_color->red - color->red) * progress), 0, 1),
+ CLAMP (color->green + ((other_color->green - color->green) * progress), 0, 1),
+ CLAMP (color->blue + ((other_color->blue - color->blue) * progress), 0, 1),
+ CLAMP (color->alpha + ((other_color->alpha - color->alpha) * progress), 0, 1));
}
if (new_pattern)
cairo_pattern_destroy (other_pattern);
if (other_bg)
- gdk_color_free (other_bg);
-
- if (other_base)
- gdk_color_free (other_base);
+ gdk_rgba_free (other_bg);
}
- cairo_rectangle (cr, 0, 0, 1, 1);
-
+ _cairo_round_rectangle_sides (cr, (gdouble) radius,
+ 0, 0, width, height,
+ SIDE_ALL, junction);
if (pattern)
{
+ style_pattern_set_matrix (pattern, mat_w, mat_h);
cairo_set_source (cr, pattern);
- cairo_pattern_destroy (pattern);
}
else
+ gdk_cairo_set_source_rgba (cr, bg_color);
+
+ if (alpha == 1)
{
- if (gtk_theming_engine_has_class (engine, "entry"))
- gdk_cairo_set_source_color (cr, base_color);
+ if (border_width > 1 &&
+ border_style != GTK_BORDER_STYLE_NONE)
+ {
+ /* stroke with the same source, so the background
+ * has exactly the shape than the frame, this
+ * is important so gtk_render_background() and
+ * gtk_render_frame() fit perfectly with round
+ * borders.
+ */
+ cairo_fill_preserve (cr);
+ cairo_stroke (cr);
+ }
else
- gdk_cairo_set_source_color (cr, bg_color);
+ cairo_fill (cr);
}
-
- if (gtk_theming_engine_has_class (engine, "tooltip"))
+ else
{
- cairo_fill_preserve (cr);
+ cairo_save (cr);
+ _cairo_round_rectangle_sides (cr, (gdouble) radius,
+ 0, 0, width, height,
+ SIDE_ALL, junction);
+ cairo_clip (cr);
- cairo_set_source_rgb (cr, 0, 0, 0);
- cairo_stroke (cr);
+ cairo_paint_with_alpha (cr, alpha);
+
+ cairo_restore (cr);
}
- else
- {
- if (alpha == 1)
- cairo_fill (cr);
- else
- {
- cairo_pattern_t *mask;
- mask = cairo_pattern_create_rgba (1, 1, 1, alpha);
- cairo_mask (cr, mask);
- cairo_pattern_destroy (mask);
- }
+ if (pattern)
+ {
+ cairo_pattern_set_matrix (pattern, &identity);
+ cairo_pattern_destroy (pattern);
}
cairo_restore (cr);
- gdk_color_free (base_color);
- gdk_color_free (bg_color);
+ gdk_rgba_free (bg_color);
+ gtk_border_free (border);
}
static void
-gtk_theming_engine_render_frame (GtkThemingEngine *engine,
- cairo_t *cr,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height)
+gtk_theming_engine_render_background (GtkThemingEngine *engine,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height)
{
- GtkStateFlags flags;
- GdkColor lighter, darker;
- GdkColor *border_color;
- Gtk9Slice *slice;
- GtkBorderStyle border_style;
- gint border_width, radius;
GtkJunctionSides junction;
- flags = gtk_theming_engine_get_state (engine);
junction = gtk_theming_engine_get_junction_sides (engine);
- gtk_theming_engine_get (engine, flags,
- "border-image", &slice,
+ render_background_internal (engine, cr,
+ x, y, width, height,
+ junction);
+}
+
+/* Renders the small triangle on corners so
+ * frames with 0 radius have a 3D-like effect
+ */
+static void
+_cairo_corner_triangle (cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gint size)
+{
+ gint i;
+
+ cairo_move_to (cr, x + 0.5, y + size - 0.5);
+ cairo_line_to (cr, x + size - 0.5, y + size - 0.5);
+ cairo_line_to (cr, x + size - 0.5, y + 0.5);
+
+ for (i = 1; i < size - 1; i++)
+ {
+ cairo_move_to (cr, x + size - 0.5, y + i + 0.5);
+ cairo_line_to (cr, x + (size - i) - 0.5, y + i + 0.5);
+ }
+}
+
+static void
+render_frame_internal (GtkThemingEngine *engine,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height,
+ guint hidden_side,
+ GtkJunctionSides junction)
+{
+ GtkStateFlags state;
+ GdkRGBA lighter;
+ GdkRGBA *border_color;
+ GtkBorderStyle border_style;
+ gint border_width, radius;
+ gdouble progress, d1, d2, m;
+ gboolean running;
+ GtkBorder *border;
+
+ state = gtk_theming_engine_get_state (engine);
+ gtk_theming_engine_get (engine, state,
"border-color", &border_color,
"border-style", &border_style,
- "border-width", &border_width,
+ "border-width", &border,
"border-radius", &radius,
NULL);
- if (slice)
+ running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
+ border_width = MIN (MIN (border->top, border->bottom),
+ MIN (border->left, border->right));
+
+ if (running)
{
- gtk_9slice_render (slice, cr, x, y, width, height);
- gtk_9slice_unref (slice);
+ GtkStateFlags other_state;
+ GdkRGBA *other_color;
+
+ if (state & GTK_STATE_FLAG_PRELIGHT)
+ {
+ other_state = state & ~(GTK_STATE_FLAG_PRELIGHT);
+ progress = 1 - progress;
+ }
+ else
+ other_state = state | GTK_STATE_FLAG_PRELIGHT;
+
+ gtk_theming_engine_get (engine, other_state,
+ "border-color", &other_color,
+ NULL);
+
+ border_color->red = CLAMP (border_color->red + ((other_color->red - border_color->red) * progress), 0, 1);
+ border_color->green = CLAMP (border_color->green + ((other_color->green - border_color->green) * progress), 0, 1);
+ border_color->blue = CLAMP (border_color->blue + ((other_color->blue - border_color->blue) * progress), 0, 1);
+ border_color->alpha = CLAMP (border_color->alpha + ((other_color->alpha - border_color->alpha) * progress), 0, 1);
+
+ gdk_rgba_free (other_color);
}
- else if (border_style != GTK_BORDER_STYLE_NONE)
+
+ cairo_save (cr);
+
+ color_shade (border_color, 1.8, &lighter);
+
+ switch (border_style)
{
- cairo_save (cr);
+ case GTK_BORDER_STYLE_NONE:
+ break;
+ case GTK_BORDER_STYLE_SOLID:
+ cairo_set_line_width (cr, border_width);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+
+ if (border_width > 1)
+ {
+ x += (gdouble) border_width / 2;
+ y += (gdouble) border_width / 2;
+ width -= border_width;
+ height -= border_width;
+ }
+ else if (border_width == 1)
+ {
+ x += 0.5;
+ y += 0.5;
+ width -= 1;
+ height -= 1;
+ }
+
+ _cairo_round_rectangle_sides (cr, (gdouble) radius,
+ x, y, width, height,
+ SIDE_ALL & ~(hidden_side),
+ junction);
+ gdk_cairo_set_source_rgba (cr, border_color);
+ cairo_stroke (cr);
+
+ break;
+ case GTK_BORDER_STYLE_INSET:
+ case GTK_BORDER_STYLE_OUTSET:
+ cairo_set_line_width (cr, border_width);
- color_shade (border_color, 0.7, &darker);
- color_shade (border_color, 1.3, &lighter);
+ if (radius == 0)
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+ else
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
- switch (border_style)
+ if (border_width > 1)
{
- case GTK_BORDER_STYLE_NONE:
- break;
- case GTK_BORDER_STYLE_SOLID:
- cairo_set_line_width (cr, border_width);
+ d1 = (gdouble) border_width / 2;
+ d2 = border_width;
+ }
+ else
+ {
+ d1 = 0.5;
+ d2 = 1;
+ }
- if (border_width > 1)
- {
- x += (gdouble) border_width / 2;
- y += (gdouble) border_width / 2;
- width -= border_width;
- height -= border_width;
- }
+ cairo_save (cr);
- _cairo_round_rectangle_sides (cr, (gdouble) radius, x, y, width, height,
- SIDE_ALL, junction);
- gdk_cairo_set_source_color (cr, border_color);
- cairo_stroke (cr);
+ m = MIN (width, height);
+ m /= 2;
- break;
- case GTK_BORDER_STYLE_INSET:
- case GTK_BORDER_STYLE_OUTSET:
- cairo_set_line_width (cr, border_width);
- cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+ if (border_style == GTK_BORDER_STYLE_INSET)
+ gdk_cairo_set_source_rgba (cr, &lighter);
+ else
+ gdk_cairo_set_source_rgba (cr, border_color);
- if (border_width > 1)
- {
- gint d;
+ _cairo_round_rectangle_sides (cr, (gdouble) radius,
+ x + d1, y + d1,
+ width - d2, height - d2,
+ (SIDE_BOTTOM | SIDE_RIGHT) & ~(hidden_side),
+ junction);
+ cairo_stroke (cr);
- d = border_width / 2;
- x += d;
- y += d;
- width -= d * 2;
- height -= d * 2;
- }
+ if (border_style == GTK_BORDER_STYLE_INSET)
+ gdk_cairo_set_source_rgba (cr, border_color);
+ else
+ gdk_cairo_set_source_rgba (cr, &lighter);
- if (border_style == GTK_BORDER_STYLE_INSET)
- gdk_cairo_set_source_color (cr, border_color);
- else
- gdk_cairo_set_source_color (cr, &darker);
+ _cairo_round_rectangle_sides (cr, (gdouble) radius,
+ x + d1, y + d1,
+ width - d2, height - d2,
+ (SIDE_TOP | SIDE_LEFT) & ~(hidden_side),
+ junction);
+ cairo_stroke (cr);
- _cairo_round_rectangle_sides (cr, (gdouble) radius, x, y, width, height,
- SIDE_BOTTOM | SIDE_RIGHT, junction);
- cairo_stroke (cr);
+ if (border_width > 1)
+ {
+ /* overprint top/right and bottom/left corner
+ * triangles if there are square corners there,
+ * to give the box a 3D-like appearance.
+ */
+ cairo_save (cr);
if (border_style == GTK_BORDER_STYLE_INSET)
- gdk_cairo_set_source_color (cr, &darker);
+ gdk_cairo_set_source_rgba (cr, &lighter);
else
- gdk_cairo_set_source_color (cr, border_color);
+ gdk_cairo_set_source_rgba (cr, border_color);
- _cairo_round_rectangle_sides (cr, (gdouble) radius, x, y, width, height,
- SIDE_TOP | SIDE_LEFT, junction);
- cairo_stroke (cr);
+ cairo_set_line_width (cr, 1);
- break;
+ if (radius == 0 ||
+ (junction & GTK_JUNCTION_CORNER_TOPRIGHT) != 0)
+ _cairo_corner_triangle (cr,
+ x + width - border_width, y,
+ border_width);
+
+ if (radius == 0 ||
+ (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) != 0)
+ _cairo_corner_triangle (cr,
+ x, y + height - border_width,
+ border_width);
+ cairo_stroke (cr);
+ cairo_restore (cr);
}
cairo_restore (cr);
+ break;
}
+ cairo_restore (cr);
+
if (border_color)
- gdk_color_free (border_color);
+ gdk_rgba_free (border_color);
+
+ gtk_border_free (border);
+}
+
+static void
+gtk_theming_engine_render_frame (GtkThemingEngine *engine,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height)
+{
+ GtkStateFlags flags;
+ Gtk9Slice *slice;
+ GtkBorderStyle border_style;
+ GtkJunctionSides junction;
+
+ flags = gtk_theming_engine_get_state (engine);
+ junction = gtk_theming_engine_get_junction_sides (engine);
+
+ gtk_theming_engine_get (engine, flags,
+ "border-image", &slice,
+ "border-style", &border_style,
+ NULL);
+
+ if (slice)
+ {
+ _gtk_9slice_render (slice, cr, x, y, width, height);
+ _gtk_9slice_unref (slice);
+ }
+ else if (border_style != GTK_BORDER_STYLE_NONE)
+ render_frame_internal (engine, cr,
+ x, y, width, height,
+ 0, junction);
}
static void
gdouble height)
{
GtkStateFlags flags;
- GdkColor *bg_color, *fg_color, *base_color;
+ GdkRGBA *outline_color, *fg_color;
double vertical_overshoot;
int diameter;
double radius;
double x_double, y_double;
gdouble angle;
gint line_width;
+ gboolean running, is_rtl;
+ gdouble progress;
cairo_save (cr);
flags = gtk_theming_engine_get_state (engine);
gtk_theming_engine_get (engine, flags,
- "foreground-color", &fg_color,
- "background-color", &bg_color,
- "base-color", &base_color,
+ "color", &fg_color,
+ NULL);
+ gtk_theming_engine_get (engine, flags,
+ "border-color", &outline_color,
NULL);
+ running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
+ is_rtl = (gtk_theming_engine_get_direction (engine) == GTK_TEXT_DIR_RTL);
line_width = 1;
- /* FIXME: LTR/RTL */
- if (flags & GTK_STATE_FLAG_ACTIVE)
+ if (!running)
+ progress = (flags & GTK_STATE_FLAG_ACTIVE) ? 1 : 0;
+
+ if (!gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_HORIZONTAL))
{
- angle = G_PI / 2;
- interp = 1.0;
+ if (is_rtl)
+ angle = (G_PI) - ((G_PI / 2) * progress);
+ else
+ angle = (G_PI / 2) * progress;
}
else
{
- angle = 0;
- interp = 0;
+ if (is_rtl)
+ angle = (G_PI / 2) + ((G_PI / 2) * progress);
+ else
+ angle = (G_PI / 2) - ((G_PI / 2) * progress);
}
+ interp = progress;
+
/* Compute distance that the stroke extends beyonds the end
* of the triangle we draw.
*/
cairo_set_line_width (cr, line_width);
- if (flags & GTK_STATE_FLAG_PRELIGHT)
- gdk_cairo_set_source_color (cr, fg_color);
- else
- gdk_cairo_set_source_color (cr, base_color);
+ gdk_cairo_set_source_rgba (cr, fg_color);
cairo_fill_preserve (cr);
- gdk_cairo_set_source_color (cr, fg_color);
+ gdk_cairo_set_source_rgba (cr, outline_color);
cairo_stroke (cr);
cairo_restore (cr);
- gdk_color_free (base_color);
- gdk_color_free (fg_color);
- gdk_color_free (bg_color);
+ gdk_rgba_free (fg_color);
+ gdk_rgba_free (outline_color);
}
static void
gdouble height)
{
GtkStateFlags flags;
- GdkColor *color;
+ GdkRGBA *color;
gint line_width;
gint8 *dash_list;
flags = gtk_theming_engine_get_state (engine);
gtk_theming_engine_get (engine, flags,
- "foreground-color", &color,
+ "color", &color,
NULL);
gtk_theming_engine_get_style (engine,
width - line_width,
height - line_width);
- gdk_cairo_set_source_color (cr, color);
+ gdk_cairo_set_source_rgba (cr, color);
cairo_stroke (cr);
cairo_restore (cr);
- gdk_color_free (color);
+ gdk_rgba_free (color);
g_free (dash_list);
}
gdouble x1,
gdouble y1)
{
- GdkColor *bg_color, darker, lighter;
+ GdkRGBA *bg_color, darker, lighter;
GtkStateFlags flags;
gint i, thickness, thickness_dark, thickness_light, len;
cairo_matrix_t matrix;
for (i = 0; i < thickness_dark; i++)
{
- gdk_cairo_set_source_color (cr, &lighter);
+ gdk_cairo_set_source_rgba (cr, &lighter);
add_path_line (cr, len - i - 1.5, y0, len - 0.5, y0);
cairo_stroke (cr);
- gdk_cairo_set_source_color (cr, &darker);
+ gdk_cairo_set_source_rgba (cr, &darker);
add_path_line (cr, 0.5, y0, len - i - 1.5, y0);
cairo_stroke (cr);
for (i = 0; i < thickness_light; i++)
{
- gdk_cairo_set_source_color (cr, &darker);
+ gdk_cairo_set_source_rgba (cr, &darker);
add_path_line (cr, 0.5, y0, thickness_light - i + 0.5, y0);
cairo_stroke (cr);
- gdk_cairo_set_source_color (cr, &lighter);
+ gdk_cairo_set_source_rgba (cr, &lighter);
add_path_line (cr, thickness_light - i + 0.5, y0, len - 0.5, y0);
cairo_stroke (cr);
cairo_restore (cr);
- gdk_color_free (bg_color);
+ gdk_rgba_free (bg_color);
}
static void
PangoLayout *layout)
{
const PangoMatrix *matrix;
- GdkColor *fg_color;
+ GdkRGBA *fg_color;
GtkStateFlags flags;
- GdkScreen *screen;
+ gdouble progress;
+ gboolean running;
cairo_save (cr);
flags = gtk_theming_engine_get_state (engine);
gtk_theming_engine_get (engine, flags,
- "foreground-color", &fg_color,
+ "color", &fg_color,
NULL);
- screen = gtk_theming_engine_get_screen (engine);
matrix = pango_context_get_matrix (pango_layout_get_context (layout));
+ running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
+
+ if (running)
+ {
+ GtkStateFlags other_flags;
+ GdkRGBA *other_fg;
+
+ if (flags & GTK_STATE_FLAG_PRELIGHT)
+ {
+ other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
+ progress = 1 - progress;
+ }
+ else
+ other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
+
+ gtk_theming_engine_get (engine, other_flags,
+ "color", &other_fg,
+ NULL);
+
+ if (fg_color && other_fg)
+ {
+ fg_color->red = CLAMP (fg_color->red + ((other_fg->red - fg_color->red) * progress), 0, 1);
+ fg_color->green = CLAMP (fg_color->green + ((other_fg->green - fg_color->green) * progress), 0, 1);
+ fg_color->blue = CLAMP (fg_color->blue + ((other_fg->blue - fg_color->blue) * progress), 0, 1);
+ fg_color->alpha = CLAMP (fg_color->alpha + ((other_fg->alpha - fg_color->alpha) * progress), 0, 1);
+ }
+
+ if (other_fg)
+ gdk_rgba_free (other_fg);
+ }
+
if (matrix)
{
cairo_matrix_t cairo_matrix;
- PangoMatrix tmp_matrix;
PangoRectangle rect;
cairo_matrix_init (&cairo_matrix,
pango_matrix_transform_rectangle (matrix, &rect);
pango_extents_to_pixels (&rect, NULL);
- tmp_matrix = *matrix;
cairo_matrix.x0 += x - rect.x;
cairo_matrix.y0 += y - rect.y;
cairo_set_matrix (cr, &cairo_matrix);
}
else
- cairo_translate (cr, x, y);
+ cairo_move_to (cr, x, y);
if (flags & GTK_STATE_FLAG_INSENSITIVE)
{
cairo_save (cr);
cairo_set_source_rgb (cr, 1, 1, 1);
- cairo_move_to (cr, 1, 1);
+ cairo_move_to (cr, x + 1, y + 1);
_gtk_pango_fill_layout (cr, layout);
cairo_restore (cr);
}
- gdk_cairo_set_source_color (cr, fg_color);
+ gdk_cairo_set_source_rgba (cr, fg_color);
pango_cairo_show_layout (cr, layout);
cairo_restore (cr);
- gdk_color_free (fg_color);
+ gdk_rgba_free (fg_color);
}
static void
gdouble xy0_gap,
gdouble xy1_gap)
{
- GtkStateFlags flags;
- GdkColor *bg_color;
- GdkColor lighter, darker;
- guint sides;
-
- cairo_save (cr);
- flags = gtk_theming_engine_get_state (engine);
-
- cairo_set_line_width (cr, 1);
+ GtkJunctionSides junction;
+ GtkStateFlags state;
+ gint border_width, radius;
+ gdouble x0, y0, x1, y1, xc, yc, wc, hc;
+ GtkBorder *border;
- gtk_theming_engine_get (engine, flags,
- "background-color", &bg_color,
+ xc = yc = wc = hc = 0;
+ state = gtk_theming_engine_get_state (engine);
+ junction = gtk_theming_engine_get_junction_sides (engine);
+ gtk_theming_engine_get (engine, state,
+ "border-width", &border,
+ "border-radius", &radius,
NULL);
- color_shade (bg_color, 0.7, &darker);
- color_shade (bg_color, 1.3, &lighter);
- if (gtk_theming_engine_has_class (engine, "frame"))
- {
- if (gap_side == GTK_POS_RIGHT)
- sides = SIDE_BOTTOM;
- else if (gap_side == GTK_POS_BOTTOM)
- sides = SIDE_RIGHT;
- else
- sides = SIDE_BOTTOM | SIDE_RIGHT;
-
- gdk_cairo_set_source_color (cr, &lighter);
- add_path_rectangle_sides (cr, x , y, width , height, sides);
- cairo_stroke (cr);
+ border_width = MIN (MIN (border->top, border->bottom),
+ MIN (border->left, border->right));
- gdk_cairo_set_source_color (cr, &darker);
- add_path_rectangle_sides (cr, x, y, width - 1, height - 1, sides);
- cairo_stroke (cr);
+ cairo_save (cr);
- if (gap_side == GTK_POS_RIGHT ||
- gap_side == GTK_POS_BOTTOM)
- {
- gdk_cairo_set_source_color (cr, &darker);
- add_path_gap_side (cr, gap_side,
- x + 1, y + 1, width - 4, height - 4,
- xy0_gap, xy1_gap);
- cairo_stroke (cr);
+ switch (gap_side)
+ {
+ case GTK_POS_TOP:
+ xc = x + xy0_gap + border_width;
+ yc = y;
+ wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
+ hc = border_width;
- gdk_cairo_set_source_color (cr, &lighter);
- add_path_gap_side (cr, gap_side,
- x, y, width, height,
- xy0_gap, xy1_gap);
- cairo_stroke (cr);
- }
+ if (xy0_gap < radius)
+ junction |= GTK_JUNCTION_CORNER_TOPLEFT;
- if (gap_side == GTK_POS_LEFT)
- sides = SIDE_TOP;
- else if (gap_side == GTK_POS_TOP)
- sides = SIDE_LEFT;
- else
- sides = SIDE_TOP | SIDE_LEFT;
+ if (xy1_gap > width - radius)
+ junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
+ break;
+ case GTK_POS_BOTTOM:
+ xc = x + xy0_gap + border_width;
+ yc = y + height - border_width;
+ wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
+ hc = border_width;
- gdk_cairo_set_source_color (cr, &lighter);
- add_path_rectangle_sides (cr, x + 1, y + 1, width - 2, height - 3, sides);
- cairo_stroke (cr);
+ if (xy0_gap < radius)
+ junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
- gdk_cairo_set_source_color (cr, &darker);
- add_path_rectangle_sides (cr, x, y, width - 1, height - 1, sides);
- cairo_stroke (cr);
+ if (xy1_gap > width - radius)
+ junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
- if (gap_side == GTK_POS_LEFT ||
- gap_side == GTK_POS_TOP)
- {
- gdk_cairo_set_source_color (cr, &lighter);
- add_path_gap_side (cr, gap_side,
- x + 1, y + 1, width - 4, height - 4,
- xy0_gap, xy1_gap);
- cairo_stroke (cr);
+ break;
+ case GTK_POS_LEFT:
+ xc = x;
+ yc = y + xy0_gap + border_width;
+ wc = border_width;
+ hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
- gdk_cairo_set_source_color (cr, &darker);
- add_path_gap_side (cr, gap_side,
- x, y, width - 2, height - 2,
- xy0_gap, xy1_gap);
- cairo_stroke (cr);
- }
- }
- else
- {
- if (gap_side == GTK_POS_RIGHT)
- sides = SIDE_BOTTOM;
- else if (gap_side == GTK_POS_BOTTOM)
- sides = SIDE_RIGHT;
- else
- sides = SIDE_BOTTOM | SIDE_RIGHT;
+ if (xy0_gap < radius)
+ junction |= GTK_JUNCTION_CORNER_TOPLEFT;
- gdk_cairo_set_source_color (cr, &darker);
- add_path_rectangle_sides (cr, x + 1, y, width - 2, height, sides);
- add_path_rectangle_sides (cr, x, y + 1, width, height - 2, sides);
- cairo_stroke (cr);
+ if (xy1_gap > height - radius)
+ junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
- cairo_set_source_rgb (cr, 0, 0, 0);
- add_path_rectangle_sides (cr, x, y, width, height, sides);
- cairo_stroke (cr);
+ break;
+ case GTK_POS_RIGHT:
+ xc = x + width - border_width;
+ yc = y + xy0_gap + border_width;
+ wc = border_width;
+ hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
- if (gap_side == GTK_POS_RIGHT ||
- gap_side == GTK_POS_BOTTOM)
- {
- gdk_cairo_set_source_color (cr, &darker);
- add_path_gap_side (cr, gap_side,
- x, y, width - 2, height - 2,
- xy0_gap, xy1_gap);
- cairo_stroke (cr);
+ if (xy0_gap < radius)
+ junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
- cairo_set_source_rgb (cr, 0, 0, 0);
- add_path_gap_side (cr, gap_side,
- x, y, width - 1, height - 1,
- xy0_gap, xy1_gap);
- cairo_stroke (cr);
- }
+ if (xy1_gap > height - radius)
+ junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
- if (gap_side == GTK_POS_LEFT)
- sides = SIDE_TOP;
- else if (gap_side == GTK_POS_TOP)
- sides = SIDE_LEFT;
- else
- sides = SIDE_TOP | SIDE_LEFT;
+ break;
+ }
- gdk_cairo_set_source_color (cr, &lighter);
- add_path_rectangle_sides (cr, x, y, width, height, sides);
- cairo_stroke (cr);
+ cairo_clip_extents (cr, &x0, &y0, &x1, &y1);
+ cairo_rectangle (cr, x0, y0, x1 - x0, yc - y0);
+ cairo_rectangle (cr, x0, yc, xc - x0, hc);
+ cairo_rectangle (cr, xc + wc, yc, x1 - (xc + wc), hc);
+ cairo_rectangle (cr, x0, yc + hc, x1 - x0, y1 - (yc + hc));
+ cairo_clip (cr);
- if (gap_side == GTK_POS_LEFT ||
- gap_side == GTK_POS_TOP)
- {
- add_path_gap_side (cr, gap_side,
- x, y, width, height,
- xy0_gap, xy1_gap);
- cairo_stroke (cr);
- }
- }
+ render_frame_internal (engine, cr,
+ x, y, width, height,
+ 0, junction);
cairo_restore (cr);
- gdk_color_free (bg_color);
+ gtk_border_free (border);
}
static void
gdouble height,
GtkPositionType gap_side)
{
- GtkStateFlags flags;
- GdkColor *bg_color;
- GdkColor lighter, darker;
+ GtkJunctionSides junction = 0;
+ guint hidden_side = 0;
cairo_save (cr);
- flags = gtk_theming_engine_get_state (engine);
-
- cairo_set_line_width (cr, 1);
-
- gtk_theming_engine_get (engine, flags,
- "background-color", &bg_color,
- NULL);
- color_shade (bg_color, 0.7, &darker);
- color_shade (bg_color, 1.3, &lighter);
switch (gap_side)
{
- case GTK_POS_TOP:
- gdk_cairo_set_source_color (cr, bg_color);
- cairo_rectangle (cr, x + 1, y, width - 2, height);
- cairo_fill (cr);
-
- gdk_cairo_set_source_color (cr, &lighter);
- add_path_line (cr, x, y, x, y + height - 2);
- cairo_stroke (cr);
-
- gdk_cairo_set_source_color (cr, bg_color);
- add_path_line (cr, x + 1, y, x + 1, y + height - 2);
- cairo_stroke (cr);
-
- gdk_cairo_set_source_color (cr, &darker);
- add_path_line (cr, x + 2, y + height - 2, x + width - 2, y + height - 2);
- add_path_line (cr, x + width - 2, y, x + width - 2, y + height - 2);
- cairo_stroke (cr);
-
- cairo_set_source_rgb (cr, 0, 0, 0);
- add_path_line (cr, x + 1, y + height - 1, x + width - 2, y + height - 1);
- add_path_line (cr, x + width - 1, y, x + width - 1, y + height - 2);
- cairo_stroke (cr);
-
- break;
- case GTK_POS_BOTTOM:
- gdk_cairo_set_source_color (cr, bg_color);
- cairo_rectangle (cr, x + 1, y, width - 2, height);
- cairo_fill (cr);
-
- gdk_cairo_set_source_color (cr, &lighter);
- add_path_line (cr, x + 1, y, x + width - 2, y);
- add_path_line (cr, x, y + 1, x, y + height - 1);
- cairo_stroke (cr);
-
- gdk_cairo_set_source_color (cr, bg_color);
- add_path_line (cr, x + 1, y + 1, x + width - 2, y + 1);
- add_path_line (cr, x + 1, y + 1, x + 1, y + height - 1);
- cairo_stroke (cr);
-
- gdk_cairo_set_source_color (cr, &darker);
- add_path_line (cr, x + width - 2, y + 2, x + width - 2, y + height - 1);
- cairo_stroke (cr);
-
- cairo_set_source_rgb (cr, 0, 0, 0);
- add_path_line (cr, x + width - 1, y + 1, x + width - 1, y + height - 1);
- cairo_stroke (cr);
-
- break;
case GTK_POS_LEFT:
- gdk_cairo_set_source_color (cr, bg_color);
- cairo_rectangle (cr, x, y + 1, width, height - 2);
- cairo_fill (cr);
-
- gdk_cairo_set_source_color (cr, &lighter);
- add_path_line (cr, x, y, x + width - 2, y);
- cairo_stroke (cr);
-
- gdk_cairo_set_source_color (cr, bg_color);
- add_path_line (cr, x + 1, y + 1, x + width - 2, y + 1);
- cairo_stroke (cr);
-
- gdk_cairo_set_source_color (cr, &darker);
- add_path_line (cr, x, y + height - 2, x + width - 2, y + height - 2);
- add_path_line (cr, x + width - 2, y + 2, x + width - 2, y + height - 2);
- cairo_stroke (cr);
-
- cairo_set_source_rgb (cr, 0, 0, 0);
- add_path_line (cr, x, y + height - 1, x + width - 2, y + height - 1);
- add_path_line (cr, x + width - 1, y + 1, x + width - 1, y + height - 2);
- cairo_stroke (cr);
+ junction = GTK_JUNCTION_LEFT;
+ hidden_side = SIDE_LEFT;
+ cairo_translate (cr, x + width, y);
+ cairo_rotate (cr, G_PI / 2);
break;
case GTK_POS_RIGHT:
- gdk_cairo_set_source_color (cr, bg_color);
- cairo_rectangle (cr, x, y + 1, width, height - 2);
- cairo_fill (cr);
-
- gdk_cairo_set_source_color (cr, &lighter);
- add_path_line (cr, x + 1, y, x + width - 1, y);
- add_path_line (cr, x, y + 1, x, y + height - 2);
- cairo_stroke (cr);
-
- gdk_cairo_set_source_color (cr, bg_color);
- add_path_line (cr, x + 1, y + 1, x + width - 1, y + 1);
- add_path_line (cr, x + 1, y + 1, x + 1, y + height - 2);
- cairo_stroke (cr);
+ junction = GTK_JUNCTION_RIGHT;
+ hidden_side = SIDE_RIGHT;
- gdk_cairo_set_source_color (cr, &darker);
- add_path_line (cr, x + 2, y + height - 2, x + width - 1, y + height - 2);
- cairo_stroke (cr);
+ cairo_translate (cr, x, y + height);
+ cairo_rotate (cr, - G_PI / 2);
+ break;
+ case GTK_POS_TOP:
+ junction = GTK_JUNCTION_TOP;
+ hidden_side = SIDE_TOP;
- cairo_set_source_rgb (cr, 0, 0, 0);
- add_path_line (cr, x + 1, y + height - 1, x + width - 1, y + height - 1);
- cairo_stroke (cr);
+ cairo_translate (cr, x + width, y + height);
+ cairo_rotate (cr, G_PI);
+ break;
+ case GTK_POS_BOTTOM:
+ junction = GTK_JUNCTION_BOTTOM;
+ hidden_side = SIDE_BOTTOM;
+ cairo_translate (cr, x, y);
break;
}
+ if (gap_side == GTK_POS_TOP ||
+ gap_side == GTK_POS_BOTTOM)
+ render_background_internal (engine, cr,
+ 0, 0, width, height,
+ GTK_JUNCTION_BOTTOM);
+ else
+ render_background_internal (engine, cr,
+ 0, 0, height, width,
+ GTK_JUNCTION_BOTTOM);
cairo_restore (cr);
- gdk_color_free (bg_color);
+ cairo_save (cr);
+
+ render_frame_internal (engine, cr,
+ x, y, width, height,
+ hidden_side, junction);
+
+ cairo_restore (cr);
}
static void
-render_dot (cairo_t *cr,
- const GdkColor *lighter,
- const GdkColor *darker,
- gdouble x,
- gdouble y,
- gdouble size)
+render_dot (cairo_t *cr,
+ const GdkRGBA *lighter,
+ const GdkRGBA *darker,
+ gdouble x,
+ gdouble y,
+ gdouble size)
{
size = CLAMP ((gint) size, 2, 3);
if (size == 2)
{
- gdk_cairo_set_source_color (cr, lighter);
+ gdk_cairo_set_source_rgba (cr, lighter);
cairo_rectangle (cr, x, y, 1, 1);
cairo_rectangle (cr, x + 1, y + 1, 1, 1);
cairo_fill (cr);
}
else if (size == 3)
{
- gdk_cairo_set_source_color (cr, lighter);
+ gdk_cairo_set_source_rgba (cr, lighter);
cairo_rectangle (cr, x, y, 2, 1);
cairo_rectangle (cr, x, y, 1, 2);
cairo_fill (cr);
- gdk_cairo_set_source_color (cr, darker);
+ gdk_cairo_set_source_rgba (cr, darker);
cairo_rectangle (cr, x + 1, y + 1, 2, 1);
cairo_rectangle (cr, x + 2, y, 1, 2);
cairo_fill (cr);
gdouble height)
{
GtkStateFlags flags;
- GdkColor *bg_color;
- GdkColor lighter, darker;
+ GdkRGBA *bg_color;
+ GdkRGBA lighter, darker;
+ GtkJunctionSides sides;
gint xx, yy;
cairo_save (cr);
flags = gtk_theming_engine_get_state (engine);
- cairo_set_line_width (cr, 1);
+ cairo_set_line_width (cr, 1.0);
+ sides = gtk_theming_engine_get_junction_sides (engine);
gtk_theming_engine_get (engine, flags,
"background-color", &bg_color,
color_shade (bg_color, 0.7, &darker);
color_shade (bg_color, 1.3, &lighter);
- gdk_cairo_set_source_color (cr, bg_color);
- cairo_rectangle (cr, x, y, width, height);
- cairo_fill (cr);
+ render_background_internal (engine, cr, x, y, width, height, sides);
+
+ if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_GRIP))
+ {
+ /* reduce confusing values to a meaningful state */
+ if ((sides & (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT)) == (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT))
+ sides &= ~GTK_JUNCTION_CORNER_TOPLEFT;
+
+ if ((sides & (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT)) == (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT))
+ sides &= ~GTK_JUNCTION_CORNER_TOPRIGHT;
+
+ if (sides == 0)
+ sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
+
+ /* align drawing area to the connected side */
+ if (sides == GTK_JUNCTION_LEFT)
+ {
+ if (height < width)
+ width = height;
+ }
+ else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
+ {
+ if (width < height)
+ height = width;
+ else if (height < width)
+ width = height;
+ }
+ else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
+ {
+ /* make it square, aligning to bottom left */
+ if (width < height)
+ {
+ y += (height - width);
+ height = width;
+ }
+ else if (height < width)
+ width = height;
+ }
+ else if (sides == GTK_JUNCTION_RIGHT)
+ {
+ /* aligning to right */
+ if (height < width)
+ {
+ x += (width - height);
+ width = height;
+ }
+ }
+ else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
+ {
+ if (width < height)
+ height = width;
+ else if (height < width)
+ {
+ x += (width - height);
+ width = height;
+ }
+ }
+ else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
+ {
+ /* make it square, aligning to bottom right */
+ if (width < height)
+ {
+ y += (height - width);
+ height = width;
+ }
+ else if (height < width)
+ {
+ x += (width - height);
+ width = height;
+ }
+ }
+ 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_CORNER_TOPLEFT)
+ {
+ 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_CORNER_TOPRIGHT)
+ {
+ 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;
- if (gtk_theming_engine_has_class (engine, "paned"))
+ 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_CORNER_BOTTOMLEFT)
+ {
+ 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_CORNER_BOTTOMRIGHT)
+ {
+ 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;
+ }
+ }
+ }
+ else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_PANE_SEPARATOR))
{
if (width > height)
for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
else
{
for (yy = y; yy < y + height; yy += 3)
- for (xx = x; xx < x + width; xx += 6)
- {
- render_dot (cr, &lighter, &darker, xx, yy, 2);
- render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
- }
+ for (xx = x; xx < x + width; xx += 6)
+ {
+ render_dot (cr, &lighter, &darker, xx, yy, 2);
+ render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
+ }
}
cairo_restore (cr);
- gdk_color_free (bg_color);
+ gdk_rgba_free (bg_color);
+}
+
+static void
+gtk_theming_engine_render_activity (GtkThemingEngine *engine,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height)
+{
+ if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER))
+ {
+ GtkStateFlags state;
+ guint num_steps, step;
+ GdkRGBA *color;
+ gdouble progress;
+ gdouble radius;
+ gdouble half;
+ gint i;
+
+ num_steps = 12;
+
+ state = gtk_theming_engine_get_state (engine);
+ gtk_theming_engine_get (engine, state,
+ "color", &color,
+ NULL);
+
+ if (gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress))
+ step = (guint) (progress * num_steps);
+ else
+ step = 0;
+
+ cairo_save (cr);
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+ cairo_set_line_width (cr, 2.0);
+ cairo_translate (cr, x + width / 2, y + height / 2);
+
+ radius = MIN (width / 2, height / 2);
+ half = num_steps / 2;
+
+ for (i = 0; i < num_steps; i++)
+ {
+ gint inset = 0.7 * radius;
+
+ /* transparency is a function of time and intial value */
+ gdouble t = 1.0 - (gdouble) ((i + step) % num_steps) / num_steps;
+ gdouble xscale = - sin (i * G_PI / half);
+ gdouble yscale = - cos (i * G_PI / half);
+
+ cairo_set_source_rgba (cr,
+ color->red,
+ color->green,
+ color->blue,
+ color->alpha * t);
+
+ cairo_move_to (cr,
+ (radius - inset) * xscale,
+ (radius - inset) * yscale);
+ cairo_line_to (cr,
+ radius * xscale,
+ radius * yscale);
+ cairo_stroke (cr);
+ }
+
+ cairo_restore (cr);
+
+ gdk_rgba_free (color);
+ }
+ else
+ {
+ gtk_theming_engine_render_background (engine, cr, x, y, width, height);
+ gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
+ }
+}
+
+static GdkPixbuf *
+scale_or_ref (GdkPixbuf *src,
+ gint width,
+ gint height)
+{
+ if (width == gdk_pixbuf_get_width (src) &&
+ height == gdk_pixbuf_get_height (src))
+ return g_object_ref (src);
+ else
+ return gdk_pixbuf_scale_simple (src,
+ width, height,
+ GDK_INTERP_BILINEAR);
+}
+
+static gboolean
+lookup_icon_size (GtkThemingEngine *engine,
+ GtkIconSize size,
+ gint *width,
+ gint *height)
+{
+ GdkScreen *screen;
+ GtkSettings *settings;
+
+ screen = gtk_theming_engine_get_screen (engine);
+ settings = gtk_settings_get_for_screen (screen);
+
+ return gtk_icon_size_lookup_for_settings (settings, size, width, height);
+}
+
+/* Kudos to the gnome-panel guys. */
+static void
+colorshift_pixbuf (GdkPixbuf *src,
+ GdkPixbuf *dest,
+ gint shift)
+{
+ gint i, j;
+ gint width, height, has_alpha, src_rowstride, dest_rowstride;
+ guchar *target_pixels;
+ guchar *original_pixels;
+ guchar *pix_src;
+ guchar *pix_dest;
+ int val;
+ guchar r, g, b;
+
+ has_alpha = gdk_pixbuf_get_has_alpha (src);
+ width = gdk_pixbuf_get_width (src);
+ height = gdk_pixbuf_get_height (src);
+ src_rowstride = gdk_pixbuf_get_rowstride (src);
+ dest_rowstride = gdk_pixbuf_get_rowstride (dest);
+ original_pixels = gdk_pixbuf_get_pixels (src);
+ target_pixels = gdk_pixbuf_get_pixels (dest);
+
+ for (i = 0; i < height; i++)
+ {
+ pix_dest = target_pixels + i * dest_rowstride;
+ pix_src = original_pixels + i * src_rowstride;
+
+ for (j = 0; j < width; j++)
+ {
+ r = *(pix_src++);
+ g = *(pix_src++);
+ b = *(pix_src++);
+
+ val = r + shift;
+ *(pix_dest++) = CLAMP (val, 0, 255);
+
+ val = g + shift;
+ *(pix_dest++) = CLAMP (val, 0, 255);
+
+ val = b + shift;
+ *(pix_dest++) = CLAMP (val, 0, 255);
+
+ if (has_alpha)
+ *(pix_dest++) = *(pix_src++);
+ }
+ }
+}
+
+static GdkPixbuf *
+gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
+ const GtkIconSource *source,
+ GtkIconSize size)
+{
+ GdkPixbuf *scaled;
+ GdkPixbuf *stated;
+ GdkPixbuf *base_pixbuf;
+ GtkStateFlags state;
+ gint width = 1;
+ gint height = 1;
+
+ base_pixbuf = gtk_icon_source_get_pixbuf (source);
+ state = gtk_theming_engine_get_state (engine);
+
+ g_return_val_if_fail (base_pixbuf != NULL, NULL);
+
+ if (size != (GtkIconSize) -1 &&
+ !lookup_icon_size (engine, size, &width, &height))
+ {
+ g_warning (G_STRLOC ": invalid icon size '%d'", size);
+ return NULL;
+ }
+
+ /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
+ * leave it alone.
+ */
+ if (size != (GtkIconSize) -1 &&
+ gtk_icon_source_get_size_wildcarded (source))
+ scaled = scale_or_ref (base_pixbuf, width, height);
+ else
+ scaled = g_object_ref (base_pixbuf);
+
+ /* If the state was wildcarded, then generate a state. */
+ if (gtk_icon_source_get_state_wildcarded (source))
+ {
+ if (state & GTK_STATE_FLAG_INSENSITIVE)
+ {
+ stated = gdk_pixbuf_copy (scaled);
+ gdk_pixbuf_saturate_and_pixelate (scaled, stated,
+ 0.8, TRUE);
+ g_object_unref (scaled);
+ }
+ else if (state & GTK_STATE_FLAG_PRELIGHT)
+ {
+ stated = gdk_pixbuf_copy (scaled);
+ colorshift_pixbuf (scaled, stated, 30);
+ g_object_unref (scaled);
+ }
+ else
+ stated = scaled;
+ }
+ else
+ stated = scaled;
+
+ return stated;
}