Send textbox rectangle and textbox type to SDL
This commit is contained in:
parent
d38156ec26
commit
f3671e667d
8 changed files with 179 additions and 32 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <Eigen/Geometry>
|
#include <Eigen/Geometry>
|
||||||
|
#include <SDL3/SDL_rect.h>
|
||||||
|
|
||||||
using namespace Eigen;
|
using namespace Eigen;
|
||||||
|
|
||||||
|
|
@ -76,6 +77,9 @@ namespace SCollision {
|
||||||
template <class Archive> void serialize(Archive& a) {
|
template <class Archive> void serialize(Archive& a) {
|
||||||
a(min, max);
|
a(min, max);
|
||||||
}
|
}
|
||||||
|
SDL_Rect get_sdl_rect() const {
|
||||||
|
return SDL_Rect{static_cast<int>(min.x()), static_cast<int>(min.y()), static_cast<int>(width()), static_cast<int>(height())};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
template <typename T> class Circle {
|
template <typename T> class Circle {
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
#include <Helpers/Serializers.hpp>
|
#include <Helpers/Serializers.hpp>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include "../../RichText/TextBox.hpp"
|
#include "../../RichText/TextBox.hpp"
|
||||||
|
#include "../../InputManager.hpp"
|
||||||
|
|
||||||
using namespace Eigen;
|
using namespace Eigen;
|
||||||
|
|
||||||
|
|
@ -97,6 +98,8 @@ struct UpdateInputData {
|
||||||
std::shared_ptr<RichText::TextBox> previousRichTextBoxToEdit;
|
std::shared_ptr<RichText::TextBox> previousRichTextBoxToEdit;
|
||||||
std::shared_ptr<RichText::TextBox> richTextBoxToEdit;
|
std::shared_ptr<RichText::TextBox> richTextBoxToEdit;
|
||||||
std::shared_ptr<RichText::TextBox::Cursor> richTextBoxToEditCursor;
|
std::shared_ptr<RichText::TextBox::Cursor> richTextBoxToEditCursor;
|
||||||
|
InputManager::TextInputProperties richTextInputProperties;
|
||||||
|
std::shared_ptr<SCollision::AABB<float>> richTextBoxToEditRectangle;
|
||||||
|
|
||||||
SkFont get_font(float fSize) const;
|
SkFont get_font(float fSize) const;
|
||||||
|
|
||||||
|
|
@ -110,6 +113,9 @@ struct UpdateInputData {
|
||||||
float deltaTime = 0.0f;
|
float deltaTime = 0.0f;
|
||||||
bool isTouch = true;
|
bool isTouch = true;
|
||||||
|
|
||||||
|
float guiScaleMultiplier = 1.0f;
|
||||||
|
Vector2f windowPos = {0.0f, 0.0f};
|
||||||
|
|
||||||
std::shared_ptr<FontData> fonts;
|
std::shared_ptr<FontData> fonts;
|
||||||
sk_sp<SkTypeface> textTypeface;
|
sk_sp<SkTypeface> textTypeface;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,13 @@
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <modules/skparagraph/include/TextStyle.h>
|
#include <modules/skparagraph/include/TextStyle.h>
|
||||||
#include "../../FontData.hpp"
|
#include "../../FontData.hpp"
|
||||||
|
#include "../../InputManager.hpp"
|
||||||
|
|
||||||
namespace GUIStuff {
|
namespace GUIStuff {
|
||||||
|
|
||||||
template <typename T> class TextBox : public Element {
|
template <typename T> class TextBox : public Element {
|
||||||
public:
|
public:
|
||||||
bool update(UpdateInputData& io, T* newData, const std::function<std::optional<T>(const std::string&)>& newFromStr, const std::function<std::string(const T&)> newToStr, bool newSingleLine, bool updateEveryEdit, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
bool update(UpdateInputData& io, T* newData, const std::function<std::optional<T>(const std::string&)>& newFromStr, const std::function<std::string(const T&)> newToStr, bool newSingleLine, bool updateEveryEdit, const InputManager::TextInputProperties& textInputProps, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
||||||
bool isUpdating = false;
|
bool isUpdating = false;
|
||||||
|
|
||||||
if(!textbox || !cur)
|
if(!textbox || !cur)
|
||||||
|
|
@ -33,6 +34,8 @@ template <typename T> class TextBox : public Element {
|
||||||
if(data && selection.selected) {
|
if(data && selection.selected) {
|
||||||
io.richTextBoxToEdit = textbox;
|
io.richTextBoxToEdit = textbox;
|
||||||
io.richTextBoxToEditCursor = cur;
|
io.richTextBoxToEditCursor = cur;
|
||||||
|
io.richTextBoxToEditRectangle = rect;
|
||||||
|
io.richTextInputProperties = textInputProps;
|
||||||
textbox->process_mouse_left_button(*cur, io.mouse.pos - bb.min, io.mouse.leftClick, io.mouse.leftHeld, io.key.leftShift);
|
textbox->process_mouse_left_button(*cur, io.mouse.pos - bb.min, io.mouse.leftClick, io.mouse.leftHeld, io.key.leftShift);
|
||||||
if((updateEveryEdit && textbox->inputChangedTextBox) || io.key.enter) {
|
if((updateEveryEdit && textbox->inputChangedTextBox) || io.key.enter) {
|
||||||
update_on_edit();
|
update_on_edit();
|
||||||
|
|
@ -53,6 +56,8 @@ template <typename T> class TextBox : public Element {
|
||||||
if(textbox)
|
if(textbox)
|
||||||
textbox->inputChangedTextBox = false;
|
textbox->inputChangedTextBox = false;
|
||||||
|
|
||||||
|
*rect = {(bb.min + io.windowPos) * io.guiScaleMultiplier, (bb.max + io.windowPos) * io.guiScaleMultiplier};
|
||||||
|
|
||||||
return isUpdating;
|
return isUpdating;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,6 +113,7 @@ template <typename T> class TextBox : public Element {
|
||||||
textbox->set_allow_newlines(false);
|
textbox->set_allow_newlines(false);
|
||||||
|
|
||||||
cur = std::make_shared<RichText::TextBox::Cursor>();
|
cur = std::make_shared<RichText::TextBox::Cursor>();
|
||||||
|
rect = std::make_shared<SCollision::AABB<float>>();
|
||||||
|
|
||||||
if(data) {
|
if(data) {
|
||||||
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, toStr(*data));
|
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, toStr(*data));
|
||||||
|
|
@ -131,8 +137,9 @@ template <typename T> class TextBox : public Element {
|
||||||
|
|
||||||
std::shared_ptr<RichText::TextBox> textbox;
|
std::shared_ptr<RichText::TextBox> textbox;
|
||||||
std::shared_ptr<RichText::TextBox::Cursor> cur;
|
std::shared_ptr<RichText::TextBox::Cursor> cur;
|
||||||
|
std::shared_ptr<SCollision::AABB<float>> rect;
|
||||||
|
|
||||||
SCollision::AABB<float> bb;
|
SCollision::AABB<float> bb = {{1.0f, 1.0f}, {2.0f, 2.0f}};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -393,7 +393,15 @@ bool GUIManager::input_color_component_255(const char* id, float* val, const std
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << convertTo255;
|
ss << convertTo255;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}, true, false, elemUpdate);
|
}, true, false,
|
||||||
|
{
|
||||||
|
.inputType = SDL_TextInputType::SDL_TEXTINPUT_TYPE_NUMBER,
|
||||||
|
.capitalization = SDL_Capitalization::SDL_CAPITALIZE_NONE,
|
||||||
|
.autocorrect = false,
|
||||||
|
.multiline = false,
|
||||||
|
.androidInputType = InputManager::AndroidInputType::ANDROIDTEXT_TYPE_CLASS_NUMBER
|
||||||
|
},
|
||||||
|
elemUpdate);
|
||||||
pop_id();
|
pop_id();
|
||||||
return isUpdating;
|
return isUpdating;
|
||||||
}
|
}
|
||||||
|
|
@ -406,7 +414,15 @@ bool GUIManager::input_text(const char* id, std::string* val, bool updateEveryEd
|
||||||
},
|
},
|
||||||
[&](const std::string& str) {
|
[&](const std::string& str) {
|
||||||
return str;
|
return str;
|
||||||
}, true, updateEveryEdit, elemUpdate);
|
}, true, updateEveryEdit,
|
||||||
|
{
|
||||||
|
.inputType = SDL_TextInputType::SDL_TEXTINPUT_TYPE_TEXT,
|
||||||
|
.capitalization = SDL_Capitalization::SDL_CAPITALIZE_NONE,
|
||||||
|
.autocorrect = false,
|
||||||
|
.multiline = false,
|
||||||
|
.androidInputType = InputManager::AndroidInputType::ANDROIDTEXT_TYPE_CLASS_TEXT
|
||||||
|
},
|
||||||
|
elemUpdate);
|
||||||
pop_id();
|
pop_id();
|
||||||
return toRet;
|
return toRet;
|
||||||
}
|
}
|
||||||
|
|
@ -533,7 +549,15 @@ bool GUIManager::input_scalar(const char* id, uint8_t* val, uint8_t min, uint8_t
|
||||||
},
|
},
|
||||||
[&](const uint8_t& a) {
|
[&](const uint8_t& a) {
|
||||||
return std::to_string(static_cast<uint32_t>(a));
|
return std::to_string(static_cast<uint32_t>(a));
|
||||||
}, true, false, elemUpdate);
|
}, true, false,
|
||||||
|
{
|
||||||
|
.inputType = SDL_TextInputType::SDL_TEXTINPUT_TYPE_NUMBER,
|
||||||
|
.capitalization = SDL_Capitalization::SDL_CAPITALIZE_NONE,
|
||||||
|
.autocorrect = false,
|
||||||
|
.multiline = false,
|
||||||
|
.androidInputType = InputManager::AndroidInputType::ANDROIDTEXT_TYPE_CLASS_NUMBER
|
||||||
|
},
|
||||||
|
elemUpdate);
|
||||||
pop_id();
|
pop_id();
|
||||||
return isUpdating;
|
return isUpdating;
|
||||||
}
|
}
|
||||||
|
|
@ -549,7 +573,15 @@ void GUIManager::input_path(const char* id, std::filesystem::path* val, std::fil
|
||||||
},
|
},
|
||||||
[&](const std::filesystem::path& a) {
|
[&](const std::filesystem::path& a) {
|
||||||
return a.string();
|
return a.string();
|
||||||
}, true, false, elemUpdate);
|
}, true, false,
|
||||||
|
{
|
||||||
|
.inputType = SDL_TextInputType::SDL_TEXTINPUT_TYPE_TEXT,
|
||||||
|
.capitalization = SDL_Capitalization::SDL_CAPITALIZE_NONE,
|
||||||
|
.autocorrect = false,
|
||||||
|
.multiline = false,
|
||||||
|
.androidInputType = InputManager::AndroidInputType::ANDROIDTEXT_TYPE_CLASS_TEXT
|
||||||
|
},
|
||||||
|
elemUpdate);
|
||||||
pop_id();
|
pop_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,15 +147,26 @@ class GUIManager {
|
||||||
return toRet;
|
return toRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool input_generic(const char* id, T* val, const std::function<std::optional<T>(const std::string&)>& fromStr, const std::function<std::string(const T&)>& toStr, bool singleLine, bool updateEveryEdit, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
template <typename T> bool input_generic(const char* id, T* val, const std::function<std::optional<T>(const std::string&)>& fromStr, const std::function<std::string(const T&)>& toStr, bool singleLine, bool updateEveryEdit, const InputManager::TextInputProperties& inputProps, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||||
bool isUpdating = false;
|
bool isUpdating = false;
|
||||||
push_id(id);
|
push_id(id);
|
||||||
isUpdating = insert_element<TextBox<T>>()->update(*io, val, fromStr, toStr, singleLine, updateEveryEdit, elemUpdate);
|
isUpdating = insert_element<TextBox<T>>()->update(*io, val, fromStr, toStr, singleLine, updateEveryEdit, inputProps, elemUpdate);
|
||||||
pop_id();
|
pop_id();
|
||||||
return isUpdating;
|
return isUpdating;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool input_scalar(const char* id, T* val, T min, T max, int decimalPrecision = 0, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
template <typename T> bool input_scalar(const char* id, T* val, T min, T max, int decimalPrecision = 0, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||||
|
InputManager::TextInputProperties textInputProps {
|
||||||
|
.inputType = SDL_TextInputType::SDL_TEXTINPUT_TYPE_NUMBER,
|
||||||
|
.capitalization = SDL_Capitalization::SDL_CAPITALIZE_NONE,
|
||||||
|
.autocorrect = false,
|
||||||
|
.multiline = false,
|
||||||
|
.androidInputType = InputManager::AndroidInputType::ANDROIDTEXT_TYPE_CLASS_NUMBER
|
||||||
|
};
|
||||||
|
if(std::is_signed<T>())
|
||||||
|
textInputProps.androidInputType |= InputManager::AndroidInputType::ANDROIDTEXT_TYPE_NUMBER_FLAG_SIGNED;
|
||||||
|
if(std::is_floating_point<T>())
|
||||||
|
textInputProps.androidInputType |= InputManager::AndroidInputType::ANDROIDTEXT_TYPE_NUMBER_FLAG_DECIMAL;
|
||||||
return input_generic<T>(id, val,
|
return input_generic<T>(id, val,
|
||||||
[&](const std::string& a) {
|
[&](const std::string& a) {
|
||||||
if(a.empty())
|
if(a.empty())
|
||||||
|
|
@ -177,7 +188,7 @@ class GUIManager {
|
||||||
else
|
else
|
||||||
ss << *val;
|
ss << *val;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}, true, false, elemUpdate);
|
}, true, false, textInputProps, elemUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool input_scalar(const char* id, uint8_t* val, uint8_t min, uint8_t max, int decimalPrecision, const std::function<void(SelectionHelper&)>& elemUpdate);
|
bool input_scalar(const char* id, uint8_t* val, uint8_t min, uint8_t max, int decimalPrecision, const std::function<void(SelectionHelper&)>& elemUpdate);
|
||||||
|
|
@ -231,7 +242,15 @@ class GUIManager {
|
||||||
}
|
}
|
||||||
return ss.str();
|
return ss.str();
|
||||||
},
|
},
|
||||||
true, false, elemUpdate);
|
true, false,
|
||||||
|
{
|
||||||
|
.inputType = SDL_TextInputType::SDL_TEXTINPUT_TYPE_TEXT,
|
||||||
|
.capitalization = SDL_Capitalization::SDL_CAPITALIZE_NONE,
|
||||||
|
.autocorrect = false,
|
||||||
|
.multiline = false,
|
||||||
|
.androidInputType = InputManager::AndroidInputType::ANDROIDTEXT_TYPE_CLASS_TEXT
|
||||||
|
},
|
||||||
|
elemUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool color_picker(const char* id, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
template <typename T> bool color_picker(const char* id, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <SDL3/SDL_keycode.h>
|
#include <SDL3/SDL_keycode.h>
|
||||||
|
|
||||||
#include <SDL3/SDL_pen.h>
|
#include <SDL3/SDL_pen.h>
|
||||||
|
#include <SDL3/SDL_properties.h>
|
||||||
#include <SDL3/SDL_timer.h>
|
#include <SDL3/SDL_timer.h>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
|
@ -87,32 +88,35 @@ InputManager::InputManager(MainProgram& initMain):
|
||||||
keyAssignments = defaultKeyAssignments;
|
keyAssignments = defaultKeyAssignments;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::set_rich_text_box_input_front(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::optional<RichText::TextStyleModifier::ModifierMap>& nModMap) {
|
void InputManager::set_rich_text_box_input_front(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::shared_ptr<SCollision::AABB<float>>& textboxRect, const TextInputProperties& inputProps, const std::optional<RichText::TextStyleModifier::ModifierMap>& nModMap) {
|
||||||
text.set_accepting_input(main.window.sdlWindow, true);
|
|
||||||
Text::TextBoxInfo textBoxInfo;
|
Text::TextBoxInfo textBoxInfo;
|
||||||
textBoxInfo.textBox = nTextBox;
|
textBoxInfo.textBox = nTextBox;
|
||||||
textBoxInfo.cursor = nCursor;
|
textBoxInfo.cursor = nCursor;
|
||||||
textBoxInfo.modMap = nModMap;
|
textBoxInfo.modMap = nModMap;
|
||||||
textBoxInfo.isRichTextBox = isRichTextBox;
|
textBoxInfo.isRichTextBox = isRichTextBox;
|
||||||
|
textBoxInfo.rect = textboxRect;
|
||||||
|
textBoxInfo.textInputProperties = inputProps;
|
||||||
text.textBoxes.emplace_front(textBoxInfo);
|
text.textBoxes.emplace_front(textBoxInfo);
|
||||||
|
text.update_accepting_input(main.window.sdlWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::set_rich_text_box_input_back(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::optional<RichText::TextStyleModifier::ModifierMap>& nModMap) {
|
void InputManager::set_rich_text_box_input_back(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::shared_ptr<SCollision::AABB<float>>& textboxRect, const TextInputProperties& inputProps, const std::optional<RichText::TextStyleModifier::ModifierMap>& nModMap) {
|
||||||
text.set_accepting_input(main.window.sdlWindow, true);
|
|
||||||
Text::TextBoxInfo textBoxInfo;
|
Text::TextBoxInfo textBoxInfo;
|
||||||
textBoxInfo.textBox = nTextBox;
|
textBoxInfo.textBox = nTextBox;
|
||||||
textBoxInfo.cursor = nCursor;
|
textBoxInfo.cursor = nCursor;
|
||||||
textBoxInfo.modMap = nModMap;
|
textBoxInfo.modMap = nModMap;
|
||||||
textBoxInfo.isRichTextBox = isRichTextBox;
|
textBoxInfo.isRichTextBox = isRichTextBox;
|
||||||
|
textBoxInfo.rect = textboxRect;
|
||||||
|
textBoxInfo.textInputProperties = inputProps;
|
||||||
text.textBoxes.emplace_back(textBoxInfo);
|
text.textBoxes.emplace_back(textBoxInfo);
|
||||||
|
text.update_accepting_input(main.window.sdlWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::remove_rich_text_box_input(const std::shared_ptr<RichText::TextBox>& nTextBox) {
|
void InputManager::remove_rich_text_box_input(const std::shared_ptr<RichText::TextBox>& nTextBox) {
|
||||||
std::erase_if(text.textBoxes, [&nTextBox](Text::TextBoxInfo& info) {
|
std::erase_if(text.textBoxes, [&nTextBox](Text::TextBoxInfo& info) {
|
||||||
return (info.textBox == nTextBox);
|
return (info.textBox == nTextBox);
|
||||||
});
|
});
|
||||||
if(text.textBoxes.empty())
|
text.update_accepting_input(main.window.sdlWindow);
|
||||||
text.set_accepting_input(main.window.sdlWindow, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::Text::add_text_to_textbox(const std::string& inputText) {
|
void InputManager::Text::add_text_to_textbox(const std::string& inputText) {
|
||||||
|
|
@ -153,18 +157,24 @@ void InputManager::Text::do_textbox_operation_with_undo(const std::function<void
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputManager::Text::is_accepting_input() {
|
bool InputManager::Text::is_accepting_input() {
|
||||||
return acceptingInput;
|
return !textBoxes.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::Text::set_accepting_input(SDL_Window* window, bool newAcceptingInputVal) {
|
void InputManager::Text::update_accepting_input(SDL_Window* window) {
|
||||||
if(!acceptingInput && newAcceptingInputVal) {
|
if(!textBoxes.empty()) {
|
||||||
SDL_StartTextInput(window);
|
auto& textbox = textBoxes.front();
|
||||||
acceptingInput = true;
|
if(!propID.has_value())
|
||||||
|
propID = SDL_CreateProperties();
|
||||||
|
SDL_PropertiesID propIDVal = propID.value();
|
||||||
|
SDL_SetNumberProperty(propIDVal, SDL_PROP_TEXTINPUT_TYPE_NUMBER, textbox.textInputProperties.inputType);
|
||||||
|
SDL_SetNumberProperty(propIDVal, SDL_PROP_TEXTINPUT_CAPITALIZATION_NUMBER, textbox.textInputProperties.capitalization);
|
||||||
|
SDL_SetNumberProperty(propIDVal, SDL_PROP_TEXTINPUT_AUTOCORRECT_BOOLEAN, textbox.textInputProperties.autocorrect);
|
||||||
|
SDL_SetNumberProperty(propIDVal, SDL_PROP_TEXTINPUT_MULTILINE_BOOLEAN, textbox.textInputProperties.multiline);
|
||||||
|
SDL_SetNumberProperty(propIDVal, SDL_PROP_TEXTINPUT_ANDROID_INPUTTYPE_NUMBER, textbox.textInputProperties.androidInputType);
|
||||||
|
SDL_StartTextInputWithProperties(window, propIDVal);
|
||||||
}
|
}
|
||||||
else if(acceptingInput && !newAcceptingInputVal) {
|
else
|
||||||
SDL_StopTextInput(window);
|
SDL_StopTextInput(window);
|
||||||
acceptingInput = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string InputManager::get_clipboard_str_SDL() {
|
std::string InputManager::get_clipboard_str_SDL() {
|
||||||
|
|
@ -968,7 +978,7 @@ void InputManager::backend_key_down_update(const SDL_KeyboardEvent& e) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(text.acceptingInput)
|
if(text.is_accepting_input())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto f = keyAssignments.find({make_generic_key_mod(kMod), kPress});
|
auto f = keyAssignments.find({make_generic_key_mod(kMod), kPress});
|
||||||
|
|
@ -1157,6 +1167,15 @@ void InputManager::update() {
|
||||||
touch_finger_do_mouse_down();
|
touch_finger_do_mouse_down();
|
||||||
touch.touchEventType = Touch::ONE_FINGER_EVENT;
|
touch.touchEventType = Touch::ONE_FINGER_EVENT;
|
||||||
}
|
}
|
||||||
|
if(!text.textBoxes.empty()) {
|
||||||
|
auto& textbox = text.textBoxes.front();
|
||||||
|
if(textbox.rect) {
|
||||||
|
SDL_Rect r = textbox.rect->get_sdl_rect();
|
||||||
|
SDL_SetTextInputArea(main.window.sdlWindow, &r, textbox.cursor->pos.fTextByteIndex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SDL_SetTextInputArea(main.window.sdlWindow, nullptr, textbox.cursor->pos.fTextByteIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::frame_reset(const Vector2i& windowSize) {
|
void InputManager::frame_reset(const Vector2i& windowSize) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <Eigen/Dense>
|
#include <Eigen/Dense>
|
||||||
|
#include <SDL3/SDL_keyboard.h>
|
||||||
|
#include <SDL3/SDL_properties.h>
|
||||||
#include <SDL3/SDL_touch.h>
|
#include <SDL3/SDL_touch.h>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "RichText/TextStyleModifier.hpp"
|
#include "RichText/TextStyleModifier.hpp"
|
||||||
|
|
@ -16,6 +18,8 @@
|
||||||
#include <SDL3/SDL_events.h>
|
#include <SDL3/SDL_events.h>
|
||||||
#include <SDL3/SDL_keycode.h>
|
#include <SDL3/SDL_keycode.h>
|
||||||
|
|
||||||
|
#include <Helpers/SCollision.hpp>
|
||||||
|
|
||||||
using namespace Eigen;
|
using namespace Eigen;
|
||||||
class MainProgram;
|
class MainProgram;
|
||||||
|
|
||||||
|
|
@ -103,8 +107,59 @@ struct InputManager {
|
||||||
|
|
||||||
bool isTouchDevice = true;
|
bool isTouchDevice = true;
|
||||||
|
|
||||||
void set_rich_text_box_input_front(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::optional<RichText::TextStyleModifier::ModifierMap>& nModMap = std::nullopt);
|
enum AndroidInputType : int {
|
||||||
void set_rich_text_box_input_back(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::optional<RichText::TextStyleModifier::ModifierMap>& nModMap = std::nullopt);
|
ANDROIDTEXT_TYPE_CLASS_DATETIME = 0x00000004,
|
||||||
|
ANDROIDTEXT_TYPE_CLASS_NUMBER = 0x00000002,
|
||||||
|
ANDROIDTEXT_TYPE_CLASS_PHONE = 0x00000003,
|
||||||
|
ANDROIDTEXT_TYPE_CLASS_TEXT = 0x00000001,
|
||||||
|
ANDROIDTEXT_TYPE_DATETIME_VARIATION_DATE = 0x00000010,
|
||||||
|
ANDROIDTEXT_TYPE_DATETIME_VARIATION_NORMAL = 0x00000000,
|
||||||
|
ANDROIDTEXT_TYPE_DATETIME_VARIATION_TIME = 0x00000020,
|
||||||
|
ANDROIDTEXT_TYPE_MASK_CLASS = 0x0000000f,
|
||||||
|
ANDROIDTEXT_TYPE_MASK_FLAGS = 0x00fff000,
|
||||||
|
ANDROIDTEXT_TYPE_MASK_VARIATION = 0x00000ff0,
|
||||||
|
ANDROIDTEXT_TYPE_NULL = 0x00000000,
|
||||||
|
ANDROIDTEXT_TYPE_NUMBER_FLAG_DECIMAL = 0x00002000,
|
||||||
|
ANDROIDTEXT_TYPE_NUMBER_FLAG_SIGNED = 0x00001000,
|
||||||
|
ANDROIDTEXT_TYPE_NUMBER_VARIATION_NORMAL = 0x00000000,
|
||||||
|
ANDROIDTEXT_TYPE_NUMBER_VARIATION_PASSWORD = 0x00000010,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_FLAG_AUTO_COMPLETE = 0x00010000,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_FLAG_AUTO_CORRECT = 0x00008000,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_FLAG_CAP_CHARACTERS = 0x00001000,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_FLAG_CAP_SENTENCES = 0x00004000,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_FLAG_CAP_WORDS = 0x00002000,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_FLAG_ENABLE_TEXT_CONVERSION_SUGGESTIONS = 0x00100000,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_FLAG_ENABLE_TEXT_SUGGESTION_SELECTED = 0x00200000,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_FLAG_IME_MULTI_LINE = 0x00040000,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_FLAG_MULTI_LINE = 0x00020000,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_FLAG_NO_SUGGESTIONS = 0x00080000,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_EMAIL_ADDRESS = 0x00000020,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_EMAIL_SUBJECT = 0x00000030,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_FILTER = 0x000000b0,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_LONG_MESSAGE = 0x00000050,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_NORMAL = 0x00000000,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_PASSWORD = 0x00000080,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_PERSON_NAME = 0x00000060,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_PHONETIC = 0x000000c0,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_POSTAL_ADDRESS = 0x00000070,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_SHORT_MESSAGE = 0x00000040,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_URI = 0x00000010,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_VISIBLE_PASSWORD = 0x00000090,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_WEB_EDIT_TEXT = 0x000000a0,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS = 0x000000d0,
|
||||||
|
ANDROIDTEXT_TYPE_TEXT_VARIATION_WEB_PASSWORD = 0x000000e0
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TextInputProperties {
|
||||||
|
SDL_TextInputType inputType;
|
||||||
|
SDL_Capitalization capitalization;
|
||||||
|
bool autocorrect;
|
||||||
|
bool multiline;
|
||||||
|
int androidInputType;
|
||||||
|
};
|
||||||
|
|
||||||
|
void set_rich_text_box_input_front(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::shared_ptr<SCollision::AABB<float>>& textboxRect, const TextInputProperties& inputProps, const std::optional<RichText::TextStyleModifier::ModifierMap>& nModMap = std::nullopt);
|
||||||
|
void set_rich_text_box_input_back(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::shared_ptr<SCollision::AABB<float>>& textboxRect, const TextInputProperties& inputProps, const std::optional<RichText::TextStyleModifier::ModifierMap>& nModMap = std::nullopt);
|
||||||
void remove_rich_text_box_input(const std::shared_ptr<RichText::TextBox>& nTextBox);
|
void remove_rich_text_box_input(const std::shared_ptr<RichText::TextBox>& nTextBox);
|
||||||
|
|
||||||
struct Text {
|
struct Text {
|
||||||
|
|
@ -120,14 +175,17 @@ struct InputManager {
|
||||||
bool isRichTextBox;
|
bool isRichTextBox;
|
||||||
std::shared_ptr<RichText::TextBox> textBox;
|
std::shared_ptr<RichText::TextBox> textBox;
|
||||||
std::shared_ptr<RichText::TextBox::Cursor> cursor;
|
std::shared_ptr<RichText::TextBox::Cursor> cursor;
|
||||||
|
std::shared_ptr<SCollision::AABB<float>> rect;
|
||||||
std::optional<RichText::TextStyleModifier::ModifierMap> modMap;
|
std::optional<RichText::TextStyleModifier::ModifierMap> modMap;
|
||||||
|
TextInputProperties textInputProperties;
|
||||||
UndoManager textboxUndo;
|
UndoManager textboxUndo;
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_accepting_input(SDL_Window* window, bool newAcceptingInputVal);
|
void update_accepting_input(SDL_Window* window);
|
||||||
|
|
||||||
bool isNextPasteRich = false;
|
bool isNextPasteRich = false;
|
||||||
bool acceptingInput = false;
|
|
||||||
|
std::optional<SDL_PropertiesID> propID;
|
||||||
|
|
||||||
std::deque<TextBoxInfo> textBoxes;
|
std::deque<TextBoxInfo> textBoxes;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2273,6 +2273,8 @@ void Toolbar::initialize_io() {
|
||||||
io->previousRichTextBoxToEdit = io->richTextBoxToEdit;
|
io->previousRichTextBoxToEdit = io->richTextBoxToEdit;
|
||||||
io->richTextBoxToEditCursor = nullptr;
|
io->richTextBoxToEditCursor = nullptr;
|
||||||
io->richTextBoxToEdit = nullptr;
|
io->richTextBoxToEdit = nullptr;
|
||||||
|
io->richTextBoxToEditRectangle = nullptr;
|
||||||
|
io->guiScaleMultiplier = final_gui_scale();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Toolbar::end_io() {
|
void Toolbar::end_io() {
|
||||||
|
|
@ -2280,7 +2282,7 @@ void Toolbar::end_io() {
|
||||||
main.input.set_clipboard_str(*io->clipboard.textOut);
|
main.input.set_clipboard_str(*io->clipboard.textOut);
|
||||||
if(io->richTextBoxToEdit != io->previousRichTextBoxToEdit) {
|
if(io->richTextBoxToEdit != io->previousRichTextBoxToEdit) {
|
||||||
if(io->richTextBoxToEdit)
|
if(io->richTextBoxToEdit)
|
||||||
main.input.set_rich_text_box_input_front(io->richTextBoxToEdit, io->richTextBoxToEditCursor, false);
|
main.input.set_rich_text_box_input_front(io->richTextBoxToEdit, io->richTextBoxToEditCursor, false, io->richTextBoxToEditRectangle, io->richTextInputProperties);
|
||||||
if(io->previousRichTextBoxToEdit)
|
if(io->previousRichTextBoxToEdit)
|
||||||
main.input.remove_rich_text_box_input(io->previousRichTextBoxToEdit);
|
main.input.remove_rich_text_box_input(io->previousRichTextBoxToEdit);
|
||||||
}
|
}
|
||||||
|
|
@ -2409,11 +2411,11 @@ void Toolbar::input_finger_motion_callback(const InputManager::FingerMotionCallb
|
||||||
void Toolbar::start_gui() {
|
void Toolbar::start_gui() {
|
||||||
SDL_Rect windowRect;
|
SDL_Rect windowRect;
|
||||||
if(SDL_GetWindowSafeArea(main.window.sdlWindow, &windowRect)) {
|
if(SDL_GetWindowSafeArea(main.window.sdlWindow, &windowRect)) {
|
||||||
gui.windowPos = Vector2f{windowRect.x, windowRect.y} / final_gui_scale();
|
io->windowPos = gui.windowPos = Vector2f{windowRect.x, windowRect.y} / final_gui_scale();
|
||||||
gui.windowSize = Vector2f{windowRect.w, windowRect.h} / final_gui_scale();
|
gui.windowSize = Vector2f{windowRect.w, windowRect.h} / final_gui_scale();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
gui.windowPos = Vector2f{0.0f, 0.0f};
|
io->windowPos = gui.windowPos = Vector2f{0.0f, 0.0f};
|
||||||
gui.windowSize = main.window.size.cast<float>() / final_gui_scale();
|
gui.windowSize = main.window.size.cast<float>() / final_gui_scale();
|
||||||
}
|
}
|
||||||
initialize_io();
|
initialize_io();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue