Initial support for scripting actions.
[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 == "quit")
64         {
65                 currentAction.type = AT_Quit;
66         }
67 }
68
69 bool DebugScript::Execute(View *view, Screen *scr)
70 {
71         if (currentAction.loops == 0)
72                 ParseAction();
73
74         switch(currentAction.type)
75         {
76         case AT_Quit:
77                 return true;
78         case AT_WaitFrame:
79                 break;
80         case AT_Translate:
81                 view->Translate(currentAction.x, currentAction.y);
82                 break;
83         case AT_TranslatePx:
84                 view->Translate(Real(currentAction.ix)/Real(scr->ViewportWidth()), Real(currentAction.iy)/Real(scr->ViewportHeight()));
85                 break;
86         case AT_Zoom:
87                 view->ScaleAroundPoint(currentAction.x, currentAction.y, currentAction.z);
88                 break;
89         case AT_ZoomPx:
90                 view->ScaleAroundPoint(Real(currentAction.ix)/Real(scr->ViewportWidth()),Real(currentAction.iy)/Real(scr->ViewportHeight()), Real(expf(-currentAction.iz/20.f)));
91                 break;
92         default:
93                 Fatal("Unknown script command in queue.");
94         }
95         currentAction.loops--;
96         return false;
97 }

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