ScummVM API documentation
graphics.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_GRAPHICS_H
23#define NANCY_GRAPHICS_H
24
25#include "common/path.h"
26
27#include "graphics/screen.h"
28
29#include "engines/nancy/font.h"
30
31namespace Nancy {
32
33class IFF;
34class RenderObject;
35struct ScriptBootData;
36
37// Packed 0xAARRGGBB colors, independent of the byte order in memory
38extern const Graphics::PixelFormat kARGBFormat;
39
40// An ARGB color, as a pixel of the given format
41uint32 argbToColor(const Graphics::PixelFormat &format, uint32 argb);
42
43// Draws a pixel with straight alpha over what the surface already holds
44void blendPixel(Graphics::ManagedSurface &surface, int x, int y, byte a, byte r, byte g, byte b);
45
46// Nancy16 blends its colors as ARGB channels from 0 to 1, in that order. These convert
47// between a channel and the byte it gets drawn with, and between channels and colors.
48byte colorChannelToByte(float channel);
49void argbToChannels(uint32 argb, float *channels);
50uint32 channelsToArgb(const float *channels);
51
52// How much of the way toward a new color gets covered in the given time. Each 1/30
53// of a second, the color keeps the given rate of its distance to the target.
54float getBlendAmount(float seconds, float rate);
55
56// Moves an ARGB color toward the target; returns true when its bytes changed
57bool blendColor(float *current, uint32 target, float amount);
58
59// Nancy16+ font colors have one color for each state of a UI control
60enum FontColorState {
61 kFontColorNormal = 0,
62 kFontColorDisabled = 1,
63 kFontColorHidden = 2,
64 kFontColorFocus = 3,
65 kFontColorMouseOver = 4,
66 kFontColorPressed = 5,
67 kNumFontColorStates = 6
68};
69
70// Graphics class that handles multilayered surface rendering with minimal redraw
72public:
74
75 void init();
76 void draw(bool updateScreen = true);
77
78 void loadFonts(Common::SeekableReadStream *chunkStream);
79 void loadSystemFonts(const IFF &fontIFF);
80 void loadSystemFonts(const ScriptBootData &boot); // Nancy19+
81
82 void addObject(RenderObject *object);
83 void removeObject(RenderObject *object);
84 // Move an already-added object to its new place in the draw order
85 void reorderObject(RenderObject *object);
86 void clearObjects();
87
88 void redrawAll();
89 void suppressNextDraw();
90
91 const Font *getFont(uint id) const { return id < _fonts.size() ? &_fonts[id] : nullptr; }
92 const Font *getFont(const Common::String &name) const;
93 int getFontID(const Common::String &name) const;
94 uint32 getFontColor(uint id, const Graphics::PixelFormat &format, FontColorState state = kFontColorNormal) const;
95 const Graphics::Screen *getScreen() { return &_screen; }
96 static Common::Rect getScreenBounds();
97
98 // Nancy16 draws the game at a lower resolution than the screen's, and scales it up.
99 // Objects and the mouse are in game coordinates, unless they are at the screen's
100 // resolution. For the other games the two are the same.
101 bool isGameScaled() const { return !_gameSurface.empty(); }
102
103 // What the game drew last, at its own resolution
104 const Graphics::ManagedSurface &getGameImage() const { return isGameScaled() ? _gameSurface : _screen; }
105 Common::Rect getGameBounds() const;
106 Common::Point screenToGame(const Common::Point &pos) const;
107 Common::Point gameToScreen(const Common::Point &pos) const;
108 Common::Rect gameToScreen(const Common::Rect &rect) const;
109
110 const Graphics::PixelFormat &getInputPixelFormat(uint bpp = 0);
111 const Graphics::PixelFormat &getScreenPixelFormat();
112 const Graphics::PixelFormat &getTransparentPixelFormat();
113 uint32 getTransColor() { return _transColor; }
114
115 Graphics::ManagedSurface &getAutotextSurface(uint16 id) { return _autotextSurfaces.getOrCreateVal(id); }
116 Common::Rect &getAutotextSurfaceBounds(uint16 id) { return _autotextSurfaceBounds.getOrCreateVal(id); }
117
118 void grabViewportObjects(Common::Array<RenderObject *> &inArray);
119 void screenshotScreen(Graphics::ManagedSurface &inSurf);
120
121 static void loadSurfacePalette(Graphics::ManagedSurface &inSurf, const Common::Path &paletteFilename, uint paletteStart = 0, uint paletteSize = 256);
122 static void copyToManaged(const Graphics::Surface &src, Graphics::ManagedSurface &dst, bool verticalFlip = false, bool doubleSize = false);
123 static void copyToManaged(void *src, Graphics::ManagedSurface &dst, uint srcW, uint srcH, const Graphics::PixelFormat &format, bool verticalFlip = false, bool doubleSize = false);
124
125 static void rotateBlit(const Graphics::ManagedSurface &src, Graphics::ManagedSurface &dest, byte rotation);
126 static void crossDissolve(const Graphics::ManagedSurface &from, const Graphics::ManagedSurface &to, byte alpha, const Common::Rect &rect, Graphics::ManagedSurface &inResult);
127
128 bool getIsSuppressed() const { return _isSuppressed; }
129
130 // Debug
131 void debugDrawToScreen(const Graphics::ManagedSurface &surf);
132
134
135
136private:
137 enum Layer {
138 kLayerAll, // the game isn't scaled
139 kLayerGame,
140 kLayerNative
141 };
142
143 void addDirtyRect(const RenderObject &object, const Common::Rect &rect);
144 bool isInLayer(const RenderObject &object, Layer layer) const;
145 static void filterDirtyRects(Common::List<Common::Rect> &rects);
146 void drawObjects(Graphics::ManagedSurface &target, const Common::List<Common::Rect> &rects, Layer layer);
147 void blitObject(Graphics::ManagedSurface &target, const RenderObject &src, Common::Rect dest);
148
149 // Where an object gets drawn, which is somewhere else for one that is zoomed into
150 Common::Rect getDrawnPosition(const RenderObject &object) const;
151 void blitGameToScreen(Common::Rect screenRect);
152
153 static int objectComparator(const void *a, const void *b);
154
156
157 Graphics::PixelFormat _inputPixelFormat16, _inputPixelFormat24, _inputPixelFormat32;
158 Graphics::PixelFormat _screenPixelFormat16, _screenPixelFormat32;
159 Graphics::PixelFormat _clut8Format;
160 Graphics::PixelFormat _transparentPixelFormat;
161
162 Graphics::Screen _screen;
163 Common::Array<Font> _fonts;
164 struct FontColor {
165 uint32 colors[kNumFontColorStates] = {};
166 };
167
168 Common::Array<FontColor> _fontColors;
169
170 Graphics::ManagedSurface _gameSurface; // empty unless the game is scaled
171
172 Common::List<Common::Rect> _dirtyRects; // in game coordinates
173 Common::List<Common::Rect> _nativeDirtyRects; // in screen coordinates
174
176 Common::HashMap<uint16, Common::Rect> _autotextSurfaceBounds;
177
178 uint32 _transColor = 0;
179
180 bool _isSuppressed;
181 bool _wasZoomed = false; // whether something was zoomed into the last time
182};
183
184} // End of namespace Nancy
185
186#endif // NANCY_GRAPHICS_H
Definition: array.h:52
size_type size() const
Definition: array.h:316
Definition: path.h:52
Definition: stream.h:745
Definition: array.h:559
Definition: str.h:59
Definition: managed_surface.h:51
bool empty() const
Definition: managed_surface.h:214
Definition: screen.h:47
Definition: font.h:38
Definition: graphics.h:71
Definition: iff.h:35
Definition: renderobject.h:48
Val & getOrCreateVal(const Key &key)
Definition: hashmap.h:626
Definition: actionmanager.h:32
Definition: rect.h:144
Definition: rect.h:536
Definition: pixelformat.h:138
Definition: surface.h:67
Definition: enginedata.h:1095