00001 // SuperTux 00002 // Copyright (C) 2006 Matthias Braun <matze@braunis.de> 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 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 00017 #ifndef HEADER_SUPERTUX_VIDEO_SDL_SURFACE_DATA_HPP 00018 #define HEADER_SUPERTUX_VIDEO_SDL_SURFACE_DATA_HPP 00019 00020 #include <config.h> 00021 00022 #include "supertux/gameconfig.hpp" 00023 #include "supertux/globals.hpp" 00024 #include "video/surface.hpp" 00025 #include "video/surface_data.hpp" 00026 #include "video/texture.hpp" 00027 00028 class SDLSurfaceData : public SurfaceData 00029 { 00030 private: 00031 const Surface &surface; 00032 SDL_Rect src_rects[NUM_EFFECTS]; 00033 00034 public: 00035 SDLSurfaceData(const Surface &surface) : 00036 surface(surface) 00037 { 00038 int numerator = 1; 00039 int denominator = 1; 00040 //float xfactor = 1.0f; // FIXME: (float) config->screenwidth / SCREEN_WIDTH; 00041 //float yfactor = 1.0f; // FIXME: (float) config->screenheight / SCREEN_HEIGHT; 00042 00043 /* FIXME: 00044 if(xfactor < yfactor) 00045 { 00046 numerator = config->screenwidth; 00047 denominator = SCREEN_WIDTH; 00048 } 00049 else 00050 { 00051 numerator = config->screenheight; 00052 denominator = SCREEN_HEIGHT; 00053 } 00054 */ 00055 00056 src_rects[NO_EFFECT].x = surface.get_x() * numerator / denominator; 00057 src_rects[NO_EFFECT].y = surface.get_y() * numerator / denominator; 00058 src_rects[NO_EFFECT].w = surface.get_width() * numerator / denominator; 00059 src_rects[NO_EFFECT].h = surface.get_height() * numerator / denominator; 00060 00061 int flipped_x = surface.get_texture()->get_texture_width() - surface.get_x() - surface.get_width(); 00062 src_rects[HORIZONTAL_FLIP].x = flipped_x * numerator / denominator; 00063 src_rects[HORIZONTAL_FLIP].y = surface.get_y() * numerator / denominator; 00064 src_rects[HORIZONTAL_FLIP].w = surface.get_width() * numerator / denominator; 00065 src_rects[HORIZONTAL_FLIP].h = surface.get_height() * numerator / denominator; 00066 00067 int flipped_y = surface.get_texture()->get_texture_height() - surface.get_y() - surface.get_height(); 00068 src_rects[VERTICAL_FLIP].x = flipped_y * numerator / denominator; 00069 src_rects[VERTICAL_FLIP].y = surface.get_y() * numerator / denominator; 00070 src_rects[VERTICAL_FLIP].w = surface.get_width() * numerator / denominator; 00071 src_rects[VERTICAL_FLIP].h = surface.get_height() * numerator / denominator; 00072 } 00073 00074 SDL_Rect *get_src_rect(DrawingEffect effect) 00075 { 00076 return src_rects + effect; 00077 } 00078 }; 00079 00080 #endif 00081 00082 /* EOF */