TD X-Window numero 2: display.c


/*****************************************************************************\
*                                                                             *
*             mini-afficheur de graphes                           *
*                                                                             *
\*****************************************************************************/

#include "graphe.h"
#include <X11/Xlib.h>

/*****************************************************************************\
*              FixGraphLabelDimensions                            *
\*****************************************************************************/

#define MARGIN 2

/* FixGraphLabelDimensions
 * prend un graphe, une fonte, et parcourt tous les noeuds du graphe pour
 * actualiser la taille des boites de facon a contenir le nom de chaque noeud
 */

void
FixGraphLabelDimensions(dpy, graph, font)
    Display *dpy;
    Graph graph;
    Font font;
{    
    int             direction, font_ascent, font_descent;
    XCharStruct     overall;
                                        /* get font info from server */
    XFontStruct *font_info;
    Node node;
    
    font_info = XQueryFont(dpy, font);
    for (node = graph->nodes; node; node = node->next) {
                                        /* get label sizes */
        XTextExtents(font_info, node->label, strlen(node->label),
                          &direction, &font_ascent, &font_descent,
                          &overall);
                                        /* compute offsets & sizes */
        node->baseline_x = MARGIN + 1;
        node->baseline_y = overall.ascent + MARGIN + 1;
        node->width = overall.width + 2*MARGIN + 2;
        node->height = overall.ascent + overall.descent + 2*MARGIN + 2;
    }
    XFreeFontInfo(0, font_info, 1);
}

/* affiche un graph */
void
DisplayGraph(graph, dpy, window, draw_gc, fill_gc)
    Graph graph;
    Display *dpy;
    Window window;
    GC draw_gc;
    GC fill_gc;
{
/***************   CODE A ECRIRE *******************/
}

/* affiche une liste de nodes */
DisplayNodes(nodes, dpy, window, draw_gc, fill_gc)
    Node nodes;
    Display *dpy;
    Window window;
    GC draw_gc;
    GC fill_gc;
{
    while (nodes) {
    DisplayNode(nodes, dpy, window, draw_gc, fill_gc);
    nodes = nodes->next;
    }
}

/* affiche un node */
DisplayNode(node, dpy, window, draw_gc, fill_gc)
    Node node;
    Display *dpy;
    Window window;
    GC draw_gc;
    GC fill_gc;
{
/***************   CODE A ECRIRE *******************/
}

/* affiche une liste de edges */
DisplayEdges(edges, dpy, window, gc)
    Edge edges;
    Display *dpy;
    Window window;
    GC gc;
{
    while (edges) {
    DisplayEdge(edges, dpy, window, gc);
    edges = edges->next;
    }
}

/* affiche une edge */
DisplayEdge(edge, dpy, window, gc)
    Edge edge;
    Display *dpy;
    Window window;
    GC gc;
{
/***************   CODE A ECRIRE *******************/
}

/* retourne le premier node dont la bounding box contient le point (x,y) */
Node
FindNode(graph, x, y)
    Graph graph;
    int x;
    int y;
{
/***************   CODE A ECRIRE *******************/
}



michel.buffa@essi.fr