Merge pull request #1009 from JJones780/LayoutGetViewAt

presentation
JJones780 7 years ago committed by GitHub
commit c329f41f0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/control/tools/EditSelection.cpp
  2. 1
      src/control/tools/EditSelectionContents.cpp
  3. 168
      src/gui/Layout.cpp
  4. 34
      src/gui/Layout.h
  5. 51
      src/gui/LayoutMapper.cpp
  6. 49
      src/gui/LayoutMapper.h
  7. 10
      src/gui/XournalView.cpp
  8. 6
      src/gui/XournalView.h
  9. 1
      src/gui/inputdevices/AbstractInputDevice.cpp
  10. 7
      src/gui/inputdevices/InputSequence.cpp
  11. 41
      src/gui/pageposition/PagePosition.cpp
  12. 50
      src/gui/pageposition/PagePosition.h
  13. 15
      src/gui/pageposition/PagePositionCache.cpp
  14. 31
      src/gui/pageposition/PagePositionCache.h
  15. 118
      src/gui/pageposition/PagePositionHandler.cpp
  16. 63
      src/gui/pageposition/PagePositionHandler.h
  17. 6
      src/gui/widgets/XournalWidget.cpp
  18. 2
      src/gui/widgets/XournalWidget.h

@ -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"
@ -17,6 +16,7 @@
#include "undo/SizeUndoAction.h"
#include "undo/UndoRedoHandler.h"
#include "util/GtkColorWrapper.h"
#include "gui/Layout.h"
#include <serializing/ObjectOutputStream.h>
#include <serializing/ObjectInputStream.h>
@ -562,17 +562,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;
}

@ -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"

@ -3,11 +3,8 @@
#include "XournalView.h"
#include "control/Control.h"
#include "pageposition/PagePositionHandler.h"
#include "widgets/XournalWidget.h"
#include "gui/scroll/ScrollHandling.h"
#include "gui/LayoutMapper.h"
/**
* Padding outside the pages, including shadow
@ -30,6 +27,7 @@ const int XOURNAL_ROOM_FOR_SHADOW = 3;
const int XOURNAL_PADDING_BETWEEN = 15;
Layout::Layout(XournalView* view, ScrollHandling* scrollHandling)
: view(view),
scrollHandling(scrollHandling)
@ -53,6 +51,7 @@ Layout::Layout(XournalView* view, ScrollHandling* scrollHandling)
layout->updateCurrentPage();
layout->scrollHandling->scrollChanged();
}), this);
lastScrollHorizontal = gtk_adjustment_get_value(scrollHandling->getHorizontal());
lastScrollVertical = gtk_adjustment_get_value(scrollHandling->getVertical());
@ -108,7 +107,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++)
@ -195,27 +194,29 @@ void Layout::layoutPages()
XOJ_CHECK_TYPE(Layout);
int len = this->view->viewPagesLen;
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();
this->rows = mapper.getRows();
this->columns = mapper.getColumns();
this->lastGetViewAtRow = this->rows/2; //reset to middle
this->lastGetViewAtCol = this->columns/2;
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 +224,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();
}
}
@ -257,18 +258,18 @@ 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 += sizeCol[c];
minRequiredWidth += this->sizeCol[c];
}
int centeringXBorder = ( visibleWidth - minRequiredWidth )/2; // this will center if all pages fit on screen.
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 += sizeRow[r];
minRequiredHeight += this->sizeRow[r];
}
int centeringYBorder = ( visibleHeight - minRequiredHeight )/2; // this will center if all pages fit on screen vertically.
@ -286,9 +287,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);
@ -300,8 +301,7 @@ void Layout::layoutPages()
{
int paddingLeft;
int paddingRight;
int columnPadding = 0;
columnPadding = (sizeCol[c] - vDisplayWidth);
int columnPadding = this->sizeCol[c] - vDisplayWidth;
if (isPairedPages && len > 1)
{
@ -335,29 +335,35 @@ 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;
for (int c = 0; c < this->columns; c++)
{
totalWidth += 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 * (rows-1);
for (int r = 0; r < rows; r++)
int totalHeight = borderY;
for (int r = 0; r < this->rows; r++)
{
totalHeight += 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);
}
@ -414,4 +420,94 @@ void Layout::ensureRectIsVisible(int x, int y, int width, int height)
}
XojPageView* Layout::getViewAt(int x, int y)
{
XOJ_CHECK_TYPE(Layout);
// 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:
int testRow = MAX(0, this->lastGetViewAtRow - 1);
if (testRow > 0 && y <= this->sizeRow[testRow]) //search lower
{
for (testRow--; testRow>=0; testRow--)
{
if ( y > this->sizeRow[testRow] )
{
break; // past region
}
}
testRow++; // it's back up one
}
else //search higher
{
for (; testRow < numRows; testRow++)
{
if (y <= this->sizeRow[testRow])
{
break; // found region
}
}
}
//Now for columns:
int testCol = MAX(0, this->lastGetViewAtCol - 1);
if (testCol >0 && x <= this->sizeCol[testCol]) //search lower
{
for (testCol--; testCol>=0; testCol--)
{
if (x > this->sizeCol[testCol])
{
break;
}
}
testCol++;
}
else
{
for (; testCol < numCols; testCol++)
{
if (x <= this->sizeCol[testCol])
{
break;
}
}
}
if (testCol < numCols && testRow < numRows)
{
int page = this->mapper.map(testCol,testRow);
this->lastGetViewAtRow = testRow;
this->lastGetViewAtCol = testCol;
if (page>=0 && this->view->viewPages[page]->containsPoint(x,y,false))
{
return this->view->viewPages[page];
}
}
return NULL;
}

@ -16,10 +16,13 @@
#include <gtk/gtk.h>
#include "gui/LayoutMapper.h"
class XojPageView;
class XournalView;
class ScrollHandling;
/**
* @brief The Layout manager for the XournalWidget
*
@ -84,6 +87,15 @@ 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);
@ -91,7 +103,9 @@ private:
private:
XOJ_TYPE_ATTRIB;
XournalView* view = NULL;
XournalView* view = NULL;
LayoutMapper mapper;
ScrollHandling* scrollHandling = NULL;
@ -108,4 +122,22 @@ private:
*/
int layoutWidth = 0;
int layoutHeight = 0;
/**
*The following are useful for locating page at a pixel location
*/
int rows;
int columns;
std::vector<int> sizeCol;
std::vector<int> sizeRow;
/**
* cache the last GetViewAt() row and column.
*/
int lastGetViewAtRow = 0;
int lastGetViewAtCol = 0;
};

@ -1,42 +1,22 @@
#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(int pages, int numRows, int numCols, bool useRows, LayoutType type, bool isPaired,
int firstPageOffset)
{
LayoutMapper::LayoutMapper(){
XOJ_INIT_TYPE(LayoutMapper);
layoutMapperInit(pages, numRows, numCols, useRows, type, isPaired, firstPageOffset);
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, 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);
XOJ_CHECK_TYPE(LayoutMapper);
int pages = numPages;
@ -55,8 +35,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()

@ -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:
/**

@ -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<XojPageView*> XournalView::pageViewIterator()
return ArrayIterator<XojPageView*> (viewPages, viewPagesLen);
}
PagePositionHandler* XournalView::getPagePositionHandler()
{
XOJ_CHECK_TYPE(XournalView);
return this->pagePosition;
}
Cursor* XournalView::getCursor()
{

@ -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
*/

@ -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"

@ -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"
@ -139,10 +138,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);
}
/**

@ -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;
}

@ -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 <XournalType.h>
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;
};

@ -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);
}

@ -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 <XournalType.h>
class PagePositionCache
{
public:
PagePositionCache();
virtual ~PagePositionCache();
private:
XOJ_TYPE_ATTRIB;
/**
* PagePositionCache ID
*/
int ppId = -1;
friend class PagePositionHandler;
};

@ -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*));
}

@ -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 <XournalType.h>
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;
};

@ -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;

@ -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

Loading…
Cancel
Save