Ejemplo n.º 1
0
        /// <summary>
        /// Finds the bounds for the specified item.
        /// </summary>
        /// <param name="xIndex">The item x index.</param>
        /// <param name="yIndex">The item y index.</param>
        /// <returns>The item bounds.</returns>
        private Rectangle ItemBounds(int xIndex, int yIndex)
        {
            KListItem item  = this[xIndex, yIndex];
            int       itemX = 0; //(itemSize.Width * xIndex);
            int       itemY = 0; //(itemSize.Height * yIndex);

            if (m_layout == KListLayout.Vertical)
            {
                Size itemSize = new Size(this.Width, (item.Height > 0 ? item.Height : DefaultItemHeight));
                itemY = (yIndex > 0 ? this[xIndex, yIndex - 1].Bounds.Bottom : 0);
                return(new Rectangle(0, itemY, this.Width, itemSize.Height));
            }
            else if (m_layout == KListLayout.Horizontal)
            {
                Size itemSize = new Size((item.Width > 0 ? item.Width : DefaultItemWidth), this.Height);
                itemX = (xIndex > 0 ? this[xIndex - 1, yIndex].Bounds.Right : 0);
                return(new Rectangle(itemX, 0, itemSize.Width, this.Height));
            }
            else
            {
                Size itemSize = new Size((item.Width > 0 ? item.Width : DefaultItemWidth), (item.Height > 0 ? item.Height : DefaultItemHeight));
                itemX = (xIndex > 0 ? this[xIndex, yIndex].Bounds.Right : 0);
                itemY = (yIndex > 0 ? this[xIndex, yIndex].Bounds.Bottom : 0);
                return(new Rectangle(itemX, itemY, itemSize.Width, itemSize.Height));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds an item.
        /// </summary>
        /// <param name="text">The text for the item.</param>
        /// <param name="value">A value related to the item.</param>
        public void AddItem(string text, object value, int size)
        {
            if (m_layout == KListLayout.Grid)
            {
                throw new NotSupportedException("List is not in grid mode");
            }

            KListItem item = new KListItem();

            item.Text   = text;
            item.Value  = value;
            item.XIndex = m_layout == KListLayout.Vertical ? 0 : m_items.Count;
            item.YIndex = m_layout == KListLayout.Horizontal ? 0 :
                          m_items.Count > 0 ? m_items[0].Count : 0;

            if (m_layout == KListLayout.Vertical || m_layout == KListLayout.Grid)
            {
                item.Height = size;
            }
            if (m_layout == KListLayout.Horizontal || m_layout == KListLayout.Grid)
            {
                item.Width = size;
            }



            AddItem(item);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Selects an item.
        /// </summary>
        private void SelectItem(int xIndex, int yIndex)
        {
            Point selectedIndex = new Point(xIndex, yIndex);

            if (selectedIndex != m_selectedIndex)
            {
                KListItem item = null;
                if (m_items.Count > selectedIndex.X &&
                    m_items[selectedIndex.X].Count > selectedIndex.Y)
                {
                    item = m_items[selectedIndex.X][selectedIndex.Y];

                    if (m_selectedItem != null)
                    {
                        m_selectedItem.Selected = false;
                    }
                    m_selectedIndex         = selectedIndex;
                    m_selectedItem          = item;
                    m_selectedItem.Selected = true;

                    OnSelectedItemChanged(new EventArgs());
                }
            }

            m_velocity.X = 0;
            m_velocity.Y = 0;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Removes an item.
 /// </summary>
 /// <param name="item">The item.</param>
 public void RemoveItem(KListItem item)
 {
     if (m_items.Count > item.XIndex &&
         m_items[item.XIndex].Count > item.YIndex)
     {
         m_items[item.XIndex].RemoveAt(item.YIndex);
     }
     Reset();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Invalidates the item (when visible).
        /// </summary>
        /// <param name="item">The item.</param>
        public void Invalidate(KListItem item)
        {
            Rectangle itemBounds = item.Bounds;

            itemBounds.Offset(-m_offset.X, -m_offset.Y);
            if (new Rectangle(0, 0, this.Width, this.Height).IntersectsWith(itemBounds))
            {
                Invalidate(itemBounds);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Adds an item.
 /// </summary>
 /// <param name="item">The item.</param>
 internal void AddItem(KListItem item)
 {
     item.Parent   = this;
     item.Selected = false;
     if (m_items.Count <= item.XIndex)
     {
         m_items.Add(new List <KListItem>());
     }
     m_items[item.XIndex].Add(item);
     item.Bounds = ItemBounds(item.XIndex, item.YIndex);
     Reset();
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds an item.
        /// </summary>
        /// <param name="x">The x position.</param>
        /// <param name="y">The y position.</param>
        /// <param name="text">The text for the item.</param>
        /// <param name="value">A value related to the item.</param>
        private void AddItem(int x, int y, string text, object value)
        {
            if (m_layout != KListLayout.Grid)
            {
                throw new NotSupportedException("List is in grid mode");
            }

            KListItem item = new KListItem();

            item.Text   = text;
            item.Value  = value;
            item.XIndex = x;
            item.YIndex = y;
            AddItem(item);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Ensures that the item is visible.
        /// </summary>
        /// <param name="item">A KListItem to make visible.</param>
        public void EnsureVisible(KListItem item)
        {
            if (item != null)
            {
                if ((-m_offset.X) + item.Bounds.Right > this.Width)
                {
                    m_offset.X = item.Bounds.X - (this.Width - item.Bounds.Width);
                }
                if ((-m_offset.X) + item.Bounds.X < 0)
                {
                    m_offset.X = item.Bounds.X;
                }

                if ((-m_offset.Y) + item.Bounds.Bottom > this.Height)
                {
                    m_offset.Y = item.Bounds.Y - (this.Height - item.Bounds.Height);
                }
                if ((-m_offset.Y) + item.Bounds.Y < 0)
                {
                    m_offset.Y = item.Bounds.Y;
                }
            }
            else
            {
                //do we need to reset offset?
                //m_offset.X = 0;
                //m_offset.Y = 0;
            }
            if (m_offset.X > MaxXOffset)
            {
                m_offset.X = MaxXOffset;
            }
            if (m_offset.Y > MaxYOffset)
            {
                m_offset.Y = MaxYOffset;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Called when the user releases a mouse button.
        /// </summary>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            KListItem item = FindItem(m_mouseDown.X, m_mouseDown.Y);

            if (item != null)
            {
                Size itemSize = item.Bounds.Size;
                // Did the click end on the same item it started on?
                bool sameX = Math.Abs(e.X - m_mouseDown.X) < itemSize.Width;
                bool sameY = Math.Abs(e.Y - m_mouseDown.Y) < itemSize.Height;

                if ((m_layout == KListLayout.Vertical && sameY) ||
                    (m_layout == KListLayout.Horizontal && sameX) ||
                    (m_layout == KListLayout.Grid && sameX && sameY))
                {
                    // Yes, so select that item.
                    //Point selectedIndex = FindIndex(e.X, e.Y);
                    //SelectItem(selectedIndex.X, selectedIndex.Y);
                    if (item == m_selectedItem)
                    {
                        OnSelectedItemClicked(new EventArgs());
                    }
                    SelectItem(item.XIndex, item.YIndex);
                }
                else
                {
                    m_timer.Enabled = true;
                }

                m_mouseDown.Y = -1;
                Capture       = false;

                Invalidate();
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Paints the control.
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (m_backBuffer != null)
            {
                if (Skinnable && !Extensions.IsDesignMode(this))
                {
                    m_backBuffer.Clear(Skin.Current.ControlBackColor);
                }
                else
                {
                    m_backBuffer.Clear(BackColor);
                }


                base.OnPaint(new PaintEventArgs(m_backBuffer, e.ClipRectangle));

                KListItem startItem = FindItem(0, 0);
                if (lastItemPaint == null)
                {
                    lastItemPaint = startItem;
                }
                else if (lastItemPaint != startItem)
                {
                    Tenor.Mobile.Device.Device.HapticSoft();
                    lastItemPaint = startItem;
                }

                List <List <KListItem> > .Enumerator xEnumerator = m_items.GetEnumerator();
                bool moreX = xEnumerator.MoveNext();
                int  i     = 0;
                while (moreX && i < startItem.XIndex)
                {
                    moreX = xEnumerator.MoveNext();
                    i++;
                }

                while (moreX)
                {
                    List <KListItem> yList = xEnumerator.Current;
                    if (yList != null)
                    {
                        List <KListItem> .Enumerator yEnumerator = yList.GetEnumerator();
                        bool moreY = yEnumerator.MoveNext();
                        int  j     = 0;
                        while (moreY && j < startItem.YIndex)
                        {
                            moreY = yEnumerator.MoveNext();
                            j++;
                        }

                        while (moreY)
                        {
                            KListItem item = yEnumerator.Current;
                            if (item != null)
                            {
                                Rectangle itemRect = item.Bounds;
                                itemRect.Offset(-m_offset.X, -m_offset.Y);
                                if (new Rectangle(0, 0, this.Width, this.Height).IntersectsWith(itemRect))
                                {
                                    if (this.DrawSeparators)
                                    {
                                        using (SolidBrush whitePen = new SolidBrush(SeparatorColor))
                                        {
                                            if (m_layout == KListLayout.Vertical || m_layout == KListLayout.Grid)
                                            {
                                                int borderSize = Convert.ToInt32(1 * scaleFactor.Height);
                                                //m_backBuffer.DrawLine(whitePen, itemRect.Left, itemRect.Top, itemRect.Right, itemRect.Top);
                                                Rectangle rect = new Rectangle(itemRect.Left, itemRect.Bottom - borderSize, itemRect.Width, borderSize);
                                                m_backBuffer.FillRectangle(whitePen, rect);
                                                //m_backBuffer.DrawLine(whitePen, itemRect.Left, itemRect.Bottom - 1, itemRect.Right, itemRect.Bottom - 1);
                                            }
                                            if (m_layout == KListLayout.Horizontal || m_layout == KListLayout.Grid)
                                            {
                                                int borderSize = Convert.ToInt32(1 * scaleFactor.Width);
                                                //m_backBuffer.DrawLine(whitePen, itemRect.Left, itemRect.Top, itemRect.Left, itemRect.Bottom);
                                                Rectangle rect = new Rectangle(itemRect.Right - borderSize, itemRect.Top, borderSize, itemRect.Height);
                                                m_backBuffer.FillRectangle(whitePen, rect);
                                                //m_backBuffer.DrawLine(whitePen, itemRect.Right - 1, itemRect.Top, itemRect.Right - 1, itemRect.Bottom);
                                            }
                                        }
                                    }

                                    if (Skinnable && m_layout == KListLayout.Vertical && !Extensions.IsDesignMode(this))
                                    {
                                        Skin.Current.DrawListItemBackground(m_backBuffer, itemRect, item.YIndex, item.Selected);
                                    }

                                    if (DrawItem == null)
                                    {
                                        item.Render(m_backBuffer, itemRect);
                                    }
                                    else
                                    {
                                        DrawItemEventArgs drawArgs = new DrawItemEventArgs()
                                        {
                                            Graphics = m_backBuffer, Item = item, Bounds = itemRect
                                        };
                                        OnDrawItem(drawArgs);
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }

                            moreY = yEnumerator.MoveNext();
                        }
                    }

                    moreX = xEnumerator.MoveNext();

                    if (DrawScrollbar)
                    {
                        int scrollSize = 3;

                        if ((m_layout == KListLayout.Vertical || m_layout == KListLayout.Grid) && MaxYOffset > 0)
                        {
                            int scrollHeight = (this.Height * 100) / (MaxYOffset + this.Height); // percentage

                            if (scrollHeight < 100)
                            {
                                int scrollWidth = Convert.ToInt32(scrollSize * scaleFactor.Width);
                                scrollHeight = (this.Height * scrollHeight) / 100;

                                int scrollTop = (100 * m_offset.Y) / MaxYOffset;
                                scrollTop = ((this.Height - scrollHeight) * scrollTop) / 100;


                                Rectangle  scroll = new Rectangle(this.Width - (scrollWidth * 2), scrollTop, scrollWidth, scrollHeight);
                                SolidBrush brush  = new SolidBrush(SystemColors.ScrollBar);
                                m_backBuffer.FillRectangle(brush, scroll);
                            }
                        }
                        if ((m_layout == KListLayout.Horizontal || m_layout == KListLayout.Grid) && MaxXOffset > 0)
                        {
                            int scrollWidth = (this.Width * 100) / (MaxXOffset + this.Width); // percentage

                            if (scrollWidth < 100)
                            {
                                int scrollHeight = Convert.ToInt32(scrollSize * scaleFactor.Height);

                                scrollWidth = (this.Width * scrollWidth) / 100;

                                int scrollLeft = (100 * m_offset.X) / MaxXOffset;
                                scrollLeft = ((this.Width - scrollWidth) * scrollLeft) / 100;


                                Rectangle  scroll = new Rectangle(scrollLeft, this.Height - (scrollHeight * 2), scrollWidth, scrollHeight);
                                SolidBrush brush  = new SolidBrush(SystemColors.ScrollBar);
                                m_backBuffer.FillRectangle(brush, scroll);
                            }
                        }
                    }
                }


                e.Graphics.DrawImage(m_backBufferBitmap, 0, 0);
            }
            else
            {
                base.OnPaint(e);
            }
        }