Speech bubbles can point down right.
[scummvm-innocent.git] / graphics / VectorRenderer.h
blob136a8d55b38535582575da4f5581cbb387159b4e
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_H
27 #define VECTOR_RENDERER_H
29 #include "common/scummsys.h"
30 #include "common/system.h"
32 #include "graphics/surface.h"
33 #include "graphics/pixelformat.h"
35 #include "gui/ThemeEngine.h"
37 namespace Graphics {
38 class VectorRenderer;
41 typedef void (VectorRenderer::*DrawingFunctionCallback)(const Common::Rect &, const Graphics::DrawStep &);
44 struct DrawStep {
45 struct Color {
46 uint8 r, g, b;
47 bool set;
49 Color fgColor; /**< Foreground color */
50 Color bgColor; /**< background color */
51 Color gradColor1; /**< gradient start*/
52 Color gradColor2; /**< gradient end */
53 Color bevelColor;
55 bool autoWidth, autoHeight;
56 int16 x, y, w, h; /**< width, height and position, if not measured automatically.
57 negative values mean counting from the opposite direction */
59 enum VectorAlignment {
60 kVectorAlignManual,
61 kVectorAlignLeft,
62 kVectorAlignRight,
63 kVectorAlignBottom,
64 kVectorAlignTop,
65 kVectorAlignCenter
68 VectorAlignment xAlign;
69 VectorAlignment yAlign;
71 uint8 shadow, stroke, factor, radius, bevel; /**< Misc options... */
73 uint8 fillMode; /**< active fill mode */
74 uint32 extraData; /**< Generic parameter for extra options (orientation/bevel) */
76 uint32 scale; /**< scale of all the coordinates in FIXED POINT with 16 bits mantissa */
78 DrawingFunctionCallback drawingCall; /**< Pointer to drawing function */
79 Graphics::Surface *blitSrc;
82 VectorRenderer *createRenderer(int mode);
84 /**
85 * VectorRenderer: The core Vector Renderer Class
87 * This virtual class exposes the API with all the vectorial
88 * rendering functions that may be used to draw on a given Surface.
90 * This class must be instantiated as one of its children, which implement
91 * the actual rendering functionality for each Byte Depth / Byte Format
92 * combination, and may also contain platform specific code.
94 * When specifying define DISABLE_FANCY_THEMES eye candy related code
95 * gets stripped off. This is especially useful for small devices like NDS.
97 * TODO: Expand documentation.
99 * @see VectorRendererSpec
100 * @see VectorRendererAA
102 class VectorRenderer {
103 public:
104 VectorRenderer() : _activeSurface(NULL), _fillMode(kFillDisabled), _shadowOffset(0),
105 _disableShadows(false), _strokeWidth(1), _gradientFactor(1) {
109 virtual ~VectorRenderer() {}
111 /** Specifies the way in which a shape is filled */
112 enum FillMode {
113 kFillDisabled = 0,
114 kFillForeground = 1,
115 kFillBackground = 2,
116 kFillGradient = 3
119 enum TriangleOrientation {
120 kTriangleAuto = 0,
121 kTriangleUp,
122 kTriangleDown,
123 kTriangleLeft,
124 kTriangleRight
128 * Draws a line by considering the special cases for optimization.
130 * @param x1 Horizontal (X) coordinate for the line start
131 * @param x2 Horizontal (X) coordinate for the line end
132 * @param y1 Vertical (Y) coordinate for the line start
133 * @param y2 Vertical (Y) coordinate for the line end
135 virtual void drawLine(int x1, int y1, int x2, int y2) = 0;
138 * Draws a circle centered at (x,y) with radius r.
140 * @param x Horizontal (X) coordinate for the center of the circle
141 * @param y Vertical (Y) coordinate for the center of the circle
142 * @param r Radius of the circle.
144 virtual void drawCircle(int x, int y, int r) = 0;
147 * Draws a square starting at (x,y) with the given width and height.
149 * @param x Horizontal (X) coordinate for the center of the square
150 * @param y Vertical (Y) coordinate for the center of the square
151 * @param w Width of the square.
152 * @param h Height of the square
154 virtual void drawSquare(int x, int y, int w, int h) = 0;
157 * Draws a rounded square starting at (x,y) with the given width and height.
158 * The corners of the square are rounded with the given radius.
160 * @param x Horizontal (X) coordinate for the center of the square
161 * @param y Vertical (Y) coordinate for the center of the square
162 * @param w Width of the square.
163 * @param h Height of the square
164 * @param r Radius of the corners.
166 virtual void drawRoundedSquare(int x, int y, int r, int w, int h) = 0;
169 * Draws a triangle starting at (x,y) with the given base and height.
170 * The triangle will always be isosceles, with the given base and height.
171 * The orientation parameter controls the position of the base of the triangle.
173 * @param x Horizontal (X) coordinate for the top left corner of the triangle
174 * @param y Vertical (Y) coordinate for the top left corner of the triangle
175 * @param base Width of the base of the triangle
176 * @param h Height of the triangle
177 * @param orient Orientation of the triangle.
179 virtual void drawTriangle(int x, int y, int base, int height, TriangleOrientation orient) = 0;
182 * Draws a beveled square like the ones in the Classic GUI themes.
183 * Beveled squares are always drawn with a transparent background. Draw them on top
184 * of a standard square to fill it.
186 * @param x Horizontal (X) coordinate for the center of the square
187 * @param y Vertical (Y) coordinate for the center of the square
188 * @param w Width of the square.
189 * @param h Height of the square
190 * @param bevel Amount of bevel. Must be positive.
192 virtual void drawBeveledSquare(int x, int y, int w, int h, int bevel) = 0;
195 * Draws a tab-like shape, specially thought for the Tab widget.
196 * If a radius is given, the tab will have rounded corners. Otherwise,
197 * the tab will be squared.
199 * @param x Horizontal (X) coordinate for the tab
200 * @param y Vertical (Y) coordinate for the tab
201 * @param w Width of the tab
202 * @param h Height of the tab
203 * @param r Radius of the corners of the tab (0 for squared tabs).
205 virtual void drawTab(int x, int y, int r, int w, int h) = 0;
209 * Simple helper function to draw a cross.
211 virtual void drawCross(int x, int y, int w, int h) {
212 drawLine(x, y, x + w, y + w);
213 drawLine(x + w, y, x, y + h);
217 * Set the active foreground painting color for the renderer.
218 * All the foreground drawing from then on will be done with that color, unless
219 * specified otherwise.
221 * Foreground drawing means all outlines and basic shapes.
223 * @param r value of the red color byte
224 * @param g value of the green color byte
225 * @param b value of the blue color byte
227 virtual void setFgColor(uint8 r, uint8 g, uint8 b) = 0;
230 * Set the active background painting color for the renderer.
231 * All the background drawing from then on will be done with that color, unless
232 * specified otherwise.
234 * Background drawing means all the shape filling.
236 * @param r value of the red color byte
237 * @param g value of the green color byte
238 * @param b value of the blue color byte
240 virtual void setBgColor(uint8 r, uint8 g, uint8 b) = 0;
242 virtual void setBevelColor(uint8 r, uint8 g, uint8 b) = 0;
245 * Set the active gradient color. All shapes drawn using kFillGradient
246 * as their fill mode will use this VERTICAL gradient as their fill color.
248 * @param r1 value of the red color byte for the start color
249 * @param g1 value of the green color byte for the start color
250 * @param b1 value of the blue color byte for the start color
251 * @param r2 value of the red color byte for the end color
252 * @param g2 value of the green color byte for the end color
253 * @param b2 value of the blue color byte for the end color
255 virtual void setGradientColors(uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2) = 0;
258 * Sets the active drawing surface. All drawing from this
259 * point on will be done on that surface.
261 * @param surface Pointer to a Surface object.
263 virtual void setSurface(Surface *surface) {
264 _activeSurface = surface;
268 * Fills the active surface with the specified fg/bg color or the active gradient.
269 * Defaults to using the active Foreground color for filling.
271 * @param mode Fill mode (bg, fg or gradient) used to fill the surface
273 virtual void fillSurface() = 0;
276 * Clears the active surface.
278 virtual void clearSurface() {
279 byte *src = (byte *)_activeSurface->pixels;
280 memset(src, 0, _activeSurface->pitch * _activeSurface->h);
284 * Sets the active fill mode for all shapes.
286 * @see VectorRenderer::FillMode
287 * @param mode Specified fill mode.
289 virtual void setFillMode(FillMode mode) {
290 _fillMode = mode;
294 * Sets the stroke width. All shapes drawn with a stroke will
295 * have that width. Pass 0 to disable shape stroking.
297 * @param width Width of the stroke in pixels.
299 virtual void setStrokeWidth(int width) {
300 _strokeWidth = width;
304 * Enables adding shadows to all drawn primitives.
305 * Shadows are drawn automatically under the shapes. The given offset
306 * controls their intensity and size (the higher the offset, the
307 * bigger the shadows). If the offset is 0, no shadows are drawn.
309 * @param offset Shadow offset.
311 virtual void setShadowOffset(int offset) {
312 if (offset >= 0)
313 _shadowOffset = offset;
316 virtual void setBevel(int amount) {
317 if (amount >= 0)
318 _bevel = amount;
322 * Sets the multiplication factor of the active gradient.
324 * @see _gradientFactor
325 * @param factor Multiplication factor.
327 virtual void setGradientFactor(int factor) {
328 if (factor > 0)
329 _gradientFactor = factor;
333 * Translates the position data inside a DrawStep into actual
334 * screen drawing positions.
336 void stepGetPositions(const DrawStep &step, const Common::Rect &area, uint16 &in_x, uint16 &in_y, uint16 &in_w, uint16 &in_h);
339 * Translates the radius data inside a drawstep into the real radius
340 * for the shape. Used for automatic radius calculations.
342 int stepGetRadius(const DrawStep &step, const Common::Rect &area);
345 * DrawStep callback functions for each drawing feature
347 void drawCallback_CIRCLE(const Common::Rect &area, const DrawStep &step) {
348 uint16 x, y, w, h, radius;
350 radius = stepGetRadius(step, area);
351 stepGetPositions(step, area, x, y, w, h);
353 drawCircle(x + radius, y + radius, radius);
356 void drawCallback_SQUARE(const Common::Rect &area, const DrawStep &step) {
357 uint16 x, y, w, h;
358 stepGetPositions(step, area, x, y, w, h);
359 drawSquare(x, y, w, h);
362 void drawCallback_LINE(const Common::Rect &area, const DrawStep &step) {
363 uint16 x, y, w, h;
364 stepGetPositions(step, area, x, y, w, h);
365 drawLine(x, y, x + w, y + w);
368 void drawCallback_ROUNDSQ(const Common::Rect &area, const DrawStep &step) {
369 uint16 x, y, w, h;
370 stepGetPositions(step, area, x, y, w, h);
371 drawRoundedSquare(x, y, stepGetRadius(step, area), w, h);
374 void drawCallback_FILLSURFACE(const Common::Rect &area, const DrawStep &step) {
375 fillSurface();
378 void drawCallback_TRIANGLE(const Common::Rect &area, const DrawStep &step) {
379 uint16 x, y, w, h;
380 stepGetPositions(step, area, x, y, w, h);
381 drawTriangle(x, y, w, h, (TriangleOrientation)step.extraData);
384 void drawCallback_BEVELSQ(const Common::Rect &area, const DrawStep &step) {
385 uint16 x, y, w, h;
386 stepGetPositions(step, area, x, y, w, h);
387 drawBeveledSquare(x, y, w, h, _bevel);
390 void drawCallback_TAB(const Common::Rect &area, const DrawStep &step) {
391 uint16 x, y, w, h;
392 stepGetPositions(step, area, x, y, w, h);
393 drawTab(x, y, stepGetRadius(step, area), w, h);
396 void drawCallback_BITMAP(const Common::Rect &area, const DrawStep &step) {
397 uint16 x, y, w, h;
398 stepGetPositions(step, area, x, y, w, h);
399 blitAlphaBitmap(step.blitSrc, Common::Rect(x, y, x + w, y + h));
402 void drawCallback_CROSS(const Common::Rect &area, const DrawStep &step) {
403 uint16 x, y, w, h;
404 stepGetPositions(step, area, x, y, w, h);
405 drawCross(x, y, w, h);
408 void drawCallback_VOID(const Common::Rect &area, const DrawStep &step) {}
411 * Draws the specified draw step on the screen.
413 * @see DrawStep
414 * @param area Zone to paint on
415 * @param step Pointer to a DrawStep struct.
417 virtual void drawStep(const Common::Rect &area, const DrawStep &step, uint32 extra = 0);
420 * Copies the part of the current frame to the system overlay.
422 * @param sys Pointer to the global System class
423 * @param r Zone of the surface to copy into the overlay.
425 virtual void copyFrame(OSystem *sys, const Common::Rect &r) = 0;
428 * Copies the current surface to the system overlay
430 * @param sys Pointer to the global System class
432 virtual void copyWholeFrame(OSystem *sys) = 0;
435 * Blits a given graphics surface on top of the current drawing surface.
437 * Note that the source surface and the active
438 * surface are expected to be of the same size, hence the area delimited
439 * by "r" in the source surface will be blitted into the area delimited by
440 * "r" on the current surface.
442 * If you wish to blit a smaller surface into the active drawing area, use
443 * VectorRenderer::blitSubSurface().
445 * @param source Surface to blit into the drawing surface.
446 * @param r Position in the active drawing surface to do the blitting.
448 virtual void blitSurface(const Graphics::Surface *source, const Common::Rect &r) = 0;
451 * Blits a given graphics surface into a small area of the current drawing surface.
453 * Note that the given surface is expected to be smaller than the
454 * active drawing surface, hence the WHOLE source surface will be
455 * blitted into the active surface, at the position specified by "r".
457 virtual void blitSubSurface(const Graphics::Surface *source, const Common::Rect &r) = 0;
459 virtual void blitAlphaBitmap(const Graphics::Surface *source, const Common::Rect &r) = 0;
462 * Draws a string into the screen. Wrapper for the Graphics::Font string drawing
463 * method.
465 virtual void drawString(const Graphics::Font *font, const Common::String &text,
466 const Common::Rect &area, Graphics::TextAlign alignH,
467 GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool useEllipsis) = 0;
470 * Allows to temporarily enable/disable all shadows drawing.
471 * i.e. for performance issues, blitting, etc
473 virtual void disableShadows() { _disableShadows = true; }
474 virtual void enableShadows() { _disableShadows = false; }
477 * Applies a whole-screen shading effect, used before opening a new dialog.
478 * Currently supports screen dimmings and luminance (b&w).
480 virtual void applyScreenShading(GUI::ThemeEngine::ShadingStyle) = 0;
482 protected:
483 Surface *_activeSurface; /**< Pointer to the surface currently being drawn */
485 FillMode _fillMode; /**< Defines in which way (if any) are filled the drawn shapes */
487 int _shadowOffset; /**< offset for drawn shadows */
488 int _bevel; /**< amount of fake bevel */
489 bool _disableShadows; /**< Disables temporarily shadow drawing for overlayed images. */
490 int _strokeWidth; /**< Width of the stroke of all drawn shapes */
491 uint32 _dynamicData; /**< Dynamic data from the GUI Theme that modifies the drawing of the current shape */
493 int _gradientFactor; /**< Multiplication factor of the active gradient */
494 int _gradientBytes[3]; /**< Color bytes of the active gradient, used to speed up calculation */
497 } // end of namespace Graphics
499 #endif