summaryrefslogtreecommitdiff
path: root/src/gplot
diff options
context:
space:
mode:
authorRuben Undheim <ruben.undheim@gmail.com>2018-07-12 23:10:08 +0200
committerRuben Undheim <ruben.undheim@gmail.com>2018-07-12 23:10:08 +0200
commite1fffcb07ce0d8b0db9e0b4b5e1e0c1128197af5 (patch)
tree850eead23d896c80df8c02ab0231164a07e8356e /src/gplot
parent1eb59a5d9eedcb2fde4cfcd8f3cf87edf18e71e4 (diff)
New upstream version 0.82
Diffstat (limited to 'src/gplot')
-rw-r--r--src/gplot/Makefile.am9
-rw-r--r--src/gplot/gplot-internal.h70
-rw-r--r--src/gplot/gplot.c141
-rw-r--r--src/gplot/gplot.h27
-rw-r--r--src/gplot/gplotfunction.c21
-rw-r--r--src/gplot/gplotfunction.h31
-rw-r--r--src/gplot/gplotlines.c163
-rw-r--r--src/gplot/gplotlines.h29
8 files changed, 305 insertions, 186 deletions
diff --git a/src/gplot/Makefile.am b/src/gplot/Makefile.am
index 85665ee..a7dd460 100644
--- a/src/gplot/Makefile.am
+++ b/src/gplot/Makefile.am
@@ -1,4 +1,10 @@
oreganodir = $(datadir)/oregano
+
+AM_CFLAGS = -Wall -DG_DISABLE_DEPRECATED -DGSEAL_ENABLE \
+ -DGDK_PIXBUF_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED \
+ -DGTK_DISABLE_DEPRECATED -DGTK_DISABLE_SINGLE_INCLUDES \
+ -DG_DISABLE_SINGLE_INCLUDES -DGDK_PIXBUF_DISABLE_SINGLE_INCLUDES
+
INCLUDES = \
$(OREGANO_CFLAGS)
@@ -7,8 +13,7 @@ libgplot_a_SOURCES = \
gplot.c \
gplotfunction.c \
gplotfunction.h \
+ gplot-internal.h \
gplot.h \
gplotlines.c \
gplotlines.h
-
-libgplot_a_LIBADD = libgplot.a
diff --git a/src/gplot/gplot-internal.h b/src/gplot/gplot-internal.h
new file mode 100644
index 0000000..90a1aee
--- /dev/null
+++ b/src/gplot/gplot-internal.h
@@ -0,0 +1,70 @@
+/*
+ * gplot-internal.h
+ *
+ * Authors:
+ * Marc Lorber <lorber.marc@wanadoo.fr>
+ *
+ * Web page: https://github.com/marc-lorber/oregano
+ *
+ * Copyright (C) 1999-2001 Richard Hult
+ * Copyright (C) 2003,2006 Ricardo Markiewicz
+ * Copyright (C) 2009-2012 Marc Lorber
+ *
+ * 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) any later version.
+ *
+ * This program 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 this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _GPLOT_INTERNAL_H_
+#define _GPLOT_INTERNAL_H_
+
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <glib.h>
+
+#include "gplot.h"
+#include "gplotfunction.h"
+
+// Internal definitions associated to gplot.h
+
+typedef struct _GPlotClass GPlotClass;
+typedef struct _GPlotPriv GPlotPriv;
+
+
+struct _GPlot {
+ GtkLayout parent;
+
+ GPlotPriv *priv;
+};
+struct _GPlotClass {
+ GtkLayoutClass parent_class;
+};
+
+
+// Internal definitions associated to gplotfunction.h
+
+#define TYPE_GPLOT_FUNCTION (g_plot_function_get_type ())
+#define GPLOT_FUNCTION_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, TYPE_GPLOT_FUNCTION, GPlotFunctionClass)
+#define GPLOT_FUNCTION_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), TYPE_GPLOT_FUNCTION, GPlotFunctionClass))
+
+typedef struct _GPlotFunctionClass GPlotFunctionClass;
+
+struct _GPlotFunctionClass {
+ GTypeInterface parent;
+
+ void (*draw) (GPlotFunction *, cairo_t *, GPlotFunctionBBox *);
+ void (*get_bbox) (GPlotFunction *, GPlotFunctionBBox *);
+};
+
+#endif
diff --git a/src/gplot/gplot.c b/src/gplot/gplot.c
index b41408d..9f50432 100644
--- a/src/gplot/gplot.c
+++ b/src/gplot/gplot.c
@@ -3,9 +3,13 @@
*
* Authors:
* Ricardo Markiewicz <rmarkie@fi.uba.ar>
+ * Marc Lorber <lorber.marc@wanadoo.fr>
+ *
+ * Web page: https://github.com/marc-lorber/oregano
*
* Copyright (C) 1999-2001 Richard Hult
* Copyright (C) 2003,2004 Ricardo Markiewicz
+ * Copyright (C) 2009-2012 Marc Lorber
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -24,13 +28,15 @@
*/
#include <math.h>
+
+#include "gplot-internal.h"
#include "gplot.h"
#define BORDER_SIZE 50
static void g_plot_class_init (GPlotClass* class);
static void g_plot_init (GPlot* plot);
-static gint g_plot_expose (GtkWidget* widget, GdkEventExpose* event);
+static gboolean g_plot_draw (GtkWidget* widget, cairo_t *cr);
static cairo_t* g_plot_create_cairo (GPlot *);
static gboolean g_plot_motion_cb (GtkWidget *, GdkEventMotion *, GPlot *);
static gboolean g_plot_button_press_cb (GtkWidget *, GdkEventButton *, GPlot *);
@@ -72,7 +78,7 @@ struct _GPlotPriv {
gdouble last_x;
gdouble last_y;
- /* Window->Viewport * Transformation Matrix */
+ // Window->Viewport * Transformation Matrix
cairo_matrix_t matrix;
gboolean window_valid;
@@ -106,7 +112,7 @@ g_plot_get_type ()
}
static void
-g_plot_class_init (GPlotClass* class)
+g_plot_class_init (GPlotClass* class)
{
GObjectClass* object_class;
GtkWidgetClass* widget_class;
@@ -115,7 +121,7 @@ g_plot_class_init (GPlotClass* class)
widget_class = GTK_WIDGET_CLASS (class);
parent_class = g_type_class_peek_parent (class);
- widget_class->expose_event = g_plot_expose;
+ widget_class->draw = g_plot_draw;
object_class->dispose = g_plot_dispose;
object_class->finalize = g_plot_finalize;
@@ -126,7 +132,7 @@ g_plot_create_cairo (GPlot *p)
{
cairo_t *cr;
- cr = gdk_cairo_create (GTK_LAYOUT (p)->bin_window);
+ cr = gdk_cairo_create (gtk_layout_get_bin_window (GTK_LAYOUT (p)));
return cr;
}
@@ -161,6 +167,7 @@ g_plot_dispose (GObject *object)
}
g_list_free (plot->priv->functions);
plot->priv->functions = NULL;
+ g_list_free_full (lst, g_object_unref);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
@@ -168,7 +175,7 @@ g_plot_dispose (GObject *object)
static int
get_best_exponent (int div)
{
- /* http://en.wikipedia.org/wiki/Micro */
+ // http://en.wikipedia.org/wiki/Micro
switch (div) {
case -24:
case -21:
@@ -197,7 +204,8 @@ get_best_exponent (int div)
}
void
-draw_axis (cairo_t *cr, GPlotFunctionBBox *bbox, gdouble min, gdouble max, gboolean vertical, gint *div)
+draw_axis (cairo_t *cr, GPlotFunctionBBox *bbox, gdouble min, gdouble max,
+ gboolean vertical, gint *div)
{
gchar *label;
cairo_text_extents_t extents;
@@ -221,7 +229,8 @@ draw_axis (cairo_t *cr, GPlotFunctionBBox *bbox, gdouble min, gdouble max, gbool
else
s = (bbox->xmax - bbox->xmin) / 10.0;
- for (i = (vertical?bbox->ymin:bbox->xmin), j = max; i <= (vertical?bbox->ymax:bbox->xmax) + 0.5; i += s, j -= step) {
+ for (i = (vertical?bbox->ymin:bbox->xmin), j = max;
+ i <= (vertical?bbox->ymax:bbox->xmax) + 0.5; i += s, j -= step) {
label = g_strdup_printf ("%.2f", j / divisor);
cairo_text_extents (cr, label, &extents);
@@ -232,7 +241,8 @@ draw_axis (cairo_t *cr, GPlotFunctionBBox *bbox, gdouble min, gdouble max, gbool
y2 = i;
x3 = bbox->xmin - extents.width * 1.5;
y3 = i + extents.height / 2.0;
- } else {
+ }
+ else {
x1 = i;
y1 = bbox->ymax - 4;
x2 = i;
@@ -253,7 +263,7 @@ draw_axis (cairo_t *cr, GPlotFunctionBBox *bbox, gdouble min, gdouble max, gbool
static gchar*
get_unit_text (int div)
{
- /* http://en.wikipedia.org/wiki/Micro */
+ // http://en.wikipedia.org/wiki/Micro
switch (div) {
case -24: return g_strdup ("y");
case -21: return g_strdup ("z");
@@ -277,29 +287,27 @@ get_unit_text (int div)
return g_strdup_printf ("10e%02d", div);
}
-static gint
-g_plot_expose (GtkWidget* widget, GdkEventExpose* event)
+static gboolean
+g_plot_draw (GtkWidget* widget, cairo_t *cr)
{
- static double dashes[] = {3, /* ink */
- 3, /* skip */
- 3, /* ink */
- 3 /* skip*/ };
- static int ndash = sizeof (dashes)/sizeof(dashes[0]);
+ static double dashes[] =
+ {3, // ink
+ 3, // skip
+ 3, // ink
+ 3}; // skip
+ static int ndash = sizeof (dashes) / sizeof (dashes[0]);
static double offset = -0.2;
GPlot *plot;
GPlotPriv *priv;
- cairo_t* cr;
guint width;
guint height;
guint graph_width;
guint graph_height;
GPlotFunction *f;
GList *lst;
- GPlotFunctionBBox bbox;
gdouble aX, bX, aY, bY;
gint div;
- int i = 0;
cairo_text_extents_t extents;
plot = GPLOT (widget);
@@ -309,49 +317,38 @@ g_plot_expose (GtkWidget* widget, GdkEventExpose* event)
g_plot_update_bbox (plot);
}
- width = widget->allocation.width;
- height = widget->allocation.height;
+ width = gtk_widget_get_allocated_width (widget);
+ height = gtk_widget_get_allocated_height (widget);
graph_width = width - priv->left_border - priv->right_border;
graph_height = height - priv->top_border - priv->bottom_border;
- cr = g_plot_create_cairo (plot);
-
- /* Set a clip region for the expose event */
- /* TODO :This is useful if we use gtk_widget_queue_draw_area */
- cairo_rectangle (cr, event->area.x, event->area.y, event->area.width, event->area.height);
- cairo_clip (cr);
-
- /* Paint background */
+ // Paint background
cairo_save (cr);
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
cairo_rectangle (cr, 0, 0, width, height);
cairo_fill (cr);
cairo_restore (cr);
- /* Plot Border */
+ // Plot Border
cairo_save (cr);
cairo_set_line_width (cr, 0.5);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
cairo_rectangle (cr, priv->left_border, priv->right_border, graph_width, graph_height);
cairo_stroke (cr);
cairo_restore (cr);
-
- /* TODO : Move this to SizeAllocation functions */
- priv->viewport_bbox.xmax = widget->allocation.width - priv->right_border;
+
+ priv->viewport_bbox.xmax = width - priv->right_border;
priv->viewport_bbox.xmin = priv->left_border;
- priv->viewport_bbox.ymax = widget->allocation.height - priv->bottom_border;
+ priv->viewport_bbox.ymax = height - priv->bottom_border;
priv->viewport_bbox.ymin = priv->top_border;
- /* Save real bbox */
- bbox = priv->window_bbox;
-
- /* Calculating Window to Viewport matrix */
- aX = (priv->viewport_bbox.xmax - priv->viewport_bbox.xmin)
- / (priv->window_bbox.xmax - priv->window_bbox.xmin);
+ // Calculating Window to Viewport matrix
+ aX = (priv->viewport_bbox.xmax - priv->viewport_bbox.xmin) /
+ (priv->window_bbox.xmax - priv->window_bbox.xmin);
bX = -aX * priv->window_bbox.xmin + priv->viewport_bbox.xmin;
- aY = (priv->viewport_bbox.ymax - priv->viewport_bbox.ymin)
- / (priv->window_bbox.ymin - priv->window_bbox.ymax);
+ aY = (priv->viewport_bbox.ymax - priv->viewport_bbox.ymin) /
+ (priv->window_bbox.ymin - priv->window_bbox.ymax);
bY = -aY * priv->window_bbox.ymax + priv->viewport_bbox.ymin;
cairo_matrix_init (&priv->matrix, aX, 0, 0, aY, bX, bY);
@@ -397,7 +394,6 @@ g_plot_expose (GtkWidget* widget, GdkEventExpose* event)
cairo_restore (cr);
cairo_save (cr);
- i = 0;
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
cairo_set_line_width (cr, 1);
@@ -417,7 +413,7 @@ g_plot_expose (GtkWidget* widget, GdkEventExpose* event)
priv->xlabel_unit = get_unit_text (div);
cairo_restore (cr);
- /* Axis Labels */
+ // Axis Labels
if (priv->xlabel) {
char *txt;
if (priv->xlabel_unit == NULL)
@@ -470,8 +466,7 @@ g_plot_expose (GtkWidget* widget, GdkEventExpose* event)
cairo_stroke (cr);
cairo_restore (cr);
}
-
- cairo_destroy (cr);
+ g_list_free_full (lst, g_object_unref);
return FALSE;
}
@@ -510,9 +505,12 @@ g_plot_new ()
GDK_BUTTON1_MOTION_MASK|GDK_BUTTON2_MOTION_MASK|
GDK_BUTTON3_MOTION_MASK);
- g_signal_connect (G_OBJECT (plot), "motion-notify-event", G_CALLBACK(g_plot_motion_cb), plot);
- g_signal_connect (G_OBJECT (plot), "button-press-event", G_CALLBACK(g_plot_button_press_cb), plot);
- g_signal_connect (G_OBJECT (plot), "button-release-event", G_CALLBACK(g_plot_button_release_cb), plot);
+ g_signal_connect (G_OBJECT (plot), "motion-notify-event",
+ G_CALLBACK (g_plot_motion_cb), plot);
+ g_signal_connect (G_OBJECT (plot), "button-press-event",
+ G_CALLBACK (g_plot_button_press_cb), plot);
+ g_signal_connect (G_OBJECT (plot), "button-release-event",
+ G_CALLBACK (g_plot_button_release_cb), plot);
return GTK_WIDGET (plot);
}
@@ -536,8 +534,7 @@ g_plot_motion_cb (GtkWidget *w, GdkEventMotion *e, GPlot *p)
gdouble dx, dy;
cairo_matrix_t t = p->priv->matrix;
GdkCursor *cursor = gdk_cursor_new (GDK_FLEUR);
- gdk_window_set_cursor (w->window, cursor);
- gdk_cursor_destroy (cursor);
+ gdk_window_set_cursor (gtk_widget_get_window (w), cursor);
gdk_flush ();
dx = p->priv->last_x - e->x;
@@ -561,8 +558,7 @@ g_plot_motion_cb (GtkWidget *w, GdkEventMotion *e, GPlot *p)
if ((p->priv->action == ACTION_STARTING_REGION) || (p->priv->action == ACTION_REGION)) {
gdouble dx, dy;
GdkCursor *cursor = gdk_cursor_new (GDK_CROSS);
- gdk_window_set_cursor (w->window, cursor);
- gdk_cursor_destroy (cursor);
+ gdk_window_set_cursor (gtk_widget_get_window (w), cursor);
gdk_flush ();
/* dx < 0 == moving to the left */
@@ -571,12 +567,14 @@ g_plot_motion_cb (GtkWidget *w, GdkEventMotion *e, GPlot *p)
if (dx < 0) {
p->priv->rubberband.xmin = e->x;
- } else {
+ }
+ else {
p->priv->rubberband.xmax = e->x;
}
if (dy < 0) {
p->priv->rubberband.ymin = e->y;
- } else {
+ }
+ else {
p->priv->rubberband.ymax = e->y;
}
@@ -594,8 +592,9 @@ g_plot_button_press_cb (GtkWidget *w, GdkEventButton *e, GPlot *p)
g_return_val_if_fail (IS_GPLOT (p), TRUE);
if (e->type == GDK_2BUTTON_PRESS) {
- /* TODO : Chekck function below cursor and open a property dialog :) */
- } else {
+ /* TODO : Check function below cursor and open a property dialog :) */
+ }
+ else {
switch (p->priv->zoom_mode) {
case GPLOT_ZOOM_INOUT:
if (e->button == 1) {
@@ -623,7 +622,7 @@ g_plot_button_press_cb (GtkWidget *w, GdkEventButton *e, GPlot *p)
static gboolean
g_plot_button_release_cb (GtkWidget *w, GdkEventButton *e, GPlot *p)
{
- gdouble zoom;
+ gdouble zoom = 0.0;
g_return_val_if_fail (IS_GPLOT (p), TRUE);
@@ -644,14 +643,15 @@ g_plot_button_release_cb (GtkWidget *w, GdkEventButton *e, GPlot *p)
p->priv->window_bbox.ymin /= zoom;
p->priv->window_bbox.ymax /= zoom;
gtk_widget_queue_draw (w);
- } else {
- gdk_window_set_cursor (w->window, NULL);
+ }
+ else {
+ gdk_window_set_cursor (gtk_widget_get_window (w), NULL);
gdk_flush ();
}
break;
case GPLOT_ZOOM_REGION:
if ((e->button == 1) && (p->priv->action == ACTION_REGION)) {
- gdk_window_set_cursor (w->window, NULL);
+ gdk_window_set_cursor (gtk_widget_get_window (w), NULL);
gdk_flush ();
{
gdouble x1, y1, x2, y2;
@@ -671,8 +671,9 @@ g_plot_button_release_cb (GtkWidget *w, GdkEventButton *e, GPlot *p)
p->priv->window_bbox.ymin = y2;
p->priv->window_bbox.ymax = y1;
}
- } else if (e->button == 3) {
- gdk_window_set_cursor (w->window, NULL);
+ }
+ else if (e->button == 3) {
+ gdk_window_set_cursor (gtk_widget_get_window (w), NULL);
gdk_flush ();
}
gtk_widget_queue_draw (w);
@@ -708,7 +709,7 @@ g_plot_update_bbox (GPlot *p)
priv = p->priv;
- /* Get functions bbox */
+ // Get functions bbox
priv->window_bbox.xmax = -9999999;
priv->window_bbox.xmin = 9999999;
priv->window_bbox.ymax = -9999999;
@@ -723,6 +724,7 @@ g_plot_update_bbox (GPlot *p)
priv->window_bbox.ymin = MIN (priv->window_bbox.ymin, bbox.ymin);
lst = lst->next;
}
+ g_list_free_full (lst, g_object_unref);
if (priv->window_bbox.xmin == priv->window_bbox.xmax)
priv->window_bbox.xmax += 1;
@@ -762,7 +764,8 @@ g_plot_set_axis_labels (GPlot *p, gchar *x, gchar *y)
p->priv->xlabel = g_strdup (x);
p->priv->bottom_border = BORDER_SIZE + extents.height;
- } else {
+ }
+ else {
p->priv->bottom_border = BORDER_SIZE;
if (p->priv->xlabel) {
g_free (p->priv->xlabel);
@@ -781,7 +784,8 @@ g_plot_set_axis_labels (GPlot *p, gchar *x, gchar *y)
p->priv->left_border = BORDER_SIZE + extents.height;
p->priv->ylabel = g_strdup (y);
- } else {
+ }
+ else {
p->priv->left_border = BORDER_SIZE;
if (p->priv->ylabel) {
g_free (p->priv->ylabel);
@@ -807,6 +811,7 @@ g_plot_clear (GPlot *plot)
g_list_free (plot->priv->functions);
plot->priv->functions = NULL;
plot->priv->window_valid = FALSE;
+ g_list_free (lst);
}
void
@@ -835,5 +840,3 @@ get_order_of_magnitude (gdouble val, gdouble *man, gdouble *pw)
*man = val / sx;
*pw = b;
}
-
-
diff --git a/src/gplot/gplot.h b/src/gplot/gplot.h
index 041a597..a03c31c 100644
--- a/src/gplot/gplot.h
+++ b/src/gplot/gplot.h
@@ -3,9 +3,13 @@
*
* Authors:
* Ricardo Markiewicz <rmarkie@fi.uba.ar>
+ * Marc Lorber <lorber.marc@wanadoo.fr>
+ *
+ * Web page: https://github.com/marc-lorber/oregano
*
* Copyright (C) 1999-2001 Richard Hult
* Copyright (C) 2003,2004 Ricardo Markiewicz
+ * Copyright (C) 2009-2012 Marc Lorber
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -30,32 +34,18 @@
#include <gtk/gtk.h>
#include <glib.h>
-#include "gplotfunction.h"
-
-#define TYPE_GPLOT (g_plot_get_type())
-#define GPLOT(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, TYPE_GPLOT, GPlot)
-#define GPLOT_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, TYPE_GPLOT, GPlotClass)
-#define IS_GPLOT(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, TYPE_GPLOT)
+#define GPLOT(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_GPLOT, GPlot)
+#define IS_GPLOT(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, TYPE_GPLOT)
+#define TYPE_GPLOT (g_plot_get_type())
typedef struct _GPlot GPlot;
-typedef struct _GPlotClass GPlotClass;
-typedef struct _GPlotPriv GPlotPriv;
+typedef struct _GPlotFunction {} GPlotFunction;
enum {
GPLOT_ZOOM_INOUT,
GPLOT_ZOOM_REGION
};
-struct _GPlot {
- GtkLayout parent;
-
- GPlotPriv *priv;
-};
-
-struct _GPlotClass {
- GtkLayoutClass parent_class;
-};
-
GType g_plot_get_type ();
GtkWidget* g_plot_new ();
void g_plot_clear (GPlot *);
@@ -67,4 +57,3 @@ void g_plot_set_axis_labels (GPlot *, gchar *, gchar *);
void g_plot_window_to_device (GPlot *, double *x, double *y);
#endif
-
diff --git a/src/gplot/gplotfunction.c b/src/gplot/gplotfunction.c
index 576aa85..d88de06 100644
--- a/src/gplot/gplotfunction.c
+++ b/src/gplot/gplotfunction.c
@@ -3,9 +3,13 @@
*
* Authors:
* Ricardo Markiewicz <rmarkie@fi.uba.ar>
+ * Marc Lorber <lorber.marc@wanadoo.fr>
+ *
+ * Web page: https://github.com/marc-lorber/oregano
*
* Copyright (C) 1999-2001 Richard Hult
* Copyright (C) 2003,2004 Ricardo Markiewicz
+ * Copyright (C) 2009-2012 Marc Lorber
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -23,6 +27,7 @@
* Boston, MA 02111-1307, USA.
*/
+#include "gplot-internal.h"
#include "gplotfunction.h"
@@ -31,7 +36,7 @@ g_plot_function_base_init (gpointer g_class)
{
static gboolean initialized = FALSE;
if (!initialized) {
- /* create interface signals here. */
+ // create interface signals here.
initialized = TRUE;
g_object_interface_install_property (g_class,
@@ -50,14 +55,14 @@ g_plot_function_get_type (void)
if (type == 0) {
static const GTypeInfo info = {
sizeof (GPlotFunctionClass),
- g_plot_function_base_init, /* base_init */
- NULL, /* base_finalize */
- NULL, /* class_init */
- NULL, /* class_finalize */
- NULL, /* class_data */
+ g_plot_function_base_init, // base_init
+ NULL, // base_finalize
+ NULL, // class_init
+ NULL, // class_finalize
+ NULL, // class_data
0,
- 0, /* n_preallocs */
- NULL /* instance_init */
+ 0, // n_preallocs
+ NULL // instance_init
};
type = g_type_register_static (G_TYPE_INTERFACE, "GPlotFunction", &info, 0);
}
diff --git a/src/gplot/gplotfunction.h b/src/gplot/gplotfunction.h
index 8cbc523..bbd0e2f 100644
--- a/src/gplot/gplotfunction.h
+++ b/src/gplot/gplotfunction.h
@@ -3,9 +3,13 @@
*
* Authors:
* Ricardo Markiewicz <rmarkie@fi.uba.ar>
+ * Marc Lorber <lorber.marc@wanadoo.fr>
*
+ * Web page: https://github.com/marc-lorber/oregano
+ *
* Copyright (C) 1999-2001 Richard Hult
* Copyright (C) 2003,2004 Ricardo Markiewicz
+ * Copyright (C) 2009-2010 Marc Lorber
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -26,19 +30,10 @@
#ifndef _GPLOT_FUNCTION_H_
#define _GPLOT_FUNCTION_H_
-#include <gdk/gdk.h>
#include <gtk/gtk.h>
-#include <glib.h>
-#define TYPE_GPLOT_FUNCTION (g_plot_function_get_type())
-#define GPLOT_FUNCTION(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, TYPE_GPLOT_FUNCTION, GPlotFunction)
-#define GPLOT_FUNCTION_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, TYPE_GPLOT_FUNCTION, GPlotFunctionClass)
-#define IS_GPLOT_FUNCTION (obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, TYPE_GPLOT_FUNCTION)
-#define GPLOT_FUNCTION_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), TYPE_GPLOT_FUNCTION, GPlotFunctionClass))
-/*
-#define MAX(a,b) ((a)>(b)?(a):(b))
-#define MIN(a,b) ((a)<(b)?(a):(b))
-*/
+#define GPLOT_FUNCTION(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_GPLOT_FUNCTION, GPlotFunction)
+#define IS_GPLOT_FUNCTION(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, TYPE_GPLOT_FUNCTION)
typedef struct _GPlotFunctionBBox {
gdouble xmin;
@@ -47,23 +42,9 @@ typedef struct _GPlotFunctionBBox {
gdouble ymax;
} GPlotFunctionBBox;
-typedef struct _GPlotFunction {} GPlotFunction;
-typedef struct _GPlotFunctionClass GPlotFunctionClass;
-
-struct _GPlotFunctionClass {
- GTypeInterface parent;
-
- void (*draw)(GPlotFunction *, cairo_t *, GPlotFunctionBBox *);
- void (*get_bbox)(GPlotFunction *, GPlotFunctionBBox *);
-};
-
-
-GType g_plot_function_get_type ();
void g_plot_function_draw (GPlotFunction *, cairo_t *, GPlotFunctionBBox *);
void g_plot_function_get_bbox (GPlotFunction *, GPlotFunctionBBox *);
void g_plot_function_set_visible (GPlotFunction *, gboolean);
gboolean g_plot_function_get_visible (GPlotFunction *);
#endif
-
-
diff --git a/src/gplot/gplotlines.c b/src/gplot/gplotlines.c
index 5e9743e..9f1bf3e 100644
--- a/src/gplot/gplotlines.c
+++ b/src/gplot/gplotlines.c
@@ -3,9 +3,13 @@
*
* Authors:
* Ricardo Markiewicz <rmarkie@fi.uba.ar>
+ * Marc Lorber <lorber.marc@wanadoo.fr>
+ *
+ * Web page: https://github.com/marc-lorber/oregano
*
* Copyright (C) 1999-2001 Richard Hult
* Copyright (C) 2003,2004 Ricardo Markiewicz
+ * Copyright (C) 2009-2012 Marc Lorber
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -23,16 +27,36 @@
* Boston, MA 02111-1307, USA.
*/
-#include "gplotlines.h"
#include <string.h>
+#include "gplot-internal.h"
+#include "gplotlines.h"
+
+typedef struct _GPlotLines GPlotLines;
+typedef struct _GPlotLinesPriv GPlotLinesPriv;
+typedef struct _GPlotLinesClass GPlotLinesClass;
+
+struct _GPlotLines {
+ GObject parent;
+
+ GPlotLinesPriv *priv;
+};
+
+struct _GPlotLinesClass {
+ GObjectClass parent;
+};
+
+GType g_plot_function_get_type ();
+
static void g_plot_lines_class_init (GPlotLinesClass* class);
static void g_plot_lines_init (GPlotLines* plot);
static void g_plot_lines_draw (GPlotFunction *, cairo_t *, GPlotFunctionBBox *);
static void g_plot_lines_get_bbox (GPlotFunction *, GPlotFunctionBBox *);
static void g_plot_lines_function_init (GPlotFunctionClass *iface);
-static void g_plot_lines_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *spec);
-static void g_plot_lines_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *spec);
+static void g_plot_lines_set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *spec);
+static void g_plot_lines_get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *spec);
static GObjectClass* parent_class = NULL;
@@ -42,6 +66,8 @@ enum {
ARG_COLOR,
ARG_COLOR_GDKCOLOR,
ARG_VISIBLE,
+ ARG_GRAPH_TYPE,
+ ARG_SHIFT
};
struct _GPlotLinesPriv {
@@ -52,18 +78,43 @@ struct _GPlotLinesPriv {
gdouble points;
gboolean visible;
- /** Line width */
+ // Line width
gdouble width;
- /** Line Color */
+ // Line Color
gchar *color_string;
GdkColor color;
+
+ // Graphic type
+ GraphicType graphic_type;
+
+ // Shift for pulse drawings
+ gdouble shift;
};
+#define TYPE_GPLOT_LINES (g_plot_lines_get_type ())
+#define TYPE_GPLOT_GRAPHIC_TYPE (g_plot_lines_graphic_get_type ())
+#define NG_DEBUG(s) if (0) g_print ("%s\n", s)
+
G_DEFINE_TYPE_WITH_CODE (GPlotLines, g_plot_lines, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (TYPE_GPLOT_FUNCTION,
g_plot_lines_function_init));
+GType
+g_plot_lines_graphic_get_type (void)
+{
+ static GType etype = 0;
+ if (etype == 0) {
+ static const GEnumValue values[] = {
+ { FUNCTIONAL_CURVE, "FUNCTIONAL_CURVE", "funct-curve" },
+ { FREQUENCY_PULSE, "FREQUENCY_PULSE", "freq-pulse" },
+ { 0, NULL, NULL }
+ };
+ etype = g_enum_register_static ("GraphicType", values);
+ }
+ return etype;
+}
+
static void
g_plot_lines_function_init (GPlotFunctionClass *iface)
{
@@ -72,13 +123,13 @@ g_plot_lines_function_init (GPlotFunctionClass *iface)
}
static void
-g_plot_lines_dispose(GObject *object)
+g_plot_lines_dispose (GObject *object)
{
- G_OBJECT_CLASS(parent_class)->dispose(object);
+ G_OBJECT_CLASS (parent_class)->dispose(object);
}
static void
-g_plot_lines_finalize(GObject *object)
+g_plot_lines_finalize (GObject *object)
{
GPlotLines *lines;
@@ -91,7 +142,7 @@ g_plot_lines_finalize(GObject *object)
g_free (lines->priv);
}
- G_OBJECT_CLASS(parent_class)->finalize(object);
+ G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
@@ -109,23 +160,26 @@ g_plot_lines_class_init (GPlotLinesClass* class)
g_object_class_override_property (object_class, ARG_VISIBLE, "visible");
- g_object_class_install_property(
- object_class,
- ARG_WIDTH,
+ g_object_class_install_property (object_class, ARG_WIDTH,
g_param_spec_double ("width", "GPlotLines::width",
"the line width", 0.1, 5.0, 1.0, G_PARAM_READWRITE));
- g_object_class_install_property(
- object_class,
- ARG_COLOR,
+ g_object_class_install_property (object_class, ARG_COLOR,
g_param_spec_string ("color", "GPlotLines::color",
"the string color line", "white", G_PARAM_READWRITE));
- g_object_class_install_property(
- object_class,
- ARG_COLOR_GDKCOLOR,
+ g_object_class_install_property (object_class, ARG_COLOR_GDKCOLOR,
g_param_spec_pointer ("color-rgb", "GPlotLines::color-rgb",
"the GdkColor of the line", G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class, ARG_GRAPH_TYPE,
+ g_param_spec_enum ("graph-type", "GPlotLines::graph-type",
+ "the type of graphic", TYPE_GPLOT_GRAPHIC_TYPE,
+ FUNCTIONAL_CURVE, G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class, ARG_SHIFT,
+ g_param_spec_double ("shift", "GPlotLines::shift",
+ "the shift for multiple pulses", 0.0, 500.0, 50.0, G_PARAM_READWRITE));
}
static void
@@ -144,7 +198,7 @@ g_plot_lines_init (GPlotLines* plot)
}
static void
-g_plot_lines_set_property(GObject *object, guint prop_id, const GValue *value,
+g_plot_lines_set_property (GObject *object, guint prop_id, const GValue *value,
GParamSpec *spec)
{
GPlotLines *plot = GPLOT_LINES (object);
@@ -161,18 +215,19 @@ g_plot_lines_set_property(GObject *object, guint prop_id, const GValue *value,
plot->priv->color_string = g_strdup (g_value_get_string (value));
gdk_color_parse (plot->priv->color_string, &plot->priv->color);
break;
- case ARG_COLOR_GDKCOLOR:
- //s = g_value_get_string (value)
- //gdk_color_parse (s, &plot->priv->color);
+ case ARG_GRAPH_TYPE:
+ plot->priv->graphic_type = g_value_get_enum (value);
+ break;
+ case ARG_SHIFT:
+ plot->priv->shift = g_value_get_double (value);
break;
default:
break;
}
}
-
static void
-g_plot_lines_get_property(GObject *object, guint prop_id, GValue *value,
+g_plot_lines_get_property (GObject *object, guint prop_id, GValue *value,
GParamSpec *spec)
{
GPlotLines *plot = GPLOT_LINES (object);
@@ -187,6 +242,12 @@ g_plot_lines_get_property(GObject *object, guint prop_id, GValue *value,
case ARG_COLOR:
g_value_set_string (value, plot->priv->color_string);
break;
+ case ARG_GRAPH_TYPE:
+ g_value_set_enum (value, plot->priv->graphic_type);
+ break;
+ case ARG_SHIFT:
+ g_value_set_double (value, plot->priv->shift);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (plot, prop_id, spec);
}
@@ -214,7 +275,7 @@ g_plot_lines_get_bbox (GPlotFunction *f, GPlotFunctionBBox *bbox)
plot = GPLOT_LINES (f);
if (!plot->priv->bbox_valid) {
- /* Update bbox */
+ // Update bbox
guint point;
gdouble *x;
gdouble *y;
@@ -228,10 +289,10 @@ g_plot_lines_get_bbox (GPlotFunction *f, GPlotFunctionBBox *bbox)
plot->priv->bbox.ymin = 99999999;
plot->priv->bbox.ymax = -99999999;
for (point = 0; point < points; point++) {
- plot->priv->bbox.xmin = MIN(plot->priv->bbox.xmin, x[point]);
- plot->priv->bbox.ymin = MIN(plot->priv->bbox.ymin, y[point]);
- plot->priv->bbox.xmax = MAX(plot->priv->bbox.xmax, x[point]);
- plot->priv->bbox.ymax = MAX(plot->priv->bbox.ymax, y[point]);
+ plot->priv->bbox.xmin = MIN (plot->priv->bbox.xmin, x[point]);
+ plot->priv->bbox.ymin = MIN (plot->priv->bbox.ymin, y[point]);
+ plot->priv->bbox.xmax = MAX (plot->priv->bbox.xmax, x[point]);
+ plot->priv->bbox.ymax = MAX (plot->priv->bbox.ymax, y[point]);
}
plot->priv->bbox_valid = TRUE;
}
@@ -239,13 +300,16 @@ g_plot_lines_get_bbox (GPlotFunction *f, GPlotFunctionBBox *bbox)
(*bbox) = plot->priv->bbox;
}
+
+// This procedure is in charge to link points with ligne.
+// Modified to only draw spectral ray for Fourier analysis.
static void
g_plot_lines_draw (GPlotFunction *f, cairo_t *cr, GPlotFunctionBBox *bbox)
{
gboolean first_point = TRUE;
guint point;
- gdouble *x;
- gdouble *y;
+ gdouble *x, x1;
+ gdouble *y, y1;
guint points;
GPlotLines *plot;
@@ -259,24 +323,36 @@ g_plot_lines_draw (GPlotFunction *f, cairo_t *cr, GPlotFunctionBBox *bbox)
x = plot->priv->x;
y = plot->priv->y;
- for (point = 1; point < points; point++) {
- if ((x[point] >= bbox->xmin) && (x[point] <= bbox->xmax) &&
- (y[point] >= bbox->ymin) && (y[point] <= bbox->ymax)) {
+ if (plot->priv->graphic_type == FUNCTIONAL_CURVE) {
+ for (point = 1; point < points; point++) {
+ if ((x[point] >= bbox->xmin) && (x[point] <= bbox->xmax) &&
+ (y[point] >= bbox->ymin) && (y[point] <= bbox->ymax)) {
- if (first_point) {
- cairo_move_to (cr, x[point-1], y[point-1]);
- first_point = FALSE;
- }
+ if (first_point) {
+ cairo_move_to (cr, x[point-1], y[point-1]);
+ first_point = FALSE;
+ }
- cairo_line_to (cr, x[point], y[point]);
- } else {
- if (!first_point) {
cairo_line_to (cr, x[point], y[point]);
- first_point = TRUE;
+ }
+ else {
+ if (!first_point) {
+ cairo_line_to (cr, x[point], y[point]);
+ first_point = TRUE;
+ }
}
}
+ }
+ else {
+ for (point = 1; point < points; point++) {
+ x1 = x[point-1]+plot->priv->shift;
+ y1 = 0;
+ NG_DEBUG (g_strdup_printf ("gplotlines: x= %lf\ty= %lf\n", x1, y1));
+ cairo_line_to (cr, x1, y1);
+ cairo_move_to (cr, x[point]+ plot->priv->shift, y[point]);
+ }
+
}
-
if (point < points) {
cairo_line_to (cr, x[point], y[point]);
}
@@ -291,4 +367,3 @@ g_plot_lines_draw (GPlotFunction *f, cairo_t *cr, GPlotFunctionBBox *bbox)
cairo_stroke (cr);
cairo_restore (cr);
}
-
diff --git a/src/gplot/gplotlines.h b/src/gplot/gplotlines.h
index c3dafb2..56450af 100644
--- a/src/gplot/gplotlines.h
+++ b/src/gplot/gplotlines.h
@@ -3,9 +3,13 @@
*
* Authors:
* Ricardo Markiewicz <rmarkie@fi.uba.ar>
+ * Marc Lorber <lorber.marc@wanadoo.fr>
+ *
+ * Web page: https://github.com/marc-lorber/oregano
*
* Copyright (C) 1999-2001 Richard Hult
* Copyright (C) 2003,2004 Ricardo Markiewicz
+ * Copyright (C) 2009-2012 Marc Lorber
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -28,28 +32,15 @@
#include "gplotfunction.h"
-#define TYPE_GPLOT_LINES (g_plot_lines_get_type())
-#define GPLOT_LINES(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, TYPE_GPLOT_LINES, GPlotLines)
-#define GPLOT_LINES_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, TYPE_GPLOT_LINES, GPlotLinesClass)
-#define IS_GPLOT_LINES(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, TYPE_GPLOT_LINES)
-typedef struct _GPlotLines GPlotLines;
-typedef struct _GPlotLinesPriv GPlotLinesPriv;
-typedef struct _GPlotLinesClass GPlotLinesClass;
+typedef enum {
+ FUNCTIONAL_CURVE=0,
+ FREQUENCY_PULSE
+} GraphicType;
-struct _GPlotLines {
- GObject parent;
+#define GPLOT_LINES(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_GPLOT_LINES, GPlotLines)
+#define IS_GPLOT_LINES(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, TYPE_GPLOT_LINES)
- GPlotLinesPriv *priv;
-};
-
-struct _GPlotLinesClass {
- GObjectClass parent;
-};
-
-GType g_plot_lines_get_type ();
GPlotFunction* g_plot_lines_new (gdouble *x, gdouble *y, guint points);
#endif
-
-