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();
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;
283 void applyGeometryToChildren()
override;
299 virtual void onDragLeave();
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;
394 bool mIsFocused =
true;
406 bool mPerformDoubleClickOnPointerRelease =
false;
408 std::chrono::milliseconds mLastButtonPressedTime = std::chrono::milliseconds::zero();
410 glm::vec2 mLastPosition = {0, 0};
412 _unique<IRenderingContext> mRenderingContext;
422 virtual void createDevtoolsWindow();
424 static _unique<AWindowManager>& getWindowManagerImpl();
426 virtual float fetchDpiFromSystem()
const;
428 virtual void showTouchscreenKeyboardImpl();
429 virtual void hideTouchscreenKeyboardImpl();
434 void processTouchscreenKeyboardRequest();
438 float mDpiRatio = 1.f;
439 ScalingParams mScalingParams;
441 BeforeFrameQueue mBeforeFrameQueue;
443 ATouchscreenKeyboardPolicy mKeyboardPolicy = ATouchscreenKeyboardPolicy::SHOWN_IF_NEEDED;
445 enum class KeyboardRequest {
451 KeyboardRequest mKeyboardRequestedState = KeyboardRequest::NO_OP;
453 glm::ivec2 mMousePos = {0, 0};
454 ASet<_<AOverlappingSurface>> mOverlappingSurfaces;
457 APointerIndex pointer;
458 ATouchScroller scroller;
464 ASmallVector<Scroll, 10 > mScrolls;
466 std::chrono::time_point<std::chrono::high_resolution_clock> mLastTimeFpsCaptured = std::chrono::high_resolution_clock::now();
467 size_t mFpsCounter = 0;
468 size_t mLastCapturedFps = 0;
473 AVector<glm::vec2> moves;
474 AOptional<glm::vec2> release;
476 AMap<APointerIndex, ShowTouches> mShowTouches;
487#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."); }
495#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
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:404
bool isPreventingClickOnPointerRelease() const noexcept
Definition AWindowBase.h:107
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:399
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:115
_< AOverlappingSurface > createOverlappingSurface(const glm::ivec2 &position, const glm::ivec2 &size, bool closeOnClick=true)
Definition AWindowBase.h:229
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:387
aui::lazy< Profiling > & profiling()
Get profiling settings (mutable).
Definition AWindowBase.h:365
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:336
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:251
emits touchscreenKeyboardShown
On touch screen keyboard show.
Definition AWindowBase.h:381
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:330
void setScalingParams(ScalingParams params)
Sets scaling params.
Definition AWindowManager.h:23
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
Definition UITestCase.h:26
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:572
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: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: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