/// <summary>
        /// Creates an ItemStackInfo element.
        /// </summary>
        /// <param name="capi">The client API</param>
        /// <param name="bounds">The bounds of the object.</param>
        /// <param name="OnRequireInfoText">The function that is called when an item information is called.</param>
        public GuiElementItemstackInfo(ICoreClientAPI capi, ElementBounds bounds, InfoTextDelegate OnRequireInfoText) : base(capi, "", CairoFont.WhiteSmallText(), bounds)
        {
            this.OnRequireInfoText = OnRequireInfoText;

            texture = new LoadedTexture(capi);

            ElementBounds textBounds = bounds.CopyOnlySize();
            ElementBounds descBounds = textBounds.CopyOffsetedSibling(ItemStackSize + 50, MarginTop, -ItemStackSize - 50, 0);

            descBounds.WithParent(bounds);
            textBounds.WithParent(bounds);

            descriptionElement = new GuiElementRichtext(capi, new RichTextComponentBase[0], descBounds);
            //new GuiElementStaticText(capi, "", EnumTextOrientation.Left, textBounds.CopyOffsetedSibling(ItemStackSize + 50, MarginTop, -ItemStackSize - 50, 0), Font);
            descriptionElement.zPos = 1001;


            titleFont            = Font.Clone();
            titleFont.FontWeight = FontWeight.Bold;

            titleElement      = new GuiElementRichtext(capi, new RichTextComponentBase[0], textBounds);
            titleElement.zPos = 1001;

            maxWidth = bounds.fixedWidth;
        }
Exemple #2
0
        /// <summary>
        /// Creates a new GUI Element List Menu
        /// </summary>
        /// <param name="capi">The Client API.</param>
        /// <param name="values">The values of the list.</param>
        /// <param name="names">The names for each of the values.</param>
        /// <param name="selectedIndex">The default selected index.</param>
        /// <param name="onSelectionChanged">The event fired when the selection is changed.</param>
        /// <param name="bounds">The bounds of the GUI element.</param>
        public GuiElementListMenu(ICoreClientAPI capi, string[] values, string[] names, int selectedIndex, SelectionChangedDelegate onSelectionChanged, ElementBounds bounds, CairoFont font, bool multiSelect) : base(capi, "", font, bounds)
        {
            if (values.Length != names.Length)
            {
                throw new ArgumentException("Values and Names arrays must be of the same length!");
            }

            hoverTexture     = new LoadedTexture(capi);
            dropDownTexture  = new LoadedTexture(capi);
            scrollbarTexture = new LoadedTexture(capi);

            this.Values             = values;
            this.Names              = names;
            this.SelectedIndex      = selectedIndex;
            this.multiSelect        = multiSelect;
            this.onSelectionChanged = onSelectionChanged;
            HoveredIndex            = selectedIndex;

            ElementBounds scrollbarBounds = ElementBounds.Fixed(0, 0, 0, 0).WithEmptyParent();

            scrollbar = new GuiElementCompactScrollbar(api, OnNewScrollbarValue, scrollbarBounds);



            richtTextElem = new GuiElementRichtext[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                ElementBounds textBounds = ElementBounds.Fixed(0, 0, 700, 100).WithEmptyParent();
                richtTextElem[i] = new GuiElementRichtext(capi, new RichTextComponentBase[0], textBounds);
            }
        }
Exemple #3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="capi">The client API</param>
        /// <param name="values">The values of the strings.</param>
        /// <param name="names">The names of the strings.</param>
        /// <param name="selectedIndex">The default selected index.</param>
        /// <param name="onSelectionChanged">The event that occurs when the selection is changed.</param>
        /// <param name="bounds">The bounds of the drop down.</param>
        public GuiElementDropDown(ICoreClientAPI capi, string[] values, string[] names, int selectedIndex, SelectionChangedDelegate onSelectionChanged, ElementBounds bounds, CairoFont font, bool multiSelect) : base(capi, "", font, bounds)
        {
            highlightTexture        = new LoadedTexture(capi);
            currentValueTexture     = new LoadedTexture(capi);
            arrowDownButtonReleased = new LoadedTexture(capi);
            arrowDownButtonPressed  = new LoadedTexture(capi);

            listMenu = new GuiElementListMenu(capi, values, names, selectedIndex, didSelect, bounds, font, multiSelect)
            {
                HoveredIndex = selectedIndex
            };

            ElementBounds textBounds = ElementBounds.Fixed(0, 0, 900, 100).WithEmptyParent();

            richTextElem = new GuiElementRichtext(capi, new RichTextComponentBase[0], textBounds);

            this.onSelectionChanged = onSelectionChanged;
            this.multiSelect        = multiSelect;
        }
Exemple #4
0
        /// <summary>
        /// Creates a new instance of hover text.
        /// </summary>
        /// <param name="capi">The client API.</param>
        /// <param name="text">The text of the text.</param>
        /// <remarks>For the text and the text.</remarks>
        /// <param name="font">The font of the text.</param>
        /// <param name="maxWidth">The width of the text.</param>
        /// <param name="bounds">the bounds of the text.</param>
        public GuiElementHoverText(ICoreClientAPI capi, string text, CairoFont font, int maxWidth, ElementBounds bounds, TextBackground background = null) : base(capi, text, font, bounds)
        {
            this.Background = background;
            if (background == null)
            {
                this.Background = GuiElementHoverText.DefaultBackground;
            }
            this.unscaledMaxWidth = maxWidth;

            hoverTexture = new LoadedTexture(capi);

            padding = Background.Padding;
            ElementBounds descBounds = bounds.CopyOnlySize();

            descBounds.WithFixedPadding(0);
            descBounds.WithParent(bounds);
            descBounds.IsDrawingSurface = true;
            descBounds.fixedWidth       = maxWidth;

            descriptionElement      = new GuiElementRichtext(capi, new RichTextComponentBase[0], descBounds);
            descriptionElement.zPos = 1001;
        }
Exemple #5
0
        /// <summary>
        /// Composes the list of elements dynamically.
        /// </summary>
        public void ComposeDynamicElements()
        {
            Bounds.CalcWorldBounds();

            if (multiSelect)
            {
                if (switches != null)
                {
                    foreach (var val in switches)
                    {
                        val.Dispose();
                    }
                }

                switches = new GuiElementSwitch[Names.Length];
            }

            for (int i = 0; i < richtTextElem.Length; i++)
            {
                richtTextElem[i].Dispose();
            }

            richtTextElem = new GuiElementRichtext[Values.Length];
            for (int i = 0; i < Values.Length; i++)
            {
                ElementBounds textBounds = ElementBounds.Fixed(0, 0, 700, 100).WithEmptyParent();
                richtTextElem[i] = new GuiElementRichtext(api, new RichTextComponentBase[0], textBounds);
            }


            double scaleMul   = Scale * RuntimeEnv.GUIScale;
            double lineHeight = unscaledLineHeight * scaleMul;

            // Expandable box with list of names
            expandedBoxWidth  = Bounds.InnerWidth;
            expandedBoxHeight = Values.Length * lineHeight;

            double scrollbarWidth = 10;

            for (int i = 0; i < Values.Length; i++)
            {
                GuiElementRichtext elem = richtTextElem[i];
                elem.SetNewTextWithoutRecompose(Names[i], Font);
                elem.BeforeCalcBounds();

                expandedBoxWidth = Math.Max(expandedBoxWidth, elem.MaxLineWidth + scaled(scrollbarWidth + 5));
            }
            expandedBoxWidth++;

            //expandedBoxWidth += 5 * scaleMul;


            ImageSurface surface = new ImageSurface(Format.Argb32, (int)expandedBoxWidth, (int)expandedBoxHeight);
            Context      ctx     = genContext(surface);

            visibleBounds             = Bounds.FlatCopy();
            visibleBounds.fixedHeight = Math.Min(MaxHeight, expandedBoxHeight / RuntimeEnv.GUIScale);
            visibleBounds.fixedWidth  = expandedBoxWidth / RuntimeEnv.GUIScale;
            visibleBounds.fixedY     += Bounds.InnerHeight / RuntimeEnv.GUIScale;
            visibleBounds.CalcWorldBounds();

            Font.SetupContext(ctx);

            ctx.SetSourceRGBA(GuiStyle.DialogStrongBgColor);
            RoundRectangle(ctx, 0, 0, expandedBoxWidth, expandedBoxHeight, 1);
            ctx.FillPreserve();
            ctx.SetSourceRGBA(0, 0, 0, 0.5);
            ctx.LineWidth = 2;
            ctx.Stroke();

            double unscaledHeight = Font.GetFontExtents().Height / RuntimeEnv.GUIScale;
            double unscaledOffY   = (unscaledLineHeight - unscaledHeight) / 2;
            double unscaledOffx   = multiSelect ? unscaledHeight + 10 : 0;

            double scaledHeight = unscaledHeight * scaleMul;

            ctx.SetSourceRGBA(GuiStyle.DialogDefaultTextColor);

            ElementBounds switchParentBounds = Bounds.FlatCopy();

            switchParentBounds.IsDrawingSurface = true;
            switchParentBounds.CalcWorldBounds();



            for (int i = 0; i < Values.Length; i++)
            {
                int    num = i;
                double y   = ((int)unscaledOffY + i * unscaledLineHeight) * scaleMul;
                double x   = unscaledOffx + 5 * scaleMul;

                double offy = (scaledHeight - Font.GetTextExtents(Names[i]).Height) / 2;

                if (multiSelect)
                {
                    double        pad          = 2;
                    ElementBounds switchBounds = new ElementBounds()
                    {
                        ParentBounds  = switchParentBounds,
                        fixedX        = 4 * Scale,
                        fixedY        = (y + offy) / RuntimeEnv.GUIScale,
                        fixedWidth    = (unscaledHeight) * Scale,
                        fixedHeight   = (unscaledHeight) * Scale,
                        fixedPaddingX = 0,
                        fixedPaddingY = 0
                    };

                    switches[i] = new GuiElementSwitch(api, (on) => toggled(on, num), switchBounds, switchBounds.fixedHeight, pad);
                    switches[i].ComposeElements(ctx, surface);

                    ctx.SetSourceRGBA(GuiStyle.DialogDefaultTextColor);
                }

                GuiElementRichtext elem = richtTextElem[i];

                elem.Bounds.fixedX = x;
                elem.Bounds.fixedY = (y + offy) / RuntimeEnv.GUIScale;
                elem.BeforeCalcBounds();
                elem.Bounds.CalcWorldBounds();
                elem.ComposeFor(elem.Bounds, ctx, surface);
            }

            generateTexture(surface, ref dropDownTexture);

            ctx.Dispose();
            surface.Dispose();


            // Scrollbar static stuff
            scrollbar.Bounds.WithFixedSize(scrollbarWidth, visibleBounds.fixedHeight - 3).WithFixedPosition(expandedBoxWidth / RuntimeEnv.GUIScale - 10, 0).WithFixedPadding(0, 2);
            scrollbar.Bounds.WithEmptyParent();
            scrollbar.Bounds.CalcWorldBounds();

            surface = new ImageSurface(Format.Argb32, (int)expandedBoxWidth, (int)scrollbar.Bounds.OuterHeight);
            ctx     = genContext(surface);

            scrollbar.ComposeElements(ctx, surface);
            scrollbar.SetHeights((int)visibleBounds.InnerHeight / RuntimeEnv.GUIScale, (int)expandedBoxHeight / RuntimeEnv.GUIScale);

            generateTexture(surface, ref scrollbarTexture);

            ctx.Dispose();
            surface.Dispose();


            // Hover bar
            surface = new ImageSurface(Format.Argb32, (int)expandedBoxWidth, (int)(unscaledLineHeight * scaleMul));
            ctx     = genContext(surface);

            double[] col = GuiStyle.DialogHighlightColor;
            col[3] = 0.5;
            ctx.SetSourceRGBA(col);
            RoundRectangle(ctx, 0, 0, expandedBoxWidth, unscaledLineHeight * scaleMul, 0);
            ctx.Fill();
            generateTexture(surface, ref hoverTexture);

            ctx.Dispose();
            surface.Dispose();
        }