Add an API function to retrieve interface key bindings for display.

develop
Alexander Gavrilov 2012-10-02 13:49:31 +04:00
parent d9cd427121
commit 7440e80e6c
5 changed files with 56 additions and 1 deletions

@ -821,6 +821,8 @@ std::string Core::getHackPath()
#endif
}
void init_screen_module(Core *);
bool Core::Init()
{
if(started)
@ -866,6 +868,7 @@ bool Core::Init()
// Init global object pointers
df::global::InitGlobals();
init_screen_module(this);
cerr << "Initializing Console.\n";
// init the console.

@ -1146,6 +1146,7 @@ static const LuaWrapper::FunctionReg dfhack_screen_module[] = {
WRAPM(Screen, inGraphicsMode),
WRAPM(Screen, clear),
WRAPM(Screen, invalidate),
WRAPM(Screen, getKeyDisplay),
{ NULL, NULL }
};

@ -128,6 +128,9 @@ namespace DFHack
DFHACK_EXPORT bool show(df::viewscreen *screen, df::viewscreen *before = NULL);
DFHACK_EXPORT void dismiss(df::viewscreen *screen, bool to_first = false);
DFHACK_EXPORT bool isDismissed(df::viewscreen *screen);
/// Retrieve the string representation of the bound key.
DFHACK_EXPORT std::string getKeyDisplay(df::interface_key key);
}
class DFHACK_EXPORT dfhack_viewscreen : public df::viewscreen {

@ -28,6 +28,7 @@ distribution.
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;
#include "modules/Screen.h"
@ -64,6 +65,8 @@ using df::global::enabler;
using Screen::Pen;
using std::string;
/*
* Screen painting API.
*/
@ -303,6 +306,51 @@ bool Screen::isDismissed(df::viewscreen *screen)
return screen->breakdown_level != interface_breakdown_types::NONE;
}
#ifdef _LINUX
// Link to the libgraphics class directly:
class DFHACK_EXPORT enabler_inputst {
public:
std::string GetKeyDisplay(int binding);
};
#else
struct less_sz {
bool operator() (const string &a, const string &b) const {
if (a.size() < b.size()) return true;
if (a.size() > b.size()) return false;
return a < b;
}
};
static std::map<df::interface_key,std::set<string,less_sz> > *keydisplay = NULL;
#endif
void init_screen_module(Core *core)
{
#ifdef _LINUX
core = core;
#else
if (!core->vinfo->getAddress("keydisplay", keydisplay))
keydisplay = NULL;
#endif
}
string Screen::getKeyDisplay(df::interface_key key)
{
#ifdef _LINUX
auto enabler = (enabler_inputst*)df::global::enabler;
if (enabler)
return enabler->GetKeyDisplay(key);
#else
if (keydisplay)
{
auto it = keydisplay->find(key);
if (it != keydisplay->end() && !it->second.empty())
return *it->second.begin();
}
#endif
return "?";
}
/*
* Base DFHack viewscreen.
*/

@ -1 +1 @@
Subproject commit 2f76de54dacd32af567b177adfb9d037fdf62d9b
Subproject commit 4c210ddb5338d3a519d03f768da828c33480e4fe