2 #include <unistd.h> // Because we can.
4 #include "controlpanel.h"
12 bool ignore_sigfpe = false;
13 const char *script_filename;
14 bool make_movie = false;
15 const char * program_name;
17 void sigfpe_handler(int sig)
20 Fatal("Floating point exception!");
24 int main(int argc, char ** argv)
26 program_name = argv[0];
29 signal(SIGFPE, sigfpe_handler);
30 #if REALTYPE == REAL_IRRAM
31 iRRAM_initialize(argc,argv);
34 #ifndef __STDC_IEC_559__
35 Warn("__STDC_IEC_559__ not defined. IEEE 754 floating point not fully supported.\n");
38 // We want to crash if we ever get a NaN.
41 //feenableexcept(FE_DIVBYZERO | FE_INVALID); // | FE_OVERFLOW);
43 #if REALTYPE == REAL_MPFRCPP
46 mpfr_set_default_prec(MPFR_PRECISION);
48 mpfr_set_default_prec(23);
56 Document doc("","fonts/ComicSans.ttf");
59 enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
64 const char * output_bmp = NULL;
65 const char * input_filename = NULL;
66 const char * input_text = NULL;
67 Real b[4] = {0,0,1,1};
69 bool hide_control_panel = false;
70 bool lazy_rendering = true;
71 bool window_visible = true;
72 bool gpu_transform = USE_GPU_TRANSFORM;
73 bool gpu_rendering = USE_GPU_RENDERING;
74 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
77 #ifdef TRANSFORM_BEZIERS_TO_PATH
85 if (argv[i][0] != '-')
87 input_filename = argv[i];
95 Fatal("No output argument following -o switch");
97 hide_control_panel = true;
101 Debug("Reading view bounds");
102 for (int j = 1; j <= 4; ++j)
105 Fatal("No %d bounds component following -b switch", j);
106 b[j-1] = RealFromStr(argv[i+j]);
114 Fatal("No text input following -t switch");
115 input_text = argv[i];
116 Debug("Insert text: %s", input_text);
123 Fatal("Expected \"gpu\" or \"cpu\" after -r switch");
124 if (strcmp(argv[i], "gpu") == 0)
126 gpu_rendering = true;
128 else if (strcmp(argv[i], "cpu") == 0)
130 gpu_rendering = false;
134 Fatal("Expected \"gpu\" or \"cpu\" after -r switch, not \"%s\"", argv[i]);
142 Fatal("Expected \"gpu\" or \"cpu\" after -T switch");
143 if (strcmp(argv[i], "gpu") == 0)
145 gpu_transform = true;
147 else if (strcmp(argv[i], "cpu") == 0)
149 gpu_transform = false;
153 Fatal("Expected \"gpu\" or \"cpu\" after -T switch, not \"%s\"", argv[i]);
160 lazy_rendering = !lazy_rendering;
165 Fatal("No frame number following -f switch");
166 max_frames = strtol(argv[i], NULL, 10);
167 hide_control_panel = true;
171 hide_control_panel = true;
175 hide_control_panel = true;
176 window_visible = !window_visible;
179 hide_control_panel = true;
181 Fatal("Expected filename after -s switch");
182 script_filename = argv[i];
190 Rect bounds(b[0],b[1],b[2],b[3]);
191 Screen scr(window_visible);
192 View view(doc,scr, bounds);
194 view.SetLazyRendering(lazy_rendering);
195 view.SetGPURendering(gpu_rendering);
196 view.SetGPUTransform(gpu_transform);
198 if (input_filename != NULL)
200 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
201 doc.LoadSVG(input_filename, Rect(Real(1)/Real(2),Real(1)/Real(2),Real(1)/Real(800),Real(1)/Real(600)));
203 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)));
206 else if (input_text != NULL)
208 doc.AddText(input_text, bounds.h/Real(2), bounds.x, bounds.y+bounds.h/Real(2));
213 #ifndef CONTROLPANEL_DISABLED
214 if (!scr.Valid()) hide_control_panel = true;
215 SDL_Thread * cp_thread = NULL;
216 if (!hide_control_panel)
218 ControlPanel::RunArgs args = {argc, argv, view, doc, scr};
219 cp_thread = SDL_CreateThread(ControlPanel::Run, "ControlPanel", &args);
220 if (cp_thread == NULL)
222 Error("Couldn't create ControlPanel thread: %s", SDL_GetError());
225 #else //CONTROLPANEL_DISABLED
226 Debug("No control panel, hide_control_panel is %d", hide_control_panel);
230 MainLoop(doc, scr, view, max_frames);
231 else if (mode == OUTPUT_TO_BMP)
233 view.SaveBMP(output_bmp);
236 #ifndef CONTROLPANEL_DISABLED
237 if (cp_thread != NULL)
240 qApp->quit(); // will close the control panel
241 // (seems to not explode if the qApp has already been quit)
242 SDL_WaitThread(cp_thread, &cp_return);
243 Debug("ControlPanel thread returned %d", cp_return);
245 #endif //CONTROLPANEL_DISABLED
247 ignore_sigfpe = true;