po: update French translation
[xcsoar.git] / src / Screen / VirtualCanvas.cpp
blobe3de72ff9585ece51869665e7fc608bf1555ba52
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2012 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "Screen/VirtualCanvas.hpp"
26 #include <assert.h>
28 #ifdef ENABLE_SDL
30 VirtualCanvas::VirtualCanvas(UPixelScalar _width, UPixelScalar _height)
32 set(_width, _height);
35 VirtualCanvas::VirtualCanvas(const Canvas &canvas,
36 UPixelScalar _width, UPixelScalar _height)
38 set(_width, _height);
41 #else /* !ENABLE_SDL */
43 VirtualCanvas::VirtualCanvas(UPixelScalar _width, UPixelScalar _height)
44 :Canvas(::CreateCompatibleDC(NULL), _width, _height)
48 VirtualCanvas::VirtualCanvas(const Canvas &canvas,
49 UPixelScalar _width, UPixelScalar _height)
50 :Canvas(::CreateCompatibleDC(canvas), _width, _height)
52 assert(canvas.IsDefined());
55 #endif /* !ENABLE_SDL */
57 #ifndef ENABLE_OPENGL
59 VirtualCanvas::~VirtualCanvas()
61 reset();
64 #endif /* !OPENGL */
66 void
67 VirtualCanvas::set(UPixelScalar _width, UPixelScalar _height)
69 assert((PixelScalar)_width >= 0);
70 assert((PixelScalar)_height >= 0);
72 #ifdef ENABLE_OPENGL
73 Canvas::set(_width, _height);
74 #else /* !OPENGL */
76 reset();
78 #ifdef ENABLE_SDL
79 const SDL_Surface *video = ::SDL_GetVideoSurface();
80 assert(video != NULL);
81 const SDL_PixelFormat *format = video->format;
83 SDL_Surface *surface;
84 surface = ::SDL_CreateRGBSurface(SDL_SWSURFACE, _width, _height,
85 format->BitsPerPixel,
86 format->Rmask, format->Gmask,
87 format->Bmask, format->Amask);
88 if (surface != NULL)
89 Canvas::set(surface);
90 #else /* !ENABLE_SDL */
91 Canvas::set(CreateCompatibleDC(NULL), _width, _height);
92 #endif /* !ENABLE_SDL */
93 #endif /* !OPENGL */
96 void
97 VirtualCanvas::set(const Canvas &canvas,
98 UPixelScalar _width, UPixelScalar _height)
100 assert(canvas.IsDefined());
102 #ifdef ENABLE_SDL
103 set(_width, _height);
104 #else /* !ENABLE_SDL */
105 reset();
106 Canvas::set(CreateCompatibleDC(canvas), _width, _height);
107 #endif /* !ENABLE_SDL */
110 void
111 VirtualCanvas::set(const Canvas &canvas)
113 set(canvas, canvas.get_width(), canvas.get_height());
116 #ifndef ENABLE_SDL
117 void VirtualCanvas::reset()
119 Canvas::reset();
121 if (dc != NULL)
122 ::DeleteDC(dc);
124 #endif /* !ENABLE_SDL */