Permalink
Browse files

Added inheritance structure

  • Loading branch information...
1 parent 01bf74c commit fced77fc3224abba6ac50f725c4797f3a6a1c4b1 @pchilds committed Sep 11, 2012
View
@@ -5,17 +5,19 @@ gtkplot_libincludedir=$(libdir)/gtkplot-2.0/include
nodist_gtkplot_libinclude_HEADERS=../gtkplotconfig.h
lib_LTLIBRARIES=libgtkplot-@PLOT_API_VERSION@.la
-libgtkplot_@PLOT_API_VERSION@_la_SOURCES= \
- gtkplotlinear.c \
+libgtkplot_@PLOT_API_VERSION@_la_SOURCES= \
+ gtkplot.c \
+ gtkplotlinear.c \
gtkplotpolar.c
-libgtkplot_@PLOT_API_VERSION@_la_LDFLAGS= \
- @lt_enable_auto_import@ \
- -no-undefined \
- -version-info 0:0:0 \
+libgtkplot_@PLOT_API_VERSION@_la_LDFLAGS= \
+ @lt_enable_auto_import@ \
+ -no-undefined \
+ -version-info 0:0:0 \
$(PLOT_LIBS)
gtkplotincludedir=$(includedir)/gtkplot-2.0
-gtkplotinclude_HEADERS= \
- gtkplotlinear.h \
+gtkplotinclude_HEADERS= \
+ gtkplot.h \
+ gtkplotlinear.h \
gtkplotpolar.h
bin_PROGRAMS=TestPlotLinear TestPlotPolar
View
@@ -0,0 +1,121 @@
+/***************************************************************************
+ * gtkplot.c
+ *
+ * A GTK+ widget that plots data on polar axes
+ * version 0.1.0
+ * Features:
+ * optimal visualisation of axes
+ * zoomable ranges
+ * signal emission for mouse movement
+ *
+ * Sat Dec 4 17:18:14 2010
+ * Copyright 2011 Paul Childs
+ * <pchilds@physics.org>
+ ****************************************************************************/
+
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
+ */
+
+#include <gtk/gtk.h>
+#include "gtkplot.h"
+
+G_DEFINE_TYPE (GtkPlot, gtk_plot, GTK_TYPE_DRAWING_AREA);
+
+void gtk_plot_set_font(GtkPlot *plot, PangoFontDescription *lf, PangoFontDescription *af)
+{
+ if (plot->afont) pango_font_description_free(plot->afont);
+ if (plot->lfont) pango_font_description_free(plot->lfont);
+ {(plot->afont)=pango_font_description_copy(af); (plot->lfont)=pango_font_description_copy(lf);}
+}
+
+void gtk_plot_set_colour(GtkPlot *plot, GArray *rd, GArray *gr, GArray *bl, GArray *al)
+{
+ if (plot->rd) g_array_free((plot->rd), FALSE);
+ if (plot->gr) g_array_free((plot->gr), FALSE);
+ if (plot->bl) g_array_free((plot->bl), FALSE);
+ if (plot->al) g_array_free((plot->al), FALSE);
+ {(plot->rd)=g_array_ref(rd); (plot->gr)=g_array_ref(gr); (plot->bl)=g_array_ref(bl); (plot->al)=g_array_ref(al);}
+}
+
+static void gtk_plot_finalise(GtkPlot *plot)
+{
+ if (plot->afont) pango_font_description_free(plot->afont);
+ if (plot->lfont) pango_font_description_free(plot->lfont);
+ if (plot->rd) g_array_free((plot->rd), FALSE);
+ if (plot->gr) g_array_free((plot->gr), FALSE);
+ if (plot->bl) g_array_free((plot->bl), FALSE);
+ if (plot->al) g_array_free((plot->al), FALSE);
+}
+
+static void gtk_plot_class_init(GtkPlotClass *klass)
+{
+ GObjectClass *obj_klass;
+ GtkWidgetClass *widget_klass;
+
+ obj_klass=G_OBJECT_CLASS(klass);
+ (obj_klass->finalize)=(GObjectFinalizeFunc) gtk_plot_finalise;
+}
+
+static void gtk_plot_init(GtkPlot *plot)
+{
+ gdouble val;
+
+ {(plot->afont)=pango_font_description_new(); (plot->lfont)=pango_font_description_new();}
+ {pango_font_description_set_family((plot->afont), "sans"); pango_font_description_set_family((plot->lfont), "sans");}
+ {pango_font_description_set_style((plot->afont), PANGO_STYLE_NORMAL); pango_font_description_set_style((plot->lfont), PANGO_STYLE_NORMAL);}
+ {pango_font_description_set_size((plot->afont), 12*PANGO_SCALE); pango_font_description_set_size((plot->lfont), 12*PANGO_SCALE);}
+ (plot->rd)=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 10);
+ (plot->gr)=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 10);
+ (plot->bl)=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 10);
+ (plot->al)=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 10);
+ val=0;
+ g_array_append_val((plot->rd), val);
+ g_array_append_val((plot->gr), val);
+ g_array_append_val((plot->bl), val);
+ g_array_append_val((plot->gr), val);
+ g_array_append_val((plot->bl), val);
+ g_array_append_val((plot->bl), val);
+ val=1;
+ g_array_append_val((plot->rd), val);
+ g_array_append_val((plot->gr), val);
+ g_array_append_val((plot->bl), val);
+ val=0;
+ g_array_append_val((plot->rd), val);
+ g_array_append_val((plot->gr), val);
+ g_array_append_val((plot->bl), val);
+ g_array_append_val((plot->rd), val);
+ val=1.0;
+ g_array_append_val((plot->gr), val);
+ g_array_append_val((plot->bl), val);
+ g_array_append_val((plot->rd), val);
+ g_array_append_val((plot->gr), val);
+ g_array_append_val((plot->bl), val);
+ val=0;
+ g_array_append_val((plot->rd), val);
+ g_array_append_val((plot->gr), val);
+ val=1;
+ g_array_append_val((plot->rd), val);
+ val=0.8;
+ g_array_append_val((plot->al), val);
+ g_array_append_val((plot->al), val);
+ g_array_append_val((plot->al), val);
+ g_array_append_val((plot->al), val);
+ g_array_append_val((plot->al), val);
+ g_array_append_val((plot->al), val);
+ g_array_append_val((plot->al), val);
+}
+
+GtkWidget *gtk_plot_new(void) {return g_object_new(GTK_TYPE_PLOT, NULL);}
View
@@ -0,0 +1,53 @@
+/***************************************************************************
+ * gtkplot.h
+ *
+ * A GTK+ base class for data plotting
+ *
+ * Sat Dec 4 17:18:14 2010
+ * Copyright 2011 Paul Childs
+ * <pchilds@physics.org>
+ ****************************************************************************/
+
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
+ */
+
+#ifndef __GTK_PLOT_H__
+# define __GTK_PLOT_H__
+# include <gtk/gtk.h>
+ G_BEGIN_DECLS
+# define GTK_TYPE_PLOT (gtk_plot_get_type())
+# define GTK_PLOT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_PLOT, GtkPlot))
+# define GTK_IS_PLOT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_PLOT))
+# define GTK_PLOT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTK_PLOT, GtkPlotClass))
+# define GTK_IS_PLOT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_PLOT))
+# define GTK_PLOT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_PLOT, GtkPlotClass))
+ typedef struct _GtkPlot GtkPlot;
+ typedef struct _GtkPlotClass GtkPlotClass;
+ struct _GtkPlot
+ {
+ GtkDrawingArea parent;
+ GArray *rd, *gr, *bl, *al; /* colour and alpha of the plots */
+ PangoFontDescription *afont, *lfont; /* font descriptions for the tick mark and axis labels */
+ };
+ struct _GtkPlotClass
+ {
+ GtkDrawingAreaClass parent_class;
+ };
+ void gtk_plot_set_font(GtkPlot *plot, PangoFontDescription *lf, PangoFontDescription *af);
+ void gtk_plot_set_colour(GtkPlot *plot, GArray *rd, GArray *gr, GArray *bl, GArray *al);
+ GtkWidget *gtk_plot_new(void);
+ G_END_DECLS
+#endif
Oops, something went wrong.

0 comments on commit fced77f

Please sign in to comment.