Merge pull request #1025 from JJones780/UpdateVisibleLayoutData

UpdateVisibility, cleanup LayoutData
presentation
JJones780 7 years ago committed by GitHub
commit fe94671528
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 152
      src/gui/Layout.cpp
  2. 2
      src/gui/Layout.h
  3. 97
      src/gui/LayoutData.cpp
  4. 54
      src/gui/LayoutData.h
  5. 26
      src/gui/PageView.cpp
  6. 17
      src/gui/PageView.h
  7. 6
      src/gui/XournalView.cpp

@ -5,7 +5,7 @@
#include "control/Control.h"
#include "widgets/XournalWidget.h"
#include "gui/scroll/ScrollHandling.h"
/**
* Padding outside the pages, including shadow
*/
@ -39,7 +39,7 @@ Layout::Layout(XournalView* view, ScrollHandling* scrollHandling)
{
XOJ_CHECK_TYPE_OBJ(layout, Layout);
layout->checkScroll(adjustment, layout->lastScrollHorizontal);
layout->updateCurrentPage();
layout->updateVisibility();
layout->scrollHandling->scrollChanged();
}), this);
@ -48,7 +48,7 @@ Layout::Layout(XournalView* view, ScrollHandling* scrollHandling)
{
XOJ_CHECK_TYPE_OBJ(layout, Layout);
layout->checkScroll(adjustment, layout->lastScrollVertical);
layout->updateCurrentPage();
layout->updateVisibility();
layout->scrollHandling->scrollChanged();
}), this);
@ -70,93 +70,59 @@ void Layout::checkScroll(GtkAdjustment* adjustment, double& lastScroll)
}
/**
* Check which page should be selected
* Update Visibilty for each page
*/
void Layout::updateCurrentPage()
void Layout::updateVisibility()
{
XOJ_CHECK_TYPE(Layout);
Rectangle visRect = getVisibleRect();
Control* control = this->view->getControl();
bool pairedPages = control->getSettings()->isShowPairedPages();
if (visRect.y < 1)
{
if (pairedPages && this->view->viewPagesLen > 1 &&
this->view->viewPages[1]->isSelected())
{
// page 2 already selected
}
else
{
control->firePageSelected(0);
}
return;
}
size_t mostPageNr = 0;
double mostPagePercent = 0;
for (size_t page = 0; page < this->view->viewPagesLen; page++)
// step through every possible page position and update using p->setIsVisible()
// Using initial grid aprox speeds things up by a factor of 5. See previous git check-in for specifics.
int x1 = 0;
int y1 = 0;
for (int onRow = 0; onRow < this->rows; onRow++)
{
XojPageView* p = this->view->viewPages[page];
Rectangle currentRect = p->getRect();
// if we are already under the visible rectangle
// then everything below will not be visible...
if (currentRect.y > visRect.y + visRect.height)
int y2 = this->sizeRow[onRow];
for (int onCol = 0; onCol < this->columns; onCol++)
{
p->setIsVisible(false);
for (; page < this->view->viewPagesLen; page++)
int x2 = this->sizeCol[onCol];
int pageIndex = this->mapper.map(onCol, onRow);
if (pageIndex >= 0) // a page exists at this grid location
{
p = this->view->viewPages[page];
p->setIsVisible(false);
}
break;
}
// if the condition is satisfied we know that
// the rectangles intersect vertically
if (currentRect.y + currentRect.height >= visRect.y)
{
double percent =
currentRect.intersect(visRect).area() / currentRect.area();
if (percent > mostPagePercent)
{
mostPagePercent = percent;
mostPageNr = page;
XojPageView* pageView = this->view->viewPages[pageIndex];
//check if grid location is visible as an aprox for page visiblity:
if( !(visRect.x >x2 || visRect.x+visRect.width < x1) // visrect not outside current row/col
&& !(visRect.y >y2 || visRect.y+visRect.height < y1))
{
// now use exact check of page itself:
Rectangle pageRect = pageView->getRect();
if( !(visRect.x >pageRect.x+pageRect.width || visRect.x+visRect.width < pageRect.x) // visrect not outside current page dimensions
&& !(visRect.y >pageRect.y+pageRect.height || visRect.y+visRect.height < pageRect.y))
{
pageView->setIsVisible(true);
}
else
{
pageView->setIsVisible(false);
}
}
else
{
pageView->setIsVisible(false);
}
}
p->setIsVisible(true);
}
else
{
p->setIsVisible(false);
x1 = x2;
}
y1 = y2;
}
if (pairedPages && mostPageNr < this->view->viewPagesLen - 1)
{
int y1 = this->view->viewPages[mostPageNr]->getY();
int y2 = this->view->viewPages[mostPageNr + 1]->getY();
if (y1 != y2 || !this->view->viewPages[mostPageNr + 1]->isSelected())
{
// if the second page is selected DON'T select the first page.
// Only select the first page if none is selected
control->firePageSelected(mostPageNr);
}
}
else
{
control->firePageSelected(mostPageNr);
}
}
Rectangle Layout::getVisibleRect()
@ -189,6 +155,12 @@ double Layout::getLayoutWidth()
return layoutWidth;
}
/**
* layoutPages
* Sets out pages in a grid.
* Document pages are assigned to grid positions by the mapper object and may be ordered in a myriad of ways.
*/
void Layout::layoutPages()
{
XOJ_CHECK_TYPE(Layout);
@ -199,12 +171,12 @@ void Layout::layoutPages()
Settings* settings = this->view->getControl()->getSettings();
// obtain rows, cols, paired and layout from view settings
mapper.configureFromSettings(len, settings);
this->mapper.configureFromSettings(len, settings);
// get from mapper (some may have changed to accomodate paired setting etc.)
bool isPairedPages = mapper.getPairedPages();
this->rows = mapper.getRows();
this->columns = mapper.getColumns();
bool isPairedPages = this->mapper.getPairedPages();
this->rows = this->mapper.getRows();
this->columns = this->mapper.getColumns();
this->lastGetViewAtRow = this->rows/2; //reset to middle
this->lastGetViewAtCol = this->columns/2;
@ -213,16 +185,18 @@ void Layout::layoutPages()
this->sizeCol.assign(this->columns,0); //new size, clear to 0's
this->sizeRow.assign(this->rows,0);
// look through every grid position, get assigned page from mapper and find out minimal row and column sizes to fit largest pages.
for (int r = 0; r < this->rows; r++)
{
for (int c = 0; c < this->columns; c++)
{
int k = mapper.map(c, r);
if (k >= 0)
int pageIndex = this->mapper.map(c, r);
if (pageIndex >= 0)
{
XojPageView* v = this->view->viewPages[k];
XojPageView* v = this->view->viewPages[pageIndex];
if (this->sizeCol[c] < v->getDisplayWidth())
{
@ -291,7 +265,7 @@ void Layout::layoutPages()
{
for (int c = 0; c < this->columns; c++)
{
int pageAtRowCol = mapper.map(c, r);
int pageAtRowCol = this->mapper.map(c, r);
if (pageAtRowCol >= 0)
{
@ -326,8 +300,8 @@ void Layout::layoutPages()
x += paddingLeft;
v->layout.setX(x);
v->layout.setY(y);
v->setX(x); //set the page position
v->setY(y);
x += vDisplayWidth + paddingRight;
@ -348,7 +322,7 @@ void Layout::layoutPages()
for (int c = 0; c < this->columns; c++)
{
totalWidth += this->sizeCol[c] + XOURNAL_PADDING_BETWEEN;
this->sizeCol[c] = totalWidth; //accumulated for use by getViewAt()
this->sizeCol[c] = totalWidth; //accumulated - absolute pixel location for use by getViewAt() and updateVisibility()
}
totalWidth += borderX - XOURNAL_PADDING_BETWEEN;

@ -85,7 +85,7 @@ public:
* the percentage of the visible area of the XojPageView relative
* to its total area.
*/
void updateCurrentPage();
void updateVisibility();

@ -1,97 +0,0 @@
#include "LayoutData.h"
#include <gtk/gtk.h>
LayoutData::LayoutData()
{
XOJ_INIT_TYPE(LayoutData);
}
LayoutData::~LayoutData()
{
XOJ_RELEASE_TYPE(LayoutData);
}
int LayoutData::getX()
{
XOJ_CHECK_TYPE(LayoutData);
return this->x;
}
void LayoutData::setX(int x)
{
XOJ_CHECK_TYPE(LayoutData);
this->x = x;
}
int LayoutData::getY()
{
XOJ_CHECK_TYPE(LayoutData);
return this->y;
}
void LayoutData::setY(int y)
{
XOJ_CHECK_TYPE(LayoutData);
this->y = y;
}
int LayoutData::getPageIndex()
{
XOJ_CHECK_TYPE(LayoutData);
return this->pageIndex;
}
void LayoutData::setPageIndex(int pageIndex)
{
XOJ_CHECK_TYPE(LayoutData);
this->pageIndex = pageIndex;
}
int LayoutData::getLayoutAbsoluteX() const
{
XOJ_CHECK_TYPE(LayoutData);
return this->x + this->marginLeft;
}
int LayoutData::getLayoutAbsoluteY() const
{
XOJ_CHECK_TYPE(LayoutData);
return this->y + this->marginTop;
}
int LayoutData::getMarginLeft()
{
XOJ_CHECK_TYPE(LayoutData);
return this->marginLeft;
}
void LayoutData::setMarginLeft(int left)
{
XOJ_CHECK_TYPE(LayoutData);
this->marginLeft = left;
}
int LayoutData::getMarginTop()
{
XOJ_CHECK_TYPE(LayoutData);
return this->marginTop;
}
void LayoutData::setMarginTop(int top)
{
XOJ_CHECK_TYPE(LayoutData);
this->marginTop = top;
}

@ -1,54 +0,0 @@
/*
* Xournal++
*
*
*
* @author andreas
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <XournalType.h>
class LayoutData
{
public:
LayoutData();
~LayoutData();
public:
int getX();
void setX(int x);
int getY();
void setY(int y);
int getPageIndex();
void setPageIndex(int pageIndex);
int getLayoutAbsoluteX() const;
int getLayoutAbsoluteY() const;
int getMarginLeft();
void setMarginLeft(int left);
int getMarginTop();
void setMarginTop(int top);
private:
XOJ_TYPE_ATTRIB;
// page position in layout, in px to the layout contents BORDER, not ABSOLUTE
int x = 0;
int y = 0;
// the margin of the layout to the top
int marginLeft = 0;
int marginTop = 0;
// 0: left page, 1: right page, will may be extended later
int pageIndex = 0;
};

@ -141,10 +141,10 @@ bool XojPageView::containsPoint(int x, int y, bool local)
if (!local)
{
bool leftOk = this->layout.getLayoutAbsoluteX() <= x;
bool rightOk = x <= this->layout.getLayoutAbsoluteX() + this->getDisplayWidth();
bool topOk = this->layout.getLayoutAbsoluteY() <= y;
bool bottomOk = y <= this->layout.getLayoutAbsoluteY() + this->getDisplayHeight();
bool leftOk = this->getX() <= x;
bool rightOk = x <= this->getX() + this->getDisplayWidth();
bool topOk = this->getY() <= y;
bool bottomOk = y <= this->getY() + this->getDisplayHeight();
return leftOk && rightOk && topOk && bottomOk;
}
@ -910,14 +910,28 @@ int XojPageView::getX() const
{
XOJ_CHECK_TYPE(XojPageView);
return this->layout.getLayoutAbsoluteX();
return this->dispX;
}
void XojPageView::setX( int x )
{
XOJ_CHECK_TYPE(XojPageView);
this->dispX = x;
}
int XojPageView::getY() const
{
XOJ_CHECK_TYPE(XojPageView);
return this->layout.getLayoutAbsoluteY();
return this->dispY;
}
void XojPageView::setY( int y )
{
XOJ_CHECK_TYPE(XojPageView);
this->dispY = y;
}
PageRef XojPageView::getPage()

@ -11,8 +11,8 @@
#pragma once
#include "LayoutData.h"
#include "Redrawable.h"
#include "Layout.h"
#include "model/PageListener.h"
#include "model/PageRef.h"
@ -129,7 +129,7 @@ public:
* respect to the display
*/
int getY() const;
TexImage* getSelectedTex();
Text* getSelectedText();
@ -165,12 +165,9 @@ private:
void addRerenderRect(double x, double y, double width, double height);
void drawLoadingPage(cairo_t* cr);
public:
/**
* position in the layout
*/
LayoutData layout;
void setX(int x);
void setY(int y);
private:
XOJ_TYPE_ATTRIB;
@ -222,10 +219,14 @@ private:
bool rerenderComplete = false;
GMutex drawingMutex;
int dispX; //position on display - set in Layout::layoutPages
int dispY;
friend class RenderJob;
friend class InputHandler;
friend class BaseSelectObject;
friend class SelectObject;
friend class PlayObject;
friend void Layout::layoutPages(); //only function allowed to setX(), setY()
};

@ -445,8 +445,8 @@ void XournalView::scrollTo(size_t pageNo, double yDocument)
// Make sure it is visible
Layout* layout = gtk_xournal_get_layout(this->widget);
int x = v->layout.getLayoutAbsoluteX();
int y = v->layout.getLayoutAbsoluteY() + yDocument;
int x = v->getX();
int y = v->getY() + yDocument;
int width = v->getDisplayWidth();
int height = v->getDisplayHeight();
@ -744,7 +744,7 @@ void XournalView::pageInserted(size_t page)
Layout* layout = gtk_xournal_get_layout(this->widget);
layout->layoutPages();
layout->updateCurrentPage();
layout->updateVisibility();
}
double XournalView::getZoom()

Loading…
Cancel
Save