GritsLine is similar to GritsPoly, but does not draw a filled polygon.
As such it does not need to do any tessellation.
Currently it draws the points directly instead of using a display list.
This should make it easier to updated the line at runtime without
needing to create a new object.
#include <objects/grits-callback.h>
#include <objects/grits-volume.h>
#include <objects/grits-poly.h>
+#include <objects/grits-line.h>
/* Plugins */
#include <grits-plugin.h>
grits-tile.h \
grits-volume.h \
grits-poly.h \
+ grits-line.h \
marching.h
noinst_LTLIBRARIES = libgrits-objects.la
grits-tile.c grits-tile.h \
grits-volume.c grits-volume.h \
grits-poly.c grits-poly.h \
+ grits-line.c grits-line.h \
marching.c marching.h
libgrits_objects_la_LDFLAGS = -static
--- /dev/null
+/*
+ * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
+ *
+ * This program 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 3 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 program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * SECTION:grits-line
+ * @short_description: Single point lines
+ *
+ * Each #GritsLine represents a 3 dimentional line.
+ */
+
+#include <config.h>
+#include "gtkgl.h"
+#include "grits-line.h"
+
+/* Drawing */
+static void grits_line_trace(guint mode, gdouble (**points)[3])
+{
+ //g_debug("GritsLine: outline");
+ for (int pi = 0; points[pi]; pi++) {
+ glBegin(mode);
+ for (int ci = 0; points[pi][ci][0] &&
+ points[pi][ci][1] &&
+ points[pi][ci][2]; ci++)
+ glVertex3dv(points[pi][ci]);
+ glEnd();
+ }
+}
+
+static void grits_line_draw(GritsObject *_poly, GritsOpenGL *opengl)
+{
+ //g_debug("GritsLine: draw");
+ GritsLine *line = GRITS_LINE(_poly);
+
+ glPushAttrib(GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT |
+ GL_POINT_BIT | GL_LINE_BIT | GL_POLYGON_BIT);
+
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_ALPHA_TEST);
+ glDisable(GL_CULL_FACE);
+ glDisable(GL_LIGHTING);
+
+ glEnable(GL_LINE_SMOOTH);
+ glEnable(GL_POINT_SMOOTH);
+
+ glColor4dv(line->color);
+
+ glPointSize(line->width);
+ glLineWidth(line->width);
+
+ if (line->width > 1)
+ grits_line_trace(GL_POINTS, line->points);
+ grits_line_trace(GL_LINE_STRIP, line->points);
+
+ glPopAttrib();
+}
+
+/**
+ * grits_line_new:
+ * @points: TODO
+ * @npoints: TODO
+ *
+ * Create a new GritsLine which TODO.
+ *
+ * Returns: the new #GritsLine.
+ */
+GritsLine *grits_line_new(gdouble (**points)[3])
+{
+ //g_debug("GritsLine: new - %p", points);
+ GritsLine *line = g_object_new(GRITS_TYPE_LINE, NULL);
+ line->points = points;
+ return line;
+}
+
+GritsLine *grits_line_parse(const gchar *str,
+ const gchar *line_sep, const gchar *point_sep, const gchar *coord_sep)
+{
+ GritsPoint center;
+ gdouble (**lines)[3] = parse_points(str,
+ line_sep, point_sep, coord_sep, NULL, ¢er);
+
+ GritsLine *line = grits_line_new(lines);
+ GRITS_OBJECT(line)->center = center;
+ GRITS_OBJECT(line)->skip = GRITS_SKIP_CENTER;
+ g_object_weak_ref(G_OBJECT(line), (GWeakNotify)free_points, lines);
+ return line;
+}
+
+/* GObject code */
+G_DEFINE_TYPE(GritsLine, grits_line, GRITS_TYPE_OBJECT);
+static void grits_line_init(GritsLine *line)
+{
+ line->color[0] = 1;
+ line->color[1] = 1;
+ line->color[2] = 1;
+ line->color[3] = 0.2;
+ line->width = 1;
+ GRITS_OBJECT(line)->skip = GRITS_SKIP_STATE;
+}
+
+static void grits_line_finalize(GObject *_line)
+{
+ //g_debug("GritsLine: finalize");
+ GritsLine *line = GRITS_LINE(_line);
+ (void)line;
+}
+
+static void grits_line_class_init(GritsLineClass *klass)
+{
+ g_debug("GritsLine: class_init");
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+ gobject_class->finalize = grits_line_finalize;
+
+ GritsObjectClass *object_class = GRITS_OBJECT_CLASS(klass);
+ object_class->draw = grits_line_draw;
+ //object_class->pick = grits_line_pick;
+}
--- /dev/null
+/*
+ * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
+ *
+ * This program 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 3 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 program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GRITS_LINE_H__
+#define __GRITS_LINE_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <cairo.h>
+#include <objects/grits-object.h>
+
+/* GritsLine */
+#define GRITS_TYPE_LINE (grits_line_get_type())
+#define GRITS_LINE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GRITS_TYPE_LINE, GritsLine))
+#define GRITS_IS_LINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GRITS_TYPE_LINE))
+#define GRITS_LINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GRITS_TYPE_LINE, GritsLineClass))
+#define GRITS_IS_LINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GRITS_TYPE_LINE))
+#define GRITS_LINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GRITS_TYPE_LINE, GritsLineClass))
+
+typedef struct _GritsLine GritsLine;
+typedef struct _GritsLineClass GritsLineClass;
+
+struct _GritsLine {
+ GritsObject parent_instance;
+ gdouble (**points)[3];
+ gdouble color[4];
+ gdouble width;
+};
+
+struct _GritsLineClass {
+ GritsObjectClass parent_class;
+};
+
+GType grits_line_get_type(void);
+
+GritsLine *grits_line_new(gdouble (**points)[3]);
+
+GritsLine *grits_line_parse(const gchar *str,
+ const gchar *line_sep, const gchar *point_sep, const gchar *coord_sep);
+
+#endif
g_signal_connect(test->poly, "key-press", G_CALLBACK(on_poly_key), NULL);
}
+void _load_line(GritsPluginTest *test)
+{
+ test->line = grits_line_parse("30,-80 30,-120 50,-120 50,-80", "\t", " ", ",");
+ test->line->color[0] = 1;
+ test->line->color[1] = 0;
+ test->line->color[2] = 0;
+ test->line->color[3] = 1;
+ test->line->width = 8;
+ grits_viewer_add(test->viewer, GRITS_OBJECT(test->line), GRITS_LEVEL_OVERLAY, TRUE);
+ g_signal_connect(test->line, "enter", G_CALLBACK(on_poly_enter), NULL);
+ g_signal_connect(test->line, "leave", G_CALLBACK(on_poly_leave), NULL);
+ g_signal_connect(test->line, "button-press", G_CALLBACK(on_poly_button), NULL);
+ g_signal_connect(test->line, "key-press", G_CALLBACK(on_poly_key), NULL);
+}
+
/**
* grits_plugin_test_new:
* @viewer: the #GritsViewer to use for drawing
test->viewer = g_object_ref(viewer);
_load_marker(test);
_load_poly(test);
+ _load_line(test);
return test;
}
GritsViewer *viewer;
GritsMarker *marker;
GritsPoly *poly;
+ GritsLine *line;
};
struct _GritsPluginTestClass {