Compare commits

..

3 Commits

Author SHA1 Message Date
9a6aee1410 Make only Cells selectable 2018-05-22 13:00:50 +02:00
4987459337 restructured code 2018-05-22 12:59:28 +02:00
1db0ac1d17 Optimized Layout in Header Bar 2018-05-22 12:47:44 +02:00
7 changed files with 157 additions and 144 deletions

View File

@ -14,10 +14,6 @@
<property name="title" translatable="yes">GDS Renderer</property> <property name="title" translatable="yes">GDS Renderer</property>
<property name="subtitle" translatable="yes">GDSII to PDF Converter</property> <property name="subtitle" translatable="yes">GDSII to PDF Converter</property>
<property name="show_close_button">True</property> <property name="show_close_button">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child> <child>
<object class="GtkButton" id="button-load-gds"> <object class="GtkButton" id="button-load-gds">
<property name="label">gtk-open</property> <property name="label">gtk-open</property>
@ -30,11 +26,6 @@
<class name="suggested-action"/> <class name="suggested-action"/>
</style> </style>
</object> </object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child> </child>
<child> <child>
<object class="GtkButton" id="button-load-mapping"> <object class="GtkButton" id="button-load-mapping">
@ -48,9 +39,7 @@
</style> </style>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="position">1</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -65,15 +54,11 @@
</style> </style>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="position">2</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing> </packing>
</child> </child>
</object> </object>
</child> </child>
</object>
</child>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">True</property> <property name="visible">True</property>

View File

@ -62,7 +62,7 @@ static void layer_element_init(LayerElement *self)
GtkWidget *layer_element_new(void) GtkWidget *layer_element_new(void)
{ {
return GTK_WIDGET(g_object_new(layer_element_get_type(), NULL)); return GTK_WIDGET(g_object_new(TYPE_LAYER_ELEMENT, NULL));
} }
const char *layer_element_get_name(LayerElement *elem) const char *layer_element_get_name(LayerElement *elem)

View File

@ -21,11 +21,13 @@
#define __LAYER_ELEMENT_H__ #define __LAYER_ELEMENT_H__
#include <gtk/gtk.h> #include <gtk/gtk.h>
// #include <gdk/gdk.h>
#define LAYER_ELEMENT(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, layer_element_get_type(), LayerElement) G_BEGIN_DECLS
#define LAYER_ELEMENT_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, layer_element_get_type(), LayerElementClass)
#define IS_LAYER_ELEMENT(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, layer_element_get_type()) /* Creates Class structure etc */
G_DECLARE_FINAL_TYPE(LayerElement, layer_element, LAYER, ELEMENT, GtkBox)
#define TYPE_LAYER_ELEMENT (layer_element_get_type())
typedef struct _LayerElementPriv { typedef struct _LayerElementPriv {
GtkEntry *name; GtkEntry *name;
@ -42,12 +44,6 @@ typedef struct _LayerElement {
LayerElementPriv priv; LayerElementPriv priv;
} LayerElement; } LayerElement;
typedef struct _LayerElementClass {
GtkBoxClass parent_class;
} LayerElementClass;
GType layer_element_get_type(void);
GtkWidget *layer_element_new(void); GtkWidget *layer_element_new(void);
const char *layer_element_get_name(LayerElement *elem); const char *layer_element_get_name(LayerElement *elem);
@ -59,4 +55,6 @@ gboolean layer_element_get_export(LayerElement *elem);
void layer_element_get_color(LayerElement *elem, GdkRGBA *rgba); void layer_element_get_color(LayerElement *elem, GdkRGBA *rgba);
void layer_element_set_color(LayerElement *elem, GdkRGBA *rgba); void layer_element_set_color(LayerElement *elem, GdkRGBA *rgba);
G_END_DECLS
#endif /* __LAYER_ELEMENT_H__ */ #endif /* __LAYER_ELEMENT_H__ */

77
main.c
View File

@ -23,16 +23,7 @@
#include <layer-element.h> #include <layer-element.h>
#include "layer-selector.h" #include "layer-selector.h"
#include "tree-renderer/lib-cell-renderer.h" #include "tree-renderer/lib-cell-renderer.h"
#include "tree-renderer/tree-store.h"
enum cell_store_columns {
LIBRARY,
CELL,
MODDATE,
ACCESSDATE,
STORE_COLUMN_COUNT
};
struct open_button_data { struct open_button_data {
GtkWindow *main_window; GtkWindow *main_window;
@ -123,9 +114,9 @@ void on_load_gds(gpointer button, gpointer user)
acc_date = generate_string_from_date(&gds_lib->access_time); acc_date = generate_string_from_date(&gds_lib->access_time);
gtk_tree_store_set (store, &libiter, gtk_tree_store_set (store, &libiter,
LIBRARY, gds_lib, CELL_SEL_LIBRARY, gds_lib,
MODDATE, mod_date->str, CELL_SEL_MODDATE, mod_date->str,
ACCESSDATE, acc_date->str, CELL_SEL_ACCESSDATE, acc_date->str,
-1); -1);
/* Delete GStrings including string data. */ /* Delete GStrings including string data. */
@ -142,9 +133,9 @@ void on_load_gds(gpointer button, gpointer user)
acc_date = generate_string_from_date(&gds_c->access_time); acc_date = generate_string_from_date(&gds_c->access_time);
gtk_tree_store_set (store, &celliter, gtk_tree_store_set (store, &celliter,
CELL, gds_c, CELL_SEL_CELL, gds_c,
MODDATE, mod_date->str, CELL_SEL_MODDATE, mod_date->str,
ACCESSDATE, acc_date->str, CELL_SEL_ACCESSDATE, acc_date->str,
-1); -1);
/* Delete GStrings including string data. */ /* Delete GStrings including string data. */
@ -163,63 +154,11 @@ end_destroy:
gtk_widget_destroy(open_dialog); gtk_widget_destroy(open_dialog);
} }
void on_convert_clicked(gpointer button, gpointer user) static void on_convert_clicked(gpointer button, gpointer user)
{ {
printf("convert\n"); printf("convert\n");
} }
static GtkTreeStore * setup_cell_selector(GtkTreeView* view)
{
GtkTreeStore *cell_store;
GtkCellRenderer *render_dates;
GtkCellRenderer *render_cell;
GtkCellRenderer *render_lib;
GtkTreeViewColumn *column;
GdkRGBA cell_text_color;
GValue val = G_VALUE_INIT;
cell_store = gtk_tree_store_new(STORE_COLUMN_COUNT, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING);
gtk_tree_view_set_model(view, GTK_TREE_MODEL(cell_store));
render_dates = gtk_cell_renderer_text_new();
render_cell = lib_cell_renderer_new();
render_lib = lib_cell_renderer_new();
/* Set foreground color for cell column */
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;
g_value_init(&val, G_TYPE_BOOLEAN);
g_value_set_boolean(&val, TRUE);
g_object_set_property(G_OBJECT(render_cell), "foreground-set", &val);
g_value_unset(&val);
g_value_init(&val, GDK_TYPE_RGBA);
g_value_set_boxed(&val, &cell_text_color);
g_object_set_property(G_OBJECT(render_cell), "foreground-rgba", &val);
g_value_unset(&val);
column = gtk_tree_view_column_new_with_attributes("Library", render_lib, "gds-lib", 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, NULL);
gtk_tree_view_append_column(view, column);
column = gtk_tree_view_column_new_with_attributes("Mod. Date", render_dates, "text", MODDATE, NULL);
gtk_tree_view_append_column(view, column);
column = gtk_tree_view_column_new_with_attributes("Acc. Date", render_dates, "text", ACCESSDATE, NULL);
gtk_tree_view_append_column(view, column);
return cell_store;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {

View File

@ -20,12 +20,11 @@
#ifndef __LIB_CELL_RENDERER_H__ #ifndef __LIB_CELL_RENDERER_H__
#define __LIB_CELL_RENDERER_H__ #define __LIB_CELL_RENDERER_H__
#include <gtk/gtk.h> #include <gtk/gtk.h>
#define LIB_CELL_RENDERER(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, lib_cell_renderer_get_type(), LibCellRenderer) G_BEGIN_DECLS
#define LIB_CELL_RENDERER_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, lib_cell_renderer_get_type(), LibCellRendererClass)
#define IS_LIB_CELL_RENDERER(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, layer_element_get_type()) G_DECLARE_FINAL_TYPE(LibCellRenderer, lib_cell_renderer, LIB_CELL, RENDERER, GtkCellRendererText)
#define TYPE_LIB_CELL_RENDERER (lib_cell_renderer_get_type()) #define TYPE_LIB_CELL_RENDERER (lib_cell_renderer_get_type())
typedef struct _LibCellRenderer { typedef struct _LibCellRenderer {
@ -34,14 +33,9 @@ typedef struct _LibCellRenderer {
/* Custom Elements */ /* Custom Elements */
} LibCellRenderer; } LibCellRenderer;
typedef struct _LibCellRendererClass {
GtkCellRendererTextClass parent;
} LibCellRendererClass;
GType lib_cell_renderer_get_type(void); GType lib_cell_renderer_get_type(void);
GtkCellRenderer *lib_cell_renderer_new(void); GtkCellRenderer *lib_cell_renderer_new(void);
G_END_DECLS
#endif /* __LIB_CELL_RENDERER_H__ */ #endif /* __LIB_CELL_RENDERER_H__ */

View File

@ -0,0 +1,81 @@
#include "tree-store.h"
#include "lib-cell-renderer.h"
#include "../gds-types.h"
static gboolean tree_sel_func(GtkTreeSelection *selection,
GtkTreeModel *model,
GtkTreePath *path,
gboolean path_currently_selected,
gpointer data)
{
static int cnt = 0;
GtkTreeIter iter;
struct gds_cell *cell;
gchar *p;
gtk_tree_model_get_iter(model, &iter, path);
gtk_tree_model_get(model, &iter, CELL_SEL_CELL, &cell, -1);
/* Allow only rows with valid cell to be selected */
if (cell)
return TRUE;
else
return FALSE;
}
GtkTreeStore *setup_cell_selector(GtkTreeView* view)
{
GtkTreeStore *cell_store;
GtkCellRenderer *render_dates;
GtkCellRenderer *render_cell;
GtkCellRenderer *render_lib;
GtkTreeViewColumn *column;
GdkRGBA cell_text_color;
GValue val = G_VALUE_INIT;
cell_store = gtk_tree_store_new(CELL_SEL_COLUMN_COUNT, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING);
gtk_tree_view_set_model(view, GTK_TREE_MODEL(cell_store));
render_dates = gtk_cell_renderer_text_new();
render_cell = lib_cell_renderer_new();
render_lib = lib_cell_renderer_new();
/* Set foreground color for cell column */
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;
g_value_init(&val, G_TYPE_BOOLEAN);
g_value_set_boolean(&val, TRUE);
g_object_set_property(G_OBJECT(render_cell), "foreground-set", &val);
g_value_unset(&val);
g_value_init(&val, GDK_TYPE_RGBA);
g_value_set_boxed(&val, &cell_text_color);
g_object_set_property(G_OBJECT(render_cell), "foreground-rgba", &val);
g_value_unset(&val);
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, 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);
gtk_tree_view_append_column(view, column);
column = gtk_tree_view_column_new_with_attributes("Acc. Date", render_dates, "text", CELL_SEL_ACCESSDATE, NULL);
gtk_tree_view_append_column(view, column);
/* Callback for selection
* This prevents selecting a library */
gtk_tree_selection_set_select_function(gtk_tree_view_get_selection(view), tree_sel_func, NULL, NULL);
return cell_store;
}

View File

@ -0,0 +1,16 @@
#ifndef __TREE_STORE_H__
#define __TREE_STORE_H__
#include <gtk/gtk.h>
enum cell_store_columns {
CELL_SEL_LIBRARY = 0,
CELL_SEL_CELL,
CELL_SEL_MODDATE,
CELL_SEL_ACCESSDATE,
CELL_SEL_COLUMN_COUNT
};
GtkTreeStore *setup_cell_selector(GtkTreeView* view);
#endif /* __TREE_STORE_H__ */