CLayoutMgr Class Reference

#include <LayoutMgr.h>

Collaboration diagram for CLayoutMgr:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 CLayoutMgr (void)
 ~CLayoutMgr (void)
void clear ()
void getPageRect (const int page, rectangle &rect)
const rectanglegetPageRect (const int page) const
double initPagesPosition (Controller *ctrl)
int getPagesVisible (int &start, int &end, const rectangle &rect)
int hitTest (const point &pt, const int start, const int end)
int hitTest (const int x, const int y, const int start, const int end)
void updatePageRect (const int x, const int y, const int width, const int height)
GBool hitTest (const int x, const int y)
void screenToVirtualScreen (Controller *ctrl, rectangle &rect)
void screenToVirtualScreen (Controller *ctrl, point &pt)
void virtualScreenToScreen (Controller *ctrl, const rectangle &rect)
void getVirtualScreen (rectangle &rect)
const rectanglegetVirtualScreen () const
void rotate (Controller *ctrl, const int angle)

Private Attributes

rectangle bound
rectangleposTab
int posLen


Detailed Description

Definition at line 30 of file LayoutMgr.h.


Constructor & Destructor Documentation

CLayoutMgr::CLayoutMgr ( void   ) 

Definition at line 23 of file LayoutMgr.cpp.

00024 : posTab(NULL)
00025 , posLen(0)
00026 {
00027 }

CLayoutMgr::~CLayoutMgr ( void   ) 

Definition at line 29 of file LayoutMgr.cpp.

00030 {
00031 }


Member Function Documentation

void CLayoutMgr::clear (  ) 

Definition at line 33 of file LayoutMgr.cpp.

00034 {
00035     if (posTab)
00036     {
00037         delete [] posTab; posTab = NULL; posLen = 0;
00038     }
00039 }

void CLayoutMgr::getPageRect ( const int  page,
rectangle rect 
)

Definition at line 97 of file LayoutMgr.cpp.

00098 {
00099     rect = posTab[page - 1];
00100 }

const rectangle & CLayoutMgr::getPageRect ( const int  page  )  const

Definition at line 102 of file LayoutMgr.cpp.

00103 {
00104     return posTab[page - 1];
00105 }

double CLayoutMgr::initPagesPosition ( Controller ctrl  ) 

Definition at line 41 of file LayoutMgr.cpp.

00042 {
00043     if (posTab && posLen != ctrl->core->getNumPages())
00044     {
00045         delete [] posTab; posTab = NULL; posLen = ctrl->core->getNumPages();
00046     }
00047     
00048     if (NULL == posTab)
00049     {
00050         posLen = ctrl->core->getNumPages();
00051         posTab = new rectangle[posLen];
00052     }
00053 
00054     // bound will record out-bound of virtual screen
00055     bound.left = bound.top = bound.right = bound.bottom = 0;
00056 
00057     // go through page list
00058     double zoom  = ctrl->calZoom(ctrl->settings.getCurrentPage());
00059     // PV_LOGPRINTF("Zoom now %g! posLen %d posTab %p", zoom, posLen, posTab);
00060     int width = 0, height = 0, tmp = 0, rot = 0;
00061     PDFDoc * pdfdoc = ctrl->core->getPDFDoc();
00062     
00063     for(int i = 1; i <= posLen; ++i)
00064     {
00065         width = (int)(pdfdoc->getPageCropWidth(i) * zoom * 0.01 + 0.5);
00066         height = (int)(pdfdoc->getPageCropHeight(i) * zoom  * 0.01 + 0.5);
00067         rot = /*ctrl->settings.getRotate() + */pdfdoc->getPageRotate(i); 
00068         if (rot >= 360) rot -= 360; 
00069         else if (rot < 0) rot += 360;
00070         if (rot == 90 || rot == 270)
00071         {
00072             tmp = width; width = height; height = tmp;
00073         }
00074         
00075         if (bound.right < width)
00076         {
00077             bound.right = width;
00078         }
00079         posTab[i - 1].right = width;
00080         posTab[i - 1].top = bound.bottom;
00081         posTab[i - 1].bottom = posTab[i - 1].top + height;
00082         bound.bottom += height + 1;
00083     }
00084 
00085     // adjust x position to make it in the center of virtual screen
00086     for(int i = 1; i <= posLen; ++i)
00087     {
00088         posTab[i - 1].left = (bound.right - posTab[i - 1].right) / 2;
00089         posTab[i - 1].right += posTab[i - 1].left;
00090         // PV_LOGPRINTF("item %d:\t\t%d %d %d %d", i, posTab[i - 1].left, posTab[i - 1].top, 
00091         //    posTab[i - 1].right, posTab[i - 1].bottom);
00092     }
00093     
00094     return zoom;
00095 }

Here is the call graph for this function:

int CLayoutMgr::getPagesVisible ( int &  start,
int &  end,
const rectangle rect 
)

Definition at line 107 of file LayoutMgr.cpp.

00108 {
00109     start = -1; end = -1;
00110     int max = 0, tmp = 0, index = -1;
00111     for(int i = 0; i < posLen; ++i)
00112     {
00113         if (rect.bottom < posTab[i].top) return index;
00114         if ((tmp = rect.isIntersect(posTab[i])) > 0)
00115         {
00116             if (start == -1) 
00117             {
00118                 start = i + 1; end = start; 
00119             }
00120             else
00121             {
00122                 ++end;
00123             }
00124             if (max < tmp) { max = tmp; index = i + 1; }
00125         }
00126     }
00127     return index;
00128 }

Here is the call graph for this function:

int CLayoutMgr::hitTest ( const point pt,
const int  start,
const int  end 
)

Definition at line 135 of file LayoutMgr.cpp.

00136 {
00137     for(int i = start; i <= end; ++i)
00138     {
00139         if (posTab[i - 1].hitTest(pt))
00140         {
00141             return i;
00142         }
00143     }
00144     return -1;
00145 }

int CLayoutMgr::hitTest ( const int  x,
const int  y,
const int  start,
const int  end 
)

Definition at line 147 of file LayoutMgr.cpp.

00148 {
00149     for(int i = start; i <= end; ++i)
00150     {
00151         if (posTab[i - 1].hitTest(x, y))
00152         {
00153             return i;
00154         }
00155     }
00156     return -1;
00157 }

Here is the call graph for this function:

void CLayoutMgr::updatePageRect ( const int  x,
const int  y,
const int  width,
const int  height 
)

Definition at line 228 of file LayoutMgr.cpp.

00229 {
00230     bound.left = x; bound.top = y;
00231     bound.right = x + width; 
00232     bound.bottom = y + height;
00233 }

GBool CLayoutMgr::hitTest ( const int  x,
const int  y 
)

Definition at line 235 of file LayoutMgr.cpp.

00236 {
00237     return bound.hitTest(x, y);
00238 }

Here is the call graph for this function:

void CLayoutMgr::screenToVirtualScreen ( Controller ctrl,
rectangle rect 
)

Definition at line 162 of file LayoutMgr.cpp.

00163 {
00164     // to virtual screen
00165     rect.left += ctrl->settings.getScreenX();
00166     rect.top += ctrl->settings.getScreenY();
00167     rect.right += ctrl->settings.getScreenX();
00168     rect.bottom += ctrl->settings.getScreenY();
00169 }

Here is the call graph for this function:

void CLayoutMgr::screenToVirtualScreen ( Controller ctrl,
point pt 
)

Definition at line 171 of file LayoutMgr.cpp.

00172 {
00173     pt.x += ctrl->settings.getScreenX();
00174     pt.y += ctrl->settings.getScreenY();
00175 }

Here is the call graph for this function:

void CLayoutMgr::virtualScreenToScreen ( Controller ctrl,
const rectangle rect 
)

Definition at line 178 of file LayoutMgr.cpp.

00179 {
00180     ctrl->settings.setScreenX(rect.left);
00181     ctrl->settings.setScreenY(rect.top);
00182 }

Here is the call graph for this function:

void CLayoutMgr::getVirtualScreen ( rectangle rect  )  [inline]

Definition at line 60 of file LayoutMgr.h.

00060 { rect = bound; }

const rectangle& CLayoutMgr::getVirtualScreen (  )  const [inline]

Definition at line 61 of file LayoutMgr.h.

00061 { return bound; }

void CLayoutMgr::rotate ( Controller ctrl,
const int  angle 
)

Definition at line 187 of file LayoutMgr.cpp.

00188 {
00189     CPageInfo * page = ctrl->pageList.getPage(ctrl->settings.getCurrentPage());
00190     if (NULL == page) return;
00191 
00192     // calculate intersection
00193     rectangle rect; rect.left = 0; rect.top = 0; 
00194     rect.right = ctrl->settings.getScreenWidth();
00195     rect.bottom = ctrl->settings.getScreenHeight();
00196     if (ctrl->settings.getScreenX() > 0) rect.left = ctrl->settings.getScreenX();
00197     if (ctrl->settings.getScreenY() > 0) rect.top = ctrl->settings.getScreenY();
00198     if (rect.right > ctrl->settings.getScreenX() + page->bitmap->getWidth())
00199     {
00200         rect.right = ctrl->settings.getScreenX() + page->bitmap->getWidth();
00201     }
00202     if (rect.bottom > ctrl->settings.getScreenY() + page->bitmap->getHeight())
00203     {
00204         rect.bottom = ctrl->settings.getScreenY() + page->bitmap->getHeight();
00205     }
00206     point center;
00207     center.x = (rect.left + rect.right) / 2;
00208     center.y = (rect.top + rect.bottom) / 2;
00209     int distX = 0, distY = 0;
00210 
00211     // calculate the new position 
00212     if (angle == 90)
00213     {
00214         distX = center.x - ctrl->settings.getScreenX();
00215         distY = page->bitmap->getHeight() - center.y + ctrl->settings.getScreenY();
00216         ctrl->settings.setScreenX(center.x - distY);
00217         ctrl->settings.setScreenY(center.y - distX);
00218     }
00219     else if (angle == -90)
00220     {
00221         distX = page->bitmap->getWidth() - center.x + ctrl->settings.getScreenX();
00222         distY = center.y - ctrl->settings.getScreenY();
00223         ctrl->settings.setScreenX(center.x - distY);
00224         ctrl->settings.setScreenY(center.y - distX);
00225     }
00226 }

Here is the call graph for this function:


Member Data Documentation

Definition at line 33 of file LayoutMgr.h.

Definition at line 34 of file LayoutMgr.h.

int CLayoutMgr::posLen [private]

Definition at line 35 of file LayoutMgr.h.


The documentation for this class was generated from the following files:

Generated on Wed Feb 4 18:26:10 2009 by  doxygen 1.5.6