draw icon working
[lttv.git] / ltt / branches / poly / lttv / modules / guiControlFlow / Event_Hooks.c
CommitLineData
f0d936c0 1/*****************************************************************************
2 * Hooks to be called by the main window *
3 *****************************************************************************/
4
f0d936c0 5
189a5d08 6#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
7#define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
8
cf6cb7e0 9//#define PANGO_ENABLE_BACKEND
558aa013 10#include <gtk/gtk.h>
11#include <gdk/gdk.h>
5f16133f 12#include <glib.h>
13
cf6cb7e0 14//#include <pango/pango.h>
15
558aa013 16#include <lttv/hook.h>
17#include <lttv/common.h>
f0d936c0 18
1ab818de 19#include "Event_Hooks.h"
f0d936c0 20#include "CFV.h"
5f16133f 21#include "Process_List.h"
1ab3d149 22#include "Drawing.h"
f7afe191 23#include "CFV-private.h"
5f16133f 24
f7afe191 25
189a5d08 26/* NOTE : no drawing data should be sent there, since the drawing widget
96cfe486 27 * has not been initialized */
f7afe191 28void send_test_drawing(ProcessList *Process_List,
29 Drawing_t *Drawing,
30 GdkPixmap *Pixmap,
31 gint x, gint y, // y not used here?
32 gint width,
33 gint height) // height won't be used here ?
34{
35 int i;
36 ProcessInfo Process_Info = {10000, 12000, 55600};
37 //ProcessInfo Process_Info = {156, 14000, 55500};
38 GtkTreeRowReference *got_RowRef;
cf6cb7e0 39 PangoContext *context;
40 PangoLayout *layout;
41 PangoFontDescription *FontDesc;// = pango_font_description_new();
42 gint Font_Size;
43
189a5d08 44 //icon
45 GdkBitmap *mask = g_new(GdkBitmap, 1);
46 GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1);
47 GdkGC * gc = gdk_gc_new(Pixmap);
48
cf6cb7e0 49 /* Sent text data */
50 layout = gtk_widget_create_pango_layout(Drawing->Drawing_Area_V,
51 NULL);
52 context = pango_layout_get_context(layout);
53 FontDesc = pango_context_get_font_description(context);
54 Font_Size = pango_font_description_get_size(FontDesc);
55 pango_font_description_set_size(FontDesc, Font_Size-3*PANGO_SCALE);
56
f7afe191 57
cf6cb7e0 58
59
f7afe191 60 LttTime birth;
61 birth.tv_sec = 12000;
62 birth.tv_nsec = 55500;
189a5d08 63 g_info("we have : x : %u, y : %u, width : %u, height : %u", x, y, width, height);
4c69e0cc 64 processlist_get_process_pixels(Process_List,
f7afe191 65 1,
66 &birth,
67 &y,
68 &height);
69
189a5d08 70 g_info("we draw : x : %u, y : %u, width : %u, height : %u", x, y, width, height);
4c69e0cc 71 drawing_draw_line(
f7afe191 72 Drawing, Pixmap, x,
73 y+(height/2), x + width, y+(height/2),
74 Drawing->Drawing_Area_V->style->black_gc);
75
cf6cb7e0 76 pango_layout_set_text(layout, "Test", -1);
77 gdk_draw_layout(Pixmap, Drawing->Drawing_Area_V->style->black_gc,
78 0, y+height, layout);
79
f7afe191 80 birth.tv_sec = 14000;
81 birth.tv_nsec = 55500;
82
4c69e0cc 83 processlist_get_process_pixels(Process_List,
f7afe191 84 156,
85 &birth,
86 &y,
87 &height);
88
89
4c69e0cc 90 drawing_draw_line(
f7afe191 91 Drawing, Pixmap, x,
92 y+(height/2), x + width, y+(height/2),
93 Drawing->Drawing_Area_V->style->black_gc);
94
189a5d08 95
96 /* Draw icon */
97 icon_pixmap = gdk_pixmap_create_from_xpm(Pixmap, &mask, NULL,
98// "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
99 "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
100 gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc);
101 gdk_gc_set_clip_mask(gc, mask);
102 gdk_draw_drawable(Pixmap,
103 gc,
104 icon_pixmap,
105 0, 0, 0, 0, -1, -1);
106
107 g_free(icon_pixmap);
108 g_free(mask);
109 g_free(gc);
110
111 g_info("y : %u, height : %u", y, height);
f7afe191 112
113 birth.tv_sec = 12000;
114 birth.tv_nsec = 55700;
115
4c69e0cc 116 processlist_get_process_pixels(Process_List,
f7afe191 117 10,
118 &birth,
119 &y,
120 &height);
121
122
4c69e0cc 123 drawing_draw_line(
f7afe191 124 Drawing, Pixmap, x,
125 y+(height/2), x + width, y+(height/2),
126 Drawing->Drawing_Area_V->style->black_gc);
127
189a5d08 128 g_info("y : %u, height : %u", y, height);
f7afe191 129
130 for(i=0; i<10; i++)
131 {
132 birth.tv_sec = i*12000;
133 birth.tv_nsec = i*55700;
134
4c69e0cc 135 processlist_get_process_pixels(Process_List,
f7afe191 136 i,
137 &birth,
138 &y,
139 &height);
140
141
4c69e0cc 142 drawing_draw_line(
f7afe191 143 Drawing, Pixmap, x,
144 y+(height/2), x + width, y+(height/2),
145 Drawing->Drawing_Area_V->style->black_gc);
146
147 g_critical("y : %u, height : %u", y, height);
148
149 }
150
151 birth.tv_sec = 12000;
152 birth.tv_nsec = 55600;
153
4c69e0cc 154 processlist_get_process_pixels(Process_List,
f7afe191 155 10,
156 &birth,
157 &y,
158 &height);
159
160
4c69e0cc 161 drawing_draw_line(
f7afe191 162 Drawing, Pixmap, x,
163 y+(height/2), x + width, y+(height/2),
164 Drawing->Drawing_Area_V->style->black_gc);
165
189a5d08 166 g_info("y : %u, height : %u", y, height);
cf6cb7e0 167
168
169 pango_font_description_set_size(FontDesc, Font_Size);
170 g_free(layout);
171 //g_free(context);
f7afe191 172}
173
174void send_test_process(ProcessList *Process_List, Drawing_t *Drawing)
5f16133f 175{
f7afe191 176 guint height, y;
5f16133f 177 int i;
178 ProcessInfo Process_Info = {10000, 12000, 55600};
179 //ProcessInfo Process_Info = {156, 14000, 55500};
180 GtkTreeRowReference *got_RowRef;
181
182 LttTime birth;
f7afe191 183
184 if(Process_List->Test_Process_Sent) return;
185
5f16133f 186 birth.tv_sec = 12000;
187 birth.tv_nsec = 55500;
188
4c69e0cc 189 processlist_add(Process_List,
5f16133f 190 1,
191 &birth,
f7afe191 192 &y);
4c69e0cc 193 processlist_get_process_pixels(Process_List,
f7afe191 194 1,
195 &birth,
196 &y,
197 &height);
4c69e0cc 198 drawing_insert_square( Drawing, y, height);
1ab3d149 199
f7afe191 200 //g_critical("y : %u, height : %u", y, height);
5f16133f 201
202 birth.tv_sec = 14000;
203 birth.tv_nsec = 55500;
204
4c69e0cc 205 processlist_add(Process_List,
5f16133f 206 156,
207 &birth,
f7afe191 208 &y);
4c69e0cc 209 processlist_get_process_pixels(Process_List,
f7afe191 210 156,
211 &birth,
212 &y,
213 &height);
4c69e0cc 214 drawing_insert_square( Drawing, y, height);
f7afe191 215
216 //g_critical("y : %u, height : %u", y, height);
217
5f16133f 218 birth.tv_sec = 12000;
219 birth.tv_nsec = 55700;
220
4c69e0cc 221 processlist_add(Process_List,
5f16133f 222 10,
223 &birth,
224 &height);
4c69e0cc 225 processlist_get_process_pixels(Process_List,
f7afe191 226 10,
227 &birth,
228 &y,
229 &height);
4c69e0cc 230 drawing_insert_square( Drawing, y, height);
f7afe191 231
232 //g_critical("y : %u, height : %u", y, height);
233
4c69e0cc 234 //drawing_insert_square( Drawing, height, 5);
5f16133f 235
236 for(i=0; i<10; i++)
237 {
238 birth.tv_sec = i*12000;
239 birth.tv_nsec = i*55700;
240
4c69e0cc 241 processlist_add(Process_List,
5f16133f 242 i,
243 &birth,
244 &height);
4c69e0cc 245 processlist_get_process_pixels(Process_List,
f7afe191 246 i,
247 &birth,
248 &y,
249 &height);
4c69e0cc 250 drawing_insert_square( Drawing, y, height);
f7afe191 251
252 // g_critical("y : %u, height : %u", y, height);
253
5f16133f 254 }
f7afe191 255 //g_critical("height : %u", height);
5f16133f 256
257 birth.tv_sec = 12000;
258 birth.tv_nsec = 55600;
259
4c69e0cc 260 processlist_add(Process_List,
5f16133f 261 10,
262 &birth,
f7afe191 263 &y);
4c69e0cc 264 processlist_get_process_pixels(Process_List,
f7afe191 265 10,
266 &birth,
267 &y,
268 &height);
4c69e0cc 269 drawing_insert_square( Drawing, y, height);
f7afe191 270
271 //g_critical("y : %u, height : %u", y, height);
272
4c69e0cc 273 processlist_add(Process_List,
5f16133f 274 10000,
275 &birth,
276 &height);
4c69e0cc 277 processlist_get_process_pixels(Process_List,
f7afe191 278 10000,
279 &birth,
280 &y,
281 &height);
4c69e0cc 282 drawing_insert_square( Drawing, y, height);
f7afe191 283
284 //g_critical("y : %u, height : %u", y, height);
285
4c69e0cc 286 //drawing_insert_square( Drawing, height, 5);
f7afe191 287 //g_critical("height : %u", height);
5f16133f 288
289
4c69e0cc 290 processlist_get_process_pixels(Process_List,
1ab3d149 291 10000,
292 &birth,
f7afe191 293 &y, &height);
4c69e0cc 294 processlist_remove( Process_List,
5f16133f 295 10000,
296 &birth);
1ab3d149 297
4c69e0cc 298 drawing_remove_square( Drawing, y, height);
5f16133f 299
300 if(got_RowRef =
301 (GtkTreeRowReference*)g_hash_table_lookup(
302 Process_List->Process_Hash,
303 &Process_Info))
304 {
305 g_critical("key found");
306 g_critical("position in the list : %s",
307 gtk_tree_path_to_string (
308 gtk_tree_row_reference_get_path(
309 (GtkTreeRowReference*)got_RowRef)
310 ));
311
312 }
313
f7afe191 314 Process_List->Test_Process_Sent = TRUE;
315
5f16133f 316}
317
318
f0d936c0 319
320/**
321 * Event Viewer's constructor hook
322 *
323 * This constructor is given as a parameter to the menuitem and toolbar button
324 * registration. It creates the list.
325 * @param pmParentWindow A pointer to the parent window.
326 * @return The widget created.
327 */
328GtkWidget *
4c69e0cc 329h_guicontrolflow(MainWindow *pmParentWindow, LttvTracesetSelector * s, char * key)
f0d936c0 330{
189a5d08 331 g_info("h_guicontrolflow, %p, %p, %s", pmParentWindow, s, key);
4c69e0cc 332 ControlFlowData *Control_Flow_Data = guicontrolflow() ;
189a5d08 333
334 Control_Flow_Data->Parent_Window = pmParentWindow;
f0d936c0 335
41a76985 336 get_time_window(pmParentWindow,
cb1686f6 337 guicontrolflow_get_time_window(Control_Flow_Data));
41a76985 338 get_current_time(pmParentWindow,
cb1686f6 339 guicontrolflow_get_current_time(Control_Flow_Data));
f7afe191 340
341 // Unreg done in the GuiControlFlow_Destructor
3cff8cc1 342 reg_update_time_window(update_time_window_hook, Control_Flow_Data,
f7afe191 343 pmParentWindow);
3cff8cc1 344 reg_update_current_time(update_current_time_hook, Control_Flow_Data,
f7afe191 345 pmParentWindow);
3cff8cc1 346 return guicontrolflow_get_widget(Control_Flow_Data) ;
f0d936c0 347
348}
349
3cff8cc1 350int event_selected_hook(void *hook_data, void *call_data)
f0d936c0 351{
352 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
353 guint *Event_Number = (guint*) call_data;
354
355 g_critical("DEBUG : event selected by main window : %u", *Event_Number);
356
357// Control_Flow_Data->Currently_Selected_Event = *Event_Number;
358// Control_Flow_Data->Selected_Event = TRUE ;
359
4c69e0cc 360// tree_v_set_cursor(Control_Flow_Data);
f0d936c0 361
362}
363
558aa013 364#ifdef DEBUG
f0d936c0 365/* Hook called before drawing. Gets the initial context at the beginning of the
366 * drawing interval and copy it to the context in Event_Request.
367 */
4c69e0cc 368int draw_before_hook(void *hook_data, void *call_data)
f0d936c0 369{
370 EventRequest *Event_Request = (EventRequest*)hook_data;
371 EventsContext Events_Context = (EventsContext*)call_data;
372
373 Event_Request->Events_Context = Events_Context;
374
375 return 0;
376}
377
378/*
379 * The draw event hook is called by the reading API to have a
380 * particular event drawn on the screen.
381 * @param hook_data ControlFlowData structure of the viewer.
382 * @param call_data Event context.
383 *
384 * This function basically draw lines and icons. Two types of lines are drawn :
385 * one small (3 pixels?) representing the state of the process and the second
386 * type is thicker (10 pixels?) representing on which CPU a process is running
387 * (and this only in running state).
388 *
389 * Extremums of the lines :
390 * x_min : time of the last event context for this process kept in memory.
391 * x_max : time of the current event.
392 * y : middle of the process in the process list. The process is found in the
393 * list, therefore is it's position in pixels.
394 *
395 * The choice of lines'color is defined by the context of the last event for this
396 * process.
397 */
4c69e0cc 398int draw_event_hook(void *hook_data, void *call_data)
f0d936c0 399{
400 EventRequest *Event_Request = (EventRequest*)hook_data;
401
402 return 0;
403}
404
405
4c69e0cc 406int draw_after_hook(void *hook_data, void *call_data)
f0d936c0 407{
408 EventRequest *Event_Request = (EventRequest*)hook_data;
409
410 g_free(Event_Request);
411 return 0;
412}
558aa013 413#endif
f7afe191 414
415
416
417
4c69e0cc 418void update_time_window_hook(void *hook_data, void *call_data)
f7afe191 419{
420 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
421 TimeWindow* Time_Window =
3cff8cc1 422 guicontrolflow_get_time_window(Control_Flow_Data);
f7afe191 423 TimeWindow *New_Time_Window = ((TimeWindow*)call_data);
424
425 // As the time interval change will mostly be used for
426 // zoom in and out, it's not useful to keep old drawing
427 // sections, as scale will be changed.
428
429
430 *Time_Window = *New_Time_Window;
189a5d08 431 g_info("New time window HOOK : %u, %u to %u, %u",
bca3b81f 432 Time_Window->start_time.tv_sec,
433 Time_Window->start_time.tv_nsec,
434 Time_Window->time_width.tv_sec,
435 Time_Window->time_width.tv_nsec);
f7afe191 436
4c69e0cc 437 drawing_data_request(Control_Flow_Data->Drawing,
f7afe191 438 &Control_Flow_Data->Drawing->Pixmap,
439 0, 0,
440 Control_Flow_Data->Drawing->width,
441 Control_Flow_Data->Drawing->height);
442
4c69e0cc 443 drawing_refresh(Control_Flow_Data->Drawing,
f7afe191 444 0, 0,
445 Control_Flow_Data->Drawing->width,
446 Control_Flow_Data->Drawing->height);
447
448}
449
4c69e0cc 450void update_current_time_hook(void *hook_data, void *call_data)
f7afe191 451{
452 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
453 LttTime* Current_Time =
4c69e0cc 454 guicontrolflow_get_current_time(Control_Flow_Data);
f7afe191 455 *Current_Time = *((LttTime*)call_data);
189a5d08 456 g_info("New Current time HOOK : %u, %u", Current_Time->tv_sec,
f7afe191 457 Current_Time->tv_nsec);
458
459 /* If current time is inside time interval, just move the highlight
460 * bar */
461
462 /* Else, we have to change the time interval. We have to tell it
463 * to the main window. */
464 /* The time interval change will take care of placing the current
465 * time at the center of the visible area */
466
467}
468
This page took 0.045113 seconds and 4 git commands to generate.