D:/Programmation/Cpp/SFML/src/SFML/Window/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/WindowListener.hpp>
00031 #include <algorithm>
00032 
00033 #if defined(SFML_SYSTEM_WINDOWS)
00034 
00035     #include <SFML/Window/Win32/WindowImplWin32.hpp>
00036 
00037 #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_MACOS)
00038 
00039     #include <SFML/Window/Unix/WindowImplUnix.hpp>
00040 
00041 #endif
00042 
00043 namespace sf_private
00044 {
00046 // Static member data
00048 const sfWindowImpl* sfWindowImpl::ourCurrent = NULL;
00049 
00050 
00054 sfWindowImpl* sfWindowImpl::New(sfVideoMode Mode, const std::string& Title, bool Fullscreen)
00055 {
00056     #if defined(SFML_SYSTEM_WINDOWS)
00057 
00058         // Win32 window
00059         return new sfWindowImplWin32(Mode, Title, Fullscreen);
00060 
00061     #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_MACOS)
00062 
00063         // Unix (X11) window
00064         return new sfWindowImplUnix(Mode, Title, Fullscreen);
00065 
00066     #endif
00067 }
00068 
00069 
00073 sfWindowImpl* sfWindowImpl::New(void* Handle)
00074 {
00075     #if defined(SFML_SYSTEM_WINDOWS)
00076 
00077         // Win32 window
00078         return new sfWindowImplWin32(Handle);
00079 
00080     #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_MACOS)
00081 
00082         // Unix (X11) window
00083         return new sfWindowImplUnix(Handle);
00084 
00085     #endif
00086 }
00087 
00088 
00092 sfWindowImpl::~sfWindowImpl()
00093 {
00094     // Nothing to do
00095 }
00096 
00097 
00101 void sfWindowImpl::AddListener(sfWindowListener* Listener)
00102 {
00103     if (Listener)
00104         myListeners.insert(Listener);
00105 }
00106 
00107 
00111 void sfWindowImpl::RemoveListener(sfWindowListener* Listener)
00112 {
00113     myListeners.erase(Listener);
00114 }
00115 
00116 
00120 unsigned int sfWindowImpl::GetWidth() const
00121 {
00122     return myWidth;
00123 }
00124 
00125 
00129 unsigned int sfWindowImpl::GetHeight() const
00130 {
00131     return myHeight;
00132 }
00133 
00134 
00138 void sfWindowImpl::SetCurrent() const
00139 {
00140     if (ourCurrent != this)
00141     {
00142         MakeCurrent();
00143         ourCurrent = this;
00144     }
00145 }
00146 
00147 
00151 float sfWindowImpl::Display()
00152 {
00153     // Measure time elapsed since last frame
00154     float ElapsedTime = myClock.GetElapsedTime();
00155     myClock.Reset();
00156 
00157     // Swap back and front buffers to display things on screen
00158     SwapBuffers();
00159 
00160     return ElapsedTime;
00161 }
00162 
00163 
00167 void sfWindowImpl::SendEvent(const sfEvent& Event)
00168 {
00169     for (std::set<sfWindowListener*>::iterator i = myListeners.begin(); i != myListeners.end(); ++i)
00170     {
00171         (*i)->OnEvent(Event);
00172     }
00173 }
00174 
00175 } // namespace sf_private

Generated for SFML by  doxygen 1.5.2