Implemented set_gamma()
[supertux.git] / src / video / sdl / sdl_surface_data.hpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #ifndef HEADER_SUPERTUX_VIDEO_SDL_SURFACE_DATA_HPP
18 #define HEADER_SUPERTUX_VIDEO_SDL_SURFACE_DATA_HPP
19
20 #include <config.h>
21
22 #include "supertux/gameconfig.hpp"
23 #include "supertux/globals.hpp"
24 #include "video/surface.hpp"
25 #include "video/surface_data.hpp"
26 #include "video/texture.hpp"
27
28 class SDLSurfaceData : public SurfaceData
29 {
30 private:
31   const Surface &surface;
32   SDL_Rect src_rects[NUM_EFFECTS];
33
34 public:
35   SDLSurfaceData(const Surface &surface) :
36     surface(surface)
37   {
38     int numerator   = 1;
39     int denominator = 1;
40     //float xfactor = 1.0f; // FIXME: (float) config->screenwidth  / SCREEN_WIDTH;
41     //float yfactor = 1.0f; // FIXME: (float) config->screenheight / SCREEN_HEIGHT;
42
43     /* FIXME: 
44        if(xfactor < yfactor)
45        {
46        numerator = config->screenwidth;
47        denominator = SCREEN_WIDTH;
48        }
49        else
50        {
51        numerator = config->screenheight;
52        denominator = SCREEN_HEIGHT;
53        }
54     */
55
56     src_rects[NO_EFFECT].x = surface.get_x() * numerator / denominator;
57     src_rects[NO_EFFECT].y = surface.get_y() * numerator / denominator;
58     src_rects[NO_EFFECT].w = surface.get_width() * numerator / denominator;
59     src_rects[NO_EFFECT].h = surface.get_height() * numerator / denominator;
60
61     int flipped_x = surface.get_texture()->get_texture_width() - surface.get_x() - surface.get_width();
62     src_rects[HORIZONTAL_FLIP].x = flipped_x * numerator / denominator;
63     src_rects[HORIZONTAL_FLIP].y = surface.get_y() * numerator / denominator;
64     src_rects[HORIZONTAL_FLIP].w = surface.get_width() * numerator / denominator;
65     src_rects[HORIZONTAL_FLIP].h = surface.get_height() * numerator / denominator;
66
67     int flipped_y = surface.get_texture()->get_texture_height() - surface.get_y() - surface.get_height();
68     src_rects[VERTICAL_FLIP].x = flipped_y * numerator / denominator;
69     src_rects[VERTICAL_FLIP].y = surface.get_y() * numerator / denominator;
70     src_rects[VERTICAL_FLIP].w = surface.get_width() * numerator / denominator;
71     src_rects[VERTICAL_FLIP].h = surface.get_height() * numerator / denominator;
72   }
73
74   SDL_Rect *get_src_rect(DrawingEffect effect)
75   {
76     return src_rects + effect;
77   }
78 };
79
80 #endif
81
82 /* EOF */