FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
renderbackend.cpp
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 // Standard C++ library includes
23 
24 // 3rd party library includes
25 
26 // FIFE includes
27 // These includes are split up in two parts, separated by one empty line
28 // First block: files included from the FIFE root src directory
29 // Second block: files included from the same folder
30 #include "renderbackend.h"
31 #include "video/devicecaps.h"
32 
33 namespace FIFE {
34 
35 
36  RenderBackend::RenderBackend(const SDL_Color& colorkey):
37  m_screen(NULL),
38  m_isalphaoptimized(false),
39  m_iscolorkeyenabled(false),
40  m_colorkey(colorkey) {
41  }
42 
43 
45  }
46 
48  delete m_screen;
49  m_screen = NULL;
50  SDL_QuitSubSystem(SDL_INIT_VIDEO);
51  }
52 
53  void RenderBackend::captureScreen(const std::string& filename) {
54  m_screen->saveImage(filename);
55  }
56 
57  void RenderBackend::pushClipArea(const Rect& cliparea, bool clear) {
58  assert(m_screen);
59  m_screen->pushClipArea(cliparea, clear);
60  }
61 
62  void RenderBackend::popClipArea() {
63  assert(m_screen);
64  m_screen->popClipArea();
65  }
66 
67  const Rect& RenderBackend::getClipArea() const {
68  assert(m_screen);
69  return m_screen->getClipArea();
70  }
71 
72  SDL_Surface* RenderBackend::getSurface() {
73  assert(m_screen);
74  return m_screen->getSurface();
75  }
76 
77  const ScreenMode& RenderBackend::getCurrentScreenMode() const{
78  return m_screenMode;
79  }
80 
81  unsigned int RenderBackend::getWidth() const {
82  assert(m_screen);
83  return m_screen->getWidth();
84  }
85 
86  unsigned int RenderBackend::getHeight() const {
87  assert(m_screen);
88  return m_screen->getHeight();
89  }
90 
91  const Rect& RenderBackend::getArea() {
92  assert(m_screen);
93  SDL_Surface* s = m_screen->getSurface();
94  static Rect r(0, 0, s->w, s->h);
95  return r;
96  }
97 
98  void RenderBackend::getPixelRGBA(int x, int y, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) {
99  assert(m_screen);
100  m_screen->getPixelRGBA(x, y, r, g, b, a);
101  }
102 
103  void RenderBackend::saveImage(const std::string& filename) {
104  assert(m_screen);
105  m_screen->saveImage(filename);
106  }
107 
108  void RenderBackend::setAlphaOptimizerEnabled(bool enabled) {
109  assert(m_screen);
110  m_screen->setAlphaOptimizerEnabled(enabled);
111  }
112 
113  bool RenderBackend::isAlphaOptimizerEnabled() {
114  assert(m_screen);
115  return m_screen->isAlphaOptimizerEnabled();
116  }
117 
118  void RenderBackend::setColorKeyEnabled(bool colorkeyenable) {
119  m_iscolorkeyenabled = colorkeyenable;
120  }
121 
123  return m_iscolorkeyenabled;
124  }
125 
126  void RenderBackend::setColorKey(const SDL_Color& colorkey) {
127  m_colorkey = colorkey;
128  }
129 
130  const SDL_Color& RenderBackend::getColorKey() const {
131  return m_colorkey;
132  }
133 }