change window name and size
[lttv.git] / ltt / branches / poly / lttv / modules / gui / controlflow / drawitem.c
CommitLineData
ce0214a6 1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19
20
cf6cb7e0 21/******************************************************************************
d66666fe 22 * drawitem.c
cf6cb7e0 23 *
24 * This file contains methods responsible for drawing a generic type of data
25 * in a drawable. Doing this generically will permit user defined drawing
26 * behavior in a later time.
27 *
b782dd11 28 * This file provides an API which is meant to be reusable for all viewers that
29 * need to show information in line, icon, text, background or point form in
30 * a drawable area having time for x axis. The y axis, in the control flow
31 * viewer case, is corresponding to the different processes, but it can be
32 * reused integrally for cpu, and eventually locks, buffers, network
33 * interfaces... What will differ between the viewers is the precise
34 * information which interests us. We may think that the most useful
35 * information for control flow are some specific events, like schedule
36 * change, and processes'states. It may differ for a cpu viewer : the
37 * interesting information could be more the execution mode of each cpu.
38 * This API in meant to make viewer's writers life easier : it will become
39 * a simple choice of icons and line types for the precise information
40 * the viewer has to provide (agremented with keeping supplementary records
41 * and modifying slightly the DrawContext to suit the needs.)
42 *
f0728492 43 * We keep each data type in attributes, keys to specific information
44 * being formed from the GQuark corresponding to the information received.
45 * (facilities / facility_name / events / eventname.)
46 * (cpus/cpu_name, process_states/ps_name,
47 * execution_modes/em_name, execution_submodes/es_name).
cf6cb7e0 48 * The goal is then to provide a generic way to print information on the
49 * screen for all this different information.
50 *
51 * Information can be printed as
52 *
53 * - text (text + color + size + position (over or under line)
54 * - icon (icon filename, corresponding to a loaded icon, accessible through
55 * a GQuark. Icons are loaded statically at the guiControlFlow level during
56 * module initialization and can be added on the fly if not present in the
57 * GQuark.) The habitual place for xpm icons is in
58 * ${prefix}/share/LinuxTraceToolkit.) + position (over or under line)
59 * - line (color, width, style)
189a5d08 60 * - Arc (big points) (color, size)
cf6cb7e0 61 * - background color (color)
62 *
189a5d08 63 * An item is a leaf of the attributes tree. It is, in that case, including
64 * all kind of events categories we can have. It then associates each category
65 * with one or more actions (drawing something) or nothing.
66 *
7d5ffafa 67 * Each item has an array of hooks (hook list). Each hook represents an
68 * operation to perform. We seek the array each time we want to
a2e850ff 69 * draw an item. We execute each operation in order. An operation type
70 * is associated with each hook to permit user listing and modification
71 * of these operations. The operation type is also used to find the
72 * corresponding priority for the sorting. Operation type and priorities
73 * are enum and a static int table.
cf6cb7e0 74 *
75 * The array has to be sorted by priority each time we add a task in it.
a2e850ff 76 * A priority is associated with each operation type. It permits
cf6cb7e0 77 * to perform background color selection before line or text drawing. We also
78 * draw lines before text, so the text appears over the lines.
79 *
80 * Executing all the arrays of operations for a specific event (which
81 * implies information for state, event, cpu, execution mode and submode)
82 * has to be done in a same DrawContext. The goal there is to keep the offset
83 * of the text and icons over and under the middle line, so a specific
84 * event could be printed as ( R Si 0 for running, scheduled in, cpu 0 ),
7d5ffafa 85 * text being easy to replace with icons. The DrawContext is passed as
86 * call_data for the operation hooks.
cf6cb7e0 87 *
b782dd11 88 * We use the lttv global attributes to keep track of the loaded icons.
89 * If we need an icon, we look for it in the icons / icon name pathname.
90 * If found, we use the pointer to it. If not, we load the pixmap in
1a31868c 91 * memory and set the pointer to the GdkPixmap in the attributes. The
92 * structure pointed to contains the pixmap and the mask bitmap.
b782dd11 93 *
cf6cb7e0 94 * Author : Mathieu Desnoyers, October 2003
95 */
7d5ffafa 96
97#include <glib.h>
09e2606f 98#include <gtk/gtk.h>
99#include <gdk/gdk.h>
7d5ffafa 100#include <lttv/hook.h>
f0728492 101#include <lttv/attribute.h>
102#include <lttv/iattribute.h>
1a31868c 103#include <string.h>
7d5ffafa 104
d8f124de 105#include <lttv/tracecontext.h>
b782dd11 106#include <lttv/state.h>
107
d66666fe 108#include "drawitem.h"
1a31868c 109
110
111#define MAX_PATH_LEN 256
112
501d5405 113/* drawing hook functions */
4c69e0cc 114gboolean draw_text( void *hook_data, void *call_data)
b782dd11 115{
a56a1ba4 116 PropertiesText *Properties = (PropertiesText*)hook_data;
c8bba5fa 117 DrawContext *draw_context = (DrawContext*)call_data;
a56a1ba4 118
119 PangoContext *context;
120 PangoLayout *layout;
121 PangoAttribute *attribute;
c8bba5fa 122 PangoFontDescription *font_desc;// = pango_font_description_new();
123 gint font_size;
a56a1ba4 124 PangoRectangle ink_rect;
125
c8bba5fa 126 layout = draw_context->pango_layout;
a56a1ba4 127
128 context = pango_layout_get_context(layout);
c8bba5fa 129 font_desc = pango_context_get_font_description(context);
a56a1ba4 130
c8bba5fa 131 pango_font_description_set_size(font_desc, Properties->size*PANGO_SCALE);
a56a1ba4 132 pango_layout_context_changed(layout);
133
68997a22 134 pango_layout_set_text(layout, Properties->text, -1);
a56a1ba4 135 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
136 switch(Properties->position) {
137 case OVER:
c8bba5fa 138 gdk_draw_layout_with_colors(draw_context->drawable,
139 draw_context->gc,
140 draw_context->drawinfo.modify_over.x,
141 draw_context->drawinfo.modify_over.y,
a56a1ba4 142 layout, Properties->foreground, Properties->background);
c8bba5fa 143 draw_context->drawinfo.modify_over.x += ink_rect.width;
a56a1ba4 144
145 break;
146 case MIDDLE:
c8bba5fa 147 gdk_draw_layout_with_colors(draw_context->drawable,
148 draw_context->gc,
149 draw_context->drawinfo.modify_middle.x,
150 draw_context->drawinfo.modify_middle.y,
a56a1ba4 151 layout, Properties->foreground, Properties->background);
c8bba5fa 152 draw_context->drawinfo.modify_middle.x += ink_rect.width;
a56a1ba4 153 break;
154 case UNDER:
c8bba5fa 155 gdk_draw_layout_with_colors(draw_context->drawable,
156 draw_context->gc,
157 draw_context->drawinfo.modify_under.x,
158 draw_context->drawinfo.modify_under.y,
a56a1ba4 159 layout, Properties->foreground, Properties->background);
c8bba5fa 160 draw_context->drawinfo.modify_under.x += ink_rect.width;
a56a1ba4 161 break;
162 }
163
164 return 0;
b782dd11 165}
166
1a31868c 167
168/* To speed up the process, search in already loaded icons list first. Only
169 * load it if not present.
170 */
4c69e0cc 171gboolean draw_icon( void *hook_data, void *call_data)
b782dd11 172{
c8bba5fa 173 PropertiesIcon *properties = (PropertiesIcon*)hook_data;
174 DrawContext *draw_context = (DrawContext*)call_data;
b782dd11 175
1a31868c 176 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
a56a1ba4 177 LttvAttributeValue value;
178 gchar icon_name[MAX_PATH_LEN] = "icons/";
179 IconStruct *icon_info;
8d088fb2 180
c8bba5fa 181 strcat(icon_name, properties->icon_name);
a56a1ba4 182
1a31868c 183 g_assert(lttv_iattribute_find_by_path(attributes, icon_name,
184 LTTV_POINTER, &value));
a56a1ba4 185 if(*(value.v_pointer) == NULL)
186 {
187 *(value.v_pointer) = icon_info = g_new(IconStruct,1);
188
c8bba5fa 189 icon_info->pixmap = gdk_pixmap_create_from_xpm(draw_context->drawable,
190 &icon_info->mask, NULL, properties->icon_name);
a56a1ba4 191 }
192 else
193 {
194 icon_info = *(value.v_pointer);
195 }
196
c8bba5fa 197 gdk_gc_set_clip_mask(draw_context->gc, icon_info->mask);
a56a1ba4 198
c8bba5fa 199 switch(properties->position) {
a56a1ba4 200 case OVER:
201 gdk_gc_set_clip_origin(
c8bba5fa 202 draw_context->gc,
203 draw_context->drawinfo.modify_over.x,
204 draw_context->drawinfo.modify_over.y);
205 gdk_draw_drawable(draw_context->drawable,
206 draw_context->gc,
a56a1ba4 207 icon_info->pixmap,
208 0, 0,
c8bba5fa 209 draw_context->drawinfo.modify_over.x,
210 draw_context->drawinfo.modify_over.y,
211 properties->width, properties->height);
a56a1ba4 212
c8bba5fa 213 draw_context->drawinfo.modify_over.x += properties->width;
a56a1ba4 214
215 break;
216 case MIDDLE:
217 gdk_gc_set_clip_origin(
c8bba5fa 218 draw_context->gc,
219 draw_context->drawinfo.modify_middle.x,
220 draw_context->drawinfo.modify_middle.y);
221 gdk_draw_drawable(draw_context->drawable,
222 draw_context->gc,
a56a1ba4 223 icon_info->pixmap,
224 0, 0,
c8bba5fa 225 draw_context->drawinfo.modify_middle.x,
226 draw_context->drawinfo.modify_middle.y,
227 properties->width, properties->height);
a56a1ba4 228
c8bba5fa 229 draw_context->drawinfo.modify_middle.x += properties->width;
a56a1ba4 230 break;
231 case UNDER:
232 gdk_gc_set_clip_origin(
c8bba5fa 233 draw_context->gc,
234 draw_context->drawinfo.modify_under.x,
235 draw_context->drawinfo.modify_under.y);
236 gdk_draw_drawable(draw_context->drawable,
237 draw_context->gc,
a56a1ba4 238 icon_info->pixmap,
239 0, 0,
c8bba5fa 240 draw_context->drawinfo.modify_under.x,
241 draw_context->drawinfo.modify_under.y,
242 properties->width, properties->height);
a56a1ba4 243
c8bba5fa 244 draw_context->drawinfo.modify_under.x += properties->width;
a56a1ba4 245 break;
246 }
247
c8bba5fa 248 gdk_gc_set_clip_origin(draw_context->gc, 0, 0);
249 gdk_gc_set_clip_mask(draw_context->gc, NULL);
a56a1ba4 250
251 return 0;
b782dd11 252}
253
4c69e0cc 254gboolean draw_line( void *hook_data, void *call_data)
b782dd11 255{
c8bba5fa 256 PropertiesLine *properties = (PropertiesLine*)hook_data;
257 DrawContext *draw_context = (DrawContext*)call_data;
258 //GdkGC *gc = gdk_gc_new(draw_context->drawable);
a56a1ba4 259
c8bba5fa 260 //gdk_gc_set_foreground(draw_context->gc, properties->color);
261 gdk_gc_set_rgb_fg_color(draw_context->gc, &properties->color);
262 //gdk_gc_set_foreground(gc, properties->color);
263 gdk_gc_set_line_attributes( draw_context->gc,
264 properties->line_width,
265 properties->style,
a56a1ba4 266 GDK_CAP_BUTT,
267 GDK_JOIN_MITER);
d0cd7f09 268 //g_critical("DRAWING LINE : x1: %i, y1: %i, x2:%i, y2:%i",
c8bba5fa 269 // draw_context->previous->middle->x,
270 // draw_context->previous->middle->y,
271 // draw_context->drawinfo.middle.x,
272 // draw_context->drawinfo.middle.y);
a56a1ba4 273
c8bba5fa 274 switch(properties->position) {
a56a1ba4 275 case OVER:
276 drawing_draw_line(
c8bba5fa 277 NULL, draw_context->drawable,
278 draw_context->previous->over->x,
279 draw_context->previous->over->y,
280 draw_context->drawinfo.over.x,
281 draw_context->current->over->y,
282 draw_context->gc);
a56a1ba4 283 break;
284 case MIDDLE:
285 drawing_draw_line(
c8bba5fa 286 NULL, draw_context->drawable,
287 draw_context->previous->middle->x,
288 draw_context->previous->middle->y,
289 draw_context->drawinfo.middle.x,
290 draw_context->drawinfo.middle.y,
291 draw_context->gc);
a56a1ba4 292 break;
293 case UNDER:
294 drawing_draw_line(
c8bba5fa 295 NULL, draw_context->drawable,
296 draw_context->previous->under->x,
297 draw_context->previous->under->y,
298 draw_context->drawinfo.under.x,
299 draw_context->drawinfo.under.y,
300 draw_context->gc);
a56a1ba4 301
302 break;
303 }
304
305 //gdk_gc_unref(gc);
306
307 return 0;
b782dd11 308}
309
4c69e0cc 310gboolean draw_arc( void *hook_data, void *call_data)
b782dd11 311{
c8bba5fa 312 PropertiesArc *properties = (PropertiesArc*)hook_data;
313 DrawContext *draw_context = (DrawContext*)call_data;
a56a1ba4 314
c8bba5fa 315 //gdk_gc_set_foreground(draw_context->gc, properties->color);
316 gdk_gc_set_rgb_fg_color(draw_context->gc, properties->color);
a56a1ba4 317
c8bba5fa 318 switch(properties->position) {
a56a1ba4 319 case OVER:
c8bba5fa 320 gdk_draw_arc(draw_context->drawable, draw_context->gc,
321 properties->filled,
322 draw_context->drawinfo.modify_over.x,
323 draw_context->drawinfo.modify_over.y,
324 properties->size, properties->size, 0, 360*64);
325 draw_context->drawinfo.modify_over.x += properties->size;
a56a1ba4 326 break;
327 case MIDDLE:
c8bba5fa 328 gdk_draw_arc(draw_context->drawable, draw_context->gc,
329 properties->filled,
330 draw_context->drawinfo.modify_middle.x,
331 draw_context->drawinfo.modify_middle.y,
332 properties->size, properties->size, 0, 360*64);
333 draw_context->drawinfo.modify_middle.x += properties->size;
a56a1ba4 334
335 break;
336 case UNDER:
c8bba5fa 337 gdk_draw_arc(draw_context->drawable, draw_context->gc,
338 properties->filled,
339 draw_context->drawinfo.modify_under.x,
340 draw_context->drawinfo.modify_under.y,
341 properties->size, properties->size, 0, 360*64);
342 draw_context->drawinfo.modify_under.x += properties->size;
a56a1ba4 343
344 break;
345 }
346
347
348 return 0;
b782dd11 349}
350
4c69e0cc 351gboolean draw_bg( void *hook_data, void *call_data)
b782dd11 352{
c8bba5fa 353 PropertiesBG *properties = (PropertiesBG*)hook_data;
354 DrawContext *draw_context = (DrawContext*)call_data;
b782dd11 355
c8bba5fa 356 //gdk_gc_set_foreground(draw_context->gc, properties->color);
357 gdk_gc_set_rgb_fg_color(draw_context->gc, properties->color);
09e2606f 358
d0cd7f09 359 //g_critical("DRAWING RECT : x: %i, y: %i, w:%i, h:%i, val1 :%i, val2:%i ",
c8bba5fa 360 // draw_context->previous->over->x,
361 // draw_context->previous->over->y,
362 // draw_context->drawinfo.over.x - draw_context->previous->over->x,
363 // draw_context->previous->under->y-draw_context->previous->over->y,
364 // draw_context->drawinfo.over.x,
365 // draw_context->previous->over->x);
366 gdk_draw_rectangle(draw_context->drawable, draw_context->gc,
a56a1ba4 367 TRUE,
c8bba5fa 368 draw_context->previous->over->x,
369 draw_context->previous->over->y,
370 draw_context->drawinfo.over.x - draw_context->previous->over->x,
371 draw_context->previous->under->y-draw_context->previous->over->y);
09e2606f 372
a56a1ba4 373 return 0;
b782dd11 374}
375
376
This page took 0.046989 seconds and 4 git commands to generate.