| 226 | //------------------------------------------------------------------------------ |
| 227 | |
| 228 | bool GuiCanvas::onAdd() |
| 229 | { |
| 230 | // ensure that we have a cursor |
| 231 | setCursor(dynamic_cast<GuiCursor*>(Sim::findObject("DefaultCursor"))); |
| 232 | |
| 233 | // Enumerate things for GFX before we have an active device. |
| 234 | GFXInit::enumerateAdapters(); |
| 235 | |
| 236 | // Create a device. |
| 237 | GFXAdapter *a = GFXInit::getBestAdapterChoice(); |
| 238 | |
| 239 | // Do we have a global device already? (This is the site if you want |
| 240 | // to start rendering to multiple devices simultaneously) |
| 241 | GFXDevice *newDevice = GFX; |
| 242 | if(newDevice == NULL) |
| 243 | newDevice = GFXInit::createDevice(a); |
| 244 | |
| 245 | newDevice->setAllowRender( false ); |
| 246 | |
| 247 | // Disable starting a new journal recording or playback from here on |
| 248 | Journal::Disable(); |
| 249 | |
| 250 | // Initialize the window... |
| 251 | GFXVideoMode vm = GFXInit::getInitialVideoMode(); |
| 252 | |
| 253 | //If we're recording, store the intial video resolution |
| 254 | if (Journal::IsRecording()) |
| 255 | { |
| 256 | Journal::Write(vm.resolution.x); |
| 257 | Journal::Write(vm.resolution.y); |
| 258 | Journal::Write(vm.fullScreen); |
| 259 | } |
| 260 | |
| 261 | //If we're playing, read the intial video resolution from the journal |
| 262 | if (Journal::IsPlaying()) |
| 263 | { |
| 264 | Journal::Read(&vm.resolution.x); |
| 265 | Journal::Read(&vm.resolution.y); |
| 266 | Journal::Read(&vm.fullScreen); |
| 267 | } |
| 268 | |
| 269 | if (a && a->mType != NullDevice) |
| 270 | { |
| 271 | mPlatformWindow = WindowManager->createWindow(newDevice, vm); |
| 272 | |
| 273 | //Disable window resizing if recording ir playing a journal |
| 274 | if (Journal::IsRecording() || Journal::IsPlaying()) |
| 275 | mPlatformWindow->lockSize(true); |
| 276 | |
| 277 | // Set a minimum on the window size so people can't break us by resizing tiny. |
| 278 | mPlatformWindow->setMinimumWindowSize(Point2I(Con::getIntVariable("$Video::minimumXResolution", 1024), |
| 279 | Con::getIntVariable("$Video::minimumYResolution", 720))); |
| 280 | |
| 281 | // Now, we have to hook in our event callbacks so we'll get |
| 282 | // appropriate events from the window. |
| 283 | mPlatformWindow->resizeEvent .notify(this, &GuiCanvas::handleResize); |
| 284 | mPlatformWindow->appEvent .notify(this, &GuiCanvas::handleAppEvent); |
| 285 | mPlatformWindow->displayEvent.notify(this, &GuiCanvas::handlePaintEvent); |
nothing calls this directly
no test coverage detected