mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-10 17:05:33 +02:00
Add text input functionality to Input module
This commit is contained in:
parent
0111175c45
commit
ac28861587
7 changed files with 98 additions and 1 deletions
|
@ -160,7 +160,8 @@ To begin deprecating the use of Win32API and by extension the fake-api build opt
|
||||||
### Input
|
### Input
|
||||||
|
|
||||||
* The `Input.press?` family of functions accepts three additional button constants: `::MOUSELEFT`, `::MOUSEMIDDLE` and `::MOUSERIGHT` for the respective mouse buttons.
|
* The `Input.press?` family of functions accepts three additional button constants: `::MOUSELEFT`, `::MOUSEMIDDLE` and `::MOUSERIGHT` for the respective mouse buttons.
|
||||||
* The `Input` module has five additional functions, `#mouse_x` and `#mouse_y` to query the mouse pointer position relative to the game screen. `#pressex?`, `#triggerex?` and `#repeatex?` provide input states for raw key codes, which are provided in the form of [Microsoft Virtual-Key Codes](https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes). Only buttons which are also [tracked by SDL](https://wiki.libsdl.org/SDL_Scancode) are supported.
|
* The `Input` module has one additional property: `text_input` determines whether to accept text editing events.
|
||||||
|
* The `Input` module has six additional functions, `#mouse_x` and `#mouse_y` to query the mouse pointer position relative to the game screen. `#pressex?`, `#triggerex?` and `#repeatex?` provide input states for raw key codes, which are provided in the form of [Microsoft Virtual-Key Codes](https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes). Only buttons which are also [tracked by SDL](https://wiki.libsdl.org/SDL_Scancode) are supported. `#gets` returns a UTF-8 string of any text that was input by the user since the last time `#gets` was called. The `text_input` property must be set to true for it to work.
|
||||||
|
|
||||||
### Graphics
|
### Graphics
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,35 @@ RB_METHOD(inputMouseY)
|
||||||
return rb_fix_new(shState->input().mouseY());
|
return rb_fix_new(shState->input().mouseY());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RB_METHOD(inputGetMode)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
return rb_bool_new(shState->input().getTextInputMode());
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(inputSetMode)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
bool mode;
|
||||||
|
rb_get_args(argc, argv, "b", &mode RB_ARG_END);
|
||||||
|
|
||||||
|
shState->input().setTextInputMode(mode);
|
||||||
|
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(inputGets)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
VALUE ret = rb_str_new_cstr(shState->input().getText());
|
||||||
|
shState->input().clearText();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -210,6 +239,10 @@ inputBindingInit()
|
||||||
_rb_define_module_function(module, "mouse_x", inputMouseX);
|
_rb_define_module_function(module, "mouse_x", inputMouseX);
|
||||||
_rb_define_module_function(module, "mouse_y", inputMouseY);
|
_rb_define_module_function(module, "mouse_y", inputMouseY);
|
||||||
|
|
||||||
|
_rb_define_module_function(module, "text_input", inputGetMode);
|
||||||
|
_rb_define_module_function(module, "text_input=", inputSetMode);
|
||||||
|
_rb_define_module_function(module, "gets", inputGets);
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
if (rgssVer >= 3)
|
||||||
{
|
{
|
||||||
VALUE symHash = rb_hash_new();
|
VALUE symHash = rb_hash_new();
|
||||||
|
|
|
@ -119,6 +119,7 @@ int discordTryConnect(DiscordStatePrivate *p)
|
||||||
|
|
||||||
p->connected = true;
|
p->connected = true;
|
||||||
|
|
||||||
|
memset(&p->defaultActivity, 0, sizeof(DiscordActivity));
|
||||||
strncpy((char*)&p->defaultActivity.details, p->threadData->config.game.title.c_str(), 128);
|
strncpy((char*)&p->defaultActivity.details, p->threadData->config.game.title.c_str(), 128);
|
||||||
p->defaultActivity.timestamps.start = time(0);
|
p->defaultActivity.timestamps.start = time(0);
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,8 @@ enum
|
||||||
REQUEST_MESSAGEBOX,
|
REQUEST_MESSAGEBOX,
|
||||||
REQUEST_SETCURSORVISIBLE,
|
REQUEST_SETCURSORVISIBLE,
|
||||||
|
|
||||||
|
REQUEST_TEXTMODE,
|
||||||
|
|
||||||
UPDATE_FPS,
|
UPDATE_FPS,
|
||||||
UPDATE_SCREEN_RECT,
|
UPDATE_SCREEN_RECT,
|
||||||
|
|
||||||
|
@ -164,6 +166,8 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
|
|
||||||
SDL_GetWindowSize(win, &winW, &winH);
|
SDL_GetWindowSize(win, &winW, &winH);
|
||||||
|
|
||||||
|
textInputBuffer.clear();
|
||||||
|
|
||||||
SettingsMenu *sMenu = 0;
|
SettingsMenu *sMenu = 0;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
@ -253,6 +257,10 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDL_TEXTINPUT :
|
||||||
|
textInputBuffer += event.text.text;
|
||||||
|
break;
|
||||||
|
|
||||||
case SDL_QUIT :
|
case SDL_QUIT :
|
||||||
terminate = true;
|
terminate = true;
|
||||||
Debug() << "EventThread termination requested";
|
Debug() << "EventThread termination requested";
|
||||||
|
@ -430,6 +438,19 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
case REQUEST_WINRENAME :
|
case REQUEST_WINRENAME :
|
||||||
rtData.config.windowTitle = (const char*)event.user.data1;
|
rtData.config.windowTitle = (const char*)event.user.data1;
|
||||||
SDL_SetWindowTitle(win, rtData.config.windowTitle.c_str());
|
SDL_SetWindowTitle(win, rtData.config.windowTitle.c_str());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case REQUEST_TEXTMODE :
|
||||||
|
if (event.user.code)
|
||||||
|
{
|
||||||
|
SDL_StartTextInput();
|
||||||
|
textInputBuffer.clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SDL_StopTextInput();
|
||||||
|
textInputBuffer.clear();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REQUEST_MESSAGEBOX :
|
case REQUEST_MESSAGEBOX :
|
||||||
|
@ -641,6 +662,14 @@ void EventThread::requestShowCursor(bool mode)
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EventThread::requestTextInputMode(bool mode)
|
||||||
|
{
|
||||||
|
SDL_Event event;
|
||||||
|
event.type = usrIdStart + REQUEST_TEXTMODE;
|
||||||
|
event.user.code = mode;
|
||||||
|
SDL_PushEvent(&event);
|
||||||
|
}
|
||||||
|
|
||||||
void EventThread::showMessageBox(const char *body, int flags)
|
void EventThread::showMessageBox(const char *body, int flags)
|
||||||
{
|
{
|
||||||
msgBoxDone.clear();
|
msgBoxDone.clear();
|
||||||
|
|
|
@ -76,6 +76,8 @@ public:
|
||||||
static MouseState mouseState;
|
static MouseState mouseState;
|
||||||
static TouchState touchState;
|
static TouchState touchState;
|
||||||
|
|
||||||
|
std::string textInputBuffer;
|
||||||
|
|
||||||
static bool allocUserEvents();
|
static bool allocUserEvents();
|
||||||
|
|
||||||
EventThread();
|
EventThread();
|
||||||
|
@ -91,6 +93,8 @@ public:
|
||||||
void requestWindowRename(const char *title);
|
void requestWindowRename(const char *title);
|
||||||
void requestShowCursor(bool mode);
|
void requestShowCursor(bool mode);
|
||||||
|
|
||||||
|
void requestTextInputMode(bool mode);
|
||||||
|
|
||||||
void requestTerminate();
|
void requestTerminate();
|
||||||
|
|
||||||
bool getFullscreen() const;
|
bool getFullscreen() const;
|
||||||
|
|
|
@ -458,6 +458,8 @@ struct InputPrivate
|
||||||
unsigned int repeatCount;
|
unsigned int repeatCount;
|
||||||
unsigned int rawRepeatCount;
|
unsigned int rawRepeatCount;
|
||||||
|
|
||||||
|
bool textInputMode;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
int active;
|
int active;
|
||||||
|
@ -496,6 +498,8 @@ struct InputPrivate
|
||||||
dir4Data.previous = Input::None;
|
dir4Data.previous = Input::None;
|
||||||
|
|
||||||
dir8Data.active = 0;
|
dir8Data.active = 0;
|
||||||
|
|
||||||
|
textInputMode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ButtonState &getStateCheck(int code)
|
inline ButtonState &getStateCheck(int code)
|
||||||
|
@ -957,6 +961,26 @@ int Input::mouseY()
|
||||||
return (EventThread::mouseState.y - rtData.screenOffset.y) * rtData.sizeResoRatio.y;
|
return (EventThread::mouseState.y - rtData.screenOffset.y) * rtData.sizeResoRatio.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Input::getTextInputMode()
|
||||||
|
{
|
||||||
|
return p->textInputMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Input::setTextInputMode(bool mode)
|
||||||
|
{
|
||||||
|
shState->eThread().requestTextInputMode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *Input::getText()
|
||||||
|
{
|
||||||
|
return shState->eThread().textInputBuffer.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Input::clearText()
|
||||||
|
{
|
||||||
|
shState->eThread().textInputBuffer.clear();
|
||||||
|
}
|
||||||
|
|
||||||
Input::~Input()
|
Input::~Input()
|
||||||
{
|
{
|
||||||
delete p;
|
delete p;
|
||||||
|
|
|
@ -66,6 +66,11 @@ public:
|
||||||
int mouseX();
|
int mouseX();
|
||||||
int mouseY();
|
int mouseY();
|
||||||
|
|
||||||
|
bool getTextInputMode();
|
||||||
|
void setTextInputMode(bool mode);
|
||||||
|
const char *getText();
|
||||||
|
void clearText();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Input(const RGSSThreadData &rtData);
|
Input(const RGSSThreadData &rtData);
|
||||||
~Input();
|
~Input();
|
||||||
|
|
Loading…
Add table
Reference in a new issue