| 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 | #ifndef _DRAW_ITEM_H |
| 21 | #define _DRAW_ITEM_H |
| 22 | |
| 23 | #include <lttv/state.h> |
| 24 | |
| 25 | typedef struct _DrawContext DrawContext; |
| 26 | typedef struct _DrawInfo DrawInfo; |
| 27 | typedef struct _ItemInfo ItemInfo; |
| 28 | |
| 29 | typedef struct _IconStruct IconStruct; |
| 30 | |
| 31 | typedef struct _DrawOperation DrawOperation; |
| 32 | |
| 33 | |
| 34 | typedef struct _PropertiesText PropertiesText; |
| 35 | typedef struct _PropertiesIcon PropertiesIcon; |
| 36 | typedef struct _PropertiesLine PropertiesLine; |
| 37 | typedef struct _PropertiesArc PropertiesArc; |
| 38 | typedef struct _PropertiesBG PropertiesBG; |
| 39 | |
| 40 | typedef enum _DrawableItems DrawableItems; |
| 41 | enum _DrawableItems { |
| 42 | ITEM_TEXT, ITEM_ICON, ITEM_LINE, ITEM_POINT, ITEM_BACKGROUND |
| 43 | }; |
| 44 | |
| 45 | typedef enum _RelPosX { |
| 46 | POS_START, POS_END |
| 47 | } RelPosX; |
| 48 | |
| 49 | typedef enum _RelPosY { |
| 50 | OVER, MIDDLE, UNDER |
| 51 | } RelPosY; |
| 52 | |
| 53 | |
| 54 | /* The DrawContext keeps information about the current drawing position and |
| 55 | * the previous one, so we can use both to draw lines. |
| 56 | * |
| 57 | * over : position for drawing over the middle line. |
| 58 | * middle : middle line position. |
| 59 | * under : position for drawing under the middle line. |
| 60 | * |
| 61 | * the modify_* are used to take into account that we should go forward |
| 62 | * when we draw a text, an arc or an icon, while it's unneeded when we |
| 63 | * draw a line or background. |
| 64 | * |
| 65 | * The modify_* positions are altered by the draw item functions. |
| 66 | * |
| 67 | */ |
| 68 | |
| 69 | |
| 70 | struct _DrawContext { |
| 71 | GdkDrawable *drawable; |
| 72 | GdkGC *gc; |
| 73 | PangoLayout *pango_layout; |
| 74 | |
| 75 | struct { |
| 76 | struct { |
| 77 | gint x; |
| 78 | struct { |
| 79 | gint over; |
| 80 | gint middle; |
| 81 | gint under; |
| 82 | } offset; |
| 83 | } start; |
| 84 | |
| 85 | struct { |
| 86 | gint x; |
| 87 | struct { |
| 88 | gint over; |
| 89 | gint middle; |
| 90 | gint under; |
| 91 | } offset; |
| 92 | } end; |
| 93 | |
| 94 | struct { |
| 95 | gint over; |
| 96 | gint middle; |
| 97 | gint under; |
| 98 | } y; |
| 99 | |
| 100 | } drawinfo; |
| 101 | }; |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | /* |
| 107 | * Structure used to keep information about icons. |
| 108 | */ |
| 109 | struct _IconStruct { |
| 110 | GdkPixmap *pixmap; |
| 111 | GdkBitmap *mask; |
| 112 | }; |
| 113 | |
| 114 | |
| 115 | /* |
| 116 | * The Item element is only used so the DrawOperation is modifiable by users. |
| 117 | * During drawing, only the Hook is needed. |
| 118 | */ |
| 119 | struct _DrawOperation { |
| 120 | DrawableItems item; |
| 121 | LttvHooks *hook; |
| 122 | }; |
| 123 | |
| 124 | /* |
| 125 | * We define here each items that can be drawn, together with their |
| 126 | * associated priority. Many item types can have the same priority, |
| 127 | * it's only used for quicksorting the operations when we add a new one |
| 128 | * to the array of operations to perform. Lower priorities are executed |
| 129 | * first. So, for example, we may want to give background color a value |
| 130 | * of 10 while a line would have 20, so the background color, which |
| 131 | * is in fact a rectangle, does not hide the line. |
| 132 | */ |
| 133 | |
| 134 | static int Items_Priorities[] = { |
| 135 | 50, /* ITEM_TEXT */ |
| 136 | 40, /* ITEM_ICON */ |
| 137 | 20, /* ITEM_LINE */ |
| 138 | 30, /* ITEM_POINT */ |
| 139 | 10 /* ITEM_BACKGROUND */ |
| 140 | }; |
| 141 | |
| 142 | /* |
| 143 | * Here are the different structures describing each item type that can be |
| 144 | * drawn. They contain the information necessary to draw the item : not the |
| 145 | * position (this is provided by the DrawContext), but the text, icon name, |
| 146 | * line width, color; all the properties of the specific items. |
| 147 | */ |
| 148 | |
| 149 | struct _PropertiesText { |
| 150 | GdkColor *foreground; |
| 151 | GdkColor *background; |
| 152 | gint size; |
| 153 | gchar *text; |
| 154 | struct { |
| 155 | RelPosX x; |
| 156 | RelPosY y; |
| 157 | } position; |
| 158 | }; |
| 159 | |
| 160 | |
| 161 | struct _PropertiesIcon { |
| 162 | gchar *icon_name; |
| 163 | gint width; |
| 164 | gint height; |
| 165 | struct { |
| 166 | RelPosX x; |
| 167 | RelPosY y; |
| 168 | } position; |
| 169 | }; |
| 170 | |
| 171 | struct _PropertiesLine { |
| 172 | GdkColor color; |
| 173 | gint line_width; |
| 174 | GdkLineStyle style; |
| 175 | RelPosY y; |
| 176 | }; |
| 177 | |
| 178 | struct _PropertiesArc { |
| 179 | GdkColor *color; |
| 180 | gint size; /* We force circle by width = height */ |
| 181 | gboolean filled; |
| 182 | struct { |
| 183 | RelPosX x; |
| 184 | RelPosY y; |
| 185 | } position; |
| 186 | }; |
| 187 | |
| 188 | struct _PropertiesBG { |
| 189 | GdkColor *color; |
| 190 | }; |
| 191 | |
| 192 | |
| 193 | |
| 194 | void draw_item( GdkDrawable *drawable, |
| 195 | gint x, |
| 196 | gint y, |
| 197 | LttvTraceState *ts, |
| 198 | LttvTracefileState *tfs, |
| 199 | LttvIAttribute *attributes); |
| 200 | |
| 201 | /* |
| 202 | * The tree of attributes used to store drawing operations goes like this : |
| 203 | * |
| 204 | * event_types/ |
| 205 | * "facility-event_type" |
| 206 | * cpus/ |
| 207 | * "cpu name" |
| 208 | * mode_types/ |
| 209 | * "execution mode"/ |
| 210 | * submodes/ |
| 211 | * "submode" |
| 212 | * process_states/ |
| 213 | * "state name" |
| 214 | * |
| 215 | * So if, for example, we want to add a hook to get called each time we |
| 216 | * receive an event that is in state LTTV_STATE_SYSCALL, we put the |
| 217 | * pointer to the GArray of DrawOperation in |
| 218 | * process_states/ "name associated with LTTV_STATE_SYSCALL" |
| 219 | */ |
| 220 | |
| 221 | |
| 222 | #if 0 |
| 223 | /* |
| 224 | * The add_operation has to do a quick sort by priority to keep the operations |
| 225 | * in the right order. |
| 226 | */ |
| 227 | void add_operation( LttvIAttribute *attributes, |
| 228 | gchar *pathname, |
| 229 | DrawOperation *operation); |
| 230 | |
| 231 | /* |
| 232 | * The del_operation seeks the array present at pathname (if any) and |
| 233 | * removes the DrawOperation if present. It returns 0 on success, -1 |
| 234 | * if it fails. |
| 235 | */ |
| 236 | gint del_operation( LttvIAttribute *attributes, |
| 237 | gchar *pathname, |
| 238 | DrawOperation *operation); |
| 239 | |
| 240 | /* |
| 241 | * The clean_operations removes all operations present at a pathname. |
| 242 | * returns 0 on success, -1 if it fails. |
| 243 | */ |
| 244 | gint clean_operations( LttvIAttribute *attributes, |
| 245 | gchar *pathname ); |
| 246 | |
| 247 | |
| 248 | /* |
| 249 | * The list_operations gives a pointer to the operation array associated |
| 250 | * with the pathname. It will be NULL if no operation is present. |
| 251 | */ |
| 252 | void list_operations( LttvIAttribute *attributes, |
| 253 | gchar *pathname, |
| 254 | GArray **operation); |
| 255 | |
| 256 | |
| 257 | |
| 258 | /* |
| 259 | * exec_operation executes the operations if present in the attributes, or |
| 260 | * do nothing if not present. |
| 261 | */ |
| 262 | void exec_operations( LttvIAttribute *attributes, |
| 263 | gchar *pathname); |
| 264 | #endif //0 |
| 265 | |
| 266 | /* |
| 267 | * Here follow the prototypes of the hook functions used to draw the |
| 268 | * different items. |
| 269 | */ |
| 270 | |
| 271 | gboolean draw_text( void *hook_data, void *call_data); |
| 272 | gboolean draw_icon( void *hook_data, void *call_data); |
| 273 | gboolean draw_line( void *hook_data, void *call_data); |
| 274 | gboolean draw_arc( void *hook_data, void *call_data); |
| 275 | gboolean draw_bg( void *hook_data, void *call_data); |
| 276 | |
| 277 | |
| 278 | #endif // _DRAW_ITEM_H |