home *** CD-ROM | disk | FTP | other *** search
/ Game Level Design / GLDesign.bin / Software / UnrealEngine2Runtime / UE2Runtime-22262001_Demo.exe / GUI / Classes / GUIHorzList.uc < prev    next >
Text File  |  2003-06-30  |  5KB  |  293 lines

  1. // ====================================================================
  2. //  Class:  GUI.GUIHorzList
  3. //  Parent: GUI.GUIListBase
  4. //
  5. //  <Enter a description here>
  6. // ====================================================================
  7.  
  8. class GUIHorzList extends GUIListBase
  9.         Native;
  10.  
  11. cpptext
  12. {
  13.     void Draw(UCanvas* Canvas);    
  14. }
  15.         
  16. function InitComponent(GUIController MyController, GUIComponent MyOwner)
  17. {
  18.     Super.Initcomponent(MyController, MyOwner);
  19.  
  20.     OnKeyType=InternalOnKeyType;
  21.     OnKeyEvent=InternalOnKeyEvent;
  22.     OnXControllerEvent=InternalOnXControllerEvent;
  23.     OnClick=InternalOnClick;
  24. }    
  25.         
  26. function bool InternalOnClick(GUIComponent Sender)
  27. {
  28.     local int NewIndex, Col;
  29.  
  30.     if ( ( !IsInClientBounds() ) || (ItemsPerPage==0) )
  31.         return false;
  32.         
  33.     // Get the Col
  34.     
  35.     Col = Controller.MouseX - ClientBounds[0];
  36.     NewIndex = Top + (Col / ItemWidth);
  37.     
  38.     if (NewIndex >= ItemCount)
  39.         return false;
  40.         
  41.     SetIndex(NewIndex);
  42.     return true;
  43. }
  44.  
  45. function bool InternalOnKeyType(out byte Key, optional string Unicode)
  46. {
  47.     // Add code to jump to next line with Char    
  48.         
  49.     return true;
  50. }
  51.  
  52. function bool InternalOnKeyEvent(out byte Key, out byte State, float delta)
  53. {
  54.  
  55.     if (ItemsPerPage==0) return false;
  56.  
  57.     
  58.     if ( (Key==0x25 || Key==0x64) && (State==1) )    // Left Arrow
  59.     {
  60.         ScrollLeft();
  61.         return true;
  62.     }
  63.     
  64.     if ( (Key==0x27 || Key==0x66) && (State==1) ) // Left Arrow
  65.     {
  66.         ScrollRight();
  67.         return true;
  68.     }
  69.     
  70.     if ( (Key==0x24 || Key==0x67) && (State==1) ) // Home
  71.     {
  72.         Home();
  73.         return true;
  74.     }
  75.     
  76.     if ( (Key==0x23 || Key==0x61) && (State==1) ) // End
  77.     {
  78.         End();
  79.         return true;
  80.     }
  81.     
  82.     if ( (Key==0x21 || Key==0x69) && (State==1) ) // PgUp
  83.     {
  84.         PgUp();
  85.         return true;
  86.     }
  87.     
  88.     if ( (Key==0x22 || Key==0x63) && (State==1) ) // PgDn
  89.     {
  90.         PgDn();
  91.         return true;
  92.     }
  93.     
  94.     if ( (key==0xEC) && (State==3) )
  95.     {
  96.     
  97.         WheelUp();
  98.         return true;
  99.     }
  100.     
  101.     if ( (key==0xED) && (State==3) )
  102.     {
  103.     
  104.         WheelDown();
  105.         return true;
  106.     }
  107.     
  108.     
  109.     return false;
  110. }
  111.  
  112.  
  113. function WheelUp()
  114. {
  115.     if (MyScrollBar!=None)
  116.         GUIHorzScrollBar(MyScrollBar).WheelUp();
  117.     else
  118.     {
  119.         if (!Controller.CtrlPressed)
  120.             ScrollLeft();
  121.         else
  122.             PgUp();
  123.     }
  124. }
  125.  
  126. function bool InternalOnXControllerEvent(byte Id, eXControllerCodes iCode)
  127. {
  128.  
  129.     if (ItemsPerPage==0) return false;
  130.  
  131.     if (iCode==XC_Left || iCode==XC_PadLeft)
  132.     {
  133.         ScrollLeft();
  134.         return true;
  135.     }
  136.     else if (iCode==XC_Right || iCode==XC_PadRight)
  137.     {
  138.         ScrollRight();
  139.         return true;
  140.     }
  141.  
  142.     else if (iCode==XC_Black)
  143.     {
  144.         Home();
  145.         return true;
  146.     }
  147.  
  148.     else if (iCode==XC_White)
  149.     {
  150.         End();
  151.         return true;
  152.     }
  153.  
  154.     else if (iCode==XC_X)
  155.     {
  156.         PgDn();
  157.         return true;
  158.     }
  159.  
  160.     else if (iCode==XC_Y)
  161.     {
  162.         PgUp();
  163.         return true;
  164.     }
  165.  
  166.     else if (iCode==XC_Start)
  167.     {
  168.         OnClick(self);
  169.         return true;
  170.     }
  171.     return false;
  172. }
  173.  
  174.  
  175. function WheelDown()
  176. {
  177.     if (MyScrollBar!=None)
  178.         GUIHorzScrollBar(MyScrollBar).WheelDown();
  179.     else
  180.     {
  181.         if (!Controller.CtrlPressed)
  182.             ScrollRight();
  183.         else
  184.             PgDn();
  185.     }
  186. }
  187.     
  188. function ScrollLeft()
  189. {
  190.     if ( (ItemCount<2) || (Index==0) ) return;
  191.  
  192.     Index = max(0,Index-1);
  193.  
  194.     if ( (Index<Top) || (Index>Top+ItemsPerPage) )
  195.     {
  196.         Top = Index;
  197.         MyScrollBar.AlignThumb();
  198.     }
  199. }
  200.  
  201. function ScrollRight()
  202. {
  203.     if ( (ItemCount<2) || (Index==ItemCount-1) )    return;
  204.     
  205.     Index = min(Index+1,ItemCount-1);
  206.     if (Index<Top)
  207.     {
  208.         Top = Index;
  209.         MyScrollBar.AlignThumb();
  210.     }
  211.     else if (Index>=Top+ItemsPerPage)
  212.     {
  213.         Top = Index-ItemsPerPage+1;
  214.         MyScrollBar.AlignThumb();
  215.     }
  216.     
  217. }
  218.     
  219. function Home()
  220. {
  221.     if (ItemCount<2)    return;    
  222.  
  223.     SetIndex(0);
  224.     Top = 0;
  225.     MyScrollBar.AlignThumb();
  226.     
  227. }
  228.  
  229. function End()
  230. {
  231.     if (ItemCount<2)    return;    
  232.  
  233.     Top = ItemCount - ItemsPerPage;
  234.     if (Top<0)
  235.         Top = 0;
  236.         
  237.     SetIndex(ItemCount-1);
  238.     MyScrollBar.AlignThumb();
  239. }    
  240.  
  241. function PgUp()
  242. {
  243.  
  244.     if (ItemCount<2)    return;
  245.  
  246.     Index -= ItemsPerPage;
  247.  
  248.     // Adjust to bounds
  249.     if (Index < 0)
  250.         Index = 0;
  251.  
  252.     // If new index 
  253.     if (Top + ItemsPerPage <= Index)        // If index is forward but not visible, jump to it
  254.         Top = Index;
  255.     else if (Index + ItemsPerPage < Top)    // Item is way too far
  256.         Top = Index;
  257.     else if (Index < Top)    // Item is 1 page or less away
  258.         SetTopItem(Top - ItemsPerPage);
  259.  
  260.     SetIndex(Index);
  261.     MyScrollBar.AlignThumb();
  262. }
  263.  
  264. function PgDn()
  265. {
  266.  
  267.     if (ItemCount<2)    return;
  268.  
  269.     // Select item 1 page away from current selection
  270.     Index += ItemsPerPage;
  271.  
  272.     // Adjust to bounds
  273.     if (Index >= ItemCount)
  274.         Index = ItemCount-1;
  275.  
  276.     
  277.     if (Index < Top)  // If item is still before Top Item, go to it
  278.         Top = Index;
  279.     else if (Index - Top - ItemsPerPage >= ItemsPerPage)    // Too far away
  280.         SetTopItem(Index);
  281.     else if (Index - Top >= ItemsPerPage) // Just 1 page away
  282.         SetTopItem(Top + ItemsPerPage);
  283.  
  284.     SetIndex(Index);
  285.     MyScrollBar.AlignThumb();
  286. }    
  287.  
  288.         
  289.  
  290. defaultproperties
  291. {
  292. }
  293.