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 
33 class OSystem;
34 
35 namespace Graphics {
36 class VectorRenderer;
37 struct DrawStep;
38 
48 typedef void (VectorRenderer::*DrawingFunctionCallback)(const Common::Rect &, const Graphics::DrawStep &);
49 
50 
51 struct DrawStep {
52  DrawingFunctionCallback drawingCall;
53  Graphics::ManagedSurface *blitSrc;
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;
73  Common::Rect clip;
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;
96  uint32 shadowIntensity;
100  DrawStep() {
101  drawingCall = nullptr;
102  blitSrc = nullptr;
103  alphaType = Graphics::ALPHA_OPAQUE;
104  // fgColor, bgColor, gradColor1, gradColor2, bevelColor initialized by Color default constructor
105  autoWidth = autoHeight = false;
106  x = y = w = h = 0;
107  // padding initialized by Common::Rect default constructor
108  xAlign = yAlign = kVectorAlignManual;
109  shadow = stroke = factor = radius = bevel = 0;
110  fillMode = 0;
111  shadowFillMode = 0;
112  extraData = 0;
113  scale = 0;
114  shadowIntensity = 1 << 16;
116  }
117 };
118 
119 VectorRenderer *createRenderer(int mode);
120 
140 public:
141  VectorRenderer() : _activeSurface(NULL), _fillMode(kFillDisabled), _shadowOffset(0), _shadowFillMode(kShadowExponential),
142  _disableShadows(false), _strokeWidth(1), _gradientFactor(1), _bevel(0), _dynamicData(0) {
143 
144  }
145 
146  virtual ~VectorRenderer() {}
147 
149  enum FillMode {
150  kFillDisabled = 0,
151  kFillForeground = 1,
152  kFillBackground = 2,
153  kFillGradient = 3
154  };
155 
156  enum TriangleOrientation {
157  kTriangleAuto = 0,
158  kTriangleUp,
159  kTriangleDown,
160  kTriangleLeft,
161  kTriangleRight
162  };
163 
164  enum ShadowFillMode {
165  kShadowLinear = 0,
166  kShadowExponential = 1
167  };
168 
177  virtual void drawLine(int x1, int y1, int x2, int y2) = 0;
178 
186  virtual void drawCircle(int x, int y, int r) = 0;
187 
196  virtual void drawSquare(int x, int y, int w, int h) = 0;
197 
208  virtual void drawRoundedSquare(int x, int y, int r, int w, int h) = 0;
209 
221  virtual void drawTriangle(int x, int y, int base, int height, TriangleOrientation orient) = 0;
222 
234  virtual void drawBeveledSquare(int x, int y, int w, int h) = 0;
235 
248  virtual void drawTab(int x, int y, int r, int w, int h, int s) = 0;
249 
253  virtual void drawCross(int x, int y, int w, int h) {
254  drawLine(x, y, x + w, y + w);
255  drawLine(x + w, y, x, y + h);
256  }
257 
269  virtual void setFgColor(uint8 r, uint8 g, uint8 b) = 0;
270 
282  virtual void setBgColor(uint8 r, uint8 g, uint8 b) = 0;
283 
284  virtual void setBevelColor(uint8 r, uint8 g, uint8 b) = 0;
285 
297  virtual void setGradientColors(uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2) = 0;
298 
305  virtual void setSurface(ManagedSurface *surface) {
306  _activeSurface = surface;
307  }
308 
313  return _activeSurface;
314  }
315 
320  virtual void fillSurface() = 0;
321 
325  virtual void clearSurface() {
326  byte *src = (byte *)_activeSurface->getPixels();
327  memset(src, 0, _activeSurface->pitch * _activeSurface->h);
328  }
329 
336  virtual void setFillMode(FillMode mode) {
337  _fillMode = mode;
338  }
339 
340  virtual void setShadowFillMode(ShadowFillMode mode) {
341  _shadowFillMode = mode;
342  }
343 
350  virtual void setStrokeWidth(int width) {
351  _strokeWidth = width;
352  }
353 
362  virtual void setShadowOffset(int offset) {
363  if (offset >= 0)
364  _shadowOffset = offset;
365  }
366 
367  virtual void setBevel(int amount) {
368  if (amount >= 0)
369  _bevel = amount;
370  }
371 
378  virtual void setGradientFactor(int factor) {
379  if (factor > 0)
380  _gradientFactor = factor;
381  }
382 
388  virtual void setShadowIntensity(uint32 shadowIntensity) {
389  if (shadowIntensity > 0)
390  _shadowIntensity = shadowIntensity;
391  else
392  warning("setShadowIntensity(): zero intensity");
393  }
394 
403  virtual void setClippingRect(const Common::Rect &clippingArea) = 0;
404 
409  void stepGetPositions(const DrawStep &step, const Common::Rect &area, uint16 &in_x, uint16 &in_y, uint16 &in_w, uint16 &in_h);
410 
415  int stepGetRadius(const DrawStep &step, const Common::Rect &area);
416 
420  Common::Rect applyStepClippingRect(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step);
421 
425  void drawCallback_CIRCLE(const Common::Rect &area, const DrawStep &step) {
426  uint16 x, y, w, h, radius;
427 
428  radius = stepGetRadius(step, area);
429  stepGetPositions(step, area, x, y, w, h);
430 
431  drawCircle(x + radius, y + radius, radius);
432  }
433 
434  void drawCallback_SQUARE(const Common::Rect &area, const DrawStep &step) {
435  uint16 x, y, w, h;
436  stepGetPositions(step, area, x, y, w, h);
437  drawSquare(x, y, w, h);
438  }
439 
440  void drawCallback_LINE(const Common::Rect &area, const DrawStep &step) {
441  uint16 x, y, w, h;
442  stepGetPositions(step, area, x, y, w, h);
443  drawLine(x, y, x + w, y + h);
444  }
445 
446  void drawCallback_ROUNDSQ(const Common::Rect &area, const DrawStep &step) {
447  uint16 x, y, w, h;
448  stepGetPositions(step, area, x, y, w, h);
449  drawRoundedSquare(x, y, stepGetRadius(step, area), w, h);
450  }
451 
452  void drawCallback_FILLSURFACE(const Common::Rect &area, const DrawStep &step) {
453  fillSurface();
454  }
455 
456  void drawCallback_TRIANGLE(const Common::Rect &area, const DrawStep &step) {
457  uint16 x, y, w, h;
458  stepGetPositions(step, area, x, y, w, h);
459  drawTriangle(x, y, w, h, (TriangleOrientation)step.extraData);
460  }
461 
462  void drawCallback_BEVELSQ(const Common::Rect &area, const DrawStep &step) {
463  uint16 x, y, w, h;
464  stepGetPositions(step, area, x, y, w, h);
465  drawBeveledSquare(x, y, w, h);
466  }
467 
468  void drawCallback_TAB(const Common::Rect &area, const DrawStep &step) {
469  uint16 x, y, w, h;
470  stepGetPositions(step, area, x, y, w, h);
471  drawTab(x, y, stepGetRadius(step, area), w, h, step.shadow);
472  }
473 
474  void drawCallback_BITMAP(const Common::Rect &area, const DrawStep &step) {
475  uint16 x, y, w, h;
476  stepGetPositions(step, area, x, y, w, h);
477  blitManagedSurface(step.blitSrc, Common::Point(x, y), step.alphaType);
478  }
479 
480  void drawCallback_CROSS(const Common::Rect &area, const DrawStep &step) {
481  uint16 x, y, w, h;
482  stepGetPositions(step, area, x, y, w, h);
483  drawCross(x, y, w, h);
484  }
485 
486  void drawCallback_VOID(const Common::Rect &area, const DrawStep &step) {}
487 
495  virtual void drawStep(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step, uint32 extra = 0);
496 
503  virtual void copyFrame(OSystem *sys, const Common::Rect &r) = 0;
504 
510  virtual void copyWholeFrame(OSystem *sys) = 0;
511 
526  virtual void blitSurface(const Graphics::ManagedSurface *source, const Common::Rect &r) = 0;
527 
528  virtual void blitManagedSurface(const Graphics::ManagedSurface *source, const Common::Point &p, Graphics::AlphaType alphaType) = 0;
529 
534  virtual void drawString(const Graphics::Font *font, const Common::U32String &text,
535  const Common::Rect &area, Graphics::TextAlign alignH,
536  GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool useEllipsis, const Common::Rect &textDrawableArea) = 0;
537 
542  virtual void disableShadows() { _disableShadows = true; }
543  virtual void enableShadows() { _disableShadows = false; }
544 
549  virtual void applyScreenShading(GUI::ThemeEngine::ShadingStyle) = 0;
550 
551 protected:
555  ShadowFillMode _shadowFillMode;
556 
558  int _bevel;
561  uint32 _dynamicData;
565 };
567 } // End of namespace Graphics
568 
569 #endif
Definition: managed_surface.h:51
uint32 _dynamicData
Definition: VectorRenderer.h:561
Color gradColor1
Definition: VectorRenderer.h:64
Definition: VectorRenderer.h:51
Definition: font.h:83
TextAlign
Definition: font.h:48
ShadingStyle
Function used to process areas other than the current dialog.
Definition: ThemeEngine.h:297
Definition: VectorRenderer.h:56
uint8 bevel
Definition: VectorRenderer.h:87
AutoScaleMode
AlphaBitmap scale mode selector.
Definition: ThemeEngine.h:304
Color bgColor
Definition: VectorRenderer.h:63
int _strokeWidth
Definition: VectorRenderer.h:560
void warning(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
ManagedSurface * _activeSurface
Definition: VectorRenderer.h:552
TextAlignVertical
Vertical alignment of the text.
Definition: ThemeEngine.h:218
GUI::ThemeEngine::AutoScaleMode autoscale
Definition: VectorRenderer.h:98
virtual void setShadowOffset(int offset)
Definition: VectorRenderer.h:362
virtual void setGradientFactor(int factor)
Definition: VectorRenderer.h:378
Definition: rect.h:144
virtual void setFillMode(FillMode mode)
Definition: VectorRenderer.h:336
DrawingFunctionCallback drawingCall
Definition: VectorRenderer.h:52
Definition: VectorRenderer.h:139
FillMode
Definition: VectorRenderer.h:149
uint32 extraData
Definition: VectorRenderer.h:92
FillMode _fillMode
Definition: VectorRenderer.h:554
uint32 scale
Definition: VectorRenderer.h:94
Definition: ustr.h:57
int _gradientFactor
Definition: VectorRenderer.h:563
virtual void drawCross(int x, int y, int w, int h)
Definition: VectorRenderer.h:253
virtual void setShadowIntensity(uint32 shadowIntensity)
Definition: VectorRenderer.h:388
virtual ManagedSurface * getActiveSurface()
Definition: VectorRenderer.h:312
Definition: formatinfo.h:28
Definition: rect.h:45
virtual void setStrokeWidth(int width)
Definition: VectorRenderer.h:350
Use image dimensions.
Definition: ThemeEngine.h:305
virtual void setSurface(ManagedSurface *surface)
Definition: VectorRenderer.h:305
uint32 _shadowIntensity
Definition: VectorRenderer.h:564
uint8 shadowFillMode
Definition: VectorRenderer.h:90
bool _disableShadows
Definition: VectorRenderer.h:559
void drawCallback_CIRCLE(const Common::Rect &area, const DrawStep &step)
Definition: VectorRenderer.h:425
virtual void clearSurface()
Definition: VectorRenderer.h:325
Color fgColor
Definition: VectorRenderer.h:62
int _shadowOffset
Definition: VectorRenderer.h:557
virtual void disableShadows()
Definition: VectorRenderer.h:542
Definition: system.h:161
uint32 shadowIntensity
Definition: VectorRenderer.h:96
int16 h
Definition: VectorRenderer.h:69
Color gradColor2
Definition: VectorRenderer.h:65
uint8 fillMode
Definition: VectorRenderer.h:89
Common::Rect clip
Definition: VectorRenderer.h:73
int _bevel
Definition: VectorRenderer.h:558