ScummVM API documentation
VectorRenderer.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 VECTOR_RENDERER_H
23#define VECTOR_RENDERER_H
24
25#include "common/rect.h"
26#include "common/scummsys.h"
27#include "common/str.h"
28
29#include "graphics/managed_surface.h"
30
31#include "gui/ThemeEngine.h"
32
33class OSystem;
34
35namespace Graphics {
36class VectorRenderer;
37struct DrawStep;
38
48typedef void (VectorRenderer::*DrawingFunctionCallback)(const Common::Rect &, const Graphics::DrawStep &);
49
50
51struct DrawStep {
52 DrawingFunctionCallback drawingCall;
54 Graphics::AlphaType alphaType;
55
56 struct Color {
57 uint8 r, g, b;
58 bool set;
59
60 Color () : r(0), g(0), b(0), set(false) {}
61 };
66 Color bevelColor;
67
68 bool autoWidth, autoHeight;
69 int16 x, y, w, h;
72 Common::Rect padding;
75 enum VectorAlignment {
76 kVectorAlignManual,
77 kVectorAlignLeft,
78 kVectorAlignRight,
79 kVectorAlignBottom,
80 kVectorAlignTop,
81 kVectorAlignCenter
82 };
83
84 VectorAlignment xAlign;
85 VectorAlignment yAlign;
86
87 uint8 shadow, stroke, factor, radius, bevel;
89 uint8 fillMode;
92 uint32 extraData;
94 uint32 scale;
100 DrawStep() {
101 drawingCall = nullptr;
102 alphaType = Graphics::ALPHA_OPAQUE;
103 // fgColor, bgColor, gradColor1, gradColor2, bevelColor initialized by Color default constructor
104 autoWidth = autoHeight = false;
105 x = y = w = h = 0;
106 // padding initialized by Common::Rect default constructor
107 xAlign = yAlign = kVectorAlignManual;
108 shadow = stroke = factor = radius = bevel = 0;
109 fillMode = 0;
110 shadowFillMode = 0;
111 extraData = 0;
112 scale = 0;
113 shadowIntensity = 1 << 16;
115 }
116};
117
118VectorRenderer *createRenderer(int mode);
119
139public:
140 VectorRenderer() : _activeSurface(NULL), _fillMode(kFillDisabled), _shadowOffset(0), _shadowFillMode(kShadowExponential),
142
143 }
144
145 virtual ~VectorRenderer() {}
146
148 enum FillMode {
149 kFillDisabled = 0,
150 kFillForeground = 1,
151 kFillBackground = 2,
152 kFillGradient = 3
153 };
154
155 enum TriangleOrientation {
156 kTriangleAuto = 0,
157 kTriangleUp,
158 kTriangleDown,
159 kTriangleLeft,
160 kTriangleRight
161 };
162
163 enum ShadowFillMode {
164 kShadowLinear = 0,
165 kShadowExponential = 1
166 };
167
176 virtual void drawLine(int x1, int y1, int x2, int y2) = 0;
177
185 virtual void drawCircle(int x, int y, int r) = 0;
186
195 virtual void drawSquare(int x, int y, int w, int h) = 0;
196
207 virtual void drawRoundedSquare(int x, int y, int r, int w, int h) = 0;
208
220 virtual void drawTriangle(int x, int y, int base, int height, TriangleOrientation orient) = 0;
221
233 virtual void drawBeveledSquare(int x, int y, int w, int h) = 0;
234
247 virtual void drawTab(int x, int y, int r, int w, int h, int s) = 0;
248
252 virtual void drawCross(int x, int y, int w, int h) {
253 drawLine(x, y, x + w, y + w);
254 drawLine(x + w, y, x, y + h);
255 }
256
268 virtual void setFgColor(uint8 r, uint8 g, uint8 b) = 0;
269
281 virtual void setBgColor(uint8 r, uint8 g, uint8 b) = 0;
282
283 virtual void setBevelColor(uint8 r, uint8 g, uint8 b) = 0;
284
296 virtual void setGradientColors(uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2) = 0;
297
304 virtual void setSurface(ManagedSurface *surface) {
305 _activeSurface = surface;
306 }
307
312 return _activeSurface;
313 }
314
319 virtual void fillSurface() = 0;
320
324 virtual void clearSurface() {
325 byte *src = (byte *)_activeSurface->getPixels();
326 memset(src, 0, _activeSurface->pitch * _activeSurface->h);
327 }
328
335 virtual void setFillMode(FillMode mode) {
336 _fillMode = mode;
337 }
338
339 virtual void setShadowFillMode(ShadowFillMode mode) {
340 _shadowFillMode = mode;
341 }
342
349 virtual void setStrokeWidth(int width) {
350 _strokeWidth = width;
351 }
352
361 virtual void setShadowOffset(int offset) {
362 if (offset >= 0)
363 _shadowOffset = offset;
364 }
365
366 virtual void setBevel(int amount) {
367 if (amount >= 0)
368 _bevel = amount;
369 }
370
377 virtual void setGradientFactor(int factor) {
378 if (factor > 0)
379 _gradientFactor = factor;
380 }
381
387 virtual void setShadowIntensity(uint32 shadowIntensity) {
388 if (shadowIntensity > 0)
389 _shadowIntensity = shadowIntensity;
390 else
391 warning("setShadowIntensity(): zero intensity");
392 }
393
402 virtual void setClippingRect(const Common::Rect &clippingArea) = 0;
403
408 void stepGetPositions(const DrawStep &step, const Common::Rect &area, uint16 &in_x, uint16 &in_y, uint16 &in_w, uint16 &in_h);
409
414 int stepGetRadius(const DrawStep &step, const Common::Rect &area);
415
420
424 void drawCallback_CIRCLE(const Common::Rect &area, const DrawStep &step) {
425 uint16 x, y, w, h, radius;
426
427 radius = stepGetRadius(step, area);
428 stepGetPositions(step, area, x, y, w, h);
429
430 drawCircle(x + radius, y + radius, radius);
431 }
432
433 void drawCallback_SQUARE(const Common::Rect &area, const DrawStep &step) {
434 uint16 x, y, w, h;
435 stepGetPositions(step, area, x, y, w, h);
436 drawSquare(x, y, w, h);
437 }
438
439 void drawCallback_LINE(const Common::Rect &area, const DrawStep &step) {
440 uint16 x, y, w, h;
441 stepGetPositions(step, area, x, y, w, h);
442 drawLine(x, y, x + w, y + h);
443 }
444
445 void drawCallback_ROUNDSQ(const Common::Rect &area, const DrawStep &step) {
446 uint16 x, y, w, h;
447 stepGetPositions(step, area, x, y, w, h);
448 drawRoundedSquare(x, y, stepGetRadius(step, area), w, h);
449 }
450
451 void drawCallback_FILLSURFACE(const Common::Rect &area, const DrawStep &step) {
452 fillSurface();
453 }
454
455 void drawCallback_TRIANGLE(const Common::Rect &area, const DrawStep &step) {
456 uint16 x, y, w, h;
457 stepGetPositions(step, area, x, y, w, h);
458 drawTriangle(x, y, w, h, (TriangleOrientation)step.extraData);
459 }
460
461 void drawCallback_BEVELSQ(const Common::Rect &area, const DrawStep &step) {
462 uint16 x, y, w, h;
463 stepGetPositions(step, area, x, y, w, h);
464 drawBeveledSquare(x, y, w, h);
465 }
466
467 void drawCallback_TAB(const Common::Rect &area, const DrawStep &step) {
468 uint16 x, y, w, h;
469 stepGetPositions(step, area, x, y, w, h);
470 drawTab(x, y, stepGetRadius(step, area), w, h, step.shadow);
471 }
472
473 void drawCallback_BITMAP(const Common::Rect &area, const DrawStep &step) {
474 uint16 x, y, w, h;
475 stepGetPositions(step, area, x, y, w, h);
476 blitManagedSurface(step.blitSrc.get(), Common::Point(x, y), step.alphaType);
477 }
478
479 void drawCallback_CROSS(const Common::Rect &area, const DrawStep &step) {
480 uint16 x, y, w, h;
481 stepGetPositions(step, area, x, y, w, h);
482 drawCross(x, y, w, h);
483 }
484
485 void drawCallback_VOID(const Common::Rect &area, const DrawStep &step) {}
486
494 virtual void drawStep(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step, uint32 extra = 0);
495
502 virtual void copyFrame(OSystem *sys, const Common::Rect &r) = 0;
503
509 virtual void copyWholeFrame(OSystem *sys) = 0;
510
525 virtual void blitSurface(const Graphics::ManagedSurface *source, const Common::Rect &r) = 0;
526
527 virtual void blitManagedSurface(const Graphics::ManagedSurface *source, const Common::Point &p, Graphics::AlphaType alphaType) = 0;
528
533 virtual void drawString(const Graphics::Font *font, const Common::U32String &text,
534 const Common::Rect &area, Graphics::TextAlign alignH,
535 GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool useEllipsis, const Common::Rect &textDrawableArea) = 0;
536
541 virtual void disableShadows() { _disableShadows = true; }
542 virtual void enableShadows() { _disableShadows = false; }
543
549
550protected:
554 ShadowFillMode _shadowFillMode;
555
557 int _bevel;
564};
566} // End of namespace Graphics
567
568#endif
Definition: ustr.h:57
ShadingStyle
Function used to process areas other than the current dialog.
Definition: ThemeEngine.h:297
TextAlignVertical
Vertical alignment of the text.
Definition: ThemeEngine.h:218
AutoScaleMode
AlphaBitmap scale mode selector.
Definition: ThemeEngine.h:304
@ kAutoScaleNone
Use image dimensions.
Definition: ThemeEngine.h:305
Definition: font.h:83
Definition: managed_surface.h:51
int16 & h
Definition: managed_surface.h:135
int32 & pitch
Definition: managed_surface.h:136
void * getPixels()
Definition: managed_surface.h:271
Definition: VectorRenderer.h:138
virtual void drawBeveledSquare(int x, int y, int w, int h)=0
virtual void setFgColor(uint8 r, uint8 g, uint8 b)=0
virtual void setShadowOffset(int offset)
Definition: VectorRenderer.h:361
uint32 _shadowIntensity
Definition: VectorRenderer.h:563
FillMode _fillMode
Definition: VectorRenderer.h:553
virtual void setShadowIntensity(uint32 shadowIntensity)
Definition: VectorRenderer.h:387
virtual void setStrokeWidth(int width)
Definition: VectorRenderer.h:349
virtual void setClippingRect(const Common::Rect &clippingArea)=0
virtual void setGradientFactor(int factor)
Definition: VectorRenderer.h:377
virtual ManagedSurface * getActiveSurface()
Definition: VectorRenderer.h:311
FillMode
Definition: VectorRenderer.h:148
int _gradientFactor
Definition: VectorRenderer.h:562
virtual void drawCross(int x, int y, int w, int h)
Definition: VectorRenderer.h:252
Common::Rect applyStepClippingRect(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step)
virtual void setSurface(ManagedSurface *surface)
Definition: VectorRenderer.h:304
virtual void drawCircle(int x, int y, int r)=0
virtual void copyWholeFrame(OSystem *sys)=0
void drawCallback_CIRCLE(const Common::Rect &area, const DrawStep &step)
Definition: VectorRenderer.h:424
virtual void disableShadows()
Definition: VectorRenderer.h:541
virtual void drawLine(int x1, int y1, int x2, int y2)=0
virtual void drawString(const Graphics::Font *font, const Common::U32String &text, const Common::Rect &area, Graphics::TextAlign alignH, GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool useEllipsis, const Common::Rect &textDrawableArea)=0
virtual void applyScreenShading(GUI::ThemeEngine::ShadingStyle)=0
virtual void setBgColor(uint8 r, uint8 g, uint8 b)=0
virtual void fillSurface()=0
virtual void drawStep(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step, uint32 extra=0)
int _shadowOffset
Definition: VectorRenderer.h:556
virtual void copyFrame(OSystem *sys, const Common::Rect &r)=0
virtual void setFillMode(FillMode mode)
Definition: VectorRenderer.h:335
ManagedSurface * _activeSurface
Definition: VectorRenderer.h:551
int _bevel
Definition: VectorRenderer.h:557
int stepGetRadius(const DrawStep &step, const Common::Rect &area)
virtual void setGradientColors(uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2)=0
bool _disableShadows
Definition: VectorRenderer.h:558
virtual void blitSurface(const Graphics::ManagedSurface *source, const Common::Rect &r)=0
virtual void drawTriangle(int x, int y, int base, int height, TriangleOrientation orient)=0
uint32 _dynamicData
Definition: VectorRenderer.h:560
virtual void drawTab(int x, int y, int r, int w, int h, int s)=0
virtual void clearSurface()
Definition: VectorRenderer.h:324
virtual void drawSquare(int x, int y, int w, int h)=0
void stepGetPositions(const DrawStep &step, const Common::Rect &area, uint16 &in_x, uint16 &in_y, uint16 &in_w, uint16 &in_h)
int _strokeWidth
Definition: VectorRenderer.h:559
virtual void drawRoundedSquare(int x, int y, int r, int w, int h)=0
Definition: system.h:166
void warning(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
TextAlign
Definition: font.h:48
Definition: formatinfo.h:28
Definition: rect.h:144
Definition: rect.h:536
Definition: VectorRenderer.h:56
Definition: VectorRenderer.h:51
Color fgColor
Definition: VectorRenderer.h:62
Color gradColor2
Definition: VectorRenderer.h:65
Color bgColor
Definition: VectorRenderer.h:63
Common::Rect clip
Definition: VectorRenderer.h:73
uint32 extraData
Definition: VectorRenderer.h:92
Color gradColor1
Definition: VectorRenderer.h:64
GUI::ThemeEngine::AutoScaleMode autoscale
Definition: VectorRenderer.h:98
DrawingFunctionCallback drawingCall
Definition: VectorRenderer.h:52
uint8 bevel
Definition: VectorRenderer.h:87
uint32 scale
Definition: VectorRenderer.h:94
int16 h
Definition: VectorRenderer.h:69
uint8 shadowFillMode
Definition: VectorRenderer.h:90
uint8 fillMode
Definition: VectorRenderer.h:89
uint32 shadowIntensity
Definition: VectorRenderer.h:96