From e7988b9fa28116e770b7fae77d87ef1ca7cf03d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Thu, 14 May 2020 12:01:17 +0200 Subject: [PATCH] [apps/round_cursor_view] Add comment about flaw in algorithm --- apps/shared/round_cursor_view.cpp | 33 ++++++++++++++++++++++++++++-- kandinsky/include/kandinsky/size.h | 3 +++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/apps/shared/round_cursor_view.cpp b/apps/shared/round_cursor_view.cpp index 10b14e86b..74661c644 100644 --- a/apps/shared/round_cursor_view.cpp +++ b/apps/shared/round_cursor_view.cpp @@ -66,11 +66,40 @@ bool RoundCursorView::eraseCursorIfPossible() { return false; } // Erase the cursor - KDColor cursorWorkingBuffer[Dots::LargeDotDiameter*Dots::LargeDotDiameter]; + KDColor cursorWorkingBuffer[k_cursorSize * k_cursorSize]; KDContext * ctx = KDIonContext::sharedContext(); ctx->setOrigin(currentFrame.origin()); ctx->setClippingRect(currentFrame); - ctx->fillRectWithPixels(KDRect(0,0,k_cursorSize, k_cursorSize), m_underneathPixelBuffer, cursorWorkingBuffer); + KDSize cursorSize = KDSize(k_cursorSize, k_cursorSize); + + /* We assert that the visible frame is not cropped (indeed a cursor is always + * fully inside the window, thanks to panToMakeCursorVisible). Otherwise, we + * would need to change this algorithm. + * + * +---+ + * | |<- frame m_underneathPixelBuffer: +---+ + * +----+---+--------+ |000| + * | |xxx| |<- parentVisibleFrame |xxx| + * | +---+ | +---+ + * | | + * +-----------------+ + * + * +---+ + * |xxx|: absoluteVisibleFrame + * +---+ + * + * What we would draw with the current algorithm: + * +---+ + * | |<- frame + * +----+---+--------+ + * | |000| |<- parentVisibleFrame + * | +---+ | + * | | + * +-----------------+ + * + * */ + assert(currentFrame.size() == cursorSize); + ctx->fillRectWithPixels(KDRect(0, 0, cursorSize), m_underneathPixelBuffer, cursorWorkingBuffer); // TODO Restore the context to previous values? return true; } diff --git a/kandinsky/include/kandinsky/size.h b/kandinsky/include/kandinsky/size.h index 970b4f071..875719de4 100644 --- a/kandinsky/include/kandinsky/size.h +++ b/kandinsky/include/kandinsky/size.h @@ -9,6 +9,9 @@ public: m_width(width), m_height(height) {} constexpr KDCoordinate width() const { return m_width; } constexpr KDCoordinate height() const { return m_height; } + bool operator==(const KDSize &other) const { + return m_width == other.width() && m_height == other.height(); + } private: KDCoordinate m_width; KDCoordinate m_height;