]> Dogcows Code - chaz/tint2/blobdiff - src/util/area.h
cleanup code
[chaz/tint2] / src / util / area.h
index 5be636f524362a2c679d25c134d83d023b40d48d..7270419d9ee6b20bb63c6a3d2ab3d0351f4c221a 100644 (file)
 /**************************************************************************
 * Copyright (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
-* 
+*
 * base class for all graphical objects (panel, taskbar, task, systray, clock, ...).
-* Area is at the begining of each graphical object so &object == &area.
-* 
+* Area is at the begining of each object (&object == &area).
+*
 * Area manage the background and border drawing, size and padding.
-* Area manage also the tree of visible objects
+* Each Area has one Pixmap (pix).
+*
+* Area manage the tree of all objects. Parent object drawn before child object.
 *   panel -> taskbars -> tasks
 *         -> systray -> icons
 *         -> clock
-* 
-* un objet comprend les actions:
-* 1) redraw(obj)
-*    force l'indicateur 'redraw' sur l'objet
-*    parcoure la liste des sous objets => redraw(obj)
-* 2) draw(obj)
-*    dessine le background, dessine le contenu dans pmap
-*    parcoure la liste des sous objets => draw(obj)
-*    le pmap de l'objet se base sur le pmap de l'objet parent (cumul des couches)
-* 3) draw_background(obj)
-*    dessine le fond dans pmap
-* 4) draw_foreground(obj) = 0 : fonction virtuelle à redéfinir
-*    dessine le contenu dans pmap
-*    si l'objet n'a pas de contenu, la fonction est nulle
-* 5) resize_width(obj, width) = 0 : fonction virtuelle à redéfinir
-*    recalcule la largeur de l'objet (car la hauteur est fixe)
-*    - taille systray calculée à partir de la liste des icones
-*    - taille clock calculée à partir de l'heure
-*    - taille d'une tache calculée à partir de la taskbar (ajout, suppression, taille)
-*    - taille d'une taskbar calculée à partir de la taille du panel et des autres objets
-* 6) voir refresh(obj)
-* 
-* Implémentation :
-* - l'objet est en fait une zone (area). 
-*   l'imbrication des sous objet doit permettre de gérer le layout.
-* - les taches ont 2 objets : l'un pour la tache inactive et l'autre pour la tache active
-*   draw(obj) est appellé sur le premier objet automatiquement 
-*   et draw_foreground(obj) lance l'affichage du 2 ieme objet
-*   ainsi la taskbar gère bien une liste d'objets mais draw(obj) dessine les 2 objets
-* - les fonctions de refresh et de draw sont totalement dissociées
-* 
-* ----------------------------------------------------
-* A évaluer :
-* 1. voir comment définir et gérer le panel_layout avec les objets
-*    => peut on s'affranchir des données spécifiques à chaque objet ?
-*    => comment gérer l'affichage du layout ?
-*    => comment configurer le layout ?
-*    => voir le cumul des couches et l'imbrication entre objet et parent ?
-* 2. voir la fonction de refresh des objets ??
-*    surtout le refresh des taches qui est différent pour la tache active
-* 
-* 3. tester l'implémentation et évaluer les autres abstractions possibles ?
-* 
-* 4. comment gérer le groupage des taches
-* 
-* voir resize_taskbar(), resize_clock() et resize_tasks()
-* voir les taches actives et inactives ?? une seule tache est active !
-* variable widthChanged ou bien emission d'un signal ???
 *
-* 6) config(obj) configure un objet (définie les positions verticales)
+* draw_foreground(obj) and resize(obj) are virtual function.
 *
 **************************************************************************/
 
 #ifndef AREA_H
 #define AREA_H
 
+#include <glib.h>
 #include <X11/Xlib.h>
-#include <pango/pangocairo.h>
-
-#include "common.h"
-
+#include <cairo.h>
+#include <cairo-xlib.h>
 
 
 typedef struct
 {
-   double color[3];
-   double alpha;
-   int width;
-   int rounded;
+       double color[3];
+       double alpha;
+       int width;
+       int rounded;
 } Border;
 
 
 typedef struct
 {
-   double color[3];
-   double alpha;
+       double color[3];
+       double alpha;
 } Color;
 
+typedef struct
+{
+       Color back;
+       Border border;
+} Background;
+
+
+// way to calculate the size
+// SIZE_BY_LAYOUT objects : taskbar and task
+// SIZE_BY_CONTENT objects : clock, battery, launcher, systray
+enum { SIZE_BY_LAYOUT, SIZE_BY_CONTENT };
 
 typedef struct {
-   // need redraw Pixmap
-   int redraw;
-   
-   int paddingx, paddingy;   
-   int width, height;
-   Pixmap pmap;
-   
-   Color back;
-   Border border;
-   
-   // absolute coordinate in panel
-   int posx, posy;
-   // parent Area
-   void *parent;
-
-   // pointer to function
-   // draw_foreground : return 1 if width changed, return O otherwise
-   int (*draw_foreground)(void *obj, cairo_t *c);
-   void (*add_child)(void *obj);
-   int (*remove_child)(void *obj);
-   
-   // list of child : Area object
-   GSList *list;
+       // coordinate relative to panel window
+       int posx, posy;
+       // width and height including border
+       int width, height;
+       Pixmap pix;
+       Background *bg;
+
+       // list of child : Area object
+       GSList *list;
+
+       // object visible on screen. 
+       // An object (like systray) could be enabled but hidden (because no tray icon).
+       int on_screen;
+       // way to calculate the size (SIZE_BY_CONTENT or SIZE_BY_LAYOUT)
+       int size_mode;
+       // need to calculate position and width
+       int resize;
+       // need redraw Pixmap
+       int redraw;
+       // paddingxlr = horizontal padding left/right
+       // paddingx = horizontal padding between childs
+       int paddingxlr, paddingx, paddingy;
+       // parent Area
+       void *parent;
+       // panel
+       void *panel;
+
+       // each object can overwrite following function
+       void (*_draw_foreground)(void *obj, cairo_t *c);
+       // update area's content and update size (width/heith). 
+       // return '1' if size changed, '0' otherwise.
+       int (*_resize)(void *obj);
+       void (*_add_child)(void *obj);
+       int (*_remove_child)(void *obj);
+       const char* (*_get_tooltip_text)(void *obj);
 } Area;
 
+// on startup, initialize fixed pos/size
+void init_rendering(void *obj, int pos);
 
-// redraw an area and childs
-void redraw (Area *a);
-
+void rendering(void *obj);
+void size_by_content (Area *a);
+void size_by_layout (Area *a, int pos, int level);
 // draw background and foreground
-// return 1 if width changed, return O otherwise
-int  draw (Area *a);
+void refresh (Area *a);
+// generic resize for SIZE_BY_LAYOUT objects
+int resize_by_layout(void *obj);
+
+// set 'redraw' on an area and childs
+void set_redraw (Area *a);
+
+// hide/unhide area
+void hide(Area *a);
+void show(Area *a);
+
+// draw pixmap
+void draw (Area *a);
 void draw_background (Area *a, cairo_t *c);
 
 void remove_area (Area *a);
 void add_area (Area *a);
 void free_area (Area *a);
 
+// draw rounded rectangle
+void draw_rect(cairo_t *c, double x, double y, double w, double h, double r);
+
+// clear pixmap with transparent color
+void clear_pixmap(Pixmap p, int x, int y, int w, int h);
 #endif
 
This page took 0.020956 seconds and 4 git commands to generate.