* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gtk/gtkintl.h>
#include "gtkprivate.h"
-#include "gtk9slice.h"
+#include "gtkmodulesprivate.h"
+#include "gtkborderimageprivate.h"
#include "gtkpango.h"
+#include "gtkcssarrayvalueprivate.h"
+#include "gtkcsscornervalueprivate.h"
+#include "gtkcssenumvalueprivate.h"
+#include "gtkcssnumbervalueprivate.h"
+#include "gtkcssrgbavalueprivate.h"
+#include "gtkcssshadowsvalueprivate.h"
+#include "gtkcsstypesprivate.h"
+#include "gtkhslaprivate.h"
+#include "gtkthemingengineprivate.h"
+#include "gtkroundedboxprivate.h"
+#include "gtkthemingbackgroundprivate.h"
+
+#include "fallback-c89.c"
/**
* SECTION:gtkthemingengine
* style information contained in the rendered object's #GtkStyleContext.
*/
-typedef struct GtkThemingEnginePrivate GtkThemingEnginePrivate;
-
-enum {
- SIDE_LEFT = 1,
- SIDE_BOTTOM = 1 << 1,
- SIDE_RIGHT = 1 << 2,
- SIDE_TOP = 1 << 3,
- SIDE_ALL = 0xF
-};
-
enum {
PROP_0,
PROP_NAME
static GdkPixbuf * gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
const GtkIconSource *source,
GtkIconSize size);
+static void gtk_theming_engine_render_icon (GtkThemingEngine *engine,
+ cairo_t *cr,
+ GdkPixbuf *pixbuf,
+ gdouble x,
+ gdouble y);
G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
#define GTK_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_THEMING_MODULE, GtkThemingModule))
#define GTK_IS_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_THEMING_MODULE))
+GType gtk_theming_module_get_type (void);
+
G_DEFINE_TYPE (GtkThemingModule, gtk_theming_module, G_TYPE_TYPE_MODULE);
static void
object_class->set_property = gtk_theming_engine_impl_set_property;
object_class->get_property = gtk_theming_engine_impl_get_property;
+ klass->render_icon = gtk_theming_engine_render_icon;
klass->render_check = gtk_theming_engine_render_check;
klass->render_option = gtk_theming_engine_render_option;
klass->render_arrow = gtk_theming_engine_render_arrow;
priv->context = context;
}
-/**
- * gtk_theming_engine_register_property:
- * @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
- * "-${@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
- * CSS to the #GValue needed. For basic types there is already
- * builtin parsing support, so %NULL may be provided for these
- * cases.
- *
- * <note>
- * 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 by specifying
- * the engine property, either in a previous rule or within the same
- * one.
- * <programlisting>
- * * {
- * engine: someengine;
- * -SomeEngine-custom-property: 2;
- * }
- * </programlisting>
- * </note>
- *
- * Since: 3.0
- **/
-void
-gtk_theming_engine_register_property (const gchar *name_space,
- GtkStylePropertyParser parse_func,
- GParamSpec *pspec)
+GtkStyleContext *
+_gtk_theming_engine_get_context (GtkThemingEngine *engine)
{
- gchar *name;
+ g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
- g_return_if_fail (name_space != NULL);
- g_return_if_fail (strchr (name_space, ' ') == NULL);
- g_return_if_fail (G_IS_PARAM_SPEC (pspec));
+ return engine->priv->context;
+}
- /* 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;
+GtkCssValue *
+_gtk_theming_engine_peek_property (GtkThemingEngine *engine,
+ guint property_id)
+{
+ g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
- gtk_style_properties_register_property (parse_func, pspec);
+ return _gtk_style_context_peek_property (engine->priv->context, property_id);
}
/**
* 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.
* Returns: %TRUE if there is a running transition animation for @state.
*
* Since: 3.0
+ *
+ * Deprecated: 3.6: Always returns %FALSE
**/
gboolean
gtk_theming_engine_state_is_running (GtkThemingEngine *engine,
GtkStateType state,
gdouble *progress)
{
- GtkThemingEnginePrivate *priv;
-
g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
- priv = engine->priv;
- return gtk_style_context_state_is_running (priv->context, state, progress);
+ return FALSE;
}
/**
*
* Since: 3.0
**/
-G_CONST_RETURN GtkWidgetPath *
+const GtkWidgetPath *
gtk_theming_engine_get_path (GtkThemingEngine *engine)
{
GtkThemingEnginePrivate *priv;
* Returns: the widget direction
*
* Since: 3.0
+ *
+ * Deprecated: 3.8: Use gtk_theming_engine_get_state() and
+ * check for #GTK_STATE_FLAG_DIR_LTR and
+ * #GTK_STATE_FLAG_DIR_RTL instead.
**/
GtkTextDirection
gtk_theming_engine_get_direction (GtkThemingEngine *engine)
g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), GTK_TEXT_DIR_LTR);
priv = engine->priv;
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
return gtk_style_context_get_direction (priv->context);
+ G_GNUC_END_IGNORE_DEPRECATIONS;
}
/**
/**
* gtk_theming_engine_get_border:
- * @engine: a #GtkthemingEngine
+ * @engine: a #GtkThemingEngine
* @state: state to retrieve the border for
- * @color: (out): return value for the border settings
+ * @border: (out): return value for the border settings
*
* Gets the border for a given state as a #GtkBorder.
*
/**
* gtk_theming_engine_get_padding:
- * @engine: a #GtkthemingEngine
+ * @engine: a #GtkThemingEngine
* @state: state to retrieve the padding for
- * @color: (out): return value for the padding settings
+ * @padding: (out): return value for the padding settings
*
* Gets the padding for a given state as a #GtkBorder.
*
/**
* gtk_theming_engine_get_margin:
- * @engien: a #GtkThemingEngine
+ * @engine: a #GtkThemingEngine
* @state: state to retrieve the border for
- * @color: (out): return value for the margin settings
+ * @margin: (out): return value for the margin settings
*
* Gets the margin for a given state as a #GtkBorder.
*
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
+ *
+ * Deprecated: 3.8: Use gtk_theming_engine_get()
+ **/
+const PangoFontDescription *
+gtk_theming_engine_get_font (GtkThemingEngine *engine,
+ GtkStateFlags state)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
+
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
+ priv = engine->priv;
+ return gtk_style_context_get_font (priv->context, state);
+ G_GNUC_END_IGNORE_DEPRECATIONS;
+}
/* GtkThemingModule */
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;
}
}
}
-
- if (!engine)
+ else
{
if (G_UNLIKELY (!default_engine))
default_engine = g_object_new (GTK_TYPE_THEMING_ENGINE, NULL);
*
* 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)
{
- GdkRGBA *fg_color, *bg_color, *border_color;
+ GdkRGBA fg_color, bg_color;
GtkStateFlags flags;
gint exterior_size, interior_size, thickness, pad;
GtkBorderStyle border_style;
- GtkBorder *border;
+ GtkBorder border;
gint border_width;
+ GtkThemingBackground bg;
+
+ _gtk_theming_background_init (&bg, engine,
+ x, y,
+ width, height,
+ gtk_theming_engine_get_junction_sides (engine));
+
+ if (_gtk_theming_background_has_background_image (&bg))
+ {
+ _gtk_theming_background_render (&bg, cr);
+ return;
+ }
flags = gtk_theming_engine_get_state (engine);
cairo_save (cr);
- gtk_theming_engine_get (engine, flags,
- "color", &fg_color,
- "background-color", &bg_color,
- "border-color", &border_color,
- "border-style", &border_style,
- "border-width", &border,
- NULL);
+ gtk_theming_engine_get_color (engine, flags, &fg_color);
+ gtk_theming_engine_get_background_color (engine, flags, &bg_color);
+ gtk_theming_engine_get_border (engine, flags, &border);
+ border_style = _gtk_css_border_style_value_get
+ (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_TOP_STYLE));
- border_width = MIN (MIN (border->top, border->bottom),
- MIN (border->left, border->right));
+ 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 */
if (border_style == GTK_BORDER_STYLE_SOLID)
{
+ GdkRGBA border_color;
+
cairo_set_line_width (cr, border_width);
+ gtk_theming_engine_get_border_color (engine, flags, &border_color);
cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
- gdk_cairo_set_source_rgba (cr, bg_color);
+ gdk_cairo_set_source_rgba (cr, &bg_color);
cairo_fill_preserve (cr);
- if (border_color)
- gdk_cairo_set_source_rgba (cr, border_color);
- else
- gdk_cairo_set_source_rgba (cr, fg_color);
-
+ gdk_cairo_set_source_rgba (cr, &border_color);
cairo_stroke (cr);
}
- gdk_cairo_set_source_rgba (cr, fg_color);
+ gdk_cairo_set_source_rgba (cr, &fg_color);
if (flags & GTK_STATE_FLAG_INCONSISTENT)
{
}
else
{
- gdouble progress;
- gboolean running;
-
- running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
-
- if ((flags & GTK_STATE_FLAG_ACTIVE) || running)
+ if (flags & GTK_STATE_FLAG_ACTIVE)
{
- if (!running)
- progress = 1;
-
cairo_translate (cr,
x + pad, y + pad);
cairo_scale (cr, interior_size / 7., interior_size / 7.);
- cairo_rectangle (cr, 0, 0, 7 * progress, 7);
+ cairo_rectangle (cr, 0, 0, 7, 7);
cairo_clip (cr);
cairo_move_to (cr, 7.0, 0.0);
}
cairo_restore (cr);
-
- 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;
- GdkRGBA *fg_color, *bg_color, *border_color;
+ GdkRGBA fg_color, bg_color;
gint exterior_size, interior_size, pad, thickness, border_width;
GtkBorderStyle border_style;
- GtkBorder *border;
- gdouble radius;
+ GtkBorder border;
+ GtkThemingBackground bg;
+
+ _gtk_theming_background_init (&bg, engine,
+ x, y,
+ width, height,
+ gtk_theming_engine_get_junction_sides (engine));
+
+ if (_gtk_theming_background_has_background_image (&bg))
+ {
+ _gtk_theming_background_render (&bg, cr);
+ return;
+ }
flags = gtk_theming_engine_get_state (engine);
- radius = MIN (width, height) / 2 - 0.5;
cairo_save (cr);
- gtk_theming_engine_get (engine, flags,
- "color", &fg_color,
- "background-color", &bg_color,
- "border-color", &border_color,
- "border-style", &border_style,
- "border-width", &border,
- NULL);
+ gtk_theming_engine_get_color (engine, flags, &fg_color);
+ gtk_theming_engine_get_background_color (engine, flags, &bg_color);
+ gtk_theming_engine_get_border (engine, flags, &border);
+ border_style = _gtk_css_border_style_value_get
+ (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_TOP_STYLE));
exterior_size = MIN (width, height);
- border_width = MIN (MIN (border->top, border->bottom),
- MIN (border->left, border->right));
+ border_width = MIN (MIN (border.top, border.bottom),
+ MIN (border.left, border.right));
if (exterior_size % 2 == 0) /* Ensure odd */
exterior_size -= 1;
if (border_style == GTK_BORDER_STYLE_SOLID)
{
+ GdkRGBA border_color;
+
cairo_set_line_width (cr, border_width);
+ gtk_theming_engine_get_border_color (engine, flags, &border_color);
+
+ 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);
+ gdk_cairo_set_source_rgba (cr, &bg_color);
cairo_fill_preserve (cr);
- if (border_color)
- gdk_cairo_set_source_rgba (cr, border_color);
- else
- gdk_cairo_set_source_rgba (cr, fg_color);
-
+ gdk_cairo_set_source_rgba (cr, &border_color);
cairo_stroke (cr);
}
- gdk_cairo_set_source_rgba (cr, fg_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_rgba_free (fg_color);
- gdk_rgba_free (bg_color);
- gdk_rgba_free (border_color);
- gtk_border_free (border);
}
static void
gdouble size)
{
GtkStateFlags flags;
- GdkRGBA *fg_color;
+ GdkRGBA fg_color;
cairo_save (cr);
flags = gtk_theming_engine_get_state (engine);
-
- gtk_theming_engine_get (engine, flags,
- "color", &fg_color,
- NULL);
+ gtk_theming_engine_get_color (engine, flags, &fg_color);
if (flags & GTK_STATE_FLAG_INSENSITIVE)
{
}
add_path_arrow (cr, angle, x, y, size);
- gdk_cairo_set_source_rgba (cr, fg_color);
+ gdk_cairo_set_source_rgba (cr, &fg_color);
cairo_fill (cr);
cairo_restore (cr);
-
- gdk_rgba_free (fg_color);
}
static void
gdouble factor,
GdkRGBA *color_return)
{
- GtkSymbolicColor *literal, *shade;
+ GtkHSLA hsla;
+
+ _gtk_hsla_init_from_rgba (&hsla, color);
+ _gtk_hsla_shade (&hsla, &hsla, factor);
+ _gdk_rgba_init_from_hsla (color_return, &hsla);
+}
+
+static void
+gtk_theming_engine_render_background (GtkThemingEngine *engine,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height)
+{
+ GtkThemingBackground bg;
- literal = gtk_symbolic_color_new_literal (color);
- shade = gtk_symbolic_color_new_shade (literal, factor);
- gtk_symbolic_color_unref (literal);
+ _gtk_theming_background_init (&bg, engine,
+ x, y,
+ width, height,
+ gtk_theming_engine_get_junction_sides (engine));
- gtk_symbolic_color_resolve (shade, NULL, color_return);
- gtk_symbolic_color_unref (shade);
+ _gtk_theming_background_render (&bg, cr);
}
static void
-_cairo_round_rectangle_sides (cairo_t *cr,
- gdouble radius,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height,
- guint sides,
- GtkJunctionSides junction)
-{
- radius = CLAMP (radius, 0, MIN (width / 2, height / 2));
-
- if (sides & SIDE_RIGHT)
- {
- if (radius == 0 ||
- (junction & GTK_JUNCTION_CORNER_TOPRIGHT))
- cairo_move_to (cr, x + width, y);
- else
- {
- cairo_new_sub_path (cr);
- cairo_arc (cr, x + width - radius, y + radius, radius, - G_PI / 4, 0);
- }
+gtk_theming_engine_hide_border_sides (double border[4],
+ GtkBorderStyle border_style[4],
+ guint hidden_side)
+{
+ guint i;
- if (radius == 0 ||
- (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);
+ for (i = 0; i < 4; i++)
+ {
+ if (hidden_side & (1 << i) ||
+ border_style[i] == GTK_BORDER_STYLE_NONE ||
+ border_style[i] == GTK_BORDER_STYLE_HIDDEN)
+ border[i] = 0;
}
+}
- if (sides & SIDE_BOTTOM)
+static void
+render_frame_fill (cairo_t *cr,
+ GtkRoundedBox *border_box,
+ const double border_width[4],
+ GdkRGBA colors[4],
+ guint hidden_side)
+{
+ GtkRoundedBox padding_box;
+ guint i, j;
+
+ padding_box = *border_box;
+ _gtk_rounded_box_shrink (&padding_box,
+ border_width[GTK_CSS_TOP],
+ border_width[GTK_CSS_RIGHT],
+ border_width[GTK_CSS_BOTTOM],
+ border_width[GTK_CSS_LEFT]);
+
+ if (hidden_side == 0 &&
+ gdk_rgba_equal (&colors[0], &colors[1]) &&
+ gdk_rgba_equal (&colors[0], &colors[2]) &&
+ gdk_rgba_equal (&colors[0], &colors[3]))
{
- if (radius != 0 &&
- ! (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT))
- {
- if ((sides & SIDE_RIGHT) == 0)
- cairo_new_sub_path (cr);
+ gdk_cairo_set_source_rgba (cr, &colors[0]);
- 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_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));
+ _gtk_rounded_box_path (border_box, cr);
+ _gtk_rounded_box_path (&padding_box, cr);
+ cairo_fill (cr);
}
else
- cairo_move_to (cr, x, y + height);
-
- if (sides & SIDE_LEFT)
{
- if (radius != 0 &&
- ! (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT))
+ for (i = 0; i < 4; i++)
{
- if ((sides & SIDE_BOTTOM) == 0)
- cairo_new_sub_path (cr);
+ if (hidden_side & (1 << i))
+ continue;
- 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);
+ for (j = 0; j < 4; j++)
+ {
+ if (hidden_side & (1 << j))
+ continue;
- if (radius == 0 ||
- (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 (i == j ||
+ (gdk_rgba_equal (&colors[i], &colors[j])))
+ {
+ /* We were already painted when i == j */
+ if (i > j)
+ break;
+
+ if (j == 0)
+ _gtk_rounded_box_path_top (border_box, &padding_box, cr);
+ else if (j == 1)
+ _gtk_rounded_box_path_right (border_box, &padding_box, cr);
+ else if (j == 2)
+ _gtk_rounded_box_path_bottom (border_box, &padding_box, cr);
+ else if (j == 3)
+ _gtk_rounded_box_path_left (border_box, &padding_box, cr);
+ }
+ }
+ /* We were already painted when i == j */
+ if (i > j)
+ continue;
- if (sides & SIDE_TOP)
- {
- if (radius != 0 &&
- ! (junction & GTK_JUNCTION_CORNER_TOPLEFT))
- {
- if ((sides & SIDE_LEFT) == 0)
- cairo_new_sub_path (cr);
+ gdk_cairo_set_source_rgba (cr, &colors[i]);
- cairo_arc (cr, x + radius, y + radius, radius, 5 * (G_PI / 4), 3 * (G_PI / 2));
+ cairo_fill (cr);
}
- else if ((sides & SIDE_LEFT) == 0)
- cairo_move_to (cr, x, y);
-
- if (radius == 0 ||
- (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);
}
}
static void
-render_background_internal (GtkThemingEngine *engine,
- cairo_t *cr,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height,
- GtkJunctionSides junction)
-{
- GdkRGBA *bg_color;
- cairo_pattern_t *pattern;
- GtkStateFlags flags;
- gboolean running;
- gdouble progress, alpha = 1;
- gint radius, border_width;
- GtkBorder *border;
-
- flags = gtk_theming_engine_get_state (engine);
- cairo_save (cr);
-
- gtk_theming_engine_get (engine, flags,
- "background-image", &pattern,
- "background-color", &bg_color,
- "border-width", &border,
- "border-radius", &radius,
- 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));
+set_stroke_style (cairo_t *cr,
+ double line_width,
+ GtkBorderStyle style,
+ double length)
+{
+ double segments[2];
+ double n;
- _cairo_round_rectangle_sides (cr, (gdouble) radius,
- x, y, width, height,
- SIDE_ALL, junction);
- cairo_clip (cr);
+ cairo_set_line_width (cr, line_width);
- if (gtk_theming_engine_has_class (engine, "background"))
+ if (style == GTK_BORDER_STYLE_DOTTED)
{
- cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); /* transparent */
- cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
- cairo_paint (cr);
- }
+ n = round (0.5 * length / line_width);
- cairo_translate (cr, x, y);
- cairo_scale (cr, width, height);
+ segments[0] = 0;
+ segments[1] = n ? length / n : 2;
+ cairo_set_dash (cr, segments, G_N_ELEMENTS (segments), 0);
- if (running)
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+ cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+ }
+ else
{
- cairo_pattern_t *other_pattern;
- GtkStateFlags other_flags;
- GdkRGBA *other_bg;
- cairo_pattern_t *new_pattern = NULL;
-
- if (flags & GTK_STATE_FLAG_PRELIGHT)
+ n = length / line_width;
+ /* Optimize the common case of an integer-sized rectangle
+ * Again, we care about focus rectangles.
+ */
+ if (n == nearbyint (n))
{
- other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
- progress = 1 - progress;
+ segments[0] = 1;
+ segments[1] = 2;
}
else
- other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
-
- gtk_theming_engine_get (engine, other_flags,
- "background-image", &other_pattern,
- "background-color", &other_bg,
- NULL);
-
- if (pattern && other_pattern)
{
- cairo_pattern_type_t type, other_type;
- gint n0, n1;
-
- cairo_pattern_get_color_stop_count (pattern, &n0);
- cairo_pattern_get_color_stop_count (other_pattern, &n1);
- type = cairo_pattern_get_type (pattern);
- other_type = cairo_pattern_get_type (other_pattern);
+ n = round ((1. / 3) * n);
- if (type == other_type && n0 == n1)
- {
- gdouble offset0, red0, green0, blue0, alpha0;
- gdouble offset1, red1, green1, blue1, alpha1;
- gdouble x00, x01, y00, y01, x10, x11, y10, y11;
- gdouble r00, r01, r10, r11;
- guint i;
-
- if (type == CAIRO_PATTERN_TYPE_LINEAR)
- {
- cairo_pattern_get_linear_points (pattern, &x00, &y00, &x01, &y01);
- cairo_pattern_get_linear_points (other_pattern, &x10, &y10, &x11, &y11);
-
- new_pattern = cairo_pattern_create_linear (x00 + (x10 - x00) * progress,
- y00 + (y10 - y00) * progress,
- x01 + (x11 - x01) * progress,
- y01 + (y11 - y01) * progress);
- }
- else
- {
- cairo_pattern_get_radial_circles (pattern, &x00, &y00, &r00, &x01, &y01, &r01);
- cairo_pattern_get_radial_circles (other_pattern, &x10, &y10, &r10, &x11, &y11, &r11);
-
- new_pattern = cairo_pattern_create_radial (x00 + (x10 - x00) * progress,
- y00 + (y10 - y00) * progress,
- r00 + (r10 - r00) * progress,
- x01 + (x11 - x01) * progress,
- y01 + (y11 - y01) * progress,
- r01 + (r11 - r01) * progress);
- }
-
- cairo_pattern_set_filter (new_pattern, CAIRO_FILTER_FAST);
- i = 0;
-
- /* Blend both gradients into one */
- while (i < n0 && i < n1)
- {
- cairo_pattern_get_color_stop_rgba (pattern, i,
- &offset0,
- &red0, &green0, &blue0,
- &alpha0);
- cairo_pattern_get_color_stop_rgba (other_pattern, i,
- &offset1,
- &red1, &green1, &blue1,
- &alpha1);
-
- cairo_pattern_add_color_stop_rgba (new_pattern,
- offset0 + ((offset1 - offset0) * progress),
- red0 + ((red1 - red0) * progress),
- green0 + ((green1 - green0) * progress),
- blue0 + ((blue1 - blue0) * progress),
- alpha0 + ((alpha1 - alpha0) * progress));
- i++;
- }
- }
- else
- {
- /* Different pattern types, or different color
- * stop counts, alpha blend both patterns.
- */
- cairo_rectangle (cr, 0, 0, 1, 1);
- cairo_set_source (cr, other_pattern);
- cairo_fill_preserve (cr);
-
- /* Set alpha for posterior drawing
- * of the target pattern
- */
- alpha = 1 - progress;
- }
+ segments[0] = n ? (1. / 3) * length / n : 1;
+ segments[1] = 2 * segments[1];
}
- else if (pattern || other_pattern)
- {
- cairo_pattern_t *p;
- const GdkRGBA *c;
- gdouble x0, y0, x1, y1, r0, r1;
- gint n, i;
-
- /* Blend a pattern with a color */
- if (pattern)
- {
- p = pattern;
- c = other_bg;
- progress = 1 - progress;
- }
- else
- {
- p = other_pattern;
- c = bg_color;
- }
+ cairo_set_dash (cr, segments, G_N_ELEMENTS (segments), 0);
- if (cairo_pattern_get_type (p) == CAIRO_PATTERN_TYPE_LINEAR)
- {
- cairo_pattern_get_linear_points (p, &x0, &y0, &x1, &y1);
- new_pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
- }
- else
- {
- cairo_pattern_get_radial_circles (p, &x0, &y0, &r0, &x1, &y1, &r1);
- new_pattern = cairo_pattern_create_radial (x0, y0, r0, x1, y1, r1);
- }
-
- cairo_pattern_get_color_stop_count (p, &n);
-
- for (i = 0; i < n; i++)
- {
- gdouble red1, green1, blue1, alpha1;
- gdouble offset;
-
- cairo_pattern_get_color_stop_rgba (p, i,
- &offset,
- &red1, &green1, &blue1,
- &alpha1);
- cairo_pattern_add_color_stop_rgba (new_pattern, offset,
- 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 GdkRGBA *color, *other_color;
-
- /* Merge just colors */
- color = bg_color;
- other_color = other_bg;
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+ cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
+ }
+}
- 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));
- }
+static void
+render_frame_stroke (cairo_t *cr,
+ GtkRoundedBox *border_box,
+ const double border_width[4],
+ GdkRGBA colors[4],
+ guint hidden_side,
+ GtkBorderStyle stroke_style)
+{
+ gboolean different_colors, different_borders;
+ GtkRoundedBox stroke_box;
+ guint i;
+
+ different_colors = !gdk_rgba_equal (&colors[0], &colors[1]) ||
+ !gdk_rgba_equal (&colors[0], &colors[2]) ||
+ !gdk_rgba_equal (&colors[0], &colors[3]);
+ different_borders = border_width[0] != border_width[1] ||
+ border_width[0] != border_width[2] ||
+ border_width[0] != border_width[3] ;
+
+ stroke_box = *border_box;
+ _gtk_rounded_box_shrink (&stroke_box,
+ border_width[GTK_CSS_TOP] / 2.0,
+ border_width[GTK_CSS_RIGHT] / 2.0,
+ border_width[GTK_CSS_BOTTOM] / 2.0,
+ border_width[GTK_CSS_LEFT] / 2.0);
+
+ if (!different_colors && !different_borders && hidden_side == 0)
+ {
+ double length = 0;
- if (new_pattern)
+ /* FAST PATH:
+ * Mostly expected to trigger for focus rectangles */
+ for (i = 0; i < 4; i++)
{
- /* Replace pattern to use */
- cairo_pattern_destroy (pattern);
- pattern = new_pattern;
+ length += _gtk_rounded_box_guess_length (&stroke_box, i);
+ _gtk_rounded_box_path_side (&stroke_box, cr, i);
}
- if (other_pattern)
- cairo_pattern_destroy (other_pattern);
-
- if (other_bg)
- gdk_rgba_free (other_bg);
- }
-
- cairo_rectangle (cr, 0, 0, 1, 1);
-
- if (pattern)
- {
- cairo_set_source (cr, pattern);
- cairo_pattern_destroy (pattern);
+ gdk_cairo_set_source_rgba (cr, &colors[0]);
+ set_stroke_style (cr, border_width[0], stroke_style, length);
+ cairo_stroke (cr);
}
- else
- gdk_cairo_set_source_rgba (cr, bg_color);
-
- if (alpha == 1)
- cairo_fill (cr);
else
{
- cairo_pattern_t *mask;
+ GtkRoundedBox padding_box;
- mask = cairo_pattern_create_rgba (1, 1, 1, alpha);
- cairo_mask (cr, mask);
- cairo_pattern_destroy (mask);
- }
+ padding_box = *border_box;
+ _gtk_rounded_box_path (&padding_box, cr);
+ _gtk_rounded_box_shrink (&padding_box,
+ border_width[GTK_CSS_TOP],
+ border_width[GTK_CSS_RIGHT],
+ border_width[GTK_CSS_BOTTOM],
+ border_width[GTK_CSS_LEFT]);
- cairo_restore (cr);
-
- gdk_rgba_free (bg_color);
- gtk_border_free (border);
-}
-
-static void
-gtk_theming_engine_render_background (GtkThemingEngine *engine,
- cairo_t *cr,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height)
-{
- GtkJunctionSides junction;
- GtkStateFlags flags;
- GtkBorder *border;
-
- junction = gtk_theming_engine_get_junction_sides (engine);
+ for (i = 0; i < 4; i++)
+ {
+ if (hidden_side & (1 << i))
+ continue;
- if (gtk_theming_engine_has_class (engine, "spinbutton") &&
- gtk_theming_engine_has_class (engine, "button"))
- {
- x += 2;
- y += 2;
- width -= 4;
- height -= 4;
- }
+ cairo_save (cr);
- flags = gtk_theming_engine_get_state (engine);
- gtk_theming_engine_get (engine, flags,
- "border-width", &border,
- NULL);
+ if (i == 0)
+ _gtk_rounded_box_path_top (border_box, &padding_box, cr);
+ else if (i == 1)
+ _gtk_rounded_box_path_right (border_box, &padding_box, cr);
+ else if (i == 2)
+ _gtk_rounded_box_path_bottom (border_box, &padding_box, cr);
+ else if (i == 3)
+ _gtk_rounded_box_path_left (border_box, &padding_box, cr);
+ cairo_clip (cr);
- x += border->left;
- y += border->top;
- width -= border->left + border->right;
- height -= border->top + border->bottom;
+ _gtk_rounded_box_path_side (&stroke_box, cr, i);
- render_background_internal (engine, cr,
- x, y, width, height,
- junction);
+ gdk_cairo_set_source_rgba (cr, &colors[i]);
+ set_stroke_style (cr,
+ border_width[i],
+ stroke_style,
+ _gtk_rounded_box_guess_length (&stroke_box, i));
+ cairo_stroke (cr);
- gtk_border_free (border);
+ cairo_restore (cr);
+ }
+ }
}
-/* 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)
+render_border (cairo_t *cr,
+ GtkRoundedBox *border_box,
+ const double border_width[4],
+ guint hidden_side,
+ GdkRGBA colors[4],
+ GtkBorderStyle border_style[4])
{
- gint i;
+ guint i, j;
+
+ cairo_save (cr);
- 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);
+ cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
- for (i = 1; i < size - 1; i++)
+ for (i = 0; i < 4; 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);
+ if (hidden_side & (1 << i))
+ continue;
+
+ switch (border_style[i])
+ {
+ case GTK_BORDER_STYLE_NONE:
+ case GTK_BORDER_STYLE_HIDDEN:
+ case GTK_BORDER_STYLE_SOLID:
+ break;
+ case GTK_BORDER_STYLE_INSET:
+ if (i == 1 || i == 2)
+ color_shade (&colors[i], 1.8, &colors[i]);
+ break;
+ case GTK_BORDER_STYLE_OUTSET:
+ if (i == 0 || i == 3)
+ color_shade (&colors[i], 1.8, &colors[i]);
+ break;
+ case GTK_BORDER_STYLE_DOTTED:
+ case GTK_BORDER_STYLE_DASHED:
+ {
+ guint dont_draw = hidden_side;
+
+ for (j = 0; j < 4; j++)
+ {
+ if (border_style[j] == border_style[i])
+ hidden_side |= (1 << j);
+ else
+ dont_draw |= (1 << j);
+ }
+
+ render_frame_stroke (cr, border_box, border_width, colors, dont_draw, border_style[i]);
+ }
+ break;
+ case GTK_BORDER_STYLE_DOUBLE:
+ {
+ GtkRoundedBox other_box;
+ double other_border[4];
+ guint dont_draw = hidden_side;
+
+ for (j = 0; j < 4; j++)
+ {
+ if (border_style[j] == GTK_BORDER_STYLE_DOUBLE)
+ hidden_side |= (1 << j);
+ else
+ dont_draw |= (1 << j);
+
+ other_border[i] = border_width[i] / 3;
+ }
+
+ render_frame_fill (cr, border_box, other_border, colors, dont_draw);
+
+ other_box = *border_box;
+ _gtk_rounded_box_shrink (&other_box,
+ 2 * other_border[GTK_CSS_TOP],
+ 2 * other_border[GTK_CSS_RIGHT],
+ 2 * other_border[GTK_CSS_BOTTOM],
+ 2 * other_border[GTK_CSS_LEFT]);
+ render_frame_fill (cr, &other_box, other_border, colors, dont_draw);
+ }
+ break;
+ case GTK_BORDER_STYLE_GROOVE:
+ case GTK_BORDER_STYLE_RIDGE:
+ {
+ GtkRoundedBox other_box;
+ GdkRGBA other_colors[4];
+ guint dont_draw = hidden_side;
+ double other_border[4];
+
+ for (j = 0; j < 4; j++)
+ {
+ other_colors[j] = colors[j];
+ if ((j == 0 || j == 3) ^ (border_style[j] == GTK_BORDER_STYLE_RIDGE))
+ color_shade (&other_colors[j], 1.8, &other_colors[j]);
+ else
+ color_shade (&colors[j], 1.8, &colors[j]);
+ if (border_style[j] == GTK_BORDER_STYLE_GROOVE ||
+ border_style[j] == GTK_BORDER_STYLE_RIDGE)
+ hidden_side |= (1 << j);
+ else
+ dont_draw |= (1 << j);
+ other_border[i] = border_width[i] / 2;
+ }
+
+ render_frame_fill (cr, border_box, other_border, colors, dont_draw);
+
+ other_box = *border_box;
+ _gtk_rounded_box_shrink (&other_box,
+ other_border[GTK_CSS_TOP],
+ other_border[GTK_CSS_RIGHT],
+ other_border[GTK_CSS_BOTTOM],
+ other_border[GTK_CSS_LEFT]);
+ render_frame_fill (cr, &other_box, other_border, other_colors, dont_draw);
+ }
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
}
+
+ render_frame_fill (cr, border_box, border_width, colors, hidden_side);
+
+ cairo_restore (cr);
}
static void
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,
- "border-radius", &radius,
- 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));
-
- if (running)
+ GtkBorderImage border_image;
+ GtkBorderStyle border_style[4];
+ GtkRoundedBox border_box;
+ double border_width[4];
+ GdkRGBA colors[4];
+
+ border_width[0] = _gtk_css_number_value_get (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH), 100);
+ border_width[1] = _gtk_css_number_value_get (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH), 100);
+ border_width[2] = _gtk_css_number_value_get (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH), 100);
+ border_width[3] = _gtk_css_number_value_get (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH), 100);
+
+ border_style[0] = _gtk_css_border_style_value_get (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_TOP_STYLE));
+ border_style[1] = _gtk_css_border_style_value_get (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_RIGHT_STYLE));
+ border_style[2] = _gtk_css_border_style_value_get (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_BOTTOM_STYLE));
+ border_style[3] = _gtk_css_border_style_value_get (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_LEFT_STYLE));
+
+ gtk_theming_engine_hide_border_sides (border_width, border_style, hidden_side);
+
+ if (_gtk_border_image_init (&border_image, engine))
+ _gtk_border_image_render (&border_image, border_width, cr, x, y, width, height);
+ else
{
- 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;
+ colors[0] = *_gtk_css_rgba_value_get_rgba (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_TOP_COLOR));
+ colors[1] = *_gtk_css_rgba_value_get_rgba (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_RIGHT_COLOR));
+ colors[2] = *_gtk_css_rgba_value_get_rgba (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR));
+ colors[3] = *_gtk_css_rgba_value_get_rgba (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_LEFT_COLOR));
- gtk_theming_engine_get (engine, other_state,
- "border-color", &other_color,
- NULL);
+ _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
+ _gtk_rounded_box_apply_border_radius_for_engine (&border_box, engine, junction);
- 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);
+ render_border (cr, &border_box, border_width, hidden_side, colors, border_style);
}
- cairo_save (cr);
-
- color_shade (border_color, 1.8, &lighter);
-
- switch (border_style)
+ border_style[0] = _gtk_css_border_style_value_get (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_OUTLINE_STYLE));
+ if (border_style[0] != GTK_BORDER_STYLE_NONE)
{
- 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);
-
- if (radius == 0)
- cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
- else
- cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
-
- if (border_width > 1)
- {
- d1 = (gdouble) border_width / 2;
- d2 = border_width;
- }
- else
- {
- d1 = 0.5;
- d2 = 1;
- }
-
- cairo_save (cr);
-
- m = MIN (width, height);
- m /= 2;
-
- if (border_style == GTK_BORDER_STYLE_INSET)
- gdk_cairo_set_source_rgba (cr, &lighter);
- else
- gdk_cairo_set_source_rgba (cr, border_color);
-
- _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);
-
- if (border_style == GTK_BORDER_STYLE_INSET)
- gdk_cairo_set_source_rgba (cr, border_color);
- else
- gdk_cairo_set_source_rgba (cr, &lighter);
-
- _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);
-
- 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_rgba (cr, &lighter);
- else
- gdk_cairo_set_source_rgba (cr, border_color);
-
- cairo_set_line_width (cr, 1);
-
- 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;
+ int offset;
+
+ border_style[1] = border_style[2] = border_style[3] = border_style[0];
+ border_width[0] = _gtk_css_number_value_get (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_OUTLINE_WIDTH), 100);
+ border_width[3] = border_width[2] = border_width[1] = border_width[0];
+ colors[0] = *_gtk_css_rgba_value_get_rgba (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_OUTLINE_COLOR));
+ colors[3] = colors[2] = colors[1] = colors[0];
+ offset = _gtk_css_number_value_get (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_OUTLINE_OFFSET), 100);
+
+ /* reinit box here - outlines don't have a border radius */
+ _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
+ _gtk_rounded_box_shrink (&border_box,
+ - border_width[GTK_CSS_TOP] - offset,
+ - border_width[GTK_CSS_RIGHT] - offset,
+ - border_width[GTK_CSS_LEFT] - offset,
+ - border_width[GTK_CSS_BOTTOM] - offset);
+
+ render_border (cr, &border_box, border_width, hidden_side, colors, border_style);
}
-
- cairo_restore (cr);
-
- if (border_color)
- gdk_rgba_free (border_color);
-
- gtk_border_free (border);
}
static void
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);
+ render_frame_internal (engine, cr,
+ x, y, width, height,
+ 0, junction);
}
static void
gdouble height)
{
GtkStateFlags flags;
- GdkRGBA *outline_color, *fg_color;
+ GdkRGBA outline_color, fg_color;
double vertical_overshoot;
int diameter;
double radius;
double x_double, y_double;
gdouble angle;
gint line_width;
+ gboolean is_rtl;
+ gdouble progress;
cairo_save (cr);
flags = gtk_theming_engine_get_state (engine);
- gtk_theming_engine_get (engine, flags,
- "color", &fg_color,
- NULL);
- gtk_theming_engine_get (engine, 0,
- "color", &outline_color,
- NULL);
+ gtk_theming_engine_get_color (engine, flags, &fg_color);
+ gtk_theming_engine_get_border_color (engine, flags, &outline_color);
+ is_rtl = (gtk_theming_engine_get_state (engine) & GTK_STATE_FLAG_DIR_RTL);
line_width = 1;
+ progress = (flags & GTK_STATE_FLAG_ACTIVE) ? 1 : 0;
- /* FIXME: LTR/RTL */
- if (flags & GTK_STATE_FLAG_ACTIVE)
+ 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);
- gdk_cairo_set_source_rgba (cr, fg_color);
+ gdk_cairo_set_source_rgba (cr, &fg_color);
cairo_fill_preserve (cr);
- gdk_cairo_set_source_rgba (cr, outline_color);
+ gdk_cairo_set_source_rgba (cr, &outline_color);
cairo_stroke (cr);
cairo_restore (cr);
-
- gdk_rgba_free (fg_color);
- gdk_rgba_free (outline_color);
}
static void
gdouble height)
{
GtkStateFlags flags;
- GdkRGBA *color;
+ GdkRGBA color;
gint line_width;
gint8 *dash_list;
cairo_save (cr);
flags = gtk_theming_engine_get_state (engine);
- gtk_theming_engine_get (engine, flags,
- "color", &color,
- NULL);
+ gtk_theming_engine_get_color (engine, flags, &color);
gtk_theming_engine_get_style (engine,
"focus-line-width", &line_width,
width - line_width,
height - line_width);
- gdk_cairo_set_source_rgba (cr, color);
+ gdk_cairo_set_source_rgba (cr, &color);
cairo_stroke (cr);
cairo_restore (cr);
- gdk_rgba_free (color);
g_free (dash_list);
}
gdouble x1,
gdouble y1)
{
- GdkRGBA *bg_color, darker, lighter;
+ GdkRGBA color;
GtkStateFlags flags;
- gint i, thickness, thickness_dark, thickness_light, len;
- cairo_matrix_t matrix;
- gdouble angle;
-
- /* FIXME: thickness */
- thickness = 2;
- thickness_dark = thickness / 2;
- thickness_light = thickness - thickness_dark;
flags = gtk_theming_engine_get_state (engine);
cairo_save (cr);
- 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);
+ gtk_theming_engine_get_color (engine, flags, &color);
cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
cairo_set_line_width (cr, 1);
- angle = atan2 (x1 - x0, y1 - y0);
- angle = (2 * G_PI) - angle;
- angle += G_PI / 2;
+ cairo_move_to (cr, x0 + 0.5, y0 + 0.5);
+ cairo_line_to (cr, x1 + 0.5, y1 + 0.5);
- cairo_get_matrix (cr, &matrix);
- cairo_matrix_translate (&matrix, x0, y0);
- cairo_matrix_rotate (&matrix, angle);
- cairo_set_matrix (cr, &matrix);
-
- x1 -= x0;
- y1 -= y0;
-
- len = (gint) sqrt ((x1 * x1) + (y1 * y1));
+ gdk_cairo_set_source_rgba (cr, &color);
+ cairo_stroke (cr);
- y0 = -thickness_dark;
+ cairo_restore (cr);
+}
- for (i = 0; i < thickness_dark; i++)
- {
- gdk_cairo_set_source_rgba (cr, &lighter);
- add_path_line (cr, len - i - 1.5, y0, len - 0.5, y0);
- cairo_stroke (cr);
+static void
+prepare_context_for_layout (cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ PangoLayout *layout)
+{
+ const PangoMatrix *matrix;
- gdk_cairo_set_source_rgba (cr, &darker);
- add_path_line (cr, 0.5, y0, len - i - 1.5, y0);
- cairo_stroke (cr);
+ matrix = pango_context_get_matrix (pango_layout_get_context (layout));
- y0++;
- }
+ cairo_move_to (cr, x, y);
- for (i = 0; i < thickness_light; i++)
+ if (matrix)
{
- gdk_cairo_set_source_rgba (cr, &darker);
- add_path_line (cr, 0.5, y0, thickness_light - i + 0.5, y0);
- cairo_stroke (cr);
+ cairo_matrix_t cairo_matrix;
- 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_matrix_init (&cairo_matrix,
+ matrix->xx, matrix->yx,
+ matrix->xy, matrix->yy,
+ matrix->x0, matrix->y0);
- y0++;
+ cairo_transform (cr, &cairo_matrix);
}
-
- cairo_restore (cr);
-
- gdk_rgba_free (bg_color);
}
static void
gdouble y,
PangoLayout *layout)
{
- const PangoMatrix *matrix;
- GdkRGBA *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_color (engine, flags, &fg_color);
- gtk_theming_engine_get (engine, flags,
- "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,
- matrix->xx, matrix->yx,
- matrix->xy, matrix->yy,
- matrix->x0, matrix->y0);
-
- pango_layout_get_extents (layout, NULL, &rect);
- 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;
+ prepare_context_for_layout (cr, x, y, layout);
- cairo_set_matrix (cr, &cairo_matrix);
- }
- else
- cairo_translate (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);
- _gtk_pango_fill_layout (cr, layout);
- cairo_restore (cr);
- }
+ _gtk_css_shadows_value_paint_layout (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_TEXT_SHADOW),
+ cr, layout);
- gdk_cairo_set_source_rgba (cr, fg_color);
+ gdk_cairo_set_source_rgba (cr, &fg_color);
pango_cairo_show_layout (cr, layout);
cairo_restore (cr);
-
- gdk_rgba_free (fg_color);
}
static void
gdouble height,
GtkOrientation orientation)
{
- const GtkWidgetPath *path;
- gint thickness;
-
- path = gtk_theming_engine_get_path (engine);
-
gtk_theming_engine_render_background (engine, cr, x, y, width, height);
gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
-
- /* FIXME: thickness */
- thickness = 2;
-
- if (gtk_widget_path_is_type (path, GTK_TYPE_SCALE))
- {
- if (orientation == GTK_ORIENTATION_VERTICAL)
- gtk_theming_engine_render_line (engine, cr,
- x + thickness,
- y + (gint) height / 2,
- x + width - thickness - 1,
- y + (gint) height / 2);
- else
- gtk_theming_engine_render_line (engine, cr,
- x + (gint) width / 2,
- y + thickness,
- x + (gint) width / 2,
- y + height - thickness - 1);
- }
}
static void
{
GtkJunctionSides junction;
GtkStateFlags state;
- gint border_width, radius;
+ gint border_width;
+ GtkCssValue *corner[4];
gdouble x0, y0, x1, y1, xc, yc, wc, hc;
- GtkBorder *border;
+ GtkBorder border;
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);
- border_width = MIN (MIN (border->top, border->bottom),
- MIN (border->left, border->right));
+ gtk_theming_engine_get_border (engine, state, &border);
+ corner[GTK_CSS_TOP_LEFT] = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS);
+ corner[GTK_CSS_TOP_RIGHT] = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS);
+ corner[GTK_CSS_BOTTOM_LEFT] = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS);
+ corner[GTK_CSS_BOTTOM_RIGHT] = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS);
+
+ border_width = MIN (MIN (border.top, border.bottom),
+ MIN (border.left, border.right));
cairo_save (cr);
wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
hc = border_width;
- if (xy0_gap < radius)
+ if (xy0_gap < _gtk_css_corner_value_get_x (corner[GTK_CSS_TOP_LEFT], width))
junction |= GTK_JUNCTION_CORNER_TOPLEFT;
- if (xy1_gap > width - radius)
+ if (xy1_gap > width - _gtk_css_corner_value_get_x (corner[GTK_CSS_TOP_RIGHT], width))
junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
break;
case GTK_POS_BOTTOM:
wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
hc = border_width;
- if (xy0_gap < radius)
+ if (xy0_gap < _gtk_css_corner_value_get_x (corner[GTK_CSS_BOTTOM_LEFT], width))
junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
- if (xy1_gap > width - radius)
+ if (xy1_gap > width - _gtk_css_corner_value_get_x (corner[GTK_CSS_BOTTOM_RIGHT], width))
junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
break;
wc = border_width;
hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
- if (xy0_gap < radius)
+ if (xy0_gap < _gtk_css_corner_value_get_y (corner[GTK_CSS_TOP_LEFT], height))
junction |= GTK_JUNCTION_CORNER_TOPLEFT;
- if (xy1_gap > height - radius)
+ if (xy1_gap > height - _gtk_css_corner_value_get_y (corner[GTK_CSS_BOTTOM_LEFT], height))
junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
break;
wc = border_width;
hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
- if (xy0_gap < radius)
+ if (xy0_gap < _gtk_css_corner_value_get_y (corner[GTK_CSS_TOP_RIGHT], height))
junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
- if (xy1_gap > height - radius)
+ if (xy1_gap > height - _gtk_css_corner_value_get_y (corner[GTK_CSS_BOTTOM_RIGHT], height))
junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
break;
0, junction);
cairo_restore (cr);
-
- gtk_border_free (border);
}
static void
gdouble height,
GtkPositionType gap_side)
{
+ GtkThemingBackground bg;
GtkJunctionSides junction = 0;
guint hidden_side = 0;
- cairo_save (cr);
-
switch (gap_side)
{
case GTK_POS_LEFT:
junction = GTK_JUNCTION_LEFT;
- hidden_side = SIDE_LEFT;
-
- cairo_translate (cr, x + width, y);
- cairo_rotate (cr, G_PI / 2);
+ hidden_side = (1 << GTK_CSS_LEFT);
break;
case GTK_POS_RIGHT:
junction = GTK_JUNCTION_RIGHT;
- hidden_side = SIDE_RIGHT;
-
- cairo_translate (cr, x, y + height);
- cairo_rotate (cr, - G_PI / 2);
+ hidden_side = (1 << GTK_CSS_RIGHT);
break;
case GTK_POS_TOP:
junction = GTK_JUNCTION_TOP;
- hidden_side = SIDE_TOP;
-
- cairo_translate (cr, x + width, y + height);
- cairo_rotate (cr, G_PI);
+ hidden_side = (1 << GTK_CSS_TOP);
break;
case GTK_POS_BOTTOM:
junction = GTK_JUNCTION_BOTTOM;
- hidden_side = SIDE_BOTTOM;
-
- cairo_translate (cr, x, y);
+ hidden_side = (1 << GTK_CSS_BOTTOM);
break;
}
- if (gap_side == GTK_POS_TOP ||
- gap_side == GTK_POS_BOTTOM)
- render_background_internal (engine, cr,
- 0, 0, width, height,
- junction);
- else
- render_background_internal (engine, cr,
- 0, 0, height, width,
+ _gtk_theming_background_init (&bg, engine,
+ x, y,
+ width, height,
junction);
-
- cairo_restore (cr);
-
- cairo_save (cr);
+ _gtk_theming_background_render (&bg, cr);
render_frame_internal (engine, cr,
x, y, width, height,
hidden_side, junction);
-
- cairo_restore (cr);
}
static void
gdouble height)
{
GtkStateFlags flags;
- GdkRGBA *bg_color;
- GdkRGBA lighter, darker;
+ GdkRGBA bg_color, lighter, darker;
+ GtkJunctionSides sides;
+ GtkThemingBackground bg;
gint xx, yy;
+ gboolean has_image;
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);
-
- gdk_cairo_set_source_rgba (cr, bg_color);
- cairo_rectangle (cr, x, y, width, height);
- cairo_fill (cr);
+ cairo_set_line_width (cr, 1.0);
+ sides = gtk_theming_engine_get_junction_sides (engine);
+ gtk_theming_engine_get_background_color (engine, flags, &bg_color);
- if (gtk_theming_engine_has_class (engine, "grip"))
- {
- GtkJunctionSides sides;
- gint skip = -1;
+ color_shade (&bg_color, 0.7, &darker);
+ color_shade (&bg_color, 1.3, &lighter);
- cairo_save (cr);
+ _gtk_theming_background_init (&bg, engine, x, y, width, height, sides);
+ has_image = _gtk_theming_background_has_background_image (&bg);
+ _gtk_theming_background_render (&bg, cr);
- cairo_set_line_width (cr, 1.0);
- sides = gtk_theming_engine_get_junction_sides (engine);
+ gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
+ 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;
height = width;
else if (height < width)
width = height;
-
- skip = 2;
}
else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
{
}
else if (height < width)
width = height;
-
- skip = 1;
}
else if (sides == GTK_JUNCTION_RIGHT)
{
x += (width - height);
width = height;
}
-
- skip = 3;
}
else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
{
x += (width - height);
width = height;
}
-
- skip = 0;
}
else if (sides == GTK_JUNCTION_TOP)
{
gdk_cairo_set_source_rgba (cr, &darker);
add_path_line (cr, x, yi, x + width, yi);
cairo_stroke (cr);
- yi+= 2;
+ yi += 2;
}
}
else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
yi += 3;
}
}
-
- cairo_restore (cr);
}
- else if (gtk_theming_engine_has_class (engine, "paned"))
+ 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)
- render_dot (cr, &lighter, &darker, xx, y + height / 2 - 1, 3);
- else
- for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5)
- render_dot (cr, &lighter, &darker, x + width / 2 - 1, yy, 3);
+ if (!has_image)
+ {
+ if (width > height)
+ for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
+ render_dot (cr, &lighter, &darker, xx, y + height / 2 - 1, 3);
+ else
+ for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5)
+ render_dot (cr, &lighter, &darker, x + width / 2 - 1, yy, 3);
+ }
}
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_rgba_free (bg_color);
}
-static void
-gtk_theming_engine_render_activity (GtkThemingEngine *engine,
- cairo_t *cr,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height)
+void
+_gtk_theming_engine_paint_spinner (cairo_t *cr,
+ gdouble radius,
+ gdouble progress,
+ const GdkRGBA *color)
{
- if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER))
- {
- GtkStateFlags state;
- guint num_steps, step;
- GdkRGBA *color;
- gdouble dx, dy;
- gdouble progress;
- gdouble radius;
- gdouble half;
- gint i;
+ guint num_steps, step;
+ gdouble half;
+ gint i;
- num_steps = 0;
+ num_steps = 12;
- gtk_theming_engine_get_style (engine,
- "num-steps", &num_steps,
- NULL);
+ if (progress >= 0)
+ step = (guint) (progress * num_steps);
+ else
+ step = 0;
- state = gtk_theming_engine_get_state (engine);
- gtk_theming_engine_get (engine, state,
- "color", &color,
- NULL);
- if (num_steps == 0)
- num_steps = 12;
+ cairo_save (cr);
- if (gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress))
- step = (guint) (progress * num_steps);
- else
- step = 0;
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+ cairo_set_line_width (cr, 2.0);
- cairo_save (cr);
+ half = num_steps / 2;
- cairo_translate (cr, x, y);
+ 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);
- /* draw clip region */
- cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+ cairo_stroke (cr);
+ }
- dx = width / 2;
- dy = height / 2;
- radius = MIN (width / 2, height / 2);
- half = num_steps / 2;
+ cairo_restore (cr);
+}
- for (i = 0; i < num_steps; i++)
- {
- gint inset = 0.7 * radius;
+static void
+render_spinner (GtkThemingEngine *engine,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height)
+{
+ GtkStateFlags state;
+ GdkRGBA color;
+ gdouble radius;
- /* transparency is a function of time and intial value */
- gdouble t = (gdouble) ((i + num_steps - step)
- % num_steps) / num_steps;
+ state = gtk_theming_engine_get_state (engine);
+ radius = MIN (width / 2, height / 2);
- cairo_save (cr);
+ gtk_theming_engine_get_color (engine, state, &color);
- cairo_set_source_rgba (cr,
- color->red,
- color->green,
- color->blue,
- color->alpha * t);
-
- cairo_set_line_width (cr, 2.0);
- cairo_move_to (cr,
- dx + (radius - inset) * cos (i * G_PI / half),
- dy + (radius - inset) * sin (i * G_PI / half));
- cairo_line_to (cr,
- dx + radius * cos (i * G_PI / half),
- dy + radius * sin (i * G_PI / half));
- cairo_stroke (cr);
+ cairo_save (cr);
+ cairo_translate (cr, x + width / 2, y + height / 2);
- cairo_restore (cr);
- }
+ _gtk_css_shadows_value_paint_spinner (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_ICON_SHADOW),
+ cr,
+ radius,
+ -1);
+
+ _gtk_theming_engine_paint_spinner (cr,
+ radius,
+ -1,
+ &color);
- cairo_restore (cr);
+ cairo_restore (cr);
+}
- gdk_rgba_free (color);
+static void
+gtk_theming_engine_render_activity (GtkThemingEngine *engine,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height)
+{
+ GtkThemingBackground bg;
+
+ _gtk_theming_background_init (&bg, engine, x, y, width, height, 0);
+
+ if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER) &&
+ !_gtk_theming_background_has_background_image (&bg))
+ {
+ render_spinner (engine, cr, x, y, width, height);
}
else
{
- gtk_theming_engine_render_background (engine, cr, x, y, width, height);
+ _gtk_theming_background_render (&bg, cr);
gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
}
}
return gtk_icon_size_lookup_for_settings (settings, size, width, height);
}
+static void
+colorshift_source (cairo_t *cr,
+ gdouble shift)
+{
+ cairo_pattern_t *source;
+
+ cairo_save (cr);
+ cairo_paint (cr);
+
+ source = cairo_pattern_reference (cairo_get_source (cr));
+
+ cairo_set_source_rgb (cr, shift, shift, shift);
+ cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
+
+ cairo_mask (cr, source);
+
+ cairo_pattern_destroy (source);
+ cairo_restore (cr);
+}
+
static GdkPixbuf *
gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
const GtkIconSource *source,
GtkStateFlags state;
gint width = 1;
gint height = 1;
+ cairo_t *cr;
+ cairo_surface_t *surface;
base_pixbuf = gtk_icon_source_get_pixbuf (source);
state = gtk_theming_engine_get_state (engine);
{
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);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ gdk_pixbuf_get_width (scaled),
+ gdk_pixbuf_get_height (scaled));
+ cr = cairo_create (surface);
+ gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
+ cairo_paint_with_alpha (cr, 0.5);
+
+ cairo_destroy (cr);
+
+ g_object_unref (scaled);
+ stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
+ cairo_image_surface_get_width (surface),
+ cairo_image_surface_get_height (surface));
+ cairo_surface_destroy (surface);
}
else if (state & GTK_STATE_FLAG_PRELIGHT)
{
- stated = gdk_pixbuf_copy (scaled);
- gdk_pixbuf_saturate_and_pixelate (scaled, stated,
- 1.2, FALSE);
- g_object_unref (scaled);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ gdk_pixbuf_get_width (scaled),
+ gdk_pixbuf_get_height (scaled));
+
+ cr = cairo_create (surface);
+ gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
+ colorshift_source (cr, 0.10);
+
+ cairo_destroy (cr);
+
+ g_object_unref (scaled);
+ stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
+ cairo_image_surface_get_width (surface),
+ cairo_image_surface_get_height (surface));
+ cairo_surface_destroy (surface);
}
else
stated = scaled;
return stated;
}
+
+static void
+gtk_theming_engine_render_icon (GtkThemingEngine *engine,
+ cairo_t *cr,
+ GdkPixbuf *pixbuf,
+ gdouble x,
+ gdouble y)
+{
+ cairo_save (cr);
+
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
+
+ _gtk_css_shadows_value_paint_icon (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_ICON_SHADOW), cr);
+
+ cairo_paint (cr);
+
+ cairo_restore (cr);
+}
+