Skip to content

Commit d379a0a

Browse files
committed
xrGame, xrEngine: add mouse key handle
1 parent ddf9da8 commit d379a0a

File tree

8 files changed

+41
-38
lines changed

8 files changed

+41
-38
lines changed

src/xrEngine/xr_input.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,21 +164,24 @@ void CInput::KeyUpdate(SDL_Event* event)
164164
*/
165165
}
166166

167-
bool CInput::get_key_name(SDL_Scancode dik, LPSTR dest_str, int dest_sz)
167+
bool CInput::get_key_name(int dik, LPSTR dest_str, int dest_sz)
168168
{
169-
const char* keyname = SDL_GetKeyName(SDL_GetKeyFromScancode(dik));
170-
if (0 == strlen(keyname))
169+
if (dik < SDL_NUM_SCANCODES)
171170
{
172-
Msg("! cant convert dik_name for dik[%d]", dik);
173-
return false;
171+
const char* keyname = SDL_GetKeyName(SDL_GetKeyFromScancode((SDL_Scancode)dik));
172+
if (0 == strlen(keyname))
173+
{
174+
Msg("! cant convert dik_name for dik[%d]", dik);
175+
return false;
176+
}
177+
strcpy_s(dest_str, dest_sz, keyname);
174178
}
175-
strcpy_s(dest_str, dest_sz, keyname);
176179

177180
return true;
178181
}
179182

180-
#define MOUSE_1 (0xED + 100)
181-
#define MOUSE_8 (0xED + 107)
183+
#define MOUSE_1 (SDL_NUM_SCANCODES + SDL_BUTTON_LEFT)
184+
#define MOUSE_8 (SDL_NUM_SCANCODES + 8)
182185

183186
BOOL CInput::iGetAsyncKeyState(int dik)
184187
{

src/xrEngine/xr_input.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ENGINE_API CInput
8484
IC bool get_exclusive_mode();
8585
void unacquire();
8686
void acquire(const bool& exclusive);
87-
bool get_key_name(SDL_Scancode dik, LPSTR dest, int dest_sz);
87+
bool get_key_name(int dik, LPSTR dest, int dest_sz);
8888

8989
void feedback(u16 s1, u16 s2, float time);
9090
};

src/xrGame/Actor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ void CActor::UpdateCL()
943943
{
944944
if (CurrentGameUI() && NULL == CurrentGameUI()->TopInputReceiver())
945945
{
946-
SDL_Scancode dik = get_action_dik(kUSE, 0);
946+
int dik = get_action_dik(kUSE, 0);
947947
if (dik && pInput->iGetAsyncKeyState(dik))
948948
m_bPickupMode = true;
949949

src/xrGame/Level_input.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void CLevel::IR_OnMouseWheel(int direction)
7272
}
7373
}
7474

75-
static int mouse_button_2_key[] = {MOUSE_1, MOUSE_2, MOUSE_3};
75+
static int mouse_button_2_key[] = {SDL_NUM_SCANCODES, MOUSE_1, MOUSE_2, MOUSE_3};
7676

7777
void CLevel::IR_OnMousePress(int btn) {IR_OnKeyboardPress(mouse_button_2_key[btn]); }
7878
void CLevel::IR_OnMouseRelease(int btn) {IR_OnKeyboardRelease(mouse_button_2_key[btn]); }

src/xrGame/MainMenu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ bool CMainMenu::ReloadUI()
302302
bool CMainMenu::IsActive() { return !!m_Flags.test(flActive); }
303303
bool CMainMenu::CanSkipSceneRendering() { return IsActive() && !m_Flags.test(flGameSaveScreenshot); }
304304
// IInputReceiver
305-
static int mouse_button_2_key[] = {MOUSE_1, MOUSE_2, MOUSE_3};
305+
static int mouse_button_2_key[] = {SDL_NUM_SCANCODES, MOUSE_1, MOUSE_2, MOUSE_3};
306306
void CMainMenu::IR_OnMousePress(int btn)
307307
{
308308
if (!IsActive())

src/xrGame/ui/UIXmlInit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "UItabButtonMP.h"
2525
#include "UILines.h"
2626

27-
extern SDL_Scancode keyname_to_dik(LPCSTR);
27+
extern int keyname_to_dik(LPCSTR);
2828

2929
#define ARIAL_FONT_NAME "arial"
3030

@@ -345,7 +345,7 @@ bool CUIXmlInit::InitText(CUIXml& xml_doc, LPCSTR path, int index, CUILines* pLi
345345
return true;
346346
}
347347
////////////////////////////////////////////////////////////////////////////////////////////
348-
extern SDL_Scancode keyname_to_dik(LPCSTR);
348+
extern int keyname_to_dik(LPCSTR);
349349

350350
bool CUIXmlInit::Init3tButton(CUIXml& xml_doc, LPCSTR path, int index, CUI3tButton* pWnd)
351351
{

src/xrGame/xr_level_controller.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ _keyboard keyboards[] = {{"kESCAPE", SDL_SCANCODE_ESCAPE}, {"k1", SDL_SCANCODE_1
8484
{"kNEXT", SDL_SCANCODE_AUDIONEXT}, {"kINSERT", SDL_SCANCODE_INSERT}, {"kDELETE", SDL_SCANCODE_DELETE},
8585
{"kLWIN", SDL_SCANCODE_LGUI}, {"kRWIN", SDL_SCANCODE_RGUI}, {"kAPPS", SDL_SCANCODE_APPLICATION},
8686
{"kPAUSE", SDL_SCANCODE_PAUSE},
87-
// {"mouse1", MOUSE_1}, {"mouse2", MOUSE_2}, {"mouse3", MOUSE_3}, {"mouse4", MOUSE_4},
88-
// {"mouse5", MOUSE_5}, {"mouse6", MOUSE_6}, {"mouse7", MOUSE_7}, {"mouse8", MOUSE_8},
87+
{"mouse1", MOUSE_1}, {"mouse2", MOUSE_2}, {"mouse3", MOUSE_3}, {"mouse4", MOUSE_4},
88+
{"mouse5", MOUSE_5}, {"mouse6", MOUSE_6}, {"mouse7", MOUSE_7}, {"mouse8", MOUSE_8},
8989
{NULL, SDL_SCANCODE_UNKNOWN}};
9090

9191
void initialize_bindings()
@@ -195,7 +195,7 @@ _keyboard* dik_to_ptr(SDL_Scancode _dik, bool bSafe)
195195
return NULL;
196196
}
197197

198-
SDL_Scancode keyname_to_dik(pcstr _name)
198+
int keyname_to_dik(pcstr _name)
199199
{
200200
_keyboard* _kb = keyname_to_ptr(_name);
201201
return _kb->dik;
@@ -234,7 +234,7 @@ bool is_binded(EGameActions _action_id, SDL_Scancode _dik)
234234
return false;
235235
}
236236

237-
SDL_Scancode get_action_dik(EGameActions _action_id, int idx)
237+
int get_action_dik(EGameActions _action_id, int idx)
238238
{
239239
_binding* pbinding = &g_key_bindings[_action_id];
240240

@@ -478,7 +478,7 @@ class CCC_BindConsoleCmd : public IConsole_Command
478478
_GetItems(args, 0, cnt - 1, console_command, ' ');
479479
_GetItem(args, cnt - 1, key, ' ');
480480

481-
SDL_Scancode dik = keyname_to_dik(key);
481+
int dik = keyname_to_dik(key);
482482
bindConsoleCmds.bind(dik, console_command);
483483
}
484484

@@ -491,17 +491,17 @@ class CCC_UnBindConsoleCmd : public IConsole_Command
491491
CCC_UnBindConsoleCmd(LPCSTR N) : IConsole_Command(N) { bEmptyArgsHandled = FALSE; };
492492
virtual void Execute(LPCSTR args)
493493
{
494-
SDL_Scancode _dik = keyname_to_dik(args);
494+
int _dik = keyname_to_dik(args);
495495
bindConsoleCmds.unbind(_dik);
496496
}
497497
};
498498

499-
void ConsoleBindCmds::bind(SDL_Scancode dik, LPCSTR N)
499+
void ConsoleBindCmds::bind(int dik, LPCSTR N)
500500
{
501501
_conCmd& c = m_bindConsoleCmds[dik];
502502
c.cmd = N;
503503
}
504-
void ConsoleBindCmds::unbind(SDL_Scancode dik)
504+
void ConsoleBindCmds::unbind(int dik)
505505
{
506506
xr_map<int, _conCmd>::iterator it = m_bindConsoleCmds.find(dik);
507507
if (it == m_bindConsoleCmds.end())
@@ -511,7 +511,7 @@ void ConsoleBindCmds::unbind(SDL_Scancode dik)
511511
}
512512

513513
void ConsoleBindCmds::clear() { m_bindConsoleCmds.clear(); }
514-
bool ConsoleBindCmds::execute(SDL_Scancode dik)
514+
bool ConsoleBindCmds::execute(int dik)
515515
{
516516
xr_map<int, _conCmd>::iterator it = m_bindConsoleCmds.find(dik);
517517
if (it == m_bindConsoleCmds.end())

src/xrGame/xr_level_controller.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ enum EGameActions
9292
struct _keyboard
9393
{
9494
pcstr key_name;
95-
SDL_Scancode dik;
95+
int dik;
9696
xr_string key_local_name;
9797
};
9898
enum _key_group
@@ -114,7 +114,7 @@ struct _action
114114
};
115115

116116
pcstr dik_to_keyname(SDL_Scancode _dik);
117-
SDL_Scancode keyname_to_dik(pcstr _name);
117+
int keyname_to_dik(pcstr _name);
118118
_keyboard* keyname_to_ptr(pcstr _name);
119119
_keyboard* dik_to_ptr(SDL_Scancode _dik, bool bSafe);
120120

@@ -136,7 +136,7 @@ struct _binding
136136
extern _binding g_key_bindings[];
137137

138138
bool is_binded(EGameActions action_id, SDL_Scancode dik);
139-
SDL_Scancode get_action_dik(EGameActions action_id, int idx = -1);
139+
int get_action_dik(EGameActions action_id, int idx = -1);
140140
EGameActions get_binded_action(SDL_Scancode dik);
141141

142142
extern void CCC_RegisterInput();
@@ -151,9 +151,9 @@ class ConsoleBindCmds
151151
public:
152152
xr_map<int, _conCmd> m_bindConsoleCmds;
153153

154-
void bind(SDL_Scancode dik, LPCSTR N);
155-
void unbind(SDL_Scancode dik);
156-
bool execute(SDL_Scancode dik);
154+
void bind(int dik, LPCSTR N);
155+
void unbind(int dik);
156+
bool execute(int dik);
157157
void clear();
158158
void save(IWriter* F);
159159
};
@@ -162,13 +162,13 @@ void GetActionAllBinding(LPCSTR action, char* dst_buff, int dst_buff_sz);
162162

163163
extern ConsoleBindCmds bindConsoleCmds;
164164

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

170-
#define MOUSE_4 (0xED + 103)
171-
#define MOUSE_5 (0xED + 104)
172-
#define MOUSE_6 (0xED + 105)
173-
#define MOUSE_7 (0xED + 106)
174-
#define MOUSE_8 (0xED + 107)
170+
#define MOUSE_4 (SDL_NUM_SCANCODES + SDL_BUTTON_X1)
171+
#define MOUSE_5 (SDL_NUM_SCANCODES + SDL_BUTTON_X2)
172+
#define MOUSE_6 (SDL_NUM_SCANCODES + 6)
173+
#define MOUSE_7 (SDL_NUM_SCANCODES + 7)
174+
#define MOUSE_8 (SDL_NUM_SCANCODES + 8)

0 commit comments

Comments
 (0)