diff options
author | Johannes Schickel | 2013-08-02 18:37:12 +0200 |
---|---|---|
committer | Johannes Schickel | 2013-08-02 18:47:00 +0200 |
commit | 058c22ddaa073a1584993b2d68b2db02ad80d088 (patch) | |
tree | 9447ed68d2bc19ad4d2e47e3ba8133456c7947f0 /graphics/surface.cpp | |
parent | ff451ba2dc8c417d781f362f4af80aec44b57341 (diff) | |
download | scummvm-rg350-058c22ddaa073a1584993b2d68b2db02ad80d088.tar.gz scummvm-rg350-058c22ddaa073a1584993b2d68b2db02ad80d088.tar.bz2 scummvm-rg350-058c22ddaa073a1584993b2d68b2db02ad80d088.zip |
GRAPHICS: Allow to query a Surface describing a subarea in Surface.
Diffstat (limited to 'graphics/surface.cpp')
-rw-r--r-- | graphics/surface.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/graphics/surface.cpp b/graphics/surface.cpp index 010389c9fa..b90ddd23e8 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -97,6 +97,34 @@ void Surface::copyFrom(const Surface &surf) { } } +Surface Surface::getSubArea(const Common::Rect &area) { + Common::Rect effectiveArea(area); + effectiveArea.clip(w, h); + + Surface subSurface; + subSurface.w = effectiveArea.width(); + subSurface.h = effectiveArea.height(); + subSurface.pitch = pitch; + subSurface.pixels = getBasePtr(area.left, area.top); + subSurface.format = format; + return subSurface; +} + +const Surface Surface::getSubArea(const Common::Rect &area) const { + Common::Rect effectiveArea(area); + effectiveArea.clip(w, h); + + Surface subSurface; + subSurface.w = effectiveArea.width(); + subSurface.h = effectiveArea.height(); + subSurface.pitch = pitch; + // We need to cast the const away here because a Surface always has a + // pointer to modifiable pixel data. + subSurface.pixels = const_cast<void *>(getBasePtr(area.left, area.top)); + subSurface.format = format; + return subSurface; +} + void Surface::hLine(int x, int y, int x2, uint32 color) { // Clipping if (y < 0 || y >= h) |