예제 #1
0
        public override void OnPaint(IGUIContext ctx, RectangleF bounds)
        {
            base.OnPaint(ctx, bounds);

            if (Font == null)
            {
                return;
            }
            for (int i = 0; i < Items.Count; i++)
            {
                ScrollingBoxItem item = Items[i];

                RectangleF r = item.rectF;
                r.Offset(bounds.Left, bounds.Top);
                if (i == 0)
                {
                    r.Offset(0, Padding.Top);
                }

                if (bounds.IntersectsWith(r))
                {
                    var txt = item as ScrollingBoxText;
                    if (txt != null)
                    {
                        ctx.DrawString(txt.Text, Font, Style.ForeColorBrush, r, Format);
                    }
                    else
                    {
                        ScrollingBoxImage img = item as ScrollingBoxImage;
                        if (img != null)
                        {
                            img.Image.Paint(ctx, new RectangleF(
                                                r.X + ImagePadding.Left,
                                                r.Top + ImagePadding.Top,
                                                r.Width - ImagePadding.Left - ImagePadding.Right,
                                                r.Height - ImagePadding.Top - ImagePadding.Bottom));
                        }
                    }
                }
            }
        }
예제 #2
0
        protected virtual void RecalculateItems()
        {
            SizeF sizeF      = new SizeF();
            float availWidth = Width - Padding.Width;

            TotalItemHeight = 0;

            for (int i = 0; i < Items.Count; i++)
            {
                ScrollingBoxItem item = Items[i];

                item.rectF.X     = Padding.Left;
                item.rectF.Width = (float)availWidth;

                if (item.GetType() == typeof(ScrollingBoxText))
                {
                    ScrollingBoxText textItem = (ScrollingBoxText)item;
                    if (String.IsNullOrEmpty(textItem.Text))
                    {
                        sizeF = new SizeF(availWidth, Font.LineHeight);
                    }
                    else
                    {
                        SizeF sz = Font.Measure(textItem.Text, availWidth, Format);
                        sizeF = new SizeF(sz.Width, sz.Height + Font.LineHeight - Font.Height);
                    }
                }
                else if (item.GetType() == typeof(ScrollingBoxImage))
                {
                    ScrollingBoxImage imgItem = (ScrollingBoxImage)item;
                    sizeF = imgItem.Image.Size;
                    sizeF = new SizeF(sizeF.Width + ImagePadding.Left + ImagePadding.Right, sizeF.Height + ImagePadding.Top + ImagePadding.Bottom);

                    imgItem.rectF.Width = sizeF.Width;
                    switch (Alignment)
                    {
                    case StringAlignment.Near:
                        item.rectF.X = Padding.Left + ImagePadding.Left;
                        break;

                    case StringAlignment.Center:
                        item.rectF.X = (availWidth / 2) - (sizeF.Width / 2) + Padding.Left + ImagePadding.Left;
                        break;

                    case StringAlignment.Far:
                        item.rectF.X = Width - sizeF.Width - Padding.Right - ImagePadding.Right;
                        break;
                    }
                }

                if (i == 0)
                {
                    sizeF = new SizeF(sizeF.Width, sizeF.Height + Padding.Top);
                }

                item.rectF.Height = sizeF.Height;
                TotalItemHeight  += sizeF.Height;

                if (i == 0)
                {
                    if (!startingPositionHasBeenSetAfterHeight)
                    {
                        item.rectF.Y = Height;
                        startingPositionHasBeenSetAfterHeight = true;
                    }
                }
                else
                {
                    item.rectF.Y = Items[i - 1].rectF.Bottom;
                }
            }
        }