Update zodat ik PPC kan scheiden. Verder wat overige GUI abstracties.
[sgc.git] / cairo.c
blob8e625c6cd5baff7993fbf7d5b11583e0e66f3087
1 #include "sgc.h"
3 void drawPitchTier(cairo_t *cr, gchar *filename, gint width, gint height, gdouble top) {
4 gchar *contents;
5 GError *error = NULL;
6 gsize length;
7 g_debug("%s welcomes %s!", __func__, filename);
8 if (g_file_get_contents(filename, &contents, &length, &error) != TRUE) {
9 // g_warning("HET PROBLEEM ZIT IN HET INLEZEN VAN HET %s BESTAND!!!!!\n", filename);
10 g_warning("%s\n", error->message);
11 g_error_free(error);
12 } else {
13 gdouble scalex = 0, scaley = 0;
14 gdouble fromx = 0;
15 gdouble middlex = 0;
16 gdouble endx = 0;
17 gdouble fromy = 0;
18 gdouble middley = 0;
19 gsize i = 0;
20 gsize j = 0;
21 gsize m = 0;
22 int pointloc = 0;
23 while (i < length) {
24 if (contents[i] == '\n') {
25 gchar * this = g_strndup(&contents[m], i-m);
26 switch ( j ) {
27 case 0:
28 case 1:
29 case 2:
30 case 3:
31 fromx = g_strtod(this, NULL);
32 j++;
33 break;
34 case 4:
35 endx = g_strtod(this, NULL);
36 scalex = width / endx;
37 scaley = height / top;
38 cairo_move_to(cr, fromx*scalex, 0);
39 case 5:
40 j++;
41 break;
42 default:
43 if (pointloc == 0) {
44 middlex = g_strtod(this, NULL);
46 pointloc = 1;
47 } else {
48 gdouble to;
49 middley = g_strtod(this, NULL);
50 pointloc = 0;
51 to = height - (middley*scaley);
53 if ((middlex - fromx) < 0.015 && fromy != -1 && middley != -1) {
54 cairo_line_to(cr, middlex*scalex, to);
55 } else {
56 cairo_move_to(cr, middlex*scalex, to);
58 fromx = middlex;
59 fromy = middley;
63 g_free(this);
64 m = i+1;
66 i++;
68 cairo_stroke (cr);
70 g_debug("%s for %s done!\n", __func__, filename);