Added more layouts to LayoutMapper ( right to left etc. ). Enum for layout now bitflag flexible.

TODO: allow user to access them via menu or prefs.
presentation
JJones780 7 years ago committed by JJones780
parent 68be24ac1d
commit 2aa04be206
  1. 2
      src/gui/Layout.cpp
  2. 82
      src/gui/LayoutMapper.cpp
  3. 26
      src/gui/LayoutMapper.h

@ -213,7 +213,7 @@ void Layout::layoutPagesUsingMapper()
if (!dualPage ) pairsOffset = 0;
LayoutMapper mapper( len, columnSetting, false, pairsOffset, dualPage?LayoutType::VerticalPaired: LayoutType::Vertical );
LayoutMapper mapper( len, columnSetting, false, pairsOffset, LayoutType::Vertical_RL, dualPage );
pagesOffset = mapper.offset;

@ -9,8 +9,9 @@
#define MAX(A, B) ((A) > (B) ? (A) : (B))
LayoutMapper::LayoutMapper( int pages, int rORc, bool isR , int off, LayoutType type ){
LayoutMapper::LayoutMapper( int pages, int rORc, bool isR , int off, LayoutType type, bool isPaired){
paired = isPaired;
if(isR){
r = MAX(1, rORc);
c = MAX(1, (pages + off + (rORc -1) )/rORc); // using + ( rORc-1) to round up (int)pages/rows
@ -18,43 +19,68 @@ LayoutMapper::LayoutMapper( int pages, int rORc, bool isR , int off, LayoutType
c = MAX(1, rORc);
r = MAX(1, (pages + off + (rORc -1) )/rORc);
}
if(paired) c += c%2; // add another column if pairing and odd number of columns.
layoutType = type;
switch ( type){
case Horizontal:
offset = off % c;
break;
case Vertical: //vertical layout
offset = off % r;
break;
case VerticalPaired:
if(type & LayoutBitFlags::ColMajor)
{
if( paired){
offset = off % (2*r);
break;
}
else{
offset = off % r;
}
}
else //Horizontal Layout
{
offset = off % c;
}
possiblePages = r * c;
rORc = rORc;
actualPages = pages;
}
int LayoutMapper::map(int x, int y){
int res;
switch( layoutType)
if( layoutType < BitFlagsUsed)
{
case Horizontal:
res = (x + c * y);
break;
case Vertical: //vertical layout
res = (y + r* x);
break;
case VerticalPaired:
res = ((( y + r*( (int)(x/2) )) * 2 ) + x %2);
break;
if ( layoutType & LayoutBitFlags::RightToLeft)
{
x = c-1-x; //mirror x
}
if ( layoutType & LayoutBitFlags::BottomToTop)
{
y = r-1-y;
}
if( layoutType & LayoutBitFlags::ColMajor) // aka Vertical
{
if( paired)
{
res = ((( y + r*( (int)(x/2) )) * 2 ) + x %2);
}
else{
res = (y + r* x);
}
}
else //Horizontal
{
res = (x + c * y);
}
res -= offset;
if( res>=actualPages) res = -1;
return res;
}
res -= offset;
if( res>=actualPages) res = -1;
return res;
}

@ -11,11 +11,23 @@
#pragma once
enum LayoutType {
Horizontal,
Vertical,
VerticalPaired,
//TODO: add in Right to Left mappings for other cultures (i.e. Japanese )
enum LayoutType { // 1 2 4
Horizontal = 0, //
Vertical = 1, // V
Horizontal_RL = 2, // RL
Vertical_RL = 3, // V RL
Horizontal_BT = 4, // BT
Vertical_BT = 5, // V BT
Horizontal_RL_BT = 6, // RL BT
Vertical_BT_RL = 7, // V RL BT
BitFlagsUsed, //do not modify this or above
};
enum LayoutBitFlags{
ColMajor = 1, //aka Vertical
RightToLeft = 2,
BottomToTop = 4,
};
/**
@ -28,11 +40,11 @@ class LayoutMapper
public:
int c=0;
int r=0;
int rORc;
int actualPages=0;
int possiblePages=0;
int offset = 0;
LayoutType layoutType;
bool paired = false;
/**
@ -45,7 +57,7 @@ public:
*
* @return Page index to put at coordinates
*/
LayoutMapper( int pages, int rORc, bool isR , int off, LayoutType type );
LayoutMapper( int pages, int rORc, bool isR , int off, LayoutType type, bool paired );

Loading…
Cancel
Save