ScummVM API documentation
lever_control.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 ZVISION_LEVER_CONTROL_H
23#define ZVISION_LEVER_CONTROL_H
24
25#include "common/list.h"
26#include "common/path.h"
27#include "common/rect.h"
28#include "math/vector2d.h"
29#include "zvision/scripting/control.h"
30
31namespace Video {
32 class VideoDecoder;
33}
34
35namespace ZVision {
36
37// Only used in Zork Nemesis, handles draggable levers (te2e, tm7e, tp2e, tt2e, tz2e)
38class LeverControl : public Control {
39public:
40 LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream);
41 ~LeverControl() override;
42
43private:
44
45 struct PathSegment {
46 PathSegment(uint a, uint t) : angle(Math::deg2rad<float>(a)), toFrame(t), direction(cos(angle), -sin(angle)) {}
47
48 float angle; // Radians
49 uint toFrame;
50 Math::Vector2d direction; // NB unit vector upon initialisation
51 float distance = 1.0f;
52 };
53
54 struct FrameInfo {
55 Common::Rect hotspot;
57 Common::List<uint> returnRoute;
58 };
59
60private:
61 Video::VideoDecoder *_animation;
62
63 int _cursor;
64 Common::Rect _animationCoords;
65 bool _mirrored;
66 uint _frameCount;
67 uint _startFrame;
68 Common::Point _hotspotDelta;
69 FrameInfo *_frameInfo;
70
71 uint _currentFrame;
72 uint _lastRenderedFrame;
73 bool _mouseIsCaptured;
74 bool _isReturning;
75 Common::Point _gripOffset;
76 Common::List<uint>::iterator _returnRoutesCurrentProgress;
77 uint _returnRoutesCurrentFrame;
78 const uint8 _returnFramePeriod = 60; // milliseconds
79 uint32 _accumulatedTime;
80
81public:
82 bool onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) override;
83 bool onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) override;
84 bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) override;
85 bool process(uint32 deltaTimeInMillis) override;
86
87private:
88 void parseLevFile(const Common::Path &fileName);
89 void renderFrame(uint frameNumber);
90 void getLevParams(const Common::String &inputStr, Common::String &parameter, Common::String &values);
91 uint getNextFrame(Common::Point &deltaPos);
92};
93
94} // End of namespace ZVision
95
96#endif
Definition: path.h:52
Definition: stream.h:745
Definition: str.h:59
Definition: video_decoder.h:53
Definition: control.h:43
Definition: lever_control.h:38
bool onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) override
bool process(uint32 deltaTimeInMillis) override
bool onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) override
bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) override
Definition: focus_list.h:27
Definition: list_intern.h:54
Definition: rect.h:144
Definition: rect.h:536