| File: | rc/chart.c |
| Location: | line 1058, column 3 |
| Description: | Value stored to 'c' is never read |
| 1 | /* GKrellM |
| 2 | | Copyright (C) 1999-2010 Bill Wilson |
| 3 | | |
| 4 | | Author: Bill Wilson billw@gkrellm.net |
| 5 | | Latest versions might be found at: http://gkrellm.net |
| 6 | | |
| 7 | | |
| 8 | | GKrellM is free software: you can redistribute it and/or modify it |
| 9 | | under the terms of the GNU General Public License as published by |
| 10 | | the Free Software Foundation, either version 3 of the License, or |
| 11 | | (at your option) any later version. |
| 12 | | |
| 13 | | GKrellM is distributed in the hope that it will be useful, but WITHOUT |
| 14 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 15 | | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 16 | | License for more details. |
| 17 | | |
| 18 | | You should have received a copy of the GNU General Public License |
| 19 | | along with this program. If not, see http://www.gnu.org/licenses/ |
| 20 | | |
| 21 | | |
| 22 | | Additional permission under GNU GPL version 3 section 7 |
| 23 | | |
| 24 | | If you modify this program, or any covered work, by linking or |
| 25 | | combining it with the OpenSSL project's OpenSSL library (or a |
| 26 | | modified version of that library), containing parts covered by |
| 27 | | the terms of the OpenSSL or SSLeay licenses, you are granted |
| 28 | | additional permission to convey the resulting work. |
| 29 | | Corresponding Source for a non-source form of such a combination |
| 30 | | shall include the source code for the parts of OpenSSL used as well |
| 31 | | as that of the covered work. |
| 32 | */ |
| 33 | |
| 34 | #include "gkrellm.h" |
| 35 | #include "gkrellm-private.h" |
| 36 | |
| 37 | #include <math.h> |
| 38 | |
| 39 | |
| 40 | static void set_grid_resolution_spin_button(GkrellmChart *, gint); |
| 41 | |
| 42 | |
| 43 | /* For grid images of height 2 pixels, make room at bottom of chartdata |
| 44 | | window so both pixel lines will show. |
| 45 | */ |
| 46 | #define GRID_HEIGHT_Y_OFFSET_ADJUST(cp)(( gdk_pixbuf_get_height((cp)->bg_grid_piximage->pixbuf ) < 2) ? 0 : 1) \ |
| 47 | (( gdk_pixbuf_get_height((cp)->bg_grid_piximage->pixbuf) < 2) ? 0 : 1) |
| 48 | |
| 49 | /* Map internal y values with origin at lower left to X screen coordinates |
| 50 | | which have origin at upper left. |
| 51 | */ |
| 52 | #define Y_SCREEN_MAP(cp,y)((cp)->h - (y) - 1) ((cp)->h - (y) - 1) |
| 53 | |
| 54 | |
| 55 | #define MIN_CHARTHEIGHT5 5 |
| 56 | #define MAX_CHARTHEIGHT200 200 |
| 57 | |
| 58 | static GList *chart_list; |
| 59 | |
| 60 | // #define DEBUG1 |
| 61 | // #define DEBUG2 |
| 62 | // #define DEBUG3 |
| 63 | |
| 64 | /* ----------------------------------------------------------------------- */ |
| 65 | |
| 66 | static gint |
| 67 | computed_index(GkrellmChart *cp, gint i) |
| 68 | { |
| 69 | gint x; |
| 70 | |
| 71 | x = (cp->position + i + 1) % cp->w; |
| 72 | return x; |
| 73 | } |
| 74 | |
| 75 | GList * |
| 76 | gkrellm_get_chart_list() |
| 77 | { |
| 78 | return chart_list; |
| 79 | } |
| 80 | |
| 81 | gint |
| 82 | gkrellm_get_chart_scalemax(GkrellmChart *cp) |
| 83 | { |
| 84 | if (!cp) |
| 85 | return 0; |
| 86 | return cp->scale_max; |
| 87 | } |
| 88 | |
| 89 | gint |
| 90 | gkrellm_get_current_chartdata(GkrellmChartdata *cd) |
| 91 | { |
| 92 | if (!cd) |
| 93 | return 0; |
| 94 | return cd->data[cd->chart->position]; |
| 95 | } |
| 96 | |
| 97 | gint |
| 98 | gkrellm_get_chartdata_data(GkrellmChartdata *cd, gint index) |
| 99 | { |
| 100 | gint x; |
| 101 | |
| 102 | if (!cd) |
| 103 | return 0; |
| 104 | x = computed_index(cd->chart, index); |
| 105 | return cd->data[x]; |
| 106 | } |
| 107 | |
| 108 | void |
| 109 | gkrellm_clear_chart(GkrellmChart *cp) |
| 110 | { |
| 111 | if (!cp) |
| 112 | return; |
| 113 | gdk_draw_drawable(cp->pixmap, _GK.draw1_GC, cp->bg_src_pixmap, |
| 114 | 0, 0, 0, 0, cp->w, cp->h); |
| 115 | gdk_draw_drawable(cp->bg_pixmap, _GK.draw1_GC, cp->bg_src_pixmap, |
| 116 | 0, 0, 0, 0, cp->w, cp->h); |
| 117 | if (cp->drawing_area->window) |
| 118 | gdk_draw_drawable(cp->drawing_area->window, _GK.draw1_GC, cp->pixmap, |
| 119 | 0, 0, 0, 0, cp->w, cp->h); |
| 120 | } |
| 121 | |
| 122 | void |
| 123 | gkrellm_clear_chart_pixmap(GkrellmChart *cp) |
| 124 | { |
| 125 | if (!cp) |
| 126 | return; |
| 127 | gdk_draw_drawable(cp->pixmap, _GK.draw1_GC, cp->bg_src_pixmap, |
| 128 | 0, 0, 0, 0, cp->w, cp->h); |
| 129 | gdk_draw_drawable(cp->bg_pixmap, _GK.draw1_GC, cp->bg_src_pixmap, |
| 130 | 0, 0, 0, 0, cp->w, cp->h); |
| 131 | } |
| 132 | |
| 133 | void |
| 134 | gkrellm_clean_bg_src_pixmap(GkrellmChart *cp) |
| 135 | { |
| 136 | if (!cp) |
| 137 | return; |
| 138 | if (!gkrellm_winop_draw_rootpixmap_onto_transparent_chart(cp)) |
| 139 | gdk_draw_drawable(cp->bg_src_pixmap, _GK.draw1_GC, |
| 140 | cp->bg_clean_pixmap, 0, 0, 0, 0, cp->w, cp->h); |
| 141 | cp->bg_sequence_id += 1; |
| 142 | } |
| 143 | |
| 144 | void |
| 145 | gkrellm_draw_chart_grid_line(GkrellmChart *cp, GdkPixmap *pixmap, gint y) |
| 146 | { |
| 147 | gint h; |
| 148 | |
| 149 | if (!cp) |
| 150 | return; |
| 151 | gdk_drawable_get_size(cp->bg_grid_pixmap, NULL((void*)0), &h); |
| 152 | gdk_draw_drawable(pixmap, _GK.draw1_GC, |
| 153 | cp->bg_grid_pixmap, 0, 0, cp->x, y, cp->w, h); |
| 154 | } |
| 155 | |
| 156 | void |
| 157 | gkrellm_draw_chart_to_screen(GkrellmChart *cp) |
| 158 | { |
| 159 | /* Draw the expose pixmap onto the screen. |
| 160 | */ |
| 161 | if (cp && cp->drawing_area->window) |
| 162 | gdk_draw_drawable(cp->drawing_area->window, _GK.draw1_GC, cp->pixmap, |
| 163 | 0, 0, 0, 0, cp->w, cp->h); |
| 164 | } |
| 165 | |
| 166 | static void |
| 167 | default_draw_chart_function(GkrellmChart *cp) |
| 168 | { |
| 169 | if (!cp) |
| 170 | return; |
| 171 | gkrellm_draw_chartdata(cp); |
| 172 | gkrellm_draw_chart_to_screen(cp); |
| 173 | } |
| 174 | |
| 175 | void |
| 176 | gkrellm_set_draw_chart_function(GkrellmChart *cp, void (*func)(), gpointer data) |
| 177 | { |
| 178 | if (!cp) |
| 179 | return; |
| 180 | cp->draw_chart = func; |
| 181 | cp->draw_chart_data = data; |
| 182 | } |
| 183 | |
| 184 | void |
| 185 | gkrellm_scale_chartdata(GkrellmChartdata *cd, gint multiplier, gint divisor) |
| 186 | { |
| 187 | gint i; |
| 188 | |
| 189 | if (!cd || !cd->data || divisor < 1) |
| 190 | return; |
| 191 | for (i = 0; i < cd->chart->w; ++i) |
| 192 | cd->data[i] = cd->data[i] * multiplier / divisor; |
| 193 | cd->previous = cd->previous * multiplier / divisor; |
| 194 | } |
| 195 | |
| 196 | void |
| 197 | gkrellm_offset_chartdata(GkrellmChartdata *cd, gint offset) |
| 198 | { |
| 199 | gint i; |
| 200 | |
| 201 | if (!cd || !cd->data) |
| 202 | return; |
| 203 | for (i = 0; i < cd->chart->w; ++i) |
| 204 | cd->data[i] = cd->data[i] + offset; |
| 205 | cd->previous = cd->previous + offset; |
| 206 | } |
| 207 | |
| 208 | void |
| 209 | gkrellm_reset_chart(GkrellmChart *cp) |
| 210 | { |
| 211 | GList *list; |
| 212 | GkrellmChartdata *cd; |
| 213 | gint i; |
| 214 | |
| 215 | cp->scale_max = 0; |
| 216 | cp->maxval = 0; |
| 217 | cp->redraw_all = TRUE(!(0)); |
| 218 | cp->position = cp->w - 1; |
| 219 | cp->primed = FALSE(0); |
| 220 | |
| 221 | for (list = cp->cd_list; list; list = list->next) |
| 222 | { |
| 223 | cd = (GkrellmChartdata *) list->data; |
| 224 | cd->maxval = 0; |
| 225 | cd->previous = 0; |
| 226 | if (cd->data) |
| 227 | for (i = 0; i < cp->w; ++i) |
| 228 | cd->data[i] = 0; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | void |
| 233 | gkrellm_reset_and_draw_chart(GkrellmChart *cp) |
| 234 | { |
| 235 | if (!cp) |
| 236 | return; |
| 237 | gkrellm_reset_chart(cp); |
| 238 | if (cp->draw_chart) |
| 239 | (*(cp->draw_chart))(cp->draw_chart_data); |
| 240 | } |
| 241 | |
| 242 | void |
| 243 | gkrellm_monotonic_chartdata(GkrellmChartdata *cd, gboolean value) |
| 244 | { |
| 245 | if (cd) |
| 246 | cd->monotonic = value; |
| 247 | } |
| 248 | |
| 249 | void |
| 250 | gkrellm_set_chartdata_draw_style(GkrellmChartdata *cd, gint dstyle) |
| 251 | { |
| 252 | if (cd) |
| 253 | cd->draw_style = dstyle; |
| 254 | } |
| 255 | |
| 256 | void |
| 257 | gkrellm_set_chartdata_draw_style_default(GkrellmChartdata *cd, gint dstyle) |
| 258 | { |
| 259 | if (cd && cd->chart->config && !cd->chart->config->config_loaded) |
| 260 | cd->draw_style = dstyle; |
| 261 | } |
| 262 | |
| 263 | void |
| 264 | gkrellm_set_chartdata_flags(GkrellmChartdata *cd, gint flags) |
| 265 | { |
| 266 | if (cd) |
| 267 | cd->flags = flags; |
| 268 | } |
| 269 | |
| 270 | static gint |
| 271 | chartdata_ycoord(GkrellmChart *cp, GkrellmChartdata *cd, gint yd) |
| 272 | { |
| 273 | glong y; |
| 274 | guint64 Y; |
| 275 | |
| 276 | if (cp->scale_max <= 0) |
| 277 | cp->scale_max = 1; |
| 278 | |
| 279 | if (yd > 2000000000 / MAX_CHARTHEIGHT200) |
| 280 | { |
| 281 | Y = (guint64) yd * (guint64) cd->h; |
| 282 | y = Y / cp->scale_max; |
| 283 | } |
| 284 | else |
| 285 | y = ((glong) yd * cd->h / cp->scale_max); |
| 286 | |
| 287 | if (y < 0) |
| 288 | y = 0; |
| 289 | if (y >= cd->h) |
| 290 | y = cd->h - 1; |
| 291 | if (cd->inverted) |
| 292 | y = cd->h - y - 1; |
| 293 | y += cd->y; |
| 294 | return Y_SCREEN_MAP(cp, y)((cp)->h - (y) - 1); |
| 295 | } |
| 296 | |
| 297 | static void |
| 298 | draw_layer_grid_lines(GkrellmChart *cp) |
| 299 | { |
| 300 | GList *list; |
| 301 | GkrellmChartdata *cd; |
| 302 | gint y, y0, h, grid_res, lines; |
| 303 | gint active_split, current_split; |
| 304 | gboolean do_next_split, done_once_per_split, tmp; |
| 305 | |
| 306 | gdk_draw_drawable(cp->bg_pixmap, _GK.draw1_GC, |
| 307 | cp->bg_src_pixmap, 0, 0, 0, 0, cp->w, cp->h); |
| 308 | do_next_split = TRUE(!(0)); |
| 309 | for (active_split = 0; do_next_split; ++active_split) |
| 310 | { |
| 311 | do_next_split = FALSE(0); |
| 312 | done_once_per_split = FALSE(0); |
| 313 | current_split = 0; |
| 314 | for (list = cp->cd_list; list; list = list->next) |
| 315 | { |
| 316 | cd = (GkrellmChartdata *) list->data; |
| 317 | if (cd->hide) |
| 318 | continue; |
| 319 | current_split += cd->split_chart; |
| 320 | if (active_split != current_split) |
| 321 | { |
| 322 | if (current_split > active_split) |
| 323 | do_next_split = TRUE(!(0)); |
| 324 | continue; |
| 325 | } |
| 326 | gdk_draw_drawable(cd->layer.pixmap, _GK.draw1_GC, |
| 327 | *(cd->layer.src_pixmap), 0, 0, 0, 0, cp->w, cp->h); |
| 328 | |
| 329 | grid_res = cp->config->grid_resolution; |
| 330 | lines = cp->scale_max / grid_res; |
| 331 | if (lines && cd->h / lines > 2) /* No grids if h is too small */ |
| 332 | { |
| 333 | for (y = 0; y <= cp->scale_max; y += grid_res) |
| 334 | { |
| 335 | if ( _GK.bg_grid_mode == GRID_MODE_RESTRAINED1 |
| 336 | && ((y == 0 && cp->y == 0) || y == cp->scale_max) |
| 337 | ) |
| 338 | continue; |
| 339 | tmp = cd->inverted; /* Draw grid lines in one direction*/ |
| 340 | cd->inverted = FALSE(0); /* else, may not line up by 1 pixel*/ |
| 341 | y0 = chartdata_ycoord(cp, cd, y); |
| 342 | cd->inverted = tmp; |
| 343 | gdk_drawable_get_size(cd->layer.grid_pixmap, NULL((void*)0), &h); |
| 344 | gdk_draw_drawable(cd->layer.pixmap, _GK.draw1_GC, |
| 345 | cd->layer.grid_pixmap, 0, 0, cp->x, y0, cp->w, h); |
| 346 | |
| 347 | if (!done_once_per_split) |
| 348 | { |
| 349 | gdk_drawable_get_size(cp->bg_grid_pixmap, NULL((void*)0), &h); |
| 350 | gdk_draw_drawable(cp->bg_pixmap, _GK.draw1_GC, |
| 351 | cp->bg_grid_pixmap, 0, 0, cp->x, y0, cp->w, h); |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | if (current_split > 0 && !done_once_per_split) |
| 356 | { |
| 357 | y = cd->y - 1; /* Get separator y value */ |
| 358 | y -= GRID_HEIGHT_Y_OFFSET_ADJUST(cp)(( gdk_pixbuf_get_height((cp)->bg_grid_piximage->pixbuf ) < 2) ? 0 : 1); |
| 359 | if (y >= 0) |
| 360 | { |
| 361 | gdk_draw_drawable(cp->bg_pixmap, _GK.draw1_GC, |
| 362 | _GK.bg_separator_pixmap, |
| 363 | 0, 0, cp->x, Y_SCREEN_MAP(cp, y)((cp)->h - (y) - 1), |
| 364 | cp->w, _GK.bg_separator_height); |
| 365 | } |
| 366 | } |
| 367 | done_once_per_split = TRUE(!(0)); |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | /* Return TRUE as long as there is a next split with impulse data needing |
| 373 | | to be drawn. |
| 374 | */ |
| 375 | static gboolean |
| 376 | draw_chartdata_impulses(GkrellmChart *cp, GList *cd_list, |
| 377 | gint i0, gint active_split) |
| 378 | { |
| 379 | GList *list; |
| 380 | GkrellmChartdata *cd; |
| 381 | gint n, x, y, y0, y1, yN, yI; |
| 382 | gint current_split; |
| 383 | gboolean need_next_split = FALSE(0); |
| 384 | |
| 385 | if (!cd_list) |
| 386 | return FALSE(0); |
| 387 | for (n = i0; n < cp->w; ++n) |
| 388 | { |
| 389 | x = computed_index(cp, n); |
| 390 | y0 = y1 = -1; |
| 391 | yN = yI = 0; |
| 392 | current_split = 0; |
| 393 | for (list = cp->cd_list; list; list= list->next) |
| 394 | { |
| 395 | cd = (GkrellmChartdata *) list->data; |
| 396 | if (cd->hide) |
| 397 | continue; |
| 398 | current_split += cd->split_chart; |
| 399 | if ( cd->draw_style != CHARTDATA_IMPULSE0 |
| 400 | || current_split != active_split |
| 401 | ) |
| 402 | { |
| 403 | if ( current_split > active_split |
| 404 | && cd->draw_style == CHARTDATA_IMPULSE0 |
| 405 | ) |
| 406 | need_next_split = TRUE(!(0)); |
| 407 | continue; |
| 408 | } |
| 409 | if (cd->inverted) |
| 410 | { |
| 411 | if (y1 < 0) |
| 412 | y1 = chartdata_ycoord(cp, cd, 0); |
| 413 | yI += cd->data[x]; |
| 414 | y = chartdata_ycoord(cp, cd, yI); |
| 415 | if (cd->data[x] > 0) |
| 416 | gdk_draw_line(cd->data_bitmap, _GK.bit1_GC, n, y1, n, y); |
| 417 | y1 = y; |
| 418 | } |
| 419 | else |
| 420 | { |
| 421 | if (y0 < 0) |
| 422 | y0 = chartdata_ycoord(cp, cd, 0); |
| 423 | yN += cd->data[x]; |
| 424 | y = chartdata_ycoord(cp, cd, yN); |
| 425 | if (cd->data[x] > 0) |
| 426 | gdk_draw_line(cd->data_bitmap, _GK.bit1_GC, n, y0, n, y); |
| 427 | y0 = y; |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | /* Push the grided pixmaps through the data bitmaps onto the expose pixmap |
| 432 | */ |
| 433 | current_split = 0; |
| 434 | for (list = cp->cd_list; list; list = list->next) |
| 435 | { |
| 436 | cd = (GkrellmChartdata *) list->data; |
| 437 | if (cd->hide) |
| 438 | continue; |
| 439 | current_split += cd->split_chart; |
| 440 | if (cd->draw_style == CHARTDATA_LINE1 || current_split != active_split) |
| 441 | continue; |
| 442 | if (cd->maxval > 0) |
| 443 | { |
| 444 | y0 = chartdata_ycoord(cp, cd, 0); |
| 445 | y1 = chartdata_ycoord(cp, cd, cd->maxval); |
| 446 | gdk_gc_set_clip_mask(_GK.draw1_GC, cd->data_bitmap); |
| 447 | if (cd->inverted) |
| 448 | gdk_draw_drawable(cp->pixmap, _GK.draw1_GC, cd->layer.pixmap, |
| 449 | 0, y0, 0, y0, cp->w, y1 - y0 + 1); |
| 450 | else |
| 451 | gdk_draw_drawable(cp->pixmap, _GK.draw1_GC, cd->layer.pixmap, |
| 452 | 0, y1, 0, y1, cp->w, y0 - y1 + 1); |
| 453 | } |
| 454 | } |
| 455 | return need_next_split; |
| 456 | } |
| 457 | |
| 458 | static gint |
| 459 | fix_y(gint yn, gint yp, gint ypp) |
| 460 | { |
| 461 | gint y; |
| 462 | |
| 463 | if (yp > ypp && yn < yp) |
| 464 | { |
| 465 | y = (yp + yn) / 2; |
| 466 | if (y < ypp) |
| 467 | y = ypp; |
| 468 | } |
| 469 | else if (yp < ypp && yn > yp) |
| 470 | { |
| 471 | y = (yp + yn) / 2; |
| 472 | if (y > ypp) |
| 473 | y = ypp; |
| 474 | } |
| 475 | else |
| 476 | y = yp; |
| 477 | return y; |
| 478 | } |
| 479 | |
| 480 | static void |
| 481 | draw_chartdata_lines(GkrellmChart *cp, GkrellmChartdata *cd, gint i0) |
| 482 | { |
| 483 | gint n, x, xp, y, y0, y1; |
| 484 | |
| 485 | y0 = chartdata_ycoord(cp, cd, 0); |
| 486 | for (n = i0; n < cp->w; ++n) |
| 487 | { |
| 488 | x = computed_index(cp, n); |
| 489 | y1 = chartdata_ycoord(cp, cd, cd->data[x]); |
| 490 | if (n == 0) |
| 491 | cd->y_p = y1; |
| 492 | else if (!cd->y_p_valid && i0 == cp->w - 1) |
| 493 | { |
| 494 | if ((xp = x - 1) < 0) |
| 495 | xp = cp->w - 1; |
| 496 | cd->y_p = cd->y_pp = chartdata_ycoord(cp, cd, cd->data[xp]); |
| 497 | } |
| 498 | y = fix_y(y1, cd->y_p, cd->y_pp); |
| 499 | cd->y_pp = y; |
| 500 | cd->y_p = y1; |
| 501 | cd->y_p_valid = FALSE(0); /* Need a store_chartdata to make it valid */ |
| 502 | if (cd->data[x] > 0 || (cd->inverted ? (y > y0) : (y < y0))) |
| 503 | { |
| 504 | if (y == y1) |
| 505 | gdk_draw_point(cd->data_bitmap, _GK.bit1_GC, cp->x + n, y1); |
| 506 | else |
| 507 | gdk_draw_line(cd->data_bitmap, _GK.bit1_GC, |
| 508 | cp->x + n, y, cp->x + n, y1); |
| 509 | } |
| 510 | } |
| 511 | /* Push the grided pixmap through the data bitmap onto the expose pixmap |
| 512 | */ |
| 513 | if (cd->maxval > 0) |
| 514 | { |
| 515 | y0 = chartdata_ycoord(cp, cd, 0); |
| 516 | y1 = chartdata_ycoord(cp, cd, cd->maxval); |
| 517 | gdk_gc_set_clip_mask(_GK.draw1_GC, cd->data_bitmap); |
| 518 | if (cd->inverted) |
| 519 | gdk_draw_drawable(cp->pixmap, _GK.draw1_GC, cd->layer.pixmap, |
| 520 | 0, y0, 0, y0, cp->w, y1 - y0 + 1); |
| 521 | else |
| 522 | gdk_draw_drawable(cp->pixmap, _GK.draw1_GC, cd->layer.pixmap, |
| 523 | 0, y1, 0, y1, cp->w, y0 - y1 + 1); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | /* See the README for description of auto grid resolution behavior. |
| 528 | */ |
| 529 | static void |
| 530 | set_auto_grid_resolution(GkrellmChart *cp, gint maxval) |
| 531 | { |
| 532 | GkrellmChartconfig *cf = cp->config; |
| 533 | gint grids, grid_res, maxval_base; |
| 534 | |
| 535 | if (maxval <= cp->maxval_auto_base) |
| 536 | maxval = cp->maxval_auto_base; |
| 537 | else |
| 538 | { |
| 539 | if (maxval > cp->maxval_peak) |
| 540 | cp->maxval_peak = maxval; |
| 541 | maxval_base = maxval / FULL_SCALE_GRIDS5; |
| 542 | if (maxval_base > cp->maxval_auto_base) |
| 543 | cp->maxval_auto_base = maxval_base; |
| 544 | } |
| 545 | cp->maxval_auto = maxval; |
| 546 | |
| 547 | grids = cf->fixed_grids; |
| 548 | if (grids == 0) /* Auto grids mode */ |
| 549 | grid_res = gkrellm_125_sequence(cp->maxval_auto_base, cf->sequence_125, |
| 550 | cf->low, cf->high, TRUE(!(0)), FALSE(0)); |
| 551 | else |
| 552 | { |
| 553 | if (cf->auto_resolution_stick) |
| 554 | maxval = cp->maxval_peak; |
| 555 | grid_res = gkrellm_125_sequence(maxval / grids, cf->sequence_125, |
| 556 | cf->low, cf->high, TRUE(!(0)), TRUE(!(0))); |
| 557 | } |
| 558 | if (grid_res != cf->grid_resolution) |
| 559 | { |
| 560 | cf->grid_resolution = grid_res; |
| 561 | set_grid_resolution_spin_button(cp, grid_res); |
| 562 | if (cf->cb_grid_resolution && !cf->cb_block) |
| 563 | (*cf->cb_grid_resolution)(cf, cf->cb_grid_resolution_data); |
| 564 | cp->redraw_all = TRUE(!(0)); |
| 565 | } |
| 566 | cp->auto_recalibrate_delay = 0; |
| 567 | } |
| 568 | |
| 569 | static gboolean |
| 570 | auto_recalibrate(GkrellmChart *cp) |
| 571 | { |
| 572 | if (++cp->auto_recalibrate_delay < 10) |
| 573 | return FALSE(0); |
| 574 | cp->maxval_peak = 0; |
| 575 | cp->maxval_auto_base = 0; |
| 576 | return TRUE(!(0)); |
| 577 | } |
| 578 | |
| 579 | static gint |
| 580 | setup_chart_scalemax(GkrellmChart *cp) |
| 581 | { |
| 582 | GkrellmChartconfig *cf = cp->config; |
| 583 | glong scalemax; |
| 584 | gint grid_res, i0; |
| 585 | |
| 586 | /* maxval may change at any gkrellm_store_chartdata(), so at each chart |
| 587 | | draw compute a scalemax and compare to last cp->scale_max. |
| 588 | | Redraw grided background if different. |
| 589 | */ |
| 590 | if (cf->auto_grid_resolution) |
| 591 | { |
| 592 | if ( cp->maxval != cp->maxval_auto |
| 593 | && ( cp->maxval > cp->maxval_auto |
| 594 | || cp->maxval_auto != cp->maxval_auto_base |
| 595 | ) |
| 596 | ) |
| 597 | set_auto_grid_resolution(cp, cp->maxval); |
| 598 | else if ( !cf->auto_resolution_stick |
| 599 | && cp->maxval < cp->maxval_auto_base / FULL_SCALE_GRIDS5 |
| 600 | ) |
| 601 | { |
| 602 | if (auto_recalibrate(cp)) |
| 603 | set_auto_grid_resolution(cp, cp->maxval); |
| 604 | } |
| 605 | else |
| 606 | cp->auto_recalibrate_delay = 0; |
| 607 | } |
| 608 | grid_res = cf->grid_resolution; |
| 609 | if (cf->fixed_grids) |
| 610 | scalemax = grid_res * cf->fixed_grids; |
| 611 | else /* Auto scale to cp->maxval */ |
| 612 | { |
| 613 | if (cp->maxval == 0) |
| 614 | scalemax = grid_res; |
| 615 | else |
| 616 | scalemax = ((cp->maxval - 1) / grid_res + 1) * grid_res; |
| 617 | if (cp->previous_total && scalemax > grid_res * FULL_SCALE_GRIDS5) |
| 618 | scalemax = grid_res * FULL_SCALE_GRIDS5; |
| 619 | } |
| 620 | if (scalemax != cp->scale_max || cp->redraw_all) |
| 621 | { |
| 622 | cp->redraw_all = FALSE(0); |
| 623 | i0 = 0; /* Will draw all data on chart */ |
| 624 | cp->scale_max = scalemax; |
| 625 | draw_layer_grid_lines(cp); |
| 626 | } |
| 627 | else |
| 628 | i0 = cp->w - 1; /* Will draw the last data point only */ |
| 629 | return i0; |
| 630 | } |
| 631 | |
| 632 | void |
| 633 | gkrellm_draw_chartdata(GkrellmChart *cp) |
| 634 | { |
| 635 | GList *list; |
| 636 | GkrellmChartdata *cd; |
| 637 | gint i0, active_split, current_split; |
| 638 | gboolean have_impulse_splits = FALSE(0); |
| 639 | |
| 640 | if (!cp) |
| 641 | return; |
| 642 | i0 = setup_chart_scalemax(cp); |
| 643 | gdk_draw_drawable(cp->pixmap, _GK.draw1_GC, cp->bg_pixmap, |
| 644 | 0, 0, 0, 0, cp->w, cp->h); |
| 645 | |
| 646 | current_split = active_split = 0; |
| 647 | for (list = cp->cd_list; list; list = list->next) |
| 648 | { |
| 649 | cd = (GkrellmChartdata *) list->data; |
| 650 | if (cd->hide) |
| 651 | continue; |
| 652 | current_split += cd->split_chart; |
| 653 | if (!have_impulse_splits && cd->draw_style == CHARTDATA_IMPULSE0) |
| 654 | { |
| 655 | have_impulse_splits = TRUE(!(0)); |
| 656 | active_split = current_split; |
| 657 | } |
| 658 | /* Clear the area of the data bitmaps that data will be drawn into |
| 659 | */ |
| 660 | gdk_draw_rectangle(cd->data_bitmap, _GK.bit0_GC, TRUE(!(0)), |
| 661 | i0, 0, cd->w - i0, cp->h); |
| 662 | } |
| 663 | |
| 664 | for ( ; have_impulse_splits; ++active_split) |
| 665 | have_impulse_splits = draw_chartdata_impulses(cp, cp->cd_list, |
| 666 | i0, active_split); |
| 667 | |
| 668 | for (list = cp->cd_list; list; list = list->next) |
| 669 | { |
| 670 | cd = (GkrellmChartdata *) list->data; |
| 671 | if (cd->draw_style == CHARTDATA_LINE1 && !cd->hide) |
| 672 | draw_chartdata_lines(cp, cd, i0); |
| 673 | } |
| 674 | gdk_gc_set_clip_mask(_GK.draw1_GC, NULL((void*)0)); |
| 675 | } |
| 676 | |
| 677 | void |
| 678 | gkrellm_alloc_chartdata(GkrellmChart *cp) |
| 679 | { |
| 680 | GList *list; |
| 681 | GkrellmChartdata *cd; |
| 682 | size_t w; |
| 683 | |
| 684 | if (!cp) |
| 685 | return; |
| 686 | w = (size_t) cp->w; |
| 687 | for (list = cp->cd_list; list; list = list->next) |
| 688 | { |
| 689 | cd = (GkrellmChartdata *) list->data; |
| 690 | if (cd->w == w && cd->data) |
| 691 | continue; |
| 692 | cd->w = w; |
| 693 | if (cd->data) |
| 694 | g_free(cd->data); |
| 695 | cd->data = (gint *) g_new0(gint, w)(gint *) (__extension__ ({ gsize __n = (gsize) (w); gsize __s = sizeof (gint); gpointer __p; if (__s == 1) __p = g_malloc0 (__n); else if (__builtin_constant_p (__n) && (__s == 0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p = g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p ; })); |
| 696 | cd->maxval = 0; |
| 697 | cp->position = cp->w - 1; |
| 698 | cp->tail = cp->position; |
| 699 | } |
| 700 | cp->alloc_width = w; |
| 701 | cp->maxval = 0; |
| 702 | cp->scale_max = 0; |
| 703 | cp->redraw_all = TRUE(!(0)); |
| 704 | } |
| 705 | |
| 706 | static void |
| 707 | scroll_chartdata_bitmaps(GkrellmChart *cp) |
| 708 | { |
| 709 | GList *list; |
| 710 | GkrellmChartdata *cd; |
| 711 | |
| 712 | for (list = cp->cd_list; list; list = list->next) |
| 713 | { |
| 714 | cd = (GkrellmChartdata *) list->data; |
| 715 | if (cd->hide) |
| 716 | continue; |
| 717 | gdk_draw_drawable(cd->data_bitmap, _GK.bit1_GC, cd->data_bitmap, |
| 718 | 1, 0, 0, 0, cp->w - 1, cp->h); |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | static gboolean |
| 723 | scan_for_impulse_maxval(GkrellmChart *cp, gint active_split) |
| 724 | { |
| 725 | GList *list; |
| 726 | GkrellmChartdata *cd; |
| 727 | gint N, I; |
| 728 | gint i, current_split; |
| 729 | gboolean need_next_split = FALSE(0); |
| 730 | |
| 731 | for (i = 0; i < cp->w; ++i) |
| 732 | { |
| 733 | /* N is normal and I inverted cumulative impulse data/split |
| 734 | */ |
| 735 | N = I = 0; |
| 736 | current_split = 0; |
| 737 | for (list = cp->cd_list; list; list = list->next) |
| 738 | { |
| 739 | cd = (GkrellmChartdata *) list->data; |
| 740 | if (cd->hide) |
| 741 | continue; |
| 742 | current_split += cd->split_chart; |
| 743 | if ( cd->draw_style != CHARTDATA_IMPULSE0 |
| 744 | || current_split != active_split |
| 745 | ) |
| 746 | { |
| 747 | if ( current_split > active_split |
| 748 | && cd->draw_style == CHARTDATA_IMPULSE0 |
| 749 | ) |
| 750 | need_next_split = TRUE(!(0)); |
| 751 | continue; |
| 752 | } |
| 753 | if (cd->inverted) |
| 754 | { |
| 755 | I += cd->data[i]; |
| 756 | if (I > cd->maxval) |
| 757 | cd->maxval = I; |
| 758 | } |
| 759 | else |
| 760 | { |
| 761 | N += cd->data[i]; |
| 762 | if (N > cd->maxval) |
| 763 | cd->maxval = N; |
| 764 | } |
| 765 | if (N + I > cp->maxval) |
| 766 | cp->maxval = N + I; |
| 767 | } |
| 768 | } |
| 769 | return need_next_split; |
| 770 | } |
| 771 | |
| 772 | static void |
| 773 | scan_for_maxval(GkrellmChart *cp) |
| 774 | { |
| 775 | GList *list; |
| 776 | GkrellmChartdata *cd; |
| 777 | gint i, current_split, active_split; |
| 778 | gboolean have_impulse_splits = FALSE(0); |
| 779 | |
| 780 | cp->maxval = 0; |
| 781 | current_split = 0; |
| 782 | active_split = 0; |
| 783 | for (list = cp->cd_list; list; list = list->next) |
| 784 | { |
| 785 | cd = (GkrellmChartdata *) list->data; |
| 786 | if (cd->hide) |
| 787 | continue; |
| 788 | cd->maxval = 0; |
| 789 | current_split += cd->split_chart; |
| 790 | if (cd->draw_style == CHARTDATA_LINE1) |
| 791 | for (i = 0; i < cp->w; ++i) |
| 792 | { |
| 793 | if (cd->data[i] > cd->maxval) |
| 794 | cd->maxval = cd->data[i]; |
| 795 | if (cd->maxval > cp->maxval) |
| 796 | cp->maxval = cd->maxval; |
| 797 | } |
| 798 | if (!have_impulse_splits && cd->draw_style == CHARTDATA_IMPULSE0) |
| 799 | { |
| 800 | have_impulse_splits = TRUE(!(0)); |
| 801 | active_split = current_split; |
| 802 | } |
| 803 | } |
| 804 | for ( ; have_impulse_splits; ++active_split) |
| 805 | have_impulse_splits = scan_for_impulse_maxval(cp, active_split); |
| 806 | } |
| 807 | |
| 808 | void |
| 809 | gkrellm_store_chartdata(GkrellmChart *cp, gulong total, ...) |
| 810 | { |
| 811 | va_list args; |
| 812 | |
| 813 | if (!cp) |
| 814 | return; |
| 815 | va_start(args, total)__builtin_va_start(args, total); |
| 816 | gkrellm_store_chartdatav(cp, total, args); |
| 817 | va_end(args)__builtin_va_end(args); |
| 818 | } |
| 819 | |
| 820 | void |
| 821 | gkrellm_store_chartdatav(GkrellmChart *cp, gulong total, va_list args) |
| 822 | { |
| 823 | GList *list; |
| 824 | GkrellmChartdata *cd; |
| 825 | gulong range, total_diff; |
| 826 | gint n, N_discard, I_discard, N, I; |
| 827 | gint active_split, current_split; |
| 828 | gboolean need_scan = FALSE(0); |
| 829 | |
| 830 | if (!cp) |
| 831 | return; |
| 832 | for (list = cp->cd_list; list; list = list->next) |
| 833 | { |
| 834 | cd = (GkrellmChartdata *) list->data; |
| 835 | //FIXME: missing check for number of passed varargs passed in "args" |
| 836 | cd->current = va_arg(args, gulong)__builtin_va_arg(args, gulong); |
| 837 | if (!cd->monotonic) |
| 838 | { |
| 839 | cd->previous = 0; |
| 840 | cp->previous_total = 0; /* All or none if total is used */ |
| 841 | } |
| 842 | /* Prime the pump. Also handle data wrap around or reset to zero. |
| 843 | */ |
| 844 | if (cd->current < cd->previous || !cp->primed) |
| 845 | cd->previous = cd->current; |
| 846 | } |
| 847 | if (total < cp->previous_total || !cp->primed) |
| 848 | cp->previous_total = total; /* Wrap around, this store won't scale */ |
| 849 | total_diff = total - cp->previous_total; |
| 850 | cp->previous_total = total; |
| 851 | |
| 852 | /* Increment position in circular buffer and remember the data |
| 853 | | value to be thrown out. |
| 854 | */ |
| 855 | cp->position = (cp->position + 1) % cp->w; |
| 856 | cp->tail = (cp->tail + 1) % cp->w; |
| 857 | n = cp->position; |
| 858 | active_split = current_split = 0; |
| 859 | N_discard = I_discard = 0; |
| 860 | |
| 861 | /* N is normal and I inverted cumulative impulse data/split |
| 862 | */ |
| 863 | N = I = 0; |
| 864 | for (list = cp->cd_list; list; list = list->next) |
| 865 | { |
| 866 | cd = (GkrellmChartdata *) list->data; |
| 867 | cd->discard = cd->data[cp->tail]; |
| 868 | cd->data[n] = (gint)(cd->current - cd->previous); |
| 869 | cd->previous = cd->current; |
| 870 | |
| 871 | /* If using totals, scale the stored data to range between 0 and the |
| 872 | | max chart value. Max chart value is number of grids * grid res. |
| 873 | | No. of grids is 5 in auto grid mode. For plotting data as a %. |
| 874 | */ |
| 875 | if (total_diff > 0) |
| 876 | { |
| 877 | range = (cp->config->fixed_grids ? cp->config->fixed_grids |
| 878 | : FULL_SCALE_GRIDS5) * cp->config->grid_resolution; |
| 879 | if (range != total_diff) |
| 880 | cd->data[n] = cd->data[n] * range / total_diff; |
| 881 | } |
| 882 | if (cd->hide || need_scan) |
| 883 | continue; |
| 884 | |
| 885 | /* Compare discarded data to new data (accounting for stacked impulse |
| 886 | | data) and decide if a new maxval must be set (new data > maxval) |
| 887 | | or if a complete rescan of the data is needed to find a new |
| 888 | | maxval (a discard > a new). |
| 889 | */ |
| 890 | current_split += cd->split_chart; |
| 891 | if (cd->draw_style == CHARTDATA_IMPULSE0) |
| 892 | { |
| 893 | if (current_split != active_split) |
| 894 | { |
| 895 | active_split = current_split; |
| 896 | N_discard = I_discard = 0; |
| 897 | N = I = 0; |
| 898 | } |
| 899 | if (cd->inverted) |
| 900 | { |
| 901 | I_discard += cd->discard; |
| 902 | I += cd->data[n]; |
| 903 | if (I_discard && I_discard >= cd->maxval) |
| 904 | need_scan = TRUE(!(0)); |
| 905 | else if (I > cd->maxval) |
| 906 | cd->maxval = I; |
| 907 | } |
| 908 | else |
| 909 | { |
| 910 | N_discard += cd->discard; |
| 911 | N += cd->data[n]; |
| 912 | if (N_discard && N_discard >= cd->maxval) |
| 913 | need_scan = TRUE(!(0)); |
| 914 | else if (N > cd->maxval) |
| 915 | cd->maxval = N; |
| 916 | } |
| 917 | if (N_discard + I_discard >= cd->maxval) |
| 918 | need_scan = TRUE(!(0)); |
| 919 | else if (N + I > cp->maxval) |
| 920 | cp->maxval = N + I; |
| 921 | } |
| 922 | else if (cd->draw_style == CHARTDATA_LINE1) |
| 923 | { |
| 924 | cd->y_p_valid = TRUE(!(0)); |
| 925 | if (cd->discard && cd->discard >= cd->maxval) |
| 926 | need_scan = TRUE(!(0)); |
| 927 | else |
| 928 | { |
| 929 | if (cd->data[n] > cd->maxval) |
| 930 | cd->maxval = cd->data[n]; |
| 931 | if (cd->maxval > cp->maxval) |
| 932 | cp->maxval = cd->maxval; |
| 933 | } |
| 934 | } |
| 935 | } |
| 936 | cp->primed = TRUE(!(0)); |
| 937 | if (need_scan || cp->redraw_all) |
| 938 | scan_for_maxval(cp); |
| 939 | scroll_chartdata_bitmaps(cp); |
| 940 | } |
| 941 | |
| 942 | |
| 943 | |
| 944 | /* =================================================================== */ |
| 945 | |
| 946 | static void |
| 947 | chart_destroy_text_run_list(GkrellmChart *cp) |
| 948 | { |
| 949 | GList *list; |
| 950 | |
| 951 | if (!cp || !cp->text_run_list) |
| 952 | return; |
| 953 | for (list = cp->text_run_list; list; list = list->next) |
| 954 | g_free(((GkrellmTextRun *) list->data)->text); |
| 955 | gkrellm_free_glist_and_data(&cp->text_run_list); |
| 956 | } |
| 957 | |
| 958 | static gint |
| 959 | chartdata_text_y(GkrellmChart *cp, char key, gint height, |
| 960 | gint y_ink, gint shadow) |
| 961 | { |
| 962 | GList *list; |
| 963 | GkrellmChartdata *cd; |
| 964 | gint n, y; |
| 965 | |
| 966 | n = key - '0'; |
| 967 | y = -100; |
| 968 | if (n >= 0) |
| 969 | { |
| 970 | list = g_list_nth(cp->cd_list, n / 2); |
| 971 | if (list) |
| 972 | { |
| 973 | cd = (GkrellmChartdata *) list->data; |
| 974 | if (!cd->hide) |
| 975 | { |
| 976 | if (n & 1) /* Justify 2 pixels from top of ChartData view */ |
| 977 | { |
| 978 | y = cd->y + cd->h + y_ink - 3; |
| 979 | } |
| 980 | else /* Justify to bottom of ChartData view */ |
| 981 | { |
| 982 | y = cd->y + height + y_ink + shadow - 1; |
| 983 | } |
| 984 | y = Y_SCREEN_MAP(cp, y)((cp)->h - (y) - 1); |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | return y; |
| 989 | } |
| 990 | |
| 991 | void |
| 992 | gkrellm_chart_reuse_text_format(GkrellmChart *cp) |
| 993 | { |
| 994 | cp->text_format_reuse = TRUE(!(0)); |
| 995 | } |
| 996 | |
| 997 | void |
| 998 | gkrellm_draw_chart_text(GkrellmChart *cp, gint style_id, gchar *str) |
| 999 | { |
| 1000 | GList *list; |
| 1001 | GkrellmTextRun *tr; |
| 1002 | GkrellmTextstyle *ts, *ts_default, *ts_alt; |
| 1003 | gchar c, *s, *t; |
| 1004 | gint h, text_length, field_width, fw; |
| 1005 | gint offset; |
| 1006 | gint xx, x, y, center, shadow; |
| 1007 | gboolean right, set_fw, fw_right; |
| 1008 | |
| 1009 | if (!cp || !str) |
| 1010 | return; |
| 1011 | |
| 1012 | /* Assume text_format will be changed at each call unless caller has said |
| 1013 | | we can reuse it or the whole string compares equal. |
| 1014 | */ |
| 1015 | if ( !cp->text_format_reuse |
| 1016 | && !gkrellm_dup_string(&cp->text_format_string, str) |
| 1017 | ) |
| 1018 | cp->text_format_reuse = TRUE(!(0)); |
| 1019 | |
| 1020 | if (_GK.debug_level & DEBUG_CHART_TEXT0x10000) |
| 1021 | { |
| 1022 | g_debug("\n"); |
| 1023 | if (!cp->text_format_reuse) |
| 1024 | g_debug("draw_chart_text: [%s]\n", str); |
| 1025 | } |
| 1026 | |
| 1027 | if ( !cp->text_format_reuse |
| 1028 | || cp->text_run_sequence_id != cp->bg_sequence_id |
| 1029 | ) |
| 1030 | chart_destroy_text_run_list(cp); |
| 1031 | cp->text_run_sequence_id = cp->bg_sequence_id; |
| 1032 | cp->text_format_reuse = FALSE(0); |
| 1033 | |
| 1034 | ts_default = gkrellm_chart_textstyle(style_id); |
| 1035 | ts_alt = gkrellm_chart_alt_textstyle(style_id); |
| 1036 | |
| 1037 | x = xx = 2; |
| 1038 | if (!cp->text_run_list) |
| 1039 | gkrellm_text_extents(ts_default->font, _("Ag8")dcgettext ("gkrellm", "Ag8", 5), 3, NULL((void*)0), |
| 1040 | &cp->h_text, &cp->baseline_ref, &cp->y_ink); |
| 1041 | |
| 1042 | y = 2 - cp->y_ink; |
| 1043 | h = fw = 0; |
| 1044 | tr = NULL((void*)0); |
| 1045 | for (list = cp->text_run_list, s = str; *s; s += text_length) |
| 1046 | { |
| 1047 | if (!list) |
| 1048 | { |
| 1049 | tr = g_new0(GkrellmTextRun, 1)(GkrellmTextRun *) (__extension__ ({ gsize __n = (gsize) (1); gsize __s = sizeof (GkrellmTextRun); gpointer __p; if (__s == 1) __p = g_malloc0 (__n); else if (__builtin_constant_p (__n ) && (__s == 0 || __n <= (9223372036854775807L *2UL +1UL) / __s)) __p = g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p; })); |
| 1050 | cp->text_run_list = g_list_append(cp->text_run_list, tr); |
| 1051 | } |
| 1052 | else |
| 1053 | { |
| 1054 | tr = (GkrellmTextRun *) list->data; |
| 1055 | list = list->next; |
| 1056 | tr->cache_valid = TRUE(!(0)); |
| 1057 | } |
| 1058 | c = '\0'; |
Value stored to 'c' is never read | |
| 1059 | center = 0; |
| 1060 | right = FALSE(0); |
| 1061 | set_fw = FALSE(0); |
| 1062 | fw_right = FALSE(0); |
| 1063 | ts = ts_default; |
| 1064 | field_width = 0; |
| 1065 | shadow = ts_default->effect ? 1 : 0; |
| 1066 | while (*s == '\\') |
| 1067 | { |
| 1068 | if ((c = *(++s)) != '\0') |
| 1069 | ++s; |
| 1070 | if (c == 'n') |
| 1071 | { |
| 1072 | y += cp->h_text + 1; |
| 1073 | x = xx; |
| 1074 | } |
| 1075 | else if (c == 'c') |
| 1076 | center = 1; |
| 1077 | else if (c == 'C') |
| 1078 | center = 2; |
| 1079 | else if (c == 'N') |
| 1080 | { |
| 1081 | x = xx; /* A conditional newline. If previous string */ |
| 1082 | if (h > 2) /* was spaces, no nl. A space has nonzero a */ |
| 1083 | y += cp->h_text + 1; |
| 1084 | } |
| 1085 | else if (c == 'b') |
| 1086 | { |
| 1087 | y = cp->h - cp->h_text - cp->y_ink - 1; |
| 1088 | x = xx; |
| 1089 | } |
| 1090 | else if (c == 't') |
| 1091 | { |
| 1092 | y = 2 - cp->y_ink; |
| 1093 | x = xx; |
| 1094 | } |
| 1095 | else if (c == 'r') |
| 1096 | right = TRUE(!(0)); |
| 1097 | else if (c == 'p') |
| 1098 | { |
| 1099 | y -= cp->h_text + 1; |
| 1100 | x = xx; |
| 1101 | } |
| 1102 | else if (c == 'w') |
| 1103 | set_fw = TRUE(!(0)); |
| 1104 | else if (c == 'a') |
| 1105 | field_width = fw; |
| 1106 | else if (c == 'e') |
| 1107 | { |
| 1108 | field_width = fw; |
| 1109 | fw_right = TRUE(!(0)); |
| 1110 | } |
| 1111 | else if (c == 'f') |
| 1112 | { |
| 1113 | ts = ts_alt; |
| 1114 | shadow = ts_alt->effect ? 1 : 0; |
| 1115 | } |
| 1116 | else if (c == 'x' && isdigit((unsigned char)*s)((*__ctype_b_loc ())[(int) (((unsigned char)*s))] & (unsigned short int) _ISdigit)) |
| 1117 | xx = *s++ - '0'; |
| 1118 | else if (c == 'y' && isdigit((unsigned char)*s)((*__ctype_b_loc ())[(int) (((unsigned char)*s))] & (unsigned short int) _ISdigit)) |
| 1119 | y = *s++ - '0'; |
| 1120 | else if (c == 'D') |
| 1121 | { |
| 1122 | y = chartdata_text_y(cp, *s++, cp->h_text, cp->y_ink, shadow); |
| 1123 | x = xx; |
| 1124 | } |
| 1125 | } |
| 1126 | t = strchr(s, (gint) '\\')(__extension__ (__builtin_constant_p ((gint) '\\') && !__builtin_constant_p (s) && ((gint) '\\') == '\0' ? (char *) __rawmemchr (s, (gint) '\\') : __builtin_strchr (s, (gint) '\\'))); |
| 1127 | if (t) |
| 1128 | text_length = t - s; |
| 1129 | else |
| 1130 | text_length = strlen(s); |
| 1131 | |
| 1132 | if (y == -100) /* asked for a chartdata that is hidden */ |
| 1133 | continue; |
| 1134 | |
| 1135 | if ( !tr->cache_valid || !tr->text |
| 1136 | || strncmp(tr->text, s, text_length)(__extension__ (__builtin_constant_p (text_length) && ((__builtin_constant_p (tr->text) && strlen (tr-> text) < ((size_t) (text_length))) || (__builtin_constant_p (s) && strlen (s) < ((size_t) (text_length)))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (tr-> text) && __builtin_constant_p (s) && (__s1_len = strlen (tr->text), __s2_len = strlen (s), (!((size_t)(const void *)((tr->text) + 1) - (size_t)(const void *)(tr->text ) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((s) + 1) - (size_t)(const void *)(s) == 1) || __s2_len >= 4)) ? __builtin_strcmp (tr->text, s) : (__builtin_constant_p (tr->text) && ((size_t)(const void *)((tr->text ) + 1) - (size_t)(const void *)(tr->text) == 1) && (__s1_len = strlen (tr->text), __s1_len < 4) ? (__builtin_constant_p (s) && ((size_t)(const void *)((s) + 1) - (size_t)(const void *)(s) == 1) ? __builtin_strcmp (tr->text, s) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (s); int __result = (((const unsigned char *) (const char *) (tr->text))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (tr->text))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (tr->text))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (tr->text))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (s) && ((size_t)(const void *)((s) + 1) - (size_t)(const void *)(s) == 1) && (__s2_len = strlen (s), __s2_len < 4) ? (__builtin_constant_p (tr->text) && ((size_t )(const void *)((tr->text) + 1) - (size_t)(const void *)(tr ->text) == 1) ? __builtin_strcmp (tr->text, s) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (tr->text); int __result = (((const unsigned char *) (const char *) (s))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (s))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ( s))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (s))[ 3] - __s2[3]); } } __result; })))) : __builtin_strcmp (tr-> text, s)))); }) : strncmp (tr->text, s, text_length))) |
| 1137 | || strlen(tr->text) != text_length |
| 1138 | ) |
| 1139 | { |
| 1140 | gkrellm_text_extents(ts->font, s, text_length, |
| 1141 | &tr->w, &tr->h, &tr->baseline, &tr->y_ink); |
| 1142 | tr->cache_valid = FALSE(0); |
| 1143 | g_free(tr->text); |
| 1144 | tr->text = g_strndup(s, text_length); |
| 1145 | } |
| 1146 | h = tr->h; |
| 1147 | |
| 1148 | if (set_fw) |
| 1149 | { |
| 1150 | fw = tr->w + shadow; |
| 1151 | continue; |
| 1152 | } |
| 1153 | if (center == 1) |
| 1154 | x = (cp->w - tr->w) / 2; |
| 1155 | else if (center == 2) |
| 1156 | x = cp->w / 2; |
| 1157 | else if (fw_right) |
| 1158 | x = x + fw - tr->w - shadow; |
| 1159 | else if (right) |
| 1160 | x = cp->w - tr->w - 2 - shadow; |
| 1161 | if (text_length > 1 || (text_length == 1 && *s != ' ')) |
| 1162 | { |
| 1163 | if (x != tr->x || y != tr->y) |
| 1164 | tr->cache_valid = FALSE(0); |
| 1165 | tr->x = x; |
| 1166 | tr->y = y; |
| 1167 | |
| 1168 | if (_GK.debug_level & DEBUG_CHART_TEXT0x10000) |
| 1169 | { |
| 1170 | gchar buf[128]; |
| 1171 | |
| 1172 | strncpy(buf, s, text_length)__builtin_strncpy (buf, s, text_length); |
| 1173 | buf[text_length] = '\0'; |
| 1174 | g_debug("draw_chart_text: [%s] ", buf); |
| 1175 | } |
| 1176 | |
| 1177 | offset = cp->baseline_ref - tr->baseline; /* align baselines */ |
| 1178 | if (_GK.chart_text_no_fill) |
| 1179 | gkrellm_draw_text(cp->pixmap, ts, x, y + offset, s, |
| 1180 | text_length); |
| 1181 | else /* Default text draw effect is fill solid and can use cache */ |
| 1182 | { |
| 1183 | if (!tr->cache_valid) |
| 1184 | { |
| 1185 | if (_GK.debug_level & DEBUG_CHART_TEXT0x10000) |
| 1186 | g_debug("pango "); |
| 1187 | gdk_draw_drawable(cp->bg_text_pixmap, _GK.draw1_GC, |
| 1188 | cp->bg_pixmap, |
| 1189 | x - 1, y + tr->y_ink + offset - 1, |
| 1190 | x - 1, y + tr->y_ink + offset - 1, |
| 1191 | tr->w + shadow + 2, tr->h + shadow + 1); |
| 1192 | gkrellm_draw_text(cp->bg_text_pixmap, ts, x, y + offset, s, |
| 1193 | text_length); |
| 1194 | } |
| 1195 | if (_GK.debug_level & DEBUG_CHART_TEXT0x10000) |
| 1196 | g_debug("x=%d y=%d w=%d h=%d\n", |
| 1197 | x - 1, y + tr->y_ink + offset - 1, |
| 1198 | tr->w + shadow + 2, tr->h + shadow + 1); |
| 1199 | gdk_draw_drawable(cp->pixmap, _GK.draw1_GC, cp->bg_text_pixmap, |
| 1200 | x - 1, y + tr->y_ink + offset - 1, |
| 1201 | x - 1, y + tr->y_ink + offset - 1, |
| 1202 | tr->w + shadow + 2, tr->h + shadow + 1); |
| 1203 | } |
| 1204 | } |
| 1205 | if (field_width && !fw_right) |
| 1206 | x += (field_width > tr->w) ? field_width : tr->w; |
| 1207 | else |
| 1208 | x += tr->w + shadow; |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | gint |
| 1213 | gkrellm_draw_chart_label(GkrellmChart *cp, GkrellmTextstyle *ts, |
| 1214 | gint x, gint y, gchar *s) |
| 1215 | { |
| 1216 | gint w, h, y_ink; |
| 1217 | |
| 1218 | if (!cp || !ts || !s) |
| 1219 | return x; |
| 1220 | |
| 1221 | gkrellm_text_extents(ts->font, s, strlen(s), &w, &h, NULL((void*)0), &y_ink); |
| 1222 | |
| 1223 | gdk_draw_drawable(cp->pixmap, _GK.draw1_GC, cp->bg_pixmap, |
| 1224 | x, y, x, y, w + ts->effect, h + ts->effect); |
| 1225 | gkrellm_draw_string(cp->pixmap, ts, x, y - y_ink, s); |
| 1226 | |
| 1227 | return x + w + ts->effect; |
| 1228 | } |
| 1229 | |
| 1230 | void |
| 1231 | gkrellm_destroy_chartdata_list(GList **cd_list_head) |
| 1232 | { |
| 1233 | GList *list; |
| 1234 | GkrellmChartdata *cd; |
| 1235 | |
| 1236 | if (!cd_list_head) |
| 1237 | return; |
| 1238 | for (list = *cd_list_head; list; list = list->next) |
| 1239 | { |
| 1240 | cd = (GkrellmChartdata *) list->data; |
| 1241 | if (cd->label) |
| 1242 | g_free(cd->label); |
| 1243 | if (cd->data) |
| 1244 | g_free(cd->data); |
| 1245 | if (cd->data_bitmap) |
| 1246 | g_object_unref(G_OBJECT(cd->data_bitmap)((((GObject*) g_type_check_instance_cast ((GTypeInstance*) (( cd->data_bitmap)), (((GType) ((20) << (2))))))))); |
| 1247 | if (cd->layer.pixmap) |
| 1248 | g_object_unref(G_OBJECT(cd->layer.pixmap)((((GObject*) g_type_check_instance_cast ((GTypeInstance*) (( cd->layer.pixmap)), (((GType) ((20) << (2))))))))); |
| 1249 | /* cd->layer.src_pixmap & cd->layer.grid_pixmap must be handled by |
| 1250 | | creating monitor. |
| 1251 | */ |
| 1252 | } |
| 1253 | gkrellm_free_glist_and_data(cd_list_head); |
| 1254 | } |
| 1255 | |
| 1256 | |
| 1257 | static void |
| 1258 | free_chart_pixmaps(GkrellmChart *cp) |
| 1259 | { |
| 1260 | GList *list; |
| 1261 | GkrellmChartdata *cd; |
| 1262 | |
| 1263 | for (list = cp->cd_list; list; list = list->next) |
| 1264 | { |
| 1265 | cd = (GkrellmChartdata *) list->data; |
| 1266 | gkrellm_free_bitmap(&cd->data_bitmap); |
| 1267 | gkrellm_free_pixmap(&cd->layer.pixmap); |
| 1268 | /* cd->layer.src_pixmap & cd->layer.grid_pixmap must be handled by |
| 1269 | | creating monitor. |
| 1270 | */ |
| 1271 | } |
| 1272 | /* If new theme or size, the cd_list will not be destroyed so I can |
| 1273 | | reuse the data arrays. Pixmaps will be recreated. |
| 1274 | */ |
| 1275 | cp->cd_list_index = 0; |
| 1276 | |
| 1277 | gkrellm_free_pixmap(&cp->bg_pixmap); |
| 1278 | gkrellm_free_pixmap(&cp->bg_text_pixmap); |
| 1279 | gkrellm_free_pixmap(&cp->bg_src_pixmap); |
| 1280 | gkrellm_free_pixmap(&cp->bg_grid_pixmap); |
| 1281 | |
| 1282 | gkrellm_free_pixmap(&cp->bg_clean_pixmap); |
| 1283 | gkrellm_free_bitmap(&cp->bg_mask); |
| 1284 | |
| 1285 | gkrellm_free_pixmap(&cp->pixmap); |
| 1286 | |
| 1287 | gkrellm_free_pixmap(&cp->top_spacer.clean_pixmap); |
| 1288 | gkrellm_free_pixmap(&cp->top_spacer.pixmap); |
| 1289 | gkrellm_free_bitmap(&cp->top_spacer.mask); |
| 1290 | gkrellm_free_pixmap(&cp->bottom_spacer.clean_pixmap); |
| 1291 | gkrellm_free_pixmap(&cp->bottom_spacer.pixmap); |
| 1292 | gkrellm_free_bitmap(&cp->bottom_spacer.mask); |
| 1293 | } |
| 1294 | |
| 1295 | static void |
| 1296 | destroy_chart_data(GkrellmChart *cp) |
| 1297 | { |
| 1298 | GList *list; |
| 1299 | GkrellmChartdata *cd; |
| 1300 | |
| 1301 | free_chart_pixmaps(cp); |
| 1302 | chart_destroy_text_run_list(cp); |
| 1303 | for (list = cp->cd_list; list; list = list->next) |
| 1304 | { |
| 1305 | cd = (GkrellmChartdata *) list->data; |
| 1306 | if (cd->label) |
| 1307 | g_free(cd->label); |
| 1308 | if (cd->data) |
| 1309 | g_free(cd->data); |
| 1310 | cd->label = NULL((void*)0); |
| 1311 | cd->data = NULL((void*)0); |
| 1312 | } |
| 1313 | /* Don't free the cd_list. It is in the GkrellmChartconfig struct. |
| 1314 | */ |
| 1315 | } |
| 1316 | |
| 1317 | /* Destroy everything inside a chart except leave cp->config alone since |
| 1318 | | the config is managed by each monitor. |
| 1319 | */ |
| 1320 | void |
| 1321 | gkrellm_chart_destroy(GkrellmChart *cp) |
| 1322 | { |
| 1323 | gint h_spacers = 0; |
| 1324 | |
| 1325 | if (!cp) |
| 1326 | return; |
| 1327 | |
| 1328 | if (cp->top_spacer.image) |
| 1329 | h_spacers = cp->top_spacer.height; |
| 1330 | if (cp->bottom_spacer.image) |
| 1331 | h_spacers += cp->bottom_spacer.height; |
| 1332 | |
| 1333 | gkrellm_freeze_side_frame_packing(); |
| 1334 | if (cp->panel) |
| 1335 | gkrellm_panel_destroy(cp->panel); |
| 1336 | destroy_chart_data(cp); |
| 1337 | gtk_widget_destroy(cp->box); |
| 1338 | chart_list = g_list_remove(chart_list, cp); |
| 1339 | gkrellm_chartconfig_window_destroy(cp); |
| 1340 | if (cp->shown) |
| 1341 | gkrellm_monitor_height_adjust(-(cp->h + h_spacers)); |
| 1342 | g_free(cp); |
| 1343 | gkrellm_thaw_side_frame_packing(); |
| 1344 | } |
| 1345 | |
| 1346 | void |
| 1347 | gkrellm_chartconfig_destroy(GkrellmChartconfig **cf) |
| 1348 | { |
| 1349 | if (!cf || !*cf) |
| 1350 | return; |
| 1351 | gkrellm_destroy_chartdata_list((*cf)->chart_cd_list); |
| 1352 | g_free(*cf); |
| 1353 | *cf = NULL((void*)0); |
| 1354 | } |
| 1355 | |
| 1356 | void |
| 1357 | gkrellm_chart_bg_piximage_override(GkrellmChart *cp, |
| 1358 | GkrellmPiximage *bg_piximage, GkrellmPiximage *bg_grid_piximage) |
| 1359 | { |
| 1360 | if (!cp || !bg_piximage || !bg_grid_piximage) |
| 1361 | return; |
| 1362 | cp->bg_piximage = bg_piximage; |
| 1363 | cp->bg_grid_piximage = bg_grid_piximage; |
| 1364 | cp->bg_piximage_override = TRUE(!(0)); |
| 1365 | } |
| 1366 | |
| 1367 | |
| 1368 | static void |
| 1369 | set_chartdata_split_heights(GkrellmChart *cp) |
| 1370 | { |
| 1371 | GList *list, *list1; |
| 1372 | GkrellmChartdata *cd, *cd1; |
| 1373 | gint splits; |
| 1374 | gint i, y0, h_avail, h_free, y_offset; |
| 1375 | |
| 1376 | for (i = 0, splits = 0, list = cp->cd_list; list; list = list->next) |
| 1377 | { |
| 1378 | cd = (GkrellmChartdata *) list->data; |
| 1379 | if (cd->hide) |
| 1380 | continue; |
| 1381 | if (++i > 1 && cd->split_chart) /* Can't split before the first one */ |
| 1382 | ++splits; |
| 1383 | cd->split_share = 1.0; |
| 1384 | for (list1 = list->next; list1; list1 = list1->next) |
| 1385 | { |
| 1386 | cd1 = (GkrellmChartdata *) list1->data; |
| 1387 | if (!cd1->split_chart || cd1->hide) |
| 1388 | continue; |
| 1389 | cd->split_share = cd1->split_fraction; |
| 1390 | break; |
| 1391 | } |
| 1392 | } |
| 1393 | y_offset = GRID_HEIGHT_Y_OFFSET_ADJUST(cp)(( gdk_pixbuf_get_height((cp)->bg_grid_piximage->pixbuf ) < 2) ? 0 : 1); |
| 1394 | y0 = cp->y + y_offset; |
| 1395 | h_avail = cp->h - cp->y - ((splits + 1) * y_offset) |
| 1396 | - splits * _GK.bg_separator_height; |
| 1397 | h_free = h_avail; |
| 1398 | for (list = cp->cd_list; list; list = list->next) |
| 1399 | { |
| 1400 | cd = (GkrellmChartdata *) list->data; |
| 1401 | if (cd->hide) |
| 1402 | continue; |
| 1403 | cd->y = y0; |
| 1404 | for (list1 = list->next; list1; list1 = list1->next) |
| 1405 | if (!((GkrellmChartdata *) list1->data)->hide) |
| 1406 | break; |
| 1407 | if (!list1) |
| 1408 | cd->h = h_free; |
| 1409 | else |
| 1410 | cd->h = (gint) (cd->split_share * (gfloat) h_free); |
| 1411 | if (cd->h < 1) |
| 1412 | cd->h = 1; |
| 1413 | if (list1 && ((GkrellmChartdata *) list1->data)->split_chart) |
| 1414 | { |
| 1415 | y0 += cd->h + _GK.bg_separator_height + y_offset; |
| 1416 | h_free -= cd->h; |
| 1417 | } |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | GkrellmChartdata * |
| 1422 | gkrellm_add_default_chartdata(GkrellmChart *cp, gchar *label) |
| 1423 | { |
| 1424 | GdkPixmap **src_pixmap, *grid_pixmap; |
| 1425 | |
| 1426 | if (!cp) |
| 1427 | return NULL((void*)0); |
| 1428 | if (cp->cd_list_index & 1) |
| 1429 | { |
| 1430 | src_pixmap = &_GK.data_in_pixmap; |
| 1431 | grid_pixmap = _GK.data_in_grid_pixmap; |
| 1432 | } |
| 1433 | else |
| 1434 | { |
| 1435 | src_pixmap = &_GK.data_out_pixmap; |
| 1436 | grid_pixmap = _GK.data_out_grid_pixmap; |
| 1437 | } |
| 1438 | return gkrellm_add_chartdata(cp, src_pixmap, grid_pixmap, label); |
| 1439 | } |
| 1440 | |
| 1441 | /* Need a GdkPixmap ** because the src pixmap can change (re-rendered at |
| 1442 | | size or theme changes). |
| 1443 | */ |
| 1444 | GkrellmChartdata * |
| 1445 | gkrellm_add_chartdata(GkrellmChart *cp, GdkPixmap **src_pixmap, |
| 1446 | GdkPixmap *grid_pixmap, gchar *label) |
| 1447 | { |
| 1448 | GtkWidget *top_win = gkrellm_get_top_window(); |
| 1449 | GList *list; |
| 1450 | GkrellmChartdata *cd; |
| 1451 | |
| 1452 | if (!cp || !src_pixmap || !grid_pixmap || !label) |
| 1453 | return NULL((void*)0); |
| 1454 | |
| 1455 | /* To handle theme and vert size changes without losing data, reuse the |
| 1456 | | GkrellmChartdata structs in the cd_list. |
| 1457 | */ |
| 1458 | list = g_list_nth(cp->cd_list, cp->cd_list_index++); |
| 1459 | if (!list) |
| 1460 | { |
| 1461 | cd = g_new0(GkrellmChartdata, 1)(GkrellmChartdata *) (__extension__ ({ gsize __n = (gsize) (1 ); gsize __s = sizeof (GkrellmChartdata); gpointer __p; if (__s == 1) __p = g_malloc0 (__n); else if (__builtin_constant_p ( __n) && (__s == 0 || __n <= (9223372036854775807L * 2UL+1UL) / __s)) __p = g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p; })); |
| 1462 | cp->cd_list = g_list_append(cp->cd_list, cd); |
| 1463 | cp->config->cd_list = cp->cd_list; |
| 1464 | cd->split_fraction = 0.5; |
| 1465 | } |
| 1466 | else |
| 1467 | cd = (GkrellmChartdata *) list->data; |
| 1468 | cd->chart = cp; |
| 1469 | gkrellm_dup_string(&cd->label, label); |
| 1470 | cd->monotonic = TRUE(!(0)); |
| 1471 | cd->data_bitmap = gdk_pixmap_new(top_win->window, cp->w, cp->h, 1); |
| 1472 | cd->layer.pixmap = gdk_pixmap_new(top_win->window, cp->w, cp->h, -1); |
| 1473 | cd->layer.src_pixmap = src_pixmap; |
| 1474 | cd->layer.grid_pixmap = grid_pixmap; |
| 1475 | |
| 1476 | set_chartdata_split_heights(cp); |
| 1477 | return cd; |
| 1478 | } |
| 1479 | |
| 1480 | void |
| 1481 | gkrellm_render_data_grid_pixmap(GkrellmPiximage *im, GdkPixmap **pixmap, |
| 1482 | GdkColor *color) |
| 1483 | { |
| 1484 | GtkWidget *top_win = gkrellm_get_top_window(); |
| 1485 | gint w, w_pixmap = 0, h = 0; |
| 1486 | |
| 1487 | w = gkrellm_chart_width(); |
| 1488 | if (*pixmap) |
| 1489 | gdk_drawable_get_size(*pixmap, &w_pixmap, NULL((void*)0)); |
| 1490 | if (!*pixmap || w != w_pixmap) |
| 1491 | { |
| 1492 | if (im) |
| 1493 | { |
| 1494 | if ((h = gdk_pixbuf_get_height(im->pixbuf)) > 2) |
| 1495 | h = 2; |
| 1496 | gkrellm_scale_piximage_to_pixmap(im, pixmap, NULL((void*)0), w, h); |
| 1497 | } |
| 1498 | else |
| 1499 | { |
| 1500 | gkrellm_free_pixmap(pixmap); |
| 1501 | *pixmap = gdk_pixmap_new(top_win->window, w, 1, -1); |
| 1502 | if (color) |
| 1503 | gdk_gc_set_foreground(_GK.draw1_GC, color); |
| 1504 | else |
| 1505 | gdk_gc_set_foreground(_GK.draw1_GC, &_GK.in_color_grid); |
| 1506 | gdk_draw_rectangle(*pixmap, _GK.draw1_GC, TRUE(!(0)), 0, 0, w, 1); |
| 1507 | } |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | void |
| 1512 | gkrellm_render_data_pixmap(GkrellmPiximage *im, GdkPixmap **pixmap, |
| 1513 | GdkColor *color, gint h) |
| 1514 | { |
| 1515 | GtkWidget *top_win = gkrellm_get_top_window(); |
| 1516 | gint w, w_pixmap = 0, h_pixmap = 0; |
| 1517 | |
| 1518 | w = gkrellm_chart_width(); |
| 1519 | if (*pixmap) |
| 1520 | gdk_drawable_get_size(*pixmap, &w_pixmap, &h_pixmap); |
| 1521 | |
| 1522 | if (!*pixmap || w != w_pixmap || h != h_pixmap) |
| 1523 | { |
| 1524 | if (!gkrellm_scale_piximage_to_pixmap(im, pixmap, NULL((void*)0), w, h)) |
| 1525 | { |
| 1526 | *pixmap = gdk_pixmap_new(top_win->window, w, h, -1); |
| 1527 | if (color) |
| 1528 | gdk_gc_set_foreground(_GK.draw1_GC, color); |
| 1529 | else |
| 1530 | gdk_gc_set_foreground(_GK.draw1_GC, &_GK.in_color_grid); |
| 1531 | gdk_draw_rectangle(*pixmap, _GK.draw1_GC, TRUE(!(0)), 0,0,w,h); |
| 1532 | } |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | static void |
| 1537 | render_default_data_pixmaps(GkrellmChart *cp) |
| 1538 | { |
| 1539 | GList *list; |
| 1540 | GdkPixmap *pixmap; |
| 1541 | gint w, h, w_pixmap = 0; |
| 1542 | |
| 1543 | gkrellm_render_data_grid_pixmap(_GK.data_in_grid_piximage, |
| 1544 | &_GK.data_in_grid_pixmap, &_GK.in_color_grid); |
| 1545 | gkrellm_render_data_grid_pixmap(_GK.data_out_grid_piximage, |
| 1546 | &_GK.data_out_grid_pixmap, &_GK.out_color_grid); |
| 1547 | |
| 1548 | w = gkrellm_chart_width(); |
| 1549 | pixmap = _GK.bg_separator_pixmap; |
| 1550 | if (pixmap) |
| 1551 | gdk_drawable_get_size(pixmap, &w_pixmap, NULL((void*)0)); |
| 1552 | if (!pixmap || w_pixmap != w) |
| 1553 | { |
| 1554 | if ((h = _GK.bg_separator_height) < 1 || h > 5) |
| 1555 | h = 2; |
| 1556 | if (_GK.bg_separator_piximage) |
| 1557 | gkrellm_scale_piximage_to_pixmap(_GK.bg_separator_piximage, |
| 1558 | &_GK.bg_separator_pixmap, NULL((void*)0), w, h); |
| 1559 | else |
| 1560 | { |
| 1561 | GkrellmPiximage *im; |
| 1562 | |
| 1563 | im = gkrellm_bg_panel_piximage(DEFAULT_STYLE_ID0); |
| 1564 | gkrellm_scale_pixbuf_to_pixmap(im->pixbuf, &_GK.bg_separator_pixmap, |
| 1565 | NULL((void*)0), w, h); |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | h = 2; |
| 1570 | for (list = chart_list; list; list = list->next) |
| 1571 | { |
| 1572 | cp = (GkrellmChart *) list->data; |
| 1573 | if (cp->h > h) |
| 1574 | h = cp->h; |
| 1575 | } |
| 1576 | gkrellm_render_data_pixmap(_GK.data_in_piximage, |
| 1577 | &_GK.data_in_pixmap, &_GK.in_color, h); |
| 1578 | gkrellm_render_data_pixmap(_GK.data_out_piximage, |
| 1579 | &_GK.data_out_pixmap, &_GK.out_color, h); |
| 1580 | } |
| 1581 | |
| 1582 | void |
| 1583 | gkrellm_chart_setup(void) |
| 1584 | { |
| 1585 | gkrellm_free_pixmap(&_GK.data_in_pixmap); |
| 1586 | gkrellm_free_pixmap(&_GK.data_in_grid_pixmap); |
| 1587 | gkrellm_free_pixmap(&_GK.data_out_pixmap); |
| 1588 | gkrellm_free_pixmap(&_GK.data_out_grid_pixmap); |
| 1589 | gkrellm_free_pixmap(&_GK.bg_separator_pixmap); |
| 1590 | } |
| 1591 | |
| 1592 | #if 0 |
| 1593 | static gint |
| 1594 | compare_chartlist(gconstpointer a, gconstpointer b) |
| 1595 | { |
| 1596 | GkrellmChart *cp_a = (GkrellmChart *) a; |
| 1597 | GkrellmChart *cp_b = (GkrellmChart *) b; |
| 1598 | gint result; |
| 1599 | |
| 1600 | if (cp_a->style_id < cp_b->style_id) |
| 1601 | result = -1; |
| 1602 | else (if cp_a->style_id > cp_b->style_id) |
| 1603 | result = 1; |
| 1604 | else |
| 1605 | result = 0; |
| 1606 | return result; |
| 1607 | } |
| 1608 | #endif |
| 1609 | |
| 1610 | static void |
| 1611 | insert_in_chartlist(GkrellmChart *cp) |
| 1612 | { |
| 1613 | GList *list; |
| 1614 | GkrellmChart *cp_x; |
| 1615 | gint position = 0; |
| 1616 | |
| 1617 | for (list = chart_list; list; list = list->next, ++position) |
| 1618 | { |
| 1619 | cp_x = (GkrellmChart *) list->data; |
| 1620 | if (cp_x->style_id > cp->style_id) |
| 1621 | { |
| 1622 | chart_list = g_list_insert(chart_list, cp, position); |
| 1623 | return; |
| 1624 | } |
| 1625 | } |
| 1626 | chart_list = g_list_append(chart_list, cp); |
| 1627 | } |
| 1628 | |
| 1629 | void |
| 1630 | gkrellm_chart_hide(GkrellmChart *cp, gboolean hide_panel) |
| 1631 | { |
| 1632 | gint h_spacers = 0; |
| 1633 | |
| 1634 | if (!cp || !cp->shown) |
| 1635 | return; |
| 1636 | |
| 1637 | if (cp->top_spacer.image) |
| 1638 | h_spacers = cp->top_spacer.height; |
| 1639 | if (cp->bottom_spacer.image) |
| 1640 | h_spacers += cp->bottom_spacer.height; |
| 1641 | |
| 1642 | gtk_widget_hide(cp->box); |
| 1643 | gkrellm_freeze_side_frame_packing(); |
| 1644 | if (hide_panel) |
| 1645 | gkrellm_panel_hide(cp->panel); |
| 1646 | gkrellm_monitor_height_adjust(- (cp->h + h_spacers)); |
| 1647 | cp->shown = FALSE(0); |
| 1648 | gkrellm_thaw_side_frame_packing(); |
| 1649 | } |
| 1650 | |
| 1651 | void |
| 1652 | gkrellm_chart_show(GkrellmChart *cp, gboolean show_panel) |
| 1653 | { |
| 1654 | gint h_spacers = 0; |
| 1655 | |
| 1656 | if (!cp || cp->shown) |
| 1657 | return; |
| 1658 | |
| 1659 | if (cp->top_spacer.image) |
| 1660 | h_spacers = cp->top_spacer.height; |
| 1661 | if (cp->bottom_spacer.image) |
| 1662 | h_spacers += cp->bottom_spacer.height; |
| 1663 | |
| 1664 | gtk_widget_show(cp->box); |
| 1665 | gkrellm_freeze_side_frame_packing(); |
| 1666 | if (show_panel) |
| 1667 | gkrellm_panel_show(cp->panel); |
| 1668 | cp->shown = TRUE(!(0)); |
| 1669 | gkrellm_monitor_height_adjust(cp->h + h_spacers); |
| 1670 | gkrellm_thaw_side_frame_packing(); |
| 1671 | } |
| 1672 | |
| 1673 | gboolean |
| 1674 | gkrellm_is_chart_visible(GkrellmChart *cp) |
| 1675 | { |
| 1676 | if (!cp) |
| 1677 | return FALSE(0); |
| 1678 | return cp->shown; |
| 1679 | } |
| 1680 | |
| 1681 | gboolean |
| 1682 | gkrellm_chart_enable_visibility(GkrellmChart *cp, gboolean new_vis, |
| 1683 | gboolean *current_vis) |
| 1684 | { |
| 1685 | gboolean changed = FALSE(0); |
| 1686 | |
| 1687 | if (new_vis && ! *current_vis) |
| 1688 | { |
| 1689 | gkrellm_chart_show(cp, TRUE(!(0))); |
| 1690 | *current_vis = TRUE(!(0)); |
| 1691 | changed = TRUE(!(0)); |
| 1692 | } |
| 1693 | if (!new_vis && *current_vis) |
| 1694 | { |
| 1695 | gkrellm_chart_hide(cp, TRUE(!(0))); |
| 1696 | *current_vis = FALSE(0); |
| 1697 | changed = TRUE(!(0)); |
| 1698 | } |
| 1699 | return changed; |
| 1700 | } |
| 1701 | |
| 1702 | void |
| 1703 | gkrellm_set_chart_height_default(GkrellmChart *cp, gint h) |
| 1704 | { |
| 1705 | if (!cp || (cp->config && cp->config->config_loaded)) |
| 1706 | return; |
| 1707 | |
| 1708 | if (h < MIN_CHARTHEIGHT5) |
| 1709 | h = MIN_CHARTHEIGHT5; |
| 1710 | if (h > MAX_CHARTHEIGHT200) |
| 1711 | h = MAX_CHARTHEIGHT200; |
| 1712 | cp->h = h; |
| 1713 | } |
| 1714 | |
| 1715 | static void |
| 1716 | render_chart_margin_spacers(GkrellmChart *cp) |
| 1717 | { |
| 1718 | GkrellmMargin *m; |
| 1719 | GkrellmSpacer *ts, *bs; |
| 1720 | |
| 1721 | ts = &cp->top_spacer; |
| 1722 | bs = &cp->bottom_spacer; |
| 1723 | if (ts->image) |
| 1724 | gtk_container_remove(GTK_CONTAINER(ts->vbox)((((GtkContainer*) g_type_check_instance_cast ((GTypeInstance *) ((ts->vbox)), ((gtk_container_get_type ())))))), ts->image); |
| 1725 | if (bs->image) |
| 1726 | gtk_container_remove(GTK_CONTAINER(bs->vbox)((((GtkContainer*) g_type_check_instance_cast ((GTypeInstance *) ((bs->vbox)), ((gtk_container_get_type ())))))), bs->image); |
| 1727 | ts->image = bs->image = NULL((void*)0); |
| 1728 | m = gkrellm_get_style_margins(cp->style); |
| 1729 | ts->piximage = cp->bg_piximage; |
| 1730 | ts->height = m->top; |
| 1731 | bs->piximage = cp->bg_piximage; |
| 1732 | bs->height = m->bottom; |
| 1733 | |
| 1734 | if (!gkrellm_render_spacer(ts, 0, m->top, |
| 1735 | _GK.frame_left_chart_overlap, _GK.frame_right_chart_overlap)) |
| 1736 | gtk_widget_hide(ts->vbox); |
| 1737 | |
| 1738 | if (!gkrellm_render_spacer(bs, |
| 1739 | gdk_pixbuf_get_height(cp->bg_piximage->pixbuf) - m->bottom, |
| 1740 | m->bottom, |
| 1741 | _GK.frame_left_chart_overlap, _GK.frame_right_chart_overlap)) |
| 1742 | gtk_widget_hide(bs->vbox); |
| 1743 | } |
| 1744 | |
| 1745 | #if 0 |
| 1746 | static gboolean |
| 1747 | cb_chart_map_event(GtkWidget *widget, GdkEvent *event, GkrellmChart *cp) |
| 1748 | { |
| 1749 | gdk_window_get_position(cp->drawing_area->window, NULL((void*)0), &cp->y_mapped); |
| 1750 | if (_GK.frame_left_chart_overlap > 0 || _GK.frame_right_chart_overlap > 0) |
| 1751 | _GK.need_frame_packing = TRUE(!(0)); |
| 1752 | return FALSE(0); |
| 1753 | } |
| 1754 | #endif |
| 1755 | |
| 1756 | static gboolean |
| 1757 | cb_chart_size_allocate(GtkWidget *widget, GtkAllocation *size, |
| 1758 | GkrellmChart *cp) |
| 1759 | { |
| 1760 | gdk_window_get_position(cp->drawing_area->window, NULL((void*)0), &cp->y_mapped); |
| 1761 | if (_GK.frame_left_chart_overlap > 0 || _GK.frame_right_chart_overlap > 0) |
| 1762 | _GK.need_frame_packing = TRUE(!(0)); |
| 1763 | return FALSE(0); |
| 1764 | } |
| 1765 | |
| 1766 | static void |
| 1767 | render_chart_pixmaps(GkrellmChart *cp) |
| 1768 | { |
| 1769 | GkrellmPiximage piximage; |
| 1770 | GkrellmMargin *m; |
| 1771 | gint h, w; |
| 1772 | |
| 1773 | m = gkrellm_get_style_margins(cp->style); |
| 1774 | w = gdk_pixbuf_get_width(cp->bg_piximage->pixbuf) |
| 1775 | - _GK.frame_left_chart_overlap - _GK.frame_right_chart_overlap; |
| 1776 | h = gdk_pixbuf_get_height(cp->bg_piximage->pixbuf) - m->top - m->bottom; |
| 1777 | |
| 1778 | if ( ( m->top > 0 || m->bottom > 0 |
| 1779 | || _GK.frame_left_chart_overlap > 0 |
| 1780 | || _GK.frame_right_chart_overlap > 0 |
| 1781 | ) |
| 1782 | && w > 0 && h > 0 |
| 1783 | ) |
| 1784 | { |
| 1785 | piximage.pixbuf = gdk_pixbuf_new_subpixbuf(cp->bg_piximage->pixbuf, |
| 1786 | _GK.frame_left_chart_overlap, m->top, w, h); |
| 1787 | piximage.border = cp->bg_piximage->border; |
| 1788 | gkrellm_border_adjust(&piximage.border, |
| 1789 | -_GK.frame_left_chart_overlap, -_GK.frame_right_chart_overlap, |
| 1790 | -m->top, -m->bottom); |
| 1791 | gkrellm_scale_piximage_to_pixmap(&piximage, &cp->bg_clean_pixmap, |
| 1792 | &cp->bg_mask, cp->w, cp->h); |
| 1793 | g_object_unref(G_OBJECT(piximage.pixbuf)((((GObject*) g_type_check_instance_cast ((GTypeInstance*) (( piximage.pixbuf)), (((GType) ((20) << (2))))))))); |
| 1794 | } |
| 1795 | else |
| 1796 | gkrellm_scale_piximage_to_pixmap(cp->bg_piximage, |
| 1797 | &cp->bg_clean_pixmap, &cp->bg_mask, cp->w, cp->h); |
| 1798 | |
| 1799 | gkrellm_clone_pixmap(&cp->pixmap, &cp->bg_clean_pixmap); |
| 1800 | gkrellm_clone_pixmap(&cp->bg_pixmap, &cp->bg_clean_pixmap); |
| 1801 | gkrellm_clone_pixmap(&cp->bg_src_pixmap, &cp->bg_clean_pixmap); |
| 1802 | gkrellm_clone_pixmap(&cp->bg_text_pixmap, &cp->bg_clean_pixmap); |
| 1803 | } |
| 1804 | |
| 1805 | void |
| 1806 | gkrellm_chart_create(GtkWidget *vbox, GkrellmMonitor *mon, GkrellmChart *cp, |
| 1807 | GkrellmChartconfig **config) |
| 1808 | { |
| 1809 | GkrellmMargin *m; |
| 1810 | GkrellmChartconfig *cf; |
| 1811 | gint h, style_id; |
| 1812 | |
| 1813 | if (!vbox || !mon || !cp || !config) |
| 1814 | return; |
| 1815 | if (mon->privat->style_type == CHART_PANEL_TYPE0) |
| 1816 | style_id = mon->privat->style_id; |
| 1817 | else |
| 1818 | style_id = DEFAULT_STYLE_ID0; |
| 1819 | cp->style = gkrellm_chart_style(style_id); |
| 1820 | m = gkrellm_get_style_margins(cp->style); |
| 1821 | cp->monitor = (gpointer) mon; |
| 1822 | if (!cp->bg_piximage_override) |
| 1823 | { |
| 1824 | cp->bg_piximage = gkrellm_bg_chart_piximage(style_id); |
| 1825 | cp->bg_grid_piximage = gkrellm_bg_grid_piximage(style_id); |
| 1826 | } |
| 1827 | cp->bg_piximage_override = FALSE(0); |
| 1828 | cp->x = 0; |
| 1829 | /* cp->y = 0; */ |
| 1830 | cp->w = _GK.chart_width; |
| 1831 | if (!*config) |
| 1832 | { |
| 1833 | *config = gkrellm_chartconfig_new0(); |
| 1834 | (*config)->auto_grid_resolution = TRUE(!(0)); /* the default */ |
| 1835 | (*config)->h = cp->h; /* In case default */ |
| 1836 | } |
| 1837 | cf = cp->config = *config; |
| 1838 | if (cf->h < 5) |
| 1839 | cf->h = 40; |
| 1840 | cp->h = cf->h; |
| 1841 | if (cf->grid_resolution < 1) |
| 1842 | cf->grid_resolution = 1; |
| 1843 | cp->cd_list = cp->config->cd_list; |
| 1844 | cp->config->chart_cd_list = &cp->cd_list; |
| 1845 | |
| 1846 | if (!cp->box) |
| 1847 | { |
| 1848 | cp->box = gtk_vbox_new(FALSE(0), 0); /* not a hbox anymore !! */ |
| 1849 | gtk_box_pack_start(GTK_BOX(vbox)((((GtkBox*) g_type_check_instance_cast ((GTypeInstance*) ((vbox )), ((gtk_box_get_type ())))))), cp->box, FALSE(0), FALSE(0), 0); |
| 1850 | |
| 1851 | cp->top_spacer.vbox = gtk_vbox_new(FALSE(0), 0); |
| 1852 | gtk_box_pack_start(GTK_BOX(cp->box)((((GtkBox*) g_type_check_instance_cast ((GTypeInstance*) ((cp ->box)), ((gtk_box_get_type ())))))), cp->top_spacer.vbox, |
| 1853 | FALSE(0), FALSE(0), 0); |
| 1854 | cp->drawing_area = gtk_drawing_area_new(); |
| 1855 | gtk_widget_set_events(cp->drawing_area, GDK_EXPOSURE_MASK |
| 1856 | | GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK |
| 1857 | | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK |
| 1858 | | GDK_POINTER_MOTION_MASK); |
| 1859 | gtk_box_pack_start(GTK_BOX(cp->box)((((GtkBox*) g_type_check_instance_cast ((GTypeInstance*) ((cp ->box)), ((gtk_box_get_type ())))))), cp->drawing_area, |
| 1860 | FALSE(0), FALSE(0), 0); |
| 1861 | cp->bottom_spacer.vbox = gtk_vbox_new(FALSE(0), 0); |
| 1862 | gtk_box_pack_start(GTK_BOX(cp->box)((((GtkBox*) g_type_check_instance_cast ((GTypeInstance*) ((cp ->box)), ((gtk_box_get_type ())))))), cp->bottom_spacer.vbox, |
| 1863 | FALSE(0), FALSE(0), 0); |
| 1864 | |
| 1865 | gtk_widget_show(cp->drawing_area); |
| 1866 | gtk_widget_show(cp->box); |
| 1867 | cp->shown = TRUE(!(0)); |
| 1868 | gtk_widget_realize(cp->box); |
| 1869 | gtk_widget_realize(cp->drawing_area); |
| 1870 | cp->style_id = style_id; |
| 1871 | insert_in_chartlist(cp); |
| 1872 | cp->y_mapped = -1; |
| 1873 | // g_signal_connect(G_OBJECT (cp->drawing_area), "map_event", |
| 1874 | // G_CALLBACK(cb_chart_map_event), cp); |
| 1875 | g_signal_connect(G_OBJECT (cp->drawing_area), "size_allocate",g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((cp->drawing_area)), (((GType) ((20) << (2))))))))), ("size_allocate"), (((GCallback) (cb_chart_size_allocate ))), (cp), ((void*)0), (GConnectFlags) 0) |
| 1876 | G_CALLBACK(cb_chart_size_allocate), cp)g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((cp->drawing_area)), (((GType) ((20) << (2))))))))), ("size_allocate"), (((GCallback) (cb_chart_size_allocate ))), (cp), ((void*)0), (GConnectFlags) 0); |
| 1877 | } |
| 1878 | else |
| 1879 | free_chart_pixmaps(cp); |
| 1880 | |
| 1881 | gtk_widget_set_size_request(cp->drawing_area, cp->w, cp->h); |
| 1882 | |
| 1883 | cp->bg_sequence_id += 1; |
| 1884 | |
| 1885 | render_chart_pixmaps(cp); |
| 1886 | render_chart_margin_spacers(cp); |
| 1887 | |
| 1888 | h = gdk_pixbuf_get_height(cp->bg_grid_piximage->pixbuf); |
| 1889 | if (h > 2) |
| 1890 | h = 2; |
| 1891 | gkrellm_scale_piximage_to_pixmap(cp->bg_grid_piximage, |
| 1892 | &cp->bg_grid_pixmap, NULL((void*)0), cp->w, h); |
| 1893 | |
| 1894 | cp->transparency = cp->style->transparency; |
| 1895 | _GK.any_transparency |= cp->transparency; |
| 1896 | |
| 1897 | gkrellm_set_draw_chart_function(cp, default_draw_chart_function, cp); |
| 1898 | cp->redraw_all = TRUE(!(0)); |
| 1899 | render_default_data_pixmaps(cp); |
| 1900 | if (cp->shown) |
| 1901 | { |
| 1902 | gkrellm_monitor_height_adjust(cp->h + m->top + m->bottom); |
| 1903 | gkrellm_pack_side_frames(); |
| 1904 | } |
| 1905 | } |
| 1906 | |
| 1907 | void |
| 1908 | gkrellm_refresh_chart(GkrellmChart *cp) |
| 1909 | { |
| 1910 | if (!cp) |
| 1911 | return; |
| 1912 | cp->redraw_all = TRUE(!(0)); |
| 1913 | cp->maxval_auto = -1; |
| 1914 | if (cp->draw_chart) |
| 1915 | (*(cp->draw_chart))(cp->draw_chart_data); |
| 1916 | } |
| 1917 | |
| 1918 | void |
| 1919 | gkrellm_rescale_chart(GkrellmChart *cp) |
| 1920 | { |
| 1921 | if (!cp) |
| 1922 | return; |
| 1923 | scan_for_maxval(cp); |
| 1924 | gkrellm_refresh_chart(cp); |
| 1925 | } |
| 1926 | |
| 1927 | /* =================================================================== */ |
| 1928 | |
| 1929 | |
| 1930 | static gint map_125_table[] = |
| 1931 | { |
| 1932 | 1, 2, 5, |
| 1933 | 10, 20, 50, |
| 1934 | 100, 200, 500, |
| 1935 | 1000, 2000, 5000, |
| 1936 | 10000, 20000, 50000, |
| 1937 | 100000, 200000, 500000, |
| 1938 | 1000000, 2000000, 5000000, |
| 1939 | 10000000, 20000000, 50000000, |
| 1940 | 100000000, 200000000, 500000000 |
| 1941 | }; |
| 1942 | |
| 1943 | static gint map_12357_table[] = |
| 1944 | { |
| 1945 | 1, 2, 3, 5, 7, |
| 1946 | 10, 15, 20, 30, 50, 70, |
| 1947 | 100, 150, 200, 300, 500, 700, |
| 1948 | 1000, 1500, 2000, 3000, 5000, 7000, |
| 1949 | 10000, 15000, 20000, 30000, 50000, 70000, |
| 1950 | 100000, 150000, 200000, 300000, 500000, 700000, |
| 1951 | 1000000, 1500000, 2000000, 3000000, 5000000, 7000000, |
| 1952 | 10000000, 15000000, 20000000, 30000000, 50000000, 70000000, |
| 1953 | 100000000, 150000000, 200000000, 300000000, 500000000, 700000000 |
| 1954 | }; |
| 1955 | |
| 1956 | gint |
| 1957 | gkrellm_125_sequence(gint value, gboolean use125, |
| 1958 | gint low, gint high, |
| 1959 | gboolean snap_to_table, gboolean roundup) |
| 1960 | { |
| 1961 | gint i, table_size; |
| 1962 | gint *table; |
| 1963 | |
| 1964 | if (use125) |
| 1965 | { |
| 1966 | table = map_125_table; |
| 1967 | table_size = sizeof(map_125_table) / sizeof(gint); |
| 1968 | } |
| 1969 | else |
| 1970 | { |
| 1971 | table = map_12357_table; |
| 1972 | table_size = sizeof(map_12357_table) / sizeof(gint); |
| 1973 | } |
| 1974 | if (value < low) |
| 1975 | value = low; |
| 1976 | if (value > high) |
| 1977 | value = high; |
| 1978 | if (value < table[0]) |
| 1979 | return table[0]; |
| 1980 | if (value > table[table_size - 1]) |
| 1981 | return table[table_size - 1]; |
| 1982 | if (!snap_to_table && !roundup) |
| 1983 | { |
| 1984 | for (i = 0; i < table_size; ++i) |
| 1985 | { |
| 1986 | /*g_debug(" mapping[%d] value=%d table=%d\n", i, value, table[i]); */ |
| 1987 | if (value == table[i]) |
| 1988 | return table[i]; |
| 1989 | else if (value == table[i] - 1) |
| 1990 | return table[i - 1]; |
| 1991 | else if (value == table[i] + 1) |
| 1992 | return table[i + 1]; |
| 1993 | } |
| 1994 | } |
| 1995 | else if (snap_to_table && !roundup) |
| 1996 | { |
| 1997 | for (i = table_size - 1; i >= 0; --i) |
| 1998 | { |
| 1999 | if (value >= table[i]) |
| 2000 | { |
| 2001 | value = table[i]; |
| 2002 | break; |
| 2003 | } |
| 2004 | } |
| 2005 | } |
| 2006 | else if (snap_to_table && roundup) |
| 2007 | { |
| 2008 | for (i = 0; i < table_size; ++i) |
| 2009 | { |
| 2010 | if (value <= table[i]) |
| 2011 | { |
| 2012 | value = table[i]; |
| 2013 | break; |
| 2014 | } |
| 2015 | } |
| 2016 | } |
| 2017 | return value; |
| 2018 | } |
| 2019 | |
| 2020 | static void |
| 2021 | set_grid_resolution_spin_button(GkrellmChart *cp, gint res) |
| 2022 | { |
| 2023 | GtkSpinButton *spin; |
| 2024 | |
| 2025 | if (!cp || !cp->config_window || !cp->config->grid_resolution_spin_button) |
| 2026 | return; |
| 2027 | spin = GTK_SPIN_BUTTON(cp->config->grid_resolution_spin_button)((((GtkSpinButton*) g_type_check_instance_cast ((GTypeInstance *) ((cp->config->grid_resolution_spin_button)), ((gtk_spin_button_get_type ())))))); |
| 2028 | gtk_spin_button_set_value(spin, (gfloat) res); |
| 2029 | } |
| 2030 | |
| 2031 | static void |
| 2032 | cb_chart_grid_resolution(GtkWidget *adjustment, GkrellmChart *cp) |
| 2033 | { |
| 2034 | GtkSpinButton *spin; |
| 2035 | GkrellmChartconfig *cf; |
| 2036 | gint res; |
| 2037 | gfloat fres; |
| 2038 | |
| 2039 | cf = cp->config; |
| 2040 | spin = GTK_SPIN_BUTTON(cf->grid_resolution_spin_button)((((GtkSpinButton*) g_type_check_instance_cast ((GTypeInstance *) ((cf->grid_resolution_spin_button)), ((gtk_spin_button_get_type ())))))); |
| 2041 | if (cf->map_sequence) |
| 2042 | { |
| 2043 | res = gtk_spin_button_get_value_as_int(spin); |
| 2044 | if (res != cf->grid_resolution) |
| 2045 | { |
| 2046 | res = gkrellm_125_sequence(res, cf->sequence_125, |
| 2047 | cf->low, cf->high, FALSE(0), FALSE(0)); |
| 2048 | cf->grid_resolution = res; |
| 2049 | gtk_spin_button_set_value(spin, (gfloat) res); |
| 2050 | if (cf->cb_grid_resolution && !cf->cb_block) |
| 2051 | (*cf->cb_grid_resolution)(cf, cf->cb_grid_resolution_data); |
| 2052 | gkrellm_refresh_chart(cp); |
| 2053 | } |
| 2054 | } |
| 2055 | else |
| 2056 | { |
| 2057 | fres = gtk_spin_button_get_value(spin); |
| 2058 | if (cf->spin_factor > 0.0) |
| 2059 | fres *= cf->spin_factor; |
| 2060 | cf->grid_resolution = (gint) fres; |
| 2061 | if (cf->grid_resolution < 1) |
| 2062 | cf->grid_resolution = 1; |
| 2063 | if (cf->cb_grid_resolution && !cf->cb_block) |
| 2064 | (*cf->cb_grid_resolution)(cf, cf->cb_grid_resolution_data); |
| 2065 | gkrellm_refresh_chart(cp); |
| 2066 | } |
| 2067 | } |
| 2068 | |
| 2069 | |
| 2070 | /* ---- GkrellmChartconfig functions ---- */ |
| 2071 | void |
| 2072 | gkrellm_chartconfig_callback_block(GkrellmChartconfig *cf, gboolean block) |
| 2073 | { |
| 2074 | if (!cf) |
| 2075 | return; |
| 2076 | cf->cb_block = block; |
| 2077 | } |
| 2078 | |
| 2079 | void |
| 2080 | gkrellm_set_chartconfig_grid_resolution(GkrellmChartconfig *cf, gint res) |
| 2081 | { |
| 2082 | if (!cf || res <= 0) |
| 2083 | return; |
| 2084 | cf->grid_resolution = res; |
| 2085 | } |
| 2086 | |
| 2087 | gint |
| 2088 | gkrellm_get_chartconfig_grid_resolution(GkrellmChartconfig *cf) |
| 2089 | { |
| 2090 | if (!cf) |
| 2091 | return 0; |
| 2092 | return cf->grid_resolution; |
| 2093 | } |
| 2094 | |
| 2095 | void |
| 2096 | gkrellm_chartconfig_grid_resolution_connect(GkrellmChartconfig *cf, |
| 2097 | void (*func)(gpointer), gpointer data) |
| 2098 | { |
| 2099 | if (!cf) |
| 2100 | return; |
| 2101 | cf->cb_grid_resolution = func; |
| 2102 | cf->cb_grid_resolution_data = data; |
| 2103 | } |
| 2104 | |
| 2105 | void |
| 2106 | gkrellm_set_chartconfig_flags(GkrellmChartconfig *cf, gint flags) |
| 2107 | { |
| 2108 | if (!cf) |
| 2109 | return; |
| 2110 | cf->flags = flags; |
| 2111 | } |
| 2112 | |
| 2113 | void |
| 2114 | gkrellm_chartconfig_grid_resolution_adjustment(GkrellmChartconfig *cf, |
| 2115 | gboolean map_sequence, gfloat spin_factor, |
| 2116 | gfloat low, gfloat high, gfloat step0, gfloat step1, gint digits, |
| 2117 | gint width) |
| 2118 | { |
| 2119 | if (!cf) |
| 2120 | return; |
| 2121 | cf->map_sequence = map_sequence; |
| 2122 | if ((cf->width = width) == 0) |
| 2123 | cf->width = 70 + log(high / 100000) * 5; |
| 2124 | if (map_sequence) |
| 2125 | { |
| 2126 | cf->low = 1; |
| 2127 | cf->low = (gfloat) gkrellm_125_sequence((gint) low, cf->sequence_125, |
| 2128 | low, high, TRUE(!(0)), FALSE(0)); |
| 2129 | cf->high = (gfloat) gkrellm_125_sequence((gint) high, |
| 2130 | cf->sequence_125, low, high, TRUE(!(0)), TRUE(!(0))); |
| 2131 | cf->step0 = 1.0; |
| 2132 | cf->step1 = 1.0; |
| 2133 | cf->digits = 0; |
| 2134 | } |
| 2135 | else |
| 2136 | { |
| 2137 | cf->low = low; |
| 2138 | cf->high = high; |
| 2139 | cf->step0 = step0; |
| 2140 | cf->step1 = step1; |
| 2141 | cf->digits = digits; |
| 2142 | cf->spin_factor = spin_factor; |
| 2143 | } |
| 2144 | if (cf->spin_factor < 1.0) |
| 2145 | cf->spin_factor = 1.0; |
| 2146 | cf->adjustment_is_set = TRUE(!(0)); |
| 2147 | } |
| 2148 | |
| 2149 | void |
| 2150 | gkrellm_chartconfig_grid_resolution_label(GkrellmChartconfig *cf, gchar *label) |
| 2151 | { |
| 2152 | if (!cf) |
| 2153 | return; |
| 2154 | gkrellm_dup_string(&cf->grid_resolution_label, label); |
| 2155 | } |
| 2156 | |
| 2157 | void |
| 2158 | gkrellm_set_chartconfig_auto_grid_resolution(GkrellmChartconfig *cf, gboolean ato) |
| 2159 | { |
| 2160 | if (cf) |
| 2161 | cf->auto_grid_resolution = ato; |
| 2162 | } |
| 2163 | |
| 2164 | void |
| 2165 | gkrellm_set_chartconfig_auto_resolution_stick(GkrellmChartconfig *cf, gboolean stick) |
| 2166 | { |
| 2167 | if (cf) |
| 2168 | cf->auto_resolution_stick = stick; |
| 2169 | } |
| 2170 | |
| 2171 | void |
| 2172 | gkrellm_set_chartconfig_sequence_125(GkrellmChartconfig *cf, gboolean seq) |
| 2173 | { |
| 2174 | if (cf) |
| 2175 | cf->sequence_125 = seq; |
| 2176 | } |
| 2177 | |
| 2178 | void |
| 2179 | gkrellm_set_chartconfig_fixed_grids(GkrellmChartconfig *cf, gint fixed_grids) |
| 2180 | { |
| 2181 | if (!cf || fixed_grids < 0 || fixed_grids > 5) |
| 2182 | return; |
| 2183 | cf->fixed_grids = fixed_grids; |
| 2184 | } |
| 2185 | |
| 2186 | gint |
| 2187 | gkrellm_get_chartconfig_fixed_grids(GkrellmChartconfig *cf) |
| 2188 | { |
| 2189 | if (!cf) |
| 2190 | return 0; |
| 2191 | return cf->fixed_grids; |
| 2192 | } |
| 2193 | |
| 2194 | void |
| 2195 | gkrellm_chartconfig_fixed_grids_connect(GkrellmChartconfig *cf, |
| 2196 | void (*func)(gpointer), gpointer data) |
| 2197 | { |
| 2198 | if (!cf) |
| 2199 | return; |
| 2200 | cf->cb_fixed_grids = func; |
| 2201 | cf->cb_fixed_grids_data = data; |
| 2202 | } |
| 2203 | |
| 2204 | gint |
| 2205 | gkrellm_get_chartconfig_height(GkrellmChartconfig *cf) |
| 2206 | { |
| 2207 | if (!cf) |
| 2208 | return 0; |
| 2209 | return cf->h; |
| 2210 | } |
| 2211 | |
| 2212 | void |
| 2213 | gkrellm_chartconfig_height_connect(GkrellmChartconfig *cf, |
| 2214 | void (*func)(gpointer), gpointer data) |
| 2215 | { |
| 2216 | if (!cf) |
| 2217 | return; |
| 2218 | cf->cb_height = func; |
| 2219 | cf->cb_height_data = data; |
| 2220 | } |
| 2221 | |
| 2222 | void |
| 2223 | gkrellm_set_chart_height(GkrellmChart *cp, gint h) |
| 2224 | { |
| 2225 | GtkWidget *top_win = gkrellm_get_top_window(); |
| 2226 | GtkSpinButton *spin; |
| 2227 | GList *list; |
| 2228 | GkrellmChartdata *cd; |
| 2229 | GkrellmChartconfig *cf; |
| 2230 | gint dy; |
| 2231 | |
| 2232 | if (!cp || cp->h == h) |
| 2233 | return; |
| 2234 | dy = h - cp->h; |
| 2235 | cp->h = h; |
| 2236 | cp->config->h = h; |
| 2237 | render_default_data_pixmaps(cp); |
| 2238 | for (list = cp->cd_list; list; list = list->next) |
| 2239 | { |
| 2240 | cd = (GkrellmChartdata *) list->data; |
| 2241 | g_object_unref(G_OBJECT(cd->data_bitmap)((((GObject*) g_type_check_instance_cast ((GTypeInstance*) (( cd->data_bitmap)), (((GType) ((20) << (2))))))))); |
| 2242 | g_object_unref(G_OBJECT(cd->layer.pixmap)((((GObject*) g_type_check_instance_cast ((GTypeInstance*) (( cd->layer.pixmap)), (((GType) ((20) << (2))))))))); |
| 2243 | cd->data_bitmap = gdk_pixmap_new(top_win->window, cp->w, cp->h, 1); |
| 2244 | cd->layer.pixmap = gdk_pixmap_new(top_win->window, cp->w, cp->h, -1); |
| 2245 | } |
| 2246 | cp->bg_sequence_id += 1; |
| 2247 | render_chart_pixmaps(cp); |
| 2248 | |
| 2249 | cf = cp->config; |
| 2250 | if (cf->cb_height && !cf->cb_block) |
| 2251 | (*cf->cb_height)(cf, cf->cb_height_data); |
| 2252 | gtk_widget_set_size_request(cp->drawing_area, cp->w, cp->h); |
| 2253 | set_chartdata_split_heights(cp); |
| 2254 | if (cp->shown) |
| 2255 | { |
| 2256 | gkrellm_monitor_height_adjust(dy); |
| 2257 | gkrellm_pack_side_frames(); |
| 2258 | gkrellm_refresh_chart(cp); |
| 2259 | } |
| 2260 | if (cp->config_window) |
| 2261 | { |
| 2262 | spin = GTK_SPIN_BUTTON(cf->height_spin_button)((((GtkSpinButton*) g_type_check_instance_cast ((GTypeInstance *) ((cf->height_spin_button)), ((gtk_spin_button_get_type ( ))))))); |
| 2263 | if (h != gtk_spin_button_get_value_as_int(spin)) |
| 2264 | gtk_spin_button_set_value(spin, (gfloat) h); |
| 2265 | } |
| 2266 | } |
| 2267 | |
| 2268 | gboolean |
| 2269 | gkrellm_get_chartdata_hide(GkrellmChartdata *cd) |
| 2270 | { |
| 2271 | if (cd && cd->hide) |
| 2272 | return TRUE(!(0)); |
| 2273 | return FALSE(0); |
| 2274 | } |
| 2275 | |
| 2276 | |
| 2277 | /* =================================================================== */ |
| 2278 | |
| 2279 | static void |
| 2280 | chart_config_window_close(GtkWidget *widget, GkrellmChart *cp) |
| 2281 | { |
| 2282 | if (cp->config_window) |
| 2283 | gtk_widget_destroy(cp->config_window); |
| 2284 | cp->config_window = NULL((void*)0); |
| 2285 | } |
| 2286 | |
| 2287 | void |
| 2288 | gkrellm_chartconfig_window_destroy(GkrellmChart *cp) |
| 2289 | { |
| 2290 | chart_config_window_close(NULL((void*)0), cp); |
| 2291 | } |
| 2292 | |
| 2293 | static gint |
| 2294 | chart_config_window_delete_event(GtkWidget *widget, GdkEvent *ev, |
| 2295 | gpointer data) |
| 2296 | { |
| 2297 | chart_config_window_close(widget, data); |
| 2298 | return FALSE(0); |
| 2299 | } |
| 2300 | |
| 2301 | static void |
| 2302 | set_resolution_menubar_items_sensitivity(GkrellmChartconfig *cf) |
| 2303 | { |
| 2304 | GtkWidget *w; |
| 2305 | |
| 2306 | if (!cf->auto_resolution_ui_manager) |
| 2307 | return; |
| 2308 | |
| 2309 | w = gtk_ui_manager_get_widget(cf->auto_resolution_ui_manager, |
| 2310 | "/menubar/Control/AutoModeStickPeak"); |
| 2311 | GTK_CHECK_MENU_ITEM(w)((((GtkCheckMenuItem*) g_type_check_instance_cast ((GTypeInstance *) ((w)), ((gtk_check_menu_item_get_type ()))))))->active = cf->auto_resolution_stick; |
| 2312 | |
| 2313 | w = gtk_ui_manager_get_widget(cf->auto_resolution_ui_manager, |
| 2314 | "/menubar/Control/AutoModeRecalibrate"); |
| 2315 | if (cf->auto_grid_resolution) |
| 2316 | gtk_widget_set_sensitive(w, TRUE(!(0))); |
| 2317 | else |
| 2318 | gtk_widget_set_sensitive(w, FALSE(0)); |
| 2319 | } |
| 2320 | |
| 2321 | static void |
| 2322 | cb_chart_height(GtkWidget *adjustment, GkrellmChart *cp) |
| 2323 | { |
| 2324 | GtkSpinButton *spin; |
| 2325 | gint h; |
| 2326 | |
| 2327 | _GK.config_modified = TRUE(!(0)); |
| 2328 | spin = GTK_SPIN_BUTTON(cp->config->height_spin_button)((((GtkSpinButton*) g_type_check_instance_cast ((GTypeInstance *) ((cp->config->height_spin_button)), ((gtk_spin_button_get_type ())))))); |
| 2329 | h = gtk_spin_button_get_value_as_int(spin); |
| 2330 | gkrellm_set_chart_height(cp, h); |
| 2331 | } |
| 2332 | |
| 2333 | static void |
| 2334 | cb_chart_fixed_grids(GtkWidget *adjustment, GkrellmChart *cp) |
| 2335 | { |
| 2336 | GtkSpinButton *spin; |
| 2337 | GkrellmChartconfig *cf = cp->config; |
| 2338 | |
| 2339 | _GK.config_modified = TRUE(!(0)); |
| 2340 | spin = GTK_SPIN_BUTTON(cf->fixed_grids_spin_button)((((GtkSpinButton*) g_type_check_instance_cast ((GTypeInstance *) ((cf->fixed_grids_spin_button)), ((gtk_spin_button_get_type ())))))); |
| 2341 | cf->fixed_grids = gtk_spin_button_get_value_as_int(spin); |
| 2342 | if (cf->auto_grid_resolution) |
| 2343 | set_auto_grid_resolution(cp, cp->maxval_auto); |
| 2344 | if (cf->cb_fixed_grids && !cf->cb_block) |
| 2345 | (*cf->cb_fixed_grids)(cf, cf->cb_fixed_grids_data); |
| 2346 | |
| 2347 | set_resolution_menubar_items_sensitivity(cf); |
| 2348 | |
| 2349 | gkrellm_refresh_chart(cp); |
| 2350 | } |
| 2351 | |
| 2352 | static void |
| 2353 | cb_line_draw_style(GtkWidget *widget, GkrellmChartdata *cd) |
| 2354 | { |
| 2355 | _GK.config_modified = TRUE(!(0)); |
| 2356 | cd->draw_style = GTK_TOGGLE_BUTTON(widget)((((GtkToggleButton*) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((gtk_toggle_button_get_type ()))))))->active; |
| 2357 | gkrellm_rescale_chart(cd->chart); |
| 2358 | } |
| 2359 | |
| 2360 | static void |
| 2361 | cb_auto_resolution(GtkWidget *widget, GkrellmChart *cp) |
| 2362 | { |
| 2363 | GtkWidget *button; |
| 2364 | GkrellmChartconfig *cf = cp->config; |
| 2365 | |
| 2366 | _GK.config_modified = TRUE(!(0)); |
| 2367 | cf->auto_grid_resolution = GTK_TOGGLE_BUTTON(widget)((((GtkToggleButton*) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((gtk_toggle_button_get_type ()))))))->active; |
| 2368 | |
| 2369 | set_resolution_menubar_items_sensitivity(cf); |
| 2370 | button = cf->grid_resolution_spin_button; |
| 2371 | if (cf->auto_grid_resolution) |
| 2372 | gtk_widget_set_sensitive(button, FALSE(0)); |
| 2373 | else |
| 2374 | gtk_widget_set_sensitive(button, TRUE(!(0))); |
| 2375 | gkrellm_rescale_chart(cp); |
| 2376 | } |
| 2377 | |
| 2378 | static void |
| 2379 | cb_inverted_draw_mode(GtkWidget *widget, GkrellmChartdata *cd) |
| 2380 | { |
| 2381 | _GK.config_modified = TRUE(!(0)); |
| 2382 | cd->inverted = GTK_TOGGLE_BUTTON(widget)((((GtkToggleButton*) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((gtk_toggle_button_get_type ()))))))->active; |
| 2383 | gkrellm_rescale_chart(cd->chart); |
| 2384 | } |
| 2385 | |
| 2386 | static void |
| 2387 | cb_hide(GtkWidget *widget, GkrellmChartdata *cd) |
| 2388 | { |
| 2389 | _GK.config_modified = TRUE(!(0)); |
| 2390 | cd->hide = GTK_TOGGLE_BUTTON(widget)((((GtkToggleButton*) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((gtk_toggle_button_get_type ()))))))->active; |
| 2391 | set_chartdata_split_heights(cd->chart); |
| 2392 | gkrellm_rescale_chart(cd->chart); |
| 2393 | } |
| 2394 | |
| 2395 | static void |
| 2396 | cb_split_mode(GtkWidget *widget, GkrellmChartdata *cd) |
| 2397 | { |
| 2398 | _GK.config_modified = TRUE(!(0)); |
| 2399 | cd->split_chart = GTK_TOGGLE_BUTTON(widget)((((GtkToggleButton*) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((gtk_toggle_button_get_type ()))))))->active; |
| 2400 | gtk_widget_set_sensitive(cd->split_fraction_spin_button, cd->split_chart); |
| 2401 | set_chartdata_split_heights(cd->chart); |
| 2402 | gkrellm_rescale_chart(cd->chart); |
| 2403 | } |
| 2404 | |
| 2405 | static void |
| 2406 | cb_split_fraction(GtkWidget *adjustment, GkrellmChartdata *cd) |
| 2407 | { |
| 2408 | GtkSpinButton *spin; |
| 2409 | |
| 2410 | _GK.config_modified = TRUE(!(0)); |
| 2411 | spin = GTK_SPIN_BUTTON(cd->split_fraction_spin_button)((((GtkSpinButton*) g_type_check_instance_cast ((GTypeInstance *) ((cd->split_fraction_spin_button)), ((gtk_spin_button_get_type ())))))); |
| 2412 | cd->split_fraction = gtk_spin_button_get_value(spin); |
| 2413 | set_chartdata_split_heights(cd->chart); |
| 2414 | gkrellm_rescale_chart(cd->chart); |
| 2415 | } |
| 2416 | |
| 2417 | |
| 2418 | /* =================================================================== */ |
| 2419 | |
| 2420 | static void |
| 2421 | cb_seq_control(GtkRadioAction *action, GtkRadioAction *current, GkrellmChart *cp ) |
| 2422 | { |
| 2423 | GkrellmChartconfig *cf = cp->config; |
| 2424 | |
| 2425 | if (cf->sequence_125 == gtk_radio_action_get_current_value(action)) |
| 2426 | return; |
| 2427 | cf->sequence_125 = gtk_radio_action_get_current_value(action); |
| 2428 | |
| 2429 | cf->grid_resolution = gkrellm_125_sequence(cf->grid_resolution, |
| 2430 | cf->sequence_125, cf->low, cf->high, TRUE(!(0)), FALSE(0)); |
| 2431 | set_grid_resolution_spin_button(cp, cf->grid_resolution); |
| 2432 | } |
| 2433 | |
| 2434 | static void |
| 2435 | cb_auto_stick_control(GtkToggleAction *action, GkrellmChart *cp ) |
| 2436 | { |
| 2437 | GkrellmChartconfig *cf = cp->config; |
| 2438 | |
| 2439 | cf->auto_resolution_stick = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)((((GtkToggleAction*) g_type_check_instance_cast ((GTypeInstance *) ((action)), ((gtk_toggle_action_get_type ()))))))); |
| 2440 | cp->maxval_auto_base = 0; |
| 2441 | gkrellm_refresh_chart(cp); |
| 2442 | } |
| 2443 | |
| 2444 | static void |
| 2445 | cb_auto_res_control(GtkAction *action, GkrellmChart *cp ) |
| 2446 | { |
| 2447 | cp->maxval_auto_base = 0; |
| 2448 | cp->maxval_peak = 0; |
| 2449 | gkrellm_refresh_chart(cp); |
| 2450 | } |
| 2451 | |
| 2452 | static const char *auto_res_control_items = "\ |
| 2453 | <ui>\ |
| 2454 | <menubar>\ |
| 2455 | <menu name=\"Control\" action=\"ControlAction\">\ |
| 2456 | <separator/>\ |
| 2457 | <menuitem name=\"AutoModeRecalibrate\" action=\"AutoModeRecalibrateAction\"/>\ |
| 2458 | <menuitem name=\"AutoModeStickPeak\" action=\"AutoModeStickPeakAction\"/>\ |
| 2459 | <menu name=\"SequenceMenu\" action=\"SequenceMenuAction\">\ |
| 2460 | <menuitem name=\"Seq125\" action=\"Seq125Action\"/>\ |
| 2461 | <menuitem name=\"Seq1357\" action=\"Seq1357Action\"/>\ |
| 2462 | </menu>\ |
| 2463 | <separator/>\ |
| 2464 | </menu>\ |
| 2465 | </menubar>\ |
| 2466 | </ui>\ |
| 2467 | "; |
| 2468 | |
| 2469 | static GtkActionEntry auto_res_control_entries[] = |
| 2470 | { |
| 2471 | { "ControlAction", NULL((void*)0), N_("Control")("Control"), |
| 2472 | NULL((void*)0), NULL((void*)0), G_CALLBACK(NULL)((GCallback) (((void*)0))) }, |
| 2473 | { "SequenceMenuAction", NULL((void*)0), N_("Sequence...")("Sequence..."), |
| 2474 | NULL((void*)0), NULL((void*)0), G_CALLBACK(NULL)((GCallback) (((void*)0))) }, |
| 2475 | { "AutoModeRecalibrateAction", NULL((void*)0), N_("Auto mode recalibrate")("Auto mode recalibrate"), |
| 2476 | NULL((void*)0), NULL((void*)0), G_CALLBACK(cb_auto_res_control)((GCallback) (cb_auto_res_control)) }, |
| 2477 | }; |
| 2478 | static guint n_auto_res_control_entries = G_N_ELEMENTS (auto_res_control_entries)(sizeof (auto_res_control_entries) / sizeof ((auto_res_control_entries )[0])); |
| 2479 | |
| 2480 | static GtkToggleActionEntry auto_res_control_toggle_entries[] = |
| 2481 | { |
| 2482 | { "AutoModeStickPeakAction", NULL((void*)0), N_("Auto mode sticks at peak value")("Auto mode sticks at peak value"), |
| 2483 | NULL((void*)0), NULL((void*)0), G_CALLBACK(cb_auto_stick_control)((GCallback) (cb_auto_stick_control)), FALSE(0) }, |
| 2484 | }; |
| 2485 | static guint n_auto_res_control_toggle_entries = G_N_ELEMENTS (auto_res_control_toggle_entries)(sizeof (auto_res_control_toggle_entries) / sizeof ((auto_res_control_toggle_entries )[0])); |
| 2486 | |
| 2487 | static GtkRadioActionEntry auto_res_control_radio_entries[] = |
| 2488 | { |
| 2489 | { "Seq125Action", NULL((void*)0), N_("1 2 5")("1 2 5"), |
| 2490 | NULL((void*)0), NULL((void*)0), 1 }, |
| 2491 | { "Seq1357Action", NULL((void*)0), N_("1 1.5 2 3 5 7")("1 1.5 2 3 5 7"), |
| 2492 | NULL((void*)0), NULL((void*)0), 0 }, |
| 2493 | }; |
| 2494 | static guint n_auto_res_control_radio_entries = G_N_ELEMENTS (auto_res_control_radio_entries)(sizeof (auto_res_control_radio_entries) / sizeof ((auto_res_control_radio_entries )[0])); |
| 2495 | |
| 2496 | static void |
| 2497 | auto_resolution_control_menubar(GtkWidget **menubar, GkrellmChart *cp) |
| 2498 | { |
| 2499 | GtkUIManager *ui_manager; |
| 2500 | GtkActionGroup *action_group; |
| 2501 | GkrellmChartconfig *cf = cp->config; |
| 2502 | GError *error; |
| 2503 | |
| 2504 | action_group = gtk_action_group_new ("ControlActions"); |
| 2505 | gtk_action_group_add_actions (action_group, auto_res_control_entries, |
| 2506 | n_auto_res_control_entries, cp); |
| 2507 | gtk_action_group_add_toggle_actions (action_group, auto_res_control_toggle_entries, |
| 2508 | n_auto_res_control_toggle_entries, cp); |
| 2509 | gtk_action_group_add_radio_actions (action_group, auto_res_control_radio_entries, |
| 2510 | n_auto_res_control_radio_entries, |
| 2511 | !!cf->sequence_125, G_CALLBACK(cb_seq_control)((GCallback) (cb_seq_control)), |
| 2512 | cp); |
| 2513 | ui_manager = gtk_ui_manager_new (); |
| 2514 | error = NULL((void*)0); |
| 2515 | gtk_ui_manager_add_ui_from_string (ui_manager, auto_res_control_items, |
| 2516 | strlen(auto_res_control_items), &error); |
| 2517 | if (error) |
| 2518 | { |
| 2519 | g_message ("building menus failed: %s", error->message); |
| 2520 | g_error_free (error); |
| 2521 | return; |
| 2522 | } |
| 2523 | gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); |
| 2524 | cf->auto_resolution_ui_manager = ui_manager; |
| 2525 | set_resolution_menubar_items_sensitivity(cf); |
| 2526 | |
| 2527 | if (menubar) |
| 2528 | *menubar = gtk_ui_manager_get_widget(ui_manager, "/menubar"); |
| 2529 | } |
| 2530 | |
| 2531 | void |
| 2532 | gkrellm_chartconfig_window_create(GkrellmChart *cp) |
| 2533 | { |
| 2534 | GtkWidget *main_vbox, *vbox, *vbox1, *vbox2, *hbox; |
| 2535 | GtkWidget *button; |
| 2536 | GList *list; |
| 2537 | GkrellmChartconfig *cf; |
| 2538 | GkrellmChartdata *cd; |
| 2539 | GkrellmPanel *p; |
| 2540 | gchar *s; |
| 2541 | |
| 2542 | if (!cp || _GK.no_config) |
| 2543 | return; |
| 2544 | if (cp->config_window) |
| 2545 | { |
| 2546 | gtk_window_present(GTK_WINDOW(cp->config_window)((((GtkWindow*) g_type_check_instance_cast ((GTypeInstance*) ( (cp->config_window)), ((gtk_window_get_type ()))))))); |
| 2547 | return; |
| 2548 | } |
| 2549 | cp->config_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 2550 | g_signal_connect(G_OBJECT(cp->config_window), "delete_event",g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((cp->config_window)), (((GType) ((20) << (2))))))))), ("delete_event"), (((GCallback) (chart_config_window_delete_event ))), (cp), ((void*)0), (GConnectFlags) 0) |
| 2551 | G_CALLBACK(chart_config_window_delete_event), cp)g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((cp->config_window)), (((GType) ((20) << (2))))))))), ("delete_event"), (((GCallback) (chart_config_window_delete_event ))), (cp), ((void*)0), (GConnectFlags) 0); |
| 2552 | |
| 2553 | p = cp->panel; |
| 2554 | cf = cp->config; |
| 2555 | if (p && p->label) |
| 2556 | s = p->label->string; |
| 2557 | else |
| 2558 | s = NULL((void*)0); |
| 2559 | gtk_window_set_title(GTK_WINDOW(cp->config_window)((((GtkWindow*) g_type_check_instance_cast ((GTypeInstance*) ( (cp->config_window)), ((gtk_window_get_type ())))))), |
| 2560 | _("GKrellM Chart Config")dcgettext ("gkrellm", "GKrellM Chart Config", 5)); |
| 2561 | gtk_window_set_wmclass(GTK_WINDOW(cp->config_window)((((GtkWindow*) g_type_check_instance_cast ((GTypeInstance*) ( (cp->config_window)), ((gtk_window_get_type ())))))), |
| 2562 | "Gkrellm_conf", "Gkrellm"); |
| 2563 | |
| 2564 | main_vbox = gtk_vbox_new(FALSE(0), 0); |
| 2565 | gtk_container_set_border_width(GTK_CONTAINER(cp->config_window)((((GtkContainer*) g_type_check_instance_cast ((GTypeInstance *) ((cp->config_window)), ((gtk_container_get_type ()))))) ), 4); |
| 2566 | gtk_container_add(GTK_CONTAINER(cp->config_window)((((GtkContainer*) g_type_check_instance_cast ((GTypeInstance *) ((cp->config_window)), ((gtk_container_get_type ()))))) ), main_vbox); |
| 2567 | vbox = gkrellm_gtk_framed_vbox(main_vbox, s, 4, FALSE(0), 4, 3); |
| 2568 | |
| 2569 | hbox = gtk_hbox_new(TRUE(!(0)), 0); |
| 2570 | gtk_box_pack_start(GTK_BOX(vbox)((((GtkBox*) g_type_check_instance_cast ((GTypeInstance*) ((vbox )), ((gtk_box_get_type ())))))), hbox, FALSE(0), FALSE(0), 0); |
| 2571 | for (list = cp->cd_list; list; list = list->next) |
| 2572 | { |
| 2573 | cd = (GkrellmChartdata *) list->data; |
| 2574 | if ((cd->flags & CHARTDATA_NO_CONFIG0xf) == CHARTDATA_NO_CONFIG0xf) |
| 2575 | continue; |
| 2576 | vbox1 = gkrellm_gtk_framed_vbox(hbox, cd->label, 2, TRUE(!(0)), 2, 2); |
| 2577 | |
| 2578 | if (!(cd->flags & CHARTDATA_NO_CONFIG_DRAW_STYLE2)) |
| 2579 | { |
| 2580 | gkrellm_gtk_check_button(vbox1, &button, cd->draw_style, FALSE(0), 0, |
| 2581 | _("Line style")dcgettext ("gkrellm", "Line style", 5)); |
| 2582 | g_signal_connect(G_OBJECT(button), "toggled",g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((button)), (((GType) ((20) << (2))) )))))), ("toggled"), (((GCallback) (cb_line_draw_style))), (cd ), ((void*)0), (GConnectFlags) 0) |
| 2583 | G_CALLBACK(cb_line_draw_style), cd)g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((button)), (((GType) ((20) << (2))) )))))), ("toggled"), (((GCallback) (cb_line_draw_style))), (cd ), ((void*)0), (GConnectFlags) 0); |
| 2584 | } |
| 2585 | if (!(cd->flags & CHARTDATA_NO_CONFIG_INVERTED4)) |
| 2586 | { |
| 2587 | gkrellm_gtk_check_button(vbox1, &button, cd->inverted, FALSE(0), 0, |
| 2588 | _("Inverted")dcgettext ("gkrellm", "Inverted", 5)); |
| 2589 | g_signal_connect(G_OBJECT(button), "toggled",g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((button)), (((GType) ((20) << (2))) )))))), ("toggled"), (((GCallback) (cb_inverted_draw_mode))), (cd), ((void*)0), (GConnectFlags) 0) |
| 2590 | G_CALLBACK(cb_inverted_draw_mode), cd)g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((button)), (((GType) ((20) << (2))) )))))), ("toggled"), (((GCallback) (cb_inverted_draw_mode))), (cd), ((void*)0), (GConnectFlags) 0); |
| 2591 | } |
| 2592 | if (list != cp->cd_list && !(cd->flags & CHARTDATA_NO_CONFIG_SPLIT8)) |
| 2593 | { |
| 2594 | vbox2 = gkrellm_gtk_framed_vbox(vbox1, NULL((void*)0), 2, FALSE(0), 2, 2); |
| 2595 | gkrellm_gtk_check_button(vbox2, &button, cd->split_chart, FALSE(0), 0, |
| 2596 | _("Split view")dcgettext ("gkrellm", "Split view", 5)); |
| 2597 | g_signal_connect(G_OBJECT(button), "toggled",g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((button)), (((GType) ((20) << (2))) )))))), ("toggled"), (((GCallback) (cb_split_mode))), (cd), ( (void*)0), (GConnectFlags) 0) |
| 2598 | G_CALLBACK(cb_split_mode), cd)g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((button)), (((GType) ((20) << (2))) )))))), ("toggled"), (((GCallback) (cb_split_mode))), (cd), ( (void*)0), (GConnectFlags) 0); |
| 2599 | gkrellm_gtk_spin_button(vbox2, &button, cd->split_fraction, |
| 2600 | 0.05, 0.95, 0.01, 0.05, 2, 55, |
| 2601 | cb_split_fraction, cd, FALSE(0), ""); |
| 2602 | gtk_widget_set_sensitive(button, cd->split_chart); |
| 2603 | cd->split_fraction_spin_button = button; |
| 2604 | } |
| 2605 | if (cd->flags & CHARTDATA_ALLOW_HIDE1) |
| 2606 | { |
| 2607 | gkrellm_gtk_check_button(vbox1, &button, cd->hide, FALSE(0), 0, |
| 2608 | _("Hide")dcgettext ("gkrellm", "Hide", 5)); |
| 2609 | g_signal_connect(G_OBJECT(button), "toggled",g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((button)), (((GType) ((20) << (2))) )))))), ("toggled"), (((GCallback) (cb_hide))), (cd), ((void* )0), (GConnectFlags) 0) |
| 2610 | G_CALLBACK(cb_hide), cd)g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((button)), (((GType) ((20) << (2))) )))))), ("toggled"), (((GCallback) (cb_hide))), (cd), ((void* )0), (GConnectFlags) 0); |
| 2611 | } |
| 2612 | } |
| 2613 | |
| 2614 | cf->auto_resolution_control_menubar = NULL((void*)0); |
| 2615 | cf->auto_resolution_ui_manager = NULL((void*)0); |
| 2616 | cf->grid_resolution_spin_button = NULL((void*)0); |
| 2617 | cf->fixed_grids_spin_button = NULL((void*)0); |
| 2618 | |
| 2619 | if (cf->adjustment_is_set) |
| 2620 | { |
| 2621 | gfloat value; |
| 2622 | |
| 2623 | vbox1 = gkrellm_gtk_framed_vbox(vbox, _("Resolution per Grid")dcgettext ("gkrellm", "Resolution per Grid", 5), |
| 2624 | 2, FALSE(0), 2, 2); |
| 2625 | if (cf->map_sequence) |
| 2626 | value = (gfloat) cf->grid_resolution; |
| 2627 | else |
| 2628 | value = cf->grid_resolution / cf->spin_factor; |
| 2629 | gkrellm_gtk_spin_button(vbox1, &button, value, |
| 2630 | cf->low, cf->high, cf->step0, cf->step1, cf->digits, cf->width, |
| 2631 | cb_chart_grid_resolution, cp, FALSE(0), cf->grid_resolution_label); |
| 2632 | cf->grid_resolution_spin_button = button; |
| 2633 | if (cp->config->auto_grid_resolution) |
| 2634 | gtk_widget_set_sensitive(button, FALSE(0)); |
| 2635 | |
| 2636 | if (!(cp->config->flags & NO_CONFIG_AUTO_GRID_RESOLUTION1)) |
| 2637 | { |
| 2638 | hbox = gtk_hbox_new (FALSE(0), 0); |
| 2639 | gtk_container_set_border_width(GTK_CONTAINER(hbox)((((GtkContainer*) g_type_check_instance_cast ((GTypeInstance *) ((hbox)), ((gtk_container_get_type ())))))), 2); |
| 2640 | gtk_container_add(GTK_CONTAINER(vbox1)((((GtkContainer*) g_type_check_instance_cast ((GTypeInstance *) ((vbox1)), ((gtk_container_get_type ())))))), hbox); |
| 2641 | gkrellm_gtk_check_button(hbox, &button, |
| 2642 | cp->config->auto_grid_resolution, TRUE(!(0)), 0, |
| 2643 | _("Auto")dcgettext ("gkrellm", "Auto", 5)); |
| 2644 | g_signal_connect(G_OBJECT(button), "toggled",g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((button)), (((GType) ((20) << (2))) )))))), ("toggled"), (((GCallback) (cb_auto_resolution))), (cp ), ((void*)0), (GConnectFlags) 0) |
| 2645 | G_CALLBACK(cb_auto_resolution), cp)g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((button)), (((GType) ((20) << (2))) )))))), ("toggled"), (((GCallback) (cb_auto_resolution))), (cp ), ((void*)0), (GConnectFlags) 0); |
| 2646 | |
| 2647 | auto_resolution_control_menubar( |
| 2648 | &cf->auto_resolution_control_menubar, cp); |
| 2649 | gtk_box_pack_start(GTK_BOX(hbox)((((GtkBox*) g_type_check_instance_cast ((GTypeInstance*) ((hbox )), ((gtk_box_get_type ())))))), |
| 2650 | cf->auto_resolution_control_menubar, FALSE(0), TRUE(!(0)), 10); |
| 2651 | } |
| 2652 | } |
| 2653 | if (!(cp->config->flags & NO_CONFIG_FIXED_GRIDS2)) |
| 2654 | { |
| 2655 | vbox1 = gkrellm_gtk_framed_vbox(vbox, _("Number of Grids")dcgettext ("gkrellm", "Number of Grids", 5), 2, FALSE(0), |
| 2656 | 2, 2); |
| 2657 | gkrellm_gtk_spin_button(vbox1, &button, (gfloat) cf->fixed_grids, |
| 2658 | 0, 5, 1.0, 1.0, 0, 50, |
| 2659 | cb_chart_fixed_grids, cp, FALSE(0), |
| 2660 | _("0: Auto 1-5: Constant")dcgettext ("gkrellm", "0: Auto 1-5: Constant", 5)); |
| 2661 | cf->fixed_grids_spin_button = button; |
| 2662 | } |
| 2663 | |
| 2664 | vbox1 = gkrellm_gtk_framed_vbox(vbox, NULL((void*)0), 2, FALSE(0), 2, 2); |
| 2665 | gkrellm_gtk_spin_button(vbox1, &button, (gfloat) cp->h, |
| 2666 | (gfloat) _GK.chart_height_min, (gfloat) _GK.chart_height_max, |
| 2667 | 5.0, 10.0, 0, 50, |
| 2668 | cb_chart_height, cp, FALSE(0), |
| 2669 | _("Chart height")dcgettext ("gkrellm", "Chart height", 5)); |
| 2670 | cf->height_spin_button = button; |
| 2671 | |
| 2672 | hbox = gtk_hbutton_box_new(); |
| 2673 | gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox)((((GtkButtonBox*) g_type_check_instance_cast ((GTypeInstance *) ((hbox)), ((gtk_button_box_get_type ())))))), GTK_BUTTONBOX_END); |
| 2674 | gtk_box_set_spacing(GTK_BOX(hbox)((((GtkBox*) g_type_check_instance_cast ((GTypeInstance*) ((hbox )), ((gtk_box_get_type ())))))), 5); |
| 2675 | gtk_box_pack_start(GTK_BOX(main_vbox)((((GtkBox*) g_type_check_instance_cast ((GTypeInstance*) ((main_vbox )), ((gtk_box_get_type ())))))), hbox, FALSE(0), FALSE(0), 0); |
| 2676 | |
| 2677 | button = gtk_button_new_from_stock(GTK_STOCK_OK"gtk-ok"); |
| 2678 | GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT)do{ (((((((GtkObject*) g_type_check_instance_cast ((GTypeInstance *) ((button)), ((gtk_object_get_type ()))))))->flags)) |= ( GTK_CAN_DEFAULT)); }while (0); |
| 2679 | g_signal_connect(G_OBJECT(button), "clicked",g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((button)), (((GType) ((20) << (2))) )))))), ("clicked"), (((GCallback) (chart_config_window_close ))), (cp), ((void*)0), (GConnectFlags) 0) |
| 2680 | G_CALLBACK(chart_config_window_close), cp)g_signal_connect_data ((((((GObject*) g_type_check_instance_cast ((GTypeInstance*) ((button)), (((GType) ((20) << (2))) )))))), ("clicked"), (((GCallback) (chart_config_window_close ))), (cp), ((void*)0), (GConnectFlags) 0); |
| 2681 | gtk_box_pack_start(GTK_BOX(hbox)((((GtkBox*) g_type_check_instance_cast ((GTypeInstance*) ((hbox )), ((gtk_box_get_type ())))))), button, TRUE(!(0)), TRUE(!(0)), 15); |
| 2682 | gtk_widget_grab_default(button); |
| 2683 | |
| 2684 | gtk_widget_show_all(cp->config_window); |
| 2685 | } |
| 2686 | |
| 2687 | void |
| 2688 | gkrellm_save_chartconfig(FILE *f, GkrellmChartconfig *cf, gchar *mon_keyword, |
| 2689 | gchar *name) |
| 2690 | { |
| 2691 | GList *list; |
| 2692 | GkrellmChartdata *cd; |
| 2693 | |
| 2694 | if (!f || !cf || !mon_keyword) |
| 2695 | return; |
| 2696 | if (name) |
| 2697 | fprintf(f, "%s %s %s ", mon_keyword, GKRELLM_CHARTCONFIG_KEYWORD"chart_config",name); |
| 2698 | else |
| 2699 | fprintf(f, "%s %s ", mon_keyword, GKRELLM_CHARTCONFIG_KEYWORD"chart_config"); |
| 2700 | fprintf(f, "%d %d %d %d %d %d", cf->h, cf->grid_resolution, |
| 2701 | cf->fixed_grids, cf->auto_grid_resolution, |
| 2702 | cf->auto_resolution_stick, cf->sequence_125); |
| 2703 | for (list = cf->cd_list; list; list = list->next) |
| 2704 | { |
| 2705 | cd = (GkrellmChartdata *) list->data; |
| 2706 | fprintf(f, " : %d %d %d %d %.0f", |
| 2707 | cd->draw_style, cd->inverted, cd->hide, |
| 2708 | cd->split_chart, cd->split_fraction * GKRELLM_FLOAT_FACTOR1000.0); |
| 2709 | } |
| 2710 | fprintf(f, "\n"); |
| 2711 | } |
| 2712 | |
| 2713 | void |
| 2714 | gkrellm_load_chartconfig(GkrellmChartconfig **config, gchar *string, |
| 2715 | gint max_cd) |
| 2716 | { |
| 2717 | GList *list; |
| 2718 | GkrellmChartdata *cd; |
| 2719 | GkrellmChartconfig *cf; |
| 2720 | gchar *s; |
| 2721 | gint index = 0; |
| 2722 | |
| 2723 | if (!config || !string) |
| 2724 | return; |
| 2725 | if (!*config) |
| 2726 | { |
| 2727 | *config = gkrellm_chartconfig_new0(); |
| 2728 | (*config)->auto_grid_resolution = TRUE(!(0)); /* the default */ |
| 2729 | } |
| 2730 | cf = *config; |
| 2731 | sscanf(string, "%d %d %d %d %d %d", &cf->h, &cf->grid_resolution, |
| 2732 | &cf->fixed_grids, &cf->auto_grid_resolution, |
| 2733 | &cf->auto_resolution_stick, &cf->sequence_125); |
| 2734 | for (s = strchr(string, (int) ':')(__extension__ (__builtin_constant_p ((int) ':') && ! __builtin_constant_p (string) && ((int) ':') == '\0' ? (char *) __rawmemchr (string, (int) ':') : __builtin_strchr ( string, (int) ':'))); s ; s = strchr(s, (int) ':')(__extension__ (__builtin_constant_p ((int) ':') && ! __builtin_constant_p (s) && ((int) ':') == '\0' ? (char *) __rawmemchr (s, (int) ':') : __builtin_strchr (s, (int) ':' )))) |
| 2735 | { |
| 2736 | ++s; |
| 2737 | list = g_list_nth(cf->cd_list, index++); |
| 2738 | if (!list) |
| 2739 | { |
| 2740 | cd = g_new0(GkrellmChartdata, 1)(GkrellmChartdata *) (__extension__ ({ gsize __n = (gsize) (1 ); gsize __s = sizeof (GkrellmChartdata); gpointer __p; if (__s == 1) __p = g_malloc0 (__n); else if (__builtin_constant_p ( __n) && (__s == 0 || __n <= (9223372036854775807L * 2UL+1UL) / __s)) __p = g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p; })); |
| 2741 | cd->split_fraction = 0.5; |
| 2742 | cf->cd_list = g_list_append(cf->cd_list, cd); |
| 2743 | } |
| 2744 | else |
| 2745 | cd = (GkrellmChartdata *) list->data; |
| 2746 | sscanf(s, "%d %d %d %d %f", |
| 2747 | &cd->draw_style, &cd->inverted, &cd->hide, |
| 2748 | &cd->split_chart, &cd->split_fraction); |
| 2749 | cd->split_fraction /= _GK.float_factor; |
| 2750 | if (cd->split_fraction <= 0.01 || cd->split_fraction >= 0.99) |
| 2751 | cd->split_fraction = 0.5; |
| 2752 | |
| 2753 | cf->config_loaded = TRUE(!(0)); |
| 2754 | if (max_cd && index >= max_cd) |
| 2755 | break; |
| 2756 | } |
| 2757 | } |
| 2758 | |
| 2759 | void |
| 2760 | debug_dump_chart_list() |
| 2761 | { |
| 2762 | GList *list, *cdlist; |
| 2763 | GkrellmChart *cp; |
| 2764 | GkrellmPanel *p; |
| 2765 | GkrellmChartdata *cd; |
| 2766 | |
| 2767 | g_debug("\n"); |
| 2768 | for (list = gkrellm_get_chart_list(); list; list = list->next) |
| 2769 | { |
| 2770 | cp = (GkrellmChart *) list->data; |
| 2771 | p = cp->panel; |
| 2772 | if (p && p->label && p->label->string) |
| 2773 | g_debug("%s [%d]: ", p->label->string, cp->style_id); |
| 2774 | else |
| 2775 | g_debug("(null) [%d]: ", cp->style_id); |
| 2776 | for (cdlist = cp->cd_list; cdlist; cdlist = cdlist->next) |
| 2777 | { |
| 2778 | cd = (GkrellmChartdata *) cdlist->data; |
| 2779 | g_debug("%s %p->data ", cd->label, cd->data); |
| 2780 | } |
| 2781 | g_debug("\n"); |
| 2782 | } |
| 2783 | } |