ScummVM API documentation
VectorRendererSpec.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_SPEC_H
23 #define VECTOR_RENDERER_SPEC_H
24 
25 #include "graphics/VectorRenderer.h"
26 
27 namespace Graphics {
28 
54 template<typename PixelType>
56  typedef VectorRenderer Base;
57 
58 public:
60 
61  void drawLine(int x1, int y1, int x2, int y2) override;
62  void drawCircle(int x, int y, int r) override;
63  void drawSquare(int x, int y, int w, int h) override;
64  void drawRoundedSquare(int x, int y, int r, int w, int h) override;
65  void drawTriangle(int x, int y, int base, int height, TriangleOrientation orient) override;
66  void drawTab(int x, int y, int r, int w, int h, int s) override;
67 
68  void drawBeveledSquare(int x, int y, int w, int h) override {
69  bool useClippingVersions = !_clippingArea.contains(Common::Rect(x, y, x + w, y + h));
70  if (useClippingVersions) {
71  drawBevelSquareAlgClip(x, y, w, h, _bevel, _bevelColor, _fgColor);
72  } else {
73  drawBevelSquareAlg(x, y, w, h, _bevel, _bevelColor, _fgColor);
74  }
75  }
76  void drawString(const Graphics::Font *font, const Common::U32String &text,
78  int deltax, bool elipsis, const Common::Rect &textDrawableArea = Common::Rect(0, 0, 0, 0)) override;
79 
80  void setFgColor(uint8 r, uint8 g, uint8 b) override { _fgColor = _format.RGBToColor(r, g, b); }
81  void setBgColor(uint8 r, uint8 g, uint8 b) override { _bgColor = _format.RGBToColor(r, g, b); }
82  void setBevelColor(uint8 r, uint8 g, uint8 b) override { _bevelColor = _format.RGBToColor(r, g, b); }
83  void setGradientColors(uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2) override;
84  void setClippingRect(const Common::Rect &clippingArea) override { _clippingArea = clippingArea; }
85 
86  void copyFrame(OSystem *sys, const Common::Rect &r) override;
87  void copyWholeFrame(OSystem *sys) override { copyFrame(sys, Common::Rect(0, 0, _activeSurface->w, _activeSurface->h)); }
88 
89  void fillSurface() override;
90  void blitSurface(const Graphics::ManagedSurface *source, const Common::Rect &r) override;
91  void blitManagedSurface(const Graphics::ManagedSurface *source, const Common::Point &p, Graphics::AlphaType alphaType) override;
92 
93  void applyScreenShading(GUI::ThemeEngine::ShadingStyle shadingStyle) override;
94 
95 protected:
96 
97  Common::Rect _clippingArea;
98 
107  inline void putPixel(int x, int y, PixelType color) {
108  PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(x, y);
109  *ptr = color;
110  }
111 
121  inline void blendPixel(int x, int y, PixelType color, uint8 alpha) {
122  blendPixelPtr((PixelType *)Base::_activeSurface->getBasePtr(x, y), color, alpha);
123  }
124 
137  inline void blendPixelPtr(PixelType *ptr, PixelType color, uint8 alpha);
138  inline void blendPixelPtrClip(PixelType *ptr, PixelType color, uint8 alpha, int x, int y);
139 
155  inline void blendPixelDestAlphaPtr(PixelType *ptr, PixelType color, uint8 alpha);
156 
157 
169  virtual void drawLineAlg(int x1, int y1, int x2, int y2,
170  uint dx, uint dy, PixelType color);
171 
172  virtual void drawLineAlgClip(int x1, int y1, int x2, int y2,
173  uint dx, uint dy, PixelType color);
174 
175  virtual void drawCircleAlg(int x, int y, int r,
176  PixelType color, FillMode fill_m);
177 
178  virtual void drawCircleAlgClip(int x, int y, int r,
179  PixelType color, FillMode fill_m);
180 
181  virtual void drawRoundedSquareAlg(int x1, int y1, int r, int w, int h,
182  PixelType color, FillMode fill_m);
183 
184  virtual void drawRoundedSquareAlgClip(int x1, int y1, int r, int w, int h,
185  PixelType color, FillMode fill_m);
186 
187  virtual void drawBorderRoundedSquareAlg(int x1, int y1, int r, int w, int h,
188  PixelType color, FillMode fill_m, uint8 alpha_t, uint8 alpha_r, uint8 alpha_b, uint8 alpha_l);
189 
190  virtual void drawBorderRoundedSquareAlgClip(int x1, int y1, int r, int w, int h,
191  PixelType color, FillMode fill_m, uint8 alpha_t, uint8 alpha_r, uint8 alpha_b, uint8 alpha_l);
192 
193  virtual void drawInteriorRoundedSquareAlg(int x1, int y1, int r, int w, int h,
194  PixelType color, FillMode fill_m);
195 
196  virtual void drawInteriorRoundedSquareAlgClip(int x1, int y1, int r, int w, int h,
197  PixelType color, FillMode fill_m);
198 
199  virtual void drawSquareAlg(int x, int y, int w, int h,
200  PixelType color, FillMode fill_m);
201 
202  virtual void drawSquareAlgClip(int x, int y, int w, int h,
203  PixelType color, FillMode fill_m);
204 
205  virtual void drawTriangleHorzAlg(int x, int y, int w, int h,
206  bool inverted, PixelType color, FillMode fill_m);
207 
208  virtual void drawTriangleHorzAlgClip(int x, int y, int w, int h,
209  bool inverted, PixelType color, FillMode fill_m);
210 
211  virtual void drawTriangleFastH(int x, int y, int size,
212  bool inverted, PixelType color, FillMode fill_m);
213 
214  virtual void drawTriangleVertAlg(int x, int y, int w, int h,
215  bool inverted, PixelType color, FillMode fill_m);
216 
217  virtual void drawTriangleVertAlgClip(int x, int y, int w, int h,
218  bool inverted, PixelType color, FillMode fill_m);
219 
220  virtual void drawTriangleFastV(int x, int y, int size,
221  bool inverted, PixelType color, FillMode fill_m);
222 
223  virtual void drawBevelSquareAlg(int x, int y, int w, int h,
224  int bevel, PixelType top_color, PixelType bottom_color);
225 
226  virtual void drawBevelSquareAlgClip(int x, int y, int w, int h,
227  int bevel, PixelType top_color, PixelType bottom_color);
228 
229  virtual void drawTabAlg(int x, int y, int w, int h, int r,
230  PixelType color, VectorRenderer::FillMode fill_m,
231  int baseLeft, int baseRight, bool vFlip);
232 
233  virtual void drawTabAlgClip(int x, int y, int w, int h, int r,
234  PixelType color, VectorRenderer::FillMode fill_m,
235  int baseLeft, int baseRight, bool vFlip);
236 
237  virtual void drawTabShadow(int x, int y, int w, int h, int r, int offset, uint32 shadowIntensity, bool vFlip);
238 
239  virtual void drawTabShadowClip(int x, int y, int w, int h, int r, int offset, uint32 shadowIntensity, bool vFlip);
240 
241  virtual void drawBevelTabAlg(int x, int y, int w, int h,
242  int bevel, PixelType topColor, PixelType bottomColor,
243  int baseLeft, int baseRight, bool vFlip);
244 
245  virtual void drawBevelTabAlgClip(int x, int y, int w, int h,
246  int bevel, PixelType topColor, PixelType bottomColor,
247  int baseLeft, int baseRight, bool vFlip);
248 
259  virtual void drawSquareShadow(int x, int y, int w, int h, int offset);
260  virtual void drawSquareShadowClip(int x, int y, int w, int h, int offset);
261  virtual void drawRoundedSquareShadow(int x, int y, int r, int w, int h, int offset, uint32 shadowIntensity);
262  virtual void drawRoundedSquareShadowClip(int x, int y, int r, int w, int h, int offset, uint32 shadowIntensity);
263 
273  inline PixelType calcGradient(uint32 pos, uint32 max);
274 
275  void precalcGradient(int h);
276  void gradientFill(PixelType *first, int width, int x, int y);
277  void gradientFillClip(PixelType *first, int width, int x, int y, int realX, int realY);
278 
289  inline void blendFill(PixelType *first, PixelType *last, PixelType color, uint8 alpha) {
290  while (first < last)
291  blendPixelPtr(first++, color, alpha);
292  }
293 
294  inline void blendFillClip(PixelType *first, PixelType *last, PixelType color, uint8 alpha, int realX, int realY) {
295  if (_clippingArea.top <= realY && realY < _clippingArea.bottom) {
296  while (first < last) {
297  if (_clippingArea.left <= realX && realX < _clippingArea.right)
298  blendPixelPtr(first++, color, alpha);
299  else
300  ++first;
301  ++realX;
302  }
303  }
304  }
305 
306  void darkenFill(PixelType *first, PixelType *last);
307  void darkenFillClip(PixelType *first, PixelType *last, int x, int y);
308 
309  const PixelFormat _format;
310  const PixelType _redMask, _greenMask, _blueMask, _alphaMask;
311 
312  PixelType _fgColor;
313  PixelType _bgColor;
315  PixelType _gradientStart;
316  PixelType _gradientEnd;
318  int _gradientBytes[3];
320  Common::Array<PixelType> _gradCache;
321  Common::Array<int> _gradIndexes;
322 
323  PixelType _bevelColor;
324 };
325 
326 
327 #ifndef DISABLE_FANCY_THEMES
328 
340 template<typename PixelType>
341 class VectorRendererAA : public VectorRendererSpec<PixelType> {
343 public:
345  }
346 
347 protected:
357  virtual void drawLineAlg(int x1, int y1, int x2, int y2, uint dx, uint dy, PixelType color);
358 
368  virtual void drawCircleAlg(int x, int y, int r, PixelType color, VectorRenderer::FillMode fill_m);
369 
377  virtual void drawRoundedSquareAlg(int x1, int y1, int r, int w, int h, PixelType color, VectorRenderer::FillMode fill_m);
378 
379  virtual void drawBorderRoundedSquareAlg(int x1, int y1, int r, int w, int h, PixelType color, VectorRenderer::FillMode fill_m, uint8 alpha_t, uint8 alpha_l, uint8 alpha_r, uint8 alpha_b);
380 
381  virtual void drawInteriorRoundedSquareAlg(int x1, int y1, int r, int w, int h, PixelType color, VectorRenderer::FillMode fill_m);
382 
383  virtual void drawRoundedSquareShadow(int x, int y, int r, int w, int h, int offset, uint32 shadowIntensity) {
384  Base::drawRoundedSquareShadow(x, y, r, w, h, offset, shadowIntensity);
385  }
386 
387  virtual void drawTabAlg(int x, int y, int w, int h, int r,
388  PixelType color, VectorRenderer::FillMode fill_m,
389  int baseLeft, int baseRight, bool vFlip);
390 };
391 #endif
392 
393 }
394 #endif
Definition: managed_surface.h:51
int16 & w
Definition: managed_surface.h:117
Definition: font.h:83
TextAlign
Definition: font.h:48
ShadingStyle
Function used to process areas other than the current dialog.
Definition: ThemeEngine.h:297
void copyWholeFrame(OSystem *sys) override
Definition: VectorRendererSpec.h:87
void drawCircle(int x, int y, int r) override
PixelType calcGradient(uint32 pos, uint32 max)
Definition: pixelformat.h:138
ManagedSurface * _activeSurface
Definition: VectorRenderer.h:552
bool contains(int16 x, int16 y) const
Definition: rect.h:210
int16 right
Definition: rect.h:146
TextAlignVertical
Vertical alignment of the text.
Definition: ThemeEngine.h:218
const void * getBasePtr(int x, int y) const
Definition: managed_surface.h:250
void setGradientColors(uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2) override
Definition: rect.h:144
void drawLine(int x1, int y1, int x2, int y2) override
Definition: VectorRendererSpec.h:341
Definition: VectorRenderer.h:139
void copyFrame(OSystem *sys, const Common::Rect &r) override
FillMode
Definition: VectorRenderer.h:149
void applyScreenShading(GUI::ThemeEngine::ShadingStyle shadingStyle) override
void blendPixel(int x, int y, PixelType color, uint8 alpha)
Definition: VectorRendererSpec.h:121
virtual void drawSquareShadow(int x, int y, int w, int h, int offset)
int16 & h
Definition: managed_surface.h:118
void drawRoundedSquare(int x, int y, int r, int w, int h) override
PixelType _fgColor
Definition: VectorRendererSpec.h:312
Definition: ustr.h:57
int _gradientBytes[3]
Definition: VectorRendererSpec.h:318
void drawTriangle(int x, int y, int base, int height, TriangleOrientation orient) override
Definition: formatinfo.h:28
virtual void drawLineAlg(int x1, int y1, int x2, int y2, uint dx, uint dy, PixelType color)
void blendFill(PixelType *first, PixelType *last, PixelType color, uint8 alpha)
Definition: VectorRendererSpec.h:289
Definition: rect.h:45
int16 left
Definition: rect.h:145
PixelType _bgColor
Definition: VectorRendererSpec.h:313
void drawTab(int x, int y, int r, int w, int h, int s) override
Definition: VectorRendererSpec.h:55
void setBgColor(uint8 r, uint8 g, uint8 b) override
Definition: VectorRendererSpec.h:81
void blendPixelPtr(PixelType *ptr, PixelType color, uint8 alpha)
void blendPixelDestAlphaPtr(PixelType *ptr, PixelType color, uint8 alpha)
PixelType _gradientEnd
Definition: VectorRendererSpec.h:316
Definition: commandLine.h:32
Definition: system.h:161
PixelType _gradientStart
Definition: VectorRendererSpec.h:315
void drawBeveledSquare(int x, int y, int w, int h) override
Definition: VectorRendererSpec.h:68
void blitSurface(const Graphics::ManagedSurface *source, const Common::Rect &r) override
void drawString(const Graphics::Font *font, const Common::U32String &text, const Common::Rect &area, Graphics::TextAlign alignH, GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool elipsis, const Common::Rect &textDrawableArea=Common::Rect(0, 0, 0, 0)) override
void setClippingRect(const Common::Rect &clippingArea) override
Definition: VectorRendererSpec.h:84
void drawSquare(int x, int y, int w, int h) override
void putPixel(int x, int y, PixelType color)
Definition: VectorRendererSpec.h:107
void setFgColor(uint8 r, uint8 g, uint8 b) override
Definition: VectorRendererSpec.h:80
uint32 RGBToColor(uint8 r, uint8 g, uint8 b) const
Definition: pixelformat.h:207
int _bevel
Definition: VectorRenderer.h:558