2018-05-15 22:54:10 +02:00
|
|
|
/*
|
|
|
|
* GDSII-Converter
|
|
|
|
* Copyright (C) 2018 Mario Hüttel <mario.huettel@gmx.net>
|
|
|
|
*
|
|
|
|
* This file is part of GDSII-Converter.
|
|
|
|
*
|
|
|
|
* GDSII-Converter is free software: you can redistribute it and/or modify
|
2018-05-16 16:29:34 +02:00
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
2018-05-15 22:54:10 +02:00
|
|
|
*
|
|
|
|
* GDSII-Converter is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-03-13 20:22:11 +01:00
|
|
|
/*
|
|
|
|
* The drag and drop implementation is adapted from
|
|
|
|
* https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-22/tests/testlist3.c
|
|
|
|
*
|
|
|
|
* Thanks to the GTK3 people for creating these examples.
|
|
|
|
*/
|
|
|
|
|
2018-07-25 16:44:04 +02:00
|
|
|
/**
|
|
|
|
* @file layer-element.c
|
2019-03-13 20:22:11 +01:00
|
|
|
* @brief Implementation of the layer element used for configuring layer colors etc.
|
2018-07-25 16:44:04 +02:00
|
|
|
* @author Mario Hüttel <mario.huettel@gmx.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2019-03-26 21:12:37 +01:00
|
|
|
* @addtogroup LayerElement
|
|
|
|
* @ingroup Widgets
|
2018-07-25 16:44:04 +02:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2019-03-26 19:57:19 +01:00
|
|
|
#include <gds-render/widgets/layer-element.h>
|
2018-05-15 16:57:08 +02:00
|
|
|
|
2018-05-23 01:03:16 +02:00
|
|
|
G_DEFINE_TYPE(LayerElement, layer_element, GTK_TYPE_LIST_BOX_ROW)
|
2018-05-16 16:20:09 +02:00
|
|
|
|
|
|
|
static void layer_element_dispose(GObject *obj)
|
|
|
|
{
|
|
|
|
/* destroy parent container. This destroys all widgets inside */
|
|
|
|
G_OBJECT_CLASS(layer_element_parent_class)->dispose(obj);
|
|
|
|
}
|
2018-05-15 16:57:08 +02:00
|
|
|
|
2018-05-22 00:00:19 +02:00
|
|
|
static void layer_element_constructed(GObject *obj)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS(layer_element_parent_class)->constructed(obj);
|
|
|
|
}
|
|
|
|
|
2018-05-15 16:57:08 +02:00
|
|
|
static void layer_element_class_init(LayerElementClass *klass)
|
|
|
|
{
|
2018-05-16 16:20:09 +02:00
|
|
|
GObjectClass *oclass = G_OBJECT_CLASS(klass);
|
|
|
|
oclass->dispose = layer_element_dispose;
|
2018-05-22 00:00:19 +02:00
|
|
|
oclass->constructed = layer_element_constructed;
|
2018-05-15 16:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void layer_element_init(LayerElement *self)
|
|
|
|
{
|
2018-05-16 16:20:09 +02:00
|
|
|
GtkBuilder *builder;
|
|
|
|
GtkWidget *glade_box;
|
2019-05-20 19:18:01 +02:00
|
|
|
builder = gtk_builder_new_from_resource("/gui/layer-widget.glade");
|
2018-05-16 16:20:09 +02:00
|
|
|
glade_box = GTK_WIDGET(gtk_builder_get_object(builder, "box"));
|
2018-05-23 01:03:16 +02:00
|
|
|
gtk_container_add(GTK_CONTAINER(self), glade_box);
|
2018-05-16 16:20:09 +02:00
|
|
|
|
|
|
|
/* Get Elements */
|
|
|
|
self->priv.color = GTK_COLOR_BUTTON(gtk_builder_get_object(builder, "color"));
|
|
|
|
self->priv.export = GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "export"));
|
|
|
|
self->priv.layer = GTK_LABEL(gtk_builder_get_object(builder, "layer"));
|
|
|
|
self->priv.name = GTK_ENTRY(gtk_builder_get_object(builder, "entry"));
|
2018-05-23 01:03:16 +02:00
|
|
|
self->priv.event_handle = GTK_EVENT_BOX(gtk_builder_get_object(builder, "event-box"));
|
2018-05-16 16:20:09 +02:00
|
|
|
|
|
|
|
g_object_unref(builder);
|
2018-05-15 16:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *layer_element_new(void)
|
|
|
|
{
|
2018-05-22 12:59:28 +02:00
|
|
|
return GTK_WIDGET(g_object_new(TYPE_LAYER_ELEMENT, NULL));
|
2018-05-15 16:57:08 +02:00
|
|
|
}
|
2018-05-16 16:20:09 +02:00
|
|
|
|
|
|
|
const char *layer_element_get_name(LayerElement *elem)
|
|
|
|
{
|
|
|
|
return gtk_entry_get_text(elem->priv.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer_element_set_name(LayerElement *elem, const char* name)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text(elem->priv.name, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer_element_set_layer(LayerElement *elem, int layer)
|
|
|
|
{
|
|
|
|
GString *string;
|
|
|
|
|
|
|
|
string = g_string_new_len(NULL, 100);
|
2018-05-22 18:45:23 +02:00
|
|
|
g_string_printf(string, "Layer: %d", layer);
|
2018-05-16 16:20:09 +02:00
|
|
|
gtk_label_set_text(elem->priv.layer, (const gchar *)string->str);
|
|
|
|
elem->priv.layer_num = layer;
|
|
|
|
g_string_free(string, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int layer_element_get_layer(LayerElement *elem)
|
|
|
|
{
|
|
|
|
return elem->priv.layer_num;
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer_element_set_export(LayerElement *elem, gboolean export)
|
|
|
|
{
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(elem->priv.export), export);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean layer_element_get_export(LayerElement *elem)
|
|
|
|
{
|
|
|
|
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(elem->priv.export));
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer_element_get_color(LayerElement *elem, GdkRGBA *rgba)
|
|
|
|
{
|
|
|
|
if (!rgba)
|
|
|
|
return;
|
2019-03-25 18:47:12 +01:00
|
|
|
|
2018-05-16 16:20:09 +02:00
|
|
|
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(elem->priv.color), rgba);
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer_element_set_color(LayerElement *elem, GdkRGBA *rgba)
|
|
|
|
{
|
2019-03-25 18:47:12 +01:00
|
|
|
if (!elem || !rgba)
|
|
|
|
return;
|
|
|
|
|
2018-05-16 16:20:09 +02:00
|
|
|
gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(elem->priv.color), rgba);
|
|
|
|
}
|
2018-07-25 16:44:04 +02:00
|
|
|
|
2019-03-25 18:47:12 +01:00
|
|
|
void layer_element_set_dnd_callbacks(LayerElement *elem, struct layer_element_dnd_data *data)
|
2019-03-15 23:17:03 +01:00
|
|
|
{
|
2019-03-25 18:47:12 +01:00
|
|
|
if (!elem || !data)
|
|
|
|
return;
|
|
|
|
|
2019-03-15 23:17:03 +01:00
|
|
|
/* Setup drag and drop */
|
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context(GTK_WIDGET(elem)), "row");
|
2019-03-25 18:47:12 +01:00
|
|
|
gtk_drag_source_set(GTK_WIDGET(elem->priv.event_handle), GDK_BUTTON1_MASK, data->entries, data->entry_count, GDK_ACTION_MOVE);
|
|
|
|
g_signal_connect(elem->priv.event_handle, "drag-begin", G_CALLBACK(data->drag_begin), NULL);
|
|
|
|
g_signal_connect(elem->priv.event_handle, "drag-data-get", G_CALLBACK(data->drag_data_get), NULL);
|
|
|
|
g_signal_connect(elem->priv.event_handle, "drag-end", G_CALLBACK(data->drag_end), NULL);
|
2019-03-15 23:17:03 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-07-25 16:44:04 +02:00
|
|
|
/** @} */
|