View Single Post
  #3  
Old 07-11-2010, 04:37 PM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
I usually just keep track of the index of the currently selected item (the one in the middle), and then increase or decrease that index whenever the user "slides" the list right or left and mod by the size of the array.

For example,
PHP Code:
function onCreated() {
  
temp.arr = {"a""b""c""d""e""f"};
  
temp.sel 0// The index of the item in the middle

  
this.printDisplay(temp.arrtemp.sel); // echoes "f a b"

  /* Now, slide to the left */
  
temp.sel = (temp.sel 1) % temp.arr.size(); // is now 1, so "b" is the middle item
  
  
this.printDisplay(temp.arrtemp.sel); // echoes "a b c"
  
  /*  Now, slide to the right twice 
      Assuming you'd always slide one at a time 
      whenever the user presses a key */
      
  
temp.sel = (temp.sel 1) % temp.arr.size(); // is now 0, "a" is in the middle again
  
temp.sel = (temp.sel 1) % temp.arr.size(); // is now 5, "f" is in the middle
  
  
this.printDisplay(temp.arrtemp.sel); // echoes "e f a"
}

/* This is generally how I would show what's on the 
   left and right of the selected item. You can do your image
   drawing or whatever here.
    
   If you have a special case for the one in the middle, such
   as having it highlighted or something, just check 
     if (temp.i == 0) { <Stuff for the middle item here> }
*/

function printDisplay(arrsel) {
  
temp.str "";
  
  for (
temp.= -1temp.=< 1temp.++) {
    
temp.str @= temp.arr[(temp.sel temp.i) % temp.arr.size()] @ " ";
  }
  
  echo(
temp.str);

__________________
Reply With Quote