From cb6eb060cc976b52c9f1eb421b1a751ecdf8590a Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Tue, 28 Feb 2012 18:28:16 +0100 Subject: [PATCH] Add a dialogue for windows which can be displayed when the graphics engine initialisation failed The dialogue has fields for resolution and a checkbox for fullscreen mode --- CMakeLists.txt | 14 +-- planet/System.ocg/LanguageDE.txt | 4 + planet/System.ocg/LanguageUS.txt | 4 + src/C4Application.cpp | 4 +- src/gui/C4GfxErrorDlg.cpp | 153 +++++++++++++++++++++++++++++++ src/gui/C4GfxErrorDlg.h | 11 +++ src/res/engine.rc | 20 +++- src/res/resource.h | 9 ++ 8 files changed, 211 insertions(+), 8 deletions(-) create mode 100644 src/gui/C4GfxErrorDlg.cpp create mode 100644 src/gui/C4GfxErrorDlg.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 48e348788..033304df3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,7 @@ separate_arguments(OC_EXE_LINKER_FLAGS_DEBUG) ############################################################################ # User selectable options ############################################################################ -option(PROJECT_FOLDERS "Put source files into subfolders in project file" ON) +option(PROJECT_FOLDERS "Put source files into subfolders in project file" ON) option(USE_GL "Enable OpenGL support" ON) SET(INITIAL_USE_SDL_MAINLOOP_VALUE OFF) SET(INITIAL_USE_OPEN_AL OFF) @@ -56,7 +56,7 @@ if(WIN32 AND FALSE) # disable DX option while it doesn't work anyway list(APPEND CMAKE_LIBRARY_PATH $ENV{DXSDK_DIR}/Lib/x86) endif() else() - + endif() else() SET(USE_DIRECTX OFF) @@ -324,6 +324,8 @@ set(OC_CLONK_SOURCES src/gui/C4GameOptions.h src/gui/C4GameOverDlg.cpp src/gui/C4GameOverDlg.h + src/gui/C4GfxErrorDlg.cpp + src/gui/C4GfxErrorDlg.h src/gui/C4GuiButton.cpp src/gui/C4GuiCheckBox.cpp src/gui/C4GuiComboBox.cpp @@ -873,14 +875,14 @@ if(APPLE) src/res/Ift_Trans.png src/res/NoIft_Trans.png ) - + # Add icon resources set_source_files_properties( ${OC_BUNDLE_RESOURCES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources ) list(APPEND OC_SYSTEM_SOURCES ${OC_BUNDLE_RESOURCES}) - + endif() ############################################################################ @@ -987,7 +989,7 @@ if(HAVE_PTHREAD) pthread ) target_link_libraries(c4script - pthread + pthread ) endif() if(USE_CONSOLE) @@ -1017,7 +1019,7 @@ if (APPLE) SET_TARGET_PROPERTIES(c4group PROPERTIES XCODE_ATTRIBUTE_GCC_PFE_FILE_C_DIALECTS "c++ objective-c++") endif() -# This expands some variables in Info.plist as a side-effect. XCode might then +# This expands some variables in Info.plist as a side-effect. XCode might then # expand a second time, using the same syntax. Try not to get confused by this! set_target_properties(clonk PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/src/res/Info.plist") diff --git a/planet/System.ocg/LanguageDE.txt b/planet/System.ocg/LanguageDE.txt index a859e74b6..0d3337af9 100644 --- a/planet/System.ocg/LanguageDE.txt +++ b/planet/System.ocg/LanguageDE.txt @@ -38,6 +38,7 @@ IDS_BTN_RELOAD=&Aktualisieren IDS_BTN_RENAME=Umbenennen IDS_BTN_RESETCONFIG=Konfiguration zurücksetzen IDS_BTN_RESETKEYBOARD=Alle zurücksetzen +IDS_BTN_RESTART=Neu &Starten IDS_BTN_RETRY=Wiederholen IDS_BTN_SIMPLE=<- Einfach IDS_BTN_START=Starten @@ -784,6 +785,9 @@ IDS_MSG_FREEVIEW=Freie Sicht IDS_MSG_FULLSCREEN=Vollbild IDS_MSG_FULLSCREEN_DESC=Vollbildmodus aktivieren. IDS_MSG_GFXENGINE_DESC=Gibt an, welcher Grafikmodus benutzt wird. Änderungen greifen erst beim nächsten Programmstart. +IDS_MSG_GFXERR_RESINVAL=Ungültige Auflösung! +IDS_MSG_GFXERR_RESNOTFOUND=Die gewählte Auflösung wird vom System anscheinend nicht unterstützt. +IDS_MSG_GFXERR_TXT=OpenClonk konnte OpenGL nicht laden. Prüfen Sie, ob Ihr Grafiktreiber aktuell ist und OpenGL 1.3 unterstützt. IDS_MSG_HASDISCONNECTED=%s hat die Verbindung beendet (%s). IDS_MSG_HASJOINEDTHECHANNEL=%s ist dem Chat-Kanal beigetreten. IDS_MSG_HASLEFTTHECHANNEL=%s hat den Chat-Kanal verlassen (%s) diff --git a/planet/System.ocg/LanguageUS.txt b/planet/System.ocg/LanguageUS.txt index 78bc2e008..8d7a640b3 100644 --- a/planet/System.ocg/LanguageUS.txt +++ b/planet/System.ocg/LanguageUS.txt @@ -38,6 +38,7 @@ IDS_BTN_RELOAD=Reloa&d IDS_BTN_RENAME=Rename IDS_BTN_RESETCONFIG=Reset configuration IDS_BTN_RESETKEYBOARD=Reset all +IDS_BTN_RESTART=Restart IDS_BTN_RETRY=Retry IDS_BTN_SIMPLE=<- Basic IDS_BTN_START=Start @@ -783,6 +784,9 @@ IDS_MSG_FREEVIEW=free view IDS_MSG_FULLSCREEN=Fullscreen IDS_MSG_FULLSCREEN_DESC=Use fullscreen mode. IDS_MSG_GFXENGINE_DESC=Determines the rendering engine. Changes take effect when the game is restarted. +IDS_MSG_GFXERR_RESINVAL=Invalid resolution! +IDS_MSG_GFXERR_RESNOTFOUND=This resolution is probably not supportet by your system. +IDS_MSG_GFXERR_TXT=OpenClonk could not load OpenGL. Please check if your graphics card driver is up-to-date and supports OpenGL 1.3. IDS_MSG_HASDISCONNECTED=%s has disconnected (%s). IDS_MSG_HASJOINEDTHECHANNEL=%s has joined the channel. IDS_MSG_HASLEFTTHECHANNEL=%s has left the channel (%s) diff --git a/src/C4Application.cpp b/src/C4Application.cpp index 120e25298..0af847502 100644 --- a/src/C4Application.cpp +++ b/src/C4Application.cpp @@ -52,6 +52,8 @@ #include +#include + static C4Network2IRCClient ApplicationIRCClient; C4Application::C4Application(): @@ -161,7 +163,7 @@ bool C4Application::DoInit(int argc, char * argv[]) if (!isEditor) { if (!(pWindow = FullScreen.Init(this))) - { Clear(); return false; } + { Clear(); ShowGfxErrorDialog(); return false; } } else { diff --git a/src/gui/C4GfxErrorDlg.cpp b/src/gui/C4GfxErrorDlg.cpp new file mode 100644 index 000000000..1a791ae46 --- /dev/null +++ b/src/gui/C4GfxErrorDlg.cpp @@ -0,0 +1,153 @@ +/* + * OpenClonk, http://www.openclonk.org + * + * Copyright (c) 2012, Julius Michaelis + * + * Portions might be copyrighted by other authors who have contributed + * to OpenClonk. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * See isc_license.txt for full license and disclaimer. + * + * "Clonk" is a registered trademark of Matthes Bender. + * See clonk_trademark_license.txt for full license. + */ + +/* Functions for displaying a settings dialogue to users when the graphics system failed */ + + +#ifdef _WIN32 + +#include +#include +#include +#include +#include +#include + +static int edittext_toi(HWND hWnd, int field) +{ + WCHAR buf[512]; buf[511] = 0; + GetDlgItemTextW(hWnd,field,buf,509); + StdStrBuf data(buf); + const char* bufp = data.getData(); + while(*bufp == ' ') ++bufp; + int res = strtol(bufp, NULL, 0); + if(errno != ERANGE) + return res; + return -1; +} + +static INT_PTR CALLBACK GfxErrProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) +{ + switch(Msg) + { + case WM_INITDIALOG: + // Set Icon, Caption and static Texts + SendMessage(hWnd,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon(Application.GetInstance(),MAKEINTRESOURCE(IDI_00_C4X))); + SendMessage(hWnd,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon(Application.GetInstance(),MAKEINTRESOURCE(IDI_00_C4X))); + SetWindowTextW(hWnd, GetWideChar(C4ENGINECAPTION)); + SetDlgItemTextW(hWnd,IDC_GFXERR_MSG ,GetWideChar(LoadResStr("IDS_MSG_GFXERR_TXT"))); + SetDlgItemTextW(hWnd,IDC_GFXERR_RES ,GetWideChar(LoadResStr("IDS_CTL_RESOLUTION"))); + SetDlgItemTextW(hWnd,IDC_GFXERR_FSCRN,GetWideChar(LoadResStr("IDS_MSG_FULLSCREEN"))); + SetDlgItemTextW(hWnd,IDCANCEL ,GetWideChar(LoadResStr("IDS_DLG_EXIT"))); + SetDlgItemTextW(hWnd,IDOK ,GetWideChar(LoadResStr("IDS_BTN_RESTART"))); + // Set Options + SendMessage(GetDlgItem(hWnd, IDC_GFXERR_FSCRN), BM_SETCHECK, Config.Graphics.Windowed?0:1, 0); + SetDlgItemTextW(hWnd,IDC_GFXERR_XINP ,FormatString("%d",Config.Graphics.ResX).GetWideChar()); + SetDlgItemTextW(hWnd,IDC_GFXERR_YINP ,FormatString("%d",Config.Graphics.ResY).GetWideChar()); + return TRUE; + + case WM_DESTROY: + EndDialog(hWnd,1); + return TRUE; + + case WM_COMMAND: + { + switch(LOWORD(wParam)) + { + case IDCANCEL: + EndDialog(hWnd,1); + return TRUE; + case IDC_GFXERR_FSCRN: + case IDC_GFXERR_XINP: + case IDC_GFXERR_YINP: + { // Handle Resolution values + if(SendMessage(GetDlgItem(hWnd, IDC_GFXERR_FSCRN),BM_GETCHECK,0,0) == BST_CHECKED) + { + int resx = edittext_toi(hWnd,IDC_GFXERR_XINP); + int resy = edittext_toi(hWnd,IDC_GFXERR_YINP); + if(resx < 1 || resy < 1) // res. will be 0 if the user supplies an invalid value + SetDlgItemTextW(hWnd,IDC_GFXERR_INVAL,GetWideChar(LoadResStr("IDS_MSG_GFXERR_RESINVAL"))); + else + { + // Check if res is in list of supportet + bool found = false; + int32_t idx = 0, iXRes, iYRes, iBitDepth; + while (Application.GetIndexedDisplayMode(idx++, &iXRes, &iYRes, &iBitDepth, NULL, Config.Graphics.Monitor)) + if (iBitDepth == Config.Graphics.BitDepth) + if(iXRes == resx && iYRes == resy) + { + found = true; + break; + } + SetDlgItemTextW(hWnd,IDC_GFXERR_INVAL,found?L"":GetWideChar(LoadResStr("IDS_MSG_GFXERR_RESNOTFOUND"))); + } + } + else + SetDlgItemTextW(hWnd,IDC_GFXERR_INVAL,L""); + return TRUE; + } + case IDOK: + { + int resx = edittext_toi(hWnd,IDC_GFXERR_XINP); + int resy = edittext_toi(hWnd,IDC_GFXERR_YINP); + if(resx < 1 || resy < 1) break; + Config.Graphics.Windowed = !(SendMessage(GetDlgItem(hWnd, IDC_GFXERR_FSCRN),BM_GETCHECK,0,0) == BST_CHECKED); + Config.Graphics.ResX = resx; + Config.Graphics.ResY = resy; + Config.Save(); + TCHAR selfpath[4096]; + GetModuleFileName(NULL, selfpath, 4096); + STARTUPINFOW siStartupInfo; + PROCESS_INFORMATION piProcessInfo; + memset(&siStartupInfo, 0, sizeof(siStartupInfo)); + memset(&piProcessInfo, 0, sizeof(piProcessInfo)); + siStartupInfo.cb = sizeof(siStartupInfo); + CreateProcessW(selfpath, L"", + NULL, NULL, FALSE, 0, NULL, Config.General.ExePath.GetWideChar(), &siStartupInfo, &piProcessInfo); + EndDialog(hWnd,2); + return TRUE; + } + } + } + } + return FALSE; +} + +void ShowGfxErrorDialog() +{ + int ret = DialogBox(Application.GetInstance(), MAKEINTRESOURCE(IDD_GFXERROR), NULL, GfxErrProcedure); + if (ret == 0 || ret == -1) + { + LPVOID lpMsgBuf; + DWORD err = GetLastError(); + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + err, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &lpMsgBuf, + 0, NULL ); + LogF("Error in GfxErrorDlg: %d - %s", err, StdStrBuf((wchar_t*)lpMsgBuf).getData()); + LocalFree(lpMsgBuf); + } +} + +#else +void ShowGfxErrorDialog(){} // To be implemented? It's mainly a windows (users') problem. +#endif diff --git a/src/gui/C4GfxErrorDlg.h b/src/gui/C4GfxErrorDlg.h new file mode 100644 index 000000000..2c43d7f43 --- /dev/null +++ b/src/gui/C4GfxErrorDlg.h @@ -0,0 +1,11 @@ +/* + * OpenClonk, http://www.openclonk.org + * + * This file is ineligible for copyright and therefore in the public domain, + * because it does not reach the required threshold of originality. + * + * "Clonk" is a registered trademark of Matthes Bender. + * See clonk_trademark_license.txt for full license. + */ + +void ShowGfxErrorDialog(); diff --git a/src/res/engine.rc b/src/res/engine.rc index 8bfa48c22..14efb4493 100644 --- a/src/res/engine.rc +++ b/src/res/engine.rc @@ -18,7 +18,7 @@ LANGUAGE LANG_GERMAN, SUBLANG_GERMAN // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. -IDI_00_C4X ICON DISCARDABLE "oc.ico" +IDI_00_C4X ICON DISCARDABLE "oc.ico" IDI_01_OCS ICON DISCARDABLE "ocs.ico" IDI_02_OCG ICON DISCARDABLE "ocg.ico" IDI_03_OCF ICON DISCARDABLE "ocf.ico" @@ -167,6 +167,24 @@ BEGIN ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL END +IDD_GFXERROR DIALOGEX 200, 200, 300, 200 +STYLE DS_MODALFRAME | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU | DS_CENTER +CAPTION "OCOGLERR" +FONT 8, "MS Sans Serif", 0, 0, 0x1 +BEGIN + LTEXT "ERRORMSGGFX",IDC_GFXERR_MSG,6,20,294,33 + LTEXT "RES",IDC_GFXERR_RES,40,72,100,11 + LTEXT "X:",IDC_GFXERR_X,100,86,20,11 + EDITTEXT IDC_GFXERR_XINP,120,85,35,13, ES_RIGHT | WS_TABSTOP + LTEXT "Y:",IDC_GFXERR_Y,100,100,20,11 + EDITTEXT IDC_GFXERR_YINP,120,99,35,13, ES_RIGHT | WS_TABSTOP + LTEXT "INVAL",IDC_GFXERR_INVAL,170,86,110,33 + AUTOCHECKBOX "FULLSCREEN",IDC_GFXERR_FSCRN, 40, 135, 100, 11, WS_TABSTOP + DEFPUSHBUTTON "RESTART",IDOK, 180,174,60,14, WS_TABSTOP + PUSHBUTTON "CANCEL",IDCANCEL,60,174,60,14, WS_TABSTOP +END + ///////////////////////////////////////////////////////////////////////////// // // Bitmap diff --git a/src/res/resource.h b/src/res/resource.h index 06b77fc48..26c18b92c 100644 --- a/src/res/resource.h +++ b/src/res/resource.h @@ -54,10 +54,19 @@ #define IDC_STATICSCRIPT 2026 #define IDC_STATICTEXTURE 2027 #define IDC_STATICTIME 2028 +#define IDC_GFXERR_MSG 2029 +#define IDC_GFXERR_RES 2030 +#define IDC_GFXERR_X 2031 +#define IDC_GFXERR_XINP 2032 +#define IDC_GFXERR_Y 2033 +#define IDC_GFXERR_YINP 2034 +#define IDC_GFXERR_FSCRN 2035 +#define IDC_GFXERR_INVAL 2036 #define IDD_COMPONENT 3000 #define IDD_CONSOLE 3001 #define IDD_PROPERTIES 3002 #define IDD_TOOLS 3003 +#define IDD_GFXERROR 3004 #define IDI_00_C4X 4000 #define IDI_01_OCS 4001 #define IDI_02_OCG 4002