From e9b67fe1bccccb653365ccf75cc5f88f78da7b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 5 Mar 2019 20:50:54 +0100 Subject: [PATCH] Implement error level indicator for cells --- main-window.c | 8 +------ tree-renderer/lib-cell-renderer.c | 39 +++++++++++++++++++++++++++++-- tree-renderer/lib-cell-renderer.h | 3 +++ tree-renderer/tree-store.c | 6 ++--- tree-renderer/tree-store.h | 2 +- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/main-window.c b/main-window.c index 600bf0a..e25ebdb 100644 --- a/main-window.c +++ b/main-window.c @@ -114,7 +114,6 @@ static void on_load_gds(gpointer button, gpointer user) char *filename; GString *mod_date; GString *acc_date; - GdkRGBA cell_text_color; open_dialog = gtk_file_chooser_dialog_new("Open GDSII File", ptr->main_window, GTK_FILE_CHOOSER_ACTION_OPEN, "Cancel", GTK_RESPONSE_CANCEL, "Open GDSII", GTK_RESPONSE_ACCEPT, NULL); @@ -175,11 +174,6 @@ static void on_load_gds(gpointer button, gpointer user) mod_date = generate_string_from_date(&gds_c->mod_time); acc_date = generate_string_from_date(&gds_c->access_time); - cell_text_color.alpha = 1; - cell_text_color.red = (double)61.0/(double)255.0; - cell_text_color.green = (double)152.0/(double)255.0; - cell_text_color.blue = 0.0; - /* Add cell to tree store model * CELL_SEL_CELL_COLOR will always be green, * because no cell cehcker is implemented, yet. @@ -188,7 +182,7 @@ static void on_load_gds(gpointer button, gpointer user) CELL_SEL_CELL, gds_c, CELL_SEL_MODDATE, mod_date->str, CELL_SEL_ACCESSDATE, acc_date->str, - CELL_SEL_CELL_COLOR, &cell_text_color, // TODO: implement cell checker + CELL_SEL_CELL_ERROR_STATE, 0, // TODO: implement cell checker -1); /* Delete GStrings including string data. */ diff --git a/tree-renderer/lib-cell-renderer.c b/tree-renderer/lib-cell-renderer.c index 192210b..c5fe6c9 100644 --- a/tree-renderer/lib-cell-renderer.c +++ b/tree-renderer/lib-cell-renderer.c @@ -25,6 +25,7 @@ G_DEFINE_TYPE(LibCellRenderer, lib_cell_renderer, GTK_TYPE_CELL_RENDERER_TEXT) enum { PROP_LIB = 1, PROP_CELL, + PROP_ERROR_LEVEL, PROP_COUNT }; @@ -38,24 +39,56 @@ static void lib_cell_renderer_constructed(GObject *obj) G_OBJECT_CLASS(lib_cell_renderer_parent_class)->constructed(obj); } +static void convert_error_level_to_color(GdkRGBA *color, unsigned int error_level) +{ + + /* Always use no transparency */ + color->alpha = 1.0; + + if (error_level & LIB_CELL_RENDERER_ERROR_ERR) { + /* Error set. Color cell red */ + color->red = 1.0; + color->blue = 0.0; + color->green = 0.0; + } else if (error_level & LIB_CELL_RENDERER_ERROR_WARN) { + /* Only warning set; orange color */ + color->red = 0.6; + color->blue = 0.0; + color->green = 0.4; + } else { + /* Everything okay; green color */ + color->red = (double)61.0/(double)255.0; + color->green = (double)152.0/(double)255.0; + color->blue = 0.0; + } +} + static void lib_cell_renderer_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *pspec) { GValue val = G_VALUE_INIT; - - g_value_init(&val, G_TYPE_STRING); + GdkRGBA color; switch (param_id) { case PROP_LIB: + g_value_init(&val, G_TYPE_STRING); g_value_set_string(&val, ((struct gds_library *)g_value_get_pointer(value))->name); g_object_set_property(object, "text", &val); break; case PROP_CELL: + g_value_init(&val, G_TYPE_STRING); g_value_set_string(&val, ((struct gds_cell *)g_value_get_pointer(value))->name); g_object_set_property(object, "text", &val); break; + case PROP_ERROR_LEVEL: + /* Set cell color according to error level */ + g_value_init(&val, GDK_TYPE_RGBA); + convert_error_level_to_color(&color, g_value_get_uint(value)); + g_value_set_boxed(&val, &color); + g_object_set_property(object, "foreground-rgba", &val); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); break; @@ -89,6 +122,8 @@ void lib_cell_renderer_class_init(LibCellRendererClass *klass) properties[PROP_CELL] = g_param_spec_pointer("gds-cell", "gds-cell", "Cell reference to be displayed", G_PARAM_WRITABLE); + properties[PROP_ERROR_LEVEL] = g_param_spec_uint("error-level", "error-level", + "Error level of this cell", 0, 255, 0, G_PARAM_WRITABLE); g_object_class_install_properties(oclass, PROP_COUNT, properties); } diff --git a/tree-renderer/lib-cell-renderer.h b/tree-renderer/lib-cell-renderer.h index 4e0949f..b71888a 100644 --- a/tree-renderer/lib-cell-renderer.h +++ b/tree-renderer/lib-cell-renderer.h @@ -27,6 +27,9 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE(LibCellRenderer, lib_cell_renderer, LIB_CELL, RENDERER, GtkCellRendererText) #define TYPE_LIB_CELL_RENDERER (lib_cell_renderer_get_type()) +#define LIB_CELL_RENDERER_ERROR_WARN (1U<<0) +#define LIB_CELL_RENDERER_ERROR_ERR (1U<<1) + typedef struct _LibCellRenderer { /* Inheritance */ GtkCellRendererText super; diff --git a/tree-renderer/tree-store.c b/tree-renderer/tree-store.c index 2ba5c11..28b3ec7 100644 --- a/tree-renderer/tree-store.c +++ b/tree-renderer/tree-store.c @@ -127,7 +127,7 @@ struct tree_stores *setup_cell_selector(GtkTreeView* view, GtkEntry *search_entr stores.base_tree_view = view; stores.search_entry = search_entry; - stores.base_store = gtk_tree_store_new(CELL_SEL_COLUMN_COUNT, G_TYPE_POINTER, G_TYPE_POINTER, GDK_TYPE_RGBA, G_TYPE_STRING, G_TYPE_STRING); + stores.base_store = gtk_tree_store_new(CELL_SEL_COLUMN_COUNT, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING); /* Searching */ if (search_entry) { @@ -147,8 +147,8 @@ struct tree_stores *setup_cell_selector(GtkTreeView* view, GtkEntry *search_entr column = gtk_tree_view_column_new_with_attributes("Library", render_lib, "gds-lib", CELL_SEL_LIBRARY, NULL); gtk_tree_view_append_column(view, column); - /* Cell color: #3D9801 */ - column = gtk_tree_view_column_new_with_attributes("Cell", render_cell, "gds-cell", CELL_SEL_CELL, "foreground-rgba", CELL_SEL_CELL_COLOR, NULL); + column = gtk_tree_view_column_new_with_attributes("Cell", render_cell, "gds-cell", CELL_SEL_CELL, + "error-level", CELL_SEL_CELL_ERROR_STATE, NULL); gtk_tree_view_append_column(view, column); column = gtk_tree_view_column_new_with_attributes("Mod. Date", render_dates, "text", CELL_SEL_MODDATE, NULL); diff --git a/tree-renderer/tree-store.h b/tree-renderer/tree-store.h index aa6d283..e9b60da 100644 --- a/tree-renderer/tree-store.h +++ b/tree-renderer/tree-store.h @@ -37,7 +37,7 @@ enum cell_store_columns { CELL_SEL_LIBRARY = 0, CELL_SEL_CELL, - CELL_SEL_CELL_COLOR, /**< Cell column color */ + CELL_SEL_CELL_ERROR_STATE, /**< Used for cell color and selectability */ CELL_SEL_MODDATE, CELL_SEL_ACCESSDATE, CELL_SEL_COLUMN_COUNT /**< Not a column. Used to determine count of coumns **/