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 "zvision/scripting/control.h"
26 
27 #include "common/list.h"
28 #include "common/path.h"
29 #include "common/rect.h"
30 
31 namespace Video {
32  class VideoDecoder;
33 }
34 
35 namespace ZVision {
36 
37 // Only used in Zork Nemesis, handles draggable levers (te2e, tm7e, tp2e, tt2e, tz2e)
38 class LeverControl : public Control {
39 public:
40  LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream);
41  ~LeverControl() override;
42 
43 private:
44 
45  struct Direction {
46  Direction(uint a, uint t) : angle(a), toFrame(t) {}
47 
48  uint angle;
49  uint toFrame;
50  };
51 
52  struct FrameInfo {
53  Common::Rect hotspot;
54  Common::List<Direction> directions;
55  Common::List<uint> returnRoute;
56  };
57 
58  enum {
59  ANGLE_DELTA = 30, // How far off a mouse angle can be and still be considered valid. This is in both directions, so the total buffer zone is (2 * ANGLE_DELTA)
60  ANIMATION_FRAME_TIME = 30 // In millis
61  };
62 
63 private:
64  Video::VideoDecoder *_animation;
65 
66  int _cursor;
67  Common::Rect _animationCoords;
68  bool _mirrored;
69  uint _frameCount;
70  uint _startFrame;
71  Common::Point _hotspotDelta;
72  FrameInfo *_frameInfo;
73 
74  uint _currentFrame;
75  uint _lastRenderedFrame;
76  bool _mouseIsCaptured;
77  bool _isReturning;
78  Common::Point _lastMousePos;
79  Common::List<uint>::iterator _returnRoutesCurrentProgress;
80  uint _returnRoutesCurrentFrame;
81  uint32 _accumulatedTime;
82 
83 public:
84  bool onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) override;
85  bool onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) override;
86  bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) override;
87  bool process(uint32 deltaTimeInMillis) override;
88 
89 private:
90  void parseLevFile(const Common::Path &fileName);
114  static int calculateVectorAngle(const Common::Point &pointOne, const Common::Point &pointTwo);
115  void renderFrame(uint frameNumber);
116  void getLevParams(const Common::String &inputStr, Common::String &parameter, Common::String &values);
117 };
118 
119 } // End of namespace ZVision
120 
121 #endif
Definition: str.h:59
Definition: control.h:43
Definition: rect.h:144
Definition: path.h:52
Definition: stream.h:745
Definition: clock.h:29
Definition: video_decoder.h:53
Definition: rect.h:45
Definition: lever_control.h:38
Definition: list_intern.h:51
Definition: avi_frames.h:36