atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
glyph.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'glyph.c'
24*
25* Contains:
26*
27
28 - Functions to draw the glyphs
29
30*
31* List of functions:
32
33 void draw_poly (cairo_t * to, double x, double y, double size, double step, double initp);
34 void draw_glyph (cairo_t * in, int theglyph, double x, double y, ColRGBA gcolor, double size);
35
36*/
37
38#include <cairo.h>
39#include <math.h>
40
41#include "global.h"
42#include "curve.h"
43
56void draw_poly (cairo_t * to, double x, double y, double size, double step, double initp)
57{
58 double px, py;
59 double alpha;
60 double astep;
61 double astart;
62
63 astart = 2*pi / initp;
64 px = x + size * cos (astart);
65 py = y + size * sin (astart);
66 astep = 2 * pi / step;
67 cairo_move_to (to, px, py);
68 for (alpha =0.0 ; alpha <= 2*pi ; alpha += astep)
69 {
70 px = x + size * cos (astart + alpha);
71 py = y + size *sin (astart + alpha);
72 cairo_line_to (to, px, py);
73 }
74}
75
88void draw_glyph (cairo_t * in, int theglyph, double x, double y, ColRGBA gcolor, double size)
89{
90 double step;
91 double start;
92 double width;
93 double cdash[3];
94 double offset;
95 int dcount;
96 int idglyph;
97 double starttab[] = {1.0, 4.0, 2.0, 1.33333};
98
99 dcount = cairo_get_dash_count (in);
100 cairo_get_dash (in, cdash, & offset);
101 cairo_set_dash (in, dashed1, len1, 0.0);
102 width = cairo_get_line_width (in);
103 cairo_set_line_width (in, 1.0);
104 cairo_set_source_rgba (in, gcolor.red, gcolor.green, gcolor.blue, 1.0);
105 if (theglyph == 1)
106 {
107 cairo_move_to (in, x + size/2.0, y - size/2.0);
108 cairo_line_to (in, x - size/2.0, y + size/2.0);
109 cairo_move_to (in, x + size/2.0, y + size/2.0);
110 cairo_line_to (in, x - size/2.0, y - size/2.0);
111 cairo_stroke (in);
112 }
113 if (theglyph > 1 && theglyph < 7)
114 {
115 cairo_move_to (in, x, y);
116 cairo_rectangle (in, x - size/2.0, y - size/2.0, size, size);
117 if (theglyph == 2)
118 {
119 cairo_fill(in);
120 }
121 else if (theglyph == 3)
122 {
123 cairo_stroke (in);
124 cairo_set_source_rgba (in, gcolor.red, gcolor.green, gcolor.blue, 0.25);
125 cairo_move_to (in, x, y);
126 cairo_rectangle (in, x - size/2.0, y - size/2.0, size, size);
127 cairo_fill (in);
128 }
129 else if (theglyph == 4)
130 {
131 cairo_stroke (in);
132 cairo_set_source_rgba (in, 1.0, 1.0, 1.0, 1.0);
133 cairo_move_to (in, x, y);
134 cairo_rectangle (in, x - size/2.0, y - size/2.0, size, size);
135 cairo_fill (in);
136 cairo_stroke (in);
137 cairo_set_source_rgba (in, gcolor.red, gcolor.green, gcolor.blue, 0.25);
138 cairo_move_to (in, x, y);
139 cairo_rectangle (in, x - size/2.0, y - size/2.0, size, size);
140 cairo_fill (in);
141 }
142 else if (theglyph == 5)
143 {
144 cairo_stroke (in);
145 cairo_set_source_rgba (in, 1.0, 1.0, 1.0, 1.0);
146 cairo_move_to (in, x, y);
147 cairo_rectangle (in, x - size/2.0, y - size/2.0, size, size);
148 cairo_fill (in);
149 }
150 cairo_stroke (in);
151 }
152 else if (theglyph >= 7 && theglyph < 12)
153 {
154 step = 4.0;
155 start = 1.0;
156 draw_poly (in, x, y, size, step, start);
157 if (theglyph == 7)
158 {
159 cairo_fill(in);
160 }
161 else if (theglyph == 8)
162 {
163 cairo_stroke (in);
164 cairo_set_source_rgba (in, gcolor.red, gcolor.green, gcolor.blue, 0.25);
165 draw_poly (in, x, y, size, step, start);
166 cairo_fill (in);
167 }
168 else if (theglyph == 9)
169 {
170 cairo_stroke (in);
171 cairo_set_source_rgba (in, 1.0, 1.0, 1.0, 1.0);
172 draw_poly (in, x, y, size, step, start);
173 cairo_fill (in);
174 cairo_stroke (in);
175 cairo_set_source_rgba (in, gcolor.red, gcolor.green, gcolor.blue, 0.25);
176 draw_poly (in, x, y, size, step, start);
177 cairo_fill (in);
178 }
179 else if (theglyph == 10)
180 {
181 cairo_stroke (in);
182 cairo_set_source_rgba (in, 1.0, 1.0, 1.0, 1.0);
183 draw_poly (in, x, y, size, step, start);
184 cairo_fill (in);
185 }
186 cairo_stroke (in);
187 }
188 else if (theglyph >= 12 && theglyph < 17)
189 {
190 cairo_arc (in, x, y, size, 0.0, 2*pi);
191 if (theglyph == 12)
192 {
193 cairo_fill(in);
194 }
195 else if (theglyph == 13)
196 {
197 cairo_stroke (in);
198 cairo_set_source_rgba (in, gcolor.red, gcolor.green, gcolor.blue, 0.25);
199 cairo_arc (in, x, y, size, 0.0, 2*pi);
200 cairo_fill (in);
201 }
202 else if (theglyph == 14)
203 {
204 cairo_stroke (in);
205 cairo_set_source_rgba (in, 1.0, 1.0, 1.0, 1.0);
206 cairo_arc (in, x, y, size, 0.0, 2*pi);
207 cairo_fill (in);
208 cairo_stroke (in);
209 cairo_set_source_rgba (in, gcolor.red, gcolor.green, gcolor.blue, 0.25);
210 cairo_arc (in, x, y, size, 0.0, 2*pi);
211 cairo_fill (in);
212 }
213 else if (theglyph == 15)
214 {
215 cairo_stroke (in);
216 cairo_set_source_rgba (in, 1.0, 1.0, 1.0, 1.0);
217 cairo_arc (in, x, y, size, 0.0, 2*pi);
218 cairo_fill (in);
219 }
220 cairo_stroke (in);
221 }
222 else if (theglyph > 16)
223 {
224 step = 3.0;
225 idglyph = (theglyph - 17) / 5;
226 start = starttab[idglyph];
227 draw_poly (in, x, y, size, step, start);
228 if (theglyph == 18 + idglyph*5)
229 {
230 cairo_fill(in);
231 }
232 else if (theglyph == 19 + idglyph*5)
233 {
234 cairo_stroke (in);
235 cairo_set_source_rgba (in, gcolor.red, gcolor.green, gcolor.blue, 0.25);
236 draw_poly (in, x, y, size, step, start);
237 cairo_fill (in);
238 }
239 else if (theglyph == 20 + idglyph*5)
240 {
241 cairo_stroke (in);
242 cairo_set_source_rgba (in, 1.0, 1.0, 1.0, 1.0);
243 draw_poly (in, x, y, size, step, start);
244 cairo_fill (in);
245 cairo_stroke (in);
246 cairo_set_source_rgba (in, gcolor.red, gcolor.green, gcolor.blue, 0.25);
247 draw_poly (in, x, y, size, step, start);
248 cairo_fill (in);
249 }
250 else if (theglyph == 21 + idglyph*5)
251 {
252 cairo_stroke (in);
253 cairo_set_source_rgba (in, 1.0, 1.0, 1.0, 1.0);
254 draw_poly (in, x, y, size, step, start);
255 cairo_fill (in);
256 }
257 cairo_stroke (in);
258 }
259 cairo_set_dash (in, cdash, dcount, offset);
260 cairo_set_source_rgba (in, gcolor.red, gcolor.green, gcolor.blue, 1.0);
261 cairo_set_line_width (in, width);
262}
263
const double dashed1[]
Definition curve.c:97
int len1
Definition curve.c:98
Variable declarations for the curve widget Functions for interactions with the curve widget.
double pi
Definition global.c:195
Global variable declarations Global convenience function declarations Global data structure defin...
int step
Definition ogl_draw.c:70
void draw_poly(cairo_t *to, double x, double y, double size, double step, double initp)
draw polyhedra glyph
Definition glyph.c:56
void draw_glyph(cairo_t *in, int theglyph, double x, double y, ColRGBA gcolor, double size)
draw glyph at (x,y)
Definition glyph.c:88
double y
Definition ogl_draw.c:57
double x
Definition ogl_draw.c:57
float blue
Definition global.h:118
float red
Definition global.h:116
float green
Definition global.h:117