summaryrefslogtreecommitdiff
path: root/src/flcurve.cxx
blob: 94908bc1d1a2a32b8062cdb2dacd9a236f1f1a2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// Copyright 2008 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
// This software may be used and distributed according to the terms
// of the GNU General Public License, incorporated herein by reference.

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/fl_draw.H>

#include <../config.h>

#include "CurveEditor.H"

static void 
parse_curve(CurveEditor *ce, const char *ctrl_points);

void
usage() {
	fprintf(stderr,
		"flcurve %s\n"
		VERSION);
}

int
main(int argc, char **argv) {
	int c, n, i, err;
	char *curve = NULL;

	while ((c = getopt(argc, argv, "?hs:g:d:f:i:C:")) != EOF) {
		switch (c) {  
			case '?':
			case 'h':
				usage();
				exit(0);
			case 'C':
				curve = optarg;
				break;
			default:
				i = optind - 1;
				n = Fl::arg(argc, argv, i);
				if (n == 0) {
					err++;
				} else {
					optind = i;
				}
				break;
		}
	}

	Fl_Window window(800, 800);
	CurveEditor ce(10, 10, 780, 780);
	window.end();
	window.resizable(ce);

	if (curve) {
		parse_curve(&ce, curve);
	}

	window.show(1, argv);

	return Fl::run();
}

static void 
parse_curve(CurveEditor *ce, const char *ctrl_points) {
    char *pstr, *buf = strdup(ctrl_points);
    int i, n = 0;
    double X, Y;

    while (pstr = strsep(&buf, ";")) {
        if (sscanf(pstr, "%lf,%lf", &X, &Y) != 2 ||
            X < 0.0 || X > 1.0 || Y < 0.0 || Y > 1.0) {
            fprintf(stderr, "Could not parse control point %s.\n", pstr);
			continue;
        }
	
		ce->add_point(X, Y);
    }   
    
    free(buf); 

	ce->init();
}