18#include <AUI/View/AViewContainer.h>
19#include "AUI/Performance/APerformanceFrame.h"
20#include "AUI/Performance/APerformanceSection.h"
21#include "AWindowManager.h"
22#include "AOverlappingSurface.h"
23#include "ADragNDrop.h"
24#include "AUI/Util/ATouchScroller.h"
25#include "ATouchscreenKeyboardPolicy.h"
33class API_AUI_VIEWS AWindowBase:
public AViewContainer {
34 friend class SoftwareRenderer;
35 friend class IPlatformAbstraction;
90 virtual ~AWindowBase();
115 template<aui::invocable<const _<AView>&> Callback>
117 for (
auto view = mFocusedView.lock(); view;) {
120 auto container = _cast<AViewContainer>(view);
121 if (!container)
return;
122 view = container->focusChainTarget();
138 return *getWindowManagerImpl();
140 template<
typename WindowManager,
typename... Args>
141 static void setWindowManager(Args&&... args) {
142 destroyWindowManager();
144 getWindowManagerImpl() = std::make_unique<WindowManager>(std::forward<Args>(args)...);
146 static void destroyWindowManager() {
147 getWindowManagerImpl() =
nullptr;
150 const _unique<IRenderingContext>& getRenderingContext()
const {
151 return mRenderingContext;
155 BeforeFrameQueue& beforeFrameQueue() noexcept {
156 return mBeforeFrameQueue;
173 return mFocusedView.lock();
176 void setFocusedView(
const _<AView>& view);
177 void updateFocusChain();
182 void closeOverlappingSurfacesOnClick();
184 bool isFocused()
const {
189 const glm::ivec2& getMousePos()
const {
193 void onKeyDown(AInput::Key key)
override;
195#pragma clang diagnostic push
196#pragma ide diagnostic ignored "HidingNonVirtualFunction"
200#pragma clang diagnostic pop
202 virtual void focusNextView();
203 virtual void flagRedraw();
206 currentWindowStorage() =
this;
237 const glm::ivec2&
size,
238 bool closeOnClick =
true) {
243 default:
return std::nullopt;
245 },
size, closeOnClick);
259 const glm::ivec2&
size,
260 bool closeOnClick =
true) {
263 for (
unsigned index = 0; ; ++index) {
264 auto optionalPosition = positionFactory(index);
265 if (optionalPosition) {
277 tmp->mParentWindow =
this;
278 tmp->mCloseOnClick = closeOnClick;
279 mOverlappingSurfaces << tmp;
284 closeOverlappingSurfaceImpl(surface);
288 void onFocusLost()
override;
290 void applyGeometryToChildren()
override;
306 virtual void onDragLeave();
332 bool onGesture(
const glm::ivec2& origin,
const AGestureEvent& event)
override;
344 return mLastCapturedFps;
347 void setTouchscreenKeyboardPolicy(ATouchscreenKeyboardPolicy policy)
noexcept {
348 mKeyboardPolicy = policy;
376 void markMinContentSizeInvalid()
override;
401 bool mIsFocused =
true;
413 bool mPerformDoubleClickOnPointerRelease =
false;
415 std::chrono::milliseconds mLastButtonPressedTime = std::chrono::milliseconds::zero();
417 glm::vec2 mLastPosition = {0, 0};
419 _unique<IRenderingContext> mRenderingContext;
429 virtual void createDevtoolsWindow();
431 static _unique<AWindowManager>& getWindowManagerImpl();
433 virtual float fetchDpiFromSystem()
const;
435 virtual void showTouchscreenKeyboardImpl();
436 virtual void hideTouchscreenKeyboardImpl();
441 void processTouchscreenKeyboardRequest();
445 float mDpiRatio = 1.f;
446 ScalingParams mScalingParams;
448 BeforeFrameQueue mBeforeFrameQueue;
450 ATouchscreenKeyboardPolicy mKeyboardPolicy = ATouchscreenKeyboardPolicy::SHOWN_IF_NEEDED;
452 enum class KeyboardRequest {
458 KeyboardRequest mKeyboardRequestedState = KeyboardRequest::NO_OP;
460 glm::ivec2 mMousePos = {0, 0};
461 ASet<_<AOverlappingSurface>> mOverlappingSurfaces;
464 APointerIndex pointer;
465 ATouchScroller scroller;
471 ASmallVector<Scroll, 10 > mScrolls;
473 std::chrono::time_point<std::chrono::high_resolution_clock> mLastTimeFpsCaptured = std::chrono::high_resolution_clock::now();
474 size_t mFpsCounter = 0;
475 size_t mLastCapturedFps = 0;
480 AVector<glm::vec2> moves;
481 AOptional<glm::vec2> release;
483 AMap<APointerIndex, ShowTouches> mShowTouches;
494#define AUI_ASSERT_UI_THREAD_ONLY() { AUI_ASSERTX(AWindow::current() == nullptr || AThread::current() == AWindow::current()->getThread(), "this method should be used in ui thread only."); }
502#define AUI_ASSERT_WORKER_THREAD_ONLY() { AUI_ASSERTX(AWindow::current() == nullptr || AThread::current() != AWindow::current()->getThread(), "this method should be used in worker thread only."); }
Universal thread-safe message (callback) queue implementation.
Definition AMessageQueue.h:29
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition AOptional.h:33
Definition AOverlappingSurface.h:19
auto size() const
Size, including content area, border and padding.
Definition AView.h:114
void redraw()
Request window manager to redraw this AView.
glm::ivec2 getSize() const noexcept
Size, including content area, border and padding.
Definition AView.h:217
auto position() const
Top left corner's position relative to top left corner's position of the parent AView.
Definition AView.h:102
Definition AWindowBase.h:33
float getDpiRatio()
Returns current dpi ratio.
Definition AWindowBase.h:166
bool mForceUpdateCursorGuard
If true, AWindowBase::forceUpdateCursor takes no action.
Definition AWindowBase.h:411
bool isPreventingClickOnPointerRelease() const noexcept
Definition AWindowBase.h:108
virtual bool onDragEnter(const ADragNDrop::EnterEvent &event)
Called when the user holds a drag-n-drop object over the window.
AOptional< bool > mPreventClickOnPointerRelease
Definition AWindowBase.h:406
void markPixelDataInvalid(ARect< int > invalidArea) override
A view requests to redraw it and passes it's coords relative to this.
virtual _< AOverlappingSurface > createOverlappingSurfaceImpl(const glm::ivec2 &position, const glm::ivec2 &size)=0
bool onGesture(const glm::ivec2 &origin, const AGestureEvent &event) override
void iterateOverFocusChain(Callback &&callback)
Iterates over focus chain, from parent to child.
Definition AWindowBase.h:116
_< AOverlappingSurface > createOverlappingSurface(const glm::ivec2 &position, const glm::ivec2 &size, bool closeOnClick=true)
Definition AWindowBase.h:236
virtual void blockUserInput(bool blockUserInput=true)
Enables or disables user input for this window.
virtual unsigned frameMillis() const noexcept=0
Returns previous frame's rendering duration in millis.
void onPointerPressed(const APointerPressedEvent &event) override
Called on pointer (mouse) released event.
emits touchscreenKeyboardHidden
On touch screen keyboard hide.
Definition AWindowBase.h:394
aui::lazy< Profiling > & profiling()
Get profiling settings (mutable).
Definition AWindowBase.h:372
void preventClickOnPointerRelease()
Prevents click action on upcoming pointer release.
void onPointerReleased(const APointerReleasedEvent &event) override
Called on pointer (mouse) released event.
bool shouldDisplayHoverAnimations() const
Determines whether views should display hover animations.
size_t getFps()
Definition AWindowBase.h:343
void onPointerMove(glm::vec2 pos, const APointerMoveEvent &event) override
Handles pointer hover events.
void requestHideTouchscreenKeyboard()
On a mobile touchscreen device, requests hiding system virtual keyboard.
void onScroll(const AScrollEvent &event) override
void render(ARenderContext context) override
Draws this AView. Noone should call this function except rendering routine.
void requestShowTouchscreenKeyboard()
On a mobile touchscreen device, requests system virtual keyboard.
_< AOverlappingSurface > createOverlappingSurface(const std::function< AOptional< glm::ivec2 >(unsigned)> &positionFactory, const glm::ivec2 &size, bool closeOnClick=true)
Definition AWindowBase.h:258
emits touchscreenKeyboardShown
On touch screen keyboard show.
Definition AWindowBase.h:388
virtual void forceUpdateCursor()
Updates cursor by triggering onPointerMove on the same position (mMousePos).
static constexpr std::chrono::milliseconds DOUBLECLICK_MAX_DURATION
double click will be captured only if time elapsed since the previous click is less than DOUBLECLICK_...
Definition AWindowBase.h:337
void setScalingParams(ScalingParams params)
Sets scaling params.
Definition AWindowManager.h:21
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
Definition UITestCase.h:26
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:577
Definition ADragNDrop.h:67
Definition ADragNDrop.h:62
Pointing method move event.
Definition APointerMoveEvent.h:21
Pointing method press event.
Definition APointerPressedEvent.h:21
Pointing method press event.
Definition APointerReleasedEvent.h:19
Basic easy-to-use property implementation containing T.
Definition AProperty.h:30
Axis aligned 2D rectangle.
Definition ARect.h:24
Render context passed to AView::render.
Definition ARenderContext.h:43
Profiling (debugging) settings for this window.
Definition AWindowBase.h:49
AProperty< bool > highlightRedrawRequests
Highlight redraw requests.
Definition AWindowBase.h:58
AProperty< _weak< AView > > highlightView
View to highlight.
Definition AWindowBase.h:53
AProperty< bool > breakpointOnMarkMinContentSizeInvalid
When set to true, the next time window's markMinContentSizeInvalid, debugger is invoked....
Definition AWindowBase.h:70
AProperty< bool > renderToTextureDecay
Visually displays render-to-texture caching by decreasing brightness of pixels that didn't updated in...
Definition AWindowBase.h:64
Definition AWindowBase.h:351
AOptional< glm::uvec2 > minimalWindowSizeDp
If set, DPI ratio will be adjusted to be small enough for proper displaying layout of given size.
Definition AWindowBase.h:360
float scalingFactor
DPI ratio will be multiplied by this factor.
Definition AWindowBase.h:355
Definition IRenderingContext.h:38
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:52
A value that initializes when accessed for the first time.
Definition values.h:184
static _< T > fake(T *raw)
Creates fake shared pointer to T* raw with empty destructor, which does nothing. It's useful when som...
Definition SharedPtrTypes.h:429