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
00032
00037 sfWindow::sfWindow() :
00038 myWindow (NULL),
00039 myLastFrameTime(0.f)
00040 {
00041
00042 }
00043
00044
00048 sfWindow::sfWindow(sfVideoMode Mode, const std::string& Title, bool Fullscreen) :
00049 myWindow (NULL),
00050 myLastFrameTime(0.f)
00051 {
00052 Create(Mode, Title, Fullscreen);
00053 }
00054
00055
00059 sfWindow::sfWindow(void* Handle) :
00060 myWindow (NULL),
00061 myLastFrameTime(0.f)
00062 {
00063 Create(Handle);
00064 }
00065
00066
00070 sfWindow::~sfWindow()
00071 {
00072
00073 delete myWindow;
00074 }
00075
00076
00080 void sfWindow::Create(sfVideoMode Mode, const std::string& Title, bool Fullscreen)
00081 {
00082
00083 if (Fullscreen && !Mode.IsValid())
00084 {
00085 std::cerr << "Requested video mode is not available, switching to a valid mode" << std::endl;
00086 Mode = sfVideoMode::GetMode(0);
00087 }
00088
00089 Initialize(sf_private::sfWindowImpl::New(Mode, Title, Fullscreen));
00090 }
00091
00092
00096 void sfWindow::Create(void* Handle)
00097 {
00098 Initialize(sf_private::sfWindowImpl::New(Handle));
00099 }
00100
00101
00105 unsigned int sfWindow::GetWidth() const
00106 {
00107 return myWindow ? myWindow->GetWidth() : 0;
00108 }
00109
00110
00114 unsigned int sfWindow::GetHeight() const
00115 {
00116 return myWindow ? myWindow->GetHeight() : 0;
00117 }
00118
00119
00123 bool sfWindow::GetEvent(sfEvent& Event)
00124 {
00125
00126 if (!myEvents.empty())
00127 {
00128 Event = myEvents.front();
00129 myEvents.pop();
00130
00131 return true;
00132 }
00133
00134 return false;
00135 }
00136
00137
00141 void sfWindow::UseVerticalSync(bool Enabled)
00142 {
00143 if (SetCurrent())
00144 myWindow->UseVerticalSync(Enabled);
00145 }
00146
00147
00151 bool sfWindow::SetCurrent() const
00152 {
00153 if (myWindow)
00154 {
00155 myWindow->SetCurrent();
00156 return true;
00157 }
00158
00159 return false;
00160 }
00161
00162
00166 void sfWindow::Display()
00167 {
00168 if (SetCurrent())
00169 {
00170
00171 myLastFrameTime = myWindow->Display();
00172
00173
00174 myWindow->ProcessEvents();
00175 }
00176 }
00177
00178
00182 const sfInput& sfWindow::GetInput() const
00183 {
00184 return myInput;
00185 }
00186
00187
00191 float sfWindow::GetFrameTime() const
00192 {
00193 return myLastFrameTime;
00194 }
00195
00196
00200 void sfWindow::OnEvent(const sfEvent& Event)
00201 {
00202 myEvents.push(Event);
00203 }
00204
00205
00209 void sfWindow::Initialize(sf_private::sfWindowImpl* Window)
00210 {
00211
00212 if (myWindow)
00213 delete myWindow;
00214
00215
00216 myWindow = Window;
00217 myWindow->AddListener(this);
00218
00219
00220 myWindow->AddListener(&myInput);
00221
00222
00223 UseVerticalSync(false);
00224
00225
00226 myLastFrameTime = 0.f;
00227 }