Item drawing completed, not tested though
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Sun, 4 Jan 2004 21:57:32 +0000 (21:57 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Sun, 4 Jan 2004 21:57:32 +0000 (21:57 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@353 04897980-b3bd-0310-b5e0-8ef037075253

ltt/branches/poly/lttv/modules/guiControlFlow/Draw_Item.c
ltt/branches/poly/lttv/modules/guiControlFlow/Draw_Item.h
ltt/branches/poly/lttv/modules/guiControlFlow/Makefile.am

index 6a1e25bd4a8337662e1489fd84fe4c52a309f461..c02725be7807ffa01086b95803e85b104ee16ce4 100644 (file)
@@ -74,6 +74,8 @@
  */
 
 #include <glib.h>
+#include <gtk/gtk.h>
+#include <gdk/gdk.h>
 #include <lttv/hook.h>
 #include <lttv/attribute.h>
 #include <lttv/iattribute.h>
 #include <lttv/processTrace.h>
 #include <lttv/state.h>
 
+#include "Draw_Item.h"
 /* The DrawContext keeps information about the current drawing position and
  * the previous one, so we can use both to draw lines.
  *
  * over : position for drawing over the middle line.
  * middle : middle line position.
  * under : position for drawing under the middle line.
+ *
+ * the modify_* are used to take into account that we should go forward
+ * when we draw a text, an arc or an icon, while it's unneeded when we
+ * draw a line or background.
  */
 struct _DrawContext {
        GdkDrawable     *drawable;
@@ -100,6 +108,10 @@ struct _DrawInfo {
        ItemInfo        *over;
        ItemInfo        *middle;
        ItemInfo        *under;
+       
+       ItemInfo        *modify_over;
+       ItemInfo        *modify_middle;
+       ItemInfo        *modify_under;
 };
 
 /* LttvExecutionState is accessible through the LttvTracefileState. Is has
@@ -145,11 +157,7 @@ struct _DrawOperation {
  * is in fact a rectangle, does not hide the line.
  */
 
-typedef enum _DrawableItems {
-       ITEM_TEXT, ITEM_ICON, ITEM_LINE, ITEM_POINT, ITEM_BACKGROUND
-} DrawableItems;
-
-static gchar * Items_Priorities = {
+static int Items_Priorities[] = {
        50,     /* ITEM_TEXT */
        40,     /* ITEM_ICON */
        20,     /* ITEM_LINE */
@@ -157,10 +165,6 @@ static gchar * Items_Priorities = {
        10      /* ITEM_BACKGROUND */
 };
 
-typedef enum _RelPos {
-       OVER, MIDDLE, UNDER
-} RelPos;
-
 /*
  * Here are the different structures describing each item type that can be
  * drawn. They contain the information necessary to draw the item : not the
@@ -203,14 +207,60 @@ struct _PropertiesBG {
 };
 
 
-
-
-
 /* Drawing hook functions */
 gboolean draw_text( void *hook_data, void *call_data)
 {
        PropertiesText *Properties = (PropertiesText*)hook_data;
        DrawContext *Draw_Context = (DrawContext*)call_data;
+
+       PangoContext *context;
+       PangoLayout *layout;
+       PangoFontDescription *FontDesc;// = pango_font_description_new();
+       gint Font_Size;
+       PangoRectangle ink_rect;
+               
+       gdk_gc_set_foreground(Draw_Context->gc, Properties->foreground);
+       gdk_gc_set_background(Draw_Context->gc, Properties->background);
+
+       layout = gtk_widget_create_pango_layout(GTK_WIDGET(Draw_Context->drawable), NULL);
+       context = pango_layout_get_context(layout);
+       FontDesc = pango_context_get_font_description(context);
+       Font_Size = pango_font_description_get_size(FontDesc);
+       pango_font_description_set_size(FontDesc, Properties->size*PANGO_SCALE);
+       
+       
+       pango_layout_set_text(layout, Properties->Text, -1);
+       pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
+       switch(Properties->position) {
+               case OVER:
+                                                       gdk_draw_layout(Draw_Context->drawable, Draw_Context->gc,
+                                                               Draw_Context->Current->modify_over->x,
+                                                               Draw_Context->Current->modify_over->y,
+                                                               layout);
+                                                       Draw_Context->Current->modify_over->x += ink_rect.width;
+
+                       break;
+               case MIDDLE:
+                                                       gdk_draw_layout(Draw_Context->drawable, Draw_Context->gc,
+                                                               Draw_Context->Current->modify_middle->x,
+                                                               Draw_Context->Current->modify_middle->y,
+                                                               layout);
+                                                       Draw_Context->Current->modify_middle->x += ink_rect.width;
+                       break;
+               case UNDER:
+                                                       gdk_draw_layout(Draw_Context->drawable, Draw_Context->gc,
+                                                               Draw_Context->Current->modify_under->x,
+                                                               Draw_Context->Current->modify_under->y,
+                                                               layout);
+                                                       Draw_Context->Current->modify_under->x += ink_rect.width;
+                       break;
+       }
+
+
+       pango_font_description_set_size(FontDesc, Font_Size);
+       g_free(layout);
+       
+       return 0;
 }
 
 gboolean draw_icon( void *hook_data, void *call_data)
@@ -218,6 +268,57 @@ gboolean draw_icon( void *hook_data, void *call_data)
        PropertiesIcon *Properties = (PropertiesIcon*)hook_data;
        DrawContext *Draw_Context = (DrawContext*)call_data;
 
+       GdkBitmap *mask = g_new(GdkBitmap, 1);
+       GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1);
+       GdkGC *gc = gdk_gc_new(Draw_Context->drawable);
+       gdk_gc_copy(gc, Draw_Context->gc);
+
+       icon_pixmap = gdk_pixmap_create_from_xpm(Draw_Context->drawable, &mask, NULL,
+                                                                                                                                                                               Properties->icon_name);
+
+       gdk_gc_set_clip_mask(gc, mask);
+
+       switch(Properties->position) {
+               case OVER:
+                                                       gdk_draw_drawable(Draw_Context->drawable, 
+                                                                       gc,
+                                                                       icon_pixmap,
+                                                                       0, 0,
+                                                                       Draw_Context->Current->modify_over->x,
+                                                                       Draw_Context->Current->modify_over->y,
+                                                                       Properties->width, Properties->height);
+
+                                                       Draw_Context->Current->modify_over->x += Properties->width;
+
+                       break;
+               case MIDDLE:
+                                                       gdk_draw_drawable(Draw_Context->drawable, 
+                                                                       gc,
+                                                                       icon_pixmap,
+                                                                       0, 0,
+                                                                       Draw_Context->Current->modify_middle->x,
+                                                                       Draw_Context->Current->modify_middle->y,
+                                                                       Properties->width, Properties->height);
+
+
+                                                       Draw_Context->Current->modify_middle->x += Properties->width;
+                       break;
+               case UNDER:
+                                                       gdk_draw_drawable(Draw_Context->drawable, 
+                                                                       gc,
+                                                                       icon_pixmap,
+                                                                       0, 0,
+                                                                       Draw_Context->Current->modify_under->x,
+                                                                       Draw_Context->Current->modify_under->y,
+                                                                       Properties->width, Properties->height);
+
+                                                       Draw_Context->Current->modify_under->x += Properties->width;
+                       break;
+       }
+
+       g_free(gc);
+       
+       return 0;
 }
 
 gboolean draw_line( void *hook_data, void *call_data)
@@ -225,6 +326,45 @@ gboolean draw_line( void *hook_data, void *call_data)
        PropertiesLine *Properties = (PropertiesLine*)hook_data;
        DrawContext *Draw_Context = (DrawContext*)call_data;
 
+       gdk_gc_set_foreground(Draw_Context->gc, Properties->color);
+       gdk_gc_set_line_attributes(     Draw_Context->gc,
+                                                                                                                       Properties->line_width,
+                                                                                                                       Properties->style,
+                                                                                                                       GDK_CAP_BUTT,
+                                                                                                                       GDK_JOIN_MITER);
+
+       switch(Properties->position) {
+               case OVER:
+                                                       drawing_draw_line(
+                                                               NULL, Draw_Context->drawable,
+                                                               Draw_Context->Previous->over->x,
+                                                               Draw_Context->Previous->over->y,
+                                                               Draw_Context->Current->over->x,
+                                                               Draw_Context->Current->over->y,
+                                                               Draw_Context->gc);
+                       break;
+               case MIDDLE:
+                                                       drawing_draw_line(
+                                                               NULL, Draw_Context->drawable,
+                                                               Draw_Context->Previous->middle->x,
+                                                               Draw_Context->Previous->middle->y,
+                                                               Draw_Context->Current->middle->x,
+                                                               Draw_Context->Current->middle->y,
+                                                               Draw_Context->gc);
+                       break;
+               case UNDER:
+                                                       drawing_draw_line(
+                                                               NULL, Draw_Context->drawable,
+                                                               Draw_Context->Previous->under->x,
+                                                               Draw_Context->Previous->under->y,
+                                                               Draw_Context->Current->under->x,
+                                                               Draw_Context->Current->under->y,
+                                                               Draw_Context->gc);
+
+                       break;
+       }
+
+       return 0;
 }
 
 gboolean draw_arc( void *hook_data, void *call_data)
@@ -232,6 +372,40 @@ gboolean draw_arc( void *hook_data, void *call_data)
        PropertiesArc *Properties = (PropertiesArc*)hook_data;
        DrawContext *Draw_Context = (DrawContext*)call_data;
 
+       gdk_gc_set_foreground(Draw_Context->gc, Properties->color);
+
+       switch(Properties->position) {
+               case OVER:
+                       gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc,
+                                                       Properties->filled,
+                                                       Draw_Context->Current->modify_over->x,
+                                                       Draw_Context->Current->modify_over->y,
+                                                       Properties->size, Properties->size, 0, 360*64);
+                       Draw_Context->Current->modify_over->x += Properties->size;
+               
+                       break;
+               case MIDDLE:
+                       gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc,
+                                                       Properties->filled,
+                                                       Draw_Context->Current->modify_middle->x,
+                                                       Draw_Context->Current->modify_middle->y,
+                                                       Properties->size, Properties->size, 0, 360*64);
+                       Draw_Context->Current->modify_middle->x += Properties->size;
+                       
+                       break;
+               case UNDER:
+                       gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc,
+                                                       Properties->filled,
+                                                       Draw_Context->Current->modify_under->x,
+                                                       Draw_Context->Current->modify_under->y,
+                                                       Properties->size, Properties->size, 0, 360*64);
+                       Draw_Context->Current->modify_under->x += Properties->size;
+       
+                       break;
+       }
+
+       
+       return 0;
 }
 
 gboolean draw_bg( void *hook_data, void *call_data)
@@ -239,6 +413,17 @@ gboolean draw_bg( void *hook_data, void *call_data)
        PropertiesBG *Properties = (PropertiesBG*)hook_data;
        DrawContext *Draw_Context = (DrawContext*)call_data;
 
+       gdk_gc_set_foreground(Draw_Context->gc, Properties->color);
+
+
+       gdk_draw_rectangle(Draw_Context->drawable, Draw_Context->gc,
+                                       TRUE,
+                                       Draw_Context->Previous->over->x,
+                                       Draw_Context->Previous->over->y,
+                                       Draw_Context->Current->over->x - Draw_Context->Previous->over->x,
+                                       Draw_Context->Previous->under->y);
+
+       return 0;
 }
 
 
index 86ecc8d9903199f0b10dda8979b29b4acb47bb27..5e6311fbe512e23fadce6d990f465dbf75ddc4f5 100644 (file)
@@ -14,6 +14,16 @@ typedef struct _PropertiesLine PropertiesLine;
 typedef struct _PropertiesArc PropertiesArc;
 typedef struct _PropertiesBG PropertiesBG;
 
+typedef enum _DrawableItems DrawableItems;
+enum _DrawableItems {
+               ITEM_TEXT, ITEM_ICON, ITEM_LINE, ITEM_POINT, ITEM_BACKGROUND
+};
+
+
+typedef enum _RelPos {
+       OVER, MIDDLE, UNDER
+} RelPos;
+
 
 void draw_item(        GdkDrawable *drawable,
                gint x,
@@ -100,19 +110,19 @@ PropertiesIcon *properties_icon_create(
        gchar           *icon_name,
        gint            width,
        gint            height,
-       RelPos          position),
+       RelPos          position);
 
 PropertiesLine *properties_line_create(
        GdkColor        *color,
        gint            line_width,
        GdkLineStyle    style,
-       RelPos          position),
+       RelPos          position);
 
 PropertiesArc *properties_arc_create(
        GdkColor        *color,
        gint            size,
        gboolean        filled,
-       RelPos          position),
+       RelPos          position);
 
 PropertiesBG *properties_bg_create(
        GdkColor        *color);
index 0298c83d65791fda5dbf098c77d919cf44735233..a8e1f7b75749856c01b5bac1a8b8d8e1f4920a5a 100644 (file)
@@ -14,7 +14,7 @@ libdir = ${lttvplugindir}
 lib_LTLIBRARIES = libguiControlFlow.la
 libguiControlFlow_la_LDFLAGS = -module
 libguiControlFlow_la_SOURCES =         module.c Event_Hooks.c CFV.c Process_List.c\
-                               Drawing.c
+                               Drawing.c Draw_Item.c
 
 noinst_HEADERS =       Event_Hooks.h CFV.h Process_List.h\
-                               Drawing.h
+                               Drawing.h Draw_Item.h
This page took 0.028153 seconds and 4 git commands to generate.