kwo pushed a commit to branch master.

http://git.enlightenment.org/e16/e16.git/commit/?id=d1b7b142cf6a43cc3b1e3188d33126b8e39b3b99

commit d1b7b142cf6a43cc3b1e3188d33126b8e39b3b99
Author: Kim Woelders <k...@woelders.dk>
Date:   Sat Dec 28 22:55:44 2013 +0100

    Wrap XDraw/FillRectangle.
---
 src/hiwin.c | 13 +++----------
 src/pager.c | 18 +++---------------
 src/x.c     | 32 ++++++++++++++++++++++++++++++++
 src/xwin.h  |  3 +++
 4 files changed, 41 insertions(+), 25 deletions(-)

diff --git a/src/hiwin.c b/src/hiwin.c
index 8bb8bfc..e649b79 100644
--- a/src/hiwin.c
+++ b/src/hiwin.c
@@ -41,7 +41,6 @@ struct _hiwin {
    void                (*evcb) (Win win, XEvent * ev, void *data);
    void               *data;
    char                animate;
-   GC                  gc;
    EImage             *im;
 };
 
@@ -167,18 +166,15 @@ static const HiwinRender HiwinRenderIclass = {
 };
 
 static void
-HiwinRenderPixmapInit(Hiwin * phi)
+HiwinRenderPixmapInit(Hiwin * phi __UNUSED__)
 {
-   phi->gc = EXCreateGC(EoGetXwin(phi), 0, NULL);
 }
 
 static void
 HiwinRenderPixmapDrawX(Hiwin * phi, Drawable draw)
 {
-   XSetForeground(disp, phi->gc, Dpy.pixel_black);
-   XFillRectangle(disp, draw, phi->gc, 0, 0, EoGetW(phi), EoGetH(phi));
-   XSetForeground(disp, phi->gc, Dpy.pixel_white);
-   XFillRectangle(disp, draw, phi->gc, 1, 1, EoGetW(phi) - 2, EoGetH(phi) - 2);
+   EXPaintRectangle(draw, 0, 0, EoGetW(phi), EoGetH(phi),
+                   Dpy.pixel_black, Dpy.pixel_white);
 }
 
 static void
@@ -199,9 +195,6 @@ HiwinRenderPixmapFini(Hiwin * phi, int shown)
        HiwinRenderPixmapDrawX(phi, pmap);
        EClearWindow(EoGetWin(phi));
      }
-
-   EXFreeGC(phi->gc);
-   phi->gc = NULL;
 }
 
 static const HiwinRender HiwinRenderPixmap = {
diff --git a/src/pager.c b/src/pager.c
index 264e1dc..d071141 100644
--- a/src/pager.c
+++ b/src/pager.c
@@ -463,10 +463,8 @@ doPagerUpdate(Pager * p)
          }
        else
          {
-            XSetForeground(disp, gc, Dpy.pixel_black);
-            XDrawRectangle(disp, pmap, gc, wx - 1, wy - 1, ww + 1, wh + 1);
-            XSetForeground(disp, gc, Dpy.pixel_white);
-            XFillRectangle(disp, pmap, gc, wx, wy, ww, wh);
+            EXPaintRectangle(pmap, wx, wy, ww, wh,
+                             Dpy.pixel_black, Dpy.pixel_white);
          }
      }
 #if USE_COMPOSITE
@@ -560,7 +558,6 @@ static void
 PagerUpdateBg(Pager * p)
 {
    Pixmap              pmap;
-   GC                  gc;
    Background         *bg;
    ImageClass         *ic;
    int                 pager_mode = PagersGetMode();
@@ -620,16 +617,7 @@ PagerUpdateBg(Pager * p)
        return;
      }
 
-   gc = EXCreateGC(pmap, 0, NULL);
-   if (!gc)
-      return;
-
-   XSetForeground(disp, gc, Dpy.pixel_black);
-   XDrawRectangle(disp, pmap, gc, 0, 0, p->dw, p->dh);
-   XSetForeground(disp, gc, Dpy.pixel_white);
-   XFillRectangle(disp, pmap, gc, 1, 1, p->dw - 2, p->dh - 2);
-
-   EXFreeGC(gc);
+   EXPaintRectangle(pmap, 0, 0, p->dw, p->dh, Dpy.pixel_black, 
Dpy.pixel_white);
 }
 
 static void
diff --git a/src/x.c b/src/x.c
index 922bf23..feaae5e 100644
--- a/src/x.c
+++ b/src/x.c
@@ -1702,6 +1702,38 @@ EXFillAreaSolid(Drawable dst, int x, int y, unsigned int 
w, unsigned int h,
    EXFreeGC(gc);
 }
 
+static void
+_EXDrawRectangle(Drawable dst, GC gc, int x, int y,
+                unsigned int w, unsigned int h, unsigned int pixel)
+{
+   XSetForeground(disp, gc, pixel);
+   XDrawRectangle(disp, dst, gc, x, y, w, h);
+}
+
+static void
+_EXFillRectangle(Drawable dst, GC gc, int x, int y,
+                unsigned int w, unsigned int h, unsigned int pixel)
+{
+   XSetForeground(disp, gc, pixel);
+   XFillRectangle(disp, dst, gc, x, y, w, h);
+}
+
+void
+EXPaintRectangle(Drawable dst, int x, int y,
+                unsigned int w, unsigned int h,
+                unsigned int fg, unsigned int bg)
+{
+   GC                  gc;
+
+   if (w == 0 || h == 0)
+      return;
+   gc = EXCreateGC(dst, 0, NULL);
+   _EXDrawRectangle(dst, gc, x, y, w - 1, h - 1, fg);
+   if (w > 2 && h > 2)
+      _EXFillRectangle(dst, gc, x + 1, y + 1, w - 2, h - 2, bg);
+   EXFreeGC(gc);
+}
+
 GC
 EXCreateGC(Drawable draw, unsigned int mask, XGCValues * val)
 {
diff --git a/src/xwin.h b/src/xwin.h
index a368286..adf6143 100644
--- a/src/xwin.h
+++ b/src/xwin.h
@@ -268,6 +268,9 @@ void                EXCopyAreaTiled(Drawable src, Pixmap 
mask, Drawable dst,
 void                EXFillAreaSolid(Drawable dst, int x, int y,
                                    unsigned int w, unsigned int h,
                                    unsigned int pixel);
+void                EXPaintRectangle(Drawable dst, int x, int y,
+                                    unsigned int w, unsigned int h,
+                                    unsigned int fg, unsigned int bg);
 
 void                EXWarpPointer(Window xwin, int x, int y);
 int                 EXQueryPointer(Window xwin, int *px, int *py,

-- 


Reply via email to