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) || defined(SFML_SYSTEM_MACOS)
00039 
00040     #include <SFML/Window/Unix/WindowImplUnix.hpp>
00041 
00042 #endif
00043 
00044 
00045 namespace sf_private
00046 {
00048 // Static member data
00050 const sfWindowImpl* sfWindowImpl::ourCurrent = NULL;
00051 
00052 
00056 sfWindowImpl* sfWindowImpl::New()
00057 {
00058     sfWindowImpl* Window = NULL;
00059 
00060     #if defined(SFML_SYSTEM_WINDOWS)
00061 
00062         // Win32 window
00063         Window = new sfWindowImplWin32();
00064 
00065     #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_MACOS)
00066 
00067         // Unix window
00068         Window = new sfWindowImplUnix();
00069 
00070     #endif
00071 
00072     // This is supposed to be the first window created,
00073     // so once it is done we can initialize the OpenGL caps
00074     sfOpenGLCaps::Initialize();
00075 
00076     return Window;
00077 }
00078 
00079 
00083 sfWindowImpl* sfWindowImpl::New(sfVideoMode Mode, const std::string& Title, bool Fullscreen)
00084 {
00085     #if defined(SFML_SYSTEM_WINDOWS)
00086 
00087         // Win32 window
00088         return new sfWindowImplWin32(Mode, Title, Fullscreen);
00089 
00090     #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_MACOS)
00091 
00092         // Unix window
00093         return new sfWindowImplUnix(Mode, Title, Fullscreen);
00094 
00095     #endif
00096 }
00097 
00098 
00102 sfWindowImpl* sfWindowImpl::New(sfWindowHandle Handle)
00103 {
00104     #if defined(SFML_SYSTEM_WINDOWS)
00105 
00106         // Win32 window
00107         return new sfWindowImplWin32(Handle);
00108 
00109     #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_MACOS)
00110 
00111         // Unix window
00112         return new sfWindowImplUnix(Handle);
00113 
00114     #endif
00115 }
00116 
00117 
00121 sfWindowImpl::sfWindowImpl() :
00122 myWidth      (0),
00123 myHeight     (0),
00124 myDepthBits  (0),
00125 myStencilBits(0)
00126 {
00127 
00128 }
00129 
00130 
00134 sfWindowImpl::~sfWindowImpl()
00135 {
00136     // Nothing to do
00137 }
00138 
00139 
00143 void sfWindowImpl::AddListener(sfWindowListener* Listener)
00144 {
00145     if (Listener)
00146         myListeners.insert(Listener);
00147 }
00148 
00149 
00153 void sfWindowImpl::RemoveListener(sfWindowListener* Listener)
00154 {
00155     myListeners.erase(Listener);
00156 }
00157 
00158 
00162 unsigned int sfWindowImpl::GetWidth() const
00163 {
00164     return myWidth;
00165 }
00166 
00167 
00171 unsigned int sfWindowImpl::GetHeight() const
00172 {
00173     return myHeight;
00174 }
00175 
00176 
00180 unsigned int sfWindowImpl::GetDepthBits() const
00181 {
00182     return myDepthBits;
00183 }
00184 
00185 
00189 unsigned int sfWindowImpl::GetStencilBits() const
00190 {
00191     return myStencilBits;
00192 }
00193 
00194 
00198 void sfWindowImpl::SetCurrent() const
00199 {
00200     if (ourCurrent != this)
00201     {
00202         MakeCurrent();
00203         ourCurrent = this;
00204     }
00205 }
00206 
00207 
00211 void sfWindowImpl::SendEvent(const sfEvent& Event)
00212 {
00213     for (std::set<sfWindowListener*>::iterator i = myListeners.begin(); i != myListeners.end(); ++i)
00214     {
00215         (*i)->OnEvent(Event);
00216     }
00217 }
00218 
00219 } // namespace sf_private