// // Copyright 2008 Johannes Hofmann // // This software may be used and distributed according to the terms // of the GNU General Public License, incorporated herein by reference. #include #include #include #include #include #include #include "CurveEditor.H" static CurveEditor *ce; static char cmd[2048]; static void editor_cb(Fl_Widget* o, void* d) { double x, y; printf("%s ", cmd); for (int i = 0; iget_n(); i++) { if (i != 0) printf(","); ce->get_point(i, &x, &y); printf("%.4g:%.4g", x, y); } printf("\n"); fflush(stdout); } static void stdin_cb(int fd, void *d) { char *curve = NULL; fgets(cmd, sizeof(cmd), stdin); for (int i = strlen(cmd) - 1; i >= 0; i--) if (isspace(cmd[i])) { cmd[i] = '\0'; if (curve) break; } else curve = &cmd[i]; if (curve) { double x, y; char *pstr; ce->clear(); while (pstr = strsep(&curve, ",")) { if (sscanf(pstr, "%lf:%lf", &x, &y) != 2 || y < 0 || x > 1 || y < 0 || y > 1) { fprintf(stderr, "Could not parse control point %s.\n", pstr); continue; } ce->add_point(x, y); } } } int main(int argc, char **argv) { Fl_Double_Window window(800, 600, "pnmcurvedit"); ce = new CurveEditor(0, 0, 800, 600); ce->add_point(0.0, 0.0); ce->add_point(0.5, 0.5); ce->add_point(1.0, 1.0); ce->callback(editor_cb, NULL); window.resizable(ce); window.show(argc, argv); Fl::add_fd(0, FL_READ, stdin_cb); return Fl::run(); }