bool CoreWin32Platform::CreateWin32Window(HINSTANCE hInstance) { this->hInstance = hInstance; //single instance check TCHAR fileName[MAX_PATH]; GetModuleFileName(NULL, fileName, MAX_PATH); fileName[MAX_PATH-1] = 0; //string can be not null-terminated on winXP for(int32 i = 0; i < MAX_PATH; ++i) { if(fileName[i] == L'\\') //symbol \ is not allowed in CreateMutex mutex name { fileName[i] = ' '; } } hMutex = CreateMutex(NULL, FALSE, fileName); if(ERROR_ALREADY_EXISTS == GetLastError()) { return false; } windowedMode = DisplayMode(800, 600, 16, 0); fullscreenMode = DisplayMode(800, 600, 16, 0); currentMode = windowedMode; isFullscreen = false; // create the window, only if we do not use the null device LPCWSTR className = L"DavaFrameworkWindowsDevice"; // Register Class WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = 0; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = 0; wcex.lpszClassName = className; wcex.hIconSm = 0; RegisterClassEx(&wcex); // calculate client size RECT clientSize; clientSize.top = 0; clientSize.left = 0; clientSize.right = currentMode.width; clientSize.bottom = currentMode.height; ULONG style = WINDOWED_STYLE | WS_CLIPCHILDREN; // Create the rendering window if (isFullscreen) { style = WS_VISIBLE | WS_POPUP; } // End if Fullscreen AdjustWindowRect(&clientSize, style, FALSE); int32 realWidth = clientSize.right - clientSize.left; int32 realHeight = clientSize.bottom - clientSize.top; int32 windowLeft = -10000;//(GetSystemMetrics(SM_CXSCREEN) - realWidth) / 2; int32 windowTop = -10000;//(GetSystemMetrics(SM_CYSCREEN) - realHeight) / 2; if (isFullscreen) { windowLeft = 0; windowTop = 0; } // create window hWindow = CreateWindow( className, L"", style, windowLeft, windowTop, realWidth, realHeight, NULL, NULL, hInstance, NULL); ShowWindow(hWindow, SW_SHOW); UpdateWindow(hWindow); // fix ugly ATI driver bugs. Thanks to ariaci (Taken from Irrlight). MoveWindow(hWindow, windowLeft, windowTop, realWidth, realHeight, TRUE); #if defined(__DAVAENGINE_DIRECTX9__) RenderManager::Create(Core::RENDERER_DIRECTX9); #elif defined(__DAVAENGINE_OPENGL__) RenderManager::Create(Core::RENDERER_OPENGL); #endif RenderManager::Instance()->Create(hInstance, hWindow); FrameworkDidLaunched(); KeyedArchive * options = Core::GetOptions(); //fullscreenMode = GetCurrentDisplayMode(); fullscreenMode = GetCurrentDisplayMode();//FindBestMode(fullscreenMode); if (options) { windowedMode.width = options->GetInt32("width"); windowedMode.height = options->GetInt32("height"); windowedMode.bpp = options->GetInt32("bpp"); // get values from config in case if they are available fullscreenMode.width = options->GetInt32("fullscreen.width", fullscreenMode.width); fullscreenMode.height = options->GetInt32("fullscreen.height", fullscreenMode.height); fullscreenMode.bpp = windowedMode.bpp; fullscreenMode = FindBestMode(fullscreenMode); isFullscreen = (0 != options->GetInt32("fullscreen")); String title = options->GetString("title", "[set application title using core options property 'title']"); WideString titleW = StringToWString(title); SetWindowText(hWindow, titleW.c_str()); } Logger::FrameworkDebug("[PlatformWin32] best display fullscreen mode matched: %d x %d x %d refreshRate: %d", fullscreenMode.width, fullscreenMode.height, fullscreenMode.bpp, fullscreenMode.refreshRate); currentMode = windowedMode; if (isFullscreen) { currentMode = fullscreenMode; } clientSize.top = 0; clientSize.left = 0; clientSize.right = currentMode.width; clientSize.bottom = currentMode.height; AdjustWindowRect(&clientSize, style, FALSE); realWidth = clientSize.right - clientSize.left; realHeight = clientSize.bottom - clientSize.top; windowLeft = (GetSystemMetrics(SM_CXSCREEN) - realWidth) / 2; windowTop = (GetSystemMetrics(SM_CYSCREEN) - realHeight) / 2; MoveWindow(hWindow, windowLeft, windowTop, realWidth, realHeight, TRUE); RAWINPUTDEVICE Rid; Rid.usUsagePage = 0x01; Rid.usUsage = 0x02; Rid.dwFlags = 0; Rid.hwndTarget = 0; RegisterRawInputDevices(&Rid, 1, sizeof(Rid)); RenderManager::Instance()->ChangeDisplayMode(currentMode, isFullscreen); RenderManager::Instance()->Init(currentMode.width, currentMode.height); UIControlSystem::Instance()->SetInputScreenAreaSize(currentMode.width, currentMode.height); Core::Instance()->SetPhysicalScreenSize(currentMode.width, currentMode.height); return true; }
bool CDisplaySettings::OnSettingChanging(const CSetting *setting) { if (setting == NULL) return false; const std::string &settingId = setting->GetId(); if (settingId == CSettings::SETTING_VIDEOSCREEN_RESOLUTION || settingId == CSettings::SETTING_VIDEOSCREEN_SCREEN) { RESOLUTION newRes = RES_DESKTOP; if (settingId == CSettings::SETTING_VIDEOSCREEN_RESOLUTION) newRes = (RESOLUTION)((CSettingInt*)setting)->GetValue(); else if (settingId == CSettings::SETTING_VIDEOSCREEN_SCREEN) { int screen = ((CSettingInt*)setting)->GetValue(); // if triggered by a change of screenmode, screen may not have changed if (screen == GetCurrentDisplayMode()) return true; // get desktop resolution for screen newRes = GetResolutionForScreen(); } std::string screenmode = GetStringFromResolution(newRes); CSettings::Get().SetString(CSettings::SETTING_VIDEOSCREEN_SCREENMODE, screenmode); } if (settingId == CSettings::SETTING_VIDEOSCREEN_SCREENMODE) { RESOLUTION oldRes = GetCurrentResolution(); RESOLUTION newRes = GetResolutionFromString(((CSettingString*)setting)->GetValue()); SetCurrentResolution(newRes, false); g_graphicsContext.SetVideoResolution(newRes); // check if the old or the new resolution was/is windowed // in which case we don't show any prompt to the user if (oldRes != RES_WINDOW && newRes != RES_WINDOW && oldRes != newRes) { if (!m_resolutionChangeAborted) { bool cancelled = false; if (!CGUIDialogYesNo::ShowAndGetInput(CVariant{13110}, CVariant{13111}, cancelled, CVariant{""}, CVariant{""}, 10000)) { m_resolutionChangeAborted = true; return false; } } else m_resolutionChangeAborted = false; } } else if (settingId == CSettings::SETTING_VIDEOSCREEN_MONITOR) { g_Windowing.UpdateResolutions(); RESOLUTION newRes = GetResolutionForScreen(); SetCurrentResolution(newRes, false); g_graphicsContext.SetVideoResolution(newRes, true); if (!m_resolutionChangeAborted) { bool cancelled = false; if (!CGUIDialogYesNo::ShowAndGetInput(CVariant{13110}, CVariant{13111}, cancelled, CVariant{""}, CVariant{""}, 10000)) { m_resolutionChangeAborted = true; return false; } } else m_resolutionChangeAborted = false; return true; } #if defined(HAS_GLX) else if (settingId == CSettings::SETTING_VIDEOSCREEN_BLANKDISPLAYS) { g_Windowing.UpdateResolutions(); } #endif return true; }
void NPAPICoreMacOSPlatform::GetAvailableDisplayModes(List<DisplayMode> & availableModes) { // One and only Display Mode is available on NPAPI plugin. availableModes.push_back(GetCurrentDisplayMode()); }