mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-09 09:38:19 +00:00
Merge pull request #8772 from Robyt3/Client-Input-Clipboard-String
Use `std::string` for `IInput::GetClipboardText`
This commit is contained in:
commit
1dd2f3a4af
|
@ -68,8 +68,6 @@ CInput::CInput()
|
||||||
|
|
||||||
m_MouseFocus = true;
|
m_MouseFocus = true;
|
||||||
|
|
||||||
m_pClipboardText = nullptr;
|
|
||||||
|
|
||||||
m_CompositionCursor = 0;
|
m_CompositionCursor = 0;
|
||||||
m_CandidateSelectedIndex = -1;
|
m_CandidateSelectedIndex = -1;
|
||||||
|
|
||||||
|
@ -90,7 +88,6 @@ void CInput::Init()
|
||||||
|
|
||||||
void CInput::Shutdown()
|
void CInput::Shutdown()
|
||||||
{
|
{
|
||||||
SDL_free(m_pClipboardText);
|
|
||||||
CloseJoysticks();
|
CloseJoysticks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,11 +300,12 @@ const std::vector<IInput::CTouchFingerState> &CInput::TouchFingerStates() const
|
||||||
return m_vTouchFingerStates;
|
return m_vTouchFingerStates;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *CInput::GetClipboardText()
|
std::string CInput::GetClipboardText()
|
||||||
{
|
{
|
||||||
SDL_free(m_pClipboardText);
|
char *pClipboardText = SDL_GetClipboardText();
|
||||||
m_pClipboardText = SDL_GetClipboardText();
|
std::string ClipboardText = pClipboardText;
|
||||||
return m_pClipboardText;
|
SDL_free(pClipboardText);
|
||||||
|
return ClipboardText;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInput::SetClipboardText(const char *pText)
|
void CInput::SetClipboardText(const char *pText)
|
||||||
|
|
|
@ -74,7 +74,6 @@ private:
|
||||||
float GetJoystickDeadzone();
|
float GetJoystickDeadzone();
|
||||||
|
|
||||||
bool m_InputGrabbed;
|
bool m_InputGrabbed;
|
||||||
char *m_pClipboardText;
|
|
||||||
|
|
||||||
bool m_MouseFocus;
|
bool m_MouseFocus;
|
||||||
#if defined(CONF_PLATFORM_ANDROID)
|
#if defined(CONF_PLATFORM_ANDROID)
|
||||||
|
@ -151,7 +150,7 @@ public:
|
||||||
|
|
||||||
const std::vector<CTouchFingerState> &TouchFingerStates() const override;
|
const std::vector<CTouchFingerState> &TouchFingerStates() const override;
|
||||||
|
|
||||||
const char *GetClipboardText() override;
|
std::string GetClipboardText() override;
|
||||||
void SetClipboardText(const char *pText) override;
|
void SetClipboardText(const char *pText) override;
|
||||||
|
|
||||||
void StartTextInput() override;
|
void StartTextInput() override;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
const int g_MaxKeys = 512;
|
const int g_MaxKeys = 512;
|
||||||
|
@ -138,7 +139,7 @@ public:
|
||||||
virtual const std::vector<CTouchFingerState> &TouchFingerStates() const = 0;
|
virtual const std::vector<CTouchFingerState> &TouchFingerStates() const = 0;
|
||||||
|
|
||||||
// clipboard
|
// clipboard
|
||||||
virtual const char *GetClipboardText() = 0;
|
virtual std::string GetClipboardText() = 0;
|
||||||
virtual void SetClipboardText(const char *pText) = 0;
|
virtual void SetClipboardText(const char *pText) = 0;
|
||||||
|
|
||||||
// text editing
|
// text editing
|
||||||
|
|
|
@ -331,10 +331,9 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
|
||||||
}
|
}
|
||||||
else if(ModPressed && !AltPressed && Event.m_Key == KEY_V)
|
else if(ModPressed && !AltPressed && Event.m_Key == KEY_V)
|
||||||
{
|
{
|
||||||
const char *pClipboardText = Input()->GetClipboardText();
|
std::string ClipboardText = Input()->GetClipboardText();
|
||||||
if(pClipboardText)
|
if(!ClipboardText.empty())
|
||||||
{
|
{
|
||||||
std::string ClipboardText = Input()->GetClipboardText();
|
|
||||||
if(m_pfnClipboardLineCallback)
|
if(m_pfnClipboardLineCallback)
|
||||||
{
|
{
|
||||||
// Split clipboard text into multiple lines. Send all complete lines to callback.
|
// Split clipboard text into multiple lines. Send all complete lines to callback.
|
||||||
|
|
|
@ -3665,12 +3665,12 @@ void CEditor::DoColorPickerButton(const void *pId, const CUIRect *pRect, ColorRG
|
||||||
{
|
{
|
||||||
if(ButtonResult == 1)
|
if(ButtonResult == 1)
|
||||||
{
|
{
|
||||||
const char *pClipboard = Input()->GetClipboardText();
|
std::string Clipboard = Input()->GetClipboardText();
|
||||||
if(*pClipboard == '#' || *pClipboard == '$') // ignore leading # (web color format) and $ (console color format)
|
if(Clipboard[0] == '#' || Clipboard[0] == '$') // ignore leading # (web color format) and $ (console color format)
|
||||||
++pClipboard;
|
Clipboard = Clipboard.substr(1);
|
||||||
if(str_isallnum_hex(pClipboard))
|
if(str_isallnum_hex(Clipboard.c_str()))
|
||||||
{
|
{
|
||||||
std::optional<ColorRGBA> ParsedColor = color_parse<ColorRGBA>(pClipboard);
|
std::optional<ColorRGBA> ParsedColor = color_parse<ColorRGBA>(Clipboard.c_str());
|
||||||
if(ParsedColor)
|
if(ParsedColor)
|
||||||
{
|
{
|
||||||
m_ColorPickerPopupContext.m_State = EEditState::ONE_GO;
|
m_ColorPickerPopupContext.m_State = EEditState::ONE_GO;
|
||||||
|
|
Loading…
Reference in a new issue