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 protected:
00068     bool clip(Common::Rect &srcBounds, Common::Rect &destBounds);
00069 
00074     virtual void addDirtyRect(const Common::Rect &r);
00075 public:
00076     uint16 &w;
00077     uint16 &h;
00078     uint16 &pitch;
00079     PixelFormat &format;
00080 public:
00084     ManagedSurface();
00085 
00092     ManagedSurface(ManagedSurface &surf);
00093 
00097     ManagedSurface(int width, int height);
00098 
00102     ManagedSurface(int width, int height, const Graphics::PixelFormat &pixelFormat);
00103 
00107     ManagedSurface(ManagedSurface &surf, const Common::Rect &bounds);
00108 
00112     virtual ~ManagedSurface();
00113 
00120     operator const Surface &() const { return _innerSurface; }
00121     const Surface &rawSurface() const { return _innerSurface; }
00122 
00127     ManagedSurface &operator=(ManagedSurface &surf);
00128 
00132     bool empty() const { return w == 0 || h == 0 || _innerSurface.getPixels() == nullptr; }
00133 
00137     DisposeAfterUse::Flag disposeAfterUse() const { return _disposeAfterUse; }
00138 
00146     inline const void *getBasePtr(int x, int y) const {
00147         return _innerSurface.getBasePtr(x, y);
00148     }
00149 
00157     inline void *getBasePtr(int x, int y) {
00158         return _innerSurface.getBasePtr(x, y);
00159     }
00160 
00164     inline void *getPixels() { return _innerSurface.getPixels(); }
00165     inline const void *getPixels() const { return _innerSurface.getPixels(); }
00166 
00170     virtual void setPixels(void *newPixels);
00171 
00175     virtual void create(uint16 width, uint16 height);
00176 
00180     virtual void create(uint16 width, uint16 height, const PixelFormat &pixelFormat);
00181 
00189     virtual void create(ManagedSurface &surf, const Common::Rect &bounds);
00190 
00195     virtual void free();
00196 
00200     virtual void clearDirtyRects() {}
00201 
00206     const Common::Point getOffsetFromOwner() const { return _offsetFromOwner; }
00207 
00211     const Common::Rect getBounds() const {
00212         return Common::Rect(0, 0, this->w, this->h);
00213     }
00214 
00218     void blitFrom(const Surface &src);
00219 
00223     void blitFrom(const Surface &src, const Common::Point &destPos);
00224 
00228     void blitFrom(const Surface &src, const Common::Rect &srcRect,
00229         const Common::Point &destPos);
00230 
00239     void transBlitFrom(const Surface &src, uint transColor = 0, bool flipped = false, uint overrideColor = 0);
00240 
00250     void transBlitFrom(const Surface &src, const Common::Point &destPos,
00251         uint transColor = 0, bool flipped = false, uint overrideColor = 0);
00252 
00263     void transBlitFrom(const Surface &src, const Common::Rect &srcRect, const Common::Point &destPos,
00264         uint transColor = 0, bool flipped = false, uint overrideColor = 0);
00265 
00277     void transBlitFrom(const Surface &src, const Common::Rect &srcRect, const Common::Rect &destRect,
00278         uint transColor = 0, bool flipped = false, uint overrideColor = 0);
00279 
00283     void clear(uint color = 0);
00284 
00288     void markAllDirty();
00289 
00294     void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height) {
00295         _innerSurface.copyRectToSurface(buffer, srcPitch, destX, destY, width, height);
00296     }
00297 
00302     void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect) {
00303         _innerSurface.copyRectToSurface(srcSurface, destX, destY, subRect);
00304     }
00305 
00310     void copyFrom(const ManagedSurface &surf);
00311 
00315     void drawLine(int x0, int y0, int x1, int y1, uint32 color) {
00316         _innerSurface.drawLine(x0, y0, x1, y1, color);
00317         addDirtyRect(Common::Rect(MIN(x0, x1), MIN(y0, y1), MAX(x0, x1), MAX(y0, y1)));
00318     }
00319 
00323     void drawThickLine(int x0, int y0, int x1, int y1, int penX, int penY, uint32 color) {
00324         _innerSurface.drawThickLine(x0, y0, x1, y1, penX, penY, color);
00325         addDirtyRect(Common::Rect(MIN(x0, x1 + penX), MIN(y0, y1 + penY), MAX(x0, x1 + penX), MAX(y0, y1 + penY)));
00326     }
00327 
00331     void hLine(int x, int y, int x2, uint32 color) {
00332         _innerSurface.hLine(x, y, x2, color);
00333         addDirtyRect(Common::Rect(x, y, x2 + 1, y + 1));
00334     }
00335 
00339     void vLine(int x, int y, int y2, uint32 color) {
00340         _innerSurface.vLine(x, y, y2, color);
00341         addDirtyRect(Common::Rect(x, y, x + 1, y2 + 1));
00342     }
00343 
00347     void fillRect(Common::Rect r, uint32 color) {
00348         _innerSurface.fillRect(r, color);
00349         addDirtyRect(r);
00350     }
00351 
00355     void frameRect(const Common::Rect &r, uint32 color) {
00356         _innerSurface.frameRect(r, color);
00357         addDirtyRect(r);
00358     }
00359 
00364     Surface getSubArea(const Common::Rect &area) {
00365         addDirtyRect(area);
00366         return _innerSurface.getSubArea(area);
00367     }
00368 
00379     void convertToInPlace(const PixelFormat &dstFormat, const byte *palette = 0) {
00380         _innerSurface.convertToInPlace(dstFormat, palette);
00381     }
00382 };
00383 
00384 } // End of namespace Graphics
00385 
00386 #endif


Generated on Sat Sep 14 2019 05:01:27 for ResidualVM by doxygen 1.7.1
curved edge   curved edge