WindowImpl.cpp

00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00026 // Headers
00028 #include <SFML/Window/WindowImpl.hpp>
00029 #include <SFML/Window/Event.hpp>
00030 #include <SFML/Window/OpenGLCaps.hpp>
00031 #include <SFML/Window/WindowListener.hpp>
00032 #include <algorithm>
00033 
00034 #if defined(SFML_SYSTEM_WINDOWS)
00035 
00036     #include <SFML/Window/Win32/WindowImplWin32.hpp>
00037 
00038 #elif defined(SFML_SYSTEM_LINUX)
00039 
00040     #include <SFML/Window/Linux/WindowImplX11.hpp>
00041 
00042 #elif defined(SFML_SYSTEM_MACOS)
00043 
00044     #include <SFML/Window/OSX/WindowImplCarbon.hpp>
00045 
00046 #endif
00047 
00048 
00049 namespace sf
00050 {
00051 namespace priv
00052 {
00054 // Static member data
00056 const WindowImpl* WindowImpl::ourCurrent = NULL;
00057 
00058 
00062 WindowImpl* WindowImpl::New()
00063 {
00064     WindowImpl* Window = NULL;
00065 
00066     #if defined(SFML_SYSTEM_WINDOWS)
00067 
00068         // Win32 window
00069         Window = new WindowImplWin32();
00070 
00071     #elif defined(SFML_SYSTEM_LINUX)
00072 
00073         // Unix window
00074         Window = new WindowImplX11();
00075 
00076     #elif defined(SFML_SYSTEM_MACOS)
00077 
00078         // Carbon window
00079         Window = new WindowImplCarbon();
00080 
00081     #endif
00082 
00083     // This is supposed to be the first window created,
00084     // so once it is done we can initialize the OpenGL caps
00085     OpenGLCaps::Initialize();
00086 
00087     return Window;
00088 }
00089 
00090 
00094 WindowImpl* WindowImpl::New(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, int AntialiasingLevel)
00095 {
00096     #if defined(SFML_SYSTEM_WINDOWS)
00097 
00098         // Win32 window
00099         return new WindowImplWin32(Mode, Title, WindowStyle, AntialiasingLevel);
00100 
00101     #elif defined(SFML_SYSTEM_LINUX)
00102 
00103         // Unix window
00104         return new WindowImplX11(Mode, Title, WindowStyle, AntialiasingLevel);
00105 
00106     #elif defined(SFML_SYSTEM_MACOS)
00107 
00108         // Carbon window
00109         return new WindowImplCarbon(Mode, Title, WindowStyle, AntialiasingLevel);
00110 
00111     #endif
00112 }
00113 
00114 
00118 WindowImpl* WindowImpl::New(WindowHandle Handle, int AntialiasingLevel)
00119 {
00120     #if defined(SFML_SYSTEM_WINDOWS)
00121 
00122         // Win32 window
00123         return new WindowImplWin32(Handle, AntialiasingLevel);
00124 
00125     #elif defined(SFML_SYSTEM_LINUX)
00126 
00127         // Unix window
00128         return new WindowImplX11(Handle, AntialiasingLevel);
00129 
00130     #elif defined(SFML_SYSTEM_MACOS)
00131 
00132         // Carbon window
00133         return new WindowImplCarbon(Handle, AntialiasingLevel);
00134 
00135     #endif
00136 }
00137 
00138 
00142 WindowImpl::WindowImpl() :
00143 myWidth      (0),
00144 myHeight     (0),
00145 myDepthBits  (0),
00146 myStencilBits(0)
00147 {
00148 
00149 }
00150 
00151 
00155 WindowImpl::~WindowImpl()
00156 {
00157     // Nothing to do
00158 }
00159 
00160 
00164 void WindowImpl::AddListener(WindowListener* Listener)
00165 {
00166     if (Listener)
00167         myListeners.insert(Listener);
00168 }
00169 
00170 
00174 void WindowImpl::RemoveListener(WindowListener* Listener)
00175 {
00176     myListeners.erase(Listener);
00177 }
00178 
00179 
00183 unsigned int WindowImpl::GetWidth() const
00184 {
00185     return myWidth;
00186 }
00187 
00188 
00192 unsigned int WindowImpl::GetHeight() const
00193 {
00194     return myHeight;
00195 }
00196 
00197 
00201 unsigned int WindowImpl::GetDepthBits() const
00202 {
00203     return myDepthBits;
00204 }
00205 
00206 
00210 unsigned int WindowImpl::GetStencilBits() const
00211 {
00212     return myStencilBits;
00213 }
00214 
00215 
00219 void WindowImpl::SetCurrent() const
00220 {
00221     if (ourCurrent != this)
00222     {
00223         MakeCurrent();
00224         ourCurrent = this;
00225     }
00226 }
00227 
00228 
00232 void WindowImpl::SendEvent(const Event& EventToSend)
00233 {
00234     for (std::set<WindowListener*>::iterator i = myListeners.begin(); i != myListeners.end(); ++i)
00235     {
00236         (*i)->OnEvent(EventToSend);
00237     }
00238 }
00239 
00240 } // namespace priv
00241 
00242 } // namespace sf