draw icon working
[lttv.git] / ltt / branches / poly / lttv / modules / guiControlFlow / Event_Hooks.c
1 /*****************************************************************************
2 * Hooks to be called by the main window *
3 *****************************************************************************/
4
5
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
9 //#define PANGO_ENABLE_BACKEND
10 #include <gtk/gtk.h>
11 #include <gdk/gdk.h>
12 #include <glib.h>
13
14 //#include <pango/pango.h>
15
16 #include <lttv/hook.h>
17 #include <lttv/common.h>
18
19 #include "Event_Hooks.h"
20 #include "CFV.h"
21 #include "Process_List.h"
22 #include "Drawing.h"
23 #include "CFV-private.h"
24
25
26 /* NOTE : no drawing data should be sent there, since the drawing widget
27 * has not been initialized */
28 void 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;
39 PangoContext *context;
40 PangoLayout *layout;
41 PangoFontDescription *FontDesc;// = pango_font_description_new();
42 gint Font_Size;
43
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
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
57
58
59
60 LttTime birth;
61 birth.tv_sec = 12000;
62 birth.tv_nsec = 55500;
63 g_info("we have : x : %u, y : %u, width : %u, height : %u", x, y, width, height);
64 processlist_get_process_pixels(Process_List,
65 1,
66 &birth,
67 &y,
68 &height);
69
70 g_info("we draw : x : %u, y : %u, width : %u, height : %u", x, y, width, height);
71 drawing_draw_line(
72 Drawing, Pixmap, x,
73 y+(height/2), x + width, y+(height/2),
74 Drawing->Drawing_Area_V->style->black_gc);
75
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
80 birth.tv_sec = 14000;
81 birth.tv_nsec = 55500;
82
83 processlist_get_process_pixels(Process_List,
84 156,
85 &birth,
86 &y,
87 &height);
88
89
90 drawing_draw_line(
91 Drawing, Pixmap, x,
92 y+(height/2), x + width, y+(height/2),
93 Drawing->Drawing_Area_V->style->black_gc);
94
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);
112
113 birth.tv_sec = 12000;
114 birth.tv_nsec = 55700;
115
116 processlist_get_process_pixels(Process_List,
117 10,
118 &birth,
119 &y,
120 &height);
121
122
123 drawing_draw_line(
124 Drawing, Pixmap, x,
125 y+(height/2), x + width, y+(height/2),
126 Drawing->Drawing_Area_V->style->black_gc);
127
128 g_info("y : %u, height : %u", y, height);
129
130 for(i=0; i<10; i++)
131 {
132 birth.tv_sec = i*12000;
133 birth.tv_nsec = i*55700;
134
135 processlist_get_process_pixels(Process_List,
136 i,
137 &birth,
138 &y,
139 &height);
140
141
142 drawing_draw_line(
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
154 processlist_get_process_pixels(Process_List,
155 10,
156 &birth,
157 &y,
158 &height);
159
160
161 drawing_draw_line(
162 Drawing, Pixmap, x,
163 y+(height/2), x + width, y+(height/2),
164 Drawing->Drawing_Area_V->style->black_gc);
165
166 g_info("y : %u, height : %u", y, height);
167
168
169 pango_font_description_set_size(FontDesc, Font_Size);
170 g_free(layout);
171 //g_free(context);
172 }
173
174 void send_test_process(ProcessList *Process_List, Drawing_t *Drawing)
175 {
176 guint height, y;
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;
183
184 if(Process_List->Test_Process_Sent) return;
185
186 birth.tv_sec = 12000;
187 birth.tv_nsec = 55500;
188
189 processlist_add(Process_List,
190 1,
191 &birth,
192 &y);
193 processlist_get_process_pixels(Process_List,
194 1,
195 &birth,
196 &y,
197 &height);
198 drawing_insert_square( Drawing, y, height);
199
200 //g_critical("y : %u, height : %u", y, height);
201
202 birth.tv_sec = 14000;
203 birth.tv_nsec = 55500;
204
205 processlist_add(Process_List,
206 156,
207 &birth,
208 &y);
209 processlist_get_process_pixels(Process_List,
210 156,
211 &birth,
212 &y,
213 &height);
214 drawing_insert_square( Drawing, y, height);
215
216 //g_critical("y : %u, height : %u", y, height);
217
218 birth.tv_sec = 12000;
219 birth.tv_nsec = 55700;
220
221 processlist_add(Process_List,
222 10,
223 &birth,
224 &height);
225 processlist_get_process_pixels(Process_List,
226 10,
227 &birth,
228 &y,
229 &height);
230 drawing_insert_square( Drawing, y, height);
231
232 //g_critical("y : %u, height : %u", y, height);
233
234 //drawing_insert_square( Drawing, height, 5);
235
236 for(i=0; i<10; i++)
237 {
238 birth.tv_sec = i*12000;
239 birth.tv_nsec = i*55700;
240
241 processlist_add(Process_List,
242 i,
243 &birth,
244 &height);
245 processlist_get_process_pixels(Process_List,
246 i,
247 &birth,
248 &y,
249 &height);
250 drawing_insert_square( Drawing, y, height);
251
252 // g_critical("y : %u, height : %u", y, height);
253
254 }
255 //g_critical("height : %u", height);
256
257 birth.tv_sec = 12000;
258 birth.tv_nsec = 55600;
259
260 processlist_add(Process_List,
261 10,
262 &birth,
263 &y);
264 processlist_get_process_pixels(Process_List,
265 10,
266 &birth,
267 &y,
268 &height);
269 drawing_insert_square( Drawing, y, height);
270
271 //g_critical("y : %u, height : %u", y, height);
272
273 processlist_add(Process_List,
274 10000,
275 &birth,
276 &height);
277 processlist_get_process_pixels(Process_List,
278 10000,
279 &birth,
280 &y,
281 &height);
282 drawing_insert_square( Drawing, y, height);
283
284 //g_critical("y : %u, height : %u", y, height);
285
286 //drawing_insert_square( Drawing, height, 5);
287 //g_critical("height : %u", height);
288
289
290 processlist_get_process_pixels(Process_List,
291 10000,
292 &birth,
293 &y, &height);
294 processlist_remove( Process_List,
295 10000,
296 &birth);
297
298 drawing_remove_square( Drawing, y, height);
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
314 Process_List->Test_Process_Sent = TRUE;
315
316 }
317
318
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 */
328 GtkWidget *
329 h_guicontrolflow(MainWindow *pmParentWindow, LttvTracesetSelector * s, char * key)
330 {
331 g_info("h_guicontrolflow, %p, %p, %s", pmParentWindow, s, key);
332 ControlFlowData *Control_Flow_Data = guicontrolflow() ;
333
334 Control_Flow_Data->Parent_Window = pmParentWindow;
335
336 get_time_window(pmParentWindow,
337 guicontrolflow_get_time_window(Control_Flow_Data));
338 get_current_time(pmParentWindow,
339 guicontrolflow_get_current_time(Control_Flow_Data));
340
341 // Unreg done in the GuiControlFlow_Destructor
342 reg_update_time_window(update_time_window_hook, Control_Flow_Data,
343 pmParentWindow);
344 reg_update_current_time(update_current_time_hook, Control_Flow_Data,
345 pmParentWindow);
346 return guicontrolflow_get_widget(Control_Flow_Data) ;
347
348 }
349
350 int event_selected_hook(void *hook_data, void *call_data)
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
360 // tree_v_set_cursor(Control_Flow_Data);
361
362 }
363
364 #ifdef DEBUG
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 */
368 int draw_before_hook(void *hook_data, void *call_data)
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 */
398 int draw_event_hook(void *hook_data, void *call_data)
399 {
400 EventRequest *Event_Request = (EventRequest*)hook_data;
401
402 return 0;
403 }
404
405
406 int draw_after_hook(void *hook_data, void *call_data)
407 {
408 EventRequest *Event_Request = (EventRequest*)hook_data;
409
410 g_free(Event_Request);
411 return 0;
412 }
413 #endif
414
415
416
417
418 void update_time_window_hook(void *hook_data, void *call_data)
419 {
420 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
421 TimeWindow* Time_Window =
422 guicontrolflow_get_time_window(Control_Flow_Data);
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;
431 g_info("New time window HOOK : %u, %u to %u, %u",
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);
436
437 drawing_data_request(Control_Flow_Data->Drawing,
438 &Control_Flow_Data->Drawing->Pixmap,
439 0, 0,
440 Control_Flow_Data->Drawing->width,
441 Control_Flow_Data->Drawing->height);
442
443 drawing_refresh(Control_Flow_Data->Drawing,
444 0, 0,
445 Control_Flow_Data->Drawing->width,
446 Control_Flow_Data->Drawing->height);
447
448 }
449
450 void update_current_time_hook(void *hook_data, void *call_data)
451 {
452 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
453 LttTime* Current_Time =
454 guicontrolflow_get_current_time(Control_Flow_Data);
455 *Current_Time = *((LttTime*)call_data);
456 g_info("New Current time HOOK : %u, %u", Current_Time->tv_sec,
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.039733 seconds and 4 git commands to generate.