00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00026
00028 #include <SFML/Window/Window.hpp>
00029 #include <SFML/Window/WindowImpl.hpp>
00030 #include <iostream>
00031 #include <memory>
00032
00033 namespace
00034 {
00035
00036
00037
00038
00039
00040 std::auto_ptr<sf_private::sfWindowImpl> DummyWindow(sf_private::sfWindowImpl::New());
00041 }
00042
00043
00048 sfWindow::sfWindow() :
00049 myWindow (NULL),
00050 myLastFrameTime(0.f)
00051 {
00052
00053 }
00054
00055
00059 sfWindow::sfWindow(sfVideoMode Mode, const std::string& Title, bool Fullscreen) :
00060 myWindow (NULL),
00061 myLastFrameTime(0.f)
00062 {
00063 Create(Mode, Title, Fullscreen);
00064 }
00065
00066
00070 sfWindow::sfWindow(sfWindowHandle Handle) :
00071 myWindow (NULL),
00072 myLastFrameTime(0.f)
00073 {
00074 Create(Handle);
00075 }
00076
00077
00081 sfWindow::~sfWindow()
00082 {
00083
00084 delete myWindow;
00085 }
00086
00087
00091 void sfWindow::Create(sfVideoMode Mode, const std::string& Title, bool Fullscreen)
00092 {
00093
00094 if (Fullscreen && !Mode.IsValid())
00095 {
00096 std::cerr << "Requested video mode is not available, switching to a valid mode" << std::endl;
00097 Mode = sfVideoMode::GetMode(0);
00098 }
00099
00100 Initialize(sf_private::sfWindowImpl::New(Mode, Title, Fullscreen));
00101 }
00102
00103
00107 void sfWindow::Create(sfWindowHandle Handle)
00108 {
00109 Initialize(sf_private::sfWindowImpl::New(Handle));
00110 }
00111
00112
00116 unsigned int sfWindow::GetWidth() const
00117 {
00118 return myWindow ? myWindow->GetWidth() : 0;
00119 }
00120
00121
00125 unsigned int sfWindow::GetHeight() const
00126 {
00127 return myWindow ? myWindow->GetHeight() : 0;
00128 }
00129
00130
00134 unsigned int sfWindow::GetDepthBits() const
00135 {
00136 return myWindow ? myWindow->GetDepthBits() : 0;
00137 }
00138
00139
00143 unsigned int sfWindow::GetStencilBits() const
00144 {
00145 return myWindow ? myWindow->GetStencilBits() : 0;
00146 }
00147
00148
00152 bool sfWindow::GetEvent(sfEvent& Event)
00153 {
00154
00155 if (!myEvents.empty())
00156 {
00157 Event = myEvents.front();
00158 myEvents.pop();
00159
00160 return true;
00161 }
00162
00163 return false;
00164 }
00165
00166
00170 void sfWindow::UseVerticalSync(bool Enabled)
00171 {
00172 if (SetCurrent())
00173 myWindow->UseVerticalSync(Enabled);
00174 }
00175
00176
00180 void sfWindow::ShowMouseCursor(bool Show)
00181 {
00182 if (SetCurrent())
00183 myWindow->ShowMouseCursor(Show);
00184 }
00185
00186
00190 bool sfWindow::SetCurrent() const
00191 {
00192 if (myWindow)
00193 {
00194 myWindow->SetCurrent();
00195 return true;
00196 }
00197
00198 return false;
00199 }
00200
00201
00205 void sfWindow::Display()
00206 {
00207
00208 myLastFrameTime = myClock.GetElapsedTime();
00209 myClock.Reset();
00210
00211 if (SetCurrent())
00212 {
00213
00214 myWindow->Display();
00215
00216
00217 myWindow->ProcessEvents();
00218 }
00219 }
00220
00221
00225 const sfInput& sfWindow::GetInput() const
00226 {
00227 return myInput;
00228 }
00229
00230
00234 float sfWindow::GetFrameTime() const
00235 {
00236 return myLastFrameTime;
00237 }
00238
00239
00243 void sfWindow::OnEvent(const sfEvent& Event)
00244 {
00245 myEvents.push(Event);
00246 }
00247
00248
00252 void sfWindow::Initialize(sf_private::sfWindowImpl* Window)
00253 {
00254
00255 if (myWindow)
00256 delete myWindow;
00257
00258
00259 myWindow = Window;
00260 myWindow->AddListener(this);
00261
00262
00263 myWindow->AddListener(&myInput);
00264
00265
00266 UseVerticalSync(false);
00267
00268
00269 myClock.Reset();
00270 myLastFrameTime = 0.f;
00271 }