25#ifndef TGUI_KEYBOARD_HPP
26#define TGUI_KEYBOARD_HPP
30#include <TGUI/Config.hpp>
31#include <TGUI/Event.hpp>
32#include <TGUI/Container.hpp>
33#include <TGUI/Widgets/ScrollablePanel.hpp>
34#include <TGUI/Backend/Window/Backend.hpp>
35#include <TGUI/Backend/Window/BackendGui.hpp>
44#ifndef TGUI_REMOVE_DEPRECATED_CODE
45 TGUI_DEPRECATED(
"Use BackendGui::startTextInput instead") inline
void openVirtualKeyboard(const Widget* requestingWidget, FloatRect inputRect)
47 const Widget* widget = requestingWidget;
50 const bool defaultOrigin = (widget->getOrigin().x == 0) && (widget->getOrigin().y == 0);
51 const bool scaledOrRotated = (widget->getScale().x != 1) || (widget->getScale().y != 1) || (widget->getRotation() != 0);
52 if (defaultOrigin && !scaledOrRotated)
53 inputRect.setPosition(inputRect.getPosition() + widget->getPosition());
56 const Vector2f origin{widget->getOrigin().
x * widget->getSize().x, widget->getOrigin().y * widget->getSize().y};
58 inputRect.setPosition(inputRect.getPosition() + widget->getPosition() - origin);
61 const Vector2f rotOrigin{widget->getRotationOrigin().
x * widget->getSize().x, widget->getRotationOrigin().y * widget->getSize().y};
62 const Vector2f scaleOrigin{widget->getScaleOrigin().
x * widget->getSize().x, widget->getScaleOrigin().y * widget->getSize().y};
65 transform.translate(widget->getPosition() - origin);
66 transform.rotate(widget->getRotation(), rotOrigin);
67 transform.scale(widget->getScale(), scaleOrigin);
68 inputRect = transform.transformRect(inputRect);
72 const Container* parent = widget->getParent();
75 inputRect.setPosition(inputRect.getPosition() + parent->getChildWidgetsOffset());
77 const ScrollablePanel* panel =
dynamic_cast<const ScrollablePanel*
>(parent);
79 inputRect.setPosition(inputRect.getPosition() - panel->getContentOffset());
85 const auto gui = requestingWidget->getParentGui();
88 const Vector2f topLeftPos = gui->mapCoordsToPixel(inputRect.getPosition());
89 const Vector2f bottomRightPos = gui->mapCoordsToPixel(inputRect.getPosition() + inputRect.getSize());
90 inputRect = {topLeftPos, bottomRightPos - topLeftPos};
93 TGUI_IGNORE_DEPRECATED_WARNINGS_START
95 TGUI_IGNORE_DEPRECATED_WARNINGS_END
100 TGUI_NODISCARD
inline bool isShiftPressed(
const Event::KeyEvent& event)
107 TGUI_NODISCARD
inline bool isShiftPressed()
109 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::Shift);
113#ifndef TGUI_REMOVE_DEPRECATED_CODE
114 TGUI_DEPRECATED(
"Use BackendGui::stopTextInput instead") inline
void closeVirtualKeyboard()
116 TGUI_IGNORE_DEPRECATED_WARNINGS_START
118 TGUI_IGNORE_DEPRECATED_WARNINGS_END
123 TGUI_NODISCARD
inline bool isMultiselectModifierPressed(
const Event::KeyEvent& event)
125#ifdef TGUI_SYSTEM_MACOS
128 return event.control;
134 TGUI_NODISCARD
inline bool isMultiselectModifierPressed()
136#ifdef TGUI_SYSTEM_MACOS
137 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::System);
139 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::Control);
145 TGUI_NODISCARD
inline bool isKeyPressCopy(
const Event::KeyEvent& event)
147#ifdef TGUI_SYSTEM_MACOS
148 return (event.code ==
Event::KeyboardKey::C) && !
event.control && !
event.alt && !
event.shift &&
event.system;
150 return (event.code ==
Event::KeyboardKey::C) &&
event.control && !
event.alt && !
event.shift && !
event.system;
156 TGUI_NODISCARD
inline bool isKeyPressCut(
const Event::KeyEvent& event)
158#ifdef TGUI_SYSTEM_MACOS
159 return (event.code ==
Event::KeyboardKey::X) && !
event.control && !
event.alt && !
event.shift &&
event.system;
161 return (event.code ==
Event::KeyboardKey::X) &&
event.control && !
event.alt && !
event.shift && !
event.system;
167 TGUI_NODISCARD
inline bool isKeyPressPaste(
const Event::KeyEvent& event)
169#ifdef TGUI_SYSTEM_MACOS
170 return (event.code ==
Event::KeyboardKey::V) && !
event.control && !
event.alt && !
event.shift &&
event.system;
172 return (event.code ==
Event::KeyboardKey::V) &&
event.control && !
event.alt && !
event.shift && !
event.system;
178 TGUI_NODISCARD
inline bool isKeyPressSelectAll(
const Event::KeyEvent& event)
180#ifdef TGUI_SYSTEM_MACOS
181 return (event.code ==
Event::KeyboardKey::A) && !
event.control && !
event.alt && !
event.shift &&
event.system;
183 return (event.code ==
Event::KeyboardKey::A) &&
event.control && !
event.alt && !
event.shift && !
event.system;
189 TGUI_NODISCARD
inline bool isKeyPressMoveCaretLeft(
const Event::KeyEvent& event)
196 TGUI_NODISCARD
inline bool isKeyPressMoveCaretRight(
const Event::KeyEvent& event)
203 TGUI_NODISCARD
inline bool isKeyPressMoveCaretWordBegin(
const Event::KeyEvent& event)
205#ifdef TGUI_SYSTEM_MACOS
214 TGUI_NODISCARD
inline bool isKeyPressMoveCaretWordEnd(
const Event::KeyEvent& event)
216#ifdef TGUI_SYSTEM_MACOS
225 TGUI_NODISCARD
inline bool isKeyPressMoveCaretUp(
const Event::KeyEvent& event)
227#ifdef TGUI_SYSTEM_MACOS
237 TGUI_NODISCARD
inline bool isKeyPressMoveCaretDown(
const Event::KeyEvent& event)
239#ifdef TGUI_SYSTEM_MACOS
249 TGUI_NODISCARD
inline bool isKeyPressMoveCaretLineStart(
const Event::KeyEvent& event)
251#ifdef TGUI_SYSTEM_MACOS
260 TGUI_NODISCARD
inline bool isKeyPressMoveCaretLineEnd(
const Event::KeyEvent& event)
262#ifdef TGUI_SYSTEM_MACOS
271 TGUI_NODISCARD
inline bool isKeyPressMoveCaretDocumentBegin(
const Event::KeyEvent& event)
273#ifdef TGUI_SYSTEM_MACOS
283 TGUI_NODISCARD
inline bool isKeyPressMoveCaretDocumentEnd(
const Event::KeyEvent& event)
285#ifdef TGUI_SYSTEM_MACOS
T x
X coordinate of the vector.
Definition Vector2.hpp:135
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
TGUI_API std::shared_ptr< Backend > getBackend()
Returns the global backend.