FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
sdlimage.h
1 /***************************************************************************
2  * Copyright (C) 2005-2011 by the FIFE team *
3  * http://www.fifengine.net *
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(IResourceLoader* loader = 0);
43  SDLImage(const std::string& name, IResourceLoader* loader = 0);
44  SDLImage(SDL_Surface* surface);
45  SDLImage(const std::string& name, SDL_Surface* surface);
46  SDLImage(const uint8_t* data, uint32_t width, uint32_t height);
47  SDLImage(const std::string& name, const uint8_t* data, uint32_t width, uint32_t height);
48 
49  virtual ~SDLImage();
50  virtual void invalidate() {}; //do nothing for SDL images (for now)
51  virtual void setSurface(SDL_Surface* surface);
52  virtual void render(const Rect& rect, uint8_t alpha = 255, uint8_t const* rgb = 0);
53  virtual size_t getSize();
54  virtual void useSharedImage(const ImagePtr& shared, const Rect& region);
55  virtual void forceLoadInternal();
56  virtual void load();
57  virtual void free();
58 
59  private:
60  // Call this before rendering
61  void finalize();
62 
68  SDL_Surface* optimize(SDL_Surface* surface);
69 
70  void resetSdlimage();
71  void validateShared();
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  // Holds Atlas ImagePtr if this is a shared image
83  ImagePtr m_atlas_img;
84  // Holds Atlas Name if this is a shared image
85  std::string m_atlas_name;
86  };
87 
88 }
89 
90 #endif
virtual void render(const Rect &rect, uint8_t alpha=255, uint8_t const *rgb=0)
Definition: sdlimage.cpp:332
virtual void invalidate()
Definition: sdlimage.h:50
virtual void forceLoadInternal()
Definition: sdlimage.cpp:684
virtual void setSurface(SDL_Surface *surface)
Definition: sdlimage.cpp:89
virtual void useSharedImage(const ImagePtr &shared, const Rect &region)
Definition: sdlimage.cpp:662