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)
25 signal(SIGFPE, sigfpe_handler);
26 #if REALTYPE == REAL_IRRAM
27 iRRAM_initialize(argc,argv);
30 #ifndef __STDC_IEC_559__
31 Warn("__STDC_IEC_559__ not defined. IEEE 754 floating point not fully supported.\n");
34 // We want to crash if we ever get a NaN.
35 // AH, so *this* is where that got enabled, I was looking for compiler flags
37 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
42 Document doc("","fonts/ComicSans.ttf");
45 enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
50 const char * output_bmp = NULL;
51 const char * input_filename = NULL;
52 const char * input_text = NULL;
53 Real b[4] = {0,0,1,1};
55 bool hide_control_panel = false;
56 bool lazy_rendering = true;
57 bool window_visible = true;
58 bool gpu_transform = true;
59 bool gpu_rendering = true;
66 if (argv[i][0] != '-')
68 input_filename = argv[i];
76 Fatal("No output argument following -o switch");
78 hide_control_panel = true;
82 Debug("Reading view bounds");
83 for (int j = 1; j <= 4; ++j)
86 Fatal("No %d bounds component following -b switch", j);
87 b[j-1] = RealFromStr(argv[i+j]);
95 Fatal("No text input following -t switch");
97 Debug("Insert text: %s", input_text);
104 Fatal("Expected \"gpu\" or \"cpu\" after -r switch");
105 if (strcmp(argv[i], "gpu") == 0)
107 gpu_rendering = true;
109 else if (strcmp(argv[i], "cpu") == 0)
111 gpu_rendering = false;
115 Fatal("Expected \"gpu\" or \"cpu\" after -r switch, not \"%s\"", argv[i]);
123 Fatal("Expected \"gpu\" or \"cpu\" after -T switch");
124 if (strcmp(argv[i], "gpu") == 0)
126 gpu_transform = true;
128 else if (strcmp(argv[i], "cpu") == 0)
130 gpu_transform = false;
134 Fatal("Expected \"gpu\" or \"cpu\" after -T switch, not \"%s\"", argv[i]);
141 lazy_rendering = !lazy_rendering;
146 Fatal("No frame number following -f switch");
147 max_frames = strtol(argv[i], NULL, 10);
148 hide_control_panel = true;
152 hide_control_panel = true;
156 hide_control_panel = true;
157 window_visible = !window_visible;
160 hide_control_panel = true;
162 Fatal("Expected filename after -s switch");
163 script_filename = argv[i];
168 Rect bounds(b[0],b[1],b[2],b[3]);
169 Screen scr(window_visible);
170 View view(doc,scr, bounds);
172 view.SetLazyRendering(lazy_rendering);
173 view.SetGPURendering(gpu_rendering);
174 view.SetGPUTransform(gpu_transform);
176 if (input_filename != NULL)
178 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
179 doc.LoadSVG(input_filename, Rect(Real(1)/Real(2),Real(1)/Real(2),Real(1)/Real(800),Real(1)/Real(600)));
181 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)));
184 else if (input_text != NULL)
186 doc.AddText(input_text, bounds.h/Real(2), bounds.x, bounds.y+bounds.h/Real(2));
191 #ifndef CONTROLPANEL_DISABLED
192 if (!scr.Valid()) hide_control_panel = true;
193 SDL_Thread * cp_thread = NULL;
194 if (!hide_control_panel)
196 ControlPanel::RunArgs args = {argc, argv, view, doc, scr};
197 cp_thread = SDL_CreateThread(ControlPanel::Run, "ControlPanel", &args);
198 if (cp_thread == NULL)
200 Error("Couldn't create ControlPanel thread: %s", SDL_GetError());
203 #else //CONTROLPANEL_DISABLED
204 Debug("No control panel, hide_control_panel is %d", hide_control_panel);
208 MainLoop(doc, scr, view, max_frames);
209 else if (mode == OUTPUT_TO_BMP)
211 view.SaveBMP(output_bmp);
214 #ifndef CONTROLPANEL_DISABLED
215 if (cp_thread != NULL)
218 qApp->quit(); // will close the control panel
219 // (seems to not explode if the qApp has already been quit)
220 SDL_WaitThread(cp_thread, &cp_return);
221 Debug("ControlPanel thread returned %d", cp_return);
223 #endif //CONTROLPANEL_DISABLED
225 ignore_sigfpe = true;