ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

VectorRenderer.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef VECTOR_RENDERER_H
00024 #define VECTOR_RENDERER_H
00025 
00026 #include "common/rect.h"
00027 #include "common/scummsys.h"
00028 #include "common/str.h"
00029 
00030 #include "graphics/surface.h"
00031 #include "graphics/transparent_surface.h"
00032 
00033 #include "gui/ThemeEngine.h"
00034 
00035 class OSystem;
00036 
00037 namespace Graphics {
00038 class VectorRenderer;
00039 struct DrawStep;
00040 
00041 
00042 typedef void (VectorRenderer::*DrawingFunctionCallback)(const Common::Rect &, const Graphics::DrawStep &);
00043 
00044 
00045 struct DrawStep {
00046     DrawingFunctionCallback drawingCall; 
00047     Graphics::Surface* blitSrc;
00048     Graphics::TransparentSurface* blitAlphaSrc;
00049 
00050     struct Color {
00051         uint8 r, g, b;
00052         bool set;
00053 
00054         Color () : r(0), g(0), b(0), set(false) {}
00055     };
00056     Color fgColor; 
00057     Color bgColor; 
00058     Color gradColor1; 
00059     Color gradColor2; 
00060     Color bevelColor;
00061 
00062     bool autoWidth, autoHeight;
00063     int16 x, y, w, h; 
00066     Common::Rect padding;
00067     Common::Rect clip; 
00069     enum VectorAlignment {
00070         kVectorAlignManual,
00071         kVectorAlignLeft,
00072         kVectorAlignRight,
00073         kVectorAlignBottom,
00074         kVectorAlignTop,
00075         kVectorAlignCenter
00076     };
00077 
00078     VectorAlignment xAlign;
00079     VectorAlignment yAlign;
00080 
00081     uint8 shadow, stroke, factor, radius, bevel; 
00083     uint8 fillMode; 
00084     uint8 shadowFillMode; 
00086     uint32 extraData; 
00088     uint32 scale; 
00090     GUI::ThemeEngine::AutoScaleMode autoscale; 
00092     DrawStep() {
00093         drawingCall = nullptr;
00094         blitSrc = nullptr;
00095         blitAlphaSrc = nullptr;
00096         // fgColor, bgColor, gradColor1, gradColor2, bevelColor initialized by Color default constructor
00097         autoWidth = autoHeight = false;
00098         x = y = w = h = 0;
00099         // padding initialized by Common::Rect default constructor
00100         xAlign = yAlign = kVectorAlignManual;
00101         shadow = stroke = factor = radius = bevel = 0;
00102         fillMode = 0;
00103         shadowFillMode = 0;
00104         extraData = 0;
00105         scale = 0;
00106         autoscale = GUI::ThemeEngine::kAutoScaleNone;
00107     }
00108 };
00109 
00110 VectorRenderer *createRenderer(int mode);
00111 
00130 class VectorRenderer {
00131 public:
00132     VectorRenderer() : _activeSurface(NULL), _fillMode(kFillDisabled), _shadowOffset(0), _shadowFillMode(kShadowExponential),
00133         _disableShadows(false), _strokeWidth(1), _gradientFactor(1), _bevel(0), _dynamicData(0) {
00134 
00135     }
00136 
00137     virtual ~VectorRenderer() {}
00138 
00140     enum FillMode {
00141         kFillDisabled = 0,
00142         kFillForeground = 1,
00143         kFillBackground = 2,
00144         kFillGradient = 3
00145     };
00146 
00147     enum TriangleOrientation {
00148         kTriangleAuto = 0,
00149         kTriangleUp,
00150         kTriangleDown,
00151         kTriangleLeft,
00152         kTriangleRight
00153     };
00154 
00155     enum ShadowFillMode {
00156         kShadowLinear = 0,
00157         kShadowExponential = 1
00158     };
00159 
00168     virtual void drawLine(int x1, int y1, int x2, int y2) = 0;
00169 
00177     virtual void drawCircle(int x, int y, int r) = 0;
00178 
00187     virtual void drawSquare(int x, int y, int w, int h) = 0;
00188 
00199     virtual void drawRoundedSquare(int x, int y, int r, int w, int h) = 0;
00200 
00212     virtual void drawTriangle(int x, int y, int base, int height, TriangleOrientation orient) = 0;
00213 
00225     virtual void drawBeveledSquare(int x, int y, int w, int h) = 0;
00226 
00238     virtual void drawTab(int x, int y, int r, int w, int h) = 0;
00239 
00243     virtual void drawCross(int x, int y, int w, int h) {
00244         drawLine(x, y, x + w, y + w);
00245         drawLine(x + w, y, x, y + h);
00246     }
00247 
00259     virtual void setFgColor(uint8 r, uint8 g, uint8 b) = 0;
00260 
00272     virtual void setBgColor(uint8 r, uint8 g, uint8 b) = 0;
00273 
00274     virtual void setBevelColor(uint8 r, uint8 g, uint8 b) = 0;
00275 
00287     virtual void setGradientColors(uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2) = 0;
00288 
00295     virtual void setSurface(TransparentSurface *surface) {
00296         _activeSurface = surface;
00297     }
00298 
00302     virtual TransparentSurface *getActiveSurface() {
00303         return _activeSurface;
00304     }
00305 
00310     virtual void fillSurface() = 0;
00311 
00315     virtual void clearSurface() {
00316         byte *src = (byte *)_activeSurface->getPixels();
00317         memset(src, 0, _activeSurface->pitch * _activeSurface->h);
00318     }
00319 
00326     virtual void setFillMode(FillMode mode) {
00327         _fillMode = mode;
00328     }
00329 
00330     virtual void setShadowFillMode(ShadowFillMode mode) {
00331         _shadowFillMode = mode;
00332     }
00333 
00340     virtual void setStrokeWidth(int width) {
00341         _strokeWidth = width;
00342     }
00343 
00352     virtual void setShadowOffset(int offset) {
00353         if (offset >= 0)
00354             _shadowOffset = offset;
00355     }
00356 
00357     virtual void setBevel(int amount) {
00358         if (amount >= 0)
00359             _bevel = amount;
00360     }
00361 
00368     virtual void setGradientFactor(int factor) {
00369         if (factor > 0)
00370             _gradientFactor = factor;
00371     }
00372 
00381     virtual void setClippingRect(const Common::Rect &clippingArea) = 0;
00382 
00387     void stepGetPositions(const DrawStep &step, const Common::Rect &area, uint16 &in_x, uint16 &in_y, uint16 &in_w, uint16 &in_h);
00388 
00393     int stepGetRadius(const DrawStep &step, const Common::Rect &area);
00394 
00398     Common::Rect applyStepClippingRect(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step);
00399 
00403     void drawCallback_CIRCLE(const Common::Rect &area, const DrawStep &step) {
00404         uint16 x, y, w, h, radius;
00405 
00406         radius = stepGetRadius(step, area);
00407         stepGetPositions(step, area, x, y, w, h);
00408 
00409         drawCircle(x + radius, y + radius, radius);
00410     }
00411 
00412     void drawCallback_SQUARE(const Common::Rect &area, const DrawStep &step) {
00413         uint16 x, y, w, h;
00414         stepGetPositions(step, area, x, y, w, h);
00415         drawSquare(x, y, w, h);
00416     }
00417 
00418     void drawCallback_LINE(const Common::Rect &area, const DrawStep &step) {
00419         uint16 x, y, w, h;
00420         stepGetPositions(step, area, x, y, w, h);
00421         drawLine(x, y, x + w, y + h);
00422     }
00423 
00424     void drawCallback_ROUNDSQ(const Common::Rect &area, const DrawStep &step) {
00425         uint16 x, y, w, h;
00426         stepGetPositions(step, area, x, y, w, h);
00427         drawRoundedSquare(x, y, stepGetRadius(step, area), w, h);
00428     }
00429 
00430     void drawCallback_FILLSURFACE(const Common::Rect &area, const DrawStep &step) {
00431         fillSurface();
00432     }
00433 
00434     void drawCallback_TRIANGLE(const Common::Rect &area, const DrawStep &step) {
00435         uint16 x, y, w, h;
00436         stepGetPositions(step, area, x, y, w, h);
00437         drawTriangle(x, y, w, h, (TriangleOrientation)step.extraData);
00438     }
00439 
00440     void drawCallback_BEVELSQ(const Common::Rect &area, const DrawStep &step) {
00441         uint16 x, y, w, h;
00442         stepGetPositions(step, area, x, y, w, h);
00443         drawBeveledSquare(x, y, w, h);
00444     }
00445 
00446     void drawCallback_TAB(const Common::Rect &area, const DrawStep &step) {
00447         uint16 x, y, w, h;
00448         stepGetPositions(step, area, x, y, w, h);
00449         drawTab(x, y, stepGetRadius(step, area), w, h);
00450     }
00451 
00452     void drawCallback_BITMAP(const Common::Rect &area, const DrawStep &step) {
00453         uint16 x, y, w, h;
00454         stepGetPositions(step, area, x, y, w, h);
00455         blitKeyBitmap(step.blitSrc, Common::Point(x, y));
00456     }
00457 
00458     void drawCallback_ALPHABITMAP(const Common::Rect &area, const DrawStep &step) {
00459         uint16 x, y, w, h;
00460         stepGetPositions(step, area, x, y, w, h);
00461         blitAlphaBitmap(step.blitAlphaSrc, Common::Rect(x, y, x + w, y + h), step.autoscale, step.xAlign, step.yAlign); // TODO
00462     }
00463 
00464     void drawCallback_CROSS(const Common::Rect &area, const DrawStep &step) {
00465         uint16 x, y, w, h;
00466         stepGetPositions(step, area, x, y, w, h);
00467         drawCross(x, y, w, h);
00468     }
00469 
00470     void drawCallback_VOID(const Common::Rect &area, const DrawStep &step) {}
00471 
00479     virtual void drawStep(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step, uint32 extra = 0);
00480 
00487     virtual void copyFrame(OSystem *sys, const Common::Rect &r) = 0;
00488 
00494     virtual void copyWholeFrame(OSystem *sys) = 0;
00495 
00510     virtual void blitSurface(const Graphics::Surface *source, const Common::Rect &r) = 0;
00511 
00515     virtual void blitSubSurface(const Graphics::Surface *source, const Common::Point &p) = 0;
00516 
00517     virtual void blitKeyBitmap(const Graphics::Surface *source, const Common::Point &p) = 0;
00518 
00519     virtual void blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r,
00520             GUI::ThemeEngine::AutoScaleMode autoscale = GUI::ThemeEngine::kAutoScaleNone,
00521             Graphics::DrawStep::VectorAlignment xAlign = Graphics::DrawStep::kVectorAlignManual,
00522             Graphics::DrawStep::VectorAlignment yAlign = Graphics::DrawStep::kVectorAlignManual,
00523             int alpha = 255) = 0;
00524 
00529     virtual void drawString(const Graphics::Font *font, const Common::String &text,
00530                             const Common::Rect &area, Graphics::TextAlign alignH,
00531                             GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool useEllipsis, const Common::Rect &textDrawableArea) = 0;
00532 
00537     virtual void disableShadows() { _disableShadows = true; }
00538     virtual void enableShadows() { _disableShadows = false; }
00539 
00544     virtual void applyScreenShading(GUI::ThemeEngine::ShadingStyle) = 0;
00545 
00546 protected:
00547     TransparentSurface *_activeSurface; 
00549     FillMode _fillMode; 
00550     ShadowFillMode _shadowFillMode;
00551 
00552     int _shadowOffset; 
00553     int _bevel; 
00554     bool _disableShadows; 
00555     int _strokeWidth; 
00556     uint32 _dynamicData; 
00558     int _gradientFactor; 
00559 };
00560 
00561 } // End of namespace Graphics
00562 
00563 #endif


Generated on Sat Aug 1 2020 05:01:32 for ResidualVM by doxygen 1.7.1
curved edge   curved edge