ScummVM API documentation
screen_overlay.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// ScreenOverlay is a simple sprite container with no advanced functions.
23// Contains an id of a sprite, which may be either owned by overlay, or shared
24// to whole game similar to how other objects use sprites.
25// May logically exist either on UI or room layer.
26// TODO: historically overlay objects contained an actual bitmap in them.
27// This was remade into having a dynamic sprite allocated exclusively for
28// overlay. But sprites do not have any kind of a ref count of their own
29// (unless exported into script as DynamicSprite), so we have to keep an
30// overlay's flag, which tells that the sprite it references must be deleted
31// on overlay's disposal. This should be improved at some point, by devising
32// a better kind of a sprite's ownership mechanic.
33
34#ifndef AGS_ENGINE_AC_SCREEN_OVERLAY_H
35#define AGS_ENGINE_AC_SCREEN_OVERLAY_H
36
37#include "common/std/memory.h"
38#include "ags/shared/core/types.h"
39#include "ags/shared/util/geometry.h"
40
41namespace AGS3 {
42
43// Forward declaration
44namespace AGS {
45namespace Shared {
46class Bitmap;
47class Stream;
48} // namespace Shared
49} // namespace AGS
50
51namespace AGS {
52namespace Engine {
53class IDriverDependantBitmap;
54} // namespace Engine
55} // namespace AGS
56
57using namespace AGS; // FIXME later
58
59enum OverlayFlags {
60 kOver_AlphaChannel = 0x0001,
61 kOver_PositionAtRoomXY = 0x0002, // room-relative position, may be in ui
62 kOver_RoomLayer = 0x0004, // work in room layer (as opposed to UI)
63 kOver_SpriteShared = 0x0008 // reference shared sprite (as opposed to exclusive)
64};
65
66enum OverlaySvgVersion {
67 kOverSvgVersion_Initial = 0,
68 kOverSvgVersion_35028 = 1, // offset x,y
69 kOverSvgVersion_36008 = 2, // z, transparency
70 kOverSvgVersion_36025 = 3, // merged options into flags
71 kOverSvgVersion_36108 = 4, // don't save owned sprites (use dynamic sprites)
72};
73
75 // Overlay's "type" is a merged special overlay ID and internal container index
76 int type = -1;
77 // Arbitrary creation order index, meant for resolving equal z-sorting
78 int creation_id = 0;
79 int timeout = 0;
80 // Note that x,y are overlay's properties, that define its position in script;
81 // but real drawn position is x + offsetX, y + offsetY;
82 int x = 0, y = 0;
83 // Border/padding offset for the tiled text windows
84 int offsetX = 0, offsetY = 0;
85 // Width and height to stretch the texture to
86 int scaleWidth = 0, scaleHeight = 0;
87 int bgSpeechForChar = -1;
88 int associatedOverlayHandle = 0; // script obj handle
89 int zorder = INT_MIN;
90 int transparency = 0;
91
92 ScreenOverlay() = default;
95 ScreenOverlay &operator=(ScreenOverlay &&);
96
97 // FIXME: These are private in the upstream repo,
98 // but Windows CI complains
99 ScreenOverlay(const ScreenOverlay &) = default;
100 ScreenOverlay &operator=(const ScreenOverlay &) = default;
101
102 bool HasAlphaChannel() const {
103 return (_flags & kOver_AlphaChannel) != 0;
104 }
105 bool IsSpriteShared() const {
106 return (_flags & kOver_SpriteShared) != 0;
107 }
108 bool IsRoomRelative() const {
109 return (_flags & kOver_PositionAtRoomXY) != 0;
110 }
111 bool IsRoomLayer() const {
112 return (_flags & kOver_RoomLayer) != 0;
113 }
114 void SetAlphaChannel(bool on) {
115 on ? _flags |= kOver_AlphaChannel : _flags &= ~kOver_AlphaChannel;
116 }
117 void SetRoomRelative(bool on) {
118 on ? _flags |= kOver_PositionAtRoomXY : _flags &= ~kOver_PositionAtRoomXY;
119 }
120 void SetRoomLayer(bool on) {
121 on ? _flags |= (kOver_RoomLayer | kOver_PositionAtRoomXY) :
122 _flags &= ~(kOver_RoomLayer | kOver_PositionAtRoomXY);
123 }
124 // Gets actual overlay's image, whether owned by overlay or by a sprite reference
125 Shared::Bitmap *GetImage() const;
126 // Get sprite reference id, or 0 if none set
127 int GetSpriteNum() const {
128 return _sprnum;
129 }
130 Size GetGraphicSize() const;
131 // Assigns an exclusive image to this overlay; the image will be stored as a dynamic sprite
132 // in a sprite cache, but owned by this overlay and therefore disposed at its disposal
133 void SetImage(std::unique_ptr<Shared::Bitmap> pic, bool has_alpha = false, int offx = 0, int offy = 0);
134 // Assigns a shared sprite to this overlay
135 void SetSpriteNum(int sprnum, int offx = 0, int offy = 0);
136 // Tells if Overlay has graphically changed recently
137 bool HasChanged() const {
138 return _hasChanged;
139 }
140 // Manually marks GUI as graphically changed
141 void MarkChanged() {
142 _hasChanged = true;
143 }
144 // Clears changed flag
145 void ClearChanged() {
146 _hasChanged = false;
147 }
148
149 void ReadFromSavegame(Shared::Stream *in, bool &has_bitmap, int32_t cmp_ver);
150 void WriteToSavegame(Shared::Stream *out) const;
151
152private:
153 void ResetImage();
154
155 int _flags = 0; // OverlayFlags
156 int _sprnum = 0; // sprite id
157 bool _hasChanged = false;
158};
159
160} // namespace AGS3
161
162#endif
Definition: allegro_bitmap.h:44
Definition: stream.h:52
Definition: ptr.h:572
Definition: engine.h:149
Definition: screen_overlay.h:74
Definition: geometry.h:148