[yelp/yelp-3-0] [libyelp/yelp-settings] Setting better colors, based on yelp-xsl color scheme
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp/yelp-3-0] [libyelp/yelp-settings] Setting better colors, based on yelp-xsl color scheme
- Date: Mon, 15 Mar 2010 23:54:03 +0000 (UTC)
commit fed4890a2bda568ceed204fe1fe2cde196e91e21
Author: Shaun McCance <shaunm gnome org>
Date: Mon Mar 15 18:53:37 2010 -0500
[libyelp/yelp-settings] Setting better colors, based on yelp-xsl color scheme
libyelp/yelp-settings.c | 277 ++++++++++++++++++-------------------------
libyelp/yelp-settings.h | 1 +
stylesheets/yelp-common.xsl | 7 +-
3 files changed, 122 insertions(+), 163 deletions(-)
---
diff --git a/libyelp/yelp-settings.c b/libyelp/yelp-settings.c
index d95d4f1..1f0dc1d 100644
--- a/libyelp/yelp-settings.c
+++ b/libyelp/yelp-settings.c
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Copyright (C) 2004-2009 Shaun McCance <shaunm gnome org>
*
@@ -85,15 +85,15 @@ static void gtk_font_changed (GtkSettings *gtk_sett
static void icon_theme_changed (GtkIconTheme *theme,
YelpSettings *settings);
-static void rgb_to_hls (gdouble r,
+static void rgb_to_hsv (gdouble r,
gdouble g,
gdouble b,
gdouble *h,
- gdouble *l,
- gdouble *s);
-static void hls_to_hex (gdouble h,
- gdouble l,
+ gdouble *s,
+ gdouble *v);
+static void hsv_to_hex (gdouble h,
gdouble s,
+ gdouble v,
gchar *str);
/******************************************************************************/
@@ -392,6 +392,7 @@ yelp_settings_get_color_param (YelpSettingsColor color)
"theme.color.link",
"theme.color.link_visted",
"theme.color.gray_background",
+ "theme.color.dark_background",
"theme.color.gray_border",
"theme.color.blue_background",
"theme.color.blue_border",
@@ -639,117 +640,121 @@ gtk_theme_changed (GtkSettings *gtk_settings,
GtkStyle *style;
GdkColor *color;
GdkColor blue = { 0, 0x1E1E, 0x3E3E, 0xE7E7 };
- gdouble base_h, base_l, base_s;
- gdouble text_h, text_l, text_s;
+ gdouble base_h, base_s, base_v;
+ gdouble text_h, text_s, text_v;
gint i;
g_mutex_lock (settings->priv->mutex);
style = gtk_rc_get_style_by_paths (gtk_settings,
- "GtkTextView", "GtkTextView",
- GTK_TYPE_TEXT_VIEW);
+ "GtkTextView", "GtkTextView",
+ GTK_TYPE_TEXT_VIEW);
if (style)
- g_object_ref (G_OBJECT (style));
+ g_object_ref (G_OBJECT (style));
else
- style = gtk_style_new ();
+ style = gtk_style_new ();
- rgb_to_hls (style->text[GTK_STATE_NORMAL].red / 65535.0,
- style->text[GTK_STATE_NORMAL].green / 65535.0,
- style->text[GTK_STATE_NORMAL].blue / 65535.0,
- &text_h, &text_l, &text_s);
- rgb_to_hls (style->base[GTK_STATE_NORMAL].red / 65535.0,
- style->base[GTK_STATE_NORMAL].green / 65535.0,
- style->base[GTK_STATE_NORMAL].blue / 65535.0,
- &base_h, &base_l, &base_s);
+ rgb_to_hsv (style->text[GTK_STATE_NORMAL].red / 65535.0,
+ style->text[GTK_STATE_NORMAL].green / 65535.0,
+ style->text[GTK_STATE_NORMAL].blue / 65535.0,
+ &text_h, &text_s, &text_v);
+ rgb_to_hsv (style->base[GTK_STATE_NORMAL].red / 65535.0,
+ style->base[GTK_STATE_NORMAL].green / 65535.0,
+ style->base[GTK_STATE_NORMAL].blue / 65535.0,
+ &base_h, &base_s, &base_v);
/* YELP_SETTINGS_COLOR_BASE */
g_snprintf (settings->priv->colors[YELP_SETTINGS_COLOR_BASE], 8,
- "#%02X%02X%02X",
- style->base[GTK_STATE_NORMAL].red >> 8,
- style->base[GTK_STATE_NORMAL].green >> 8,
- style->base[GTK_STATE_NORMAL].blue >> 8);
+ "#%02X%02X%02X",
+ style->base[GTK_STATE_NORMAL].red >> 8,
+ style->base[GTK_STATE_NORMAL].green >> 8,
+ style->base[GTK_STATE_NORMAL].blue >> 8);
/* YELP_SETTINGS_COLOR_TEXT */
g_snprintf (settings->priv->colors[YELP_SETTINGS_COLOR_TEXT], 8,
- "#%02X%02X%02X",
- style->text[GTK_STATE_NORMAL].red >> 8,
- style->text[GTK_STATE_NORMAL].green >> 8,
- style->text[GTK_STATE_NORMAL].blue >> 8);
+ "#%02X%02X%02X",
+ style->text[GTK_STATE_NORMAL].red >> 8,
+ style->text[GTK_STATE_NORMAL].green >> 8,
+ style->text[GTK_STATE_NORMAL].blue >> 8);
/* YELP_SETTINGS_COLOR_LINK */
widget = gtk_link_button_new ("http://www.gnome.org");
gtk_widget_style_get (widget, "link-color", &color, NULL);
if (!color)
- color = &blue;
+ color = &blue;
g_snprintf (settings->priv->colors[YELP_SETTINGS_COLOR_LINK], 8,
- "#%02X%02X%02X",
- color->red >> 8,
- color->green >> 8,
- color->blue >> 8);
+ "#%02X%02X%02X",
+ color->red >> 8,
+ color->green >> 8,
+ color->blue >> 8);
if (color != &blue)
- gdk_color_free (color);
-
+ gdk_color_free (color);
+
/* YELP_SETTINGS_COLOR_LINK_VISITED */
color = NULL;
gtk_widget_style_get (widget, "visited-link-color", &color, NULL);
if (color) {
- g_snprintf (settings->priv->colors[YELP_SETTINGS_COLOR_LINK_VISITED], 8,
- "#%02X%02X%02X",
- color->red >> 8,
- color->green >> 8,
- color->blue >> 8);
- gdk_color_free (color);
+ g_snprintf (settings->priv->colors[YELP_SETTINGS_COLOR_LINK_VISITED], 8,
+ "#%02X%02X%02X",
+ color->red >> 8,
+ color->green >> 8,
+ color->blue >> 8);
+ gdk_color_free (color);
}
g_object_ref_sink (widget);
g_object_unref (widget);
/* YELP_SETTINGS_COLOR_TEXT_LIGHT */
- hls_to_hex (text_h,
- text_l - ((text_l - base_l) * 0.25),
- text_s,
- settings->priv->colors[YELP_SETTINGS_COLOR_TEXT_LIGHT]);
+ hsv_to_hex (text_h,
+ text_s,
+ text_v - ((text_v - base_v) * 0.25),
+ settings->priv->colors[YELP_SETTINGS_COLOR_TEXT_LIGHT]);
/* YELP_SETTINGS_COLOR_GRAY */
- hls_to_hex (base_h,
- base_l - ((base_l - text_l) * 0.03),
- base_s,
- settings->priv->colors[YELP_SETTINGS_COLOR_GRAY_BASE]);
- hls_to_hex (base_h,
- base_l - ((base_l - text_l) * 0.25),
- base_s,
- settings->priv->colors[YELP_SETTINGS_COLOR_GRAY_BORDER]);
+ hsv_to_hex (base_h,
+ base_s,
+ base_v - ((base_v - text_v) * 0.05),
+ settings->priv->colors[YELP_SETTINGS_COLOR_GRAY_BASE]);
+ hsv_to_hex (base_h,
+ base_s,
+ base_v - ((base_v - text_v) * 0.1),
+ settings->priv->colors[YELP_SETTINGS_COLOR_DARK_BASE]);
+ hsv_to_hex (base_h,
+ base_s,
+ base_v - ((base_v - text_v) * 0.26),
+ settings->priv->colors[YELP_SETTINGS_COLOR_GRAY_BORDER]);
/* YELP_SETTINGS_COLOR_BLUE */
- hls_to_hex (204,
- base_l - ((base_l - text_l) * 0.03),
- 0.75,
- settings->priv->colors[YELP_SETTINGS_COLOR_BLUE_BASE]);
- hls_to_hex (204,
- base_l - ((base_l - text_l) * 0.25),
- 0.75,
- settings->priv->colors[YELP_SETTINGS_COLOR_BLUE_BORDER]);
+ hsv_to_hex (211,
+ 0.1,
+ base_v - ((base_v - text_v) * 0.01),
+ settings->priv->colors[YELP_SETTINGS_COLOR_BLUE_BASE]);
+ hsv_to_hex (211,
+ 0.45,
+ base_v - ((base_v - text_v) * 0.19),
+ settings->priv->colors[YELP_SETTINGS_COLOR_BLUE_BORDER]);
/* YELP_SETTINGS_COLOR_RED */
- hls_to_hex (0,
- base_l - ((base_l - text_l) * 0.03),
- 0.75,
- settings->priv->colors[YELP_SETTINGS_COLOR_RED_BASE]);
- hls_to_hex (0,
- base_l - ((base_l - text_l) * 0.25),
- 0.75,
- settings->priv->colors[YELP_SETTINGS_COLOR_RED_BORDER]);
+ hsv_to_hex (0,
+ 0.13,
+ base_v - ((base_v - text_v) * 0.01),
+ settings->priv->colors[YELP_SETTINGS_COLOR_RED_BASE]);
+ hsv_to_hex (0,
+ 0.83,
+ base_v - ((base_v - text_v) * 0.06),
+ settings->priv->colors[YELP_SETTINGS_COLOR_RED_BORDER]);
/* YELP_SETTINGS_COLOR_YELLOW */
- hls_to_hex (60,
- base_l - ((base_l - text_l) * 0.03),
- 0.75,
- settings->priv->colors[YELP_SETTINGS_COLOR_YELLOW_BASE]);
- hls_to_hex (60,
- base_l - ((base_l - text_l) * 0.25),
- 0.75,
- settings->priv->colors[YELP_SETTINGS_COLOR_YELLOW_BORDER]);
+ hsv_to_hex (54,
+ 0.2,
+ base_v - ((base_v - text_v) * 0.01),
+ settings->priv->colors[YELP_SETTINGS_COLOR_YELLOW_BASE]);
+ hsv_to_hex (54,
+ 1.0,
+ base_v - ((base_v - text_v) * 0.07),
+ settings->priv->colors[YELP_SETTINGS_COLOR_YELLOW_BORDER]);
g_object_unref (G_OBJECT (style));
@@ -817,42 +822,24 @@ icon_theme_changed (GtkIconTheme *theme,
/******************************************************************************/
static void
-rgb_to_hls (gdouble r, gdouble g, gdouble b, gdouble *h, gdouble *l, gdouble *s)
+rgb_to_hsv (gdouble r, gdouble g, gdouble b, gdouble *h, gdouble *s, gdouble *v)
{
gdouble min, max, delta;
- if (r > g) {
- if (r > b)
- max = r;
- else
- max = b;
- if (g < b)
- min = g;
- else
- min = b;
- }
- else {
- if (g > b)
- max = g;
- else
- max = b;
- if (r < b)
- min = r;
- else
- min = b;
- }
+ max = (r > g) ? r : g;
+ max = (max > b) ? max : b;
+ min = (r < g) ? r : g;
+ min = (min < b) ? min : b;
+
+ delta = max - min;
- *l = (max + min) / 2;
+ *v = max;
*s = 0;
*h = 0;
if (max != min) {
- if (*l <= 0.5)
- *s = (max - min) / (max + min);
- else
- *s = (max - min) / (2 - max - min);
+ *s = delta / *v;
- delta = max - min;
if (r == max)
*h = (g - b) / delta;
else if (g == max)
@@ -867,67 +854,35 @@ rgb_to_hls (gdouble r, gdouble g, gdouble b, gdouble *h, gdouble *l, gdouble *s)
}
static void
-hls_to_hex (gdouble h, gdouble l, gdouble s, gchar *str)
+hsv_to_hex (gdouble h, gdouble s, gdouble v, gchar *str)
{
- gdouble hue;
- gdouble m1, m2;
+ gint hue;
+ gdouble c;
+ gdouble m1, m2, m3;
gdouble r, g, b;
guint8 red, green, blue;
- if (l <= 0.5)
- m2 = l * (1 + s);
- else
- m2 = l + s - l * s;
- m1 = 2 * l - m2;
-
- if (s == 0) {
- r = g = b = l;
- }
- else {
- hue = h + 120;
- while (hue > 360)
- hue -= 360;
- while (hue < 0)
- hue += 360;
-
- if (hue < 60)
- r = m1 + (m2 - m1) * hue / 60;
- else if (hue < 180)
- r = m2;
- else if (hue < 240)
- r = m1 + (m2 - m1) * (240 - hue) / 60;
- else
- r = m1;
-
- hue = h;
- while (hue > 360)
- hue -= 360;
- while (hue < 0)
- hue += 360;
-
- if (hue < 60)
- g = m1 + (m2 - m1) * hue / 60;
- else if (hue < 180)
- g = m2;
- else if (hue < 240)
- g = m1 + (m2 - m1) * (240 - hue) / 60;
- else
- g = m1;
-
- hue = h - 120;
- while (hue > 360)
- hue -= 360;
- while (hue < 0)
- hue += 360;
-
- if (hue < 60)
- b = m1 + (m2 - m1) * hue / 60;
- else if (hue < 180)
- b = m2;
- else if (hue < 240)
- b = m1 + (m2 - m1) * (240 - hue) / 60;
- else
- b = m1;
+ c = v * s;
+ h /= 60;
+ hue = (int) h;
+ m1 = v * (1 - s);
+ m2 = v * (1 - s * (h - hue));
+ m3 = v * (1 - s * (-h + hue + 1));
+
+ r = g = b = v;
+ switch (hue) {
+ case 0:
+ b = m1; g = m3; break;
+ case 1:
+ b = m1; r = m2; break;
+ case 2:
+ r = m1; b = m3; break;
+ case 3:
+ r = m1; g = m2; break;
+ case 4:
+ g = m1; r = m3; break;
+ case 5:
+ g = m1; b = m2; break;
}
red = r * 255;
diff --git a/libyelp/yelp-settings.h b/libyelp/yelp-settings.h
index c1324fc..93143c6 100644
--- a/libyelp/yelp-settings.h
+++ b/libyelp/yelp-settings.h
@@ -54,6 +54,7 @@ typedef enum {
YELP_SETTINGS_COLOR_LINK,
YELP_SETTINGS_COLOR_LINK_VISITED,
YELP_SETTINGS_COLOR_GRAY_BASE,
+ YELP_SETTINGS_COLOR_DARK_BASE,
YELP_SETTINGS_COLOR_GRAY_BORDER,
YELP_SETTINGS_COLOR_BLUE_BASE,
YELP_SETTINGS_COLOR_BLUE_BORDER,
diff --git a/stylesheets/yelp-common.xsl b/stylesheets/yelp-common.xsl
index 177917b..8120eb5 100644
--- a/stylesheets/yelp-common.xsl
+++ b/stylesheets/yelp-common.xsl
@@ -20,13 +20,16 @@ body {
div.head {
max-width: 100%;
width: 100%;
- padding: 0.2em 0 0 0;
+ padding: 0;
margin: 0 0 1em 0;
}
div.trails {
- padding: 0 12px 0 12px;
+ margin: 0;
+ padding: 0.2em 12px 0 12px;
background-color: </xsl:text>
<xsl:value-of select="$theme.color.gray_background"/><xsl:text>;
+ border-top: solid 1px </xsl:text>
+ <xsl:value-of select="$theme.color.gray_border"/><xsl:text>;
border-bottom: solid 1px </xsl:text>
<xsl:value-of select="$theme.color.gray_border"/><xsl:text>;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]