예제 #1
0
        //FreeTypeFontFace fontFace = FreeTypeFontFace.Create(LoadtimeSettings.AssetPath + "/font/" + LoadtimeSettings.GUIFontName, 0);
        //ctx.SetContextFontFace(fontFace);

        public override void ComposeTextElements(Context ctxStatic, ImageSurface surfaceStatic)
        {
            Font.SetupContext(ctxStatic);

            Bounds.CalcWorldBounds();

            ImageSurface insetShadowSurface = new ImageSurface(Format.Argb32, Bounds.ParentBounds.OuterWidthInt, Bounds.ParentBounds.OuterHeightInt);
            Context      ctxInsetShadow     = new Context(insetShadowSurface);

            ctxInsetShadow.SetSourceRGB(0, 0, 0);
            ctxInsetShadow.Paint();
            Font.Color = new double[] { 20, 20, 20, 0.35f };
            Font.SetupContext(ctxInsetShadow);

            DrawMultilineTextAt(ctxInsetShadow, Bounds.drawX + scaled(2), Bounds.drawY + scaled(2), orientation);


            insetShadowSurface.Blur(7,
                                    (int)Math.Max(0, Bounds.drawX - 4),
                                    (int)Math.Max(0, Bounds.drawY - 4),
                                    (int)Math.Min(Bounds.ParentBounds.OuterWidth, Bounds.drawX + Font.GetTextExtents(text).Width + 6),
                                    (int)Math.Min(Bounds.ParentBounds.OuterHeight, Bounds.drawY + ctxInsetShadow.FontExtents.Height + 6)
                                    );

            ImageSurface surface = new ImageSurface(Format.Argb32, Bounds.ParentBounds.OuterWidthInt, Bounds.ParentBounds.OuterHeightInt);
            Context      ctxText = new Context(surface);

            ctxText.Operator = Operator.Source;

            ctxText.Antialias = Antialias.Best;

            Font.Color = new double[] { 0, 0, 0, 0.4 };
            Font.SetupContext(ctxText);

            ctxText.SetSourceRGBA(0, 0, 0, 0.4);
            DrawMultilineTextAt(ctxText, Bounds.drawX - scaled(0.5), Bounds.drawY - scaled(0.5), orientation);

            ctxText.SetSourceRGBA(1, 1, 1, 1);
            DrawMultilineTextAt(ctxText, Bounds.drawX + scaled(1), Bounds.drawY + scaled(1), orientation);

            ctxText.Operator = Operator.Atop;
            ctxText.SetSourceSurface(insetShadowSurface, 0, 0);
            ctxText.Paint();

            ctxInsetShadow.Dispose();
            insetShadowSurface.Dispose();

            ctxText.Operator = Operator.Over;
            Font.Color       = new double[] { 0, 0, 0, 0.35 };
            Font.SetupContext(ctxText);
            DrawMultilineTextAt(ctxText, (int)Bounds.drawX, (int)Bounds.drawY, orientation);

            ctxStatic.Antialias = Antialias.Best;
            ctxStatic.Operator  = Operator.HardLight;
            ctxStatic.SetSourceSurface(surface, 0, 0);
            ctxStatic.Paint();

            surface.Dispose();
            ctxText.Dispose();
        }
예제 #2
0
        public void Compose()
        {
            Bounds.CalcWorldBounds();

            ImageSurface surface = new ImageSurface(Format.Argb32, Bounds.OuterWidthInt, Bounds.OuterHeightInt);
            Context      ctx     = new Context(surface);

            ComposeButton(ctx, surface, false);
            generateTexture(surface, ref releasedButtonTexture);

            ctx.Operator = Operator.Clear;
            ctx.Paint();
            ctx.Operator = Operator.Over;

            ComposeButton(ctx, surface, true);
            generateTexture(surface, ref pressedButtonTexture);

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

            ComposeHover(true, ref leftHighlightTexture);
            if (ShowModifyIcons)
            {
                ComposeHover(false, ref rightHighlightTexture);
            }
        }
예제 #3
0
        public override void ComposeElements(Context ctx, ImageSurface surface)
        {
            Bounds.CalcWorldBounds();

            ctx.SetSourceRGBA(0, 0, 0, 0.35);
            ctx.Fill();
            ctx.Paint();
        }
예제 #4
0
        public override void ComposeElements(Context ctx, ImageSurface surface)
        {
            Bounds.CalcWorldBounds();

            ctx.SetSourceRGBA(bgcolor);
            ctx.Rectangle(Bounds.bgDrawX, Bounds.bgDrawY, Bounds.OuterWidth, Bounds.OuterHeight);
            ctx.FillPreserve();
            ShadePath(ctx, 2);
        }
예제 #5
0
        void Compose()
        {
            Bounds.CalcWorldBounds();

            double shadowOffset = scaled(1.5) / 2;
            double shineOffset  = -scaled(1.5) / 2;
            double padding      = scaled(Padding);

            if (!enabled)
            {
                shadowOffset /= 2;
                shineOffset  /= 2;
            }

            ImageSurface surface = new ImageSurface(Format.Argb32, Bounds.OuterWidthInt, Bounds.OuterHeightInt);
            Context      ctxText = new Context(surface);

            ctxText.SetSourceRGBA(0, 0, 0, 0);
            ctxText.Paint();

            ctxText.Operator  = Operator.Source;
            ctxText.Antialias = Antialias.Best;

            Font.Color = new double[] { 0, 0, 0, 0.4 };
            Font.SetupContext(ctxText);

            ctxText.SetSourceRGBA(0, 0, 0, 0.95);
            ctxText.MoveTo(padding + shadowOffset, padding + shadowOffset);
            DrawTextLineAt(ctxText, text, 0, 0);

            ctxText.SetSourceRGBA(255, 255, 255, enabled ? 0.95 : 0.5);
            ctxText.MoveTo(padding + shineOffset, padding + shineOffset);
            DrawTextLineAt(ctxText, text, 0, 0);


            surface.Blur(3, 0, 0, Bounds.OuterWidthInt, Bounds.OuterHeightInt);

            ctxText.Operator = Operator.Source;
            if (enabled)
            {
                Font.Color = new double[] { 0, 0, 0, 0.5 };
            }
            else
            {
                Font.Color = new double[] { 0.5, 0.5, 0.5, 0.75 };
            }

            Font.SetupContext(ctxText);
            ctxText.MoveTo(padding, padding);
            DrawTextLineAt(ctxText, text, 0, 0);

            generateTexture(surface, ref texture);

            surface.Dispose();
            ctxText.Dispose();
        }
예제 #6
0
        /// <summary>
        /// Composes the element in both the pressed, and released states.
        /// </summary>
        /// <param name="ctx">The context of the element.</param>
        /// <param name="surface">The surface of the element.</param>
        /// <remarks>Neither the context, nor the surface is used in this function.</remarks>
        public override void ComposeElements(Context ctx, ImageSurface surface)
        {
            Bounds.CalcWorldBounds();
            double[] dcolor = ColorUtil.ToRGBADoubles(color);
            ctx.SetSourceRGBA(dcolor[2], dcolor[1], dcolor[0], 1);
            RoundRectangle(ctx, Bounds.drawX, Bounds.drawY, Bounds.InnerWidth, Bounds.InnerHeight, 1);
            ctx.Fill();

            ComposeActiveButton();
        }
예제 #7
0
        public override void ComposeElements(Context ctxStatic, ImageSurface surface)
        {
            Bounds.CalcWorldBounds();

            ctxStatic.SetSourceRGBA(0, 0, 0, 0.2);
            RoundRectangle(ctxStatic, Bounds.drawX, Bounds.drawY, Bounds.InnerWidth, Bounds.InnerHeight, 1);
            ctxStatic.Fill();
            EmbossRoundRectangleElement(ctxStatic, Bounds, true, 1, 1);

            genOnTexture();
        }
예제 #8
0
        public override void ComposeElements(Context ctxStatic, ImageSurface surface)
        {
            Bounds.CalcWorldBounds();
            chunkViewBoundsBefore = new Cuboidi();

            BlockPos start = api.World.Player.Entity.Pos.AsBlockPos;

            CurrentBlockViewBounds = new Cuboidd(
                start.X - Bounds.InnerWidth / 2 / ZoomLevel, 0, start.Z - Bounds.InnerHeight / 2 / ZoomLevel,
                start.X + Bounds.InnerWidth / 2 / ZoomLevel, 0, start.Z + Bounds.InnerHeight / 2 / ZoomLevel
                );
        }
예제 #9
0
        public override void ComposeElements(Context ctxStatic, ImageSurface surfaceStatic)
        {
            Bounds.CalcWorldBounds();

            if (!interactive)
            {
                OnDraw(ctxStatic, surfaceStatic, Bounds);
            }
            else
            {
                Redraw();
            }
        }
예제 #10
0
        public override void ComposeElements(Context ctx, ImageSurface surface)
        {
            Bounds.CalcWorldBounds();

            if (brightness < 1)
            {
                ctx.SetSourceRGBA(0, 0, 0, 1 - brightness);
                Rectangle(ctx, Bounds);
                ctx.Fill();
            }

            EmbossRoundRectangleElement(ctx, Bounds, true, depth);
        }
예제 #11
0
        /// <summary>
        /// Recomposes the element for lines.
        /// </summary>
        public void RecomposeText()
        {
            CalcHeightAndPositions();
            Bounds.CalcWorldBounds();

            ImageSurface surface = new ImageSurface(Format.Argb32, (int)Bounds.InnerWidth, (int)Bounds.InnerHeight);
            Context      ctx     = genContext(surface);

            ComposeFor(Bounds.CopyOnlySize(), ctx, surface);

            generateTexture(surface, ref richtTextTexture);

            ctx.Dispose();
            surface.Dispose();
        }
예제 #12
0
        public override void ComposeElements(Context ctxStatic, ImageSurface surfaceStatic)
        {
            Bounds.CalcWorldBounds();
            normalText.Bounds.CalcWorldBounds();

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

            // 1. Normal button
            ComposeButton(ctx, surface);
            generateTexture(surface, ref normalTexture);
            ctx.Clear();


            // 2. Hover button
            if (buttonStyle != EnumButtonStyle.None)
            {
                ctx.SetSourceRGBA(0, 0, 0, 0.4);
                ctx.Rectangle(0, 0, Bounds.OuterWidth, Bounds.OuterHeight);
                ctx.Fill();
            }

            pressedText.Bounds.fixedY += textOffsetY;
            pressedText.ComposeElements(ctx, surface);
            pressedText.Bounds.fixedY -= textOffsetY;

            generateTexture(surface, ref hoverTexture);

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


            // 3. Disabled button
            surface = new ImageSurface(Format.Argb32, 2, 2);
            ctx     = genContext(surface);

            if (buttonStyle != EnumButtonStyle.None)
            {
                ctx.SetSourceRGBA(0, 0, 0, 0.4);
                ctx.Rectangle(0, 0, 2, 2);
                ctx.Fill();
            }

            generateTexture(surface, ref disabledTexture);

            ctx.Dispose();
            surface.Dispose();
        }
예제 #13
0
        void Recompose()
        {
            descriptionElement.SetNewText(text, Font);
            RecalcBounds();
            Bounds.CalcWorldBounds();

            ElementBounds textBounds = Bounds.CopyOnlySize();

            textBounds.CalcWorldBounds();

            ImageSurface surface = new ImageSurface(Format.Argb32, (int)Math.Ceiling(hoverWidth), (int)Math.Ceiling(hoverHeight));
            Context      ctx     = genContext(surface);

            ctx.SetSourceRGBA(0, 0, 0, 0);
            ctx.Paint();

            if (Background?.FillColor != null)
            {
                ctx.SetSourceRGBA(Background.FillColor);
                RoundRectangle(ctx, 0, 0, hoverWidth, hoverHeight, Background.Radius);
                ctx.Fill();
            }

            if (Background?.Shade == true)
            {
                ctx.SetSourceRGBA(GuiStyle.DialogLightBgColor[0] * 1.4, GuiStyle.DialogStrongBgColor[1] * 1.4, GuiStyle.DialogStrongBgColor[2] * 1.4, 1);
                RoundRectangle(ctx, 0, 0, hoverWidth, hoverHeight, Background.Radius);
                ctx.LineWidth = Background.BorderWidth * 1.75;
                ctx.Stroke();
                surface.Blur(8.2);
            }

            if (Background?.BorderColor != null)
            {
                ctx.SetSourceRGBA(Background.BorderColor);
                RoundRectangle(ctx, 0, 0, hoverWidth, hoverHeight, Background.Radius);
                ctx.LineWidth = Background.BorderWidth;
                ctx.Stroke();
            }


            generateTexture(surface, ref hoverTexture);

            ctx.Dispose();
            surface.Dispose();
        }
예제 #14
0
        public override void ComposeElements(Context ctx, ImageSurface surface)
        {
            Bounds.CalcWorldBounds();

            ctx.Operator = Operator.Over; // WTF man, somehwere within this code or within cairo the main context operator is being changed

            RoundRectangle(ctx, Bounds.drawX, Bounds.drawY, Bounds.InnerWidth, Bounds.InnerHeight, 1);

            ctx.SetSourceRGB(0.15, 0.15, 0.15);
            ctx.Fill();
            EmbossRoundRectangleElement(ctx, Bounds, false, 3, 1);

            if (valuesSet)
            {
                recomposeOverlays();
            }
        }
예제 #15
0
        public void SetNewTextWithoutRecompose(string vtmlCode, CairoFont baseFont, Action <LinkTextComponent> didClickLink = null, bool recalcBounds = false)
        {
            if (this.Components != null)
            {
                foreach (var val in Components)
                {
                    val?.Dispose();
                }
            }

            this.Components = VtmlUtil.Richtextify(api, vtmlCode, baseFont, didClickLink);

            if (recalcBounds)
            {
                CalcHeightAndPositions();
                Bounds.CalcWorldBounds();
            }
        }