| 21 | } |
| 22 | |
| 23 | bool SdlBaseManager::create(int _width, int _height) |
| 24 | { |
| 25 | // initialize SDL |
| 26 | if (SDL_Init(SDL_INIT_VIDEO) != 0) |
| 27 | { |
| 28 | std::cerr << "Failed to initialize SDL2."; |
| 29 | exit(1); |
| 30 | } |
| 31 | |
| 32 | const int width = _width; |
| 33 | const int height = _height; |
| 34 | bool windowed = true; |
| 35 | |
| 36 | // create window and position it at the center of the screen |
| 37 | SDL_DisplayMode currDisp; |
| 38 | if (SDL_GetCurrentDisplayMode(0, &currDisp) != 0) |
| 39 | { |
| 40 | std::cerr << "Failed to retrieve screen info."; |
| 41 | exit(1); |
| 42 | } |
| 43 | int left = (currDisp.w - width) / 2; |
| 44 | int top = (currDisp.h - height) / 2; |
| 45 | |
| 46 | mSdlWindow = SDL_CreateWindow( |
| 47 | "MyGUI Render Window", |
| 48 | left, |
| 49 | top, |
| 50 | width, |
| 51 | height, |
| 52 | (mIsOpenGlWindow ? SDL_WINDOW_OPENGL : 0) | SDL_WINDOW_RESIZABLE); |
| 53 | if (mSdlWindow == nullptr) |
| 54 | { |
| 55 | std::cerr << "Failed to create SDL window."; |
| 56 | exit(1); |
| 57 | } |
| 58 | mWindowOn = true; |
| 59 | |
| 60 | #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 |
| 61 | // set icon |
| 62 | SDL_SysWMinfo wmInfo; |
| 63 | SDL_VERSION(&wmInfo.version) |
| 64 | if (SDL_GetWindowWMInfo(mSdlWindow, &wmInfo) == SDL_FALSE) |
| 65 | { |
| 66 | std::cerr << "Failed to SDL_GetWindowWMInfo."; |
| 67 | exit(1); |
| 68 | } |
| 69 | size_t handle = (size_t)wmInfo.info.win.window; |
| 70 | |
| 71 | char buf[MAX_PATH]; |
| 72 | ::GetModuleFileNameA(0, (LPCH)&buf, MAX_PATH); |
| 73 | HINSTANCE instance = ::GetModuleHandleA(buf); |
| 74 | HICON hIconSmall = |
| 75 | static_cast<HICON>(LoadImage(instance, MAKEINTRESOURCE(1001), IMAGE_ICON, 32, 32, LR_DEFAULTSIZE)); |
| 76 | HICON hIconBig = |
| 77 | static_cast<HICON>(LoadImage(instance, MAKEINTRESOURCE(1001), IMAGE_ICON, 256, 256, LR_DEFAULTSIZE)); |
| 78 | if (hIconSmall) |
| 79 | ::SendMessageA((HWND)handle, WM_SETICON, 0, (LPARAM)hIconSmall); |
| 80 | if (hIconBig) |