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 TGUI_ASSERT(requestingWidget !=
nullptr,
"requestingWidget must not be nullptr");
48 if (!requestingWidget)
51 const Widget* widget = requestingWidget;
54 const bool defaultOrigin = (widget->getOrigin().x == 0) && (widget->getOrigin().y == 0);
55 const bool scaledOrRotated = (widget->getScale().x != 1) || (widget->getScale().y != 1) || (widget->getRotation() != 0);
56 if (defaultOrigin && !scaledOrRotated)
57 inputRect.setPosition(inputRect.getPosition() + widget->getPosition());
60 const Vector2f origin{widget->getOrigin().x * widget->getSize().x, widget->getOrigin().y * widget->getSize().y};
62 inputRect.setPosition(inputRect.getPosition() + widget->getPosition() - origin);
65 const Vector2f rotOrigin{widget->getRotationOrigin().x * widget->getSize().x, widget->getRotationOrigin().y * widget->getSize().y};
66 const Vector2f scaleOrigin{widget->getScaleOrigin().x * widget->getSize().x, widget->getScaleOrigin().y * widget->getSize().y};
69 transform.translate(widget->getPosition() - origin);
70 transform.rotate(widget->getRotation(), rotOrigin);
71 transform.scale(widget->getScale(), scaleOrigin);
72 inputRect = transform.transformRect(inputRect);
76 const Container* parent = widget->getParent();
79 inputRect.setPosition(inputRect.getPosition() + parent->getChildWidgetsOffset());
81 const auto* panel =
dynamic_cast<const ScrollablePanel*
>(parent);
83 inputRect.setPosition(inputRect.getPosition() - panel->getContentOffset());
89 const auto* gui = requestingWidget->getParentGui();
92 const Vector2f topLeftPos = gui->mapCoordsToPixel(inputRect.getPosition());
93 const Vector2f bottomRightPos = gui->mapCoordsToPixel(inputRect.getPosition() + inputRect.getSize());
94 inputRect = {topLeftPos, bottomRightPos - topLeftPos};
97 TGUI_IGNORE_DEPRECATED_WARNINGS_START
99 TGUI_IGNORE_DEPRECATED_WARNINGS_END
104 TGUI_NODISCARD
inline bool isShiftPressed(
const Event::KeyEvent& event)
110#ifndef TGUI_REMOVE_DEPRECATED_CODE
111 TGUI_DEPRECATED(
"Use isShiftPressed(gui) instead") TGUI_NODISCARD inline
bool isShiftPressed()
113 TGUI_IGNORE_DEPRECATED_WARNINGS_START
114 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::Shift);
115 TGUI_IGNORE_DEPRECATED_WARNINGS_END
120 TGUI_NODISCARD
inline bool isShiftPressed(
const BackendGui* gui)
122 return gui->isKeyboardModifierPressed(Event::KeyModifier::Shift);
126#ifndef TGUI_REMOVE_DEPRECATED_CODE
127 TGUI_DEPRECATED(
"Use BackendGui::stopTextInput instead") inline
void closeVirtualKeyboard()
129 TGUI_IGNORE_DEPRECATED_WARNINGS_START
131 TGUI_IGNORE_DEPRECATED_WARNINGS_END
136 TGUI_NODISCARD
inline bool isMultiselectModifierPressed(
const Event::KeyEvent& event)
138#ifdef TGUI_SYSTEM_MACOS
141 return event.control;
146#ifndef TGUI_REMOVE_DEPRECATED_CODE
147 TGUI_DEPRECATED(
"Use isMultiselectModifierPressed(gui) instead") TGUI_NODISCARD inline
bool isMultiselectModifierPressed()
149 TGUI_IGNORE_DEPRECATED_WARNINGS_START
150#ifdef TGUI_SYSTEM_MACOS
151 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::System);
153 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::Control);
155 TGUI_IGNORE_DEPRECATED_WARNINGS_END
160 TGUI_NODISCARD
inline bool isMultiselectModifierPressed(
const BackendGui* gui)
162#ifdef TGUI_SYSTEM_MACOS
163 return gui->isKeyboardModifierPressed(Event::KeyModifier::System);
165 return gui->isKeyboardModifierPressed(Event::KeyModifier::Control);
171 TGUI_NODISCARD
inline bool isKeyPressCopy(
const Event::KeyEvent& event)
173#ifdef TGUI_SYSTEM_MACOS
174 return (event.code ==
Event::KeyboardKey::C) && !
event.control && !
event.alt && !
event.shift &&
event.system;
176 return (event.code ==
Event::KeyboardKey::C) &&
event.control && !
event.alt && !
event.shift && !
event.system;
182 TGUI_NODISCARD
inline bool isKeyPressCut(
const Event::KeyEvent& event)
184#ifdef TGUI_SYSTEM_MACOS
185 return (event.code ==
Event::KeyboardKey::X) && !
event.control && !
event.alt && !
event.shift &&
event.system;
187 return (event.code ==
Event::KeyboardKey::X) &&
event.control && !
event.alt && !
event.shift && !
event.system;
193 TGUI_NODISCARD
inline bool isKeyPressPaste(
const Event::KeyEvent& event)
195#ifdef TGUI_SYSTEM_MACOS
196 return (event.code ==
Event::KeyboardKey::V) && !
event.control && !
event.alt && !
event.shift &&
event.system;
198 return (event.code ==
Event::KeyboardKey::V) &&
event.control && !
event.alt && !
event.shift && !
event.system;
204 TGUI_NODISCARD
inline bool isKeyPressSelectAll(
const Event::KeyEvent& event)
206#ifdef TGUI_SYSTEM_MACOS
207 return (event.code ==
Event::KeyboardKey::A) && !
event.control && !
event.alt && !
event.shift &&
event.system;
209 return (event.code ==
Event::KeyboardKey::A) &&
event.control && !
event.alt && !
event.shift && !
event.system;
215 TGUI_NODISCARD
inline bool isKeyPressMoveCaretLeft(
const Event::KeyEvent& event)
222 TGUI_NODISCARD
inline bool isKeyPressMoveCaretRight(
const Event::KeyEvent& event)
229 TGUI_NODISCARD
inline bool isKeyPressMoveCaretWordBegin(
const Event::KeyEvent& event)
231#ifdef TGUI_SYSTEM_MACOS
240 TGUI_NODISCARD
inline bool isKeyPressMoveCaretWordEnd(
const Event::KeyEvent& event)
242#ifdef TGUI_SYSTEM_MACOS
251 TGUI_NODISCARD
inline bool isKeyPressMoveCaretUp(
const Event::KeyEvent& event)
253#ifdef TGUI_SYSTEM_MACOS
263 TGUI_NODISCARD
inline bool isKeyPressMoveCaretDown(
const Event::KeyEvent& event)
265#ifdef TGUI_SYSTEM_MACOS
275 TGUI_NODISCARD
inline bool isKeyPressMoveCaretLineStart(
const Event::KeyEvent& event)
277#ifdef TGUI_SYSTEM_MACOS
286 TGUI_NODISCARD
inline bool isKeyPressMoveCaretLineEnd(
const Event::KeyEvent& event)
288#ifdef TGUI_SYSTEM_MACOS
297 TGUI_NODISCARD
inline bool isKeyPressMoveCaretDocumentBegin(
const Event::KeyEvent& event)
299#ifdef TGUI_SYSTEM_MACOS
309 TGUI_NODISCARD
inline bool isKeyPressMoveCaretDocumentEnd(
const Event::KeyEvent& event)
311#ifdef TGUI_SYSTEM_MACOS
321 TGUI_NODISCARD
inline bool isKeyPressDeleteWordLeft(
const Event::KeyEvent& event)
323#ifdef TGUI_SYSTEM_MACOS
332 TGUI_NODISCARD
inline bool isKeyPressDeleteWordRight(
const Event::KeyEvent& event)
334#ifdef TGUI_SYSTEM_MACOS
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
TGUI_API std::shared_ptr< Backend > getBackend()
Returns the global backend.
@ X
The X key.
Definition Event.hpp:67
@ Down
Down arrow.
Definition Event.hpp:118
@ C
The C key.
Definition Event.hpp:46
@ Up
Up arrow.
Definition Event.hpp:117
@ V
The V key.
Definition Event.hpp:65
@ A
The A key.
Definition Event.hpp:44
@ End
The End key.
Definition Event.hpp:107
@ Home
The Home key.
Definition Event.hpp:108
@ Right
Right arrow.
Definition Event.hpp:116
@ Left
Left arrow.
Definition Event.hpp:115
@ Backspace
The Backspace key.
Definition Event.hpp:103
@ Delete
The Delete key.
Definition Event.hpp:110