2 #include <unistd.h> // Because we can.
4 #include "controlpanel.h"
12 bool ignore_sigfpe = false;
13 const char *script_filename;
15 void sigfpe_handler(int sig)
18 Fatal("Floating point exception!");
22 int main(int argc, char ** argv)
24 signal(SIGFPE, sigfpe_handler);
25 #if REALTYPE == REAL_IRRAM
26 iRRAM_initialize(argc,argv);
29 #ifndef __STDC_IEC_559__
30 Warn("__STDC_IEC_559__ not defined. IEEE 754 floating point not fully supported.\n");
33 // We want to crash if we ever get a NaN.
34 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
38 Document doc("","fonts/ComicSans.ttf");
41 enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
46 const char * output_bmp = NULL;
47 const char * input_filename = NULL;
48 const char * input_text = NULL;
49 Real b[4] = {0,0,1,1};
51 bool hide_control_panel = false;
52 bool lazy_rendering = true;
53 bool window_visible = true;
54 bool gpu_transform = true;
55 bool gpu_rendering = true;
62 if (argv[i][0] != '-')
64 input_filename = argv[i];
72 Fatal("No output argument following -o switch");
74 hide_control_panel = true;
78 Debug("Reading view bounds");
79 for (int j = 1; j <= 4; ++j)
82 Fatal("No %d bounds component following -b switch", j);
83 b[j-1] = RealFromStr(argv[i+j]);
91 Fatal("No text input following -t switch");
93 Debug("Insert text: %s", input_text);
100 Fatal("Expected \"gpu\" or \"cpu\" after -r switch");
101 if (strcmp(argv[i], "gpu") == 0)
103 gpu_rendering = true;
105 else if (strcmp(argv[i], "cpu") == 0)
107 gpu_rendering = false;
111 Fatal("Expected \"gpu\" or \"cpu\" after -r switch, not \"%s\"", argv[i]);
119 Fatal("Expected \"gpu\" or \"cpu\" after -T switch");
120 if (strcmp(argv[i], "gpu") == 0)
122 gpu_transform = true;
124 else if (strcmp(argv[i], "cpu") == 0)
126 gpu_transform = false;
130 Fatal("Expected \"gpu\" or \"cpu\" after -T switch, not \"%s\"", argv[i]);
137 lazy_rendering = !lazy_rendering;
142 Fatal("No frame number following -f switch");
143 max_frames = strtol(argv[i], NULL, 10);
144 hide_control_panel = true;
148 hide_control_panel = true;
152 hide_control_panel = true;
153 window_visible = !window_visible;
156 hide_control_panel = true;
158 Fatal("Expected filename after -s switch");
159 script_filename = argv[i];
164 Rect bounds(b[0],b[1],b[2],b[3]);
165 Screen scr(window_visible);
166 View view(doc,scr, bounds);
168 view.SetLazyRendering(lazy_rendering);
169 view.SetGPURendering(gpu_rendering);
170 view.SetGPUTransform(gpu_transform);
172 if (input_filename != NULL)
174 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
175 doc.LoadSVG(input_filename, Rect(Real(1)/Real(2),Real(1)/Real(2),Real(1)/Real(800),Real(1)/Real(600)));
177 doc.LoadSVG(input_filename, Rect(bounds.x+bounds.w/Real(2),bounds.y+bounds.h/Real(2),bounds.w/Real(800),bounds.h/Real(600)));
180 else if (input_text != NULL)
182 doc.AddText(input_text, bounds.h/Real(2), bounds.x, bounds.y+bounds.h/Real(2));
187 #ifndef CONTROLPANEL_DISABLED
188 if (!scr.Valid()) hide_control_panel = true;
189 SDL_Thread * cp_thread = NULL;
190 if (!hide_control_panel)
192 ControlPanel::RunArgs args = {argc, argv, view, doc, scr};
193 cp_thread = SDL_CreateThread(ControlPanel::Run, "ControlPanel", &args);
194 if (cp_thread == NULL)
196 Error("Couldn't create ControlPanel thread: %s", SDL_GetError());
199 #else //CONTROLPANEL_DISABLED
200 Debug("No control panel, hide_control_panel is %d", hide_control_panel);
204 MainLoop(doc, scr, view, max_frames);
205 else if (mode == OUTPUT_TO_BMP)
207 view.SaveBMP(output_bmp);
210 #ifndef CONTROLPANEL_DISABLED
211 if (cp_thread != NULL)
214 qApp->quit(); // will close the control panel
215 // (seems to not explode if the qApp has already been quit)
216 SDL_WaitThread(cp_thread, &cp_return);
217 Debug("ControlPanel thread returned %d", cp_return);
219 #endif //CONTROLPANEL_DISABLED
221 ignore_sigfpe = true;