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;
89 virtual ~AWindowBase();
114 template<aui::invocable<const _<AView>&> Callback>
116 for (
auto view = mFocusedView.lock(); view;) {
119 auto container = _cast<AViewContainer>(view);
120 if (!container)
return;
121 view = container->focusChainTarget();
137 return *getWindowManagerImpl();
139 template<
typename WindowManager,
typename... Args>
140 static void setWindowManager(Args&&... args) {
141 destroyWindowManager();
143 getWindowManagerImpl() = std::make_unique<WindowManager>(std::forward<Args>(args)...);
145 static void destroyWindowManager() {
146 getWindowManagerImpl() =
nullptr;
149 const _unique<IRenderingContext>& getRenderingContext()
const {
150 return mRenderingContext;
154 BeforeFrameQueue& beforeFrameQueue() noexcept {
155 return mBeforeFrameQueue;
172 return mFocusedView.lock();
175 void setFocusedView(
const _<AView>& view);
176 void updateFocusChain();
179 void onPointerMove(glm::vec2 pos,
const APointerMoveEvent& event)
override;
181 void closeOverlappingSurfacesOnClick();
183 bool isFocused()
const {
188 const glm::ivec2& getMousePos()
const {
192 void onKeyDown(AInput::Key key)
override;
195 virtual void focusNextView();
196 virtual void flagRedraw();
199 currentWindowStorage() =
this;
230 const glm::ivec2&
size,
231 bool closeOnClick =
true) {
236 default:
return std::nullopt;
238 },
size, closeOnClick);
252 const glm::ivec2&
size,
253 bool closeOnClick =
true) {
256 for (
unsigned index = 0; ; ++index) {
257 auto optionalPosition = positionFactory(index);
258 if (optionalPosition) {
270 tmp->mParentWindow =
this;
271 tmp->mCloseOnClick = closeOnClick;
272 mOverlappingSurfaces << tmp;
277 closeOverlappingSurfaceImpl(surface);
281 void onFocusLost()
override;
282 void render(ARenderContext context)
override;
283 void applyGeometryToChildren()
override;
298 virtual bool onDragEnter(
const ADragNDrop::EnterEvent& event);
299 virtual void onDragLeave();
300 virtual void onDragDrop(
const ADragNDrop::DropEvent& event);
305 void requestShowTouchscreenKeyboard();
310 void requestHideTouchscreenKeyboard();
316 bool shouldDisplayHoverAnimations()
const;
318 void onScroll(
const AScrollEvent& event)
override;
323 virtual void forceUpdateCursor();
325 bool onGesture(
const glm::ivec2& origin,
const AGestureEvent& event)
override;
337 return mLastCapturedFps;
340 void setTouchscreenKeyboardPolicy(ATouchscreenKeyboardPolicy policy)
noexcept {
341 mKeyboardPolicy = policy;
369 void markMinContentSizeInvalid()
override;
393 bool mIsFocused =
true;
405 bool mPerformDoubleClickOnPointerRelease =
false;
407 std::chrono::milliseconds mLastButtonPressedTime = std::chrono::milliseconds::zero();
409 glm::vec2 mLastPosition = {0, 0};
411 _unique<IRenderingContext> mRenderingContext;
421 virtual void createDevtoolsWindow();
423 static _unique<AWindowManager>& getWindowManagerImpl();
425 virtual float fetchDpiFromSystem()
const;
427 virtual void showTouchscreenKeyboardImpl();
428 virtual void hideTouchscreenKeyboardImpl();
433 void processTouchscreenKeyboardRequest();
437 float mDpiRatio = 1.f;
438 ScalingParams mScalingParams;
440 BeforeFrameQueue mBeforeFrameQueue;
442 ATouchscreenKeyboardPolicy mKeyboardPolicy = ATouchscreenKeyboardPolicy::SHOWN_IF_NEEDED;
444 enum class KeyboardRequest {
450 KeyboardRequest mKeyboardRequestedState = KeyboardRequest::NO_OP;
452 glm::ivec2 mMousePos = {0, 0};
453 ASet<_<AOverlappingSurface>> mOverlappingSurfaces;
456 APointerIndex pointer;
457 ATouchScroller scroller;
463 ASmallVector<Scroll, 10 > mScrolls;
465 std::chrono::time_point<std::chrono::high_resolution_clock> mLastTimeFpsCaptured = std::chrono::high_resolution_clock::now();
466 size_t mFpsCounter = 0;
467 size_t mLastCapturedFps = 0;
472 AVector<glm::vec2> moves;
473 AOptional<glm::vec2> release;
475 AMap<APointerIndex, ShowTouches> mShowTouches;
486#define AUI_ASSERT_UI_THREAD_ONLY() { AUI_ASSERTX((AWindow::current() ? AThread::current() == AWindow::current()->getThread() : AThread::current() == getThread()), "this method should be used in ui thread only."); }
494#define AUI_ASSERT_WORKER_THREAD_ONLY() { AUI_ASSERTX(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:32
Definition AOverlappingSurface.h:19
void onPointerPressed(const APointerPressedEvent &event) override
Called on pointer (mouse) released event.
Definition AViewContainerBase.cpp:289
bool onGesture(const glm::ivec2 &origin, const AGestureEvent &event) override
Definition AViewContainerBase.cpp:551
void onPointerMove(glm::vec2 pos, const APointerMoveEvent &event) override
Handles pointer hover events.
Definition AViewContainerBase.cpp:244
void markPixelDataInvalid(ARect< int > invalidArea) override
A view requests to redraw it and passes it's coords relative to this.
Definition AViewContainerBase.cpp:645
void onPointerReleased(const APointerReleasedEvent &event) override
Called on pointer (mouse) released event.
Definition AViewContainerBase.cpp:329
void onScroll(const AScrollEvent &event) override
Definition AViewContainerBase.cpp:361
void render(ARenderContext context) override
Draws this AView. Noone should call this function except rendering routine.
Definition AViewContainerBase.cpp:235
auto size() const
Size, including content area, border and padding.
Definition AView.h:114
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:165
bool mForceUpdateCursorGuard
If true, AWindowBase::forceUpdateCursor takes no action.
Definition AWindowBase.h:403
bool isPreventingClickOnPointerRelease() const noexcept
Definition AWindowBase.h:107
virtual void blockUserInput(bool blockUserInput=true)
Enables or disables user input for this window.
Definition AWindowBase.cpp:518
AOptional< bool > mPreventClickOnPointerRelease
Definition AWindowBase.h:398
virtual _< AOverlappingSurface > createOverlappingSurfaceImpl(const glm::ivec2 &position, const glm::ivec2 &size)=0
void iterateOverFocusChain(Callback &&callback)
Iterates over focus chain, from parent to child.
Definition AWindowBase.h:115
_< AOverlappingSurface > createOverlappingSurface(const glm::ivec2 &position, const glm::ivec2 &size, bool closeOnClick=true)
Definition AWindowBase.h:229
virtual unsigned frameMillis() const noexcept=0
Returns previous frame's rendering duration in millis.
emits touchscreenKeyboardHidden
On touch screen keyboard hide.
Definition AWindowBase.h:386
aui::lazy< Profiling > & profiling()
Get profiling settings (mutable).
Definition AWindowBase.h:365
void preventClickOnPointerRelease()
Prevents click action on upcoming pointer release.
Definition AWindowBase.cpp:563
size_t getFps()
Definition AWindowBase.h:336
_< AOverlappingSurface > createOverlappingSurface(const std::function< AOptional< glm::ivec2 >(unsigned)> &positionFactory, const glm::ivec2 &size, bool closeOnClick=true)
Definition AWindowBase.h:251
emits touchscreenKeyboardShown
On touch screen keyboard show.
Definition AWindowBase.h:380
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:330
void setScalingParams(ScalingParams params)
Sets scaling params.
Definition AWindowBase.cpp:70
Definition AWindowManager.h:23
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:178
Definition UITestCase.h:26
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:348
Basic easy-to-use property implementation containing T.
Definition AProperty.h:156
Axis aligned 2D rectangle.
Definition ARect.h:24
Profiling (debugging) settings for this window.
Definition AWindowBase.h:48
AProperty< bool > highlightRedrawRequests
Highlight redraw requests.
Definition AWindowBase.h:57
AProperty< _weak< AView > > highlightView
View to highlight.
Definition AWindowBase.h:52
AProperty< bool > breakpointOnMarkMinContentSizeInvalid
When set to true, the next time window's markMinContentSizeInvalid, debugger is invoked....
Definition AWindowBase.h:69
AProperty< bool > renderToTextureDecay
Visually displays render-to-texture caching by decreasing brightness of pixels that didn't updated in...
Definition AWindowBase.h:63
Definition AWindowBase.h:344
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:353
float scalingFactor
DPI ratio will be multiplied by this factor.
Definition AWindowBase.h:348
Definition IRenderingContext.h:38
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:51
A value that initializes when accessed for the first time.
Definition values.h:182
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:377