26#ifndef TGUI_KEYBOARD_HPP
27#define TGUI_KEYBOARD_HPP
31#include <TGUI/Config.hpp>
32#include <TGUI/Event.hpp>
33#include <TGUI/Container.hpp>
34#include <TGUI/Widgets/ScrollablePanel.hpp>
35#include <TGUI/Backend/Window/Backend.hpp>
36#include <TGUI/Backend/Window/BackendGui.hpp>
45#ifndef TGUI_REMOVE_DEPRECATED_CODE
46 TGUI_DEPRECATED(
"Use BackendGui::startTextInput instead") inline
void openVirtualKeyboard(const Widget* requestingWidget, FloatRect inputRect)
48 const Widget* widget = requestingWidget;
51 const bool defaultOrigin = (widget->getOrigin().x == 0) && (widget->getOrigin().y == 0);
52 const bool scaledOrRotated = (widget->getScale().x != 1) || (widget->getScale().y != 1) || (widget->getRotation() != 0);
53 if (defaultOrigin && !scaledOrRotated)
54 inputRect.setPosition(inputRect.getPosition() + widget->getPosition());
57 const Vector2f origin{widget->getOrigin().
x * widget->getSize().x, widget->getOrigin().y * widget->getSize().y};
59 inputRect.setPosition(inputRect.getPosition() + widget->getPosition() - origin);
62 const Vector2f rotOrigin{widget->getRotationOrigin().
x * widget->getSize().x, widget->getRotationOrigin().y * widget->getSize().y};
63 const Vector2f scaleOrigin{widget->getScaleOrigin().
x * widget->getSize().x, widget->getScaleOrigin().y * widget->getSize().y};
66 transform.translate(widget->getPosition() - origin);
67 transform.rotate(widget->getRotation(), rotOrigin);
68 transform.scale(widget->getScale(), scaleOrigin);
69 inputRect = transform.transformRect(inputRect);
73 const Container* parent = widget->getParent();
76 inputRect.setPosition(inputRect.getPosition() + parent->getChildWidgetsOffset());
78 const ScrollablePanel* panel =
dynamic_cast<const ScrollablePanel*
>(parent);
80 inputRect.setPosition(inputRect.getPosition() - panel->getContentOffset());
86 const auto gui = requestingWidget->getParentGui();
89 const Vector2f topLeftPos = gui->mapCoordsToPixel(inputRect.getPosition());
90 const Vector2f bottomRightPos = gui->mapCoordsToPixel(inputRect.getPosition() + inputRect.getSize());
91 inputRect = {topLeftPos, bottomRightPos - topLeftPos};
94 TGUI_IGNORE_DEPRECATED_WARNINGS_START
96 TGUI_IGNORE_DEPRECATED_WARNINGS_END
101 TGUI_NODISCARD
inline bool isShiftPressed(
const Event::KeyEvent& event)
108 TGUI_NODISCARD
inline bool isShiftPressed()
110 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::Shift);
114#ifndef TGUI_REMOVE_DEPRECATED_CODE
115 TGUI_DEPRECATED(
"Use BackendGui::stopTextInput instead") inline
void closeVirtualKeyboard()
117 TGUI_IGNORE_DEPRECATED_WARNINGS_START
119 TGUI_IGNORE_DEPRECATED_WARNINGS_END
124 TGUI_NODISCARD
inline bool isMultiselectModifierPressed(
const Event::KeyEvent& event)
126#ifdef TGUI_SYSTEM_MACOS
129 return event.control;
135 TGUI_NODISCARD
inline bool isMultiselectModifierPressed()
137#ifdef TGUI_SYSTEM_MACOS
138 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::System);
140 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::Control);
146 TGUI_NODISCARD
inline bool isKeyPressCopy(
const Event::KeyEvent& event)
148#ifdef TGUI_SYSTEM_MACOS
149 return (event.code ==
Event::KeyboardKey::C) && !
event.control && !
event.alt && !
event.shift &&
event.system;
151 return (event.code ==
Event::KeyboardKey::C) &&
event.control && !
event.alt && !
event.shift && !
event.system;
157 TGUI_NODISCARD
inline bool isKeyPressCut(
const Event::KeyEvent& event)
159#ifdef TGUI_SYSTEM_MACOS
160 return (event.code ==
Event::KeyboardKey::X) && !
event.control && !
event.alt && !
event.shift &&
event.system;
162 return (event.code ==
Event::KeyboardKey::X) &&
event.control && !
event.alt && !
event.shift && !
event.system;
168 TGUI_NODISCARD
inline bool isKeyPressPaste(
const Event::KeyEvent& event)
170#ifdef TGUI_SYSTEM_MACOS
171 return (event.code ==
Event::KeyboardKey::V) && !
event.control && !
event.alt && !
event.shift &&
event.system;
173 return (event.code ==
Event::KeyboardKey::V) &&
event.control && !
event.alt && !
event.shift && !
event.system;
179 TGUI_NODISCARD
inline bool isKeyPressSelectAll(
const Event::KeyEvent& event)
181#ifdef TGUI_SYSTEM_MACOS
182 return (event.code ==
Event::KeyboardKey::A) && !
event.control && !
event.alt && !
event.shift &&
event.system;
184 return (event.code ==
Event::KeyboardKey::A) &&
event.control && !
event.alt && !
event.shift && !
event.system;
190 TGUI_NODISCARD
inline bool isKeyPressMoveCaretLeft(
const Event::KeyEvent& event)
197 TGUI_NODISCARD
inline bool isKeyPressMoveCaretRight(
const Event::KeyEvent& event)
204 TGUI_NODISCARD
inline bool isKeyPressMoveCaretWordBegin(
const Event::KeyEvent& event)
206#ifdef TGUI_SYSTEM_MACOS
215 TGUI_NODISCARD
inline bool isKeyPressMoveCaretWordEnd(
const Event::KeyEvent& event)
217#ifdef TGUI_SYSTEM_MACOS
226 TGUI_NODISCARD
inline bool isKeyPressMoveCaretUp(
const Event::KeyEvent& event)
228#ifdef TGUI_SYSTEM_MACOS
238 TGUI_NODISCARD
inline bool isKeyPressMoveCaretDown(
const Event::KeyEvent& event)
240#ifdef TGUI_SYSTEM_MACOS
250 TGUI_NODISCARD
inline bool isKeyPressMoveCaretLineStart(
const Event::KeyEvent& event)
252#ifdef TGUI_SYSTEM_MACOS
261 TGUI_NODISCARD
inline bool isKeyPressMoveCaretLineEnd(
const Event::KeyEvent& event)
263#ifdef TGUI_SYSTEM_MACOS
272 TGUI_NODISCARD
inline bool isKeyPressMoveCaretDocumentBegin(
const Event::KeyEvent& event)
274#ifdef TGUI_SYSTEM_MACOS
284 TGUI_NODISCARD
inline bool isKeyPressMoveCaretDocumentEnd(
const Event::KeyEvent& event)
286#ifdef TGUI_SYSTEM_MACOS
T x
X coordinate of the vector.
Definition Vector2.hpp:138
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
TGUI_API std::shared_ptr< Backend > getBackend()
Returns the global backend.