| 1 | #include "Drawing.h" |
| 2 | |
| 3 | /***************************************************************************** |
| 4 | * Drawing functions * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | typedef enum |
| 8 | { |
| 9 | RED, |
| 10 | GREEN, |
| 11 | BLUE, |
| 12 | WHITE, |
| 13 | BLACK |
| 14 | |
| 15 | } ControlFlowColors; |
| 16 | |
| 17 | /* Vector of unallocated colors */ |
| 18 | static GdkColor CF_Colors [] = |
| 19 | { |
| 20 | { 0, 0xffff, 0x0000, 0x0000 }, // RED |
| 21 | { 0, 0x0000, 0xffff, 0x0000 }, // GREEN |
| 22 | { 0, 0x0000, 0x0000, 0xffff }, // BLUE |
| 23 | { 0, 0xffff, 0xffff, 0xffff }, // WHITE |
| 24 | { 0, 0x0000, 0x0000, 0x0000 } // BLACK |
| 25 | }; |
| 26 | |
| 27 | |
| 28 | typedef struct _Drawing_t { |
| 29 | GtkWidget *Drawing_Area_V |
| 30 | |
| 31 | guint height, width; |
| 32 | |
| 33 | } Drawing_t; |
| 34 | |
| 35 | |
| 36 | Drawing_t *Drawing(void) |
| 37 | { |
| 38 | |
| 39 | Drawing_t Drawing = g_new(Drawing_t, 1); |
| 40 | |
| 41 | Drawing->Drawing_Area_V = gtk_drawing_area_new (); |
| 42 | |
| 43 | g_object_set_data_full( |
| 44 | G_OBJECT(Drawing->Drawing_Area_V), |
| 45 | "Drawing_Data", |
| 46 | Drawing, |
| 47 | Drawing_destroy); |
| 48 | |
| 49 | gtk_widget_modify_bg( Control_Flow_Data->Drawing_Area_V, |
| 50 | GTK_STATE_NORMAL, |
| 51 | &CF_Colors[BLACK]); |
| 52 | |
| 53 | |
| 54 | return Drawing; |
| 55 | } |
| 56 | |
| 57 | void Drawing_destroy(Drawing_t *Drawing) |
| 58 | { |
| 59 | |
| 60 | g_object_unref( G_OBJECT(Drawing->Drawing_Area_V)); |
| 61 | |
| 62 | g_free(Drawing); |
| 63 | } |
| 64 | |
| 65 | /* get_time_from_pixels |
| 66 | * |
| 67 | * Get the time interval from window time and pixels, and pixels requested. This |
| 68 | * function uses TimeMul, which should only be used if the float value is lower |
| 69 | * that 4, and here it's always lower than 1, so it's ok. |
| 70 | */ |
| 71 | void get_time_from_pixels( |
| 72 | guint area_x, |
| 73 | guint area_width, |
| 74 | guint window_width, |
| 75 | ltt_time *window_time_begin, |
| 76 | ltt_time *window_time_end, |
| 77 | ltt_time *time_begin, |
| 78 | ltt_time *time_end) |
| 79 | { |
| 80 | ltt_time window_time_interval; |
| 81 | |
| 82 | TimeSub(window_time_interval, window_time_end, window_time_begin); |
| 83 | |
| 84 | |
| 85 | TimeMul(time_begin, window_time_interval, (area_x/(float)window_width)); |
| 86 | TimeAdd(time_begin, window_time_begin, time_begin); |
| 87 | |
| 88 | TimeMul(time_end, window_time_interval, (area_width/(float)window_width)); |
| 89 | TimeAdd(time_end, time_begin, time_end); |
| 90 | |
| 91 | } |
| 92 | |
| 93 | void Drawing_Resize(Drawing_t *Drawing, guint h, guint, w) |
| 94 | { |
| 95 | guint w; |
| 96 | |
| 97 | Drawing->height = h ; |
| 98 | Drawing->weight = w ; |
| 99 | |
| 100 | gtk_widget_set_size_request ( Control_Flow_Data->Drawing_Area_V, |
| 101 | Drawing->weight, |
| 102 | Drawing->height); |
| 103 | |
| 104 | |
| 105 | } |
| 106 | |
| 107 | |
| 108 | |