GDS-Render v1.2.1
layer-element.c
Go to the documentation of this file.
1/*
2 * GDSII-Converter
3 * Copyright (C) 2018 Mario Hüttel <mario.huettel@gmx.net>
4 *
5 * This file is part of GDSII-Converter.
6 *
7 * GDSII-Converter is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * GDSII-Converter is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * The drag and drop implementation is adapted from
22 * https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-22/tests/testlist3.c
23 *
24 * Thanks to the GTK3 people for creating these examples.
25 */
26
40#include <glib/gi18n.h>
41
42G_DEFINE_TYPE(LayerElement, layer_element, GTK_TYPE_LIST_BOX_ROW)
43
44static void layer_element_dispose(GObject *obj)
45{
46 /* destroy parent container. This destroys all widgets inside */
47 G_OBJECT_CLASS(layer_element_parent_class)->dispose(obj);
48}
49
50static void layer_element_constructed(GObject *obj)
51{
52 G_OBJECT_CLASS(layer_element_parent_class)->constructed(obj);
53}
54
55static void layer_element_class_init(LayerElementClass *klass)
56{
57 GObjectClass *oclass = G_OBJECT_CLASS(klass);
58
59 oclass->dispose = layer_element_dispose;
60 oclass->constructed = layer_element_constructed;
61}
62
63static void layer_element_init(LayerElement *self)
64{
65 GtkBuilder *builder;
66 GtkWidget *glade_box;
67
68 builder = gtk_builder_new_from_resource("/gui/layer-widget.glade");
69 glade_box = GTK_WIDGET(gtk_builder_get_object(builder, "box"));
70 gtk_container_add(GTK_CONTAINER(self), glade_box);
71
72 /* Get Elements */
73 self->priv.color = GTK_COLOR_BUTTON(gtk_builder_get_object(builder, "color"));
74 self->priv.export = GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "export"));
75 self->priv.layer = GTK_LABEL(gtk_builder_get_object(builder, "layer"));
76 self->priv.name = GTK_ENTRY(gtk_builder_get_object(builder, "entry"));
77 self->priv.event_handle = GTK_EVENT_BOX(gtk_builder_get_object(builder, "event-box"));
78
79 g_object_unref(builder);
80}
81
82GtkWidget *layer_element_new(void)
83{
84 return GTK_WIDGET(g_object_new(TYPE_LAYER_ELEMENT, NULL));
85}
86
87const char *layer_element_get_name(LayerElement *elem)
88{
89 return gtk_entry_get_text(elem->priv.name);
90}
91
92void layer_element_set_name(LayerElement *elem, const char *name)
93{
94 gtk_entry_set_text(elem->priv.name, name);
95}
96
97void layer_element_set_layer(LayerElement *elem, int layer)
98{
99 GString *string;
100
101 string = g_string_new_len(NULL, 100);
102 g_string_printf(string, _("Layer: %d"), layer);
103 gtk_label_set_text(elem->priv.layer, (const gchar *)string->str);
104 elem->priv.layer_num = layer;
105 g_string_free(string, TRUE);
106}
107
108int layer_element_get_layer(LayerElement *elem)
109{
110 return elem->priv.layer_num;
111}
112
113void layer_element_set_export(LayerElement *elem, gboolean export)
114{
115 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(elem->priv.export), export);
116}
117
118gboolean layer_element_get_export(LayerElement *elem)
119{
120 return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(elem->priv.export));
121}
122
123void layer_element_get_color(LayerElement *elem, GdkRGBA *rgba)
124{
125 if (!rgba)
126 return;
127
128 gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(elem->priv.color), rgba);
129}
130
131void layer_element_set_color(LayerElement *elem, GdkRGBA *rgba)
132{
133 if (!elem || !rgba)
134 return;
135
136 gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(elem->priv.color), rgba);
137}
138
139void layer_element_set_dnd_callbacks(LayerElement *elem, struct layer_element_dnd_data *data)
140{
141 if (!elem || !data)
142 return;
143
144 /* Setup drag and drop */
145 gtk_style_context_add_class(gtk_widget_get_style_context(GTK_WIDGET(elem)), "row");
146 gtk_drag_source_set(GTK_WIDGET(elem->priv.event_handle), GDK_BUTTON1_MASK,
147 data->entries, data->entry_count, GDK_ACTION_MOVE);
148 g_signal_connect(elem->priv.event_handle, "drag-begin", G_CALLBACK(data->drag_begin), NULL);
149 g_signal_connect(elem->priv.event_handle, "drag-data-get", G_CALLBACK(data->drag_data_get), NULL);
150 g_signal_connect(elem->priv.event_handle, "drag-end", G_CALLBACK(data->drag_end), NULL);
151
152}
153
const char * layer_element_get_name(LayerElement *elem)
get name of the layer
Definition: layer-element.c:87
static void layer_element_constructed(GObject *obj)
Definition: layer-element.c:50
void layer_element_set_color(LayerElement *elem, GdkRGBA *rgba)
Set color of layer.
static void layer_element_init(LayerElement *self)
Definition: layer-element.c:63
static void layer_element_class_init(LayerElementClass *klass)
Definition: layer-element.c:55
static void layer_element_dispose(GObject *obj)
Definition: layer-element.c:44
int layer_element_get_layer(LayerElement *elem)
Get layer number.
void layer_element_set_layer(LayerElement *elem, int layer)
Set layer number for this layer.
Definition: layer-element.c:97
#define TYPE_LAYER_ELEMENT
Definition: layer-element.h:42
void layer_element_get_color(LayerElement *elem, GdkRGBA *rgba)
Get color of layer.
void layer_element_set_name(LayerElement *elem, const char *name)
layer_element_set_name
Definition: layer-element.c:92
void layer_element_set_dnd_callbacks(LayerElement *elem, struct layer_element_dnd_data *data)
Setup drag and drop of elem for use in the LayerSelector.
void layer_element_set_export(LayerElement *elem, gboolean export)
Set export flag for this layer.
gboolean layer_element_get_export(LayerElement *elem)
Get export flag of layer.
GtkWidget * layer_element_new(void)
Create new layer element object.
Definition: layer-element.c:82
Implementation of the layer element used for configuring layer colors etc.
This structure holds the necessary data to set up a LayerElement for Drag'n'Drop.
Definition: layer-element.h:63
void(* drag_data_get)(GtkWidget *, GdkDragContext *, GtkSelectionData *, guint, guint, gpointer)
Callback fucktion for data_get event.
Definition: layer-element.h:71
GtkTargetEntry * entries
Array of target entries for the DnD operation.
Definition: layer-element.h:65
void(* drag_begin)(GtkWidget *, GdkDragContext *, gpointer)
Callback function for drag_begin event.
Definition: layer-element.h:69
void(* drag_end)(GtkWidget *, GdkDragContext *, gpointer)
Callback function for drag_end event.
Definition: layer-element.h:73
int entry_count
Count of elements in layer_element_dnd_data::entries array.
Definition: layer-element.h:67