UI: use Mac key symbols in menus on macOS, instead of text like "Cmd"

On Windows "Cmd" is also replaced with "Win".

Differential Revision: https://developer.blender.org/D4689
This commit is contained in:
Harley Acheson 2019-05-01 17:22:32 +02:00 committed by Brecht Van Lommel
parent 0a80be40e3
commit 3747282932
3 changed files with 83 additions and 4 deletions

View File

@ -53,6 +53,9 @@ int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size
void BLF_unload(const char *name) ATTR_NONNULL();
void BLF_unload_id(int fontid);
/* Check if font supports a particular glyph */
bool BLF_has_glyph(int fontid, const char *utf8);
/* Attach a file with metrics information from memory. */
void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size);

View File

@ -41,6 +41,7 @@
#include "DNA_vec_types.h"
#include "BLI_math.h"
#include "BLI_string_utf8.h"
#include "BLI_threads.h"
#include "BLF_api.h"
@ -188,6 +189,16 @@ int BLF_default(void)
return global_font_default;
}
bool BLF_has_glyph(int fontid, const char *utf8)
{
FontBLF *font = blf_get(fontid);
if (font) {
unsigned int unicode = BLI_str_utf8_as_unicode(utf8);
return FT_Get_Char_Index(font->face, unicode) != 0;
}
return false;
}
int BLF_load(const char *name)
{
FontBLF *font;

View File

@ -39,6 +39,8 @@
#include "BLI_utildefines.h"
#include "BLI_math.h"
#include "BLF_api.h"
#include "BKE_context.h"
#include "BKE_idprop.h"
#include "BKE_global.h"
@ -1048,8 +1050,71 @@ static void wm_user_modal_keymap_set_items(wmWindowManager *wm, wmKeyMap *km)
/* ***************** get string from key events **************** */
/* if try_unicode see if fancy glyph is in the font, otherwise return text fallback */
static const char *key_event_icon_or_text(const bool try_unicode,
const int font_id,
const char *icon,
const char *text)
{
return (try_unicode && BLF_has_glyph(font_id, icon)) ? icon : text;
}
const char *WM_key_event_string(const short type, const bool compact)
{
if (compact) {
int font_id = BLF_default();
bool is_macos = false;
bool is_windows = false;
#ifdef __APPLE__
is_macos = true;
#endif
#ifdef WIN32
is_windows = true;
#endif
switch (type) {
case LEFTSHIFTKEY:
case RIGHTSHIFTKEY:
return key_event_icon_or_text(is_macos, font_id, "\xe2\x87\xa7\x00", IFACE_("Shift"));
case LEFTCTRLKEY:
case RIGHTCTRLKEY:
return (is_macos) ? "^" : IFACE_("Ctrl");
case LEFTALTKEY:
case RIGHTALTKEY:
return key_event_icon_or_text(is_macos, font_id, "\xe2\x8c\xa5\x00", IFACE_("Alt"));
case OSKEY: {
if (is_macos) {
return key_event_icon_or_text(true, font_id, "\xe2\x8c\x98\x00", IFACE_("Cmd"));
}
else if (is_windows) {
return key_event_icon_or_text(true, font_id, "\xe2\x8a\x9e\x00", IFACE_("Win"));
}
else {
return IFACE_("OSkey");
}
} break;
case TABKEY:
return key_event_icon_or_text(is_macos, font_id, "\xe2\x86\xb9\x00", IFACE_("Tab"));
case BACKSPACEKEY:
return key_event_icon_or_text(true, font_id, "\xe2\x8c\xab\x00", IFACE_("Bksp"));
case ESCKEY:
return key_event_icon_or_text(false, font_id, "\xe2\x8e\x8b\x00", IFACE_("Esc"));
case RETKEY:
return key_event_icon_or_text(is_macos, font_id, "\xe2\x8f\x8e\x00", IFACE_("Enter"));
case SPACEKEY:
return key_event_icon_or_text(false, font_id, "\xe2\x90\xa3\x00", IFACE_("Space"));
case LEFTARROWKEY:
return key_event_icon_or_text(true, font_id, "\xe2\x86\x90\x00", IFACE_("Left"));
case UPARROWKEY:
return key_event_icon_or_text(true, font_id, "\xe2\x86\x91\x00", IFACE_("Up"));
case RIGHTARROWKEY:
return key_event_icon_or_text(true, font_id, "\xe2\x86\x92\x00", IFACE_("Right"));
case DOWNARROWKEY:
return key_event_icon_or_text(true, font_id, "\xe2\x86\x93\x00", IFACE_("Down"));
}
}
const EnumPropertyItem *it;
const int i = RNA_enum_from_value(rna_enum_event_type_items, (int)type);
@ -1097,22 +1162,22 @@ int WM_keymap_item_raw_to_string(const short shift,
else {
if (shift) {
ADD_SEP;
p += BLI_strcpy_rlen(p, IFACE_("Shift"));
p += BLI_strcpy_rlen(p, WM_key_event_string(LEFTSHIFTKEY, true));
}
if (ctrl) {
ADD_SEP;
p += BLI_strcpy_rlen(p, IFACE_("Ctrl"));
p += BLI_strcpy_rlen(p, WM_key_event_string(LEFTCTRLKEY, true));
}
if (alt) {
ADD_SEP;
p += BLI_strcpy_rlen(p, IFACE_("Alt"));
p += BLI_strcpy_rlen(p, WM_key_event_string(LEFTALTKEY, true));
}
if (oskey) {
ADD_SEP;
p += BLI_strcpy_rlen(p, IFACE_("Cmd"));
p += BLI_strcpy_rlen(p, WM_key_event_string(OSKEY, true));
}
}