Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

EffectMirror.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "EffectMirror.h"
00010 
00011 #include "SurfaceLock.h"
00012 #include "PixelTool.h"
00013 
00014 //-----------------------------------------------------------------
00015 /**
00016  * Mirror effect. Draw left side inside.
00017  * The pixel in the middle will be used as a mask.
00018  * NOTE: mirror object should be draw as the last.
00019  */
00020 void
00021 EffectMirror::blit(SDL_Surface *screen, SDL_Surface *surface, int x, int y)
00022 {
00023     SurfaceLock lock1(screen);
00024     SurfaceLock lock2(surface);
00025 
00026     SDL_Color mask = PixelTool::getColor(surface,
00027             surface->w / 2, surface->h / 2);
00028 
00029     for (int py = 0; py < surface->h; ++py) {
00030         for (int px = 0; px < surface->w; ++px) {
00031             SDL_Color pixel = PixelTool::getColor(surface, px, py);
00032             if (px > MIRROR_BORDER && PixelTool::colorEquals(pixel, mask)) {
00033                 SDL_Color sample = PixelTool::getColor(screen,
00034                         x - px + MIRROR_BORDER, y + py);
00035                 PixelTool::putColor(screen, x + px, y + py, sample);
00036             }
00037             else {
00038                 if (pixel.unused == 255) {
00039                     PixelTool::putColor(screen, x + px, y + py, pixel);
00040                 }
00041             }
00042         }
00043     }
00044 }
00045 

Generated on Wed Jun 1 09:54:30 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2