예제 #1
0
        /// <summary>
        /// Draws the list pane containing the collection items.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void DrawPane(object sender, DrawEventArgs e)
        {
            // Collection is non-empty?
            if (items != null && items.Count > 0)
            {
                SkinText  font = Skin.Layers["Control"].Text;
                SkinLayer sel  = Skin.Layers["ListBox.Selection"];
                int       h    = (items[0] as T).Height;
                int       v    = (sbVert.Value / 10);
                int       p    = (sbVert.PageSize / 10);
                int       d    = (int)(((sbVert.Value % 10) / 10f) * h);
                int       c    = items.Count;
                int       s    = itemIndex;
                // Draw selection overlay?
                if (s >= 0 && s < c && (Focused || !hideSelection))
                {
                    int pos = -d + ((s - v) * h);

                    // Selected index is visible?
                    if (pos > -h && pos < (p + 1) * h)
                    {
                        e.Renderer.DrawLayer(this, sel, new Rectangle(e.Rectangle.Left, e.Rectangle.Top + pos, e.Rectangle.Width, h));
                    }
                }
                // Draw the visible collection items in the list pane.
                for (int i = v; i <= v + p + 1; i++)
                {
                    if (i < c)
                    {
                        if (i < items.Count)
                        {
                            foreach (Control ctr in (items[i] as T).Controls)
                            {
                                ctr.DrawControl(e.Renderer,
                                                new Rectangle(e.Rectangle.Left + ctr.Left,
                                                              (e.Rectangle.Top - d + ((i - v) * h)) + ctr.Top, e.Rectangle.Width, h),
                                                e.GameTime);
                            }
                        }
                    }
                }
                // Draw selection overlay?
                if (s >= 0 && s < c && (Focused || !hideSelection))
                {
                    int pos = -d + ((s - v) * h);

                    // Selected index is visible?
                    if (pos > -h && pos < (p + 1) * h)
                    {
                        e.Renderer.DrawLayer(sel, new Rectangle(e.Rectangle.Left, e.Rectangle.Top + pos, e.Rectangle.Width, h), Color.White * .2f, 0);
                    }
                }
            }
        }
예제 #2
0
 public SkinText(SkinText source) : base(source)
 {
     if (source != null)
     {
         Font      = new SkinFont(source.Font);
         OffsetX   = source.OffsetX;
         OffsetY   = source.OffsetY;
         Alignment = source.Alignment;
         Colors    = source.Colors;
     }
 }
예제 #3
0
        /// </summary>
        /// Calculates the dimensions of the context menu.
        /// <summary>
        private void AutoSize()
        {
            SkinText font = Skin.Layers["Control"].Text;

            if (Items != null && Items.Count > 0)
            {
                Height = (LineHeight() * Items.Count) + (Skin.Layers["Control"].ContentMargins.Vertical - Skin.OriginMargins.Vertical);
                Width  = LineWidth() + (Skin.Layers["Control"].ContentMargins.Horizontal - Skin.OriginMargins.Horizontal) + font.OffsetX;
            }
            else
            {
                Height = 16;
                Width  = 16;
            }
        }
예제 #4
0
        /// </summary>
        /// Determines which, if any, menu entry of the context menu is at the specified offset and updates
        /// the selected index, and raises the selected event for the new selection if needed.
        /// <summary>
        /// <param name="x">X position of the mouse as an offset from the context menu origins.</param>
        /// <param name="y">Y position of the mouse as an offset from the context menu origins.</param>
        private void TrackItem(int x, int y)
        {
            // Context menu has menu entries?
            if (Items != null && Items.Count > 0)
            {
                SkinText font = Skin.Layers["Control"].Text;
                int      h    = LineHeight();
                y -= Skin.Layers["Control"].ContentMargins.Top;

                // Y position / line height = Item Index.
                int i = (int)((float)y / h);

                // Item index within the limits of the menu entries list?
                if (i < Items.Count)
                {
                    // Item index is different from previous selection and the new item index is enabled?
                    if (i != ItemIndex && Items[i].Enabled)
                    {
                        // Hide the child menu of the previous selection if there was one.
                        if (ChildMenu != null)
                        {
                            this.HideMenu(false);
                        }

                        // And select the new menu entry.
                        if (i >= 0 && i != ItemIndex)
                        {
                            Items[i].SelectedInvoke(new EventArgs());
                        }

                        // Refocus the context menu, update the selected index, and update the delay timer.
                        Focused   = true;
                        ItemIndex = i;
                        timer     = (long)TimeSpan.FromTicks(DateTime.Now.Ticks).TotalMilliseconds;
                    }

                    // The new menu entry is not enabled, update the selected index to indicate an invalid selection.
                    else if (!Items[i].Enabled && ChildMenu == null)
                    {
                        ItemIndex = -1;
                    }
                }
                Invalidate();
            }
        }
예제 #5
0
        /// <summary>
        /// Sizes the list pane so the specified number of items will be able to be
        /// displayed in it without needing a scroll bar.
        /// </summary>
        /// <param name="maxItems">Number of items that can be displayed without needing a scroll bar.</param>
        public override void AutoHeight(int maxItems)
        {
            // Collection has less than the maximum items specified?
            if (items != null && items.Count < maxItems)
            {
                maxItems = items.Count;
            }

            // Adjust width of the pane to account for scroll bar visibility.
            if (maxItems < 3)
            {
                //maxItems = 3;
                sbVert.Visible = false;
                pane.Width     = Width - Skin.Layers["Control"].ContentMargins.Horizontal - 1;
            }

            else
            {
                pane.Width     = Width - sbVert.Width - Skin.Layers["Control"].ContentMargins.Horizontal - 1;
                sbVert.Visible = true;
            }

            // Get the list box font resource.
            SkinText font = Skin.Layers["Control"].Text;

            // Non-empty collection? Measure the height of a line of font and set the
            // height of the list pane based on the specified number of items that
            // should be able to display in it.
            if (items != null && items.Count > 0)
            {
                int h = (items[0] as T).Height;
                Height = (h * maxItems) + (Skin.Layers["Control"].ContentMargins.Vertical);// - Skin.OriginMargins.Vertical);
            }

            // Empty collection. Default height to 32.
            else
            {
                Height = 32;
            }
        }
예제 #6
0
 public SkinLayer(SkinLayer source) : base(source)
 {
     if (source != null)
     {
         Image          = new SkinImage(source.Image);
         Width          = source.Width;
         Height         = source.Height;
         OffsetX        = source.OffsetX;
         OffsetY        = source.OffsetY;
         Alignment      = source.Alignment;
         SizingMargins  = source.SizingMargins;
         ContentMargins = source.ContentMargins;
         States         = source.States;
         Overlays       = source.Overlays;
         Text           = new SkinText(source.Text);
         Attributes     = new SkinList <SkinAttribute>(source.Attributes);
     }
     else
     {
         throw new Exception("Parameter for SkinLayer copy constructor cannot be null.");
     }
 }