X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsdl.c;h=b6fd5b407b2ec9dbfcfe9f0d0af3e49c9d1ddaa7;hb=97f03ad86e7458be79933d91363a38c4d2e35deb;hp=3d45ad0ad28d45f1c12018d2205bbb3be6f7f897;hpb=eb6f957a5666e96d9d9d428bb6e91a5e44ef8601;p=rocksndiamonds.git diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 3d45ad0a..b6fd5b40 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -255,6 +255,7 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window, #endif video.window_scaling_percent = setup.window_scaling_percent; + video.window_scaling_quality = setup.window_scaling_quality; #if defined(TARGET_SDL2) int num_displays = SDL_GetNumVideoDisplays(); @@ -514,13 +515,23 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer, if (sdl_window != NULL) { +#if 0 + /* if SDL_CreateRenderer() is called from within a VirtualBox Windows VM + *without* enabling 2D/3D acceleration and/or guest additions installed, + it will crash if flags are *not* set to SDL_RENDERER_SOFTWARE (because + it will try to use accelerated graphics and apparently fails miserably) */ + if (sdl_renderer == NULL) + sdl_renderer = SDL_CreateRenderer(sdl_window, -1, SDL_RENDERER_SOFTWARE); +#else if (sdl_renderer == NULL) sdl_renderer = SDL_CreateRenderer(sdl_window, -1, 0); +#endif if (sdl_renderer != NULL) { SDL_RenderSetLogicalSize(sdl_renderer, width, height); - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); + // SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, setup.window_scaling_quality); sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, @@ -608,6 +619,8 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen) #endif SDL_Surface *new_surface = NULL; + SetWindowTitle(); + if (*backbuffer == NULL) *backbuffer = CreateBitmapStruct(); @@ -794,6 +807,7 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen) video.fullscreen_enabled = FALSE; video.window_scaling_percent = setup.window_scaling_percent; + video.window_scaling_quality = setup.window_scaling_quality; success = TRUE; } @@ -811,13 +825,26 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen) { SDL_SysWMinfo wminfo; HWND hwnd; + boolean wminfo_success = FALSE; SDL_VERSION(&wminfo.version); - SDL_GetWMInfo(&wminfo); +#if defined(TARGET_SDL2) + if (sdl_window) + wminfo_success = SDL_GetWindowWMInfo(sdl_window, &wminfo); +#else + wminfo_success = (SDL_GetWMInfo(&wminfo) == 1); +#endif - hwnd = wminfo.window; + if (wminfo_success) + { +#if defined(TARGET_SDL2) + hwnd = wminfo.info.win.window; +#else + hwnd = wminfo.window; +#endif - DragAcceptFiles(hwnd, TRUE); + DragAcceptFiles(hwnd, TRUE); + } } #endif #endif @@ -825,6 +852,15 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen) return success; } +void SDLSetWindowTitle() +{ +#if defined(TARGET_SDL2) + SDL_SetWindowTitle(sdl_window, program.window_title); +#else + SDL_WM_SetCaption(program.window_title, program.window_title); +#endif +} + #if defined(TARGET_SDL2) void SDLSetWindowScaling(int window_scaling_percent) { @@ -844,6 +880,32 @@ void SDLSetWindowScaling(int window_scaling_percent) video.window_scaling_percent = window_scaling_percent; video.window_width = new_window_width; video.window_height = new_window_height; + + SetWindowTitle(); +} + +void SDLSetWindowScalingQuality(char *window_scaling_quality) +{ + if (sdl_texture == NULL) + return; + + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, window_scaling_quality); + + SDL_Texture *new_texture = SDL_CreateTexture(sdl_renderer, + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STREAMING, + video.width, video.height); + + if (new_texture != NULL) + { + SDL_DestroyTexture(sdl_texture); + + sdl_texture = new_texture; + + SDLRedrawWindow(); + } + + video.window_scaling_quality = window_scaling_quality; } void SDLSetWindowFullscreen(boolean fullscreen) @@ -2472,9 +2534,17 @@ void SDLHandleWindowManagerEvent(Event *event) SDL_SysWMEvent *syswmevent = (SDL_SysWMEvent *)event; SDL_SysWMmsg *syswmmsg = (SDL_SysWMmsg *)(syswmevent->msg); +#if defined(TARGET_SDL2) + if (syswmmsg->msg.win.msg == WM_DROPFILES) +#else if (syswmmsg->msg == WM_DROPFILES) +#endif { +#if defined(TARGET_SDL2) + HDROP hdrop = (HDROP)syswmmsg->msg.win.wParam; +#else HDROP hdrop = (HDROP)syswmmsg->wParam; +#endif int i, num_files; printf("::: SDL_SYSWMEVENT:\n"); @@ -2491,7 +2561,11 @@ void SDLHandleWindowManagerEvent(Event *event) printf("::: - '%s'\n", buffer); } +#if defined(TARGET_SDL2) + DragFinish((HDROP)syswmmsg->msg.win.wParam); +#else DragFinish((HDROP)syswmmsg->wParam); +#endif } #endif }