Use Gmprat for Path bounds with TRANSFORM_BEZIERS_TO_PATH
[ipdf/code.git] / src / debugscript.cpp
1 #include "debugscript.h"
2
3 #include <string>
4
5 using namespace IPDF;
6
7 void DebugScript::ParseAction()
8 {
9         std::string actionType;
10         inp >> actionType;
11         // Skip comments
12         while (actionType[0] == '#')
13         {
14                 std::string tmp;
15                 std::getline(inp, tmp);
16                 inp >> std::ws >> actionType;
17         }
18         if (actionType == "loop")
19         {
20                 inp >> currentAction.loops >> actionType;
21         }
22         else
23         {
24                 currentAction.loops = 1;
25         }
26
27         if (actionType == "wait")
28         {
29                 currentAction.type = AT_WaitFrame;
30                 return;
31         }
32         else if (actionType == "translate")
33         {
34                 std::string _x, _y;
35                 inp >> _x >> _y;
36                 currentAction.type = AT_Translate;
37                 currentAction.x = RealFromStr(_x.c_str());
38                 currentAction.y = RealFromStr(_y.c_str());
39                 return;
40         }
41         else if (actionType == "zoom")
42         {
43                 std::string _x, _y, _z;
44                 inp >> _x >> _y >> _z;
45                 currentAction.type = AT_Zoom;
46                 currentAction.x = RealFromStr(_x.c_str());
47                 currentAction.y = RealFromStr(_y.c_str());
48                 currentAction.z = RealFromStr(_z.c_str());
49         }
50         else if (actionType == "pxtranslate")
51         {
52                 inp >> currentAction.ix >> currentAction.iy;
53                 currentAction.type = AT_TranslatePx;
54         }
55         else if (actionType == "pxzoom")
56         {
57                 inp >> currentAction.ix >> currentAction.iy >> currentAction.iz;
58                 currentAction.type = AT_ZoomPx;
59         }
60         else if (actionType == "gpu")
61         {
62                 currentAction.type = AT_SetGPURendering;
63         }
64         else if (actionType == "cpu")
65         {
66                 currentAction.type = AT_SetCPURendering;
67         }
68         else if (actionType == "lazy")
69         {
70                 currentAction.type = AT_EnableLazyRendering;
71         }
72         else if (actionType == "nolazy")
73         {
74                 currentAction.type = AT_DisableLazyRendering;
75         }
76         else if (actionType == "quit")
77         {
78                 currentAction.type = AT_Quit;
79         }
80         else if (actionType == "loadsvg")
81         {
82                 currentAction.type = AT_LoadSVG;
83                 inp >> currentAction.textargs;
84         }
85         else if (actionType == "label")
86         {
87                 currentAction.type = AT_Label;
88                 inp >> currentAction.textargs;
89         }
90         else if (actionType == "goto")
91         {
92                 currentAction.type = AT_Goto;
93                 inp >> currentAction.textargs;
94         }
95         else if (actionType == "debug")
96         {
97                 currentAction.type = AT_Debug;
98                 getline(inp,currentAction.textargs);
99         }
100 }
101
102 bool DebugScript::Execute(View *view, Screen *scr)
103 {
104         if (currentAction.loops <= 0)
105         {
106                 if (m_index >= m_actions.size())
107                 {
108                         ParseAction();
109                         if (m_labels.size() > 0)
110                         {
111                                 m_actions.push_back(currentAction);
112                                 m_index++;
113                         }
114                                 
115                 }
116                 else
117                         currentAction = m_actions[m_index++];
118         }
119
120         switch(currentAction.type)
121         {
122         case AT_Quit:
123                 return true;
124         case AT_WaitFrame:
125                 break;
126         case AT_Translate:
127                 view->Translate(currentAction.x, currentAction.y);
128                 break;
129         case AT_TranslatePx:
130                 view->Translate(Real(currentAction.ix)/Real(scr->ViewportWidth()), Real(currentAction.iy)/Real(scr->ViewportHeight()));
131                 break;
132         case AT_Zoom:
133                 view->ScaleAroundPoint(currentAction.x, currentAction.y, currentAction.z);
134                 break;
135         case AT_ZoomPx:
136                 view->ScaleAroundPoint(Real(currentAction.ix)/Real(scr->ViewportWidth()),Real(currentAction.iy)/Real(scr->ViewportHeight()), Real(expf(-currentAction.iz/20.f)));
137                 break;
138         case AT_SetGPURendering:
139                 view->SetGPURendering(true);
140                 break;
141         case AT_SetCPURendering:
142                 view->SetGPURendering(false);
143                 break;
144         case AT_EnableLazyRendering:
145                 view->SetLazyRendering(true);
146                 break;
147         case AT_DisableLazyRendering:
148                 view->SetLazyRendering(false);
149                 break;
150         case AT_LoadSVG:
151         {
152                 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
153                         view->Doc().LoadSVG(currentAction.textargs, Rect(Real(1)/Real(2),Real(1)/Real(2),Real(1)/Real(800),Real(1)/Real(600))); 
154                 #else
155                         const Rect & bounds = view->GetBounds();
156                         view->Doc().LoadSVG(currentAction.textargs, Rect(bounds.x+bounds.w/Real(2),bounds.y+bounds.h/Real(2),bounds.w/Real(800),bounds.h/Real(600)));
157                 #endif
158                 currentAction.type = AT_WaitFrame;
159                 view->ForceRenderDirty();
160                 view->ForceBufferDirty();
161                 view->ForceBoundsDirty();
162                 currentAction.loops = 1;
163                 break;
164         }
165         case AT_Label:
166                 m_labels[currentAction.textargs] = m_index;
167                 currentAction.type = AT_WaitFrame;
168                 currentAction.loops = 1;
169                 break;
170         case AT_Goto:
171                 m_index = m_labels[currentAction.textargs];
172                 currentAction.loops = 1;
173                 break;
174         case AT_Debug:
175                 Debug("View bounds: %s", view->GetBounds().Str().c_str());
176                 if (currentAction.textargs.size() > 0)
177                         Debug("%s", currentAction.textargs.c_str());
178                 break;
179         default:
180                 Fatal("Unknown script command in queue.");
181         }
182         currentAction.loops--;
183         return false;
184 }

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