[goffice] GOArrowSel: new widget.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] GOArrowSel: new widget.
- Date: Wed, 11 Feb 2015 14:39:45 +0000 (UTC)
commit b5f1557ae8add6be95be026fee2daaa2dabe77ea
Author: Morten Welinder <terra gnome org>
Date: Wed Feb 11 09:39:22 2015 -0500
GOArrowSel: new widget.
NEWS | 1 +
goffice/Makefile.am | 3 +
goffice/gtk/go-arrow-sel.c | 233 +++++++++++++++++++++++++++++++++++++++++++
goffice/gtk/go-arrow-sel.h | 40 ++++++++
goffice/gtk/go-arrow-sel.ui | 173 ++++++++++++++++++++++++++++++++
goffice/gtk/goffice-gtk.h | 1 +
6 files changed, 451 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index 7339b12..5c5cb6a 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ goffice 0.10.21:
Morten:
* Fix problem with linear solver.
+ * Add arrow selector widget.
--------------------------------------------------------------------------
goffice 0.10.20:
diff --git a/goffice/Makefile.am b/goffice/Makefile.am
index 71e2b2d..0fce905 100644
--- a/goffice/Makefile.am
+++ b/goffice/Makefile.am
@@ -270,6 +270,7 @@ gtk_SOURCES = \
gtk/go-charmap-sel.c \
gtk/go-locale-sel.c \
gtk/go-3d-rotation-sel.c \
+ gtk/go-arrow-sel.c \
\
gtk/go-optionmenu.c \
gtk/go-combo-box.c \
@@ -307,6 +308,7 @@ gtk_HEADERS = \
gtk/go-charmap-sel.h \
gtk/go-locale-sel.h \
gtk/go-3d-rotation-sel.h \
+ gtk/go-arrow-sel.h \
\
gtk/go-optionmenu.h \
gtk/go-combo-box.h \
@@ -605,6 +607,7 @@ embedded_stuff_compress = \
graph/gog-theme-editor.ui \
graph/new-theme-prefs.ui \
gtk/go-3d-rotation-sel.ui \
+ gtk/go-arrow-sel.ui \
gtk/go-font-sel.ui \
gtk/go-format-sel.ui \
gtk/go-image-save-dialog-extra.ui \
diff --git a/goffice/gtk/go-arrow-sel.c b/goffice/gtk/go-arrow-sel.c
new file mode 100644
index 0000000..9fd228f
--- /dev/null
+++ b/goffice/gtk/go-arrow-sel.c
@@ -0,0 +1,233 @@
+/*
+ * An arrow selector widget.
+ *
+ * Copyright 2015 by Morten Welinder (terra gnome org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) version 3.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ * USA.
+ */
+#include <goffice/goffice-config.h>
+#include <goffice/goffice.h>
+
+#include <gsf/gsf-impl-utils.h>
+#include <glib/gi18n-lib.h>
+#include <errno.h>
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+struct _GOArrowSel {
+ GtkBin base;
+ GtkBuilder *gui;
+ GOArrow arrow;
+
+ GtkSpinButton *spin_a, *spin_b, *spin_c;
+ GtkWidget *preview;
+};
+
+typedef struct {
+ GtkBinClass parent_class;
+} GOArrowSelClass;
+
+enum {
+ PROP_0,
+ PROP_ARROW
+};
+
+static GObjectClass *as_parent_class;
+
+static void
+cb_spin_changed (GtkWidget *spin, GOArrowSel *as)
+{
+ GOArrow arr = as->arrow;
+
+ arr.a = gtk_spin_button_get_value (as->spin_a);
+ arr.b = gtk_spin_button_get_value (as->spin_b);
+ arr.c = gtk_spin_button_get_value (as->spin_c);
+ go_arrow_sel_set_arrow (as, &arr);
+}
+
+static gboolean
+cb_draw_arrow (GtkWidget *widget, cairo_t *cr, GOArrowSel *as)
+{
+ guint width = gtk_widget_get_allocated_width (widget);
+ guint height = gtk_widget_get_allocated_height (widget);
+ double dx, dy;
+ double x = width / 2;
+ double y1 = height / 4, y2 = height * 3 / 4;
+
+ cairo_save (cr);
+ cairo_translate (cr, x, y2);
+ /* cairo_scale (cr, 2, 2); */
+ /* cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (style->line.color)); */
+ go_arrow_draw (&as->arrow, cr, &dx, &dy, 0);
+ cairo_restore (cr);
+
+ cairo_move_to (cr, x, y1);
+ cairo_line_to (cr, x + dx, y2 + dy);
+ cairo_stroke (cr);
+
+ return FALSE;
+}
+
+static GObject*
+go_arrow_sel_constructor (GType type,
+ guint n_construct_properties,
+ GObjectConstructParam *construct_params)
+{
+ GtkWidget *arrowsel, *placeholder;
+ GOArrowSel *as = (GOArrowSel *)
+ (as_parent_class->constructor (type,
+ n_construct_properties,
+ construct_params));
+
+ if (!as)
+ return NULL;
+
+ as->gui = go_gtk_builder_load_internal ("res:go:gtk/go-arrow-sel.ui", GETTEXT_PACKAGE, NULL);
+ as->spin_a = GTK_SPIN_BUTTON (go_gtk_builder_get_widget (as->gui, "spin_a"));
+ g_signal_connect (as->spin_a, "value-changed", G_CALLBACK (cb_spin_changed), as);
+ as->spin_b = GTK_SPIN_BUTTON (go_gtk_builder_get_widget (as->gui, "spin_b"));
+ g_signal_connect (as->spin_b, "value-changed", G_CALLBACK (cb_spin_changed), as);
+ as->spin_c = GTK_SPIN_BUTTON (go_gtk_builder_get_widget (as->gui, "spin_c"));
+ g_signal_connect (as->spin_c, "value-changed", G_CALLBACK (cb_spin_changed), as);
+
+ as->preview = go_gtk_builder_get_widget (as->gui, "preview");
+ g_signal_connect (G_OBJECT (as->preview), "draw",
+ G_CALLBACK (cb_draw_arrow), as);
+
+ arrowsel = go_gtk_builder_get_widget (as->gui, "arrow-selector");
+ gtk_widget_show_all (arrowsel);
+ gtk_container_add (GTK_CONTAINER (as), arrowsel);
+
+ return (GObject *)as;
+}
+
+static void
+go_arrow_sel_dispose (GObject *obj)
+{
+ GOArrowSel *as = GO_ARROW_SEL (obj);
+ g_clear_object (&as->gui);
+ as_parent_class->dispose (obj);
+}
+
+static void
+go_arrow_sel_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GOArrowSel *as = GO_ARROW_SEL (object);
+
+ switch (prop_id) {
+ case PROP_ARROW:
+ g_value_set_boxed (value, &as->arrow);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+go_arrow_sel_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GOArrowSel *as = GO_ARROW_SEL (object);
+
+ switch (prop_id) {
+ case PROP_ARROW:
+ go_arrow_sel_set_arrow (as, g_value_peek_pointer (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+go_arrow_sel_init (GObject *object)
+{
+ GOArrowSel *as = GO_ARROW_SEL (object);
+ go_arrow_clear (&as->arrow);
+}
+
+static void
+go_arrow_sel_class_init (GObjectClass *klass)
+{
+ klass->constructor = go_arrow_sel_constructor;
+ klass->dispose = go_arrow_sel_dispose;
+ klass->get_property = go_arrow_sel_get_property;
+ klass->set_property = go_arrow_sel_set_property;
+
+ as_parent_class = g_type_class_peek_parent (klass);
+
+ g_object_class_install_property
+ (klass, PROP_ARROW,
+ g_param_spec_boxed ("arrow",
+ _("Arrow"),
+ _("The currently selected arrow"),
+ GO_ARROW_TYPE,
+ GSF_PARAM_STATIC | G_PARAM_READWRITE));
+}
+
+GSF_CLASS (GOArrowSel, go_arrow_sel,
+ go_arrow_sel_class_init, go_arrow_sel_init, GTK_TYPE_BIN)
+#if 0
+;
+#endif
+
+
+GtkWidget *
+go_arrow_sel_new (void)
+{
+ return g_object_new (GO_TYPE_ARROW_SEL, NULL);
+}
+
+
+GOArrow const *
+go_arrow_sel_get_arrow (GOArrowSel const *as)
+{
+ g_return_val_if_fail (GO_IS_ARROW_SEL (as), NULL);
+
+ return &as->arrow;
+}
+
+void
+go_arrow_sel_set_arrow (GOArrowSel *as, GOArrow const *arrow)
+{
+ g_return_if_fail (GO_IS_ARROW_SEL (as));
+
+ if (as->arrow.typ == arrow->typ &&
+ as->arrow.a == arrow->a &&
+ as->arrow.b == arrow->b &&
+ as->arrow.c == arrow->c)
+ return;
+
+ g_object_freeze_notify (G_OBJECT (as));
+ as->arrow = *arrow;
+ g_object_notify (G_OBJECT (as), "arrow");
+ gtk_spin_button_set_value (as->spin_a, arrow->a);
+ gtk_spin_button_set_value (as->spin_b, arrow->b);
+ gtk_spin_button_set_value (as->spin_c, arrow->c);
+ g_object_thaw_notify (G_OBJECT (as));
+
+ gtk_widget_queue_draw (as->preview);
+}
diff --git a/goffice/gtk/go-arrow-sel.h b/goffice/gtk/go-arrow-sel.h
new file mode 100644
index 0000000..dd8d1af
--- /dev/null
+++ b/goffice/gtk/go-arrow-sel.h
@@ -0,0 +1,40 @@
+/*
+ * go-arrow-sel.h - Selector for GOArrow
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) version 3.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ * USA.
+ */
+#ifndef _GO_ARROW_SEL_H_
+#define _GO_ARROW_SEL_H_
+
+#include <goffice/goffice.h>
+
+G_BEGIN_DECLS
+
+#define GO_TYPE_ARROW_SEL (go_arrow_sel_get_type ())
+#define GO_ARROW_SEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GO_TYPE_ARROW_SEL, GOArrowSel))
+#define GO_IS_ARROW_SEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GO_TYPE_ARROW_SEL))
+
+typedef struct _GOArrowSel GOArrowSel;
+
+GType go_arrow_sel_get_type (void);
+GtkWidget *go_arrow_sel_new (void);
+
+void go_arrow_sel_set_arrow (GOArrowSel *as, GOArrow const *arrow);
+GOArrow const *go_arrow_sel_get_arrow (GOArrowSel const *as);
+
+G_END_DECLS
+
+#endif /* _GO_ARROW_SEL_H_ */
diff --git a/goffice/gtk/go-arrow-sel.ui b/goffice/gtk/go-arrow-sel.ui
new file mode 100644
index 0000000..d53f7d6
--- /dev/null
+++ b/goffice/gtk/go-arrow-sel.ui
@@ -0,0 +1,173 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.0 on Wed Feb 11 08:26:35 2015 -->
+<interface>
+ <!-- interface-requires gtk+ 3.8 -->
+ <object class="GtkAdjustment" id="adjustment1">
+ <property name="upper">25</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
+ <object class="GtkAdjustment" id="adjustment2">
+ <property name="upper">25</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
+ <object class="GtkAdjustment" id="adjustment3">
+ <property name="upper">25</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
+ <object class="GtkBox" id="arrow-selector">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="border_width">12</property>
+ <child>
+ <object class="GtkGrid" id="grid1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="row_spacing">6</property>
+ <property name="column_spacing">12</property>
+ <child>
+ <object class="GtkBox" id="type_placeholder">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">2</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Dimension A</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Dimension B</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Dimension C</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="spin_a">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="input_purpose">number</property>
+ <property name="adjustment">adjustment1</property>
+ <property name="climb_rate">0.10000000149011612</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="spin_b">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="text" translatable="yes">0</property>
+ <property name="input_purpose">number</property>
+ <property name="adjustment">adjustment2</property>
+ <property name="climb_rate">0.10000000149011612</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="spin_c">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="text" translatable="yes">0</property>
+ <property name="input_purpose">number</property>
+ <property name="adjustment">adjustment3</property>
+ <property name="climb_rate">0.10000000149011612</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">3</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSeparator" id="separator1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_left">6</property>
+ <property name="margin_right">6</property>
+ <property name="orientation">vertical</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkDrawingArea" id="preview">
+ <property name="width_request">100</property>
+ <property name="height_request">100</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+</interface>
diff --git a/goffice/gtk/goffice-gtk.h b/goffice/gtk/goffice-gtk.h
index a79a2e5..33d2e24 100644
--- a/goffice/gtk/goffice-gtk.h
+++ b/goffice/gtk/goffice-gtk.h
@@ -25,6 +25,7 @@
#include <goffice/gtk/go-palette.h>
#include <goffice/gtk/go-selector.h>
+#include <goffice/gtk/go-arrow-sel.h>
#include <goffice/gtk/go-3d-rotation-sel.h>
#include <goffice/gtk/go-action-combo-color.h>
#include <goffice/gtk/go-action-combo-pixmaps.h>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]