예제 #1
0
        } // Update

        #endregion

        #region Track Item

        /// <summary>
        /// This method select the element that is under the mouse pointer (if any).
        /// </summary>
        private void TrackItem(int x, int y)
        {
            if (items != null && items.Count > 0 && (pane.ControlRectangleRelativeToParent.Contains(new Point(x, y))))
            {
                SkinText font           = SkinInformation.Layers["Control"].Text;
                int      fontHeight     = (int)font.Font.Font.MeasureString(items[0].ToString()).Y;
                int      scrollbarValue = scrollBarVertical.Value;
                if (!scrollBarVertical.Visible)
                {
                    scrollbarValue = 0;
                }

                int lowerBound = (int)Math.Floor((float)scrollbarValue / 10f);
                int upperBound = (int)Math.Ceiling((float)(scrollbarValue + scrollBarVertical.PageSize) / 10f);
                // Last page is special.
                if (upperBound > itemsCount)
                {
                    lowerBound = items.Count - (int)Math.Ceiling(scrollBarVertical.PageSize / 10f);
                    upperBound = items.Count;
                    if (lowerBound < 0)
                    {
                        lowerBound = 0;
                    }
                }
                // Calculate current item (without considering bounds or out of range)
                int i = (int)Math.Floor(lowerBound + ((float)y / fontHeight));

                if (i >= 0 && i < Items.Count && i >= lowerBound && i < upperBound)
                {
                    ItemIndex = i;
                }
                Focused = true;
            }
        } // TrackItem
예제 #2
0
        } // DisposeManagedResources

        #endregion

        #region Auto Height

        public virtual void AutoHeight(int maxItems)
        {
            if (items != null && items.Count < maxItems)
            {
                maxItems = items.Count;
            }
            if (items == null || items.Count == maxItems)
            {
                // No scroll bar for 3 or few items.
                scrollBarVertical.Visible = false;
                pane.Width = Width - SkinInformation.Layers["Control"].ContentMargins.Horizontal - 1;
            }
            else
            {
                // Reduce pane size to place the scroll bar.
                scrollBarVertical.Visible = true;
                pane.Width = Width - scrollBarVertical.Width - SkinInformation.Layers["Control"].ContentMargins.Horizontal - 1;
            }

            SkinText font = SkinInformation.Layers["Control"].Text;

            if (items != null && items.Count > 0)
            {
                // Calculate the height of the list box.
                int fontHeight = (int)font.Font.Font.MeasureString(items[0].ToString()).Y;
                Height = (fontHeight * maxItems) + (SkinInformation.Layers["Control"].ContentMargins.Vertical);// - Skin.OriginMargins.Vertical);
            }
            else
            {
                Height = 32;
            }
        } // AutoHeight
예제 #3
0
        } // SkinText

        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;
            }
        } // SkinText
예제 #4
0
        } // LineWidth

        #endregion

        #region Auto Size

        /// <summary>
        /// Auto Size
        /// </summary>
        private void AutoSize()
        {
            SkinText font = SkinInformation.Layers["Control"].Text;
            if (Items != null && Items.Count > 0)
            {
                Height = (LineHeight() * Items.Count) + (SkinInformation.Layers["Control"].ContentMargins.Vertical - SkinInformation.OriginMargins.Vertical);
                Width = LineWidth() + (SkinInformation.Layers["Control"].ContentMargins.Horizontal - SkinInformation.OriginMargins.Horizontal) + font.OffsetX;
            }
            else
            {
                Height = 16;
                Width = 16;
            }
        } // AutoSize
예제 #5
0
        } // DrawString

        public static void DrawString(Control control, SkinLayer layer, string text, Rectangle rect, ControlState state, bool margins, int ox, int oy, bool ellipsis)
        {
            if (layer.Text != null)
            {
                if (margins)
                {
                    Margins m = layer.ContentMargins;
                    rect = new Rectangle(rect.Left + m.Left, rect.Top + m.Top, rect.Width - m.Horizontal, rect.Height - m.Vertical);
                }

                #region Resolve Text Color

                Color color;
                if (state == ControlState.Hovered && (layer.States.Hovered.Index != -1))
                {
                    color = layer.Text.Colors.Hovered;
                }
                else if (state == ControlState.Pressed)
                {
                    color = layer.Text.Colors.Pressed;
                }
                else if (state == ControlState.Focused || (control.Focused && state == ControlState.Hovered && layer.States.Hovered.Index == -1))
                {
                    color = layer.Text.Colors.Focused;
                }
                else if (state == ControlState.Disabled)
                {
                    color = layer.Text.Colors.Disabled;
                }
                else
                {
                    color = layer.Text.Colors.Enabled;
                }

                #endregion

                if (!string.IsNullOrEmpty(text))
                {
                    SkinText font = layer.Text;
                    if (control.TextColor != Control.UndefinedColor && control.ControlState != ControlState.Disabled) 
                        color = control.TextColor;
                    DrawString(font.Font.Font.Resource, text, rect, color, font.Alignment, font.OffsetX + ox, font.OffsetY + oy, ellipsis);
                }
            }
        } // DrawString
예제 #6
0
        } // DrawControl

        private void DrawPane(object sender, DrawEventArgs e)
        {
            if (items != null && items.Count > 0)
            {
                SkinText  fontLayer     = SkinInformation.Layers["Control"].Text;
                SkinLayer selectedLayer = SkinInformation.Layers["ListBox.Selection"];
                int       fontHeight    = (int)fontLayer.Font.Font.MeasureString(items[0].ToString()).Y;
                int       v             = (scrollBarVertical.Value / 10);
                if (!scrollBarVertical.Visible) // If the scrooll bar is invisible then this value should be 0 (first page).
                {
                    v = 0;
                }
                int p = (scrollBarVertical.PageSize / 10);
                int d = (int)(((scrollBarVertical.Value % 10) / 10f) * fontHeight);
                // This is done to show all last elements in the same page.
                if (v + p + 1 > items.Count)
                {
                    v = items.Count - p;
                    if (v < 0)
                    {
                        v = 0;
                    }
                }
                // Draw elements
                for (int i = v; i <= v + p + 1; i++)
                {
                    if (i < items.Count)
                    {
                        Renderer.DrawString(this, SkinInformation.Layers["Control"], items[i].ToString(),
                                            new Rectangle(e.Rectangle.Left, e.Rectangle.Top - d + ((i - v) * fontHeight), e.Rectangle.Width, fontHeight), false);
                    }
                }
                // Draw selection
                if (itemIndex >= 0 && itemIndex < items.Count && (Focused || !hideSelection))
                {
                    int pos = -d + ((itemIndex - v) * fontHeight);
                    if (pos > -fontHeight && pos < (p + 1) * fontHeight)
                    {
                        Renderer.DrawLayer(this, selectedLayer, new Rectangle(e.Rectangle.Left, e.Rectangle.Top + pos, e.Rectangle.Width, fontHeight));
                        Renderer.DrawString(this, selectedLayer, items[itemIndex].ToString(), new Rectangle(e.Rectangle.Left, e.Rectangle.Top + pos, e.Rectangle.Width, fontHeight), false);
                    }
                }
            }
        } // DrawPane
예제 #7
0
        } // TrackItem

        #endregion

        #region Items Changed

        private void ItemsChanged()
        {
            if (items != null && items.Count > 0)
            {
                SkinText font = SkinInformation.Layers["Control"].Text;
                int      h    = (int)font.Font.Font.MeasureString(items[0].ToString()).Y;

                int sizev = Height - SkinInformation.Layers["Control"].ContentMargins.Vertical;
                scrollBarVertical.Range    = items.Count * 10;
                scrollBarVertical.PageSize = (int)Math.Floor((float)sizev * 10 / h);
                Invalidate();
            }
            else if (items == null || items.Count <= 0)
            {
                scrollBarVertical.Range    = 1;
                scrollBarVertical.PageSize = 1;
                Invalidate();
            }
        } // ItemsChanged
예제 #8
0
        } // SkinLayer

        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.");
            }
        } // SkinLayer