2 * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @short_description: Single point lines
22 * Each #GritsLine represents a 3 dimentional line.
27 #include "grits-line.h"
30 static void grits_line_trace(guint mode, gdouble (**points)[3])
32 //g_debug("GritsLine: outline");
33 for (int pi = 0; points[pi]; pi++) {
35 for (int ci = 0; points[pi][ci][0] &&
37 points[pi][ci][2]; ci++)
38 glVertex3dv(points[pi][ci]);
43 static void grits_line_draw(GritsObject *_poly, GritsOpenGL *opengl)
45 //g_debug("GritsLine: draw");
46 GritsLine *line = GRITS_LINE(_poly);
48 glPushAttrib(GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT |
49 GL_POINT_BIT | GL_LINE_BIT | GL_POLYGON_BIT);
51 glDisable(GL_TEXTURE_2D);
52 glDisable(GL_ALPHA_TEST);
53 glDisable(GL_CULL_FACE);
54 glDisable(GL_LIGHTING);
56 glEnable(GL_LINE_SMOOTH);
57 glEnable(GL_POINT_SMOOTH);
59 glColor4dv(line->color);
61 glPointSize(line->width);
62 glLineWidth(line->width);
65 grits_line_trace(GL_POINTS, line->points);
66 grits_line_trace(GL_LINE_STRIP, line->points);
76 * Create a new GritsLine which TODO.
78 * Returns: the new #GritsLine.
80 GritsLine *grits_line_new(gdouble (**points)[3])
82 //g_debug("GritsLine: new - %p", points);
83 GritsLine *line = g_object_new(GRITS_TYPE_LINE, NULL);
84 line->points = points;
88 GritsLine *grits_line_parse(const gchar *str,
89 const gchar *line_sep, const gchar *point_sep, const gchar *coord_sep)
92 gdouble (**lines)[3] = parse_points(str,
93 line_sep, point_sep, coord_sep, NULL, ¢er);
95 GritsLine *line = grits_line_new(lines);
96 GRITS_OBJECT(line)->center = center;
97 GRITS_OBJECT(line)->skip = GRITS_SKIP_CENTER;
98 g_object_weak_ref(G_OBJECT(line), (GWeakNotify)free_points, lines);
103 G_DEFINE_TYPE(GritsLine, grits_line, GRITS_TYPE_OBJECT);
104 static void grits_line_init(GritsLine *line)
109 line->color[3] = 0.2;
111 GRITS_OBJECT(line)->skip = GRITS_SKIP_STATE;
114 static void grits_line_finalize(GObject *_line)
116 //g_debug("GritsLine: finalize");
117 GritsLine *line = GRITS_LINE(_line);
121 static void grits_line_class_init(GritsLineClass *klass)
123 g_debug("GritsLine: class_init");
124 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
125 gobject_class->finalize = grits_line_finalize;
127 GritsObjectClass *object_class = GRITS_OBJECT_CLASS(klass);
128 object_class->draw = grits_line_draw;
129 //object_class->pick = grits_line_pick;