📄 krell.c
字号:
k->w = w_render; k->stencil = gdk_pixmap_new(top_win->window, _GK.chart_width, k->h_frame, 1); k->period = style->krell_ema_period; if (k->period >= 4 * _GK.update_HZ) k->period = 4 * _GK.update_HZ; k->x_position = -1; /* Force initial draw */ k->full_scale_expand = 1; k->monotonic = TRUE; return k; }voidgkrellm_monotonic_krell_values(GkrellmKrell *k, gboolean mono) { if (k) k->monotonic = mono; }/* -------------------------------------------------------------- */static voidremove_from_button_list(GkrellmPanel *p, GkrellmDecalbutton *b) { if (!p || !b) return; p->button_list = g_list_remove(p->button_list, b); g_free(b); if (!p->button_list && p->drawing_area) { g_signal_handler_disconnect(G_OBJECT(p->drawing_area), p->id_press); g_signal_handler_disconnect(G_OBJECT(p->drawing_area), p->id_release); g_signal_handler_disconnect(G_OBJECT(p->drawing_area), p->id_enter); g_signal_handler_disconnect(G_OBJECT(p->drawing_area), p->id_leave); p->button_signals_connected = FALSE; } }voidgkrellm_move_decal(GkrellmPanel *p, GkrellmDecal *d, gint x, gint y) { if (!d || (d->x == x && d->y == y)) return; if (!(d->flags & DF_MOVED)) /* If no intervening draw_panel_layers() */ { /* then preserve original old position */ d->x_old = d->x; d->y_old = d->y; } d->x = x; d->y = y; d->flags |= DF_MOVED; d->modified = TRUE; if (p) p->need_decal_overlap_check = TRUE; }voidgkrellm_decal_on_top_layer(GkrellmDecal *d, gboolean top) { GkrellmPanel *p = (GkrellmPanel *) d->panel; if (!d) return; if (top) d->flags |= DF_TOP_LAYER; else d->flags &= ~DF_TOP_LAYER; if (p) p->need_decal_overlap_check = TRUE; d->modified = TRUE; }static void_destroy_decal(GkrellmDecal *d) { if (!d) return; if ((d->flags & DF_LOCAL_PIXMAPS) && d->pixmap) g_object_unref(G_OBJECT(d->pixmap)); if (d->stencil) g_object_unref(G_OBJECT(d->stencil)); if (d->text_list) decal_text_list_free(&d->text_list); if (d->scroll_text) g_free(d->scroll_text); if (d->panel) ((GkrellmPanel *)d->panel)->need_decal_overlap_check = TRUE; g_free(d); }static void_remove_decal(GkrellmPanel *p, GkrellmDecal *d) { if (!g_list_find(p->decal_list, d)) return; p->decal_list = g_list_remove(p->decal_list, d); p->need_decal_overlap_check = TRUE; d->panel = NULL; if (p->pixmap && p->bg_pixmap) { gdk_draw_drawable(p->pixmap, _GK.draw1_GC, p->bg_pixmap, d->x, d->y, d->x, d->y, d->w, d->h); if (p->drawing_area && p->drawing_area->window) gdk_draw_drawable(p->drawing_area->window, _GK.draw1_GC, p->bg_pixmap, d->x, d->y, d->x, d->y, d->w, d->h); gkrellm_draw_panel_layers_force(p); } }voidgkrellm_destroy_decal(GkrellmDecal *d) { GkrellmDecalbutton *b; if (d && d->panel) { if ((b = gkrellm_decal_is_button(d)) != NULL) gkrellm_destroy_button(b); else { _remove_decal((GkrellmPanel *) d->panel, d); _destroy_decal(d); } } else _destroy_decal(d); }voidgkrellm_remove_decal(GkrellmPanel *p, GkrellmDecal *d) { if (!p || !d || gkrellm_decal_is_button(d)) return; _remove_decal(p, d); }voidgkrellm_insert_decal(GkrellmPanel *p, GkrellmDecal *d, gboolean append) { if (!p || !d || g_list_find(p->decal_list, d)) return; if (append) p->decal_list = g_list_append(p->decal_list, d); else p->decal_list = g_list_prepend(p->decal_list, d); d->panel = (gpointer) p; p->need_decal_overlap_check = TRUE; gkrellm_draw_panel_layers_force(p); }voidgkrellm_insert_decal_nth(GkrellmPanel *p, GkrellmDecal *d, gint n) { if (!p || !d || g_list_find(p->decal_list, d)) return; p->decal_list = g_list_insert(p->decal_list, d, n); d->panel = (gpointer) p; p->need_decal_overlap_check = TRUE; gkrellm_draw_panel_layers_force(p); }voidgkrellm_destroy_decal_list(GkrellmPanel *p) { GkrellmDecalbutton *b; GkrellmDecal *d; GList *list; if (!p) return; for (list = p->decal_list; list; list = list->next) { d = (GkrellmDecal *) list->data; if ((b = gkrellm_decal_is_button(d)) != NULL) remove_from_button_list(p, b); _destroy_decal(d); } if (p->decal_list) g_list_free(p->decal_list); p->decal_list = NULL; }GkrellmDecal *gkrellm_create_decal_pixmap(GkrellmPanel *p, GdkPixmap *pixmap, GdkBitmap *mask, gint depth, GkrellmStyle *style, gint x, gint y) { GtkWidget *top_win; GkrellmMargin *m; GkrellmDecal *d; if (!pixmap) return NULL; top_win = gkrellm_get_top_window(); d = (GkrellmDecal *) g_new0(GkrellmDecal, 1); if (p) { p->decal_list = g_list_append(p->decal_list, d); p->need_decal_overlap_check = TRUE; } d->panel = (gpointer) p; gdk_drawable_get_size(pixmap, &d->w, &d->h); if (depth > 0) d->h /= depth; if (d->h == 0) d->h = 1; d->x = x; m = gkrellm_get_style_margins(style); if (d->x < 0 && style) { if ( style->label_position < 50 && style->label_position != GKRELLM_LABEL_NONE ) d->x = _GK.chart_width - d->w - m->right; else d->x = m->left; } d->y = y; if (d->y < 0) d->y = m->top; d->pixmap = pixmap; d->mask = mask; d->stencil = gdk_pixmap_new(top_win->window, d->w, d->h, 1); d->value = -1; /* Force initial draw */ d->flags = 0; d->state = DS_VISIBLE; return d; }static GkrellmDecal *_create_decal_text(GkrellmPanel *p, gchar *string, GkrellmTextstyle *ts, GkrellmStyle *style, gint x, gint y, gint w, gint h, gint y_ink, gboolean markup) { GtkWidget *top_win; GkrellmMargin *m; GkrellmDecal *d; GkrellmText *tx; gint width, height, baseline; top_win = gkrellm_get_top_window(); d = (GkrellmDecal *) g_new0(GkrellmDecal, 1); if (p) { p->decal_list = g_list_append(p->decal_list, d); p->need_decal_overlap_check = TRUE; } d->panel = (gpointer) p; d->text_style = ts ? *ts : *gkrellm_meter_textstyle(0); tx = g_new0(GkrellmText, 1); d->text_list = g_list_append(d->text_list, tx); gkrellm_dup_string(&tx->text, ""); tx->text_style = d->text_style; if (string && *string) { if (markup) gkrellm_text_markup_extents(d->text_style.font, string, strlen(string), &width, &height, &baseline, &d->y_ink); else gkrellm_text_extents(d->text_style.font, string, strlen(string), &width, &height, &baseline, &d->y_ink); d->h = height + d->text_style.effect; } else { width = 2; d->h = h; d->y_ink = y_ink; } if (d->h <= 0) d->h = 2; /* Width defaults to full chart width | minus borders unless w > 0, or w == 0 to use string width. */ if (style) { m = gkrellm_get_style_margins(style); if (w < 0) d->w = _GK.chart_width - m->left - m->right; else if (w == 0) d->w = width + d->text_style.effect; else d->w = w; d->x = (x >= 0) ? x : m->left; d->y = y; if (d->y < 0) d->y = m->top; } else { if (w < 0) d->w = _GK.chart_width; else if (w == 0) d->w = width; else d->w = w; d->x = x; d->y = y; } if (d->w == 0) d->w = 1; d->pixmap = gdk_pixmap_new(top_win->window, d->w, d->h, -1);; d->mask = NULL; d->stencil = gdk_pixmap_new(top_win->window, d->w, d->h, 1); d->value = -1; /* Force initial draw */ d->flags = DF_LOCAL_PIXMAPS; d->state = DS_VISIBLE; return d; }GkrellmDecal *gkrellm_create_decal_text(GkrellmPanel *p, gchar *string, GkrellmTextstyle *ts, GkrellmStyle *style, gint x, gint y, gint w) { return _create_decal_text(p, string, ts, style, x, y, w, 0, 0, FALSE); }GkrellmDecal *gkrellm_create_decal_text_markup(GkrellmPanel *p, gchar *string, GkrellmTextstyle *ts, GkrellmStyle *style, gint x, gint y, gint w) { return _create_decal_text(p, string, ts, style, x, y, w, 0, 0, TRUE); }GkrellmDecal *gkrellm_create_decal_text_with_height(GkrellmPanel *p, GkrellmTextstyle *ts, GkrellmStyle *style, gint x, gint y, gint w, gint h, gint y_ink) { return _create_decal_text(p, NULL, ts, style, x, y, w, h, y_ink, FALSE); }voidgkrellm_make_decal_invisible(GkrellmPanel *p, GkrellmDecal *d) { if (!p || !d || d->state == DS_INVISIBLE) return; d->state = DS_INVISIBLE; d->modified = TRUE; p->need_decal_overlap_check = TRUE; gkrellm_draw_panel_layers(p); }voidgkrellm_make_decal_visible(GkrellmPanel *p, GkrellmDecal *d) { if (!p || !d || d->state == DS_VISIBLE) return; d->state = DS_VISIBLE; d->modified = TRUE; p->need_decal_overlap_check = TRUE; gkrellm_draw_panel_layers(p); }gintgkrellm_is_decal_visible(GkrellmDecal *d) { if (!d) return FALSE; return (d->state == DS_VISIBLE) ? TRUE : FALSE; }/* ===================================================================== */#define AUTO_HIDE_BUTTON 1gbooleangkrellm_in_decal(GkrellmDecal *d, GdkEventButton *ev) { if (!d || !ev) return FALSE; if ( ev->x >= d->x && ev->x < d->x + d->w && ev->y >= d->y && ev->y < d->y + d->h ) return TRUE; return FALSE; }static voidset_button_index(GkrellmDecalbutton *b, gint index, gint do_draw) { if (!b) return; gkrellm_draw_decal_pixmap(b->panel, b->decal, index); b->cur_index = index; if (do_draw) gkrellm_draw_panel_layers(b->panel); }voidgkrellm_set_button_sensitive(GkrellmDecalbutton *b, gboolean sensitive) { if (b) b->sensitive = sensitive; }voidgkrellm_hide_button(GkrellmDecalbutton *b) { if (!b) return; b->sensitive = FALSE; gkrellm_make_decal_invisible(b->panel, b->decal); }voidgkrellm_show_button(GkrellmDecalbutton *b) { if (!b) return; b->sensitive = TRUE; gkrellm_make_decal_visible(b->panel, b->decal); }gbooleangkrellm_in_button(GkrellmDecalbutton *b, GdkEventButton *ev) { return gkrellm_in_decal(b->decal, ev); }static gintcb_decal_button_press(GtkWidget *widget, GdkEventButton *ev, GkrellmPanel *p) { GList *list; GkrellmDecalbutton *b; gboolean stop_sig = FALSE; if (ev->type != GDK_BUTTON_PRESS) /* I'm connected to "event" */ return FALSE; for (list = p->button_list; list; list = list->next) { b = (GkrellmDecalbutton *) list->data; if ( b->sensitive && (*(b->cb_in_button))(b, ev, b->in_button_data) && ( (b->cb_button_click && ev->button == 1) || (b->cb_button_right_click && ev->button == 3) ) ) { if (b->cur_index != b->pressed_index) { b->saved_index = b->cur_index; set_button_index(b, b->pressed_index, 1); } stop_sig = TRUE; break; } } return stop_sig; }static gintcb_decal_button_release(GtkWidget *widget, GdkEventButton *ev, GkrellmPanel *p) { GList *list; GkrellmDecalbutton *b; gboolean stop_sig = FALSE; if (ev->type != GDK_BUTTON_RELEASE) /* I'm connected to "event" */ return FALSE; for (list = p->button_list; list; list = list->next) { b = (GkrellmDecalbutton *) list->data; if (b->cur_index == b->pressed_index) { set_button_index(b, b->saved_index, 1); if ( (*(b->cb_in_button))(b, ev, b->in_button_data) ) { if (b->cb_button_click && ev->button == 1) (*(b->cb_button_click))(b, b->data); else if (b->cb_button_right_click && ev->button == 3) (*(b->cb_button_right_click))(b, b->right_data); } stop_sig = TRUE; } } return stop_sig; }static gintcb_decal_button_leave(GtkWidget *widget, GdkEventButton *ev, GkrellmPanel *p) { GList *list; GkrellmDecalbutton *b; if (ev->type != GDK_LEAVE_NOTIFY) /* I'm connected to "event" */ return FALSE; for (list = p->button_list; list; list = list->next) { b = (GkrellmDecalbutton *) list->data; if (b->type == AUTO_HIDE_BUTTON) { if (b->sensitive) { set_button_index(b, 0, 0); b->decal->state = DS_INVISIBLE; b->decal->modified = TRUE; p->need_decal_overlap_check = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -