diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6652861..41527be 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -70,7 +70,7 @@ target_sources(xsystem35 PRIVATE network.c) if (WIN32) - target_sources(xsystem35 PRIVATE win/dialog.c win/resources.rc) + target_sources(xsystem35 PRIVATE win/dialog.c win/resources.rc win/menubar.c) endif() if (EMSCRIPTEN) diff --git a/src/menu.h b/src/menu.h index 8b93812..2da339d 100644 --- a/src/menu.h +++ b/src/menu.h @@ -55,4 +55,10 @@ extern void menu_widgetinit(void); extern void menu_init(); extern void menu_gtkmainiteration(); +#ifdef _WIN32 +struct SDL_SysWMmsg; +extern void win_menu_init(void); +extern void win_menu_onsyswmevent(struct SDL_SysWMmsg* msg); +#endif + #endif /* !__MENULL */ diff --git a/src/menu_sdl.c b/src/menu_sdl.c index 5720605..8e0bb2d 100644 --- a/src/menu_sdl.c +++ b/src/menu_sdl.c @@ -88,7 +88,9 @@ void menu_msgbox_open(char *msg) { } void menu_init(void) { - return; +#ifdef _WIN32 + win_menu_init(); +#endif } void menu_gtkmainiteration() { diff --git a/src/sdl_event.c b/src/sdl_event.c index 54ec5e0..d0cb201 100644 --- a/src/sdl_event.c +++ b/src/sdl_event.c @@ -126,6 +126,11 @@ static void sdl_getEvent(void) { break; } break; +#ifdef _WIN32 + case SDL_SYSWMEVENT: + win_menu_onsyswmevent(e.syswm.msg); + break; +#endif case SDL_APP_DIDENTERFOREGROUND: sdl_dirty = TRUE; break; diff --git a/src/win/menubar.c b/src/win/menubar.c new file mode 100644 index 0000000..dbd603d --- /dev/null +++ b/src/win/menubar.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2020 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#include +#undef min +#undef max +#include +#include "system.h" +#include "menu.h" +#include "sdl_private.h" +#include "resources.h" +#include "ags.h" + +static HWND get_hwnd(SDL_Window *window) { + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + SDL_GetWindowWMInfo(window, &info); + return info.info.win.window; +} + +void win_menu_init(void) { + HINSTANCE hinst = (HINSTANCE)GetModuleHandle(NULL); + HMENU hmenu = LoadMenu(hinst, MAKEINTRESOURCE(IDR_MENU1)); + SetMenu(get_hwnd(sdl_window), hmenu); + SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); + // Let SDL recalc the window size, taking menu height into account. + SDL_SetWindowSize(sdl_window, view_w, view_h); +} + +void win_menu_onsyswmevent(SDL_SysWMmsg* msg) { + switch (msg->msg.win.msg) { + case WM_COMMAND: + switch (msg->msg.win.wParam) { + case ID_EXIT: + menu_quitmenu_open(); + break; + case ID_SCREEN_WINDOW: + ags_fullscreen(FALSE); + break; + case ID_SCREEN_FULL: + ags_fullscreen(TRUE); + break; + } + break; + } +} diff --git a/src/win/resources.h b/src/win/resources.h index cc6ba42..419fd2b 100644 --- a/src/win/resources.h +++ b/src/win/resources.h @@ -21,10 +21,15 @@ #define XSYSTEM35_REGKEY "Software\\Kichikuou\\xsystem35" +#define IDR_MENU1 101 #define IDD_DIALOG1 103 #define IDC_TEXT 104 #define IDC_EDITBOX 105 #define IDS_CHOOSE_GAME_FOLDER 1001 +#define ID_EXIT 40001 +#define ID_SCREEN_WINDOW 40002 +#define ID_SCREEN_FULL 40003 + #endif /* __RESOURCES_H__ */ diff --git a/src/win/resources.rc b/src/win/resources.rc index 2e69112..7c34b57 100644 --- a/src/win/resources.rc +++ b/src/win/resources.rc @@ -4,7 +4,22 @@ 100 ICON DISCARDABLE "xsystem35.ico" +//////////////////////////////////////////////////////////////////////// LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL + +IDR_MENU1 MENU DISCARDABLE +{ + POPUP "File" + { + MENUITEM "Exit", ID_EXIT + } + POPUP "Screen" + { + MENUITEM "Window", ID_SCREEN_WINDOW + MENUITEM "Fullscreen", ID_SCREEN_FULL + } +} + STRINGTABLE { IDS_CHOOSE_GAME_FOLDER "Choose a game folder:" @@ -20,7 +35,22 @@ FONT 9, "MS Shell Dlg" DEFPUSHBUTTON "OK",IDOK,35,36,50,14 } +//////////////////////////////////////////////////////////////////////// LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT + +IDR_MENU1 MENU DISCARDABLE +{ + POPUP "ファイル" + { + MENUITEM "閉じる", ID_EXIT + } + POPUP "画面" + { + MENUITEM "ウィンドウ", ID_SCREEN_WINDOW + MENUITEM "フルスクリーン", ID_SCREEN_FULL + } +} + STRINGTABLE { IDS_CHOOSE_GAME_FOLDER "ゲームフォルダを選んでください:" diff --git a/src/xsystem35.c b/src/xsystem35.c index 5748f81..2be0f6d 100644 --- a/src/xsystem35.c +++ b/src/xsystem35.c @@ -518,8 +518,8 @@ int main(int argc, char **argv) { gtk_rc_parse(rc_path); free(rc_path); - menu_init(); #endif + menu_init(); nact_main(); #ifdef __EMSCRIPTEN__