give windows drop shadows in gl
authorDana Jansens <danakj@orodu.net>
Sat, 15 Mar 2008 22:17:11 +0000 (18:17 -0400)
committerDana Jansens <danakj@orodu.net>
Sat, 15 Mar 2008 22:26:07 +0000 (18:26 -0400)
glxrender.c

index 63fa91c..663522e 100644 (file)
@@ -4,7 +4,6 @@
 #include "screen.h"
 #include "window.h"
 #include "display.h"
-#include "glxcompat.h"
 #include "list.h"
 #include <stdio.h>
 #include <string.h>
@@ -32,7 +31,7 @@ typedef struct {
     void (*window_resize)(d_window_t *w);
     void (*window_reshape)(d_window_t *w);
 
-    uint16_t shadowalpha;
+    float shadowalpha;
     int xshadowoff;
     int yshadowoff;
 
@@ -100,7 +99,7 @@ glxrender_init(d_screen_t *sc, int id)
     sc->window_resize = glxrender_window_resize;
     sc->window_reshape = glxrender_window_reshape;
 
-    d->shadowalpha = 0x3333; /* 20% */
+    d->shadowalpha = 0.2f; /* 20% */
     d->xshadowoff = 2;
     d->yshadowoff = 2;
 
@@ -588,14 +587,44 @@ static void
 paint_shadow(d_window_t *w, data_t *d, window_data_t *wd,
              int x, int y, int width, int height, int bwidth)
 {
-/*
-    xcb_render_composite(w->sc->dpy->conn,
-                         XCB_RENDER_PICT_OP_OVER,
-                         wd->shadow_picture,
-                         wd->picture,
-                         d->overlay_buffer,
-                         0, 0, 0, 0,
-                         x+d->xshadowoff, y+d->yshadowoff,
-                         width + bwidth*2, height + bwidth *2);
-*/
+    int xoff = d->xshadowoff;
+    int yoff = d->yshadowoff;
+    float alpha = d->shadowalpha;
+
+    alpha *= window_get_opacity(w);
+    alpha /= 0xffff;
+
+    if (alpha < 0.01) return;
+
+    glEnable(GL_BLEND);
+    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+    /* black shadow */
+    glColor4f(0.0f, 0.0f, 0.0f, alpha);
+
+    if (window_is_argb(w)) {
+        /* shape the shadow to the window's alpha levels */
+        glBindTexture(GL_TEXTURE_2D, wd->texname);
+
+        glBegin(GL_QUADS);
+        glVertex2i(x + xoff, y + yoff);
+        glTexCoord2f(1, 0);
+        glVertex2i(x + width + bwidth + xoff, y + yoff);
+        glTexCoord2f(1, 1);
+        glVertex2i(x + width + bwidth + xoff,
+                   y + height + bwidth + yoff);
+        glTexCoord2f(0, 1);
+        glVertex2i(x + xoff, y + height + bwidth + yoff);
+        glTexCoord2f(0, 0);
+        glEnd();
+
+        glBindTexture(GL_TEXTURE_2D, 0);
+    }
+    else
+        /* draw a solid rectangle */
+        glRecti(x + xoff, y + yoff,
+                x + width + bwidth - 1 + xoff, y + height + bwidth - 1 + yoff);
+
+    glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
+    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+    glDisable(GL_BLEND);
 }