]> Dogcows Code - chaz/tint2/blobdiff - src/util/area.c
Remove useless Xrandr.h include.
[chaz/tint2] / src / util / area.c
index 91a6a763ed17c61d98e004853aec84cfa795e53b..61919f9ae81e301f5500b932bdeb86a7a90b9f14 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <glib.h>
+#include <pango/pangocairo.h>
 
-#include "window.h"
-#include "server.h"
 #include "area.h"
+#include "server.h"
+#include "panel.h"
 
-
+// 1) resize child
+// 2) resize parent
+// 3) redraw parent
+// 4) redraw child
 void refresh (Area *a)
 {
+       // don't draw and resize hide objects
+       if (!a->on_screen) return;
+
+       size(a);
+
+       // don't draw transparent objects (without foreground and without background)
+
    if (a->redraw) {
-      //printf("draw pix\n");
+          a->redraw = 0;
+          //printf("draw area posx %d, width %d\n", a->posx, a->width);
       draw(a, 0);
       if (a->use_active)
              draw(a, 1);
-          a->redraw = 0;
-      //printf("end draw pix\n");
        }
 
-   Pixmap *pmap = (a->is_active == 0) ? (&a->pix.pmap) : (&a->pix_active.pmap);
-
        // draw current Area
-   XCopyArea (server.dsp, *pmap, server.pmap, server.gc, 0, 0, a->width, a->height, a->posx, a->posy);
+   Pixmap *pmap = (a->is_active == 0) ? (&a->pix.pmap) : (&a->pix_active.pmap);
+       if (*pmap == 0) printf("empty area posx %d, width %d\n", a->posx, a->width);
+   XCopyArea (server.dsp, *pmap, ((Panel *)a->panel)->temp_pmap, server.gc, 0, 0, a->width, a->height, a->posx, a->posy);
 
    // and then refresh child object
-   GSList *l = a->list;
-   for (; l ; l = l->next)
+       GSList *l;
+   for (l = a->list; l ; l = l->next)
       refresh(l->data);
 }
 
 
+void size (Area *a)
+{
+       GSList *l;
+
+       if (a->resize) {
+      a->resize = 0;
+               for (l = a->list; l ; l = l->next)
+                       size(l->data);
+
+       // resize can generate a redraw
+          if (a->_resize) {
+       a->_resize(a);
+               }
+       }
+}
+
+
 void set_redraw (Area *a)
 {
    a->redraw = 1;
@@ -67,12 +93,11 @@ void draw (Area *a, int active)
 {
    Pixmap *pmap = (active == 0) ? (&a->pix.pmap) : (&a->pix_active.pmap);
 
-   //printf("begin draw area\n");
    if (*pmap) XFreePixmap (server.dsp, *pmap);
-   *pmap = server_create_pixmap (a->width, a->height);
+   *pmap = XCreatePixmap (server.dsp, server.root_win, a->width, a->height, server.depth);
 
    // add layer of root pixmap
-   XCopyArea (server.dsp, server.pmap, *pmap, server.gc, a->posx, a->posy, a->width, a->height, 0, 0);
+   XCopyArea (server.dsp, ((Panel *)a->panel)->temp_pmap, *pmap, server.gc, a->posx, a->posy, a->width, a->height, 0, 0);
 
    cairo_surface_t *cs;
    cairo_t *c;
@@ -82,8 +107,8 @@ void draw (Area *a, int active)
 
    draw_background (a, c, active);
 
-   if (a->draw_foreground)
-      a->draw_foreground(a, c, active);
+   if (a->_draw_foreground)
+      a->_draw_foreground(a, c, active);
 
    cairo_destroy (c);
    cairo_surface_destroy (cs);
@@ -136,7 +161,6 @@ void draw_background (Area *a, cairo_t *c, int active)
       x1 = X1 * ((double)a->height / 100);
       y0 = Y0 * ((double)a->width / 100);
       y1 = Y1 * ((double)a->width / 100);
-      printf("repère (%d, %d)  points (%lf, %lf) (%lf, %lf)\n", a->width, a->height, x0, y0, x1, y1);
 
       cairo_pattern_t *linpat;
       linpat = cairo_pattern_create_linear (x0, y0, x1, y1);
@@ -154,9 +178,8 @@ void draw_background (Area *a, cairo_t *c, int active)
 
 void remove_area (Area *a)
 {
-   Area *parent;
+   Area *parent = (Area*)a->parent;
 
-   parent = (Area*)a->parent;
    parent->list = g_slist_remove(parent->list, a);
    set_redraw (parent);
 
@@ -165,9 +188,8 @@ void remove_area (Area *a)
 
 void add_area (Area *a)
 {
-   Area *parent;
+   Area *parent = (Area*)a->parent;
 
-   parent = (Area*)a->parent;
    parent->list = g_slist_remove(parent->list, a);
    set_redraw (parent);
 
@@ -184,5 +206,34 @@ void free_area (Area *a)
       g_slist_free(a->list);
       a->list = 0;
    }
+   if (a->pix.pmap) {
+       XFreePixmap (server.dsp, a->pix.pmap);
+       a->pix.pmap = 0;
+       }
+   if (a->pix_active.pmap) {
+       XFreePixmap (server.dsp, a->pix_active.pmap);
+       a->pix_active.pmap = 0;
+       }
 }
 
+
+void draw_rect(cairo_t *c, double x, double y, double w, double h, double r)
+{
+   if (r > 0.0) {
+      double c1 = 0.55228475 * r;
+
+      cairo_move_to(c, x+r, y);
+      cairo_rel_line_to(c, w-2*r, 0);
+      cairo_rel_curve_to(c, c1, 0.0, r, c1, r, r);
+      cairo_rel_line_to(c, 0, h-2*r);
+      cairo_rel_curve_to(c, 0.0, c1, c1-r, r, -r, r);
+      cairo_rel_line_to (c, -w +2*r, 0);
+      cairo_rel_curve_to (c, -c1, 0, -r, -c1, -r, -r);
+      cairo_rel_line_to (c, 0, -h + 2 * r);
+      cairo_rel_curve_to (c, 0, -c1, r - c1, -r, r, -r);
+   }
+   else
+      cairo_rectangle(c, x, y, w, h);
+}
+
+
This page took 0.023978 seconds and 4 git commands to generate.