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     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     Common::Rect clip; 
00063     enum VectorAlignment {
00064         kVectorAlignManual,
00065         kVectorAlignLeft,
00066         kVectorAlignRight,
00067         kVectorAlignBottom,
00068         kVectorAlignTop,
00069         kVectorAlignCenter
00070     };
00071 
00072     VectorAlignment xAlign;
00073     VectorAlignment yAlign;
00074 
00075     uint8 shadow, stroke, factor, radius, bevel; 
00077     uint8 fillMode; 
00078     uint8 shadowFillMode; 
00080     uint32 extraData; 
00082     uint32 scale; 
00084     GUI::ThemeEngine::AutoScaleMode autoscale; 
00086     DrawingFunctionCallback drawingCall; 
00087     Graphics::Surface *blitSrc;
00088     Graphics::TransparentSurface *blitAlphaSrc;
00089 };
00090 
00091 VectorRenderer *createRenderer(int mode);
00092 
00111 class VectorRenderer {
00112 public:
00113     VectorRenderer() : _activeSurface(NULL), _fillMode(kFillDisabled), _shadowOffset(0), _shadowFillMode(kShadowExponential),
00114         _disableShadows(false), _strokeWidth(1), _gradientFactor(1) {
00115 
00116     }
00117 
00118     virtual ~VectorRenderer() {}
00119 
00121     enum FillMode {
00122         kFillDisabled = 0,
00123         kFillForeground = 1,
00124         kFillBackground = 2,
00125         kFillGradient = 3
00126     };
00127 
00128     enum TriangleOrientation {
00129         kTriangleAuto = 0,
00130         kTriangleUp,
00131         kTriangleDown,
00132         kTriangleLeft,
00133         kTriangleRight
00134     };
00135 
00136     enum ShadowFillMode {
00137         kShadowLinear = 0,
00138         kShadowExponential = 1
00139     };
00140 
00149     virtual void drawLine(int x1, int y1, int x2, int y2) = 0;
00150 
00158     virtual void drawCircle(int x, int y, int r) = 0;
00159 
00168     virtual void drawSquare(int x, int y, int w, int h) = 0;
00169 
00180     virtual void drawRoundedSquare(int x, int y, int r, int w, int h) = 0;
00181 
00193     virtual void drawTriangle(int x, int y, int base, int height, TriangleOrientation orient) = 0;
00194 
00206     virtual void drawBeveledSquare(int x, int y, int w, int h) = 0;
00207 
00219     virtual void drawTab(int x, int y, int r, int w, int h) = 0;
00220 
00224     virtual void drawCross(int x, int y, int w, int h) {
00225         drawLine(x, y, x + w, y + w);
00226         drawLine(x + w, y, x, y + h);
00227     }
00228 
00240     virtual void setFgColor(uint8 r, uint8 g, uint8 b) = 0;
00241 
00253     virtual void setBgColor(uint8 r, uint8 g, uint8 b) = 0;
00254 
00255     virtual void setBevelColor(uint8 r, uint8 g, uint8 b) = 0;
00256 
00268     virtual void setGradientColors(uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2) = 0;
00269 
00276     virtual void setSurface(TransparentSurface *surface) {
00277         _activeSurface = surface;
00278     }
00279 
00283     virtual TransparentSurface *getActiveSurface() {
00284         return _activeSurface;
00285     }
00286 
00291     virtual void fillSurface() = 0;
00292 
00296     virtual void clearSurface() {
00297         byte *src = (byte *)_activeSurface->getPixels();
00298         memset(src, 0, _activeSurface->pitch * _activeSurface->h);
00299     }
00300 
00307     virtual void setFillMode(FillMode mode) {
00308         _fillMode = mode;
00309     }
00310 
00311     virtual void setShadowFillMode(ShadowFillMode mode) {
00312         _shadowFillMode = mode;
00313     }
00314 
00321     virtual void setStrokeWidth(int width) {
00322         _strokeWidth = width;
00323     }
00324 
00333     virtual void setShadowOffset(int offset) {
00334         if (offset >= 0)
00335             _shadowOffset = offset;
00336     }
00337 
00338     virtual void setBevel(int amount) {
00339         if (amount >= 0)
00340             _bevel = amount;
00341     }
00342 
00349     virtual void setGradientFactor(int factor) {
00350         if (factor > 0)
00351             _gradientFactor = factor;
00352     }
00353 
00362     virtual void setClippingRect(const Common::Rect &clippingArea) = 0;
00363 
00368     void stepGetPositions(const DrawStep &step, const Common::Rect &area, uint16 &in_x, uint16 &in_y, uint16 &in_w, uint16 &in_h);
00369 
00374     int stepGetRadius(const DrawStep &step, const Common::Rect &area);
00375 
00379     Common::Rect applyStepClippingRect(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step);
00380 
00384     void drawCallback_CIRCLE(const Common::Rect &area, const DrawStep &step) {
00385         uint16 x, y, w, h, radius;
00386 
00387         radius = stepGetRadius(step, area);
00388         stepGetPositions(step, area, x, y, w, h);
00389 
00390         drawCircle(x + radius, y + radius, radius);
00391     }
00392 
00393     void drawCallback_SQUARE(const Common::Rect &area, const DrawStep &step) {
00394         uint16 x, y, w, h;
00395         stepGetPositions(step, area, x, y, w, h);
00396         drawSquare(x, y, w, h);
00397     }
00398 
00399     void drawCallback_LINE(const Common::Rect &area, const DrawStep &step) {
00400         uint16 x, y, w, h;
00401         stepGetPositions(step, area, x, y, w, h);
00402         drawLine(x, y, x + w, y + h);
00403     }
00404 
00405     void drawCallback_ROUNDSQ(const Common::Rect &area, const DrawStep &step) {
00406         uint16 x, y, w, h;
00407         stepGetPositions(step, area, x, y, w, h);
00408         drawRoundedSquare(x, y, stepGetRadius(step, area), w, h);
00409     }
00410 
00411     void drawCallback_FILLSURFACE(const Common::Rect &area, const DrawStep &step) {
00412         fillSurface();
00413     }
00414 
00415     void drawCallback_TRIANGLE(const Common::Rect &area, const DrawStep &step) {
00416         uint16 x, y, w, h;
00417         stepGetPositions(step, area, x, y, w, h);
00418         drawTriangle(x, y, w, h, (TriangleOrientation)step.extraData);
00419     }
00420 
00421     void drawCallback_BEVELSQ(const Common::Rect &area, const DrawStep &step) {
00422         uint16 x, y, w, h;
00423         stepGetPositions(step, area, x, y, w, h);
00424         drawBeveledSquare(x, y, w, h);
00425     }
00426 
00427     void drawCallback_TAB(const Common::Rect &area, const DrawStep &step) {
00428         uint16 x, y, w, h;
00429         stepGetPositions(step, area, x, y, w, h);
00430         drawTab(x, y, stepGetRadius(step, area), w, h);
00431     }
00432 
00433     void drawCallback_BITMAP(const Common::Rect &area, const DrawStep &step) {
00434         uint16 x, y, w, h;
00435         stepGetPositions(step, area, x, y, w, h);
00436         blitKeyBitmap(step.blitSrc, Common::Point(x, y));
00437     }
00438 
00439     void drawCallback_ALPHABITMAP(const Common::Rect &area, const DrawStep &step) {
00440         uint16 x, y, w, h;
00441         stepGetPositions(step, area, x, y, w, h);
00442         blitAlphaBitmap(step.blitAlphaSrc, Common::Rect(x, y, x + w, y + h), step.autoscale, step.xAlign, step.yAlign); // TODO
00443     }
00444 
00445     void drawCallback_CROSS(const Common::Rect &area, const DrawStep &step) {
00446         uint16 x, y, w, h;
00447         stepGetPositions(step, area, x, y, w, h);
00448         drawCross(x, y, w, h);
00449     }
00450 
00451     void drawCallback_VOID(const Common::Rect &area, const DrawStep &step) {}
00452 
00460     virtual void drawStep(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step, uint32 extra = 0);
00461 
00468     virtual void copyFrame(OSystem *sys, const Common::Rect &r) = 0;
00469 
00475     virtual void copyWholeFrame(OSystem *sys) = 0;
00476 
00491     virtual void blitSurface(const Graphics::Surface *source, const Common::Rect &r) = 0;
00492 
00496     virtual void blitSubSurface(const Graphics::Surface *source, const Common::Point &p) = 0;
00497 
00498     virtual void blitKeyBitmap(const Graphics::Surface *source, const Common::Point &p) = 0;
00499 
00500     virtual void blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r,
00501             GUI::ThemeEngine::AutoScaleMode autoscale = GUI::ThemeEngine::kAutoScaleNone,
00502             Graphics::DrawStep::VectorAlignment xAlign = Graphics::DrawStep::kVectorAlignManual,
00503             Graphics::DrawStep::VectorAlignment yAlign = Graphics::DrawStep::kVectorAlignManual,
00504             int alpha = 255) = 0;
00505 
00510     virtual void drawString(const Graphics::Font *font, const Common::String &text,
00511                             const Common::Rect &area, Graphics::TextAlign alignH,
00512                             GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool useEllipsis, const Common::Rect &textDrawableArea) = 0;
00513 
00518     virtual void disableShadows() { _disableShadows = true; }
00519     virtual void enableShadows() { _disableShadows = false; }
00520 
00525     virtual void applyScreenShading(GUI::ThemeEngine::ShadingStyle) = 0;
00526 
00527 protected:
00528     TransparentSurface *_activeSurface; 
00530     FillMode _fillMode; 
00531     ShadowFillMode _shadowFillMode;
00532 
00533     int _shadowOffset; 
00534     int _bevel; 
00535     bool _disableShadows; 
00536     int _strokeWidth; 
00537     uint32 _dynamicData; 
00539     int _gradientFactor; 
00540 };
00541 
00542 } // End of namespace Graphics
00543 
00544 #endif


Generated on Sat Dec 14 2019 05:00:49 for ResidualVM by doxygen 1.7.1
curved edge   curved edge