FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sdlimage.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 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
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
84  // Holds Atlas Name if this is a shared image
85  std::string m_atlas_name;
86  };
87 
88 }
89 
90 #endif
bool m_finalized
Definition: sdlimage.h:76
A Rectangle on screen.
Definition: rect.h:80
void validateShared()
Definition: sdlimage.cpp:698
Base Class for Images.
Definition: image.h:47
SDL_Color m_colorkey
Definition: sdlimage.h:77
The SDL implementation of the Image base class.
Definition: sdlimage.h:40
Uint8 m_last_alpha
Definition: sdlimage.h:74
ImagePtr m_atlas_img
Definition: sdlimage.h:83
virtual size_t getSize()
Definition: sdlimage.cpp:660
float m_scale_y
Definition: sdlimage.h:81
unsigned char uint8_t
Definition: core.h:38
virtual void render(const Rect &rect, uint8_t alpha=255, uint8_t const *rgb=0)
Renders itself to the current render target (main screen or attached destination image) at the rectan...
Definition: sdlimage.cpp:335
virtual ~SDLImage()
Definition: sdlimage.cpp:86
void finalize()
Definition: sdlimage.cpp:412
SDL_Surface * m_zoom_surface
Definition: sdlimage.h:79
void resetSdlimage()
Definition: sdlimage.cpp:77
virtual void invalidate()
Invalidates the Image causing it to be reset or re-loaded.
Definition: sdlimage.h:50
virtual void forceLoadInternal()
Forces to load the image into internal memory of GPU.
Definition: sdlimage.cpp:694
float m_scale_x
Definition: sdlimage.h:80
std::string m_atlas_name
Definition: sdlimage.h:85
virtual void setSurface(SDL_Surface *surface)
This frees the current suface and replaces it with the surface passed in the parameter (which can be ...
Definition: sdlimage.cpp:92
unsigned int uint32_t
Definition: core.h:40
virtual void load()
Definition: sdlimage.cpp:709
SDLImage(IResourceLoader *loader=0)
Definition: sdlimage.cpp:47
virtual void free()
Definition: sdlimage.cpp:723
virtual void useSharedImage(const ImagePtr &shared, const Rect &region)
After this call all image data will be taken from the given image and its subregion.
Definition: sdlimage.cpp:672
SDL_Surface * optimize(SDL_Surface *surface)
SDL Alpha Optimizer This tries to convert an image with a fake alpha channel to an RGB image when the...
Definition: sdlimage.cpp:453