FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
sdlimage.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_VIDEO_RENDERBACKENDS_SDL_SDLIMAGE_H
23 #define FIFE_VIDEO_RENDERBACKENDS_SDL_SDLIMAGE_H
24 
25 // Standard C++ library includes
26 
27 // 3rd party library includes
28 #include <SDL_video.h>
29 
30 // FIFE includes
31 // These includes are split up in two parts, separated by one empty line
32 // First block: files included from the FIFE root src directory
33 // Second block: files included from the same folder
34 #include "video/image.h"
35 
36 namespace FIFE {
37 
40  class SDLImage : public Image {
41  public:
42  SDLImage(SDL_Surface* surface);
43  SDLImage(const uint8_t* data, unsigned int width, unsigned int height);
44  virtual ~SDLImage();
45  void invalidate() {}; //do nothing for SDL images (for now)
46  void render(const Rect& rect, SDL_Surface* dst, unsigned char alpha = 255);
47  void saveImage(const std::string& filename);
48  bool putPixel(int x, int y, int r, int g, int b, int a = 255);
49  void drawLine(const Point& p1, const Point& p2, int r, int g, int b, int a = 255);
50  void drawTriangle(const Point& p1, const Point& p2, const Point& p3, int r, int g, int b, int a = 255);
51  void drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
52  void fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
53  void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b, int a = 255);
54  void drawVertex(const Point& p, const uint8_t size, int r, int g, int b, int a = 255);
55  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);
56 
57  protected:
58  void setClipArea(const Rect& cliparea, bool clear);
59 
60  private:
61  // Call this before rendering
62  void finalize();
63 
69  SDL_Surface* optimize(SDL_Surface* surface);
70 
71  void resetSdlimage();
72 
73  // SDLSurface used to create the SDLImage.
74  Uint8 m_last_alpha;
75  // Is the surface already optimized for rendering
76  bool m_finalized;
77  SDL_Color m_colorkey;
78  // Surface for zoom
79  SDL_Surface* m_zoom_surface;
80  float m_scale_x;
81  float m_scale_y;
82  };
83 
84 }
85 
86 #endif