mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-04 14:05:32 +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
|
||||
|
||||
* 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
|
||||
|
||||
|
|
|
@ -153,6 +153,35 @@ RB_METHOD(inputMouseY)
|
|||
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
|
||||
{
|
||||
|
@ -209,6 +238,10 @@ inputBindingInit()
|
|||
|
||||
_rb_define_module_function(module, "mouse_x", inputMouseX);
|
||||
_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)
|
||||
{
|
||||
|
|
|
@ -119,6 +119,7 @@ int discordTryConnect(DiscordStatePrivate *p)
|
|||
|
||||
p->connected = true;
|
||||
|
||||
memset(&p->defaultActivity, 0, sizeof(DiscordActivity));
|
||||
strncpy((char*)&p->defaultActivity.details, p->threadData->config.game.title.c_str(), 128);
|
||||
p->defaultActivity.timestamps.start = time(0);
|
||||
|
||||
|
|
|
@ -87,6 +87,8 @@ enum
|
|||
REQUEST_WINCENTER,
|
||||
REQUEST_MESSAGEBOX,
|
||||
REQUEST_SETCURSORVISIBLE,
|
||||
|
||||
REQUEST_TEXTMODE,
|
||||
|
||||
UPDATE_FPS,
|
||||
UPDATE_SCREEN_RECT,
|
||||
|
@ -163,6 +165,8 @@ void EventThread::process(RGSSThreadData &rtData)
|
|||
SDL_DisplayMode dm = {0};
|
||||
|
||||
SDL_GetWindowSize(win, &winW, &winH);
|
||||
|
||||
textInputBuffer.clear();
|
||||
|
||||
SettingsMenu *sMenu = 0;
|
||||
|
||||
|
@ -252,6 +256,10 @@ void EventThread::process(RGSSThreadData &rtData)
|
|||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_TEXTINPUT :
|
||||
textInputBuffer += event.text.text;
|
||||
break;
|
||||
|
||||
case SDL_QUIT :
|
||||
terminate = true;
|
||||
|
@ -430,6 +438,19 @@ void EventThread::process(RGSSThreadData &rtData)
|
|||
case REQUEST_WINRENAME :
|
||||
rtData.config.windowTitle = (const char*)event.user.data1;
|
||||
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;
|
||||
|
||||
case REQUEST_MESSAGEBOX :
|
||||
|
@ -641,6 +662,14 @@ void EventThread::requestShowCursor(bool mode)
|
|||
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)
|
||||
{
|
||||
msgBoxDone.clear();
|
||||
|
|
|
@ -75,6 +75,8 @@ public:
|
|||
static JoyState joyState;
|
||||
static MouseState mouseState;
|
||||
static TouchState touchState;
|
||||
|
||||
std::string textInputBuffer;
|
||||
|
||||
static bool allocUserEvents();
|
||||
|
||||
|
@ -90,6 +92,8 @@ public:
|
|||
void requestWindowCenter();
|
||||
void requestWindowRename(const char *title);
|
||||
void requestShowCursor(bool mode);
|
||||
|
||||
void requestTextInputMode(bool mode);
|
||||
|
||||
void requestTerminate();
|
||||
|
||||
|
|
|
@ -457,6 +457,8 @@ struct InputPrivate
|
|||
int rawRepeating;
|
||||
unsigned int repeatCount;
|
||||
unsigned int rawRepeatCount;
|
||||
|
||||
bool textInputMode;
|
||||
|
||||
struct
|
||||
{
|
||||
|
@ -496,6 +498,8 @@ struct InputPrivate
|
|||
dir4Data.previous = Input::None;
|
||||
|
||||
dir8Data.active = 0;
|
||||
|
||||
textInputMode = false;
|
||||
}
|
||||
|
||||
inline ButtonState &getStateCheck(int code)
|
||||
|
@ -957,6 +961,26 @@ int Input::mouseY()
|
|||
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()
|
||||
{
|
||||
delete p;
|
||||
|
|
|
@ -65,6 +65,11 @@ public:
|
|||
/* Non-standard extensions */
|
||||
int mouseX();
|
||||
int mouseY();
|
||||
|
||||
bool getTextInputMode();
|
||||
void setTextInputMode(bool mode);
|
||||
const char *getText();
|
||||
void clearText();
|
||||
|
||||
private:
|
||||
Input(const RGSSThreadData &rtData);
|
||||
|
|
Loading…
Add table
Reference in a new issue