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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef TRECISION_GRAPHICS_H
24 #define TRECISION_GRAPHICS_H
25 
26 #include "common/rect.h"
27 #include "graphics/pixelformat.h"
28 #include "graphics/surface.h"
29 
30 namespace Common {
31 class SeekableReadStream;
32 }
33 
34 
35 namespace Trecision {
36 class TrecisionEngine;
37 
38 struct Font {
39 	int8 *_data;
40 	uint16 _width;
41 };
42 
43 class GraphicsManager {
44 	TrecisionEngine *_vm;
45 
46 	Graphics::Surface _screenBuffer;
47 	Graphics::Surface _background;
48 	Graphics::Surface _smkBackground;
49 	Graphics::Surface _leftInventoryArrow;
50 	Graphics::Surface _rightInventoryArrow;
51 	Graphics::Surface _inventoryIcons;
52 	Graphics::Surface _saveSlotThumbnails;
53 	Graphics::Surface _textureMat;
54 
55 	Graphics::PixelFormat _screenFormat;
56 	uint16 _bitMask[3];
57 	Font _fonts[256];
58 
59 	Common::List<Common::Rect> _dirtyRects;
60 
61 	const Graphics::PixelFormat _rgb555Format;
62 
63 	uint16 aliasing(uint32 val1, uint32 val2, uint8 num);
64 	void drawCharPixel(uint16 y, uint16 charLeft, uint16 charRight, Common::Rect rect, Common::Rect subtitleRect, uint16 color, Graphics::Surface *externalSurface = nullptr);
65 	void initCursor();
66 	void copyToScreenBufferInner(const Graphics::Surface *surface, int x, int y);
67 	void paintObjAnm(uint16 curBox);
68 	void drawObj(int index, bool mask, Common::Rect drawRect, Common::Rect drawObjRect, bool includeDirtyRect = true);
69 	void eraseObj(Common::Rect drawObjRect);
70 
71 public:
72 	GraphicsManager(TrecisionEngine *vm);
73 	~GraphicsManager();
74 
75 	bool init();
76 	void clearScreen();
77 	void copyToScreen(int x, int y, int w, int h);
78 	void copyToScreenBuffer(const Graphics::Surface *surface, int x, int y, const byte *palette);
79 	void blitToScreenBuffer(const Graphics::Surface *surface, int x, int y, const byte *palette, bool useSmkBg);
80 	void paintScreen(bool flag);
81 	void loadBackground(Common::SeekableReadStream *stream, uint16 width, uint16 height);
82 	void clearScreenBuffer();
83 	void clearScreenBufferTop();
84 	void clearScreenBufferInventory();
85 	void clearScreenBufferSaveSlotDescriptions();
86 	void drawLeftInventoryArrow(byte startLine);
87 	void drawRightInventoryArrow(byte startLine);
88 	void drawInventoryIcon(byte iconIndex, byte iconSlot, byte startLine);
89 	void drawSaveSlotThumbnail(byte iconIndex, byte iconSlot, byte startLine);
90 	void setSaveSlotThumbnail(byte iconSlot, const Graphics::Surface *thumbnail);
91 	void readSurface(Common::SeekableReadStream *stream, Graphics::Surface *surface, uint16 width, uint16 height, uint16 count = 1);
92 	void readTexture(Common::SeekableReadStream *stream);
93 	void drawTexturePixel(uint16 textureX, uint16 textureY, uint16 screenX, uint16 screenY);
94 
95 	uint16 convertToScreenFormat(uint16 color) const;
96 
97 	void shadow(uint16 x, uint16 y, uint8 num);
98 	void pixelAliasing(uint16 x, uint16 y);
99 	void dissolve();
100 
101 	void addDirtyRect(Common::Rect rect, bool translateRect);
102 
103 	uint16 getCharWidth(byte character);
104 	void drawChar(byte curChar, uint16 textColor, uint16 line, Common::Rect rect, Common::Rect subtitleRect, uint16 inc, Graphics::Surface *externalSurface);
105 
106 	bool isCursorVisible();
107 	void showCursor();
108 	void hideCursor();
109 
110 	void loadFont();
111 	void loadData();
112 	void showDemoPic();
113 
114 };
115 
116 } // End of namespace Trecision
117 #endif
118