Skip to content

Commit

Permalink
xrGame, xrEngine: add mouse key handle
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleivg committed Jul 8, 2018
1 parent ddf9da8 commit d379a0a
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 38 deletions.
19 changes: 11 additions & 8 deletions src/xrEngine/xr_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,24 @@ void CInput::KeyUpdate(SDL_Event* event)
*/
}

bool CInput::get_key_name(SDL_Scancode dik, LPSTR dest_str, int dest_sz)
bool CInput::get_key_name(int dik, LPSTR dest_str, int dest_sz)
{
const char* keyname = SDL_GetKeyName(SDL_GetKeyFromScancode(dik));
if (0 == strlen(keyname))
if (dik < SDL_NUM_SCANCODES)
{
Msg("! cant convert dik_name for dik[%d]", dik);
return false;
const char* keyname = SDL_GetKeyName(SDL_GetKeyFromScancode((SDL_Scancode)dik));
if (0 == strlen(keyname))
{
Msg("! cant convert dik_name for dik[%d]", dik);
return false;
}
strcpy_s(dest_str, dest_sz, keyname);
}
strcpy_s(dest_str, dest_sz, keyname);

return true;
}

#define MOUSE_1 (0xED + 100)
#define MOUSE_8 (0xED + 107)
#define MOUSE_1 (SDL_NUM_SCANCODES + SDL_BUTTON_LEFT)
#define MOUSE_8 (SDL_NUM_SCANCODES + 8)

BOOL CInput::iGetAsyncKeyState(int dik)
{
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/xr_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ENGINE_API CInput
IC bool get_exclusive_mode();
void unacquire();
void acquire(const bool& exclusive);
bool get_key_name(SDL_Scancode dik, LPSTR dest, int dest_sz);
bool get_key_name(int dik, LPSTR dest, int dest_sz);

void feedback(u16 s1, u16 s2, float time);
};
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ void CActor::UpdateCL()
{
if (CurrentGameUI() && NULL == CurrentGameUI()->TopInputReceiver())
{
SDL_Scancode dik = get_action_dik(kUSE, 0);
int dik = get_action_dik(kUSE, 0);
if (dik && pInput->iGetAsyncKeyState(dik))
m_bPickupMode = true;

Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/Level_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void CLevel::IR_OnMouseWheel(int direction)
}
}

static int mouse_button_2_key[] = {MOUSE_1, MOUSE_2, MOUSE_3};
static int mouse_button_2_key[] = {SDL_NUM_SCANCODES, MOUSE_1, MOUSE_2, MOUSE_3};

void CLevel::IR_OnMousePress(int btn) {IR_OnKeyboardPress(mouse_button_2_key[btn]); }
void CLevel::IR_OnMouseRelease(int btn) {IR_OnKeyboardRelease(mouse_button_2_key[btn]); }
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ bool CMainMenu::ReloadUI()
bool CMainMenu::IsActive() { return !!m_Flags.test(flActive); }
bool CMainMenu::CanSkipSceneRendering() { return IsActive() && !m_Flags.test(flGameSaveScreenshot); }
// IInputReceiver
static int mouse_button_2_key[] = {MOUSE_1, MOUSE_2, MOUSE_3};
static int mouse_button_2_key[] = {SDL_NUM_SCANCODES, MOUSE_1, MOUSE_2, MOUSE_3};
void CMainMenu::IR_OnMousePress(int btn)
{
if (!IsActive())
Expand Down
4 changes: 2 additions & 2 deletions src/xrGame/ui/UIXmlInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "UItabButtonMP.h"
#include "UILines.h"

extern SDL_Scancode keyname_to_dik(LPCSTR);
extern int keyname_to_dik(LPCSTR);

#define ARIAL_FONT_NAME "arial"

Expand Down Expand Up @@ -345,7 +345,7 @@ bool CUIXmlInit::InitText(CUIXml& xml_doc, LPCSTR path, int index, CUILines* pLi
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////
extern SDL_Scancode keyname_to_dik(LPCSTR);
extern int keyname_to_dik(LPCSTR);

bool CUIXmlInit::Init3tButton(CUIXml& xml_doc, LPCSTR path, int index, CUI3tButton* pWnd)
{
Expand Down
18 changes: 9 additions & 9 deletions src/xrGame/xr_level_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ _keyboard keyboards[] = {{"kESCAPE", SDL_SCANCODE_ESCAPE}, {"k1", SDL_SCANCODE_1
{"kNEXT", SDL_SCANCODE_AUDIONEXT}, {"kINSERT", SDL_SCANCODE_INSERT}, {"kDELETE", SDL_SCANCODE_DELETE},
{"kLWIN", SDL_SCANCODE_LGUI}, {"kRWIN", SDL_SCANCODE_RGUI}, {"kAPPS", SDL_SCANCODE_APPLICATION},
{"kPAUSE", SDL_SCANCODE_PAUSE},
// {"mouse1", MOUSE_1}, {"mouse2", MOUSE_2}, {"mouse3", MOUSE_3}, {"mouse4", MOUSE_4},
// {"mouse5", MOUSE_5}, {"mouse6", MOUSE_6}, {"mouse7", MOUSE_7}, {"mouse8", MOUSE_8},
{"mouse1", MOUSE_1}, {"mouse2", MOUSE_2}, {"mouse3", MOUSE_3}, {"mouse4", MOUSE_4},
{"mouse5", MOUSE_5}, {"mouse6", MOUSE_6}, {"mouse7", MOUSE_7}, {"mouse8", MOUSE_8},
{NULL, SDL_SCANCODE_UNKNOWN}};

void initialize_bindings()
Expand Down Expand Up @@ -195,7 +195,7 @@ _keyboard* dik_to_ptr(SDL_Scancode _dik, bool bSafe)
return NULL;
}

SDL_Scancode keyname_to_dik(pcstr _name)
int keyname_to_dik(pcstr _name)
{
_keyboard* _kb = keyname_to_ptr(_name);
return _kb->dik;
Expand Down Expand Up @@ -234,7 +234,7 @@ bool is_binded(EGameActions _action_id, SDL_Scancode _dik)
return false;
}

SDL_Scancode get_action_dik(EGameActions _action_id, int idx)
int get_action_dik(EGameActions _action_id, int idx)
{
_binding* pbinding = &g_key_bindings[_action_id];

Expand Down Expand Up @@ -478,7 +478,7 @@ class CCC_BindConsoleCmd : public IConsole_Command
_GetItems(args, 0, cnt - 1, console_command, ' ');
_GetItem(args, cnt - 1, key, ' ');

SDL_Scancode dik = keyname_to_dik(key);
int dik = keyname_to_dik(key);
bindConsoleCmds.bind(dik, console_command);
}

Expand All @@ -491,17 +491,17 @@ class CCC_UnBindConsoleCmd : public IConsole_Command
CCC_UnBindConsoleCmd(LPCSTR N) : IConsole_Command(N) { bEmptyArgsHandled = FALSE; };
virtual void Execute(LPCSTR args)
{
SDL_Scancode _dik = keyname_to_dik(args);
int _dik = keyname_to_dik(args);
bindConsoleCmds.unbind(_dik);
}
};

void ConsoleBindCmds::bind(SDL_Scancode dik, LPCSTR N)
void ConsoleBindCmds::bind(int dik, LPCSTR N)
{
_conCmd& c = m_bindConsoleCmds[dik];
c.cmd = N;
}
void ConsoleBindCmds::unbind(SDL_Scancode dik)
void ConsoleBindCmds::unbind(int dik)
{
xr_map<int, _conCmd>::iterator it = m_bindConsoleCmds.find(dik);
if (it == m_bindConsoleCmds.end())
Expand All @@ -511,7 +511,7 @@ void ConsoleBindCmds::unbind(SDL_Scancode dik)
}

void ConsoleBindCmds::clear() { m_bindConsoleCmds.clear(); }
bool ConsoleBindCmds::execute(SDL_Scancode dik)
bool ConsoleBindCmds::execute(int dik)
{
xr_map<int, _conCmd>::iterator it = m_bindConsoleCmds.find(dik);
if (it == m_bindConsoleCmds.end())
Expand Down
30 changes: 15 additions & 15 deletions src/xrGame/xr_level_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ enum EGameActions
struct _keyboard
{
pcstr key_name;
SDL_Scancode dik;
int dik;
xr_string key_local_name;
};
enum _key_group
Expand All @@ -114,7 +114,7 @@ struct _action
};

pcstr dik_to_keyname(SDL_Scancode _dik);
SDL_Scancode keyname_to_dik(pcstr _name);
int keyname_to_dik(pcstr _name);
_keyboard* keyname_to_ptr(pcstr _name);
_keyboard* dik_to_ptr(SDL_Scancode _dik, bool bSafe);

Expand All @@ -136,7 +136,7 @@ struct _binding
extern _binding g_key_bindings[];

bool is_binded(EGameActions action_id, SDL_Scancode dik);
SDL_Scancode get_action_dik(EGameActions action_id, int idx = -1);
int get_action_dik(EGameActions action_id, int idx = -1);
EGameActions get_binded_action(SDL_Scancode dik);

extern void CCC_RegisterInput();
Expand All @@ -151,9 +151,9 @@ class ConsoleBindCmds
public:
xr_map<int, _conCmd> m_bindConsoleCmds;

void bind(SDL_Scancode dik, LPCSTR N);
void unbind(SDL_Scancode dik);
bool execute(SDL_Scancode dik);
void bind(int dik, LPCSTR N);
void unbind(int dik);
bool execute(int dik);
void clear();
void save(IWriter* F);
};
Expand All @@ -162,13 +162,13 @@ void GetActionAllBinding(LPCSTR action, char* dst_buff, int dst_buff_sz);

extern ConsoleBindCmds bindConsoleCmds;

// 0xED - max vavue in DIK* enum
#define MOUSE_1 (0xED + 100)
#define MOUSE_2 (0xED + 101)
#define MOUSE_3 (0xED + 102)
// SDL_NUM_SCANCODES - max vavue in SDL_SCANCODE_* enum
#define MOUSE_1 (SDL_NUM_SCANCODES + SDL_BUTTON_LEFT)
#define MOUSE_2 (SDL_NUM_SCANCODES + SDL_BUTTON_MIDDLE)
#define MOUSE_3 (SDL_NUM_SCANCODES + SDL_BUTTON_RIGHT)

#define MOUSE_4 (0xED + 103)
#define MOUSE_5 (0xED + 104)
#define MOUSE_6 (0xED + 105)
#define MOUSE_7 (0xED + 106)
#define MOUSE_8 (0xED + 107)
#define MOUSE_4 (SDL_NUM_SCANCODES + SDL_BUTTON_X1)
#define MOUSE_5 (SDL_NUM_SCANCODES + SDL_BUTTON_X2)
#define MOUSE_6 (SDL_NUM_SCANCODES + 6)
#define MOUSE_7 (SDL_NUM_SCANCODES + 7)
#define MOUSE_8 (SDL_NUM_SCANCODES + 8)

0 comments on commit d379a0a

Please sign in to comment.