Skip to content

Commit

Permalink
Merge pull request hrydgard#11609 from unknownbrackets/win-menu
Browse files Browse the repository at this point in the history
Windows: Translate all items by id, not position
  • Loading branch information
hrydgard authored Nov 29, 2018
2 parents 9bda7cb + db7cdce commit 93bb96d
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 128 deletions.
142 changes: 48 additions & 94 deletions Windows/MainWindowMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace MainWindow {
static W32Util::AsyncBrowseDialog *browseImageDialog;
static bool browsePauseAfter;

static std::map<int, std::string> initialMenuKeys;
static std::unordered_map<int, std::string> initialMenuKeys;
static std::vector<std::string> availableShaders;
static std::string menuLanguageID = "";
static bool menuShaderInfoLoaded = false;
Expand Down Expand Up @@ -79,44 +79,23 @@ namespace MainWindow {
EnableMenuItem(menu, ID_OPTIONS_LANGUAGE, state == UISTATE_INGAME ? MF_GRAYED : MF_ENABLED);
}

// These are used as an offset
// to determine which menu item to change.
// Make sure to count(from 0) the separators too, when dealing with submenus!!
enum MenuItemPosition {
// Main menus
MENU_FILE = 0,
MENU_EMULATION = 1,
MENU_DEBUG = 2,
MENU_OPTIONS = 3,
MENU_HELP = 4,

// File submenus
SUBMENU_FILE_SAVESTATE_SLOT = 6,
SUBMENU_FILE_RECORD = 11,

// Emulation submenus
SUBMENU_DISPLAY_ROTATION = 4,

// Game Settings submenus
SUBMENU_DISPLAY_LAYOUT = 7,
SUBMENU_CUSTOM_SHADERS = 10,
SUBMENU_RENDERING_RESOLUTION = 11,
SUBMENU_WINDOW_SIZE = 12,
SUBMENU_RENDERING_BACKEND = 13,
SUBMENU_RENDERING_MODE = 14,
SUBMENU_FRAME_SKIPPING = 15,
SUBMENU_TEXTURE_FILTERING = 16,
SUBMENU_BUFFER_FILTER = 17,
SUBMENU_TEXTURE_SCALING = 18,
};
static HMENU GetSubmenuById(HMENU menu, int menuID) {
MENUITEMINFO menuInfo{ sizeof(MENUITEMINFO), MIIM_SUBMENU };
if (GetMenuItemInfo(menu, menuID, MF_BYCOMMAND, &menuInfo) != FALSE) {
return menuInfo.hSubMenu;
}
return nullptr;
}

static std::string GetMenuItemText(HMENU menu, int menuID) {
MENUITEMINFO menuInfo;
memset(&menuInfo, 0, sizeof(menuInfo));
menuInfo.cbSize = sizeof(MENUITEMINFO);
menuInfo.fMask = MIIM_STRING;
menuInfo.dwTypeData = 0;
static void EmptySubMenu(HMENU menu) {
int c = GetMenuItemCount(menu);
for (int i = 0; i < c; ++i) {
RemoveMenu(menu, i, MF_BYPOSITION);
}
}

static std::string GetMenuItemText(HMENU menu, int menuID) {
MENUITEMINFO menuInfo{ sizeof(menuInfo), MIIM_STRING };
std::string retVal;
if (GetMenuItemInfo(menu, menuID, MF_BYCOMMAND, &menuInfo) != FALSE) {
wchar_t *buffer = new wchar_t[++menuInfo.cch];
Expand All @@ -139,19 +118,15 @@ namespace MainWindow {
void CreateHelpMenu(HMENU menu) {
I18NCategory *des = GetI18NCategory("DesktopUI");

const std::wstring help = ConvertUTF8ToWString(des->T("Help"));
const std::wstring visitMainWebsite = ConvertUTF8ToWString(des->T("www.ppsspp.org"));
const std::wstring visitForum = ConvertUTF8ToWString(des->T("PPSSPP Forums"));
const std::wstring buyGold = ConvertUTF8ToWString(des->T("Buy Gold"));
const std::wstring gitHub = ConvertUTF8ToWString(des->T("GitHub"));
const std::wstring discord = ConvertUTF8ToWString(des->T("Discord"));
const std::wstring aboutPPSSPP = ConvertUTF8ToWString(des->T("About PPSSPP..."));

// Simply remove the old help menu and create a new one.
RemoveMenu(menu, MENU_HELP, MF_BYPOSITION);

HMENU helpMenu = CreatePopupMenu();
InsertMenu(menu, MENU_HELP, MF_POPUP | MF_STRING | MF_BYPOSITION, (UINT_PTR)helpMenu, help.c_str());
HMENU helpMenu = GetSubmenuById(menu, ID_HELP_MENU);
EmptySubMenu(helpMenu);

AppendMenu(helpMenu, MF_STRING | MF_BYCOMMAND, ID_HELP_OPENWEBSITE, visitMainWebsite.c_str());
AppendMenu(helpMenu, MF_STRING | MF_BYCOMMAND, ID_HELP_OPENFORUM, visitForum.c_str());
Expand Down Expand Up @@ -187,20 +162,12 @@ namespace MainWindow {
return false;
}

I18NCategory *des = GetI18NCategory("DesktopUI");
I18NCategory *ps = GetI18NCategory("PostShaders");
const std::wstring key = ConvertUTF8ToWString(des->T("Postprocessing Shader"));

HMENU optionsMenu = GetSubMenu(menu, MENU_OPTIONS);

HMENU shaderMenu = CreatePopupMenu();

RemoveMenu(optionsMenu, SUBMENU_CUSTOM_SHADERS, MF_BYPOSITION);
InsertMenu(optionsMenu, SUBMENU_CUSTOM_SHADERS, MF_POPUP | MF_STRING | MF_BYPOSITION, (UINT_PTR)shaderMenu, key.c_str());
HMENU shaderMenu = GetSubmenuById(menu, ID_OPTIONS_SHADER_MENU);
EmptySubMenu(shaderMenu);

int item = ID_SHADERS_BASE + 1;
int checkedStatus = -1;

const char *translatedShaderName = nullptr;

availableShaders.clear();
Expand All @@ -209,7 +176,7 @@ namespace MainWindow {
AppendMenu(shaderMenu, MF_STRING | MF_BYPOSITION | MF_GRAYED, item++, ConvertUTF8ToWString(translatedShaderName).c_str());
} else {
for (auto i = info.begin(); i != info.end(); ++i) {
checkedStatus = MF_UNCHECKED;
int checkedStatus = MF_UNCHECKED;
availableShaders.push_back(i->section);
if (g_Config.sPostShaderName == i->section) {
checkedStatus = MF_CHECKED;
Expand All @@ -225,60 +192,46 @@ namespace MainWindow {
return true;
}

static void _TranslateMenuItem(const HMENU hMenu, const int menuIDOrPosition, const char *key, bool byCommand = false, const std::wstring& accelerator = L"") {
static void TranslateMenuItem(const HMENU hMenu, const int menuID, const std::wstring& accelerator = L"", const char *key = nullptr) {
I18NCategory *des = GetI18NCategory("DesktopUI");

std::wstring translated = ConvertUTF8ToWString(des->T(key));
std::wstring translated;
if (key == nullptr || !strcmp(key, "")) {
translated = ConvertUTF8ToWString(des->T(GetMenuItemInitialText(hMenu, menuID)));
} else {
translated = ConvertUTF8ToWString(des->T(key));
}
translated.append(accelerator);

u32 flags = MF_STRING | (byCommand ? MF_BYCOMMAND : MF_BYPOSITION);

ModifyMenu(hMenu, menuIDOrPosition, flags, menuIDOrPosition, translated.c_str());
}

void TranslateMenuItem(HMENU menu, int menuID, const std::wstring& accelerator = L"", const char *key = "") {
if (key == nullptr || !strcmp(key, ""))
_TranslateMenuItem(menu, menuID, GetMenuItemInitialText(menu, menuID).c_str(), true, accelerator);
else
_TranslateMenuItem(menu, menuID, key, true, accelerator);
}

void TranslateMenu(HMENU menu, const char *key, const MenuItemPosition mainMenuPosition, const std::wstring& accelerator = L"") {
_TranslateMenuItem(menu, mainMenuPosition, key, false, accelerator);
}

void TranslateSubMenu(HMENU menu, const char *key, const MenuItemPosition mainMenuItem, const MenuItemPosition subMenuItem, const std::wstring& accelerator = L"") {
_TranslateMenuItem(GetSubMenu(menu, mainMenuItem), subMenuItem, key, false, accelerator);
ModifyMenu(hMenu, menuID, MF_STRING | MF_BYCOMMAND, menuID, translated.c_str());
}

void DoTranslateMenus(HWND hWnd, HMENU menu) {
// Menu headers and submenu headers don't have resource IDs,
// So we have to hardcode strings here, unfortunately.
TranslateMenu(menu, "File", MENU_FILE);
TranslateMenu(menu, "Emulation", MENU_EMULATION);
TranslateMenu(menu, "Debugging", MENU_DEBUG);
TranslateMenu(menu, "Game Settings", MENU_OPTIONS);
TranslateMenu(menu, "Help", MENU_HELP);
TranslateMenuItem(menu, ID_FILE_MENU);
TranslateMenuItem(menu, ID_EMULATION_MENU);
TranslateMenuItem(menu, ID_DEBUG_MENU);
TranslateMenuItem(menu, ID_OPTIONS_MENU);
TranslateMenuItem(menu, ID_HELP_MENU);

// File menu
TranslateMenuItem(menu, ID_FILE_LOAD);
TranslateMenuItem(menu, ID_FILE_LOAD_DIR);
TranslateMenuItem(menu, ID_FILE_LOAD_MEMSTICK);
TranslateMenuItem(menu, ID_FILE_MEMSTICK);
TranslateSubMenu(menu, "Savestate Slot", MENU_FILE, SUBMENU_FILE_SAVESTATE_SLOT, L"\tF3");
TranslateMenuItem(menu, ID_FILE_SAVESTATE_SLOT_MENU, L"\tF3");
TranslateMenuItem(menu, ID_FILE_QUICKLOADSTATE, L"\tF4");
TranslateMenuItem(menu, ID_FILE_QUICKSAVESTATE, L"\tF2");
TranslateMenuItem(menu, ID_FILE_LOADSTATEFILE);
TranslateMenuItem(menu, ID_FILE_SAVESTATEFILE);
TranslateSubMenu(menu, "Record", MENU_FILE, SUBMENU_FILE_RECORD);
TranslateMenuItem(menu, ID_FILE_RECORD_MENU);
TranslateMenuItem(menu, ID_FILE_EXIT, L"\tAlt+F4");

// Emulation menu
TranslateMenuItem(menu, ID_EMULATION_PAUSE);
TranslateMenuItem(menu, ID_EMULATION_STOP, L"\tCtrl+W");
TranslateMenuItem(menu, ID_EMULATION_RESET, L"\tCtrl+B");
TranslateMenuItem(menu, ID_EMULATION_SWITCH_UMD, L"\tCtrl+U", "Switch UMD");
TranslateSubMenu(menu, "Display Rotation", MENU_EMULATION, SUBMENU_DISPLAY_ROTATION);
TranslateMenuItem(menu, ID_EMULATION_SWITCH_UMD, L"\tCtrl+U");
TranslateMenuItem(menu, ID_EMULATION_ROTATION_MENU);
TranslateMenuItem(menu, ID_EMULATION_ROTATION_H);
TranslateMenuItem(menu, ID_EMULATION_ROTATION_V);
TranslateMenuItem(menu, ID_EMULATION_ROTATION_H_R);
Expand Down Expand Up @@ -319,36 +272,37 @@ namespace MainWindow {
// Skip display multipliers x1-x10
TranslateMenuItem(menu, ID_OPTIONS_FULLSCREEN, L"\tAlt+Return, F11");
TranslateMenuItem(menu, ID_OPTIONS_VSYNC);
TranslateSubMenu(menu, "Postprocessing Shader", MENU_OPTIONS, SUBMENU_CUSTOM_SHADERS);
TranslateSubMenu(menu, "Rendering Resolution", MENU_OPTIONS, SUBMENU_RENDERING_RESOLUTION, L"\tCtrl+1");
TranslateMenuItem(menu, ID_OPTIONS_SHADER_MENU);
TranslateMenuItem(menu, ID_OPTIONS_SCREEN_MENU, L"\tCtrl+1");
TranslateMenuItem(menu, ID_OPTIONS_SCREENAUTO);
// Skip rendering resolution 2x-5x..
TranslateSubMenu(menu, "Window Size", MENU_OPTIONS, SUBMENU_WINDOW_SIZE);
TranslateMenuItem(menu, ID_OPTIONS_WINDOW_MENU);
// Skip window size 1x-4x..
TranslateSubMenu(menu, "Backend", MENU_OPTIONS, SUBMENU_RENDERING_BACKEND);
TranslateMenuItem(menu, ID_OPTIONS_BACKEND_MENU);
TranslateMenuItem(menu, ID_OPTIONS_DIRECT3D11);
TranslateMenuItem(menu, ID_OPTIONS_DIRECT3D9);
TranslateMenuItem(menu, ID_OPTIONS_OPENGL);
TranslateMenuItem(menu, ID_OPTIONS_VULKAN);

TranslateSubMenu(menu, "Rendering Mode", MENU_OPTIONS, SUBMENU_RENDERING_MODE);
TranslateMenuItem(menu, ID_OPTIONS_RENDERMODE_MENU);
TranslateMenuItem(menu, ID_OPTIONS_NONBUFFEREDRENDERING);
TranslateMenuItem(menu, ID_OPTIONS_BUFFEREDRENDERING);
TranslateSubMenu(menu, "Frame Skipping", MENU_OPTIONS, SUBMENU_FRAME_SKIPPING, L"\tF7");
TranslateMenuItem(menu, ID_OPTIONS_FRAMESKIP_MENU, L"\tF7");
TranslateMenuItem(menu, ID_OPTIONS_FRAMESKIP_AUTO);
TranslateMenuItem(menu, ID_OPTIONS_FRAMESKIP_0);
TranslateMenuItem(menu, ID_OPTIONS_FRAMESKIPTYPE_MENU);
TranslateMenuItem(menu, ID_OPTIONS_FRAMESKIPTYPE_COUNT);
TranslateMenuItem(menu, ID_OPTIONS_FRAMESKIPTYPE_PRCNT);
// Skip frameskipping 1-8..
TranslateSubMenu(menu, "Texture Filtering", MENU_OPTIONS, SUBMENU_TEXTURE_FILTERING);
TranslateMenuItem(menu, ID_OPTIONS_TEXTUREFILTERING_MENU);
TranslateMenuItem(menu, ID_OPTIONS_TEXTUREFILTERING_AUTO);
TranslateMenuItem(menu, ID_OPTIONS_NEARESTFILTERING);
TranslateMenuItem(menu, ID_OPTIONS_LINEARFILTERING);
TranslateMenuItem(menu, ID_OPTIONS_LINEARFILTERING_CG);
TranslateSubMenu(menu, "Screen Scaling Filter", MENU_OPTIONS, SUBMENU_BUFFER_FILTER);
TranslateMenuItem(menu, ID_OPTIONS_SCREENFILTER_MENU);
TranslateMenuItem(menu, ID_OPTIONS_BUFLINEARFILTER);
TranslateMenuItem(menu, ID_OPTIONS_BUFNEARESTFILTER);
TranslateSubMenu(menu, "Texture Scaling", MENU_OPTIONS, SUBMENU_TEXTURE_SCALING);
TranslateMenuItem(menu, ID_OPTIONS_TEXTURESCALING_MENU);
TranslateMenuItem(menu, ID_TEXTURESCALING_OFF);
// Skip texture scaling 2x-5x...
TranslateMenuItem(menu, ID_TEXTURESCALING_XBRZ);
Expand Down
Loading

0 comments on commit 93bb96d

Please sign in to comment.