Bug 2509 - Split gradients
Status: CLOSED FIXED
Alias: None
Product: Openbox
Classification: Unclassified
Component: general
Version: 3.3-rc2
Hardware: PC FreeBSD
: P2 enhancement
Assignee: Mikachu
QA Contact:
URL:
Depends on:
Blocks: 2582
 
Reported: 2005-11-26 22:08 EST by Brandon Cash
Modified: 2007-05-16 15:52:43 EDT
0 users

See Also:


Attachments
A patch to add the new gradient. (3.66 KB, patch)
2005-11-26 22:10 EST, Brandon Cash
Proposed final version (3.57 KB, patch)
2006-02-15 06:26 EST, Brandon Cash

Description Brandon Cash 2005-11-26 22:08:59 EST
I've written a patch that adds a new type of gradient, which I'll call a split gradient (and RR_SURFACE_SPLIT).  It's basically a vertical gradient, but is drawn halfway through the height, and only has three pixels of gradient to it.  It's a look that is used a lot in OS X and related themes.
Comment 1 Brandon Cash 2005-11-26 22:10:01 EST
Created attachment 815 [details]
A patch to add the new gradient.
Comment 2 Brandon Cash 2005-11-26 22:30:36 EST
Comment on attachment 815 [details]
A patch to add the new gradient.

diff -pud ../openbox-3.3-rc2/render/gradient.c render/gradient.c
--- ../openbox-3.3-rc2/render/gradient.c	Tue Oct 14 22:59:35 2003
+++ render/gradient.c	Sat Nov 26 20:58:09 2005
@@ -24,6 +24,7 @@
 
 static void highlight(RrPixel32 *x, RrPixel32 *y, gboolean raised);
 static void gradient_solid(RrAppearance *l, gint w, gint h);
+static void gradient_split(RrSurface *sf, gint w, gint h);
 static void gradient_vertical(RrSurface *sf, gint w, gint h);
 static void gradient_horizontal(RrSurface *sf, gint w, gint h);
 static void gradient_diagonal(RrSurface *sf, gint w, gint h);
@@ -41,6 +42,9 @@ void RrRender(RrAppearance *a, gint w, g
     case RR_SURFACE_SOLID:
         gradient_solid(a, w, h);
         break;
+    case RR_SURFACE_SPLIT:
+        gradient_split(&a->surface, w, h);
+        break;
     case RR_SURFACE_VERTICAL:
         gradient_vertical(&a->surface, w, h);
         break;
@@ -60,7 +64,7 @@ void RrRender(RrAppearance *a, gint w, g
         g_assert_not_reached(); /* unhandled gradient */
         return;
     }
-  
+    
     if (a->surface.interlaced) {
         gint i;
         RrPixel32 *p;
@@ -76,7 +80,7 @@ void RrRender(RrAppearance *a, gint w, g
             for (x = 0; x < w; ++x, ++p)
                 *p = current;
     }
-
+  
     if (a->surface.relief == RR_RELIEF_FLAT && a->surface.border) {
         r = a->surface.border_color->r;
         g = a->surface.border_color->g;
@@ -199,13 +203,6 @@ static void gradient_solid(RrAppearance 
     XFillRectangle(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->primary),
                    0, 0, w, h);
 
-    if (sp->interlaced) {
-        for (i = 0; i < h; i += 2)
-            XDrawLine(RrDisplay(l->inst), l->pixmap,
-                      RrColorGC(sp->interlace_color),
-                      0, i, w, i);
-    }
-
     switch (sp->relief) {
     case RR_RELIEF_RAISED:
         if (!sp->bevel_dark)
@@ -359,6 +356,29 @@ static void gradient_solid(RrAppearance 
     }                                                     \
 }
 
+static void gradient_split(RrSurface *sf, gint w, gint h)
+{
+    gint x, y, pos;
+    RrPixel32 *data = sf->pixel_data;
+    RrPixel32 current;
+
+    VARS(y);
+    SETUP(y, sf->primary, sf->secondary, 3);
+
+    for (y = h - 1; y > 0; --y) {  /* 0 -> h-1 */
+        current = COLOR(y);
+        for (x = w - 1; x >= 0; --x)  /* 0 -> w */
+            *(data++) = current;
+
+        pos = h / 2;
+        if (y == pos - 1 || y == pos || y == pos + 1)
+            NEXT(y);
+    }
+    current = COLOR(y);
+    for (x = w - 1; x >= 0; --x)  /* 0 -> w */
+        *(data++) = current;
+}
+
 static void gradient_horizontal(RrSurface *sf, gint w, gint h)
 {
     gint x, y;
@@ -567,4 +587,3 @@ static void gradient_pyramid(RrSurface *
     *(end-x) = current;
     *(end-(inw-x)) = current;
 }
-
diff -pud ../openbox-3.3-rc2/render/render.h render/render.h
--- ../openbox-3.3-rc2/render/render.h	Fri Jul 15 09:39:31 2005
+++ render/render.h	Sat Nov 26 01:01:35 2005
@@ -61,6 +61,7 @@ typedef enum {
     RR_SURFACE_NONE,
     RR_SURFACE_PARENTREL,
     RR_SURFACE_SOLID,
+    RR_SURFACE_SPLIT,
     RR_SURFACE_HORIZONTAL,
     RR_SURFACE_VERTICAL,
     RR_SURFACE_DIAGONAL,
diff -pud ../openbox-3.3-rc2/render/theme.c render/theme.c
--- ../openbox-3.3-rc2/render/theme.c	Thu Jul 14 15:41:24 2005
+++ render/theme.c	Sat Nov 26 01:22:59 2005
@@ -1200,6 +1200,8 @@ static void parse_appearance(gchar *tex,
                 *grad = RR_SURFACE_HORIZONTAL;
             else if (strstr(tex, "vertical") != NULL)
                 *grad = RR_SURFACE_VERTICAL;
+            else if (strstr(tex, "split") != NULL)
+                *grad = RR_SURFACE_SPLIT;
             else
                 *grad = RR_SURFACE_DIAGONAL;
         } else {
Comment 3 David Barr 2005-11-29 16:57:23 EST
I think this is a good idea, and i'd like to explain why

firstly, it is only a minor change, it doesn't break anything, it only modifies a feature, so it is still 'minimalist' and does not get in the way of defaults or whathaveyou.

secondly, i think it give a kind of 'glossy' effect that many themes are going for these days; clearlooks and tango are 2 and i think the oxygen iconset is also rather glossy, this would help openbox 'fit' in other desktop frameworks

thirdly, it looks cool

forthly, it is a new feature that people can gawk at for the next release, bit of PR and all that?

Comment 4 Brandon Cash 2006-02-15 06:26:27 EST
Created attachment 836 [details]
Proposed final version

After ping-ponging back and forth between mulberry and I, this seems to be the version that has stuck.  It is more rounded than the original version, by calculating darker and lighter shades of the two colors (reused code from hilight()).
Comment 5 Mikachu 2006-06-14 15:48:08 EDT
^_*