ScummVM API documentation
graph.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 TWINE_SCENE_GRAPH_H
23#define TWINE_SCENE_GRAPH_H
24
25#include "graphics/screen.h"
26#include "twine/shared.h"
27
28namespace TwinE {
29
30// WARNING: Rewrite this function to have better performance
31inline bool drawGraph(int32 posX, int32 posY, const uint8 *pGraph, bool isSprite, Graphics::Screen &frontVideoBuffer, const Common::Rect &clip) { // AffGraph
32 if (!clip.isValidRect()) {
33 return false;
34 }
35
36 const int32 left = posX + pGraph[2];
37 if (left >= clip.right) {
38 return false;
39 }
40 const int32 top = posY + pGraph[3];
41 if (top >= clip.bottom) {
42 return false;
43 }
44 const int32 right = pGraph[0] + left;
45 if (right < clip.left) {
46 return false;
47 }
48 const int32 bottom = pGraph[1] + top;
49 if (bottom < clip.top) {
50 return false;
51 }
52 const int32 maxY = MIN(bottom, (int32)clip.bottom);
53
54 pGraph += 4; // skip the header
55
56 int32 x = left;
57
58 // if (left >= textWindowLeft-2 && top >= textWindowTop-2 && right <= textWindowRight-2 && bottom <= textWindowBottom-2) // crop
59 {
60 for (int32 y = top; y < maxY; ++y) {
61 const uint8 rleAmount = *pGraph++;
62 for (int32 run = 0; run < rleAmount; ++run) {
63 const uint8 rleMask = *pGraph++;
64 const uint8 iterations = bits(rleMask, 0, 6) + 1;
65 const uint8 opCode = bits(rleMask, 6, 2);
66 if (opCode == 0) {
67 x += iterations;
68 continue;
69 }
70 if (y < clip.top || x >= clip.right || x + iterations < clip.left) {
71 if (opCode == 1) {
72 pGraph += iterations;
73 } else {
74 ++pGraph;
75 }
76 x += iterations;
77 continue;
78 }
79 if (opCode == 1) { // 0x40
80 uint8 *out = (uint8 *)frontVideoBuffer.getBasePtr(x, y);
81 for (uint8 i = 0; i < iterations; i++) {
82 if (x >= clip.left && x < clip.right) {
83 *out = *pGraph;
84 }
85
86 ++out;
87 ++x;
88 ++pGraph;
89 }
90 } else {
91 const uint8 pixel = *pGraph++;
92 uint8 *out = (uint8 *)frontVideoBuffer.getBasePtr(x, y);
93 for (uint8 i = 0; i < iterations; i++) {
94 if (x >= clip.left && x < clip.right) {
95 *out = pixel;
96 }
97
98 ++out;
99 ++x;
100 }
101 }
102 }
103 x = left;
104 }
105 }
106
107 Common::Rect rect(left, top, right, bottom);
108 frontVideoBuffer.addDirtyRect(rect);
109
110 return true;
111}
112
113} // namespace TwinE
114
115#endif // TWINE_SCENE_GRAPH_H
const void * getBasePtr(int x, int y) const
Definition: managed_surface.h:252
Definition: screen.h:47
void addDirtyRect(const Common::Rect &r) override
T MIN(T a, T b)
Definition: util.h:63
Definition: rect.h:536