示例#1
0
        //Obtains the clicked item, calls that items click handler, and sets focus.
        private void handleClick(MouseKeyBinding.MouseButton button)
        {
            if (items == null)
            {
                return;
            }

            //Find the last (top) clicked item
            InputComponent ic          = graphics.engine.inputComponent;
            Vector2        pos         = ic.getMousePosition();
            GUIItem        clickedItem = getItemAt(pos);

            if (clickedItem != null)
            {
                clickedItem.handleMouseDown(pos, button);
            }

            //Set Focus
            if (focused != null)
            {
                focused.onBlur();
            }
            if (clickedItem == null || clickedItem.focusable)
            {
                focused = clickedItem;
            }
            if (focused != null)
            {
                focused.onFocus();
            }
        }
        public void performLayout()
        {
            if (orientation == ScrollDirection.HORIZONTAL)
            {
                for (int i = 0; i < filledSpots; i++)
                {
                    if ((i) % rows >= currentPos && i % rows < currentPos + columns)
                    {
                        GUIItem square = this.items[i];//there was a +4 here i assume for commented out constructor, WHY!??! -James

                        square.pos = new Vector2(padding + pos.x + ((i) % rows - currentPos) * cellDim.x, padding + pos.y + ((i) / rows) * cellDim.y);
                    }
                }
            }
            if (orientation == ScrollDirection.VERTICAL)
            {
                for (int i = 0; i < filledSpots; i++)
                {
                    if ((i) % columns >= currentPos && i % columns < currentPos + rows)
                    {
                        GUIItem square = this.items[i]; //there was a +4 here i assume for commented out constructor, WHY!??! -James
                        square.pos = new Vector2(padding + pos.x + ((i) % columns) * cellDim.x, padding + pos.y + ((i) / columns - currentPos) * cellDim.y);
                    }
                }
            }
        }
 public void resetAllBut(GUIItem exceptionalItem)
 {
     foreach (GUIItem item in toolButtonsDialog.items)
     {
         if (item is GUIButton && (item as GUIButton) != exceptionalItem)
         {
             (item as GUIButton).resetImg();
         }
     }
 }
示例#4
0
        //Gets the GUIItem at the given location, or returns null if none
        public GUIItem getItemAt(Vector2 pos)
        {
            GUIItem lastItem = null;

            foreach (GUIItem item in items)
            {
                if (item.isOver(pos))
                {
                    lastItem = item;
                }
            }

            return(lastItem);
        }
示例#5
0
        /**
         * Add the item to the GUI
         */
        public virtual void add(GUIItem item)
        {
            if (item == null)
            {
                return;
            }
            GUIControl control = item as GUIControl;

            if (control != null)
            {
                add(control);
            }
            else
            {
                items.Add(item);
            }
        }
示例#6
0
        /**
         * Attempts to remove the item from the GUI
         */
        public virtual void remove(GUIItem item)
        {
            if (item == null)
            {
                return;
            }
            GUIControl control = item as GUIControl;

            if (control != null)
            {
                remove(control);
            }
            else
            {
                try
                {
                    items.Remove(item);
                }
                catch (Exception e) { }
            }
        }
 /**
  * Add item from this control
  *
  * @param item The item to add
  */
 public virtual void remove(GUIItem item)
 {
     items.Remove(item);
 }
 /**
  * Add item to this control
  *
  * @param item The item to add
  */
 public virtual void add(GUIItem item)
 {
     item.pos += this.pos;
     items.Add(item);
 }
        /**
         * Lays out the list
         *
         * @param startPos If not centering, specifies the position of the left-most/top-most corner of the first item along the alignment edge, e.g., the top-right corner if align == RIGHT.
         *                 If centering, specifies the position of the center of the left-most/top-most edge of the first item, depending on orientation.
         *                 To summarize, it's where you want the first item to go, try things until you get it right. TODO: Clean up this description.
         */
        public override void performLayout(Vector2 startPos)
        {
            if (items == null || items.Count < 2)
            {
                return;
            }

            GUIItem prevItem = null;

            foreach (GUIItem item in items)
            {
                // Handle first iteration
                if (prevItem == null)
                {
                    if (orientation == Orientation.HORIZONTAL)
                    {
                        item.left = startPos.x;

                        if (align == Align.TOP)
                        {
                            item.top = startPos.y;
                        }
                        else if (align == Align.BOTTOM)
                        {
                            item.bot = startPos.y;
                        }
                        else if (align == Align.CENTER)
                        {
                            // TODO: Handle centering
                            throw new NotImplementedException("Haven't written CENTER yet");
                        }
                        else
                        {
                            throw new Exception("Invalid Align/Orientation combination.");
                        }
                    }
                    else      // orientation == Orientation.VERTICAL
                    {
                        item.top = startPos.y;

                        if (align == Align.LEFT)
                        {
                            item.left = startPos.x;
                        }
                        else if (align == Align.RIGHT)
                        {
                            item.right = startPos.x;
                        }
                        else if (align == Align.CENTER)
                        {
                            // TODO: Handle centering
                            throw new NotImplementedException("Haven't written CENTER yet");
                        }
                        else
                        {
                            throw new Exception("Invalid Align/Orientation combination.");
                        }
                    }
                }
                else      // prevItem != null
                {
                    if (orientation == Orientation.HORIZONTAL)
                    {
                        item.left = prevItem.right;

                        if (align == Align.TOP)
                        {
                            item.top = prevItem.top;
                        }
                        else if (align == Align.BOTTOM)
                        {
                            item.bot = prevItem.bot;
                        }
                        else if (align == Align.CENTER)
                        {
                            // TODO: Handle centering
                            throw new NotImplementedException("Haven't written CENTER yet");
                        }
                        else
                        {
                            throw new Exception("Invalid Align/Orientation combination.");
                        }
                    }
                    else      // orientation == Orientation.VERTICAL
                    {
                        item.top = prevItem.bot;

                        if (align == Align.LEFT)
                        {
                            item.left = prevItem.left;
                        }
                        else if (align == Align.RIGHT)
                        {
                            item.right = prevItem.right;
                        }
                        else if (align == Align.CENTER)
                        {
                            // TODO: Handle centering
                            throw new NotImplementedException("Haven't written CENTER yet");
                        }
                        else
                        {
                            throw new Exception("Invalid Align/Orientation combination.");
                        }
                    }
                }

                prevItem = item;
            }
        }
 /**
  * Remove an item
  *
  * @param item The item to remove
  */
 public void removeItem(GUIItem item)
 {
     items.Add(item);
 }
 /**
  * Add an item
  *
  * @param item The item to add
  */
 public virtual void addItem(GUIItem item)
 {
     items.Add(item);
 }
 public virtual void Add(GUIItem the)
 {
     this.children.Add(the);
 }
 //Overrides manually adding items to this control.
 public override void add(GUIItem item)
 {
 }
 public override void remove(GUIItem item)
 {
     base.remove(item);
     filledSpots--;
 }
 public override void add(GUIItem item)
 {
     this.items.Add(item);
     filledSpots++;
 }