From 2e44c36997c9ff0680e12cdfe2fa3691efb3bf03 Mon Sep 17 00:00:00 2001 From: JJones780 Date: Mon, 18 Feb 2019 01:13:51 -0700 Subject: [PATCH 1/9] Make LayoutMapper, row and column sizes persist within Layout ( preparing for quick pageposition lookup ). --- src/gui/Layout.cpp | 55 ++++++++++++++++++++-------------------- src/gui/Layout.h | 19 +++++++++++++- src/gui/LayoutMapper.cpp | 48 +++++++++++------------------------ src/gui/LayoutMapper.h | 49 +++++++++++++++-------------------- 4 files changed, 81 insertions(+), 90 deletions(-) diff --git a/src/gui/Layout.cpp b/src/gui/Layout.cpp index 0a42f911..ae349ccc 100644 --- a/src/gui/Layout.cpp +++ b/src/gui/Layout.cpp @@ -6,7 +6,7 @@ #include "pageposition/PagePositionHandler.h" #include "widgets/XournalWidget.h" #include "gui/scroll/ScrollHandling.h" -#include "gui/LayoutMapper.h" + /** @@ -199,23 +199,22 @@ void Layout::layoutPages() Settings* settings = this->view->getControl()->getSettings(); // obtain rows, cols, paired and layout from view settings - LayoutMapper mapper(len, settings); + mapper.configureFromSettings(len, settings); // get from mapper (some may have changed to accomodate paired setting etc.) bool isPairedPages = mapper.getPairedPages(); - int rows = mapper.getRows(); - int columns = mapper.getColumns(); + int pagesOffset = mapper.getFirstPageOffset(); + this->rows = mapper.getRows(); + this->columns = mapper.getColumns(); + - int sizeCol[columns]; - // Needs dynamic initialisation, else clang will not compile... - memset(sizeCol, 0, columns * sizeof(int)); + this->sizeCol.assign(this->columns,0); //new size, clear to 0's - int sizeRow[rows]; - memset(sizeRow, 0, rows * sizeof(int)); + this->sizeRow.assign(this->rows,0); - for (int r = 0; r < rows; r++) + for (int r = 0; r < this->rows; r++) { - for (int c = 0; c < columns; c++) + for (int c = 0; c < this->columns; c++) { int k = mapper.map(c, r); if (k >= 0) @@ -223,13 +222,13 @@ void Layout::layoutPages() XojPageView* v = this->view->viewPages[k]; - if (sizeCol[c] < v->getDisplayWidth()) + if (this->sizeCol[c] < v->getDisplayWidth()) { - sizeCol[c] = v->getDisplayWidth(); + this->sizeCol[c] = v->getDisplayWidth(); } - if (sizeRow[r] < v->getDisplayHeight()) + if (this->sizeRow[r] < v->getDisplayHeight()) { - sizeRow[r] = v->getDisplayHeight(); + this->sizeRow[r] = v->getDisplayHeight(); } } @@ -259,7 +258,7 @@ void Layout::layoutPages() int minRequiredWidth = XOURNAL_PADDING_BETWEEN * (columns-1); for( int c = 0 ; c< columns; c++ ) { - minRequiredWidth += sizeCol[c]; + minRequiredWidth += this->sizeCol[c]; } int centeringXBorder = ( visibleWidth - minRequiredWidth )/2; // this will center if all pages fit on screen. @@ -268,7 +267,7 @@ void Layout::layoutPages() int minRequiredHeight = XOURNAL_PADDING_BETWEEN * (rows-1); for( int r = 0 ; r< rows; r++ ) { - minRequiredHeight += sizeRow[r]; + minRequiredHeight += this->sizeRow[r]; } int centeringYBorder = ( visibleHeight - minRequiredHeight )/2; // this will center if all pages fit on screen vertically. @@ -286,9 +285,9 @@ void Layout::layoutPages() // Iterate over ALL possible rows and columns. //We don't know which page, if any, is to be displayed in each row, column - ask the mapper object! //Then assign that page coordinates with center, left or right justify within row,column grid cell as required. - for (int r = 0; r < rows; r++) + for (int r = 0; r < this->rows; r++) { - for (int c = 0; c < columns; c++) + for (int c = 0; c < this->columns; c++) { int pageAtRowCol = mapper.map(c, r); @@ -301,7 +300,7 @@ void Layout::layoutPages() int paddingLeft; int paddingRight; int columnPadding = 0; - columnPadding = (sizeCol[c] - vDisplayWidth); + columnPadding = (this->sizeCol[c] - vDisplayWidth); if (isPairedPages && len > 1) { @@ -335,24 +334,24 @@ void Layout::layoutPages() } else { - x += sizeCol[c] + XOURNAL_PADDING_BETWEEN; + x += this->sizeCol[c] + XOURNAL_PADDING_BETWEEN; } } x = borderX; - y += sizeRow[r] + XOURNAL_PADDING_BETWEEN; + y += this->sizeRow[r] + XOURNAL_PADDING_BETWEEN; } - int totalWidth = borderX * 2 + XOURNAL_PADDING_BETWEEN * (columns-1); - for (int c = 0; c < columns; c++) + int totalWidth = borderX * 2 + XOURNAL_PADDING_BETWEEN * (this->columns-1); + for (int c = 0; c < this->columns; c++) { - totalWidth += sizeCol[c]; // this includes paddingLeft and paddingRight + totalWidth += this->sizeCol[c]; // this includes paddingLeft and paddingRight } - int totalHeight = borderY * 2 + XOURNAL_PADDING_BETWEEN * (rows-1); - for (int r = 0; r < rows; r++) + int totalHeight = borderY * 2 + XOURNAL_PADDING_BETWEEN * (this->rows-1); + for (int r = 0; r < this->rows; r++) { - totalHeight += sizeRow[r]; + totalHeight += this->sizeRow[r]; } diff --git a/src/gui/Layout.h b/src/gui/Layout.h index 53f58e20..27818b7d 100644 --- a/src/gui/Layout.h +++ b/src/gui/Layout.h @@ -16,10 +16,13 @@ #include +#include "gui/LayoutMapper.h" + class XojPageView; class XournalView; class ScrollHandling; + /** * @brief The Layout manager for the XournalWidget * @@ -91,7 +94,9 @@ private: private: XOJ_TYPE_ATTRIB; - XournalView* view = NULL; + XournalView* view = NULL; + + LayoutMapper mapper; ScrollHandling* scrollHandling = NULL; @@ -108,4 +113,16 @@ private: */ int layoutWidth = 0; int layoutHeight = 0; + + + /** + *The following are useful for locating page at a pixel location + */ + + int rows; + int columns; + + std::vector sizeCol; + std::vector sizeRow; + }; diff --git a/src/gui/LayoutMapper.cpp b/src/gui/LayoutMapper.cpp index 6537573c..14c29470 100644 --- a/src/gui/LayoutMapper.cpp +++ b/src/gui/LayoutMapper.cpp @@ -1,40 +1,17 @@ #include "gui/LayoutMapper.h" -/** - * compileLayout - assemble bitflags to create basic layouts - */ -LayoutType compileLayout(bool isVertical, bool isRightToLeft, bool isBottomToTop) -{ - int type = isVertical ? LayoutBitFlags::Vertically : 0; - type |= isRightToLeft ? LayoutBitFlags::RightToLeft : 0; - type |= isBottomToTop ? LayoutBitFlags::BottomToTop : 0; - - return (LayoutType) type; +LayoutMapper::LayoutMapper(){ + this->actualPages = 0; + this->possiblePages = 0; + this->rows = 0; + this->cols = 0; + this->layoutType = Horizontal; + } -LayoutMapper::LayoutMapper(int pages, int numRows, int numCols, bool useRows, LayoutType type, bool isPaired, - int firstPageOffset) -{ - - XOJ_INIT_TYPE(LayoutMapper); - - layoutMapperInit(pages, numRows, numCols, useRows, type, isPaired, firstPageOffset); - -} -LayoutMapper::LayoutMapper(int pages, int numRows, int numCols, bool useRows, bool isVertical, bool isRightToLeft, - bool isBottomToTop, bool isPaired, int firstPageOffset) -{ - - XOJ_INIT_TYPE(LayoutMapper); - - LayoutType type = compileLayout(isVertical, isRightToLeft, isBottomToTop); - - layoutMapperInit(pages, numRows, numCols, useRows, type, isPaired, firstPageOffset); -} - -LayoutMapper::LayoutMapper(int numPages, Settings* settings) +void LayoutMapper::configureFromSettings(int numPages, Settings* settings) { XOJ_INIT_TYPE(LayoutMapper); @@ -55,8 +32,13 @@ LayoutMapper::LayoutMapper(int numPages, Settings* settings) pairsOffset = 0; } - LayoutType type = compileLayout(isVertical, isRightToLeft, isBottomToTop); - layoutMapperInit(pages, numRows, numCols, fixRows, type, isPairedPages, pairsOffset); + //assemble bitflags for LayoutType + int type = isVertical ? LayoutBitFlags::Vertically : 0; + type |= isRightToLeft ? LayoutBitFlags::RightToLeft : 0; + type |= isBottomToTop ? LayoutBitFlags::BottomToTop : 0; + + + layoutMapperInit(pages, numRows, numCols, fixRows, (LayoutType)type, isPairedPages, pairsOffset); } LayoutMapper::~LayoutMapper() diff --git a/src/gui/LayoutMapper.h b/src/gui/LayoutMapper.h index 13929ded..a9765b5a 100644 --- a/src/gui/LayoutMapper.h +++ b/src/gui/LayoutMapper.h @@ -41,47 +41,40 @@ class LayoutMapper { public: /** - * Initialize mapper of LayoutType with number of pages and of fixed rows or columns + * LayoutMapper + * + * Create a bare mapper to be configured before use. + */ + LayoutMapper(); + + + /** + * configureFromSettings + * configure layoutMapper from user settings settings + * * @param pages The number of pages in the document - * @param numRows Number of rows ( used if useRows ) - * @param numCols Number of columns ( used if !useRows ) - * @param useRows use pages/rows to recalculate cols else recalculate rows - * @param type Specify LayoutType desired. Options include: Horizontal, Vertical, - * @param isPaired Display pages in pairs including offset - * @param firstPageOffset Pages to offset - usually one or zero in order to pair up properly + * @param settings The Settings from which users settings are obtained */ - LayoutMapper(int pages, int numRows, int numCols, bool useRows, LayoutType type, bool isPaired, - int firstPageOffset); + + void configureFromSettings(int numPages, Settings* settings); + + virtual ~LayoutMapper(); +private: /** - * LayoutMapper with broken out layout arguments + * layoutMapperInit * + * Initialize mapper of LayoutType with number of pages and of fixed rows or columns * @param pages The number of pages in the document * @param numRows Number of rows ( used if useRows ) * @param numCols Number of columns ( used if !useRows ) * @param useRows use pages/rows to recalculate cols else recalculate rows - * @param isVertical lay out pages by filling columns first - * @param isRightToLeft go from right to left - * @param isBottomToTop go from bottom to top + * @param type Specify LayoutType desired. Options include: Horizontal, Vertical, * @param isPaired Display pages in pairs including offset * @param firstPageOffset Pages to offset - usually one or zero in order to pair up properly */ - LayoutMapper(int pages, int numRows, int numCols, bool useRows, bool isVertical, bool isRightToLeft, - bool isBottomToTop, bool isPaired, int firstPageOffset); - - /** - * LayoutMapper using view to get settings - * - * @param pages The number of pages in the document - * @param settings The Settings from which users settings are obtained - */ - LayoutMapper(int pages, Settings* settings); - - virtual ~LayoutMapper(); -private: - // called by constructors void layoutMapperInit(int pages, int numRows, int numCols, bool useRows, LayoutType type, bool paired, - int firstPageOffset); + int firstPageOffset); public: /** From 7f6d4b73a34da220ec234269c73e015e53126e1c Mon Sep 17 00:00:00 2001 From: JJones780 Date: Sun, 24 Feb 2019 18:47:05 -0700 Subject: [PATCH 2/9] add simple getViewAt() functionality to Layout. --- src/control/tools/EditSelection.cpp | 8 +-- src/gui/Layout.cpp | 78 ++++++++++++++++++++++++++ src/gui/Layout.h | 8 +++ src/gui/LayoutMapper.cpp | 5 +- src/gui/inputdevices/InputSequence.cpp | 6 +- 5 files changed, 96 insertions(+), 9 deletions(-) diff --git a/src/control/tools/EditSelection.cpp b/src/control/tools/EditSelection.cpp index 2332c662..b9bdaaf0 100644 --- a/src/control/tools/EditSelection.cpp +++ b/src/control/tools/EditSelection.cpp @@ -17,6 +17,7 @@ #include "undo/SizeUndoAction.h" #include "undo/UndoRedoHandler.h" #include "util/GtkColorWrapper.h" +#include "gui/Layout.h" #include #include @@ -562,17 +563,16 @@ void EditSelection::mouseMove(double x, double y) XojPageView* EditSelection::getPageViewUnderCursor() { XOJ_CHECK_TYPE(EditSelection); - - PagePositionHandler* pp = this->view->getXournal()->getPagePositionHandler(); double zoom = view->getXournal()->getZoom(); - //get grabbing hand position double hx = this->view->getX() + (this->x + this->relMousePosX)*zoom; double hy = this->view->getY() + (this->y + this->relMousePosY)*zoom; - XojPageView* v = pp->getViewAt(hx,hy); + + Layout* layout = gtk_xournal_get_layout(this->view->getXournal()->getWidget()); + XojPageView* v = layout->getViewAt(hx,hy); return v; } diff --git a/src/gui/Layout.cpp b/src/gui/Layout.cpp index ae349ccc..11b81260 100644 --- a/src/gui/Layout.cpp +++ b/src/gui/Layout.cpp @@ -413,4 +413,82 @@ void Layout::ensureRectIsVisible(int x, int y, int width, int height) } +XojPageView* Layout::getViewAt(int x, int y) +{ + + XOJ_CHECK_TYPE(Layout); + + int r; + int rTotalPixels = 0; + int c; + int cTotalPixels = 0; + int numRows = mapper.getRows(); + int numCols = mapper.getColumns(); + + for( r = 0; r < numRows; r++) + { + rTotalPixels += sizeRow[r] + XOURNAL_PADDING_BETWEEN; + if ( y < rTotalPixels) break; // found region + } + + for( c = 0; c < numCols; c++) + { + cTotalPixels += sizeCol[c] +XOURNAL_PADDING_BETWEEN; + if ( x < cTotalPixels) break; + } + + + + if ( c > numCols || r > numRows ) + { + return NULL; //not found + } + else + { + int page = mapper.map(c,r); + //this->view->viewPages[1]; + if ( page>=0 && this->view->viewPages[page]->containsPoint(x,y,false) ) + { + return this->view->viewPages[page]; + } + else + { + return NULL; + } + + + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} diff --git a/src/gui/Layout.h b/src/gui/Layout.h index 27818b7d..77a43bf7 100644 --- a/src/gui/Layout.h +++ b/src/gui/Layout.h @@ -87,6 +87,14 @@ public: */ void updateCurrentPage(); + + + /** + * Return the pageview containing co-ordinates. + */ + XojPageView* getViewAt(int x, int y); + + private: void checkScroll(GtkAdjustment* adjustment, double& lastScroll); void setLayoutSize(int width, int height); diff --git a/src/gui/LayoutMapper.cpp b/src/gui/LayoutMapper.cpp index 14c29470..3b59a639 100644 --- a/src/gui/LayoutMapper.cpp +++ b/src/gui/LayoutMapper.cpp @@ -2,6 +2,9 @@ LayoutMapper::LayoutMapper(){ + + XOJ_INIT_TYPE(LayoutMapper); + this->actualPages = 0; this->possiblePages = 0; this->rows = 0; @@ -13,7 +16,7 @@ LayoutMapper::LayoutMapper(){ void LayoutMapper::configureFromSettings(int numPages, Settings* settings) { - XOJ_INIT_TYPE(LayoutMapper); + XOJ_CHECK_TYPE(LayoutMapper); int pages = numPages; diff --git a/src/gui/inputdevices/InputSequence.cpp b/src/gui/inputdevices/InputSequence.cpp index 4438122c..53283bd9 100644 --- a/src/gui/inputdevices/InputSequence.cpp +++ b/src/gui/inputdevices/InputSequence.cpp @@ -139,10 +139,8 @@ XojPageView* InputSequence::getPageAtCurrentPosition() double x = this->x + xournal->x; double y = this->y + xournal->y; - - PagePositionHandler* pph = xournal->view->getPagePositionHandler(); - - return pph->getViewAt(x, y, xournal->pagePositionCache); + + return xournal->layout->getViewAt(x,y); } /** From 4b3e4046061ac9109894693f0086f482162588b2 Mon Sep 17 00:00:00 2001 From: JJones780 Date: Sat, 9 Mar 2019 23:57:41 -0700 Subject: [PATCH 3/9] Cache last getViewAt result. --- src/gui/Layout.cpp | 16 ++++++++++++++-- src/gui/Layout.h | 5 +++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/gui/Layout.cpp b/src/gui/Layout.cpp index 11b81260..57582e5b 100644 --- a/src/gui/Layout.cpp +++ b/src/gui/Layout.cpp @@ -53,6 +53,8 @@ Layout::Layout(XournalView* view, ScrollHandling* scrollHandling) layout->updateCurrentPage(); layout->scrollHandling->scrollChanged(); }), this); + + this->lastGetViewAtPage = 0; lastScrollHorizontal = gtk_adjustment_get_value(scrollHandling->getHorizontal()); lastScrollVertical = gtk_adjustment_get_value(scrollHandling->getVertical()); @@ -195,7 +197,9 @@ void Layout::layoutPages() XOJ_CHECK_TYPE(Layout); int len = this->view->viewPagesLen; - + + this->lastGetViewAtPage = len; // invalidate cache index. + Settings* settings = this->view->getControl()->getSettings(); // obtain rows, cols, paired and layout from view settings @@ -418,6 +422,12 @@ XojPageView* Layout::getViewAt(int x, int y) XOJ_CHECK_TYPE(Layout); + //try cached result first + if ( this->lastGetViewAtPage < this->view->viewPagesLen && this->view->viewPages[this->lastGetViewAtPage]->containsPoint(x,y,false) ) + { + return this->view->viewPages[this->lastGetViewAtPage]; + } + int r; int rTotalPixels = 0; int c; @@ -449,8 +459,10 @@ XojPageView* Layout::getViewAt(int x, int y) int page = mapper.map(c,r); //this->view->viewPages[1]; if ( page>=0 && this->view->viewPages[page]->containsPoint(x,y,false) ) + { - return this->view->viewPages[page]; + this->lastGetViewAtPage = page; + return this->view->viewPages[page]; } else { diff --git a/src/gui/Layout.h b/src/gui/Layout.h index 77a43bf7..97670f37 100644 --- a/src/gui/Layout.h +++ b/src/gui/Layout.h @@ -133,4 +133,9 @@ private: std::vector sizeCol; std::vector sizeRow; + /** + * cache the last GetViewAt() page# + */ + int lastGetViewAtPage; + }; From 33c94caf8b7a53a7208e1c7cc84c3c58d1df6b3e Mon Sep 17 00:00:00 2001 From: JJones780 Date: Thu, 28 Feb 2019 00:05:32 -0700 Subject: [PATCH 4/9] Add binary search - TIME vs linear search. Pre-accumulate sizeRow/Col for searches. --- src/gui/Layout.cpp | 127 +++++++++++++++++++++++++-------------------- src/gui/Layout.h | 1 + 2 files changed, 72 insertions(+), 56 deletions(-) diff --git a/src/gui/Layout.cpp b/src/gui/Layout.cpp index 57582e5b..34005a87 100644 --- a/src/gui/Layout.cpp +++ b/src/gui/Layout.cpp @@ -7,7 +7,15 @@ #include "widgets/XournalWidget.h" #include "gui/scroll/ScrollHandling.h" +#define COMPARE_LAYOUT_BINARY_VS_LINEAR_SEARCH +#ifdef COMPARE_LAYOUT_BINARY_VS_LINEAR_SEARCH + + #include + #include + typedef std::chrono::high_resolution_clock Clock; + +#endif /** * Padding outside the pages, including shadow @@ -346,21 +354,28 @@ void Layout::layoutPages() } - int totalWidth = borderX * 2 + XOURNAL_PADDING_BETWEEN * (this->columns-1); + + int totalWidth = borderX; for (int c = 0; c < this->columns; c++) { - totalWidth += this->sizeCol[c]; // this includes paddingLeft and paddingRight + totalWidth += this->sizeCol[c] + XOURNAL_PADDING_BETWEEN; + this->sizeCol[c] = totalWidth; //accumulated for use by getViewAt() } + totalWidth += borderX - XOURNAL_PADDING_BETWEEN; - int totalHeight = borderY * 2 + XOURNAL_PADDING_BETWEEN * (this->rows-1); + + int totalHeight = borderY; for (int r = 0; r < this->rows; r++) { - totalHeight += this->sizeRow[r]; + totalHeight += this->sizeRow[r]+ XOURNAL_PADDING_BETWEEN; + this->sizeRow[r] = totalHeight; } + totalHeight += borderY - XOURNAL_PADDING_BETWEEN; this->setLayoutSize(totalWidth, totalHeight); this->view->pagePosition->update(this->view->viewPages, len, totalHeight); + } @@ -429,78 +444,78 @@ XojPageView* Layout::getViewAt(int x, int y) } int r; - int rTotalPixels = 0; int c; - int cTotalPixels = 0; - int numRows = mapper.getRows(); - int numCols = mapper.getColumns(); + int numRows = this->mapper.getRows(); + int numCols = this->mapper.getColumns(); + + #ifdef COMPARE_LAYOUT_BINARY_VS_LINEAR_SEARCH + auto t1 = Clock::now(); + #endif + + + + auto rit = std::lower_bound( this->sizeRow.begin(), this->sizeRow.end(), y); //binary search + r = rit - this->sizeRow.begin(); //get index + + auto cit = std::lower_bound( this->sizeCol.begin(), this->sizeCol.end(), x); + c = cit - this->sizeCol.begin(); + + #ifdef COMPARE_LAYOUT_BINARY_VS_LINEAR_SEARCH + auto t2 = Clock::now(); + #endif + + /* test against linear search: */ for( r = 0; r < numRows; r++) { - rTotalPixels += sizeRow[r] + XOURNAL_PADDING_BETWEEN; - if ( y < rTotalPixels) break; // found region + if ( y <= this->sizeRow[r] ) break; // found region } - + for( c = 0; c < numCols; c++) { - cTotalPixels += sizeCol[c] +XOURNAL_PADDING_BETWEEN; - if ( x < cTotalPixels) break; + if ( x <= this->sizeCol[c]) break; } + //*/ + + + #ifdef COMPARE_LAYOUT_BINARY_VS_LINEAR_SEARCH + auto t3 = Clock::now(); + + double binarySearchtime = std::chrono::duration_cast(t2 - t1).count(); + double linearSearchTime = std::chrono::duration_cast(t3 - t2).count(); + double diff = linearSearchTime - binarySearchtime ; + if ( diff < 0) + { + + std::cout << "binarySearch SLOWER by: " + << -diff + << " nanoseconds" << std::endl; + } + else + { + std::cout << "binarySearch faster by: " + << diff + << " nanoseconds" << std::endl; + + } + #endif + - - - if ( c > numCols || r > numRows ) - { - return NULL; //not found - } - else + if ( c <= numCols && r <= numRows ) { - int page = mapper.map(c,r); - //this->view->viewPages[1]; + int page = this->mapper.map(c,r); + if ( page>=0 && this->view->viewPages[page]->containsPoint(x,y,false) ) { this->lastGetViewAtPage = page; return this->view->viewPages[page]; } - else - { - return NULL; - } - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + return NULL; } diff --git a/src/gui/Layout.h b/src/gui/Layout.h index 97670f37..c3b09a28 100644 --- a/src/gui/Layout.h +++ b/src/gui/Layout.h @@ -91,6 +91,7 @@ public: /** * Return the pageview containing co-ordinates. + * */ XojPageView* getViewAt(int x, int y); From cbe0ebd55b3ea1e2c28f3025c4bc1d82d1d30169 Mon Sep 17 00:00:00 2001 From: JJones780 Date: Wed, 13 Mar 2019 00:31:43 -0600 Subject: [PATCH 5/9] also compare linear search from previous, calculated aproximation, previous -2 oneway , previous -2 directed --- src/gui/Layout.cpp | 305 +++++++++++++++++++++++++++++++++++++++------ src/gui/Layout.h | 3 + 2 files changed, 270 insertions(+), 38 deletions(-) diff --git a/src/gui/Layout.cpp b/src/gui/Layout.cpp index 34005a87..4c180c50 100644 --- a/src/gui/Layout.cpp +++ b/src/gui/Layout.cpp @@ -7,15 +7,12 @@ #include "widgets/XournalWidget.h" #include "gui/scroll/ScrollHandling.h" -#define COMPARE_LAYOUT_BINARY_VS_LINEAR_SEARCH - -#ifdef COMPARE_LAYOUT_BINARY_VS_LINEAR_SEARCH - +// TODO: REMOVE AFTER TEST #include #include typedef std::chrono::high_resolution_clock Clock; -#endif + /** * Padding outside the pages, including shadow @@ -38,6 +35,18 @@ const int XOURNAL_ROOM_FOR_SHADOW = 3; const int XOURNAL_PADDING_BETWEEN = 15; +// TODO: REMOVE AFTER TEST +double binarySearchtime = 0; +double linearSearchTime = 0; +double fromLastLinearSearchTime = 0; +double fromCalcLinearSearchTime = 0; +double fromB4LastLinearSearchTime = 0; +double fromB4LastLinearBackSearchTime = 0; +double plotindex = 0; + + + + Layout::Layout(XournalView* view, ScrollHandling* scrollHandling) : view(view), scrollHandling(scrollHandling) @@ -63,6 +72,8 @@ Layout::Layout(XournalView* view, ScrollHandling* scrollHandling) }), this); this->lastGetViewAtPage = 0; + this->lastGetViewRow = 0; + this->lastGetViewCol = 0; lastScrollHorizontal = gtk_adjustment_get_value(scrollHandling->getHorizontal()); lastScrollVertical = gtk_adjustment_get_value(scrollHandling->getVertical()); @@ -207,6 +218,8 @@ void Layout::layoutPages() int len = this->view->viewPagesLen; this->lastGetViewAtPage = len; // invalidate cache index. + this->lastGetViewRow = 0; + this->lastGetViewCol = 0; Settings* settings = this->view->getControl()->getSettings(); @@ -436,8 +449,8 @@ XojPageView* Layout::getViewAt(int x, int y) { XOJ_CHECK_TYPE(Layout); - - //try cached result first + +// //try cached result first if ( this->lastGetViewAtPage < this->view->viewPagesLen && this->view->viewPages[this->lastGetViewAtPage]->containsPoint(x,y,false) ) { return this->view->viewPages[this->lastGetViewAtPage]; @@ -448,9 +461,9 @@ XojPageView* Layout::getViewAt(int x, int y) int numRows = this->mapper.getRows(); int numCols = this->mapper.getColumns(); - #ifdef COMPARE_LAYOUT_BINARY_VS_LINEAR_SEARCH - auto t1 = Clock::now(); - #endif + + auto t1 = Clock::now(); // TODO: REMOVE AFTER TEST ************* BINARY SEARCH *************** + @@ -461,55 +474,271 @@ XojPageView* Layout::getViewAt(int x, int y) auto cit = std::lower_bound( this->sizeCol.begin(), this->sizeCol.end(), x); c = cit - this->sizeCol.begin(); - #ifdef COMPARE_LAYOUT_BINARY_VS_LINEAR_SEARCH - auto t2 = Clock::now(); - #endif + + auto t2 = Clock::now(); // TODO: REMOVE AFTER TEST ************* LINEAR SEARCH: From 0 *************** + /* test against linear search: */ - for( r = 0; r < numRows; r++) + int r1; + for( r1 = 0; r1 < numRows; r1++) + { + if ( y <= this->sizeRow[r1] ) break; // found region + } + + int c1; + for( c1 = 0; c1 < numCols; c1++) + { + if ( x <= this->sizeCol[c1]) break; + } + //*/ + + + auto t3 = Clock::now(); // TODO: REMOVE AFTER TEST ************* LINEAR SEARCH: From Previous *************** + + + /* Linear Search from last position: */ + + // Rows: + int r2 = this->lastGetViewRow; + if( r2 > 0 && y <= this->sizeRow[r2] ) //search lower + { + for( r2--; r2>=0; r2--) + { + if ( y > this->sizeRow[r2] ) + { + break; // past region + } + } + r2++; + } + else + { + for( ; r2 < numRows; r2++) + { + if ( y <= this->sizeRow[r2] ) break; // found region + } + + } + + + //Columns: + int c2 = this->lastGetViewCol; + if( c2 >0 && x <= this->sizeCol[c2] ) //search lower + { + for( c2--; c2>=0; c2--) + { + if ( x > this->sizeCol[c2] ) + { + break; // past region + } + } + c2++; + } + else { - if ( y <= this->sizeRow[r] ) break; // found region + for( ; c2 < numCols; c2++) + { + if ( x <= this->sizeCol[c2] ) break; // found region + } + } + + auto t4 = Clock::now(); // TODO: REMOVE AFTER TEST ************* LINEAR SEARCH: From Approximation - would be bad with irregular sized pages - bi-directional *************** - for( c = 0; c < numCols; c++) + + /* Linear Search from calculated position: */ + + // Rows: + int r3 = y / ( this->sizeRow[numRows-1]/numRows); + int calcR = r3; + if( r3 > 0 && y <= this->sizeRow[r3] ) //search lower { - if ( x <= this->sizeCol[c]) break; + for( r3--; r3>=0; r3--) + { + if ( y > this->sizeRow[r3] ) + { + break; // past region + } + } + r3++; + } + else + { + for( ; r3 < numRows; r3++) + { + if ( y <= this->sizeRow[r3] ) break; // found region + } + + } + + + //Columns: + int c3 = x / ( this->sizeCol[numCols-1]/numCols); + int calcC = c3; + if( c3 >0 && x <= this->sizeCol[c3] ) //search lower + { + for( c3--; c3>=0; c3--) + { + if ( x > this->sizeCol[c3] ) + { + break; // past region + } + } + c3++; + } + else + { + for( ; c3 < numCols; c3++) + { + if ( x <= this->sizeCol[c3] ) break; // found region + } + + } + + + + auto t5 = Clock::now(); // TODO: REMOVE AFTER TEST ************* LINEAR SEARCH: From previous - 2 forward only *************** + + + /* test against linear search: */ + int r4 = MAX(0, this->lastGetViewRow - 3); + if ( y > this->sizeRow[r4] ) //search forward + { + r4++; + for( ; r4 < numRows; r4++) + { + if ( y <= this->sizeRow[r4] ) break; // found region + } + } + else + { + for( r4 = 0; r4 < numRows; r4++) + { + if ( y <= this->sizeRow[r4] ) break; // found region + } + } + + + int c4 = MAX(0, this->lastGetViewCol - 3); + if ( x > this->sizeCol[c4]) //search forward + { + c4++; + for( ; c4 < numCols; c4++) + { + if ( x <= this->sizeCol[c4]) break; + } + } + else + { + for( c4 = 0; c4 < numCols; c4++) + { + if ( x <= this->sizeCol[c4]) break; + } } //*/ + + + auto t6 = Clock::now(); // TODO: REMOVE AFTER TEST ************* LINEAR SEARCH: From Previous - Bidriectional *************** + + /* Linear Search from last position: */ - #ifdef COMPARE_LAYOUT_BINARY_VS_LINEAR_SEARCH - auto t3 = Clock::now(); + // Rows: + int r5 = MAX(0, this->lastGetViewRow - 1); + if( r5 > 0 && y <= this->sizeRow[r5] ) //search lower + { + for( r5--; r5>=0; r5--) + { + if ( y > this->sizeRow[r5] ) + { + break; // past region + } + } + r5++; + } + else + { + for( ; r5 < numRows; r5++) + { + if ( y <= this->sizeRow[r5] ) break; // found region + } + + } + + + //Columns: + int c5 = MAX(0, this->lastGetViewCol - 1); + if( c5 >0 && x <= this->sizeCol[c5] ) //search lower + { + for( c5--; c5>=0; c5--) + { + if ( x > this->sizeCol[c5] ) + { + break; // past region + } + } + c5++; + } + else + { + for( ; c5 < numCols; c5++) + { + if ( x <= this->sizeCol[c5] ) break; // found region + } + + } + + + + + + + // TODO: REMOVE BELOW AFTER TEST + auto t7 = Clock::now(); - double binarySearchtime = std::chrono::duration_cast(t2 - t1).count(); - double linearSearchTime = std::chrono::duration_cast(t3 - t2).count(); - double diff = linearSearchTime - binarySearchtime ; - if ( diff < 0) - { - - std::cout << "binarySearch SLOWER by: " - << -diff - << " nanoseconds" << std::endl; - } - else - { - std::cout << "binarySearch faster by: " - << diff - << " nanoseconds" << std::endl; + binarySearchtime += std::chrono::duration_cast(t2 - t1).count(); + linearSearchTime += std::chrono::duration_cast(t3 - t2).count(); + fromLastLinearSearchTime += std::chrono::duration_cast(t4 - t3).count(); + fromCalcLinearSearchTime += std::chrono::duration_cast(t5 - t4).count(); + fromB4LastLinearSearchTime += std::chrono::duration_cast(t6 - t5).count(); + fromB4LastLinearBackSearchTime += std::chrono::duration_cast(t7 - t6).count(); - } - #endif + string cOK = ( c == c1 && c == c2 && c == c3 && c == c4 && c == c5)? "cOK" : "cBAD"; + string rOK = ( r == r1 && r == r2 && r == r3 && r == r4 && r == r5)? "rOK" : "rBAD"; + if( plotindex == 0 ) + { + std::clog << " index \t binary \tlinear \t fromlast \t fromCalc \t fromB4Last \t fromB4LastBiDir" << std::endl; + } + std::clog << plotindex++ << '\t' + << binarySearchtime << '\t' + << linearSearchTime << '\t' + << fromLastLinearSearchTime << "\t" + << fromCalcLinearSearchTime << "\t" + << fromB4LastLinearSearchTime << "\t" + << fromB4LastLinearBackSearchTime + << "\t\t" + << c << '=' << c1 << '=' << c2 << '=' << c3 << '=' << c4 << '=' << c5 <<" \t" << cOK << "\t" + << r << '=' << r1 << '=' << r2 << '=' << r3 << '=' << r4 << '=' << r5 << " \t" << rOK << "\t" + << " \t Last " << this->lastGetViewCol << ":" << this->lastGetViewRow << "\t\t" + << " \t Calc " << calcC << ":" << calcR + << std::endl; + + c = c3; + r = r3; + + if ( c <= numCols && r <= numRows ) { int page = this->mapper.map(c,r); + this->lastGetViewAtPage = page; + this->lastGetViewRow = r; + this->lastGetViewCol = c; if ( page>=0 && this->view->viewPages[page]->containsPoint(x,y,false) ) - { - this->lastGetViewAtPage = page; return this->view->viewPages[page]; } diff --git a/src/gui/Layout.h b/src/gui/Layout.h index c3b09a28..059a2885 100644 --- a/src/gui/Layout.h +++ b/src/gui/Layout.h @@ -139,4 +139,7 @@ private: */ int lastGetViewAtPage; + int lastGetViewRow; + int lastGetViewCol; + }; From b8130bd11a2a6b7d50b0ffe9319cec86e4a66a69 Mon Sep 17 00:00:00 2001 From: JJones780 Date: Sun, 24 Mar 2019 18:29:08 -0600 Subject: [PATCH 6/9] Cleanup. Using search: linear directional from last. Searches Linear from before last and linear from last were slightly faster but I feel directional is more robust. Binary search was by far the slowest - assumingly due to the overhead and relatively small search range. --- src/gui/Layout.cpp | 306 ++++++--------------------------------------- src/gui/Layout.h | 8 +- 2 files changed, 43 insertions(+), 271 deletions(-) diff --git a/src/gui/Layout.cpp b/src/gui/Layout.cpp index 4c180c50..42dba16c 100644 --- a/src/gui/Layout.cpp +++ b/src/gui/Layout.cpp @@ -7,13 +7,6 @@ #include "widgets/XournalWidget.h" #include "gui/scroll/ScrollHandling.h" -// TODO: REMOVE AFTER TEST - #include - #include - typedef std::chrono::high_resolution_clock Clock; - - - /** * Padding outside the pages, including shadow */ @@ -35,17 +28,6 @@ const int XOURNAL_ROOM_FOR_SHADOW = 3; const int XOURNAL_PADDING_BETWEEN = 15; -// TODO: REMOVE AFTER TEST -double binarySearchtime = 0; -double linearSearchTime = 0; -double fromLastLinearSearchTime = 0; -double fromCalcLinearSearchTime = 0; -double fromB4LastLinearSearchTime = 0; -double fromB4LastLinearBackSearchTime = 0; -double plotindex = 0; - - - Layout::Layout(XournalView* view, ScrollHandling* scrollHandling) : view(view), @@ -71,9 +53,9 @@ Layout::Layout(XournalView* view, ScrollHandling* scrollHandling) layout->scrollHandling->scrollChanged(); }), this); - this->lastGetViewAtPage = 0; - this->lastGetViewRow = 0; - this->lastGetViewCol = 0; + this->lastGetViewAtPageNum = 0; + this->lastGetViewAtRow = 0; + this->lastGetViewAtCol = 0; lastScrollHorizontal = gtk_adjustment_get_value(scrollHandling->getHorizontal()); lastScrollVertical = gtk_adjustment_get_value(scrollHandling->getVertical()); @@ -217,9 +199,9 @@ void Layout::layoutPages() int len = this->view->viewPagesLen; - this->lastGetViewAtPage = len; // invalidate cache index. - this->lastGetViewRow = 0; - this->lastGetViewCol = 0; + this->lastGetViewAtPageNum = len; // invalidate cache index. + this->lastGetViewAtRow = 0; + this->lastGetViewAtCol = 0; Settings* settings = this->view->getControl()->getSettings(); @@ -228,7 +210,6 @@ void Layout::layoutPages() // get from mapper (some may have changed to accomodate paired setting etc.) bool isPairedPages = mapper.getPairedPages(); - int pagesOffset = mapper.getFirstPageOffset(); this->rows = mapper.getRows(); this->columns = mapper.getColumns(); @@ -450,292 +431,83 @@ XojPageView* Layout::getViewAt(int x, int y) XOJ_CHECK_TYPE(Layout); -// //try cached result first - if ( this->lastGetViewAtPage < this->view->viewPagesLen && this->view->viewPages[this->lastGetViewAtPage]->containsPoint(x,y,false) ) + //try cached result first + if ( this->lastGetViewAtPageNum < this->view->viewPagesLen && this->view->viewPages[this->lastGetViewAtPageNum]->containsPoint(x,y,false) ) { - return this->view->viewPages[this->lastGetViewAtPage]; + return this->view->viewPages[this->lastGetViewAtPageNum]; } int r; int c; int numRows = this->mapper.getRows(); int numCols = this->mapper.getColumns(); - - - auto t1 = Clock::now(); // TODO: REMOVE AFTER TEST ************* BINARY SEARCH *************** - - - - - auto rit = std::lower_bound( this->sizeRow.begin(), this->sizeRow.end(), y); //binary search - r = rit - this->sizeRow.begin(); //get index - - - auto cit = std::lower_bound( this->sizeCol.begin(), this->sizeCol.end(), x); - c = cit - this->sizeCol.begin(); - - - auto t2 = Clock::now(); // TODO: REMOVE AFTER TEST ************* LINEAR SEARCH: From 0 *************** - - - /* test against linear search: */ - int r1; - for( r1 = 0; r1 < numRows; r1++) - { - if ( y <= this->sizeRow[r1] ) break; // found region - } - - int c1; - for( c1 = 0; c1 < numCols; c1++) - { - if ( x <= this->sizeCol[c1]) break; - } - //*/ - - - auto t3 = Clock::now(); // TODO: REMOVE AFTER TEST ************* LINEAR SEARCH: From Previous *************** - - - /* Linear Search from last position: */ - - // Rows: - int r2 = this->lastGetViewRow; - if( r2 > 0 && y <= this->sizeRow[r2] ) //search lower - { - for( r2--; r2>=0; r2--) - { - if ( y > this->sizeRow[r2] ) - { - break; // past region - } - } - r2++; - } - else - { - for( ; r2 < numRows; r2++) - { - if ( y <= this->sizeRow[r2] ) break; // found region - } - - } - - - //Columns: - int c2 = this->lastGetViewCol; - if( c2 >0 && x <= this->sizeCol[c2] ) //search lower - { - for( c2--; c2>=0; c2--) - { - if ( x > this->sizeCol[c2] ) - { - break; // past region - } - } - c2++; - } - else - { - for( ; c2 < numCols; c2++) - { - if ( x <= this->sizeCol[c2] ) break; // found region - } - - } - - - auto t4 = Clock::now(); // TODO: REMOVE AFTER TEST ************* LINEAR SEARCH: From Approximation - would be bad with irregular sized pages - bi-directional *************** - - - /* Linear Search from calculated position: */ - - // Rows: - int r3 = y / ( this->sizeRow[numRows-1]/numRows); - int calcR = r3; - if( r3 > 0 && y <= this->sizeRow[r3] ) //search lower - { - for( r3--; r3>=0; r3--) - { - if ( y > this->sizeRow[r3] ) - { - break; // past region - } - } - r3++; - } - else - { - for( ; r3 < numRows; r3++) - { - if ( y <= this->sizeRow[r3] ) break; // found region - } - - } - - - //Columns: - int c3 = x / ( this->sizeCol[numCols-1]/numCols); - int calcC = c3; - if( c3 >0 && x <= this->sizeCol[c3] ) //search lower - { - for( c3--; c3>=0; c3--) - { - if ( x > this->sizeCol[c3] ) - { - break; // past region - } - } - c3++; - } - else - { - for( ; c3 < numCols; c3++) - { - if ( x <= this->sizeCol[c3] ) break; // found region - } - - } - - - - auto t5 = Clock::now(); // TODO: REMOVE AFTER TEST ************* LINEAR SEARCH: From previous - 2 forward only *************** + +// Binary Search ... too much overhead makes this a slower option. Leave here for checking against. +// auto rit = std::lower_bound( this->sizeRow.begin(), this->sizeRow.end(), y); //binary search +// int rb = rit - this->sizeRow.begin(); //get index +// +// +// auto cit = std::lower_bound( this->sizeCol.begin(), this->sizeCol.end(), x); +// int cb = cit - this->sizeCol.begin(); - /* test against linear search: */ - int r4 = MAX(0, this->lastGetViewRow - 3); - if ( y > this->sizeRow[r4] ) //search forward - { - r4++; - for( ; r4 < numRows; r4++) - { - if ( y <= this->sizeRow[r4] ) break; // found region - } - } - else - { - for( r4 = 0; r4 < numRows; r4++) - { - if ( y <= this->sizeRow[r4] ) break; // found region - } - } - - int c4 = MAX(0, this->lastGetViewCol - 3); - if ( x > this->sizeCol[c4]) //search forward - { - c4++; - for( ; c4 < numCols; c4++) - { - if ( x <= this->sizeCol[c4]) break; - } - } - else - { - for( c4 = 0; c4 < numCols; c4++) - { - if ( x <= this->sizeCol[c4]) break; - } - } - //*/ - - - auto t6 = Clock::now(); // TODO: REMOVE AFTER TEST ************* LINEAR SEARCH: From Previous - Bidriectional *************** - /* Linear Search from last position: */ + /* Linear Up or Down Search from last position: */ // Rows: - int r5 = MAX(0, this->lastGetViewRow - 1); - if( r5 > 0 && y <= this->sizeRow[r5] ) //search lower + r = MAX(0, this->lastGetViewAtRow - 1); + if( r > 0 && y <= this->sizeRow[r] ) //search lower { - for( r5--; r5>=0; r5--) + for( r--; r>=0; r--) { - if ( y > this->sizeRow[r5] ) + if ( y > this->sizeRow[r] ) { - break; // past region + break; // past region - it's back up one } } - r5++; + r++; } - else + else //search higher { - for( ; r5 < numRows; r5++) + for( ; r < numRows; r++) { - if ( y <= this->sizeRow[r5] ) break; // found region + if ( y <= this->sizeRow[r] ) break; // found region } } - //Columns: - int c5 = MAX(0, this->lastGetViewCol - 1); - if( c5 >0 && x <= this->sizeCol[c5] ) //search lower + //Now for columns: + c = MAX(0, this->lastGetViewAtCol - 1); + if( c >0 && x <= this->sizeCol[c] ) //search lower { - for( c5--; c5>=0; c5--) + for( c--; c>=0; c--) { - if ( x > this->sizeCol[c5] ) + if ( x > this->sizeCol[c] ) { break; // past region } } - c5++; + c++; } else { - for( ; c5 < numCols; c5++) + for( ; c < numCols; c++) { - if ( x <= this->sizeCol[c5] ) break; // found region + if ( x <= this->sizeCol[c] ) break; // found region } } - - - - - - // TODO: REMOVE BELOW AFTER TEST - auto t7 = Clock::now(); - - binarySearchtime += std::chrono::duration_cast(t2 - t1).count(); - linearSearchTime += std::chrono::duration_cast(t3 - t2).count(); - fromLastLinearSearchTime += std::chrono::duration_cast(t4 - t3).count(); - fromCalcLinearSearchTime += std::chrono::duration_cast(t5 - t4).count(); - fromB4LastLinearSearchTime += std::chrono::duration_cast(t6 - t5).count(); - fromB4LastLinearBackSearchTime += std::chrono::duration_cast(t7 - t6).count(); - - string cOK = ( c == c1 && c == c2 && c == c3 && c == c4 && c == c5)? "cOK" : "cBAD"; - string rOK = ( r == r1 && r == r2 && r == r3 && r == r4 && r == r5)? "rOK" : "rBAD"; - if( plotindex == 0 ) - { - std::clog << " index \t binary \tlinear \t fromlast \t fromCalc \t fromB4Last \t fromB4LastBiDir" << std::endl; - } - std::clog << plotindex++ << '\t' - << binarySearchtime << '\t' - << linearSearchTime << '\t' - << fromLastLinearSearchTime << "\t" - << fromCalcLinearSearchTime << "\t" - << fromB4LastLinearSearchTime << "\t" - << fromB4LastLinearBackSearchTime - << "\t\t" - << c << '=' << c1 << '=' << c2 << '=' << c3 << '=' << c4 << '=' << c5 <<" \t" << cOK << "\t" - << r << '=' << r1 << '=' << r2 << '=' << r3 << '=' << r4 << '=' << r5 << " \t" << rOK << "\t" - << " \t Last " << this->lastGetViewCol << ":" << this->lastGetViewRow << "\t\t" - << " \t Calc " << calcC << ":" << calcR - << std::endl; - - c = c3; - r = r3; - - - - if ( c <= numCols && r <= numRows ) + if ( c < numCols && r < numRows ) { int page = this->mapper.map(c,r); - this->lastGetViewAtPage = page; - this->lastGetViewRow = r; - this->lastGetViewCol = c; + this->lastGetViewAtPageNum = page; + this->lastGetViewAtRow = r; + this->lastGetViewAtCol = c; if ( page>=0 && this->view->viewPages[page]->containsPoint(x,y,false) ) { diff --git a/src/gui/Layout.h b/src/gui/Layout.h index 059a2885..6643eb7c 100644 --- a/src/gui/Layout.h +++ b/src/gui/Layout.h @@ -135,11 +135,11 @@ private: std::vector sizeRow; /** - * cache the last GetViewAt() page# + * cache the last GetViewAt() page#, row and column. */ - int lastGetViewAtPage; + int lastGetViewAtPageNum; - int lastGetViewRow; - int lastGetViewCol; + int lastGetViewAtRow; + int lastGetViewAtCol; }; From effa626cf811c5ad541bb6e0ddd58c2dcc2e44fb Mon Sep 17 00:00:00 2001 From: JJones780 Date: Sun, 10 Mar 2019 01:09:07 -0700 Subject: [PATCH 7/9] Remove all pageposition, pagepositionHandler and pagePositionCache files and references. --- src/control/tools/EditSelection.cpp | 1 - src/control/tools/EditSelectionContents.cpp | 1 - src/gui/Layout.cpp | 2 - src/gui/XournalView.cpp | 10 -- src/gui/XournalView.h | 6 - src/gui/inputdevices/AbstractInputDevice.cpp | 1 - src/gui/inputdevices/InputSequence.cpp | 1 - src/gui/pageposition/PagePosition.cpp | 41 ------- src/gui/pageposition/PagePosition.h | 50 -------- src/gui/pageposition/PagePositionCache.cpp | 15 --- src/gui/pageposition/PagePositionCache.h | 31 ----- src/gui/pageposition/PagePositionHandler.cpp | 118 ------------------- src/gui/pageposition/PagePositionHandler.h | 63 ---------- src/gui/widgets/XournalWidget.cpp | 6 - src/gui/widgets/XournalWidget.h | 2 - 15 files changed, 348 deletions(-) delete mode 100644 src/gui/pageposition/PagePosition.cpp delete mode 100644 src/gui/pageposition/PagePosition.h delete mode 100644 src/gui/pageposition/PagePositionCache.cpp delete mode 100644 src/gui/pageposition/PagePositionCache.h delete mode 100644 src/gui/pageposition/PagePositionHandler.cpp delete mode 100644 src/gui/pageposition/PagePositionHandler.h diff --git a/src/control/tools/EditSelection.cpp b/src/control/tools/EditSelection.cpp index b9bdaaf0..05b3b958 100644 --- a/src/control/tools/EditSelection.cpp +++ b/src/control/tools/EditSelection.cpp @@ -4,7 +4,6 @@ #include "Selection.h" #include "control/Control.h" -#include "gui/pageposition/PagePositionHandler.h" #include "gui/PageView.h" #include "gui/XournalView.h" #include "model/Document.h" diff --git a/src/control/tools/EditSelectionContents.cpp b/src/control/tools/EditSelectionContents.cpp index c030907d..96a7b343 100644 --- a/src/control/tools/EditSelectionContents.cpp +++ b/src/control/tools/EditSelectionContents.cpp @@ -3,7 +3,6 @@ #include "Selection.h" #include "control/Control.h" -#include "gui/pageposition/PagePositionHandler.h" #include "gui/PageView.h" #include "gui/XournalView.h" #include "model/Document.h" diff --git a/src/gui/Layout.cpp b/src/gui/Layout.cpp index 42dba16c..ade88fe3 100644 --- a/src/gui/Layout.cpp +++ b/src/gui/Layout.cpp @@ -3,7 +3,6 @@ #include "XournalView.h" #include "control/Control.h" -#include "pageposition/PagePositionHandler.h" #include "widgets/XournalWidget.h" #include "gui/scroll/ScrollHandling.h" @@ -368,7 +367,6 @@ void Layout::layoutPages() this->setLayoutSize(totalWidth, totalHeight); - this->view->pagePosition->update(this->view->viewPages, len, totalHeight); } diff --git a/src/gui/XournalView.cpp b/src/gui/XournalView.cpp index 252d6748..34ef00ed 100644 --- a/src/gui/XournalView.cpp +++ b/src/gui/XournalView.cpp @@ -12,7 +12,6 @@ #include "gui/inputdevices/TouchHelper.h" #include "model/Document.h" #include "model/Stroke.h" -#include "pageposition/PagePositionHandler.h" #include "undo/DeleteUndoAction.h" #include "widgets/XournalWidget.h" @@ -42,7 +41,6 @@ XournalView::XournalView(GtkWidget* parent, Control* control, ScrollHandling* sc g_signal_connect(getWidget(), "realize", G_CALLBACK(onRealized), this); this->repaintHandler = new RepaintHandler(this); - this->pagePosition = new PagePositionHandler(); this->touchHelper = new TouchHelper(control->getSettings()); control->getZoomControl()->addZoomListener(this); @@ -74,8 +72,6 @@ XournalView::~XournalView() delete this->repaintHandler; this->repaintHandler = NULL; - delete this->pagePosition; - this->pagePosition = NULL; gtk_widget_destroy(this->widget); this->widget = NULL; @@ -1034,12 +1030,6 @@ ArrayIterator XournalView::pageViewIterator() return ArrayIterator (viewPages, viewPagesLen); } -PagePositionHandler* XournalView::getPagePositionHandler() -{ - XOJ_CHECK_TYPE(XournalView); - - return this->pagePosition; -} Cursor* XournalView::getCursor() { diff --git a/src/gui/XournalView.h b/src/gui/XournalView.h index 8ec4e607..3f4d4451 100644 --- a/src/gui/XournalView.h +++ b/src/gui/XournalView.h @@ -96,7 +96,6 @@ public: double getZoom(); int getDpiScaleFactor(); Document* getDocument(); - PagePositionHandler* getPagePositionHandler(); PdfCache* getCache(); RepaintHandler* getRepaintHandler(); GtkWidget* getWidget(); @@ -182,11 +181,6 @@ private: */ RepaintHandler* repaintHandler = NULL; - /** - * The positions of all pages - */ - PagePositionHandler* pagePosition = NULL; - /** * Memory cleanup timeout */ diff --git a/src/gui/inputdevices/AbstractInputDevice.cpp b/src/gui/inputdevices/AbstractInputDevice.cpp index 4233c664..d889dd06 100644 --- a/src/gui/inputdevices/AbstractInputDevice.cpp +++ b/src/gui/inputdevices/AbstractInputDevice.cpp @@ -4,7 +4,6 @@ #include "control/settings/ButtonConfig.h" #include "gui/Cursor.h" #include "gui/Layout.h" -#include "gui/pageposition/PagePositionHandler.h" #include "gui/widgets/XournalWidget.h" #include "gui/XournalView.h" diff --git a/src/gui/inputdevices/InputSequence.cpp b/src/gui/inputdevices/InputSequence.cpp index 53283bd9..5b84b786 100644 --- a/src/gui/inputdevices/InputSequence.cpp +++ b/src/gui/inputdevices/InputSequence.cpp @@ -7,7 +7,6 @@ #include "control/tools/EditSelection.h" #include "control/ToolHandler.h" #include "gui/Cursor.h" -#include "gui/pageposition/PagePositionHandler.h" #include "gui/PageView.h" #include "gui/Layout.h" #include "gui/XournalView.h" diff --git a/src/gui/pageposition/PagePosition.cpp b/src/gui/pageposition/PagePosition.cpp deleted file mode 100644 index 1fde5028..00000000 --- a/src/gui/pageposition/PagePosition.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "PagePosition.h" - -#include "gui/PageView.h" - -PagePosition::PagePosition(XojPageView* aPv) -{ - XOJ_INIT_TYPE(PagePosition); - - this->y1 = aPv->getY(); - this->y2 = this->y1 + aPv->getDisplayHeight(); - this->x1 = aPv->getX(); - this->x2 = this->x1 + aPv->getDisplayWidth(); - - this->pv = aPv; -} - -PagePosition::PagePosition() -{ - XOJ_INIT_TYPE(PagePosition); - - this->y1 = 0; - this->y2 = 0; - this->x1 = 0; - this->x2 = 0; - this->pv = 0; -} - -PagePosition::~PagePosition() -{ - XOJ_CHECK_TYPE(PagePosition); - - XOJ_RELEASE_TYPE(PagePosition); -} - -bool PagePosition::containsPoint(int x, int y) const -{ - XOJ_CHECK_TYPE(PagePosition); - - return y >= this->y1 && y <= this->y2 && x >= this->x1 && x <= this->x2; -} - diff --git a/src/gui/pageposition/PagePosition.h b/src/gui/pageposition/PagePosition.h deleted file mode 100644 index dace0995..00000000 --- a/src/gui/pageposition/PagePosition.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Xournal++ - * - * A page position (a vertical rect) - * - * @author Xournal++ Team, Justin Jones - * https://github.com/xournalpp/xournalpp - * - * @license GNU GPLv2 or later - */ - -#pragma once - -#include - -class XojPageView; - -/** - * @brief A set of XojPageViews within an interval of y coordinates - */ -class PagePosition -{ -public: - PagePosition(XojPageView* pv); - PagePosition(); - virtual ~PagePosition(); - -public: - - /** - * Returns whether or not the given x,y value is in - * this pageview - */ - bool containsPoint(int x, int y) const; - - -private: - XOJ_TYPE_ATTRIB; - - // the minimal/maximal y and x coordinates - int y1; - int y2; - int x1; - int x2; - - // the associated XojPageView - XojPageView* pv; - - friend class PagePositionHandler; -}; diff --git a/src/gui/pageposition/PagePositionCache.cpp b/src/gui/pageposition/PagePositionCache.cpp deleted file mode 100644 index d0d91789..00000000 --- a/src/gui/pageposition/PagePositionCache.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "PagePositionCache.h" - -PagePositionCache::PagePositionCache() -{ - XOJ_INIT_TYPE(PagePositionCache); -} - -PagePositionCache::~PagePositionCache() -{ - XOJ_CHECK_TYPE(PagePositionCache); - - this->ppId = -1; - - XOJ_RELEASE_TYPE(PagePositionCache); -} diff --git a/src/gui/pageposition/PagePositionCache.h b/src/gui/pageposition/PagePositionCache.h deleted file mode 100644 index 809512b7..00000000 --- a/src/gui/pageposition/PagePositionCache.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Xournal++ - * - * Cache for Query the page position handler - * - * @author Xournal++ Team - * https://github.com/xournalpp/xournalpp - * - * @license GNU GPLv2 or later - */ - -#pragma once - -#include - -class PagePositionCache -{ -public: - PagePositionCache(); - virtual ~PagePositionCache(); - -private: - XOJ_TYPE_ATTRIB; - - /** - * PagePositionCache ID - */ - int ppId = -1; - - friend class PagePositionHandler; -}; diff --git a/src/gui/pageposition/PagePositionHandler.cpp b/src/gui/pageposition/PagePositionHandler.cpp deleted file mode 100644 index c6bb3cc6..00000000 --- a/src/gui/pageposition/PagePositionHandler.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "PagePositionHandler.h" - -#include "PagePosition.h" -#include "PagePositionCache.h" - - -PagePositionHandler::PagePositionHandler() -{ - XOJ_INIT_TYPE(PagePositionHandler); -} - -PagePositionHandler::~PagePositionHandler() -{ - XOJ_CHECK_TYPE(PagePositionHandler); - - this->freeData(); - - XOJ_RELEASE_TYPE(PagePositionHandler); -} - -void PagePositionHandler::freeData() -{ - XOJ_CHECK_TYPE(PagePositionHandler); - - for (int i = 0; i < this->dataCount; i++) - { - delete this->data[i]; - } - - g_free(this->data); - this->data = NULL; - this->dataCount = 0; - this->dataAllocSize = 0; -} - -void PagePositionHandler::update(XojPageView** viewPages, int viewPagesLen, int theMaxY) -{ - XOJ_CHECK_TYPE(PagePositionHandler); - - this->freeData(); - - this->maxY = theMaxY; - - for (int i = 0; i < viewPagesLen; i++) - { - XojPageView* pv = viewPages[i]; - PagePosition* pp = new PagePosition(pv); - this->addData(pp); - } - -} - -XojPageView* PagePositionHandler::getViewAt(int x, int y, PagePositionCache* cache) -{ - XOJ_CHECK_TYPE(PagePositionHandler); - - if (y < 0 || y > this->maxY) - { - return NULL; - } - - if (cache && cache->ppId >= 0 && cache->ppId < this->dataCount) - { - if (this->data[cache->ppId]->containsPoint(x, y)) - { - return this->data[cache->ppId]->pv; - } - } - - int index = -1; - PagePosition* pp = this->linearSearch(x, y, index); - - if (cache) - { - cache->ppId = index; - } - if (pp == NULL) - { - return NULL; - } - - return pp->pv; -} - -PagePosition* PagePositionHandler::linearSearch(int x, int y, int& index) -{ - XOJ_CHECK_TYPE(PagePositionHandler); - - for (int i = 0; i < this->dataCount; i++) - { - if (this->data[i]->containsPoint(x, y)) - { - index = i; - return this->data[i]; - } - } - - return NULL; // nothing found -} - -void PagePositionHandler::addData(PagePosition* p) -{ - XOJ_CHECK_TYPE(PagePositionHandler); - - if (this->dataCount >= this->dataAllocSize - 1) - { - this->allocDataSize(this->dataAllocSize + 100); - } - this->data[this->dataCount++] = p; -} - -void PagePositionHandler::allocDataSize(int size) -{ - XOJ_CHECK_TYPE(PagePositionHandler); - - this->dataAllocSize = size; - this->data = (PagePosition**) g_realloc(this->data, this->dataAllocSize * sizeof(PagePosition*)); -} diff --git a/src/gui/pageposition/PagePositionHandler.h b/src/gui/pageposition/PagePositionHandler.h deleted file mode 100644 index 7ba7f1c5..00000000 --- a/src/gui/pageposition/PagePositionHandler.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Xournal++ - * - * Knows the positions of pages in the view - * - * @author Xournal++ Team - * https://github.com/xournalpp/xournalpp - * - * @license GNU GPLv2 or later - */ - -#pragma once - -#include - -class PagePosition; -class PagePositionCache; -class XojPageView; - -/** - * @brief Look up XojPageView's from display coordinates - * - * The PagePositionHandler maintains a set of PagePosition's - * not necessarily sorted. - */ -class PagePositionHandler -{ -public: - PagePositionHandler(); - virtual ~PagePositionHandler(); - -public: - void update(XojPageView** viewPages, int viewPagesLen, int maxY); - - /** - * Returns the XojPageView with the given coordinates - */ - XojPageView* getViewAt(int x, int y, PagePositionCache* cache = NULL); - -private: - void addData(PagePosition* p); - void allocDataSize(int size); - void freeData(); - - /** - * Find page containing x,y coordinates - * - * @param x x pixel coordinate - * @param y y pixel coordinate - * - * @return Page containing coordinate. Index set to data index (to try first next time) - */ - PagePosition* linearSearch(int x, int y, int& index); - -private: - XOJ_TYPE_ATTRIB; - - int dataCount = 0; - int dataAllocSize = 0; - PagePosition** data = NULL; - - int maxY = 0; -}; diff --git a/src/gui/widgets/XournalWidget.cpp b/src/gui/widgets/XournalWidget.cpp index f33e77d3..b628fe08 100644 --- a/src/gui/widgets/XournalWidget.cpp +++ b/src/gui/widgets/XournalWidget.cpp @@ -5,8 +5,6 @@ #include "control/settings/Settings.h" #include "gui/Layout.h" #include "gui/inputdevices/NewGtkInputDevice.h" -#include "gui/pageposition/PagePositionCache.h" -#include "gui/pageposition/PagePositionHandler.h" #include "gui/scroll/ScrollHandling.h" #include "gui/Shadow.h" #include "gui/XournalView.h" @@ -75,8 +73,6 @@ GtkWidget* gtk_xournal_new(XournalView* view, ScrollHandling* scrollHandling) xoj->x = 0; xoj->y = 0; xoj->layout = new Layout(view, scrollHandling); - xoj->pagePositionCache = new PagePositionCache(); - xoj->selection = NULL; xoj->input = new NewGtkInputDevice(GTK_WIDGET(xoj), view, scrollHandling); @@ -343,8 +339,6 @@ static void gtk_xournal_destroy(GtkWidget* object) g_return_if_fail(GTK_IS_XOURNAL(object)); GtkXournal* xournal = GTK_XOURNAL(object); - delete xournal->pagePositionCache; - xournal->pagePositionCache = NULL; delete xournal->selection; xournal->selection = NULL; diff --git a/src/gui/widgets/XournalWidget.h b/src/gui/widgets/XournalWidget.h index 2de282ad..22d1cfb2 100644 --- a/src/gui/widgets/XournalWidget.h +++ b/src/gui/widgets/XournalWidget.h @@ -23,7 +23,6 @@ class AbstractInputDevice; class EditSelection; class Layout; class XojPageView; -class PagePositionCache; class Rectangle; class ScrollHandling; class XournalView; @@ -54,7 +53,6 @@ struct _GtkXournal Layout* layout; - PagePositionCache* pagePositionCache; /** * Selected content, if any From 3a81d7b6b981c53ed72194f7ecba3022c2ab1124 Mon Sep 17 00:00:00 2001 From: JJones780 Date: Sun, 24 Mar 2019 20:38:52 -0600 Subject: [PATCH 8/9] Formatting cleanup --- src/gui/Layout.cpp | 52 +++++++++++++++++++++++----------------------- src/gui/Layout.h | 3 +-- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/gui/Layout.cpp b/src/gui/Layout.cpp index ade88fe3..be925719 100644 --- a/src/gui/Layout.cpp +++ b/src/gui/Layout.cpp @@ -110,7 +110,7 @@ void Layout::updateCurrentPage() // if we are already under the visible rectangle // then everything below will not be visible... - if(currentRect.y > visRect.y + visRect.height) + if (currentRect.y > visRect.y + visRect.height) { p->setIsVisible(false); for (; page < this->view->viewPagesLen; page++) @@ -261,7 +261,7 @@ void Layout::layoutPages() //Calculate border offset which will center pages in viewing area int visibleWidth = gtk_adjustment_get_page_size(scrollHandling->getHorizontal()); int minRequiredWidth = XOURNAL_PADDING_BETWEEN * (columns-1); - for( int c = 0 ; c< columns; c++ ) + for (int c = 0 ; c< columns; c++ ) { minRequiredWidth += this->sizeCol[c]; } @@ -270,7 +270,7 @@ void Layout::layoutPages() int visibleHeight = gtk_adjustment_get_page_size(scrollHandling->getVertical()); int minRequiredHeight = XOURNAL_PADDING_BETWEEN * (rows-1); - for( int r = 0 ; r< rows; r++ ) + for (int r = 0 ; r< rows; r++ ) { minRequiredHeight += this->sizeRow[r]; } @@ -430,9 +430,9 @@ XojPageView* Layout::getViewAt(int x, int y) XOJ_CHECK_TYPE(Layout); //try cached result first - if ( this->lastGetViewAtPageNum < this->view->viewPagesLen && this->view->viewPages[this->lastGetViewAtPageNum]->containsPoint(x,y,false) ) + if (this->lastGetViewAtPageNum < this->view->viewPagesLen && this->view->viewPages[this->lastGetViewAtPageNum]->containsPoint(x,y,false)) { - return this->view->viewPages[this->lastGetViewAtPageNum]; + return this->view->viewPages[this->lastGetViewAtPageNum]; } int r; @@ -440,13 +440,13 @@ XojPageView* Layout::getViewAt(int x, int y) int numRows = this->mapper.getRows(); int numCols = this->mapper.getColumns(); -// Binary Search ... too much overhead makes this a slower option. Leave here for checking against. +// //Binary Search ... too much overhead makes this a slower option. Leave here for checking against. // auto rit = std::lower_bound( this->sizeRow.begin(), this->sizeRow.end(), y); //binary search -// int rb = rit - this->sizeRow.begin(); //get index +// int rb = rit - this->sizeRow.begin(); //get index // // // auto cit = std::lower_bound( this->sizeCol.begin(), this->sizeCol.end(), x); -// int cb = cit - this->sizeCol.begin(); +// int cb = cit - this->sizeCol.begin(); @@ -456,58 +456,58 @@ XojPageView* Layout::getViewAt(int x, int y) // Rows: r = MAX(0, this->lastGetViewAtRow - 1); - if( r > 0 && y <= this->sizeRow[r] ) //search lower + if (r > 0 && y <= this->sizeRow[r]) //search lower { - for( r--; r>=0; r--) + for (r--; r>=0; r--) { if ( y > this->sizeRow[r] ) - { - break; // past region - it's back up one + { + break; // past region } } - r++; + r++; // it's back up one } else //search higher { - for( ; r < numRows; r++) + for (; r < numRows; r++) { - if ( y <= this->sizeRow[r] ) break; // found region - } + if (y <= this->sizeRow[r]) break; // found region + } } //Now for columns: c = MAX(0, this->lastGetViewAtCol - 1); - if( c >0 && x <= this->sizeCol[c] ) //search lower + if (c >0 && x <= this->sizeCol[c]) //search lower { - for( c--; c>=0; c--) + for (c--; c>=0; c--) { - if ( x > this->sizeCol[c] ) - { - break; // past region + if (x > this->sizeCol[c]) + { + break; } } c++; } else { - for( ; c < numCols; c++) + for (; c < numCols; c++) { - if ( x <= this->sizeCol[c] ) break; // found region - } + if (x <= this->sizeCol[c]) break; + } } - if ( c < numCols && r < numRows ) + if (c < numCols && r < numRows) { int page = this->mapper.map(c,r); this->lastGetViewAtPageNum = page; this->lastGetViewAtRow = r; this->lastGetViewAtCol = c; - if ( page>=0 && this->view->viewPages[page]->containsPoint(x,y,false) ) + if (page>=0 && this->view->viewPages[page]->containsPoint(x,y,false)) { return this->view->viewPages[page]; } diff --git a/src/gui/Layout.h b/src/gui/Layout.h index 6643eb7c..d9ef31f9 100644 --- a/src/gui/Layout.h +++ b/src/gui/Layout.h @@ -137,8 +137,7 @@ private: /** * cache the last GetViewAt() page#, row and column. */ - int lastGetViewAtPageNum; - + int lastGetViewAtPageNum; int lastGetViewAtRow; int lastGetViewAtCol; From 769a878ada4ae38ab91afb764367c6fa8cc8b480 Mon Sep 17 00:00:00 2001 From: JJones780 Date: Tue, 26 Mar 2019 18:39:23 -0600 Subject: [PATCH 9/9] Remove redundant page cache check. Various changes from reviewers notes - thanks. --- src/gui/Layout.cpp | 79 +++++++++++++++++++++------------------------- src/gui/Layout.h | 7 ++-- 2 files changed, 39 insertions(+), 47 deletions(-) diff --git a/src/gui/Layout.cpp b/src/gui/Layout.cpp index be925719..f21d2495 100644 --- a/src/gui/Layout.cpp +++ b/src/gui/Layout.cpp @@ -52,9 +52,6 @@ Layout::Layout(XournalView* view, ScrollHandling* scrollHandling) layout->scrollHandling->scrollChanged(); }), this); - this->lastGetViewAtPageNum = 0; - this->lastGetViewAtRow = 0; - this->lastGetViewAtCol = 0; lastScrollHorizontal = gtk_adjustment_get_value(scrollHandling->getHorizontal()); lastScrollVertical = gtk_adjustment_get_value(scrollHandling->getVertical()); @@ -198,9 +195,6 @@ void Layout::layoutPages() int len = this->view->viewPagesLen; - this->lastGetViewAtPageNum = len; // invalidate cache index. - this->lastGetViewAtRow = 0; - this->lastGetViewAtCol = 0; Settings* settings = this->view->getControl()->getSettings(); @@ -211,7 +205,10 @@ void Layout::layoutPages() bool isPairedPages = mapper.getPairedPages(); this->rows = mapper.getRows(); this->columns = mapper.getColumns(); - + + this->lastGetViewAtRow = this->rows/2; //reset to middle + this->lastGetViewAtCol = this->columns/2; + this->sizeCol.assign(this->columns,0); //new size, clear to 0's @@ -304,8 +301,7 @@ void Layout::layoutPages() { int paddingLeft; int paddingRight; - int columnPadding = 0; - columnPadding = (this->sizeCol[c] - vDisplayWidth); + int columnPadding = this->sizeCol[c] - vDisplayWidth; if (isPairedPages && len > 1) { @@ -429,83 +425,80 @@ XojPageView* Layout::getViewAt(int x, int y) XOJ_CHECK_TYPE(Layout); - //try cached result first - if (this->lastGetViewAtPageNum < this->view->viewPagesLen && this->view->viewPages[this->lastGetViewAtPageNum]->containsPoint(x,y,false)) - { - return this->view->viewPages[this->lastGetViewAtPageNum]; - } - - int r; - int c; - int numRows = this->mapper.getRows(); - int numCols = this->mapper.getColumns(); - -// //Binary Search ... too much overhead makes this a slower option. Leave here for checking against. -// auto rit = std::lower_bound( this->sizeRow.begin(), this->sizeRow.end(), y); //binary search +// No need to check page cache as the Linear search below starts at cached position. +// Keep Binary search handy to check against. +// +// //Binary Search ... too much overhead makes this a slower option in our use case. +// auto rit = std::lower_bound( this->sizeRow.begin(), this->sizeRow.end(), y); // int rb = rit - this->sizeRow.begin(); //get index -// -// // auto cit = std::lower_bound( this->sizeCol.begin(), this->sizeCol.end(), x); // int cb = cit - this->sizeCol.begin(); + int numRows = this->mapper.getRows(); + int numCols = this->mapper.getColumns(); /* Linear Up or Down Search from last position: */ // Rows: - r = MAX(0, this->lastGetViewAtRow - 1); - if (r > 0 && y <= this->sizeRow[r]) //search lower + int testRow = MAX(0, this->lastGetViewAtRow - 1); + if (testRow > 0 && y <= this->sizeRow[testRow]) //search lower { - for (r--; r>=0; r--) + for (testRow--; testRow>=0; testRow--) { - if ( y > this->sizeRow[r] ) + if ( y > this->sizeRow[testRow] ) { break; // past region } } - r++; // it's back up one + testRow++; // it's back up one } else //search higher { - for (; r < numRows; r++) + for (; testRow < numRows; testRow++) { - if (y <= this->sizeRow[r]) break; // found region + if (y <= this->sizeRow[testRow]) + { + break; // found region + } } } //Now for columns: - c = MAX(0, this->lastGetViewAtCol - 1); - if (c >0 && x <= this->sizeCol[c]) //search lower + int testCol = MAX(0, this->lastGetViewAtCol - 1); + if (testCol >0 && x <= this->sizeCol[testCol]) //search lower { - for (c--; c>=0; c--) + for (testCol--; testCol>=0; testCol--) { - if (x > this->sizeCol[c]) + if (x > this->sizeCol[testCol]) { break; } } - c++; + testCol++; } else { - for (; c < numCols; c++) + for (; testCol < numCols; testCol++) { - if (x <= this->sizeCol[c]) break; + if (x <= this->sizeCol[testCol]) + { + break; + } } } - if (c < numCols && r < numRows) + if (testCol < numCols && testRow < numRows) { - int page = this->mapper.map(c,r); - this->lastGetViewAtPageNum = page; - this->lastGetViewAtRow = r; - this->lastGetViewAtCol = c; + int page = this->mapper.map(testCol,testRow); + this->lastGetViewAtRow = testRow; + this->lastGetViewAtCol = testCol; if (page>=0 && this->view->viewPages[page]->containsPoint(x,y,false)) { diff --git a/src/gui/Layout.h b/src/gui/Layout.h index d9ef31f9..559262e4 100644 --- a/src/gui/Layout.h +++ b/src/gui/Layout.h @@ -135,10 +135,9 @@ private: std::vector sizeRow; /** - * cache the last GetViewAt() page#, row and column. + * cache the last GetViewAt() row and column. */ - int lastGetViewAtPageNum; - int lastGetViewAtRow; - int lastGetViewAtCol; + int lastGetViewAtRow = 0; + int lastGetViewAtCol = 0; };