2 #include <unistd.h> // Because we can.
4 #include "controlpanel.h"
12 int main(int argc, char ** argv)
14 #ifndef __STDC_IEC_559__
15 Warn("__STDC_IEC_559__ not defined. IEEE 754 floating point not fully supported.\n");
18 // We want to crash if we ever get a NaN.
19 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
21 Debug("Compiled with REAL = %d => \"%s\" sizeof(Real) == %d bytes", REAL, g_real_name[REAL], sizeof(Real));
23 Document doc("","fonts/ComicSans.ttf");
26 enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
30 const char * input_bmp = NULL;
31 const char * output_bmp = NULL;
32 const char * input_filename = NULL;
33 float b[4] = {0,0,1,1};
38 if (argv[i][0] != '-')
40 input_filename = argv[i];
48 Fatal("No input argument following -o switch");
51 Fatal("No output argument following -o switch");
57 Debug("Reading view bounds");
58 for (int j = 1; j <= 4; ++j)
61 Fatal("No %d bounds component following -b switch", j);
63 b[j-1] = strtof(argv[i+j], &e);
65 Fatal("Bounds component %d not a valid float", j);
73 if (input_filename != NULL)
75 doc.LoadSVG(input_filename, Rect(0,0,Real(1)/Real(800),Real(1)/Real(600)));
79 doc.Add(RECT_OUTLINE, Rect(0,0,0,0),0); // hack to stop segfault if document is empty (:S)
82 Rect bounds(b[0],b[1],b[2],b[3]);
85 View view(doc,scr, bounds);
87 #ifndef CONTROLPANEL_DISABLED
88 ControlPanel::RunArgs args = {argc, argv, view, doc, scr};
89 SDL_Thread * cp_thread = SDL_CreateThread(ControlPanel::Run, "ControlPanel", &args);
90 if (cp_thread == NULL)
92 Error("Couldn't create ControlPanel thread: %s", SDL_GetError());
94 #endif //CONTROLPANEL_DISABLED
97 MainLoop(doc, scr, view);
98 else if (mode == OUTPUT_TO_BMP) //TODO: Remove this shit
99 OverlayBMP(doc, input_bmp, output_bmp, bounds, c);
101 #ifndef CONTROLPANEL_DISABLED
103 if (cp_thread != NULL)
106 qApp->quit(); // will close the control panel
107 // (seems to not explode if the qApp has already been quit)
108 SDL_WaitThread(cp_thread, &cp_return);
109 Debug("ControlPanel thread returned %d", cp_return);
111 #endif //CONTROLPANEL_DISABLED