示例#1
0
        /// <summary>
        /// Fetches an image surface from a named file.
        /// </summary>
        /// <param name="capi">The Client API</param>
        /// <param name="texFileName">The name of the text file.</param>
        /// <returns></returns>
        public static ImageSurface getImageSurfaceFromAsset(ICoreClientAPI capi, string texFileName)
        {
            byte[] pngdata = capi.Assets.Get("textures/" + texFileName).Data;

            BitmapExternal bitmap = (BitmapExternal)capi.Render.BitmapCreateFromPng(pngdata);

            BitmapData bmp_data = bitmap.bmp.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.bmp.Width, bitmap.bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            ImageSurface imageSurface = new ImageSurface(Format.Argb32, bitmap.bmp.Width, bitmap.bmp.Height);

            unsafe
            {
                uint *destPixels   = (uint *)imageSurface.DataPtr.ToPointer();
                uint *sourcePixels = (uint *)bmp_data.Scan0.ToPointer();

                int size = bitmap.bmp.Width * bitmap.bmp.Height;

                for (int i = 0; i < size; i++)
                {
                    destPixels[i] = sourcePixels[i];
                }
            }

            imageSurface.MarkDirty();


            bitmap.bmp.UnlockBits(bmp_data);
            bitmap.Dispose();

            return(imageSurface);
        }
        /// <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();
        }