ScummVM API documentation
types.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NANCY_SCRIPT_TYPES_H
23 #define NANCY_SCRIPT_TYPES_H
24 
25 #include "common/rect.h"
26 #include "common/str.h"
27 
28 struct lua_State;
29 
30 namespace Nancy {
31 namespace Script {
32 
33 // The plain values scripts pass around: rectangles, points and colors.
34 //
35 // Scripts are free to build rectangles that are empty or inside out, and to move
36 // them far off the screen, so they are kept as they are and only turned into the
37 // engine's own type where they get used.
38 
39 struct ScriptRect {
40  int32 left = 0;
41  int32 top = 0;
42  int32 right = 0;
43  int32 bottom = 0;
44 
45  ScriptRect() {}
46  ScriptRect(int32 l, int32 t, int32 r, int32 b) : left(l), top(t), right(r), bottom(b) {}
47  ScriptRect(const Common::Rect &rect) : left(rect.left), top(rect.top), right(rect.right), bottom(rect.bottom) {}
48 
49  int32 width() const { return right - left; }
50  int32 height() const { return bottom - top; }
51  bool isEmpty() const { return right <= left || bottom <= top; }
52  bool contains(int32 x, int32 y) const { return x >= left && x < right && y >= top && y < bottom; }
53  void translate(int32 dx, int32 dy) { left += dx; right += dx; top += dy; bottom += dy; }
54  bool operator==(const ScriptRect &other) const {
55  return left == other.left && top == other.top && right == other.right && bottom == other.bottom;
56  }
57 
58  // An empty or inside out rectangle becomes an empty one
59  Common::Rect toRect() const;
60 };
61 
62 struct ScriptPoint {
63  int32 x = 0;
64  int32 y = 0;
65 
66  ScriptPoint() {}
67  ScriptPoint(int32 px, int32 py) : x(px), y(py) {}
68  ScriptPoint(const Common::Point &point) : x(point.x), y(point.y) {}
69 
70  Common::Point toPoint() const { return Common::Point(x, y); }
71 };
72 
73 void registerTypes(lua_State *L);
74 
75 void pushRect(lua_State *L, const ScriptRect &rect);
76 ScriptRect *testRect(lua_State *L, int index); // null when it is something else
77 ScriptRect &checkRect(lua_State *L, int index);
78 
79 void pushPoint(lua_State *L, const ScriptPoint &point);
80 
81 // Reads anything that has an x and a y: a point, a vector or a table.
82 // Returns false when the value has neither.
83 bool readPoint(lua_State *L, int index, ScriptPoint &point);
84 
85 // Colors are 0xAARRGGBB
86 void pushColor(lua_State *L, uint32 argb);
87 uint32 *testColor(lua_State *L, int index);
88 uint32 checkColor(lua_State *L, int index);
89 
90 // What a script sends to a scene, or to the records of one that go by a name
91 struct Message {
92  Common::String action;
93  Common::String target;
94  Common::String sender;
95  Common::String text;
96  double value = 0;
97 };
98 
99 } // End of namespace Script
100 } // End of namespace Nancy
101 
102 #endif // NANCY_SCRIPT_TYPES_H
Definition: types.h:91
Definition: str.h:59
T left
Definition: rect.h:170
Definition: types.h:39
Definition: rect.h:536
Definition: lstate.h:100
T right
Definition: rect.h:171
T y
Definition: rect.h:49
T x
Definition: rect.h:48
Definition: rect.h:144
Definition: types.h:62
Definition: actionmanager.h:32