00001 /* 00002 libwt - Vassilis Virvilis Toolkit - a widget library 00003 Copyright (C) 2006 Vassilis Virvilis <vasvir2@fastmail.fm> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the 00017 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, SA. 00019 */ 00020 00021 #include <wt/trace.h> 00022 00023 #include "sdldisplay.h" 00024 00025 namespace Wt { 00026 00027 SDLDisplay *SDLDisplay::load(int w, int h, int depth, int flags) { 00028 SDLSurface s = SDL_SetVideoMode(w, h, depth, 00029 flagMap.state(flags ? flags 00030 : static_cast<int>(W::DefaultDisplayPixmapFlags))); 00031 instance_ = (s) ? new SDLDisplay(s) : 0; 00032 return instance_; 00033 } 00034 00035 SDLDisplay::SDLDisplay(int w, int h, int depth, int flags) 00036 : SDLSurface(SDL_SetVideoMode(w, h, depth, 00037 flagMap.state( 00038 flags ? flags 00039 : static_cast<int>(W::DefaultDisplayPixmapFlags)))), 00040 Singleton<SDLDisplay>(this) {} 00041 00042 SDLDisplay::SDLDisplay(SDLSurface &src) 00043 : SDLSurface(src), 00044 Singleton<SDLDisplay>(this) {} 00045 00046 void SDLDisplay::update() { 00047 SDL_UpdateRect(*this, 0, 0, 0, 0); 00048 } 00049 00050 void SDLDisplay::update(const SDLRect& r) { 00051 SDL_UpdateRect(*this, r.x(), r.y(), r.width(), r.height()); 00052 } 00053 00054 void SDLDisplay::update(const std::vector<SDLRect>& rects) { 00055 if (!rects.size()) // could cause a problem with zero size array 00056 return; 00057 00058 const SDL_Rect *rc = rects[0]; 00059 SDL_Rect *r = const_cast<SDL_Rect *>(rc); 00060 SDL_UpdateRects(*this, rects.size(), r); 00061 } 00062 00063 void SDLDisplay::flip() { 00064 SDL_Flip(*this); 00065 } 00066 00067 int SDLDisplay::setGamma(float r, float g, float b) { 00068 return SDL_SetGamma(r, g, b); 00069 } 00070 00071 int SDLDisplay::setGammaRamp(const std::vector<Uint16>& red, 00072 const std::vector<Uint16>& green, 00073 const std::vector<Uint16>& blue) { 00074 00075 return SDL_SetGammaRamp(&red[0], &green[0], &blue[0]); 00076 } 00077 00078 int SDLDisplay::toggleFullScreen() { 00079 return SDL_WM_ToggleFullScreen(*this); 00080 } 00081 00082 void SDLDisplay::resize(int w, int h) { 00083 if(!isResizable() || (w == width() && h == height()) || (!w && !h)) 00084 return; 00085 SDLSurface& self = *this; 00086 trace("sdlsurface", "Resizing %p to %d x %d\n", 00087 static_cast<SDL_Surface *>(self), w, h); 00088 00089 /*!\note first we delete our reference to VideoSurface 00090 before SDL frees it under our feet 00091 SDL proctects us from deleting the Display surface and 00092 auto deletes it in case we call SDL_SetVideoMode, However 00093 SDL does not protect against deletion of the previous 00094 VideoSurface. 00095 */ 00096 // first save intersting parameters 00097 int bpp = pixelFormat().bitsPerPixel(); 00098 int fl = flags(); 00099 self = SDLSurface(); 00100 // now set it the resized surface 00101 self = SDL_SetVideoMode(w, h, bpp, fl); 00102 } 00103 00104 } // namespace
This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.