FIFE 2008.0
sdlimage.h
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2008 by the FIFE team                              *
00003  *   http://www.fifengine.de                                               *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 #ifndef FIFE_VIDEO_RENDERBACKENDS_SDL_SDLIMAGE_H
00023 #define FIFE_VIDEO_RENDERBACKENDS_SDL_SDLIMAGE_H
00024 
00025 // Standard C++ library includes
00026 
00027 // 3rd party library includes
00028 #include <SDL_video.h>
00029 
00030 // FIFE includes
00031 // These includes are split up in two parts, separated by one empty line
00032 // First block: files included from the FIFE root src directory
00033 // Second block: files included from the same folder
00034 #include "video/image.h"
00035 
00036 namespace FIFE {
00037 
00040     class SDLImage : public Image {
00041     public:
00042         SDLImage(SDL_Surface* surface);
00043         SDLImage(const uint8_t* data, unsigned int width, unsigned int height);
00044         virtual ~SDLImage();
00045         void invalidate() {}; //do nothing for SDL images (for now)
00046         void render(const Rect& rect, SDL_Surface* dst, unsigned char alpha = 255);
00047         void saveImage(const std::string& filename);
00048         bool putPixel(int x, int y, int r, int g, int b, int a = 255);
00049         void drawLine(const Point& p1, const Point& p2, int r, int g, int b, int a = 255);
00050         void drawTriangle(const Point& p1, const Point& p2, const Point& p3, int r, int g, int b, int a = 255);
00051         void drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
00052         void fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
00053         void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4,  int r, int g, int b, int a = 255);
00054         void drawVertex(const Point& p, const uint8_t size, int r, int g, int b, int a = 255);
00055         void drawLightPrimitive(const Point& p, uint8_t intensity, float radius, int subdivisions, float xstretch, float ystretch, uint8_t red, uint8_t green, uint8_t blue);
00056 
00057     protected:
00058         void setClipArea(const Rect& cliparea, bool clear);
00059 
00060     private:
00061         // Call this before rendering
00062         void finalize();
00063 
00069         SDL_Surface* optimize(SDL_Surface* surface);
00070 
00071         void resetSdlimage();
00072 
00073         // SDLSurface used to create the SDLImage.
00074         Uint8 m_last_alpha;
00075         // Is the surface already optimized for rendering
00076         bool m_finalized;
00077         SDL_Color m_colorkey;
00078         // Surface for zoom
00079         SDL_Surface* m_zoom_surface;
00080         float m_scale_x;
00081         float m_scale_y;
00082     };
00083 
00084 }
00085 
00086 #endif
 All Classes Namespaces Functions Variables Enumerations Enumerator