cheese r679 - in trunk: . data/pixmaps src



Author: dgsiegel
Date: Fri Apr 25 12:08:58 2008
New Revision: 679
URL: http://svn.gnome.org/viewvc/cheese?rev=679&view=rev

Log:
use gtk theme colors for the countdown widget


Modified:
   trunk/ChangeLog
   trunk/data/pixmaps/camera-icon.svg
   trunk/src/cheese-countdown.c

Modified: trunk/data/pixmaps/camera-icon.svg
==============================================================================
--- trunk/data/pixmaps/camera-icon.svg	(original)
+++ trunk/data/pixmaps/camera-icon.svg	Fri Apr 25 12:08:58 2008
@@ -2,7 +2,7 @@
 <!-- Created with Inkscape (http://www.inkscape.org/) -->
 <svg
    xmlns:dc="http://purl.org/dc/elements/1.1/";
-   xmlns:cc="http://web.resource.org/cc/";
+   xmlns:cc="http://creativecommons.org/ns#";
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
    xmlns:svg="http://www.w3.org/2000/svg";
    xmlns="http://www.w3.org/2000/svg";
@@ -13,7 +13,7 @@
    height="30"
    id="svg2"
    sodipodi:version="0.32"
-   inkscape:version="0.45.1"
+   inkscape:version="0.46"
    sodipodi:docname="camera-icon.svg"
    sodipodi:docbase="/home/users/patrys/Desktop/lab/cheese/data/pixmaps"
    inkscape:output_extension="org.inkscape.output.svg.inkscape">
@@ -29,10 +29,10 @@
     </rdf:RDF>
   </metadata>
   <sodipodi:namedview
-     inkscape:window-height="620"
-     inkscape:window-width="872"
+     inkscape:window-height="722"
+     inkscape:window-width="1288"
      inkscape:pageshadow="2"
-     inkscape:pageopacity="0.0"
+     inkscape:pageopacity="0"
      guidetolerance="10.0"
      gridtolerance="10.0"
      objecttolerance="10.0"
@@ -42,14 +42,28 @@
      id="base"
      width="30px"
      height="30px"
-     inkscape:zoom="6.7833333"
-     inkscape:cx="30"
-     inkscape:cy="12.309582"
-     inkscape:window-x="0"
-     inkscape:window-y="25"
-     inkscape:current-layer="svg2" />
+     inkscape:zoom="13.566667"
+     inkscape:cx="19.732415"
+     inkscape:cy="17.268334"
+     inkscape:window-x="3"
+     inkscape:window-y="51"
+     inkscape:current-layer="layer3"
+     showgrid="true">
+    <inkscape:grid
+       type="xygrid"
+       id="grid5139"
+       visible="true"
+       enabled="true" />
+  </sodipodi:namedview>
   <defs
      id="defs4">
+    <inkscape:perspective
+       sodipodi:type="inkscape:persp3d"
+       inkscape:vp_x="0 : 15 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_z="30 : 15 : 1"
+       inkscape:persp3d-origin="15 : 10 : 1"
+       id="perspective24" />
     <filter
        x="-0.1545473"
        width="1.3090945"
@@ -121,31 +135,10 @@
      style="display:inline"
      id="layer3"
      transform="matrix(0.4962866,0,0,0.4962866,0.1114021,0.1114022)">
-    <g
-       style="opacity:1;fill:#ffffff;fill-opacity:1;display:inline"
-       id="g2183">
-      <g
-         style="fill:#ffffff;fill-opacity:1"
-         id="g2185">
-        <rect
-           width="32.623775"
-           height="5.6962147"
-           rx="2.2113023"
-           ry="2.2113023"
-           x="13.688112"
-           y="8.6353283"
-           style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
-           id="rect2187" />
-        <path
-           d="M 4.0940897,11.993542 C 2.564051,11.993542 1.3498196,13.244365 1.3498196,14.774403 L 1.3498196,48.583811 C 1.3498196,50.113849 2.564051,51.364671 4.0940897,51.364671 L 55.90591,51.364671 C 57.435948,51.364671 58.65018,50.113849 58.65018,48.583811 L 58.65018,14.774403 C 58.65018,13.244365 57.435948,11.993542 55.90591,11.993542 L 4.0940897,11.993542 z M 30,15.469618 C 38.950294,15.469618 46.209489,22.728813 46.209489,31.679107 C 46.20949,40.6294 38.950294,47.888596 30,47.888596 C 21.049708,47.888596 13.790511,40.6294 13.790511,31.679107 C 13.790511,22.728813 21.049706,15.469618 30,15.469618 z "
-           style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
-           id="path2189" />
-        <path
-           d="M 46.06637,34.20763 C 46.068254,40.635655 40.857839,45.847598 34.429814,45.847598 C 28.001788,45.847598 22.791373,40.635655 22.793257,34.20763 C 22.791373,27.779605 28.001788,22.567662 34.429814,22.567662 C 40.857839,22.567662 46.068254,27.779605 46.06637,34.20763 L 46.06637,34.20763 z "
-           transform="matrix(0.9038829,0,0,0.9038829,-1.1205199,0.7594145)"
-           style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;display:inline"
-           id="path2191" />
-      </g>
-    </g>
+    <path
+       style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+       d="M 0 0 L 0 30 L 30 30 L 30 0 L 0 0 z M 8.09375 4.34375 L 22.09375 4.34375 C 22.701731 4.3437501 23.1875 4.8295183 23.1875 5.4375 L 23.1875 6 L 27.9375 6 C 28.696837 6 29.312499 6.6156624 29.3125 7.375 L 29.3125 24.15625 C 29.3125 24.915587 28.696836 25.531248 27.9375 25.53125 L 2.25 25.53125 C 1.4906623 25.53125 0.87500001 24.915587 0.875 24.15625 L 0.875 7.375 C 0.875 6.6156626 1.4906623 6 2.25 6 L 7 6 L 7 5.4375 C 7 4.8295185 7.4857684 4.3437499 8.09375 4.34375 z M 15.09375 7.71875 C 10.65184 7.71875 7.0624999 11.339339 7.0625 15.78125 C 7.0625 20.22316 10.65184 23.8125 15.09375 23.8125 C 19.535661 23.8125 23.125001 20.22316 23.125 15.78125 C 23.125 11.33934 19.535661 7.7187502 15.09375 7.71875 z M 14.5625 10.5625 C 14.738015 10.544672 14.91353 10.5625 15.09375 10.5625 C 17.977266 10.5625 20.313345 12.897735 20.3125 15.78125 C 20.313345 18.664766 17.977265 20.999999 15.09375 21 C 12.210234 21 9.8741551 18.664765 9.875 15.78125 C 9.8742074 13.077955 11.929774 10.82
 992 14.5625 10.5625 z "
+       transform="matrix(2.0149647,0,0,2.0149647,-0.2244713,-0.2244715)"
+       id="rect5141" />
   </g>
 </svg>

Modified: trunk/src/cheese-countdown.c
==============================================================================
--- trunk/src/cheese-countdown.c	(original)
+++ trunk/src/cheese-countdown.c	Fri Apr 25 12:08:58 2008
@@ -53,8 +53,160 @@
   cheese_countdown_cb_t picture_callback;
   cheese_countdown_cb_t hide_callback;
   gpointer callback_data;
+  gdouble bg[3];
+  gdouble bg_light[3];
+  gdouble text[3];
 } CheeseCountdownPrivate;
 
+/* copied from gtk/gtkhsv.c, released under GPL v2 */
+/* Converts from HSV to RGB */
+static void
+hsv_to_rgb (gdouble *h,
+            gdouble *s,
+            gdouble *v)
+{
+  gdouble hue, saturation, value;
+  gdouble f, p, q, t;
+
+  if (*s <= 0.0)
+  {
+    *h = *v;
+    *s = *v;
+    *v = *v; /* heh */
+  }
+  else
+  {
+    hue = *h * 6.0;
+    saturation = *s;
+    value = *v;
+
+    if (hue >= 6.0)
+      hue = 0.0;
+
+    f = hue - (int) hue;
+    p = value * (1.0 - saturation);
+    q = value * (1.0 - saturation * f);
+    t = value * (1.0 - saturation * (1.0 - f));
+
+    switch ((int) hue)
+    {
+      case 0:
+        *h = value;
+        *s = t;
+        *v = p;
+        break;
+
+      case 1:
+        *h = q;
+        *s = value;
+        *v = p;
+        break;
+
+      case 2:
+        *h = p;
+        *s = value;
+        *v = t;
+        break;
+
+      case 3:
+        *h = p;
+        *s = q;
+        *v = value;
+        break;
+
+      case 4:
+        *h = t;
+        *s = p;
+        *v = value;
+        break;
+
+      case 5:
+        *h = value;
+        *s = p;
+        *v = q;
+        break;
+
+      default:
+        g_assert_not_reached ();
+    }
+  }
+}
+
+/* Converts from RGB to HSV */
+static void
+rgb_to_hsv (gdouble *r,
+            gdouble *g,
+            gdouble *b)
+{
+  gdouble red, green, blue;
+  gdouble h, s, v;
+  gdouble min, max;
+  gdouble delta;
+
+  red = *r;
+  green = *g;
+  blue = *b;
+
+  h = 0.0;
+
+  if (red > green)
+  {
+    if (red > blue)
+      max = red;
+    else
+      max = blue;
+
+    if (green < blue)
+      min = green;
+    else
+      min = blue;
+  }
+  else
+  {
+    if (green > blue)
+      max = green;
+    else
+      max = blue;
+
+    if (red < blue)
+      min = red;
+    else
+      min = blue;
+  }
+
+  v = max;
+
+  if (max != 0.0)
+    s = (max - min) / max;
+  else
+    s = 0.0;
+
+  if (s <= 0.0)
+    h = 0.0;
+  else
+  {
+    delta = max - min;
+
+    if (red == max)
+      h = (green - blue) / delta;
+    else if (green == max)
+      h = 2 + (blue - red) / delta;
+    else if (blue == max)
+      h = 4 + (red - green) / delta;
+
+    h /= 6.0;
+
+    if (h < 0.0)
+      h += 1.0;
+    else if (h > 1.0)
+      h -= 1.0;
+  }
+
+  *r = h;
+  *g = s;
+  *b = v;
+}
+
 static gint
 do_text (cairo_t*    pContext,
          gchar*      pcText,
@@ -126,8 +278,8 @@
 static gboolean
 on_expose (GtkWidget* widget, GdkEventExpose* pEvent, gpointer data)
 {
-  CheeseCountdownPrivate* priv = CHEESE_COUNTDOWN_GET_PRIVATE (widget);
-  cairo_t*  pContext = NULL;
+  CheeseCountdownPrivate *priv = CHEESE_COUNTDOWN_GET_PRIVATE (widget);
+  cairo_t  *pContext = NULL;
   gdouble   fWidth   = (gdouble) widget->allocation.width;
   gdouble   fHeight  = (gdouble) widget->allocation.height;
   gint      iOffsetX = (widget->allocation.width - 4 * 24) / 2;
@@ -165,23 +317,24 @@
   cairo_rectangle (pContext, 0.0f, 0.0f, fWidth, fHeight);
   cairo_clip (pContext);
 
-  /* draw the red-ish background */
+  /* draw the color-ish background */
   /* glossy version */
-  /*
-  cairo_set_source_rgba (pContext, 1.0f, 0.5f, 0.5f, 1.0f);
+  cairo_set_source_rgba (pContext, priv->bg_light[R], priv->bg_light[G], priv->bg_light[B], 1.0f);
   cairo_rectangle (pContext, 0.0f, 0.0f, fWidth, fHeight);
   cairo_fill (pContext);
-  cairo_set_source_rgba (pContext, 1.0f, 0.25f, 0.25f, 1.0f);
+
+  cairo_set_source_rgba (pContext, priv->bg[R], priv->bg[G], priv->bg[B], 1.0f);
   cairo_rectangle (pContext, 0.0f, fHeight / 2.0f, fWidth, fHeight / 2.0f);
   cairo_fill (pContext);
-  */
   /* plain version */
-  cairo_set_source_rgba (pContext, 1.0f, 0.25f, 0.25f, 1.0f);
+  /*
+  cairo_set_source_rgba (pContext, bg[R], bg[G], bg[B], 1.0f);
   cairo_rectangle (pContext, 0.0f, 0.0f, fWidth, fHeight);
   cairo_fill (pContext);
+  */
 
   /* draw the 3 */
-  cairo_set_source_rgba (pContext, 1.0f, 1.0f, 1.0f, fAlpha3);
+  cairo_set_source_rgba (pContext, priv->text[R], priv->text[G], priv->text[B], fAlpha3);
   cairo_move_to (pContext, (gdouble) iOffsetX, (gdouble) iOffsetY);
   iOffsetX += do_text (pContext,
                        "3 ",
@@ -192,7 +345,7 @@
   cairo_fill (pContext);
 
   /* draw the 2 */
-  cairo_set_source_rgba (pContext, 1.0f, 1.0f, 1.0f, fAlpha2);
+  cairo_set_source_rgba (pContext, priv->text[R], priv->text[G], priv->text[B], fAlpha2);
   cairo_move_to (pContext, (gdouble) iOffsetX, (gdouble) iOffsetY);
   iOffsetX += do_text (pContext,
                        "2 ",
@@ -203,7 +356,7 @@
   cairo_fill (pContext);
 
   /* draw the 1 */
-  cairo_set_source_rgba (pContext, 1.0f, 1.0f, 1.0f, fAlpha1);
+  cairo_set_source_rgba (pContext, priv->text[R], priv->text[G], priv->text[B], fAlpha1);
   cairo_move_to (pContext, (gdouble) iOffsetX, (gdouble) iOffsetY);
   iOffsetX += do_text (pContext,
                        "1 ",
@@ -235,7 +388,7 @@
 }
 
 static cairo_surface_t*
-create_surface_from_svg (gchar* pcFilename)
+create_surface_from_svg (GtkWidget *widget, gchar* pcFilename)
 {
   cairo_surface_t*  pSurface   = NULL;
   RsvgHandle*       pSvgHandle = NULL;
@@ -243,6 +396,8 @@
   cairo_t*          pContext   = NULL;
   RsvgDimensionData dimension;
 
+  CheeseCountdownPrivate* priv = CHEESE_COUNTDOWN_GET_PRIVATE (widget);
+
   rsvg_init ();
 
   /* load svg-file from disk */
@@ -250,7 +405,7 @@
   if (!pSvgHandle)
   {
     g_print ("Could not load file %s!\n", pcFilename);
-    g_error_free(pError);
+    g_error_free (pError);
     return NULL;
   }
 
@@ -259,8 +414,8 @@
 
   /* create a surface-buffer */
   pSurface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
-                 dimension.width,
-                 dimension.height);
+                                         dimension.width,
+                                         dimension.height);
   if (cairo_surface_status (pSurface) != CAIRO_STATUS_SUCCESS)
   {
     g_print ("Could not create surface for svg-icon!\n");
@@ -276,8 +431,8 @@
   }
 
   /* clear that context */
-  cairo_set_source_rgba (pContext, 1.0f, 1.0f, 1.0f, 0.0f);
-  cairo_set_operator (pContext, CAIRO_OPERATOR_OVER);
+  cairo_set_source_rgba (pContext, priv->text[R], priv->text[G], priv->text[B], 1.0f);
+  cairo_set_operator (pContext, CAIRO_OPERATOR_XOR);
   cairo_paint (pContext);
 
   /* draw icon into surface-buffer */
@@ -291,6 +446,44 @@
   return pSurface;
 }
 
+static void
+on_style_set_cb (GtkWidget *widget, GtkStyle *previous_style, gpointer data)
+{
+  CheeseCountdownPrivate* priv = CHEESE_COUNTDOWN_GET_PRIVATE (data);
+
+  GdkColor *color_bg = &GTK_WIDGET(widget)->style->bg[GTK_STATE_SELECTED];
+  GdkColor *color_text = &GTK_WIDGET(widget)->style->text[GTK_STATE_SELECTED];
+  priv->bg[R] = ((double)color_bg->red) / 65535;
+  priv->bg[G] = ((double)color_bg->green) / 65535;
+  priv->bg[B] = ((double)color_bg->blue) / 65535;
+  priv->text[R] = ((double)color_text->red) / 65535;
+  priv->text[G] = ((double)color_text->green) / 65535;
+  priv->text[B] = ((double)color_text->blue) / 65535;
+  gdouble h, s, v;
+  gdouble s_mid, s_light, s_dark;
+
+  h = priv->bg[R]; s = priv->bg[G]; v = priv->bg[B];
+  rgb_to_hsv (&h, &s, &v);
+
+  s_mid = s;
+  if (s_mid <= 0.125)
+    s_mid = 0.125;
+  if (s_mid >= 0.875)
+    s_mid = 0.875;
+  s_dark = s_mid - 0.125;
+  s_light = s_mid + 0.125;
+
+  priv->bg[R] = h; priv->bg[G] = s_light; priv->bg[B] = v;
+  hsv_to_rgb (&priv->bg[R], &priv->bg[G], &priv->bg[B]);
+
+  priv->bg_light[R] = h; priv->bg_light[G] = s_dark; priv->bg_light[B] = v;
+  hsv_to_rgb (&priv->bg_light[R], &priv->bg_light[G], &priv->bg_light[B]);
+
+  /* create/load svg-icon */
+  g_free(priv->pSurface);
+  priv->pSurface = create_surface_from_svg (widget, PACKAGE_DATADIR "/pixmaps/camera-icon.svg");
+}
+
 static gboolean
 cheese_countdown_cb (gpointer countdown)
 {
@@ -366,14 +559,14 @@
 {
   CheeseCountdownPrivate* priv = CHEESE_COUNTDOWN_GET_PRIVATE (countdown);
 
-  /* create/load svg-icon */
-  priv->pSurface = create_surface_from_svg (PACKAGE_DATADIR "/pixmaps/camera-icon.svg");
   priv->iState = STATE_OFF;
   priv->picture_callback = NULL;
   priv->hide_callback = NULL;
 
   g_signal_connect (G_OBJECT (countdown), "expose-event",
-        G_CALLBACK (on_expose), NULL);
+                    G_CALLBACK (on_expose), NULL);
+  g_signal_connect (G_OBJECT (countdown), "style-set",
+                    G_CALLBACK (on_style_set_cb), countdown);
 
   g_timeout_add (100, redraw_handler, (gpointer) countdown);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]