Inflict Qt4 upon the codebase
[ipdf/code.git] / src / main.cpp
1 #include "main.h"
2 #include <unistd.h> // Because we can.
3
4 #include "controlpanel.h"
5
6
7
8 int main(int argc, char ** argv)
9 {       
10         #ifndef __STDC_IEC_559__
11         Warn("__STDC_IEC_559__ not defined. IEEE 754 floating point not fully supported.\n");
12         #endif
13
14
15         Debug("Compiled with REAL = %d => \"%s\" sizeof(Real) == %d bytes", REAL, g_real_name[REAL], sizeof(Real));
16
17         Document doc;
18         srand(time(NULL));
19
20         enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
21         
22         
23         Colour c(0,0,0,1);
24         const char * input_bmp = NULL;
25         const char * output_bmp = NULL;
26         const char * input_filename = NULL;
27         float b[4] = {0,0,1,1};
28
29         int i = 0;
30         while (++i < argc)
31         {
32                 if (argv[i][0] != '-')
33                 {
34                         input_filename = argv[i];
35                         continue;               
36                 }
37                 switch (argv[i][1])
38                 {
39                         case 'o':
40                                 mode = OUTPUT_TO_BMP;
41                                 if (++i >= argc)
42                                         Fatal("No input argument following -o switch");
43                                 input_bmp = argv[i];
44                                 if (++i >= argc)
45                                         Fatal("No output argument following -o switch");
46                                 output_bmp = argv[i];
47
48                                 break;
49                         case 'c':
50                         {
51                                 Debug("Reading paint colour");
52                                 for (int j = 1; j <= 4; ++j)
53                                 {
54                                         if (i+j >= argc)
55                                                 Fatal("No %d colour component following -c switch", j);
56                                         char * e;
57                                         float * comp = (j == 1) ? (&c.r) : ((j == 2) ? (&c.g) : ((j == 3) ? (&c.b) : &(c.a)));
58                                         *comp = strtof(argv[i+j], &e);
59                                         if (*e != '\0')
60                                                 Fatal("Colour component %d not a valid float", j); 
61                                 }
62                                 i += 4;
63                                 break;
64                         }
65                         case 'b':
66                         {
67                                 Debug("Reading view bounds");
68                                 for (int j = 1; j <= 4; ++j)
69                                 {
70                                         if (i+j >= argc)
71                                                 Fatal("No %d bounds component following -b switch", j);
72                                         char * e;
73                                         b[j-1] = strtof(argv[i+j], &e);
74                                         if (*e != '\0')
75                                                 Fatal("Bounds component %d not a valid float", j); 
76                                 }
77                                 i += 4;
78                                 break;
79                         }
80                 }       
81         }
82
83         if (input_filename != NULL)
84         {
85                 doc.LoadSVG(input_filename, Rect(0,0,Real(1)/Real(800),Real(1)/Real(600)));
86         }
87         else 
88         {
89                 //doc.AddBezier(Bezier(0,0, 1,0.5, 0.5,1, 1,1));
90                 doc.AddText("The quick brown\nfox jumps over\nthe lazy dog",0.1,0,0.5);
91                 //doc.AddBezier(Bezier(0,0,0,0.1,0,0.1,0,0.1));
92         }
93         Debug("Start!");
94         Rect bounds(b[0],b[1],b[2],b[3]);
95         
96         Screen scr;
97         View view(doc,scr, bounds);
98
99         #ifndef CONTROLPANEL_DISABLED
100                 ControlPanel::RunArgs args = {argc, argv, view, doc, scr};
101                 SDL_Thread * cp_thread = SDL_CreateThread(ControlPanel::Run, "ControlPanel", &args);
102                 if (cp_thread == NULL)
103                 {
104                         Error("Couldn't create ControlPanel thread: %s", SDL_GetError());
105                 }
106         #endif //CONTROLPANEL_DISABLED
107
108         if (mode == LOOP)
109                 MainLoop(doc, scr, view);
110         else if (mode == OUTPUT_TO_BMP) //TODO: Remove this shit
111                 OverlayBMP(doc, input_bmp, output_bmp, bounds, c);
112                 
113         #ifndef CONTROLPANEL_DISABLED
114                 
115                 if (cp_thread != NULL)
116                 {
117                         int cp_return;
118                         qApp->quit(); // will close the control panel
119                         // (seems to not explode if the qApp has already been quit)
120                         SDL_WaitThread(cp_thread, &cp_return);
121                         Debug("ControlPanel thread returned %d", cp_return);
122                 }
123         #endif //CONTROLPANEL_DISABLED
124         return 0;
125 }

UCC git Repository :: git.ucc.asn.au