From f1415df22f9a7ea8f207049e1f9d48b44014d557 Mon Sep 17 00:00:00 2001 From: "Leandro A. F. Pereira" Date: Sat, 30 Dec 2006 15:08:41 +0000 Subject: Image is now saved with the right size. Enable the save image as menu item only when needed. --- hardinfo2/benchmark.c | 18 +++++++++++++++ hardinfo2/callbacks.c | 61 ++++++++++++++++++++++++++++++++++++++++++--------- hardinfo2/shell.c | 1 + hardinfo2/shell.h | 1 + hardinfo2/util.c | 2 ++ 5 files changed, 73 insertions(+), 10 deletions(-) (limited to 'hardinfo2') diff --git a/hardinfo2/benchmark.c b/hardinfo2/benchmark.c index ed62ba19..bcf5c84e 100644 --- a/hardinfo2/benchmark.c +++ b/hardinfo2/benchmark.c @@ -145,6 +145,24 @@ hi_info(gint entry) } } +const gchar * +hi_note_func(gint entry) +{ + switch (entry) { + case BENCHMARK_ZLIB: + case BENCHMARK_MD5: + case BENCHMARK_SHA1: + return "Results in bytes/second. Higher is better."; + + case BENCHMARK_RAYTRACE: + case BENCHMARK_BLOWFISH: + case BENCHMARK_FIB: + return "Results in seconds. Lower is better."; + } + + return ""; +} + void hi_reload(gint entry) { diff --git a/hardinfo2/callbacks.c b/hardinfo2/callbacks.c index 526ac1fb..7982efe2 100644 --- a/hardinfo2/callbacks.c +++ b/hardinfo2/callbacks.c @@ -28,10 +28,31 @@ #include +static gint get_tree_view_visible_height(GtkTreeView *tv) +{ + GtkTreePath *path; + GdkRectangle rect; + GtkTreeIter iter; + GtkTreeModel *model = gtk_tree_view_get_model(tv); + gint nrows = 1; + + path = gtk_tree_path_new_first(); + gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), + path, NULL, &rect); + + gtk_tree_model_get_iter_first(model, &iter); + do { + nrows++; + } while (gtk_tree_model_iter_next(model, &iter)); + + gtk_tree_path_free(path); + + return nrows * rect.height; +} + void cb_save_graphic() { - /* this is ridiculously complicated :/ why in the hell gtk+ makes this kind of thing so difficult? - FIXME: it still don't save the image with the right size; we should do this sometime soon (tm) */ + /* this is ridiculously complicated :/ why in the hell gtk+ makes this kind of thing so difficult? */ Shell *shell = shell_get_main_shell(); GtkWidget *widget = shell->info->view; GtkWidget *dialog; @@ -46,29 +67,49 @@ void cb_save_graphic() GdkColor black = { 0, 0, 0, 0 }; GdkColor white = { 0, 65535, 65535, 65535 }; - gint w, h; - gchar *filename = NULL; + gint w, h, visible_height; + gchar *filename = NULL, *tmp; /* */ shell_status_update("Creating image..."); + + /* unselect things in the information treeview */ + gtk_range_set_value(GTK_RANGE + (GTK_SCROLLED_WINDOW(shell->info->scroll)-> + vscrollbar), 0.0); + gtk_tree_selection_unselect_all( + gtk_tree_view_get_selection(GTK_TREE_VIEW(widget))); + while (gtk_events_pending()) + gtk_main_iteration(); /* initialize stuff */ gc = gdk_gc_new(widget->window); + gdk_gc_set_background(gc, &black); + gdk_gc_set_foreground(gc, &white); + context = gtk_widget_get_pango_context (widget); layout = pango_layout_new(context); - + + visible_height = get_tree_view_visible_height(GTK_TREE_VIEW(widget)); + /* draw the title */ - pango_layout_set_markup(layout, shell->selected->name, -1); + tmp = g_strdup_printf("%s\n%s", + shell->selected->name, + shell->selected->notefunc(shell->selected->number)); + pango_layout_set_markup(layout, tmp, -1); pango_layout_set_width(layout, widget->allocation.width * PANGO_SCALE); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); + g_free(tmp); pango_layout_get_pixel_extents(layout, NULL, &rect); w = widget->allocation.width; - h = widget->allocation.height + rect.height; + h = visible_height + rect.height; - pm = gdk_pixmap_new(widget->window, w, h, -1); - gdk_draw_layout_with_colors (GDK_DRAWABLE(pm), gc, 0, 0, layout, &white, &black); + pm = gdk_pixmap_new(widget->window, w, rect.height, -1); + gdk_draw_rectangle(GDK_DRAWABLE(pm), gc, TRUE, 0, 0, w, rect.height); + gdk_draw_layout_with_colors (GDK_DRAWABLE(pm), gc, 0, 0, layout, + &white, &black); /* copy the pixmap from the treeview and from the title */ pb = gdk_pixbuf_get_from_drawable(NULL, @@ -81,7 +122,7 @@ void cb_save_graphic() pm, NULL, 0, 0, - 0, widget->allocation.height, + 0, visible_height, widget->allocation.width, rect.height); /* save the pixbuf to a png file */ diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index f9c12a5e..6d971f95 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -246,6 +246,7 @@ void shell_view_set_enabled(gboolean setting) shell_action_set_enabled("RefreshAction", setting); shell_action_set_enabled("CopyAction", setting); shell_action_set_enabled("ReportAction", setting); + shell_action_set_enabled("SaveGraphAction", setting ? shell->view_type == SHELL_VIEW_PROGRESS : FALSE); } void shell_status_set_enabled(gboolean setting) diff --git a/hardinfo2/shell.h b/hardinfo2/shell.h index c343f557..f9ac39e5 100644 --- a/hardinfo2/shell.h +++ b/hardinfo2/shell.h @@ -121,6 +121,7 @@ struct _ShellModuleEntry { gchar *(*reloadfunc) (gint entry); gchar *(*fieldfunc) (gchar * entry); gchar *(*morefunc) (gchar * entry); + gchar *(*notefunc) (gint entry); }; struct _ShellFieldUpdate { diff --git a/hardinfo2/util.c b/hardinfo2/util.c index ce34a010..ccfc413f 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/util.c @@ -427,6 +427,8 @@ static ShellModule *module_load(gchar *filename) { (gpointer) & (entry->morefunc)); g_module_symbol(module->dll, "hi_get_field", (gpointer) & (entry->fieldfunc)); + g_module_symbol(module->dll, "hi_note_func", + (gpointer) & (entry->notefunc)); entry->number = i; -- cgit v1.2.3