2 #include <unistd.h> // Because we can.
4 #include "controlpanel.h"
8 int main(int argc, char ** argv)
10 #ifndef __STDC_IEC_559__
11 Warn("__STDC_IEC_559__ not defined. IEEE 754 floating point not fully supported.\n");
15 Debug("Compiled with REAL = %d => \"%s\" sizeof(Real) == %d bytes", REAL, g_real_name[REAL], sizeof(Real));
17 Document doc("","fonts/ComicSans.ttf");
20 enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
24 const char * input_bmp = NULL;
25 const char * output_bmp = NULL;
26 const char * input_filename = NULL;
27 float b[4] = {0,0,1,1};
32 if (argv[i][0] != '-')
34 input_filename = argv[i];
42 Fatal("No input argument following -o switch");
45 Fatal("No output argument following -o switch");
51 Debug("Reading paint colour");
52 for (int j = 1; j <= 4; ++j)
55 Fatal("No %d colour component following -c switch", j);
57 float * comp = (j == 1) ? (&c.r) : ((j == 2) ? (&c.g) : ((j == 3) ? (&c.b) : &(c.a)));
58 *comp = strtof(argv[i+j], &e);
60 Fatal("Colour component %d not a valid float", j);
67 Debug("Reading view bounds");
68 for (int j = 1; j <= 4; ++j)
71 Fatal("No %d bounds component following -b switch", j);
73 b[j-1] = strtof(argv[i+j], &e);
75 Fatal("Bounds component %d not a valid float", j);
83 if (input_filename != NULL)
85 doc.LoadSVG(input_filename, Rect(0,0,Real(1)/Real(800),Real(1)/Real(600)));
89 doc.Add(RECT_OUTLINE, Rect(0,0,0,0),0); // hack to stop segfault if document is empty (:S)
92 Rect bounds(b[0],b[1],b[2],b[3]);
95 View view(doc,scr, bounds);
97 #ifndef CONTROLPANEL_DISABLED
98 ControlPanel::RunArgs args = {argc, argv, view, doc, scr};
99 SDL_Thread * cp_thread = SDL_CreateThread(ControlPanel::Run, "ControlPanel", &args);
100 if (cp_thread == NULL)
102 Error("Couldn't create ControlPanel thread: %s", SDL_GetError());
104 #endif //CONTROLPANEL_DISABLED
107 MainLoop(doc, scr, view);
108 else if (mode == OUTPUT_TO_BMP) //TODO: Remove this shit
109 OverlayBMP(doc, input_bmp, output_bmp, bounds, c);
111 #ifndef CONTROLPANEL_DISABLED
113 if (cp_thread != NULL)
116 qApp->quit(); // will close the control panel
117 // (seems to not explode if the qApp has already been quit)
118 SDL_WaitThread(cp_thread, &cp_return);
119 Debug("ControlPanel thread returned %d", cp_return);
121 #endif //CONTROLPANEL_DISABLED