Debian Codegraph @

src/effect/EffectMirror.cpp

raw
1 /*
2 * Copyright (C) 2004 Ivo Danihelka ([email protected])
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
9 #include "EffectMirror.h"
10
11 #include "SurfaceLock.h"
12 #include "PixelTool.h"
13
14 const char *EffectMirror::NAME = "mirror";
15 //-----------------------------------------------------------------
16 /**
17 * Mirror effect. Draw left side inside.
18 * The pixel in the middle will be used as a mask.
19 * NOTE: mirror object should be drawn as the last.
20 */
21 void
22 EffectMirror::blit(SDL_Surface *screen, SDL_Surface *surface, int x, int y)
23 {
24 SurfaceLock lock1(screen);
25 SurfaceLock lock2(surface);
26
27 SDL_Color mask = PixelTool::getColor(surface,
28 surface->w / 2, surface->h / 2);
29
30 for (int py = 0; py < surface->h; ++py) {
31 for (int px = 0; px < surface->w; ++px) {
32 SDL_Color pixel = PixelTool::getColor(surface, px, py);
33 if (px > MIRROR_BORDER && PixelTool::colorEquals(pixel, mask)) {
34 SDL_Color sample = PixelTool::getColor(screen,
35 x - px + MIRROR_BORDER, y + py);
36 PixelTool::putColor(screen, x + px, y + py, sample);
37 }
38 else {
39 if (pixel.unused == 255) {
40 PixelTool::putColor(screen, x + px, y + py, pixel);
41 }
42 }
43 }
44 }
45 }
46