Lazy + CPU/GPU rendering toggle in script.
[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                 return;
50         }
51         else if (actionType == "pxtranslate")
52         {
53                 inp >> currentAction.ix >> currentAction.iy;
54                 currentAction.type = AT_TranslatePx;
55                 return;
56         }
57         else if (actionType == "pxzoom")
58         {
59                 inp >> currentAction.ix >> currentAction.iy >> currentAction.iz;
60                 currentAction.type = AT_ZoomPx;
61                 return;
62         }
63         else if (actionType == "gpu")
64         {
65                 currentAction.type = AT_SetGPURendering;
66                 return;
67         }
68         else if (actionType == "cpu")
69         {
70                 currentAction.type = AT_SetCPURendering;
71                 return;
72         }
73         else if (actionType == "lazy")
74         {
75                 currentAction.type = AT_EnableLazyRendering;
76                 return;
77         }
78         else if (actionType == "nolazy")
79         {
80                 currentAction.type = AT_DisableLazyRendering;
81                 return;
82         }
83         else if (actionType == "quit")
84         {
85                 currentAction.type = AT_Quit;
86         }
87 }
88
89 bool DebugScript::Execute(View *view, Screen *scr)
90 {
91         if (currentAction.loops == 0)
92                 ParseAction();
93
94         switch(currentAction.type)
95         {
96         case AT_Quit:
97                 return true;
98         case AT_WaitFrame:
99                 break;
100         case AT_Translate:
101                 view->Translate(currentAction.x, currentAction.y);
102                 break;
103         case AT_TranslatePx:
104                 view->Translate(Real(currentAction.ix)/Real(scr->ViewportWidth()), Real(currentAction.iy)/Real(scr->ViewportHeight()));
105                 break;
106         case AT_Zoom:
107                 view->ScaleAroundPoint(currentAction.x, currentAction.y, currentAction.z);
108                 break;
109         case AT_ZoomPx:
110                 view->ScaleAroundPoint(Real(currentAction.ix)/Real(scr->ViewportWidth()),Real(currentAction.iy)/Real(scr->ViewportHeight()), Real(expf(-currentAction.iz/20.f)));
111                 break;
112         case AT_SetGPURendering:
113                 view->SetGPURendering(true);
114                 break;
115         case AT_SetCPURendering:
116                 view->SetGPURendering(false);
117                 break;
118         case AT_EnableLazyRendering:
119                 view->SetLazyRendering(true);
120                 break;
121         case AT_DisableLazyRendering:
122                 view->SetLazyRendering(false);
123                 break;
124         default:
125                 Fatal("Unknown script command in queue.");
126         }
127         currentAction.loops--;
128         return false;
129 }

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