ManiaLib 1.0b1 API Reference

Source for file PageNavigator.class.php

Documentation is available at PageNavigator.class.php

  1. <?php
  2. /**
  3.  * @author Maxime Raoust
  4.  * @copyright 2009-2010 NADEO
  5.  * @package ManiaLib
  6.  */
  7.  
  8. /**
  9.  * Page Navigator
  10.  * Page navigation arrows at the bottom of the lists
  11.  * @package ManiaLib
  12.  * @subpackage GUIToolkit_Cards
  13.  */
  14. class PageNavigator extends GuiComponent
  15. {
  16.     /**
  17.      * @var Icons64x64_1 
  18.      */
  19.     public $arrowNext;
  20.     /**
  21.      * @var Icons64x64_1 
  22.      */
  23.     public $arrowPrev;
  24.     /**
  25.      * @var Icons64x64_1 
  26.      */
  27.     public $arrowFastNext;
  28.     /**
  29.      * @var Icons64x64_1 
  30.      */
  31.     public $arrowFastPrev;
  32.     /**
  33.      * @var Icons64x64_1 
  34.      */
  35.     public $arrowLast;
  36.     /**
  37.      * @var Icons64x64_1 
  38.      */
  39.     public $arrowFirst;
  40.     /**
  41.      * @var Label 
  42.      */
  43.     public $text;
  44.  
  45.     public $arrowNoneStyle = Icons64x64_1::StarGold;
  46.     public $arrowNextStyle = Icons64x64_1::ArrowNext;
  47.     public $arrowPrevStyle = Icons64x64_1::ArrowPrev;
  48.     public $arrowFastNextStyle = Icons64x64_1::ArrowFastNext;
  49.     public $arrowFastPrevStyle = Icons64x64_1::ArrowFastPrev;
  50.     public $arrowFirstStyle = Icons64x64_1::ArrowFirst;
  51.     public $arrowLastStyle = Icons64x64_1::ArrowLast;
  52.  
  53.     /**#@+
  54.      * @ignore
  55.      */
  56.     protected $showLast;
  57.     protected $showFastNext;
  58.     protected $showText;
  59.     protected $pageNumber;
  60.     protected $currentPage;
  61.     /**#@-*/
  62.  
  63.     function __construct($iconSize 5)
  64.     {
  65.         $this->arrowNext = new Icon64($iconSize);
  66.         $this->arrowPrev = new Icon64($iconSize);
  67.         $this->arrowFastNext = new Icon64($iconSize);
  68.         $this->arrowFastPrev = new Icon64($iconSize);
  69.         $this->arrowLast = new Icon64($iconSize);
  70.         $this->arrowFirst = new Icon64($iconSize);
  71.         $this->text = new Label(5);
  72.         
  73.         $this->showLast false;
  74.         $this->showFastNext false;
  75.         $this->showText true;
  76.         
  77.         $this->arrowNext->setSubStyle($this->arrowNoneStyle);
  78.         $this->arrowPrev->setSubStyle($this->arrowNoneStyle);
  79.         $this->arrowFastNext->setSubStyle($this->arrowNoneStyle);
  80.         $this->arrowFastPrev->setSubStyle($this->arrowNoneStyle);
  81.         $this->arrowLast->setSubStyle($this->arrowNoneStyle);
  82.         $this->arrowFirst->setSubStyle($this->arrowNoneStyle);
  83.     }
  84.     
  85.     /**
  86.      * Sets the size of the navigation icons
  87.      */
  88.     function setSize($iconSize 5$nullValue=null)
  89.     {
  90.         $this->arrowNext->setSize($iconSize$iconSize);
  91.         $this->arrowPrev->setSize($iconSize$iconSize);
  92.         $this->arrowFastNext->setSize($iconSize$iconSize);
  93.         $this->arrowFastPrev->setSize($iconSize$iconSize);
  94.         $this->arrowLast->setSize($iconSize$iconSize);
  95.         $this->arrowFirst->setSize($iconSize$iconSize);
  96.     }
  97.     
  98.     /**
  99.      * Sets the page number
  100.      */
  101.     function setPageNumber($pageNumber)
  102.     {
  103.         $this->pageNumber $pageNumber;
  104.     }
  105.     
  106.     /**
  107.      * Sets the current page
  108.      */
  109.     function setCurrentPage($currentPage)
  110.     {
  111.         $this->currentPage $currentPage;
  112.     }
  113.     
  114.     /**
  115.      * Shows or hides the "go to first/last" navigation icons
  116.      */
  117.     function showLast($show true)
  118.     {
  119.         $this->showLast $show;
  120.     }
  121.     
  122.     /**
  123.      * Returns whether the "go to first/last" navigation icons are shown
  124.      */
  125.     function isLastShown()
  126.     {
  127.         return $this->showLast;
  128.     }
  129.     
  130.     /**
  131.      * Shows or hides the "fast prev/next" navigation icons
  132.      */
  133.     function showFastNext($show true)
  134.     {
  135.         $this->showFastNext $show;
  136.     }
  137.     
  138.     /**
  139.      * Returns whether the "fast prev/next" navigation icons are shown
  140.      */
  141.     function isFastNextShown()
  142.     {
  143.         return $this->showFastNext;
  144.     }
  145.     
  146.     /**
  147.      * Shows or hides the text. Note that if the current page or the page number
  148.      * isn't declared, the text won't be shown
  149.      */
  150.     function showText($show true)
  151.     {
  152.         $this->showText $show;
  153.     }
  154.     
  155.     /**
  156.      * Returns whether the text is shown
  157.      */
  158.     function isTextShown()
  159.     {
  160.         return $this->showText;
  161.     }
  162.     
  163.     /**
  164.      * Saves the PageNavigator in the GUI objects stack
  165.      */
  166.     function save()
  167.     {
  168.         // Show / hide text
  169.         if(!$this->currentPage || !$this->pageNumber)
  170.         {
  171.             $this->showText(false);
  172.         }
  173.         
  174.         // Auto show fast next / last
  175.         if($this->arrowFirst->hasLink(|| $this->arrowLast->hasLink() )
  176.         {
  177.             $this->showLast();
  178.         }
  179.         if($this->arrowFastNext->hasLink(|| $this->arrowFastPrev->hasLink() )
  180.         {
  181.             $this->showFastNext();
  182.         }
  183.         
  184.         // Arrow styles
  185.         if($this->arrowNext->hasLink())
  186.         {
  187.             $this->arrowNext->setSubStyle($this->arrowNextStyle);
  188.         
  189.         if($this->arrowPrev->hasLink())
  190.         {
  191.              $this->arrowPrev->setSubStyle($this->arrowPrevStyle);
  192.         }
  193.         if($this->arrowNext->hasLink(&& $this->arrowFastNext->hasLink())
  194.         {
  195.             $this->arrowFastNext->setSubStyle($this->arrowFastNextStyle);
  196.         }
  197.         else
  198.         {
  199.             $this->arrowFastNext->setManialink(null);
  200.         
  201.         if($this->arrowPrev->hasLink(&& $this->arrowFastPrev->hasLink())
  202.         {
  203.              $this->arrowFastPrev->setSubStyle($this->arrowFastPrevStyle);
  204.         }
  205.         else
  206.         {
  207.             $this->arrowFastNext->setManialink(null);
  208.         
  209.         if($this->arrowNext->hasLink(&& $this->arrowLast->hasLink())
  210.         {
  211.              $this->arrowLast->setSubStyle($this->arrowLastStyle);
  212.         }
  213.         if($this->arrowPrev->hasLink(&& $this->arrowFirst->hasLink())
  214.         {
  215.              $this->arrowFirst->setSubStyle($this->arrowFirstStyle);
  216.         }
  217.  
  218.         // Text
  219.         $this->text->setStyle("TextStaticSmall");
  220.         $this->text->setText($this->currentPage "/" $this->pageNumber);
  221.  
  222.         // Positioning in relation to the center of the containing frame
  223.         $this->text->setAlign("center""center");
  224.         $this->text->setPositionZ(1);
  225.  
  226.         $this->arrowNext->setValign("center");
  227.         $this->arrowFastNext->setValign("center");
  228.         $this->arrowLast->setValign("center");
  229.  
  230.         $this->arrowNext->setPosition(($this->text->getSizeX(2101);
  231.         $this->arrowFastNext->setPosition($this->arrowNext->getPosX($this->arrowNext->getSizeX()01);
  232.         $this->arrowLast->setPosition(
  233.             $this->arrowNext->getPosX(
  234.             (int)$this->showFastNext*$this->arrowFastNext->getSizeX(
  235.             $this->arrowNext->getSizeX()
  236.             01);
  237.  
  238.         $this->arrowPrev->setAlign("right""center");
  239.         $this->arrowFastPrev->setAlign("right""center");
  240.         $this->arrowFirst->setAlign("right""center");
  241.  
  242.         $this->arrowPrev->setPosition(-($this->text->getSizeX()/2101);
  243.         $this->arrowFastPrev->setPosition($this->arrowPrev->getPosX($this->arrowPrev->getSizeX()01);
  244.         $this->arrowFirst->setPosition(
  245.             $this->arrowPrev->getPosX(-
  246.             (int)$this->showFastNext*$this->arrowFastPrev->getSizeX(
  247.             $this->arrowPrev->getSizeX(),
  248.             01);
  249.  
  250.         // Save the gui
  251.         Manialink::beginFrame($this->posX$this->posY$this->posZ);
  252.         {
  253.             if ($this->showText)
  254.             {
  255.                 $this->text->save();
  256.             }
  257.             $this->arrowNext->save();
  258.             $this->arrowPrev->save();
  259.             if ($this->showLast)
  260.             {
  261.                 $this->arrowFirst->save();
  262.                 $this->arrowLast->save();
  263.             }
  264.             if ($this->showFastNext)
  265.             {
  266.                 $this->arrowFastNext->save();
  267.                 $this->arrowFastPrev->save();
  268.             }
  269.         }
  270.         Manialink::endFrame();
  271.     }
  272. }
  273.  
  274. ?>