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)
106#ifndef TGUI_REMOVE_DEPRECATED_CODE
107 TGUI_DEPRECATED(
"Use isShiftPressed(gui) instead") TGUI_NODISCARD inline
bool isShiftPressed()
109 TGUI_IGNORE_DEPRECATED_WARNINGS_START
110 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::Shift);
111 TGUI_IGNORE_DEPRECATED_WARNINGS_END
116 TGUI_NODISCARD
inline bool isShiftPressed(
const BackendGui* gui)
118 return gui->isKeyboardModifierPressed(Event::KeyModifier::Shift);
122#ifndef TGUI_REMOVE_DEPRECATED_CODE
123 TGUI_DEPRECATED(
"Use BackendGui::stopTextInput instead") inline
void closeVirtualKeyboard()
125 TGUI_IGNORE_DEPRECATED_WARNINGS_START
127 TGUI_IGNORE_DEPRECATED_WARNINGS_END
132 TGUI_NODISCARD
inline bool isMultiselectModifierPressed(
const Event::KeyEvent& event)
134#ifdef TGUI_SYSTEM_MACOS
137 return event.control;
142#ifndef TGUI_REMOVE_DEPRECATED_CODE
143 TGUI_DEPRECATED(
"Use isMultiselectModifierPressed(gui) instead") TGUI_NODISCARD inline
bool isMultiselectModifierPressed()
145 TGUI_IGNORE_DEPRECATED_WARNINGS_START
146#ifdef TGUI_SYSTEM_MACOS
147 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::System);
149 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::Control);
151 TGUI_IGNORE_DEPRECATED_WARNINGS_END
156 TGUI_NODISCARD
inline bool isMultiselectModifierPressed(
const BackendGui* gui)
158#ifdef TGUI_SYSTEM_MACOS
159 return gui->isKeyboardModifierPressed(Event::KeyModifier::System);
161 return gui->isKeyboardModifierPressed(Event::KeyModifier::Control);
167 TGUI_NODISCARD
inline bool isKeyPressCopy(
const Event::KeyEvent& event)
169#ifdef TGUI_SYSTEM_MACOS
170 return (event.code ==
Event::KeyboardKey::C) && !
event.control && !
event.alt && !
event.shift &&
event.system;
172 return (event.code ==
Event::KeyboardKey::C) &&
event.control && !
event.alt && !
event.shift && !
event.system;
178 TGUI_NODISCARD
inline bool isKeyPressCut(
const Event::KeyEvent& event)
180#ifdef TGUI_SYSTEM_MACOS
181 return (event.code ==
Event::KeyboardKey::X) && !
event.control && !
event.alt && !
event.shift &&
event.system;
183 return (event.code ==
Event::KeyboardKey::X) &&
event.control && !
event.alt && !
event.shift && !
event.system;
189 TGUI_NODISCARD
inline bool isKeyPressPaste(
const Event::KeyEvent& event)
191#ifdef TGUI_SYSTEM_MACOS
192 return (event.code ==
Event::KeyboardKey::V) && !
event.control && !
event.alt && !
event.shift &&
event.system;
194 return (event.code ==
Event::KeyboardKey::V) &&
event.control && !
event.alt && !
event.shift && !
event.system;
200 TGUI_NODISCARD
inline bool isKeyPressSelectAll(
const Event::KeyEvent& event)
202#ifdef TGUI_SYSTEM_MACOS
203 return (event.code ==
Event::KeyboardKey::A) && !
event.control && !
event.alt && !
event.shift &&
event.system;
205 return (event.code ==
Event::KeyboardKey::A) &&
event.control && !
event.alt && !
event.shift && !
event.system;
211 TGUI_NODISCARD
inline bool isKeyPressMoveCaretLeft(
const Event::KeyEvent& event)
218 TGUI_NODISCARD
inline bool isKeyPressMoveCaretRight(
const Event::KeyEvent& event)
225 TGUI_NODISCARD
inline bool isKeyPressMoveCaretWordBegin(
const Event::KeyEvent& event)
227#ifdef TGUI_SYSTEM_MACOS
236 TGUI_NODISCARD
inline bool isKeyPressMoveCaretWordEnd(
const Event::KeyEvent& event)
238#ifdef TGUI_SYSTEM_MACOS
247 TGUI_NODISCARD
inline bool isKeyPressMoveCaretUp(
const Event::KeyEvent& event)
249#ifdef TGUI_SYSTEM_MACOS
259 TGUI_NODISCARD
inline bool isKeyPressMoveCaretDown(
const Event::KeyEvent& event)
261#ifdef TGUI_SYSTEM_MACOS
271 TGUI_NODISCARD
inline bool isKeyPressMoveCaretLineStart(
const Event::KeyEvent& event)
273#ifdef TGUI_SYSTEM_MACOS
282 TGUI_NODISCARD
inline bool isKeyPressMoveCaretLineEnd(
const Event::KeyEvent& event)
284#ifdef TGUI_SYSTEM_MACOS
293 TGUI_NODISCARD
inline bool isKeyPressMoveCaretDocumentBegin(
const Event::KeyEvent& event)
295#ifdef TGUI_SYSTEM_MACOS
305 TGUI_NODISCARD
inline bool isKeyPressMoveCaretDocumentEnd(
const Event::KeyEvent& event)
307#ifdef TGUI_SYSTEM_MACOS
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
TGUI_API std::shared_ptr< Backend > getBackend()
Returns the global backend.