ScummVM API documentation
renderobject.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_RENDEROBJECT_H
23#define NANCY_RENDEROBJECT_H
24
25#include "common/path.h"
26#include "graphics/managed_surface.h"
27
28namespace Nancy {
29
30class NancyEngine;
31class GraphicsManager;
32
33// Nancy21 can zoom into the viewport, with everything in some of the streams
34// of scenes: what is drawn gets scaled around the top left of the viewport, then
35// moved by the offset, in viewport pixels
37 double scaleX = 1.0;
38 double scaleY = 1.0;
39 double offsetX = 0.0;
40 double offsetY = 0.0;
41
42 bool isIdentity() const { return scaleX == 1.0 && scaleY == 1.0 && offsetX == 0.0 && offsetY == 0.0; }
43};
44
45// Loosely equivalent to the original engine's ZRenderStructs.
46// A subclass of this will be automatically updated and drawn from the graphics manager,
47// but initialization needs to be done manually.
49public:
50 RenderObject(uint16 zOrder);
51 RenderObject(uint16 zOrder, Graphics::ManagedSurface &surface, const Common::Rect &srcBounds, const Common::Rect &destBounds);
52
53 virtual ~RenderObject();
54
55 RenderObject(RenderObject &&) = default;
56
57 virtual void init(); // Does not get called automatically
58 virtual void registerGraphics(); // Does not get called automatically
59 virtual void updateGraphics() {}
60
61 void moveTo(const Common::Point &position);
62 void moveTo(const Common::Rect &bounds);
63 void setVisible(bool visible);
64 void setTransparent(bool isTransparent);
65 bool isVisible() const { return _isVisible; }
66
67 // Where on the screen the object was the last time it got drawn; empty when it
68 // wasn't shown. The viewport can scroll since, which moves where the object
69 // would be now, but not what is on the screen.
70 const Common::Rect &getDrawnScreenPosition() const { return _drawnScreenPosition; }
71 void setDrawnScreenPosition(const Common::Rect &position) { _drawnScreenPosition = position; }
72
73 bool needsRedraw() const { return _needsRedraw; }
74 void setNeedsRedraw(bool needsRedraw) { _needsRedraw = needsRedraw; }
75
76 void setHasMoved(bool hasMoved) { _hasMoved = hasMoved; }
77
78 // Nancy16 scales the game up to fit the screen; these objects get drawn at the
79 // screen's own resolution instead, and are positioned in screen coordinates
80 bool isNativeResolution() const { return _isNativeResolution; }
81 void setNativeResolution(bool isNative) { _isNativeResolution = isNative; }
82
83 // Only used by The Vampire Diaries
84 void grabPalette(byte *colors, uint paletteStart = 0, uint paletteSize = 256);
85 void setPalette(const Common::Path &paletteName, uint paletteStart = 0, uint paletteSize = 256);
86 void setPalette(const byte *colors, uint paletteStart = 0, uint paletteSize = 256);
87
88 bool hasMoved() const { return _previousScreenPosition != _screenPosition; }
89 void updatePreviousScreenPosition() { _previousScreenPosition = _screenPosition; }
90
91 Common::Rect getScreenPosition() const;
92 Common::Rect getScreenPositionRaw() const { return _screenPosition; }
93 Common::Rect getPreviousScreenPosition() const;
94
95 // Given a screen-space rect, convert it to the _drawSurface's local space
96 Common::Rect convertToLocal(const Common::Rect &screen) const;
97 // Given a local (to the _drawSurface) space rect, convert it to screen space
98 Common::Rect convertToScreen(const Common::Rect &rect) const;
99
100 Common::Rect getBounds() const { return Common::Rect(_screenPosition.width(), _screenPosition.height()); }
101 uint16 getZOrder() const { return _z; }
102 // Also moves the object in the draw order, so changing the z of a registered
103 // object takes effect without re-registering it
104 void setZOrder(uint16 z);
105
106 Graphics::ManagedSurface _drawSurface;
107
108 // Needed for proper handling of objects inside the viewport
109 virtual bool isViewportRelative() const { return false; }
110
111 // The zoom the object gets drawn with, if any. It belongs to whoever set it.
112 const ViewTransform *getViewTransform() const { return _viewTransform; }
113 void setViewTransform(const ViewTransform *viewTransform) { _viewTransform = viewTransform; }
114 bool isZoomed() const { return _viewTransform && !_viewTransform->isIdentity(); }
115
116protected:
117 bool _needsRedraw;
118 bool _isVisible;
119 bool _hasMoved;
120 bool _isNativeResolution = false;
121 uint16 _z;
122 Common::Rect _drawnScreenPosition;
123 Common::Rect _previousScreenPosition;
124 Common::Rect _screenPosition;
125 const ViewTransform *_viewTransform = nullptr;
126};
127
128} // End of namespace Nancy
129
130#endif // NANCY_RENDEROBJECT_H
Definition: path.h:52
Definition: managed_surface.h:51
Definition: graphics.h:38
Definition: renderobject.h:48
Definition: actionmanager.h:32
Definition: rect.h:144
T height() const
Definition: rect.h:218
T width() const
Definition: rect.h:217
Definition: rect.h:536
Definition: renderobject.h:36