Speech bubbles can point down right.
[scummvm-innocent.git] / graphics / VectorRendererSpec.h
blob07d37e184756ce6ded1dcf4c74d63337968060fe
1 /* ScummVM - Graphic Adventure Engine
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.
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.
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.
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.
21 * $URL$
22 * $Id$
26 #ifndef VECTOR_RENDERER_SPEC_H
27 #define VECTOR_RENDERER_SPEC_H
29 #include "graphics/VectorRenderer.h"
31 namespace Graphics {
33 /**
34 * VectorRendererSpec: Specialized Vector Renderer Class
36 * This templated class implements the basic subset of vector operations for
37 * all platforms by allowing the user to provide the actual Pixel Type and
38 * pixel information structs.
40 * This class takes two template parameters:
42 * @param PixelType Defines a type which may hold the color value of a single
43 * pixel, such as "byte" or "uint16" for 8 and 16 BPP respectively.
45 * TODO: Expand documentation.
47 * @see VectorRenderer
49 template<typename PixelType>
50 class VectorRendererSpec : public VectorRenderer {
51 typedef VectorRenderer Base;
53 public:
54 VectorRendererSpec(PixelFormat format);
56 void drawLine(int x1, int y1, int x2, int y2);
57 void drawCircle(int x, int y, int r);
58 void drawSquare(int x, int y, int w, int h);
59 void drawRoundedSquare(int x, int y, int r, int w, int h);
60 void drawTriangle(int x, int y, int base, int height, TriangleOrientation orient);
61 void drawTab(int x, int y, int r, int w, int h);
62 void drawBeveledSquare(int x, int y, int w, int h, int bevel) {
63 drawBevelSquareAlg(x, y, w, h, bevel, _bevelColor, _fgColor, Base::_fillMode != kFillDisabled);
65 void drawString(const Graphics::Font *font, const Common::String &text,
66 const Common::Rect &area, Graphics::TextAlign alignH,
67 GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool elipsis);
69 void setFgColor(uint8 r, uint8 g, uint8 b) { _fgColor = _format.RGBToColor(r, g, b); }
70 void setBgColor(uint8 r, uint8 g, uint8 b) { _bgColor = _format.RGBToColor(r, g, b); }
71 void setBevelColor(uint8 r, uint8 g, uint8 b) { _bevelColor = _format.RGBToColor(r, g, b); }
72 void setGradientColors(uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2);
74 void copyFrame(OSystem *sys, const Common::Rect &r);
75 void copyWholeFrame(OSystem *sys) { copyFrame(sys, Common::Rect(0, 0, _activeSurface->w, _activeSurface->h)); }
77 void fillSurface();
78 void blitSurface(const Graphics::Surface *source, const Common::Rect &r);
79 void blitSubSurface(const Graphics::Surface *source, const Common::Rect &r);
80 void blitAlphaBitmap(const Graphics::Surface *source, const Common::Rect &r);
82 void applyScreenShading(GUI::ThemeEngine::ShadingStyle shadingStyle);
84 protected:
86 /**
87 * Draws a single pixel on the surface with the given coordinates and
88 * the given color.
90 * @param x Horizontal coordinate of the pixel.
91 * @param y Vertical coordinate of the pixel.
92 * @param color Color of the pixel
94 inline void putPixel(int x, int y, PixelType color) {
95 PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(x, y);
96 *ptr = color;
99 /**
100 * Blends a single pixel on the surface with the given coordinates, color
101 * and Alpha intensity.
103 * @param x Horizontal coordinate of the pixel.
104 * @param y Vertical coordinate of the pixel.
105 * @param color Color of the pixel
106 * @param alpha Alpha intensity of the pixel (0-255)
108 inline void blendPixel(int x, int y, PixelType color, uint8 alpha) {
109 blendPixelPtr((PixelType*)Base::_activeSurface->getBasePtr(x, y), color, alpha);
113 * Blends a single pixel on the surface in the given pixel pointer, using supplied color
114 * and Alpha intensity.
116 * This is implemented to prevent blendPixel() to calculate the surface pointer on each call.
117 * Optimized drawing algorithms should call this function when possible.
119 * @see blendPixel
120 * @param ptr Pointer to the pixel to blend on top of
121 * @param color Color of the pixel
122 * @param alpha Alpha intensity of the pixel (0-255)
124 inline void blendPixelPtr(PixelType *ptr, PixelType color, uint8 alpha);
127 * PRIMITIVE DRAWING ALGORITHMS
129 * Generic algorithms for drawing all kinds of aliased primitive shapes.
130 * These may be overloaded in inheriting classes to implement platform-specific
131 * optimizations or improve looks.
133 * @see VectorRendererAA
134 * @see VectorRendererAA::drawLineAlg
135 * @see VectorRendererAA::drawCircleAlg
137 virtual void drawLineAlg(int x1, int y1, int x2, int y2,
138 int dx, int dy, PixelType color);
140 virtual void drawCircleAlg(int x, int y, int r,
141 PixelType color, FillMode fill_m);
143 virtual void drawRoundedSquareAlg(int x1, int y1, int r, int w, int h,
144 PixelType color, FillMode fill_m);
146 virtual void drawSquareAlg(int x, int y, int w, int h,
147 PixelType color, FillMode fill_m);
149 virtual void drawTriangleVertAlg(int x, int y, int w, int h,
150 bool inverted, PixelType color, FillMode fill_m);
152 virtual void drawTriangleFast(int x, int y, int size,
153 bool inverted, PixelType color, FillMode fill_m);
155 virtual void drawBevelSquareAlg(int x, int y, int w, int h,
156 int bevel, PixelType top_color, PixelType bottom_color, bool fill);
158 virtual void drawTabAlg(int x, int y, int w, int h, int r,
159 PixelType color, VectorRenderer::FillMode fill_m,
160 int baseLeft = 0, int baseRight = 0);
162 virtual void drawBevelTabAlg(int x, int y, int w, int h,
163 int bevel, PixelType topColor, PixelType bottomColor,
164 int baseLeft = 0, int baseRight = 0);
167 * SHADOW DRAWING ALGORITHMS
169 * Optimized versions of the primitive drawing algorithms with alpha blending
170 * for shadow drawing.
171 * There functions may be overloaded in inheriting classes to improve performance
172 * in the slowest platforms where pixel alpha blending just doesn't cut it.
174 * @param blur Intensity/size of the shadow.
176 virtual void drawSquareShadow(int x, int y, int w, int h, int blur);
177 virtual void drawRoundedSquareShadow(int x, int y, int r, int w, int h, int blur);
178 virtual void drawRoundedSquareFakeBevel(int x, int y, int r, int w, int h, int amount);
181 * Calculates the color gradient on a given point.
182 * This function assumes that the gradient start/end colors have been set
183 * beforehand from the API function call.
185 * @param pos Progress of the gradient.
186 * @param max Maximum amount of the progress.
187 * @return Composite color of the gradient at the given "progress" amount.
189 inline PixelType calcGradient(uint32 pos, uint32 max);
192 * Fills several pixels in a row with a given color and the specified alpha blending.
194 * @see blendPixelPtr
195 * @see blendPixel
196 * @param first Pointer to the first pixel to fill.
197 * @param last Pointer to the last pixel to fill.
198 * @param color Color of the pixel
199 * @param alpha Alpha intensity of the pixel (0-255)
201 inline void blendFill(PixelType *first, PixelType *last, PixelType color, uint8 alpha) {
202 while (first != last) blendPixelPtr(first++, color, alpha);
205 const PixelFormat _format;
206 const PixelType _redMask, _greenMask, _blueMask, _alphaMask;
208 PixelType _fgColor; /**< Foreground color currently being used to draw on the renderer */
209 PixelType _bgColor; /**< Background color currently being used to draw on the renderer */
211 PixelType _gradientStart; /**< Start color for the fill gradient */
212 PixelType _gradientEnd; /**< End color for the fill gradient */
214 PixelType _bevelColor;
215 PixelType _bitmapAlphaColor;
219 #ifndef DISABLE_FANCY_THEMES
221 * VectorRendererAA: Anti-Aliased Vector Renderer Class
223 * This templated class inherits all the functionality of the VectorRendererSpec
224 * class but uses better looking yet slightly slower AA algorithms for drawing
225 * most primitives. May be used in faster platforms.
227 * TODO: Expand documentation.
229 * @see VectorRenderer
230 * @see VectorRendererSpec
232 template<typename PixelType>
233 class VectorRendererAA : public VectorRendererSpec<PixelType> {
234 typedef VectorRendererSpec<PixelType> Base;
235 public:
236 VectorRendererAA(PixelFormat format) : VectorRendererSpec<PixelType>(format) {
239 protected:
241 * "Wu's Line Antialiasing Algorithm" as published by Xiaolin Wu, July 1991
242 * Based on the implementation found in Michael Abrash's Graphics Programming Black Book.
244 * Generic line drawing algorithm for the Antialiased renderer. Optimized with no
245 * floating point operations, assumes no special cases.
247 * @see VectorRenderer::drawLineAlg()
249 virtual void drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy, PixelType color);
252 * "Wu's Circle Antialiasing Algorithm" as published by Xiaolin Wu, July 1991
253 * Based on the theoretical concept of the algorithm.
255 * Implementation of Wu's algorithm for circles using fixed point arithmetics.
256 * Could be quite fast.
258 * @see VectorRenderer::drawCircleAlg()
260 virtual void drawCircleAlg(int x, int y, int r, PixelType color, VectorRenderer::FillMode fill_m);
263 * "Wu's Circle Antialiasing Algorithm" as published by Xiaolin Wu, July 1991,
264 * modified with corner displacement to allow drawing of squares with rounded
265 * corners.
267 * @see VectorRenderer::drawRoundedAlg()
269 virtual void drawRoundedSquareAlg(int x1, int y1, int r, int w, int h, PixelType color, VectorRenderer::FillMode fill_m);
271 virtual void drawRoundedSquareShadow(int x, int y, int r, int w, int h, int blur) {
272 Base::drawRoundedSquareShadow(x, y, r, w, h, blur);
273 // VectorRenderer::applyConvolutionMatrix(VectorRenderer::kConvolutionHardBlur,
274 // Common::Rect(x, y, x + w + blur * 2, y + h + blur * 2));
277 #endif
280 #endif