2020-02-20 15:48:15 +09:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
|
|
|
* OpenMiner
|
2020-02-25 01:42:10 +09:00
|
|
|
*
|
2020-02-20 15:48:15 +09:00
|
|
|
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <openminer@unarelith.net>
|
2020-02-25 01:42:10 +09:00
|
|
|
* Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md)
|
|
|
|
*
|
|
|
|
* This file is part of OpenMiner.
|
2020-02-20 15:48:15 +09:00
|
|
|
*
|
2020-02-25 01:42:10 +09:00
|
|
|
* OpenMiner is free software; you can redistribute it and/or
|
2020-02-20 15:48:15 +09:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2020-02-25 01:42:10 +09:00
|
|
|
* OpenMiner is distributed in the hope that it will be useful,
|
2020-02-20 15:48:15 +09:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2020-02-25 01:42:10 +09:00
|
|
|
* along with OpenMiner; if not, write to the Free Software Foundation, Inc.,
|
2020-02-20 15:48:15 +09:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
|
|
|
#ifndef TEXTINPUT_HPP_
|
|
|
|
#define TEXTINPUT_HPP_
|
|
|
|
|
2020-07-07 19:33:01 +02:00
|
|
|
#include <gk/core/SDLHeaders.hpp>
|
2020-02-20 15:48:15 +09:00
|
|
|
|
|
|
|
#include "Text.hpp"
|
|
|
|
|
|
|
|
class TextInput : public gk::Drawable, public gk::Transformable {
|
|
|
|
public:
|
|
|
|
TextInput();
|
|
|
|
|
2020-07-07 19:33:01 +02:00
|
|
|
void onEvent(const SDL_Event &event);
|
2020-02-20 15:48:15 +09:00
|
|
|
|
2020-06-20 01:24:06 +02:00
|
|
|
const std::string &string() const { return m_content; }
|
2020-06-26 01:31:41 +02:00
|
|
|
void setString(const std::string &string);
|
2020-02-21 17:25:56 +09:00
|
|
|
|
2020-03-04 13:18:22 +01:00
|
|
|
gk::Vector2f getBackgroundSize() const { return m_text.getBackgroundSize(); }
|
|
|
|
|
2020-02-21 23:58:15 +09:00
|
|
|
void setBackgroundColor(const gk::Color &color) { m_text.setBackgroundColor(color); }
|
|
|
|
void setBackgroundSize(unsigned int width, unsigned int height) { m_text.setBackgroundSize(width, height); }
|
2020-03-04 13:18:22 +01:00
|
|
|
void setBackgroundOutline(int thickness, const gk::Color &color) { m_text.setBackgroundOutline(thickness, color); }
|
2020-02-20 17:07:45 +09:00
|
|
|
|
2020-06-26 01:31:41 +02:00
|
|
|
void setPadding(int x, int y) { m_text.setPadding(x, y); m_cursor.setPadding(x, y); m_placeholder.setPadding(x, y); }
|
2020-03-04 13:18:22 +01:00
|
|
|
void setCharacterLimit(u16 characterLimit) { m_characterLimit = characterLimit; }
|
2020-02-20 17:07:45 +09:00
|
|
|
|
2020-06-26 01:31:41 +02:00
|
|
|
void setPlaceholder(const std::string &placeholder) { m_placeholder.setString(placeholder); }
|
|
|
|
|
|
|
|
void setFocus(bool hasFocus) { m_hasFocus = hasFocus; }
|
|
|
|
|
2020-02-20 15:48:15 +09:00
|
|
|
private:
|
|
|
|
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
|
|
|
|
|
|
|
|
Text m_text;
|
|
|
|
std::string m_content;
|
2020-06-26 01:31:41 +02:00
|
|
|
|
|
|
|
Text m_cursor;
|
2020-02-20 15:48:15 +09:00
|
|
|
|
|
|
|
u16 m_characterLimit = 0;
|
2020-06-26 01:31:41 +02:00
|
|
|
|
|
|
|
Text m_placeholder;
|
|
|
|
|
|
|
|
bool m_hasFocus = true;
|
2020-02-20 15:48:15 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TEXTINPUT_HPP_
|