Started working on RichTextBox (Broken commit)
This commit is contained in:
parent
5f93445506
commit
e507473e3a
7 changed files with 454 additions and 50 deletions
|
|
@ -77,6 +77,17 @@ void InputManager::text_input_silence_everything() {
|
|||
text.newInput.clear();
|
||||
}
|
||||
|
||||
void InputManager::Text::set_rich_text_box_input(const std::shared_ptr<RichTextBox>& nTextBox, const std::shared_ptr<RichTextBox::Cursor>& nCursor) {
|
||||
set_accepting_input();
|
||||
newTextBox = nTextBox;
|
||||
newCursor = nCursor;
|
||||
}
|
||||
|
||||
void InputManager::Text::add_text_to_textbox(const std::string& inputText) {
|
||||
if(textBox)
|
||||
textBox->process_text_input(*cursor, inputText);
|
||||
}
|
||||
|
||||
void InputManager::Text::set_accepting_input() {
|
||||
acceptingInputNew = true;
|
||||
}
|
||||
|
|
@ -206,24 +217,43 @@ void InputManager::backend_key_down_update(const SDL_KeyboardEvent& e) {
|
|||
switch(kPress) {
|
||||
case SDLK_UP:
|
||||
set_key_down(e, KEY_TEXT_UP);
|
||||
if(text.textBox && key(KEY_TEXT_UP).repeat)
|
||||
text.textBox->process_key_input(*text.cursor, RichTextBox::InputKey::UP, ctrl_or_meta_held(), key(KEY_GENERIC_LSHIFT).held);
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
set_key_down(e, KEY_TEXT_DOWN);
|
||||
if(text.textBox && key(KEY_TEXT_DOWN).repeat)
|
||||
text.textBox->process_key_input(*text.cursor, RichTextBox::InputKey::DOWN, ctrl_or_meta_held(), key(KEY_GENERIC_LSHIFT).held);
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
set_key_down(e, KEY_TEXT_LEFT);
|
||||
if(text.textBox && key(KEY_TEXT_LEFT).repeat)
|
||||
text.textBox->process_key_input(*text.cursor, RichTextBox::InputKey::LEFT, ctrl_or_meta_held(), key(KEY_GENERIC_LSHIFT).held);
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
set_key_down(e, KEY_TEXT_RIGHT);
|
||||
if(text.textBox && key(KEY_TEXT_RIGHT).repeat)
|
||||
text.textBox->process_key_input(*text.cursor, RichTextBox::InputKey::RIGHT, ctrl_or_meta_held(), key(KEY_GENERIC_LSHIFT).held);
|
||||
break;
|
||||
case SDLK_BACKSPACE:
|
||||
set_key_down(e, KEY_TEXT_BACKSPACE);
|
||||
if(text.textBox && key(KEY_TEXT_BACKSPACE).repeat)
|
||||
text.textBox->process_key_input(*text.cursor, RichTextBox::InputKey::BACKSPACE, ctrl_or_meta_held(), key(KEY_GENERIC_LSHIFT).held);
|
||||
break;
|
||||
case SDLK_DELETE:
|
||||
set_key_down(e, KEY_TEXT_DELETE);
|
||||
if(text.textBox && key(KEY_TEXT_DELETE).repeat)
|
||||
text.textBox->process_key_input(*text.cursor, RichTextBox::InputKey::DELETE, ctrl_or_meta_held(), key(KEY_GENERIC_LSHIFT).held);
|
||||
break;
|
||||
case SDLK_HOME:
|
||||
set_key_down(e, KEY_TEXT_HOME);
|
||||
if(text.textBox && key(KEY_TEXT_HOME).repeat)
|
||||
text.textBox->process_key_input(*text.cursor, RichTextBox::InputKey::HOME, ctrl_or_meta_held(), key(KEY_GENERIC_LSHIFT).held);
|
||||
break;
|
||||
case SDLK_END:
|
||||
set_key_down(e, KEY_TEXT_END);
|
||||
if(text.textBox && key(KEY_TEXT_END).repeat)
|
||||
text.textBox->process_key_input(*text.cursor, RichTextBox::InputKey::END, ctrl_or_meta_held(), key(KEY_GENERIC_LSHIFT).held);
|
||||
break;
|
||||
case SDLK_LSHIFT:
|
||||
set_key_down(e, KEY_TEXT_SHIFT);
|
||||
|
|
@ -236,26 +266,41 @@ void InputManager::backend_key_down_update(const SDL_KeyboardEvent& e) {
|
|||
set_key_down(e, KEY_TEXT_CTRL);
|
||||
set_key_down(e, KEY_GENERIC_LCTRL);
|
||||
break;
|
||||
case SDLK_LMETA:
|
||||
set_key_down(e, KEY_TEXT_META);
|
||||
set_key_down(e, KEY_GENERIC_LMETA);
|
||||
break;
|
||||
case SDLK_C:
|
||||
// Use either Ctrl or Meta (command for Mac) keys. We do either instead of checking, since checking can get complicated on Emscripten
|
||||
if((kMod & SDL_KMOD_GUI) || (kMod & SDL_KMOD_CTRL))
|
||||
set_key_down(e, KEY_TEXT_COPY);
|
||||
if(text.textBox && key(KEY_TEXT_COPY).repeat)
|
||||
set_clipboard_str(text.textBox->process_copy(*text.cursor));
|
||||
break;
|
||||
case SDLK_X:
|
||||
if((kMod & SDL_KMOD_GUI) || (kMod & SDL_KMOD_CTRL))
|
||||
set_key_down(e, KEY_TEXT_CUT);
|
||||
if(text.textBox && key(KEY_TEXT_CUT).repeat)
|
||||
set_clipboard_str(text.textBox->process_cut(*text.cursor));
|
||||
break;
|
||||
case SDLK_V:
|
||||
if((kMod & SDL_KMOD_GUI) || (kMod & SDL_KMOD_CTRL))
|
||||
set_key_down(e, KEY_TEXT_PASTE);
|
||||
if(text.textBox && key(KEY_TEXT_PASTE).repeat)
|
||||
text.textBox->process_text_input(*text.cursor, get_clipboard_str());
|
||||
break;
|
||||
case SDLK_A:
|
||||
if((kMod & SDL_KMOD_GUI) || (kMod & SDL_KMOD_CTRL))
|
||||
set_key_down(e, KEY_TEXT_SELECTALL);
|
||||
if(text.textBox && key(KEY_TEXT_SELECTALL).repeat)
|
||||
text.textBox->process_key_input(*text.cursor, RichTextBox::InputKey::SELECT_ALL, ctrl_or_meta_held(), key(KEY_GENERIC_LSHIFT).held);
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
case SDLK_RETURN: {
|
||||
set_key_down(e, KEY_TEXT_ENTER);
|
||||
if(text.textBox && key(KEY_TEXT_ENTER).repeat)
|
||||
text.textBox->process_key_input(*text.cursor, RichTextBox::InputKey::ENTER, ctrl_or_meta_held(), key(KEY_GENERIC_LSHIFT).held);
|
||||
break;
|
||||
}
|
||||
case SDLK_ESCAPE:
|
||||
set_key_down(e, KEY_GENERIC_ESCAPE);
|
||||
break;
|
||||
|
|
@ -271,6 +316,10 @@ void InputManager::backend_key_down_update(const SDL_KeyboardEvent& e) {
|
|||
set_key_down(e, f->second);
|
||||
}
|
||||
|
||||
bool InputManager::ctrl_or_meta_held() {
|
||||
return key(KEY_GENERIC_LCTRL).held || key(KEY_GENERIC_LMETA).held;
|
||||
}
|
||||
|
||||
void InputManager::backend_key_up_update(const SDL_KeyboardEvent& e) {
|
||||
auto kPress = e.key;
|
||||
//auto kMod = e.mod;
|
||||
|
|
@ -297,6 +346,9 @@ void InputManager::backend_key_up_update(const SDL_KeyboardEvent& e) {
|
|||
case SDLK_HOME:
|
||||
set_key_up(e, KEY_TEXT_HOME);
|
||||
break;
|
||||
case SDLK_END:
|
||||
set_key_up(e, KEY_TEXT_END);
|
||||
break;
|
||||
case SDLK_LSHIFT:
|
||||
set_key_up(e, KEY_TEXT_SHIFT);
|
||||
set_key_up(e, KEY_GENERIC_LSHIFT);
|
||||
|
|
@ -354,6 +406,11 @@ void InputManager::frame_reset(const Vector2i& windowSize) {
|
|||
mouse.middleClicks = 0;
|
||||
text.acceptingInput = text.acceptingInputNew;
|
||||
text.acceptingInputNew = false;
|
||||
text.cursor = text.newCursor;
|
||||
text.textBox = text.newTextBox;
|
||||
text.newCursor = nullptr;
|
||||
text.newTextBox = nullptr;
|
||||
|
||||
text.newInput.clear();
|
||||
droppedItems.clear();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue