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

managed_surface.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 GRAPHICS_MANAGED_SURFACE_H
00024 #define GRAPHICS_MANAGED_SURFACE_H
00025 
00026 #include "graphics/pixelformat.h"
00027 #include "graphics/surface.h"
00028 #include "common/rect.h"
00029 #include "common/types.h"
00030 
00031 namespace Graphics {
00032 
00033 class Font;
00034 
00039 class ManagedSurface {
00040     friend class Font;
00041 private:
00045     Surface _innerSurface;
00046 
00051     DisposeAfterUse::Flag _disposeAfterUse;
00052 
00057     ManagedSurface *_owner;
00058 
00063     Common::Point _offsetFromOwner;
00064 
00069     uint _transparentColor;
00070     bool _transparentColorSet;
00071 
00075     uint32 _palette[256];
00076     bool _paletteSet;
00077 protected:
00082     virtual void addDirtyRect(const Common::Rect &r);
00083 
00087     void blitFromInner(const Surface &src, const Common::Rect &srcRect,
00088         const Common::Point &destPos, const uint32 *palette);
00089 
00093     void transBlitFromInner(const Surface &src, const Common::Rect &srcRect,
00094         const Common::Rect &destRect, uint transColor, bool flipped, uint overrideColor,
00095         uint srcAlpha, const uint32 *palette, const Surface *mask, bool maskOnly);
00096 public:
00100     bool clip(Common::Rect &srcBounds, Common::Rect &destBounds);
00101 public:
00102     uint16 &w;
00103     uint16 &h;
00104     uint16 &pitch;
00105     PixelFormat &format;
00106 public:
00110     ManagedSurface();
00111 
00118     ManagedSurface(const ManagedSurface &surf);
00119 
00123     ManagedSurface(int width, int height);
00124 
00128     ManagedSurface(int width, int height, const Graphics::PixelFormat &pixelFormat);
00129 
00133     ManagedSurface(ManagedSurface &surf, const Common::Rect &bounds);
00134 
00138     virtual ~ManagedSurface();
00139 
00146     operator const Surface &() const { return _innerSurface; }
00147     const Surface &rawSurface() const { return _innerSurface; }
00148 
00153     ManagedSurface &operator=(const ManagedSurface &surf);
00154 
00158     bool empty() const { return w == 0 || h == 0 || _innerSurface.getPixels() == nullptr; }
00159 
00163     DisposeAfterUse::Flag disposeAfterUse() const { return _disposeAfterUse; }
00164 
00172     inline const void *getBasePtr(int x, int y) const {
00173         return _innerSurface.getBasePtr(x, y);
00174     }
00175 
00183     inline void *getBasePtr(int x, int y) {
00184         return _innerSurface.getBasePtr(x, y);
00185     }
00186 
00190     inline void *getPixels() { return _innerSurface.getPixels(); }
00191     inline const void *getPixels() const { return _innerSurface.getPixels(); }
00192 
00196     virtual void setPixels(void *newPixels);
00197 
00201     virtual void create(uint16 width, uint16 height);
00202 
00206     virtual void create(uint16 width, uint16 height, const PixelFormat &pixelFormat);
00207 
00215     virtual void create(ManagedSurface &surf, const Common::Rect &bounds);
00216 
00221     virtual void free();
00222 
00226     virtual void clearDirtyRects() {}
00227 
00232     const Common::Point getOffsetFromOwner() const { return _offsetFromOwner; }
00233 
00237     const Common::Rect getBounds() const {
00238         return Common::Rect(0, 0, this->w, this->h);
00239     }
00240 
00244     void blitFrom(const Surface &src);
00245 
00249     void blitFrom(const Surface &src, const Common::Point &destPos);
00250 
00254     void blitFrom(const Surface &src, const Common::Rect &srcRect,
00255         const Common::Point &destPos);
00256 
00260     void blitFrom(const ManagedSurface &src);
00261 
00265     void blitFrom(const ManagedSurface &src, const Common::Point &destPos);
00266 
00270     void blitFrom(const ManagedSurface &src, const Common::Rect &srcRect,
00271         const Common::Point &destPos);
00272 
00282     void transBlitFrom(const Surface &src, uint transColor = 0, bool flipped = false,
00283         uint overrideColor = 0, uint srcAlpha = 0xff);
00284 
00295     void transBlitFrom(const Surface &src, const Common::Point &destPos,
00296         uint transColor = 0, bool flipped = false, uint overrideColor = 0, uint srcAlpha = 0xff);
00297 
00304     void transBlitFrom(const Surface &src, const Common::Point &destPos,
00305         const ManagedSurface &mask);
00306 
00313     void transBlitFrom(const Surface &src, const Common::Point &destPos,
00314         const Surface &mask);
00315 
00329     void transBlitFrom(const Surface &src, const Common::Rect &srcRect, const Common::Point &destPos,
00330         uint transColor = 0, bool flipped = false, uint overrideColor = 0, uint srcAlpha = 0xff);
00331 
00346     void transBlitFrom(const Surface &src, const Common::Rect &srcRect, const Common::Rect &destRect,
00347         uint transColor = 0, bool flipped = false, uint overrideColor = 0, uint srcAlpha = 0xff,
00348         const Surface *mask = nullptr, bool maskOnly = false);
00349 
00359     void transBlitFrom(const ManagedSurface &src, uint transColor = 0, bool flipped = false,
00360         uint overrideColor = 0, uint srcAlpha = 0xff);
00361 
00372     void transBlitFrom(const ManagedSurface &src, const Common::Point &destPos,
00373         uint transColor = 0, bool flipped = false, uint overrideColor = 0, uint srcAlpha = 0xff);
00374 
00381     void transBlitFrom(const ManagedSurface &src, const Common::Point &destPos,
00382         const ManagedSurface &mask);
00383 
00395     void transBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect, const Common::Point &destPos,
00396         uint transColor = 0, bool flipped = false, uint overrideColor = 0, uint srcAlpha = 0xff);
00397 
00410     void transBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect, const Common::Rect &destRect,
00411         uint transColor = 0, bool flipped = false, uint overrideColor = 0, uint srcAlpha = 0xff,
00412         const Surface *mask = nullptr, bool maskOnly = false);
00413 
00417     void clear(uint color = 0);
00418 
00422     void markAllDirty();
00423 
00428     void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height) {
00429         _innerSurface.copyRectToSurface(buffer, srcPitch, destX, destY, width, height);
00430     }
00431 
00436     void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect) {
00437         _innerSurface.copyRectToSurface(srcSurface, destX, destY, subRect);
00438     }
00439 
00444     void copyFrom(const ManagedSurface &surf);
00445 
00449     void drawLine(int x0, int y0, int x1, int y1, uint32 color) {
00450         _innerSurface.drawLine(x0, y0, x1, y1, color);
00451         addDirtyRect(Common::Rect(MIN(x0, x1), MIN(y0, y1), MAX(x0, x1), MAX(y0, y1)));
00452     }
00453 
00457     void drawThickLine(int x0, int y0, int x1, int y1, int penX, int penY, uint32 color) {
00458         _innerSurface.drawThickLine(x0, y0, x1, y1, penX, penY, color);
00459         addDirtyRect(Common::Rect(MIN(x0, x1 + penX), MIN(y0, y1 + penY), MAX(x0, x1 + penX), MAX(y0, y1 + penY)));
00460     }
00461 
00465     void hLine(int x, int y, int x2, uint32 color) {
00466         _innerSurface.hLine(x, y, x2, color);
00467         addDirtyRect(Common::Rect(x, y, x2 + 1, y + 1));
00468     }
00469 
00473     void vLine(int x, int y, int y2, uint32 color) {
00474         _innerSurface.vLine(x, y, y2, color);
00475         addDirtyRect(Common::Rect(x, y, x + 1, y2 + 1));
00476     }
00477 
00481     void fillRect(Common::Rect r, uint32 color) {
00482         _innerSurface.fillRect(r, color);
00483         addDirtyRect(r);
00484     }
00485 
00489     void frameRect(const Common::Rect &r, uint32 color) {
00490         _innerSurface.frameRect(r, color);
00491         addDirtyRect(r);
00492     }
00493 
00498     Surface getSubArea(const Common::Rect &area) {
00499         addDirtyRect(area);
00500         return _innerSurface.getSubArea(area);
00501     }
00502 
00513     void convertToInPlace(const PixelFormat &dstFormat, const byte *palette = 0) {
00514         _innerSurface.convertToInPlace(dstFormat, palette);
00515     }
00516 
00520     uint getTransparentColor() const { return _transparentColor; }
00521 
00525     void setTransparentColor(uint color) {
00526         _transparentColor = color;
00527         _transparentColorSet = true;
00528     }
00529 
00533     void clearTransparentColor() {
00534         _transparentColorSet = false;
00535     }
00536 
00540     bool hasTransparentColor() const {
00541         return _transparentColorSet;
00542     }
00543 
00547     void clearPalette() {
00548         _paletteSet = false;
00549     }
00550 
00554     const uint32 *getPalette() const {
00555         return _palette;
00556     }
00557 
00561     void setPalette(const byte *colors, uint start, uint num);
00562 
00566     void setPalette(const uint32 *colors, uint start, uint num);
00567 };
00568 
00569 } // End of namespace Graphics
00570 
00571 #endif


Generated on Sat Aug 8 2020 05:01:23 for ResidualVM by doxygen 1.7.1
curved edge   curved edge