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 &, const Common::Rect &);
00043 
00044 
00045 struct DrawStep {
00046     struct Color {
00047         uint8 r, g, b;
00048         bool set;
00049     };
00050     Color fgColor; 
00051     Color bgColor; 
00052     Color gradColor1; 
00053     Color gradColor2; 
00054     Color bevelColor;
00055 
00056     bool autoWidth, autoHeight;
00057     int16 x, y, w, h; 
00060     Common::Rect padding;
00061 
00062     enum VectorAlignment {
00063         kVectorAlignManual,
00064         kVectorAlignLeft,
00065         kVectorAlignRight,
00066         kVectorAlignBottom,
00067         kVectorAlignTop,
00068         kVectorAlignCenter
00069     };
00070 
00071     VectorAlignment xAlign;
00072     VectorAlignment yAlign;
00073 
00074     uint8 shadow, stroke, factor, radius, bevel; 
00076     uint8 fillMode; 
00077     uint8 shadowFillMode; 
00079     uint32 extraData; 
00081     uint32 scale; 
00083     GUI::ThemeEngine::AutoScaleMode autoscale; 
00085     DrawingFunctionCallback drawingCall; 
00086     Graphics::Surface *blitSrc;
00087     Graphics::TransparentSurface *blitAlphaSrc;
00088 };
00089 
00090 VectorRenderer *createRenderer(int mode);
00091 
00110 class VectorRenderer {
00111 public:
00112     VectorRenderer() : _activeSurface(NULL), _fillMode(kFillDisabled), _shadowOffset(0), _shadowFillMode(kShadowExponential),
00113         _disableShadows(false), _strokeWidth(1), _gradientFactor(1) {
00114 
00115     }
00116 
00117     virtual ~VectorRenderer() {}
00118 
00120     enum FillMode {
00121         kFillDisabled = 0,
00122         kFillForeground = 1,
00123         kFillBackground = 2,
00124         kFillGradient = 3
00125     };
00126 
00127     enum TriangleOrientation {
00128         kTriangleAuto = 0,
00129         kTriangleUp,
00130         kTriangleDown,
00131         kTriangleLeft,
00132         kTriangleRight
00133     };
00134 
00135     enum ShadowFillMode {
00136         kShadowLinear = 0,
00137         kShadowExponential = 1
00138     };
00139 
00148     virtual void drawLine(int x1, int y1, int x2, int y2) = 0;
00149     virtual void drawLineClip(int x1, int y1, int x2, int y2, Common::Rect clipping) = 0;
00150 
00158     virtual void drawCircle(int x, int y, int r) = 0;
00159     virtual void drawCircleClip(int x, int y, int r, Common::Rect clipping) = 0;
00160 
00169     virtual void drawSquare(int x, int y, int w, int h) = 0;
00170     virtual void drawSquareClip(int x, int y, int w, int h, Common::Rect clipping) = 0;
00171 
00182     virtual void drawRoundedSquare(int x, int y, int r, int w, int h) = 0;
00183     virtual void drawRoundedSquareClip(int x, int y, int r, int w, int h, Common::Rect clipping) = 0;
00184 
00196     virtual void drawTriangle(int x, int y, int base, int height, TriangleOrientation orient) = 0;
00197     virtual void drawTriangleClip(int x, int y, int base, int height, TriangleOrientation orient, Common::Rect clipping) = 0;
00198 
00210     virtual void drawBeveledSquare(int x, int y, int w, int h, int bevel) = 0;
00211     virtual void drawBeveledSquareClip(int x, int y, int w, int h, int bevel, Common::Rect clipping) = 0;
00212 
00224     virtual void drawTab(int x, int y, int r, int w, int h) = 0;
00225     virtual void drawTabClip(int x, int y, int r, int w, int h, Common::Rect clipping) = 0;
00226 
00227 
00231     virtual void drawCross(int x, int y, int w, int h) {
00232         drawLine(x, y, x + w, y + w);
00233         drawLine(x + w, y, x, y + h);
00234     }
00235 
00236     virtual void drawCrossClip(int x, int y, int w, int h, Common::Rect clipping) {
00237         drawLineClip(x, y, x + w, y + w, clipping);
00238         drawLineClip(x + w, y, x, y + h, clipping);
00239     }
00240 
00252     virtual void setFgColor(uint8 r, uint8 g, uint8 b) = 0;
00253 
00265     virtual void setBgColor(uint8 r, uint8 g, uint8 b) = 0;
00266 
00267     virtual void setBevelColor(uint8 r, uint8 g, uint8 b) = 0;
00268 
00280     virtual void setGradientColors(uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2) = 0;
00281 
00288     virtual void setSurface(TransparentSurface *surface) {
00289         _activeSurface = surface;
00290     }
00291 
00295     virtual TransparentSurface *getActiveSurface() {
00296         return _activeSurface;
00297     }
00298 
00303     virtual void fillSurface() = 0;
00304     virtual void fillSurfaceClip(Common::Rect clipping) = 0;
00305 
00309     virtual void clearSurface() {
00310         byte *src = (byte *)_activeSurface->getPixels();
00311         memset(src, 0, _activeSurface->pitch * _activeSurface->h);
00312     }
00313 
00320     virtual void setFillMode(FillMode mode) {
00321         _fillMode = mode;
00322     }
00323 
00324     virtual void setShadowFillMode(ShadowFillMode mode) {
00325         _shadowFillMode = mode;
00326     }
00327 
00334     virtual void setStrokeWidth(int width) {
00335         _strokeWidth = width;
00336     }
00337 
00346     virtual void setShadowOffset(int offset) {
00347         if (offset >= 0)
00348             _shadowOffset = offset;
00349     }
00350 
00351     virtual void setBevel(int amount) {
00352         if (amount >= 0)
00353             _bevel = amount;
00354     }
00355 
00362     virtual void setGradientFactor(int factor) {
00363         if (factor > 0)
00364             _gradientFactor = factor;
00365     }
00366 
00371     void stepGetPositions(const DrawStep &step, const Common::Rect &area, uint16 &in_x, uint16 &in_y, uint16 &in_w, uint16 &in_h);
00372 
00377     int stepGetRadius(const DrawStep &step, const Common::Rect &area);
00378 
00382     void drawCallback_CIRCLE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
00383         uint16 x, y, w, h, radius;
00384 
00385         radius = stepGetRadius(step, area);
00386         stepGetPositions(step, area, x, y, w, h);
00387 
00388         drawCircleClip(x + radius, y + radius, radius, clip);
00389     }
00390 
00391     void drawCallback_SQUARE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
00392         uint16 x, y, w, h;
00393         stepGetPositions(step, area, x, y, w, h);
00394         drawSquareClip(x, y, w, h, clip);
00395     }
00396 
00397     void drawCallback_LINE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
00398         uint16 x, y, w, h;
00399         stepGetPositions(step, area, x, y, w, h);
00400         drawLineClip(x, y, x + w, y + w, clip);
00401     }
00402 
00403     void drawCallback_ROUNDSQ(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
00404         uint16 x, y, w, h;
00405         stepGetPositions(step, area, x, y, w, h);
00406         drawRoundedSquareClip(x, y, stepGetRadius(step, area), w, h, clip);
00407     }
00408 
00409     void drawCallback_FILLSURFACE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
00410         fillSurfaceClip(clip);
00411     }
00412 
00413     void drawCallback_TRIANGLE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
00414         uint16 x, y, w, h;
00415         stepGetPositions(step, area, x, y, w, h);
00416         drawTriangleClip(x, y, w, h, (TriangleOrientation)step.extraData, clip);
00417     }
00418 
00419     void drawCallback_BEVELSQ(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
00420         uint16 x, y, w, h;
00421         stepGetPositions(step, area, x, y, w, h);
00422         drawBeveledSquareClip(x, y, w, h, _bevel, clip);
00423     }
00424 
00425     void drawCallback_TAB(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
00426         uint16 x, y, w, h;
00427         stepGetPositions(step, area, x, y, w, h);
00428         drawTabClip(x, y, stepGetRadius(step, area), w, h, clip);
00429     }
00430 
00431     void drawCallback_BITMAP(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
00432         uint16 x, y, w, h;
00433         stepGetPositions(step, area, x, y, w, h);
00434         blitKeyBitmapClip(step.blitSrc, Common::Rect(x, y, x + w, y + h), clip);
00435     }
00436 
00437     void drawCallback_ALPHABITMAP(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
00438         uint16 x, y, w, h;
00439         stepGetPositions(step, area, x, y, w, h);
00440         blitAlphaBitmap(step.blitAlphaSrc, Common::Rect(x, y, x + w, y + h), step.autoscale, step.xAlign, step.yAlign); // TODO
00441     }
00442 
00443     void drawCallback_CROSS(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
00444         uint16 x, y, w, h;
00445         stepGetPositions(step, area, x, y, w, h);
00446         drawCrossClip(x, y, w, h, clip);
00447     }
00448 
00449     void drawCallback_VOID(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {}
00450 
00458     virtual void drawStep(const Common::Rect &area, const DrawStep &step, uint32 extra = 0);
00459     virtual void drawStepClip(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step, uint32 extra = 0);
00460 
00467     virtual void copyFrame(OSystem *sys, const Common::Rect &r) = 0;
00468 
00474     virtual void copyWholeFrame(OSystem *sys) = 0;
00475 
00490     virtual void blitSurface(const Graphics::Surface *source, const Common::Rect &r) = 0;
00491 
00499     virtual void blitSubSurface(const Graphics::Surface *source, const Common::Rect &r) = 0;
00500     virtual void blitSubSurfaceClip(const Graphics::Surface *source, const Common::Rect &r, const Common::Rect &clipping) = 0;
00501 
00502     virtual void blitKeyBitmap(const Graphics::Surface *source, const Common::Rect &r) = 0;
00503     virtual void blitKeyBitmapClip(const Graphics::Surface *source, const Common::Rect &r, const Common::Rect &clipping) = 0;
00504 
00505     virtual void blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r,
00506             GUI::ThemeEngine::AutoScaleMode autoscale = GUI::ThemeEngine::kAutoScaleNone,
00507             Graphics::DrawStep::VectorAlignment xAlign = Graphics::DrawStep::kVectorAlignManual,
00508             Graphics::DrawStep::VectorAlignment yAlign = Graphics::DrawStep::kVectorAlignManual,
00509             int alpha = 255) = 0;
00510 
00515     virtual void drawString(const Graphics::Font *font, const Common::String &text,
00516                             const Common::Rect &area, Graphics::TextAlign alignH,
00517                             GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool useEllipsis, const Common::Rect &textDrawableArea) = 0;
00518 
00523     virtual void disableShadows() { _disableShadows = true; }
00524     virtual void enableShadows() { _disableShadows = false; }
00525 
00530     virtual void applyScreenShading(GUI::ThemeEngine::ShadingStyle) = 0;
00531 
00532 protected:
00533     TransparentSurface *_activeSurface; 
00535     FillMode _fillMode; 
00536     ShadowFillMode _shadowFillMode;
00537 
00538     int _shadowOffset; 
00539     int _bevel; 
00540     bool _disableShadows; 
00541     int _strokeWidth; 
00542     uint32 _dynamicData; 
00544     int _gradientFactor; 
00545 };
00546 
00547 } // End of namespace Graphics
00548 
00549 #endif


Generated on Sat Mar 23 2019 05:02:21 for ResidualVM by doxygen 1.7.1
curved edge   curved edge