⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chart.c

📁 系统任务管理器
💻 C
📖 第 1 页 / 共 5 页
字号:
			else if (c == 'c')				center = 1;			else if (c == 'C')				center = 2;			else if (c == 'N')				{				x = xx;		/* A conditional newline.  If previous string */				if (h > 2)	/* was spaces, no nl.  A space has nonzero a  */					y += cp->h_text + 1;				}			else if (c == 'b')				{				y = cp->h - cp->h_text - cp->y_ink - 1;				x = xx;				}			else if (c == 't')				{				y = 2 - cp->y_ink;				x = xx;				}			else if (c == 'r')				right = TRUE;			else if (c == 'p')				{				y -= cp->h_text + 1;				x = xx;				}			else if (c == 'w')				set_fw = TRUE;			else if (c == 'a')				field_width = fw;			else if (c == 'e')				{				field_width = fw;				fw_right = TRUE;				}			else if (c == 'f')				{				ts = ts_alt;				shadow = ts_alt->effect ? 1 : 0;				}			else if (c == 'x' && isdigit(*s))				xx = *s++ - '0';			else if (c == 'y' && isdigit(*s))				y = *s++ - '0';			else if (c == 'D')				{				y = chartdata_text_y(cp, *s++, cp->h_text, cp->y_ink, shadow);				x = xx;				}			}		t = strchr(s, (gint) '\\');		if (t)			text_length = t - s;		else			text_length = strlen(s);		if (y == -100)	/* asked for a chartdata that is hidden */			continue;		if (   !tr->cache_valid || !tr->text			|| strncmp(tr->text, s, text_length)			|| strlen(tr->text) != text_length		   )			{			gkrellm_text_extents(ts->font, s, text_length,						&tr->w, &tr->h, &tr->baseline, &tr->y_ink);			tr->cache_valid = FALSE;			g_free(tr->text);			tr->text = g_strndup(s, text_length);			}		h = tr->h;		if (set_fw)			{			fw = tr->w + shadow;			continue;			}		if (center == 1)			x = (cp->w - tr->w) / 2;		else if (center == 2)			x = cp->w / 2;		else if (fw_right)			x = x + fw - tr->w - shadow;		else if (right)			x = cp->w - tr->w - 2 - shadow;		if (text_length > 1 || (text_length == 1 && *s != ' '))			{			if (x != tr->x || y != tr->y)				tr->cache_valid = FALSE;			tr->x = x;			tr->y = y;			if (_GK.debug_level & DEBUG_CHART_TEXT)				{				gchar	buf[128];				strncpy(buf, s, text_length);				buf[text_length] = '\0';				printf("draw_chart_text: [%s] ", buf);				}						offset = cp->baseline_ref - tr->baseline;	/* align baselines */			if (_GK.chart_text_no_fill)	    		gkrellm_draw_text(cp->pixmap, ts, x, y + offset, s,						text_length);			else /* Default text draw effect is fill solid and can use cache */				{				if (!tr->cache_valid)					{					if (_GK.debug_level & DEBUG_CHART_TEXT)						printf("pango ");					gdk_draw_drawable(cp->bg_text_pixmap, _GK.draw1_GC,							cp->bg_pixmap,							x - 1, y + tr->y_ink + offset - 1,							x - 1, y + tr->y_ink + offset - 1,							tr->w + shadow + 2, tr->h + shadow + 1);		    		gkrellm_draw_text(cp->bg_text_pixmap, ts, x, y + offset, s,							text_length);					}				if (_GK.debug_level & DEBUG_CHART_TEXT)					printf("x=%d y=%d w=%d h=%d\n",							x - 1, y + tr->y_ink + offset - 1,							tr->w + shadow + 2, tr->h + shadow + 1);				gdk_draw_drawable(cp->pixmap, _GK.draw1_GC, cp->bg_text_pixmap,						x - 1, y + tr->y_ink + offset - 1,						x - 1, y + tr->y_ink + offset - 1,						tr->w + shadow + 2, tr->h + shadow + 1);				}			}		if (field_width && !fw_right)			x += (field_width > tr->w) ? field_width : tr->w;		else			x += tr->w + shadow;		}	}gintgkrellm_draw_chart_label(GkrellmChart *cp, GkrellmTextstyle *ts,				gint x, gint y, gchar *s)	{	gint	w, h, y_ink;	if (!cp || !ts || !s)		return x;	gkrellm_text_extents(ts->font, s, strlen(s), &w, &h, NULL, &y_ink);	gdk_draw_drawable(cp->pixmap, _GK.draw1_GC, cp->bg_pixmap,				x, y, x, y, w + ts->effect, h + ts->effect);    gkrellm_draw_string(cp->pixmap, ts, x, y - y_ink, s);	return x + w + ts->effect;	}voidgkrellm_destroy_chartdata_list(GList **cd_list_head)	{	GList			*list;	GkrellmChartdata *cd;	if (!cd_list_head)		return;	for (list = *cd_list_head; list; list = list->next)		{		cd = (GkrellmChartdata *) list->data;		if (cd->label)			g_free(cd->label);		if (cd->data)			g_free(cd->data);		if (cd->data_bitmap)			g_object_unref(G_OBJECT(cd->data_bitmap));		if (cd->layer.pixmap)			g_object_unref(G_OBJECT(cd->layer.pixmap));		/* cd->layer.src_pixmap & cd->layer.grid_pixmap must be handled by		|  creating monitor.		*/		}	gkrellm_free_glist_and_data(cd_list_head);	}static voidfree_chart_pixmaps(GkrellmChart *cp)	{	GList			*list;	GkrellmChartdata *cd;	for (list = cp->cd_list; list; list = list->next)		{		cd = (GkrellmChartdata *) list->data;		gkrellm_free_bitmap(&cd->data_bitmap);		gkrellm_free_pixmap(&cd->layer.pixmap);		/* cd->layer.src_pixmap & cd->layer.grid_pixmap must be handled by		|  creating monitor.		*/		}	/* If new theme or size, the cd_list will not be destroyed so I can	|  reuse the data arrays.   Pixmaps will be recreated.	*/	cp->cd_list_index = 0;	gkrellm_free_pixmap(&cp->bg_pixmap);	gkrellm_free_pixmap(&cp->bg_text_pixmap);	gkrellm_free_pixmap(&cp->bg_src_pixmap);	gkrellm_free_pixmap(&cp->bg_grid_pixmap);	gkrellm_free_pixmap(&cp->bg_clean_pixmap);	gkrellm_free_bitmap(&cp->bg_mask);	gkrellm_free_pixmap(&cp->pixmap);	gkrellm_free_pixmap(&cp->top_spacer.clean_pixmap);	gkrellm_free_pixmap(&cp->top_spacer.pixmap);	gkrellm_free_bitmap(&cp->top_spacer.mask);	gkrellm_free_pixmap(&cp->bottom_spacer.clean_pixmap);	gkrellm_free_pixmap(&cp->bottom_spacer.pixmap);	gkrellm_free_bitmap(&cp->bottom_spacer.mask);	}static voiddestroy_chart_data(GkrellmChart *cp)	{	GList			*list;	GkrellmChartdata *cd;	free_chart_pixmaps(cp);	chart_destroy_text_run_list(cp);	for (list = cp->cd_list; list; list = list->next)		{		cd = (GkrellmChartdata *) list->data;		if (cd->label)			g_free(cd->label);		if (cd->data)			g_free(cd->data);		cd->label = NULL;		cd->data = NULL;		}	/* Don't free the cd_list.  It is in the GkrellmChartconfig struct.	*/	}  /* Destroy everything inside a chart except leave cp->config alone since  |  the config is managed by each monitor.  */voidgkrellm_chart_destroy(GkrellmChart *cp)	{	gint	h_spacers = 0;	if (!cp)		return;	if (cp->top_spacer.image)		h_spacers = cp->top_spacer.height;	if (cp->bottom_spacer.image)		h_spacers += cp->bottom_spacer.height;	gkrellm_freeze_side_frame_packing();	if (cp->panel)		gkrellm_panel_destroy(cp->panel);	destroy_chart_data(cp);	gtk_widget_destroy(cp->box);	chart_list = g_list_remove(chart_list, cp);	gkrellm_chartconfig_window_destroy(cp);	if (cp->shown)		gkrellm_monitor_height_adjust(-(cp->h + h_spacers));	g_free(cp);	gkrellm_thaw_side_frame_packing();	}voidgkrellm_chartconfig_destroy(GkrellmChartconfig **cf)	{	if (!cf || !*cf)		return;	gkrellm_destroy_chartdata_list((*cf)->chart_cd_list);	g_free(*cf);	*cf = NULL;	}voidgkrellm_chart_bg_piximage_override(GkrellmChart *cp,			GkrellmPiximage *bg_piximage, GkrellmPiximage *bg_grid_piximage)	{	if (!cp || !bg_piximage || !bg_grid_piximage)		return;	cp->bg_piximage = bg_piximage;	cp->bg_grid_piximage = bg_grid_piximage;	cp->bg_piximage_override = TRUE;	}static voidset_chartdata_split_heights(GkrellmChart *cp)	{	GList			*list, *list1;	GkrellmChartdata *cd, *cd1;	gint			splits;	gint			i, y0, h_avail, h_free, y_offset;	for (i = 0, splits = 0, list = cp->cd_list; list; list = list->next)		{		cd = (GkrellmChartdata *) list->data;		if (cd->hide)			continue;		if (++i > 1 && cd->split_chart)	/* Can't split before the first one */			++splits;		cd->split_share = 1.0;		for (list1 = list->next; list1; list1 = list1->next)			{			cd1 = (GkrellmChartdata *) list1->data;			if (!cd1->split_chart || cd1->hide)				continue;			cd->split_share = cd1->split_fraction;			break;			}		}	y_offset = GRID_HEIGHT_Y_OFFSET_ADJUST(cp);	y0 = cp->y + y_offset;	h_avail = cp->h - cp->y - ((splits + 1) * y_offset)				- splits * _GK.bg_separator_height;	h_free = h_avail;	for (list = cp->cd_list; list; list = list->next)		{		cd = (GkrellmChartdata *) list->data;		if (cd->hide)			continue;		cd->y = y0;		for (list1 = list->next; list1; list1 = list1->next)			if (!((GkrellmChartdata *) list1->data)->hide)				break;		if (!list1)			cd->h = h_free;		else			cd->h = (gint) (cd->split_share * (gfloat) h_free);		if (cd->h < 1)			cd->h = 1;		if (list1 && ((GkrellmChartdata *) list1->data)->split_chart)			{			y0 += cd->h + _GK.bg_separator_height + y_offset;			h_free -= cd->h;			}		}	}GkrellmChartdata *gkrellm_add_default_chartdata(GkrellmChart *cp, gchar *label)	{	GdkPixmap	**src_pixmap, *grid_pixmap;	if (!cp)		return NULL;	if (cp->cd_list_index & 1)		{		src_pixmap = &_GK.data_in_pixmap;		grid_pixmap = _GK.data_in_grid_pixmap;		}	else		{		src_pixmap = &_GK.data_out_pixmap;		grid_pixmap = _GK.data_out_grid_pixmap;		}	return gkrellm_add_chartdata(cp, src_pixmap, grid_pixmap, label);	}  /* Need a GdkPixmap ** because the src pixmap can change (re-rendered at  |  size or theme changes).  */GkrellmChartdata *gkrellm_add_chartdata(GkrellmChart *cp, GdkPixmap **src_pixmap,			GdkPixmap *grid_pixmap, gchar *label)	{	GtkWidget		*top_win	= gkrellm_get_top_window();	GList			*list;	GkrellmChartdata *cd;	if (!cp || !src_pixmap || !grid_pixmap || !label)		return NULL;	/* To handle theme and vert size changes without loosing data, reuse the	|  GkrellmChartdata structs in the cd_list.	*/	list = g_list_nth(cp->cd_list, cp->cd_list_index++);	if (!list)		{		cd = g_new0(GkrellmChartdata, 1);		cp->cd_list = g_list_append(cp->cd_list, cd);		cp->config->cd_list = cp->cd_list;		cd->split_fraction = 0.5;		}	else		cd = (GkrellmChartdata *) list->data;	cd->chart = cp;	gkrellm_dup_string(&cd->label, label);	cd->monotonic = TRUE;	cd->data_bitmap = gdk_pixmap_new(top_win->window, cp->w, cp->h, 1);	cd->layer.pixmap = gdk_pixmap_new(top_win->window, cp->w, cp->h, -1);	cd->layer.src_pixmap = src_pixmap;	cd->layer.grid_pixmap = grid_pixmap;	set_chartdata_split_heights(cp);	return cd;	}voidgkrellm_render_data_grid_pixmap(GkrellmPiximage *im, GdkPixmap **pixmap,			GdkColor *color)	{	GtkWidget   *top_win = gkrellm_get_top_window();	gint		w, w_pixmap = 0, h = 0;	w = gkrellm_chart_width();	if (*pixmap)		gdk_drawable_get_size(*pixmap, &w_pixmap, NULL);	if (!*pixmap || w != w_pixmap)		{		if (im)			{			if ((h = gdk_pixbuf_get_height(im->pixbuf)) > 2)				h = 2;			gkrellm_scale_piximage_to_pixmap(im, pixmap, NULL, w, h);			}		else			{			gkrellm_free_pixmap(pixmap);			*pixmap = gdk_pixmap_new(top_win->window, w, 1, -1);			if (color)				gdk_gc_set_foreground(_GK.draw1_GC, color);			else				gdk_gc_set_foreground(_GK.draw1_GC, &_GK.in_color_grid);			gdk_draw_rectangle(*pixmap, _GK.draw1_GC, TRUE, 0, 0, w, 1);			}		}	}voidgkrellm_render_data_pixmap(GkrellmPiximage *im, GdkPixmap **pixmap,			GdkColor *color, gint h)	{	GtkWidget   *top_win = gkrellm_get_top_window();	gint		w, w_pixmap = 0, h_pixmap = 0;	w = gkrellm_chart_width();	if (*pixmap)		gdk_drawable_get_size(*pixmap, &w_pixmap, &h_pixmap);	if (!*pixmap || w != w_pixmap || h != h_pixmap)		{		if (!gkrellm_scale_piximage_to_pixmap(im, pixmap, NULL, w, h))			{			*pixmap = gdk_pixmap_new(top_win->window, w, h, -1);			if (color)				gdk_gc_set_foreground(_GK.draw1_GC, color);			else				gdk_gc_set_foreground(_GK.draw1_GC, &_GK.in_color_grid);			gdk_draw_rectangle(*pixmap, _GK.draw1_GC, TRUE, 0,0,w,h);			}		}	}static voidrender_default_data_pixmaps(GkrellmChart *cp)	{	GList		*list;	GdkPixmap	*pixmap;	gint		w, h, w_pixmap = 0;	gkrellm_render_data_grid_pixmap(_GK.data_in_grid_piximage,				&_GK.data_in_grid_pixmap, &_GK.in_color_grid);	gkrellm_render_data_grid_pixmap(_GK.data_out_grid_piximage,				&_GK.data_out_grid_pixmap, &_GK.out_color_grid);	w = gkrellm_chart_width();	pixmap = _GK.bg_separator_pixmap;	if (pixmap)		gdk_drawable_get_size(pixmap, &w_pixmap, NULL);	if (!pixmap || w_pixmap != w)		{		if ((h = _GK.bg_separator_height) < 1 || h > 5)			h = 2;		if (_GK.bg_separator_piximage)			gkrellm_scale_piximage_to_pixmap(_GK.bg_separator_piximage,						&_GK.bg_separator_pixmap, NULL, w, h);		else			{			GkrellmPiximage	*im;			im = gkrellm_bg_panel_piximage(DEFAULT_STYLE_ID);			gkrellm_scale_pixbuf_to_pixmap(im->pixbuf, &_GK.bg_separator_pixmap,					NULL, w, h);			}		}	h = 2;	for (list = chart_list; list; list = list->next)		{		cp = (GkrellmChart *) list->data;		if (cp->h > h)			h = cp->h;		}	gkrellm_render_data_pixmap(_GK.data_in_piximage,				&_GK.data_in_pixmap, &_GK.in_color, h);	gkrellm_render_data_pixmap(_GK.data_out_piximage,				&_GK.data_out_pixmap, &_GK.out_color, h);	}voidgkrellm_chart_setup(void)	{	gkrellm_free_pixmap(&_GK.data_in_pixmap);	gkrellm_free_pixmap(&_GK.data_in_grid_pixmap);	gkrellm_free_pixmap(&_GK.data_out_pixmap);	gkrellm_free_pixmap(&_GK.data_out_grid_pixmap);	gkrellm_free_pixmap(&_GK.bg_separator_pixmap);	}#if 0static gintcompare_chartlist(gconstpointer a, gconstpointer b)    {	GkrellmChart	*cp_a	= (GkrellmChart *) a;	GkrellmChart	*cp_b	= (GkrellmChart *) b;	gint	result;	if (cp_a->style_id < cp_b->style_id)		result = -1;	else (if cp_a->style_id > cp_b->style_id)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -