Пример #1
0
        /// <summary>
        /// Gets an image surface based off the bitmap.
        /// </summary>
        /// <param name="bitmap">The provided bitmap.</param>
        /// <param name="width">The width requested.</param>
        /// <param name="height">The height requested.</param>
        /// <returns>The image surface built from the bitmap and data.</returns>
        public static ImageSurface getImageSurfaceFromAsset(Bitmap bitmap, int width, int height)
        {
            ImageSurface imageSurface = new ImageSurface(Format.Argb32, width, height);

            imageSurface.Image(bitmap, 0, 0, width, height);
            return(imageSurface);
        }
Пример #2
0
 public static void Image(this ImageSurface surface, BitmapRef bmp, int xPos, int yPos, int width, int height)
 {
     surface.Image(((BitmapExternal)bmp).bmp, xPos, yPos, width, height);
 }
        /// <summary>
        /// Recomposes a multi-line message.
        /// </summary>
        /// <param name="versionnumber">The version number of the new version.</param>
        public void RecomposeMultiLine(string versionnumber)
        {
            text = Lang.Get("versionavailable", versionnumber);

            Bounds.fixedHeight = GetMultilineTextHeight() / RuntimeEnv.GUIScale;
            Bounds.CalcWorldBounds();

            offsetY = -2 * Bounds.fixedHeight;

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

            double iconX    = scaled(15);
            double iconSize = scaled(14);
            double iconY    = (Bounds.InnerHeight - iconSize) / 2;

            double[] bgc = GuiStyle.DarkBrownColor;
            bgc[0] /= 2;
            bgc[1] /= 2;
            bgc[2] /= 2;
            LinearGradient gradient = new LinearGradient(0, Bounds.OuterHeightInt, 0, Bounds.OuterHeightInt + 10);

            gradient.AddColorStop(0, new Color(bgc[0], bgc[1], bgc[2], 1));
            gradient.AddColorStop(1, new Color(bgc[0], bgc[1], bgc[2], 0));
            ctx.SetSource(gradient);
            ctx.Rectangle(0, Bounds.OuterHeightInt, Bounds.OuterWidthInt, Bounds.OuterHeightInt + 10);
            ctx.Fill();
            gradient.Dispose();


            gradient = new LinearGradient(0, 0, Bounds.OuterWidth, 0);
            gradient.AddColorStop(0, new Color(backColor[0], backColor[1], backColor[2], 1));
            gradient.AddColorStop(0.99, new Color(backColor[0], backColor[1], backColor[2], 1));
            gradient.AddColorStop(1, new Color(backColor[0], backColor[1], backColor[2], 0));
            ctx.SetSource(gradient);
            ctx.Rectangle(0, 0, Bounds.OuterWidthInt, Bounds.OuterHeightInt);
            ctx.Fill();
            gradient.Dispose();

            ctx.Arc(Bounds.drawX + iconX, Bounds.OuterHeight / 2, iconSize / 2 + scaled(4), 0, Math.PI * 2);
            ctx.SetSourceRGBA(GuiStyle.DarkBrownColor);
            ctx.Fill();

            double fontheight = Font.GetFontExtents().Height;

            byte[]         pngdata = api.Assets.Get("textures/gui/newversion.png").Data;
            BitmapExternal bitmap  = (BitmapExternal)api.Render.BitmapCreateFromPng(pngdata);

            surface.Image(bitmap.bmp, (int)(Bounds.drawX + iconX - iconSize / 2), (int)(Bounds.drawY + iconY), (int)iconSize, (int)iconSize);
            bitmap.Dispose();

            DrawMultilineTextAt(ctx, Bounds.drawX + iconX + 20, Bounds.drawY);

            generateTexture(surface, ref texture);
            ctx.Dispose();
            surface.Dispose();


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

            ctx.SetSourceRGBA(1, 1, 1, 0.1);
            ctx.Paint();

            generateTexture(surface, ref hoverTexture);

            ctx.Dispose();
            surface.Dispose();
        }
Пример #4
0
        void Compose()
        {
            ComposeHover(true, ref leftHighlightTextureId);
            ComposeHover(false, ref rightHighlightTextureId);
            genOnTexture();

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

            double rightBoxWidth = scaled(unscaledRightBoxWidth);

            Bounds.CalcWorldBounds();

            var  mod      = (Mod)cell.Data;
            bool validMod = mod.Info != null;

            if (cell.DrawAsButton)
            {
                RoundRectangle(ctx, 0, 0, Bounds.OuterWidth, Bounds.OuterHeight, 0);

                ctx.SetSourceRGB(GuiStyle.DialogDefaultBgColor[0], GuiStyle.DialogDefaultBgColor[1], GuiStyle.DialogDefaultBgColor[2]);
                ctx.Fill();
            }

            double textOffset = 0;

            if (validMod && mod.Icon != null)
            {
                int imageSize = (int)(Bounds.InnerHeight - Bounds.absPaddingY * 2 - 10);
                textOffset = imageSize + 10;

                Bitmap bmp = mod.Icon;
                surface.Image(bmp, (int)Bounds.absPaddingX + 5, (int)Bounds.absPaddingY + 5, imageSize, imageSize);


                bmp.Dispose();
            }

            Font            = cell.TitleFont;
            titleTextheight = textUtil.AutobreakAndDrawMultilineTextAt(ctx, Font, cell.Title, Bounds.absPaddingX + textOffset, Bounds.absPaddingY, Bounds.InnerWidth - textOffset);

            Font = cell.DetailTextFont;
            textUtil.AutobreakAndDrawMultilineTextAt(ctx, Font, cell.DetailText, Bounds.absPaddingX + textOffset, Bounds.absPaddingY + titleTextheight + Bounds.absPaddingY, Bounds.InnerWidth - textOffset);

            if (cell.RightTopText != null)
            {
                TextExtents extents = Font.GetTextExtents(cell.RightTopText);
                textUtil.AutobreakAndDrawMultilineTextAt(ctx, Font, cell.RightTopText, Bounds.absPaddingX + Bounds.InnerWidth - extents.Width - rightBoxWidth - scaled(10), Bounds.absPaddingY + scaled(cell.RightTopOffY), extents.Width + 1, EnumTextOrientation.Right);
            }

            if (cell.DrawAsButton)
            {
                EmbossRoundRectangleElement(ctx, 0, 0, Bounds.OuterWidth, Bounds.OuterHeight, false, 4, 0);
            }

            if (!validMod)
            {
                ctx.SetSourceRGBA(0, 0, 0, 0.5);
                RoundRectangle(ctx, 0, 0, Bounds.OuterWidth, Bounds.OuterHeight, 1);

                ctx.Fill();
            }

            if (showModifyIcons)
            {
                double checkboxsize = scaled(unscaledSwitchSize);
                double padd         = scaled(unscaledSwitchPadding);

                double x = Bounds.absPaddingX + Bounds.InnerWidth - scaled(0) - checkboxsize - padd;
                double y = Bounds.absPaddingY + Bounds.absPaddingY;


                ctx.SetSourceRGBA(0, 0, 0, 0.2);
                RoundRectangle(ctx, x, y, checkboxsize, checkboxsize, 3);
                ctx.Fill();
                EmbossRoundRectangleElement(ctx, x, y, checkboxsize, checkboxsize, true, 1, 2);
            }

            generateTexture(surface, ref modcellTexture);

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