2 #include <unistd.h> // Because we can.
4 #include "controlpanel.h"
12 bool ignore_sigfpe = false;
14 void sigfpe_handler(int sig)
17 Fatal("Floating point exception!");
21 int main(int argc, char ** argv)
23 signal(SIGFPE, sigfpe_handler);
24 #if REALTYPE == REAL_IRRAM
25 iRRAM_initialize(argc,argv);
28 #ifndef __STDC_IEC_559__
29 Warn("__STDC_IEC_559__ not defined. IEEE 754 floating point not fully supported.\n");
32 // We want to crash if we ever get a NaN.
33 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
37 Document doc("","fonts/ComicSans.ttf");
40 enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
45 const char * output_bmp = NULL;
46 const char * input_filename = NULL;
47 const char * input_text = NULL;
48 float b[4] = {0,0,1,1};
50 bool hide_control_panel = false;
51 bool lazy_rendering = true;
52 bool window_visible = true;
53 bool gpu_transform = true;
54 bool gpu_rendering = true;
61 if (argv[i][0] != '-')
63 input_filename = argv[i];
71 Fatal("No output argument following -o switch");
73 hide_control_panel = true;
77 Debug("Reading view bounds");
78 for (int j = 1; j <= 4; ++j)
81 Fatal("No %d bounds component following -b switch", j);
83 b[j-1] = strtof(argv[i+j], &e);
85 Fatal("Bounds component %d not a valid float", j);
93 Fatal("No text input following -t switch");
95 Debug("Insert text: %s", input_text);
102 Fatal("Expected \"gpu\" or \"cpu\" after -r switch");
103 if (strcmp(argv[i], "gpu") == 0)
105 gpu_rendering = true;
107 else if (strcmp(argv[i], "cpu") == 0)
109 gpu_rendering = false;
113 Fatal("Expected \"gpu\" or \"cpu\" after -r switch, not \"%s\"", argv[i]);
121 Fatal("Expected \"gpu\" or \"cpu\" after -T switch");
122 if (strcmp(argv[i], "gpu") == 0)
124 gpu_transform = true;
126 else if (strcmp(argv[i], "cpu") == 0)
128 gpu_transform = false;
132 Fatal("Expected \"gpu\" or \"cpu\" after -T switch, not \"%s\"", argv[i]);
139 lazy_rendering = !lazy_rendering;
144 Fatal("No frame number following -f switch");
145 max_frames = strtol(argv[i], NULL, 10);
146 hide_control_panel = true;
150 hide_control_panel = true;
154 hide_control_panel = true;
155 window_visible = !window_visible;
160 Rect bounds(b[0],b[1],b[2],b[3]);
161 Screen scr(window_visible);
162 View view(doc,scr, bounds);
164 view.SetLazyRendering(lazy_rendering);
165 view.SetGPURendering(gpu_rendering);
166 view.SetGPUTransform(gpu_transform);
168 if (input_filename != NULL)
170 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
171 doc.LoadSVG(input_filename, Rect(Real(1)/Real(2),Real(1)/Real(2),Real(1)/Real(800),Real(1)/Real(600)));
173 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)));
176 else if (input_text != NULL)
178 doc.AddText(input_text, bounds.h/Real(2), bounds.x, bounds.y+bounds.h/Real(2));
182 doc.Add(RECT_OUTLINE, Rect(0,0,0,0),0); // hack to stop segfault if document is empty (:S)
186 #ifndef CONTROLPANEL_DISABLED
187 if (!scr.Valid()) hide_control_panel = true;
188 SDL_Thread * cp_thread = NULL;
189 if (!hide_control_panel)
191 ControlPanel::RunArgs args = {argc, argv, view, doc, scr};
192 cp_thread = SDL_CreateThread(ControlPanel::Run, "ControlPanel", &args);
193 if (cp_thread == NULL)
195 Error("Couldn't create ControlPanel thread: %s", SDL_GetError());
198 #else //CONTROLPANEL_DISABLED
199 Debug("No control panel, hide_control_panel is %d", hide_control_panel);
203 MainLoop(doc, scr, view, max_frames);
204 else if (mode == OUTPUT_TO_BMP)
206 view.SaveBMP(output_bmp);
209 #ifndef CONTROLPANEL_DISABLED
210 if (cp_thread != NULL)
213 qApp->quit(); // will close the control panel
214 // (seems to not explode if the qApp has already been quit)
215 SDL_WaitThread(cp_thread, &cp_return);
216 Debug("ControlPanel thread returned %d", cp_return);
218 #endif //CONTROLPANEL_DISABLED
220 ignore_sigfpe = true;