Skip to content

Commit

Permalink
annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
y5nw committed Jan 7, 2025
1 parent e13e1bc commit 9590be1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions irr/include/IrrlichtDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,22 @@ class IrrlichtDevice : public virtual IReferenceCounted
}

//! Get the scancode of the corresponding keycode.
/**
\param key The keycode to convert.
\return The implementation-dependent scancode for the key (represented by the u32 component) or, if a scancode is not
available, the corresponding Irrlicht keycode (represented by the EKEY_CODE component).
*/
virtual std::variant<u32, EKEY_CODE> getScancodeFromKey(const Keycode &key) const {
if (auto pv = std::get_if<EKEY_CODE>(&key))
return *pv;
return (u32)std::get<wchar_t>(key);
}

//! Get the keycode of the corresponding scancode.
/**
\param scancode The implementation-dependent scancode for the key.
\return The corresponding keycode.
*/
virtual Keycode getKeyFromScancode(const u32 scancode) const {
return Keycode(KEY_UNKNOWN, (wchar_t)scancode);
}
Expand Down
1 change: 1 addition & 0 deletions irr/include/Keycodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ enum EKEY_CODE
KEY_KEY_CODES_COUNT = 0x100 // this is not a key, but the amount of keycodes there are.
};

// A Keycode is either a character produced by the key or one of Irrlicht's codes (EKEY_CODE)
class Keycode : public std::variant<EKEY_CODE, wchar_t> {
using super = std::variant<EKEY_CODE, wchar_t>;
public:
Expand Down
3 changes: 2 additions & 1 deletion src/client/keycode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct table_key {
std::string Name;
irr::EKEY_CODE Key;
wchar_t Char; // L'\0' means no character assigned
std::string LangName; // NULL means it doesn't have a human description
std::string LangName; // empty string means it doesn't have a human description
};

#define DEFINEKEY1(x, lang) /* Irrlicht key without character */ \
Expand Down Expand Up @@ -238,6 +238,7 @@ static const table_key &lookup_keychar(wchar_t Char)
return table_key;
}

// Create a new entry in the lookup table if one is not available.
auto newsym = wide_to_utf8(std::wstring_view(&Char, 1));
table_key new_key {newsym, irr::KEY_KEY_CODES_COUNT, Char, newsym};
return table.emplace_back(std::move(new_key));
Expand Down

0 comments on commit 9590be1

Please sign in to comment.