make HMENU possible on Windows SDL2

This commit is contained in:
Wengier 2022-01-25 01:38:24 -05:00
parent ee713dabeb
commit adca760169
7 changed files with 43 additions and 8 deletions

View File

@ -101,7 +101,7 @@ void DOSBox_NoMenu(void);
#if C_FORCE_MENU_SDLDRAW /* Programmer/Dev wants to compile with SDL drawn menus even if host OS offers menus (shrug) Ok */
# define DOSBOXMENU_TYPE DOSBOXMENU_SDLDRAW
#elif defined(WIN32) && !defined(C_SDL2) && !defined(HX_DOS)
#elif defined(WIN32) && !defined(C_SDL2) && !defined(HX_DOS) // Windows SDL1 (except for HX-DOS)
# define DOSBOXMENU_TYPE DOSBOXMENU_HMENU
#elif defined(MACOSX)
# define DOSBOXMENU_TYPE DOSBOXMENU_NSMENU

View File

@ -65,10 +65,6 @@ void* sdl_hax_nsMenuItemAlloc(cons
void sdl_hax_nsMenuItemRelease(void *nsMenuItem);
#endif
#if DOSBOXMENU_TYPE == DOSBOXMENU_HMENU
extern "C" void SDL1_hax_SetMenu(HMENU menu);
#endif
void reflectmenu_INITMENU_cb();
bool GFX_GetPreventFullscreen(void);
void RENDER_CallBack( GFX_CallBackFunctions_t function );
@ -1785,6 +1781,15 @@ void SetVal(const std::string& secname, const std::string& preval, const std::st
}
}
#if defined(WIN32) && defined(C_SDL2) && defined(SDL_DOSBOX_X_IME)
extern "C" void SDL2_hax_SetMenu(SDL_Window *window, HMENU menu);
void SDL1_hax_SetMenu(HMENU menu) {
SDL2_hax_SetMenu(sdl.window, menu);
}
#elif DOSBOXMENU_TYPE == DOSBOXMENU_HMENU
extern "C" void SDL1_hax_SetMenu(HMENU menu);
#endif
void DOSBox_SetMenu(DOSBoxMenu &altMenu) {
#if DOSBOXMENU_TYPE == DOSBOXMENU_SDLDRAW
/* nothing to do */

View File

@ -41,10 +41,12 @@ bool date_host_forced=false;
#if defined (WIN32) && !defined (__MINGW32__)
typedef Bitu suseconds_t;
#if !(defined (C_SDL2) && defined(SDL_DOSBOX_X_IME))
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
#endif
static void gettimeofday (timeval* ptime, void* pdummy) {
struct _timeb thetime;

View File

@ -123,8 +123,13 @@ std::string GetDOSBoxXPath(bool withexe=false);
#if defined(C_SDL2)
void GFX_SetResizeable(bool enable);
SDL_Window * GFX_SetSDLSurfaceWindow(uint16_t width, uint16_t height);
#elif defined(WIN32)
#endif
#if defined(WIN32)
#if !defined(C_SDL2)
extern "C" void SDL1_hax_SetMenu(HMENU menu);
#elif DOSBOXMENU_TYPE == DOSBOXMENU_HMENU
void SDL1_hax_SetMenu(HMENU menu);
#endif
#endif
Bitu OUTPUT_TTF_SetSize() {

View File

@ -38,6 +38,9 @@
#include "SDL_quit.h"
#include "SDL_gesture.h"
#include "SDL_touch.h"
#if __WIN32__
#include "windows.h"
#endif
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
@ -777,6 +780,10 @@ extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state);
*/
extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
#if __WIN32__
extern DECLSPEC void SDL2_hax_SetMenu(SDL_Window *window, HMENU menu);
#endif
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}

View File

@ -167,13 +167,14 @@ DEFINE_GUID(SDL_IID_IMMDeviceEnumerator, 0xA95664D2, 0x9614, 0x4F35, 0xA7, 0x46,
DEFINE_GUID(SDL_IID_IAudioEndpointVolume, 0x5CDF2C82, 0x841E, 0x4546, 0x97, 0x22, 0x0C, 0xF7, 0x40, 0x78, 0x22, 0x9A);
#endif
static float GetSystemVolume(void)
{
float volume = -1.0f; /* Return this if we can't get system volume */
#if defined(__WIN32__) && defined(HAVE_ENDPOINTVOLUME_H)
#ifndef IUnknown_Release
#define IUnknown_Release(p) (p)->lpVtbl->Release(p)
#endif
HRESULT hr = WIN_CoInitialize();
if (SUCCEEDED(hr)) {
IMMDeviceEnumerator *pEnumerator;

View File

@ -222,6 +222,21 @@ WIN_CreateDevice(int devindex)
return device;
}
HMENU WIN_SurfaceMenu = NULL;
void SDL2_hax_SetMenu(SDL_Window * window, HMENU menu) {
if (menu == WIN_SurfaceMenu)
return;
WIN_SurfaceMenu = menu;
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if ((window->flags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN)
SetMenu(data->hwnd, NULL);
else
SetMenu(data->hwnd, WIN_SurfaceMenu);
DrawMenuBar(data->hwnd);
}
VideoBootStrap WINDOWS_bootstrap = {
"windows", "SDL Windows video driver", WIN_Available, WIN_CreateDevice