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

screen.cpp

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 #include "common/system.h"
00024 #include "common/algorithm.h"
00025 #include "graphics/screen.h"
00026 #include "graphics/palette.h"
00027 
00028 namespace Graphics {
00029 
00030 Screen::Screen(): ManagedSurface() {
00031     create(g_system->getWidth(), g_system->getHeight(), g_system->getScreenFormat());
00032 }
00033 
00034 Screen::Screen(int width, int height): ManagedSurface() {
00035     create(width, height);
00036 }
00037 
00038 Screen::Screen(int width, int height, PixelFormat pixelFormat): ManagedSurface() {
00039     create(width, height, pixelFormat);
00040 }
00041 
00042 void Screen::update() {
00043     // Merge the dirty rects
00044     mergeDirtyRects();
00045 
00046     // Loop through copying dirty areas to the physical screen
00047     Common::List<Common::Rect>::iterator i;
00048     for (i = _dirtyRects.begin(); i != _dirtyRects.end(); ++i) {
00049         const Common::Rect &r = *i;
00050         const byte *srcP = (const byte *)getBasePtr(r.left, r.top);
00051         g_system->copyRectToScreen(srcP, pitch, r.left, r.top,
00052             r.width(), r.height());
00053     }
00054 
00055     // Signal the physical screen to update
00056     g_system->updateScreen();
00057     _dirtyRects.clear();
00058 }
00059 
00060 
00061 void Screen::addDirtyRect(const Common::Rect &r) {
00062     Common::Rect bounds = r;
00063     bounds.clip(getBounds());
00064     bounds.translate(getOffsetFromOwner().x, getOffsetFromOwner().y);
00065 
00066     if (bounds.width() > 0 && bounds.height() > 0)
00067         _dirtyRects.push_back(bounds);
00068 }
00069 
00070 void Screen::makeAllDirty() {
00071     addDirtyRect(Common::Rect(0, 0, this->w, this->h));
00072 }
00073 
00074 void Screen::mergeDirtyRects() {
00075     Common::List<Common::Rect>::iterator rOuter, rInner;
00076 
00077     // Process the dirty rect list to find any rects to merge
00078     for (rOuter = _dirtyRects.begin(); rOuter != _dirtyRects.end(); ++rOuter) {
00079         rInner = rOuter;
00080         while (++rInner != _dirtyRects.end()) {
00081 
00082             if ((*rOuter).intersects(*rInner)) {
00083                 // These two rectangles overlap, so merge them
00084                 unionRectangle(*rOuter, *rOuter, *rInner);
00085 
00086                 // remove the inner rect from the list
00087                 _dirtyRects.erase(rInner);
00088 
00089                 // move back to beginning of list
00090                 rInner = rOuter;
00091             }
00092         }
00093     }
00094 }
00095 
00096 bool Screen::unionRectangle(Common::Rect &destRect, const Common::Rect &src1, const Common::Rect &src2) {
00097     destRect = src1;
00098     destRect.extend(src2);
00099 
00100     return !destRect.isEmpty();
00101 }
00102 
00103 void Screen::getPalette(byte palette[PALETTE_SIZE]) {
00104     assert(format.bytesPerPixel == 1);
00105     g_system->getPaletteManager()->grabPalette(palette, 0, PALETTE_COUNT);
00106 }
00107 
00108 void Screen::getPalette(byte *palette, uint start, uint num) {
00109     assert(format.bytesPerPixel == 1);
00110     g_system->getPaletteManager()->grabPalette(palette, start, num);
00111 }
00112 
00113 void Screen::setPalette(const byte palette[PALETTE_SIZE]) {
00114     assert(format.bytesPerPixel == 1);
00115     g_system->getPaletteManager()->setPalette(palette, 0, PALETTE_COUNT);
00116 }
00117 
00118 void Screen::setPalette(const byte *palette, uint start, uint num) {
00119     assert(format.bytesPerPixel == 1);
00120     g_system->getPaletteManager()->setPalette(palette, start, num);
00121 }
00122 
00123 void Screen::clearPalette() {
00124     byte palette[PALETTE_SIZE];
00125     Common::fill(&palette[0], &palette[PALETTE_SIZE], 0);
00126     setPalette(palette);
00127 }
00128 
00129 } // End of namespace Graphics


Generated on Sat Feb 16 2019 05:01:03 for ResidualVM by doxygen 1.7.1
curved edge   curved edge