Ejemplo n.º 1
0
        private void FreeDrawingObjects()
        {
            pix?.Dispose();
            pix = null;

            // SkiaSharp objects should only exist if the Pixbuf is set as well
            surface?.Dispose();
            surface = null;
        }
Ejemplo n.º 2
0
        protected override bool OnDrawn(Context cr)
        {
            Stopwatch?sw = null;

            if (this.Log().IsEnabled(LogLevel.Trace))
            {
                sw = Stopwatch.StartNew();
                this.Log().Trace($"Render {renderCount++}");
            }

            var scaledWidth  = (int)(AllocatedWidth * _dpi);
            var scaledHeight = (int)(AllocatedHeight * _dpi);

            // reset the surfaces (skia/cairo) and bitmap if the size has changed
            if (_surface == null || scaledWidth != _bwidth || scaledHeight != _bheight)
            {
                _gtkSurface?.Dispose();
                _surface?.Dispose();
                _bitmap?.Dispose();

                var info = new SKImageInfo(scaledWidth, scaledHeight, _colorType, SKAlphaType.Premul);
                _bitmap  = new SKBitmap(info);
                _bwidth  = _bitmap.Width;
                _bheight = _bitmap.Height;
                var pixels = _bitmap.GetPixels(out _);
                _surface    = SKSurface.Create(info, pixels);
                _gtkSurface = new ImageSurface(pixels, Format.Argb32, _bwidth, _bheight, _bwidth * 4);
            }

            var canvas = _surface.Canvas;

            using (new SKAutoCanvasRestore(canvas, true))
            {
                canvas.Clear(BackgroundColor);
                canvas.Scale(_dpi);

                WUX.Window.Current.Compositor.Render(_surface);
            }

            _gtkSurface !.MarkDirty();
            cr.Save();
            cr.Scale(1 / _dpi, 1 / _dpi);
            cr.SetSourceSurface(_gtkSurface, 0, 0);
            cr.Paint();
            cr.Restore();

            if (this.Log().IsEnabled(LogLevel.Trace))
            {
                sw?.Stop();
                this.Log().Trace($"Frame: {sw?.Elapsed}");
            }

            return(true);
        }
Ejemplo n.º 3
0
        void ComposeHover(bool left, ref LoadedTexture texture)
        {
            ImageSurface surface = new ImageSurface(Format.Argb32, (int)Bounds.OuterWidth, (int)Bounds.OuterHeight);
            Context      ctx     = genContext(surface);

            double rightBoxWidth = scaled(unscaledRightBoxWidth);

            if (!ShowModifyIcons)
            {
                rightBoxWidth = -Bounds.OuterWidth + Bounds.InnerWidth;
            }

            if (left)
            {
                ctx.NewPath();
                ctx.LineTo(0, 0);
                ctx.LineTo(Bounds.InnerWidth - rightBoxWidth, 0);
                ctx.LineTo(Bounds.InnerWidth - rightBoxWidth, Bounds.OuterHeight);
                ctx.LineTo(0, Bounds.OuterHeight);
                ctx.ClosePath();
            }
            else
            {
                ctx.NewPath();
                ctx.LineTo(Bounds.InnerWidth - rightBoxWidth, 0);
                ctx.LineTo(Bounds.OuterWidth, 0);
                ctx.LineTo(Bounds.OuterWidth, Bounds.OuterHeight);
                ctx.LineTo(Bounds.InnerWidth - rightBoxWidth, Bounds.OuterHeight);
                ctx.ClosePath();
            }

            ctx.SetSourceRGBA(0, 0, 0, 0.15);
            ctx.Fill();

            generateTexture(surface, ref texture);

            ctx.Dispose();
            surface.Dispose();
        }
Ejemplo n.º 4
0
        public override void ComposeTextElements(Context ctx, ImageSurface surface)
        {
            ctx.LineWidth = 1;

            // Vertical seperator line above the bounds
            ctx.NewPath();
            ctx.MoveTo(Bounds.drawX + 1, Bounds.drawY);
            ctx.LineTo(Bounds.drawX + 1 + Bounds.InnerWidth, Bounds.drawY);
            ctx.ClosePath();
            ctx.SetSourceRGBA(1, 1, 1, 0.7);
            ctx.Stroke();


            ctx.NewPath();
            ctx.MoveTo(Bounds.drawX + 1, Bounds.drawY + 1);
            ctx.LineTo(Bounds.drawX + 1 + Bounds.InnerWidth, Bounds.drawY + 1);
            ctx.ClosePath();
            ctx.SetSourceRGBA(0, 0, 0, 0.7);
            ctx.Stroke();

            ImageSurface surfaceHighlight = new ImageSurface(Format.Argb32, (int)Bounds.OuterWidth, (int)Bounds.OuterHeight);
            Context      ctxHighlight     = genContext(surfaceHighlight);

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

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

            generateTexture(surfaceHighlight, ref highlightTexture);

            ctxHighlight.Dispose();
            surfaceHighlight.Dispose();

            highlightBounds = Bounds.CopyOffsetedSibling().WithFixedPadding(0, 0).FixedGrow(2 * Bounds.absPaddingX, 2 * Bounds.absPaddingY);
            highlightBounds.CalcWorldBounds();

            RecomposeText();
        }
Ejemplo n.º 5
0
        public override void OnMapOpenedClient()
        {
            bool rebuildAnyway = false;

#if DEBUG
            rebuildAnyway = true;
#endif

            if (texturesByIcon == null || rebuildAnyway)
            {
                texturesByIcon = new Dictionary <string, LoadedTexture>();

                ImageSurface surface = new ImageSurface(Format.Argb32, 25, 25);
                Context      ctx     = new Context(surface);

                string[]       icons = new string[] { "circle", "bee", "cave", "home", "ladder", "pick", "rocks", "ruins", "spiral", "star1", "star2", "trader", "vessel" };
                ICoreClientAPI capi  = api as ICoreClientAPI;

                foreach (var val in icons)
                {
                    ctx.Operator = Operator.Clear;
                    ctx.SetSourceRGBA(0, 0, 0, 0);
                    ctx.Paint();
                    ctx.Operator = Operator.Over;

                    capi.Gui.Icons.DrawIcon(ctx, "wp" + val.UcFirst(), 1, 1, 23, 23, ColorUtil.WhiteArgbDouble);

                    //surface.WriteToPng("icon-" + val+".png");

                    texturesByIcon[val] = new LoadedTexture(api as ICoreClientAPI, (api as ICoreClientAPI).Gui.LoadCairoTexture(surface, false), 20, 20);
                }

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


            RebuildMapComponents();
        }
Ejemplo n.º 6
0
        public void Compose(bool genTextureLater = false)
        {
            ElementBounds rtbounds = Bounds.CopyOnlySize();

            rtbounds.fixedPaddingX = 0;
            rtbounds.fixedPaddingY = 0;


            Bounds.CalcWorldBounds();

            int wdt = (int)Bounds.InnerWidth;
            int hgt = (int)Bounds.InnerHeight;

            if (richtTextTexture.TextureId != 0)
            {
                wdt = Math.Max(1, Math.Max(wdt, richtTextTexture.Width));
                hgt = Math.Max(1, Math.Max(hgt, richtTextTexture.Height));
            }

            surface = new ImageSurface(Format.ARGB32, wdt, hgt);
            ctx     = new Context(surface);
            ctx.SetSourceRGBA(0, 0, 0, 0);
            ctx.Paint();

            if (!genTextureLater)
            {
                ComposeFor(rtbounds, ctx, surface);
                generateTexture(surface, ref richtTextTexture);

                ctx.Dispose();
                surface.Dispose();
                ctx     = null;
                surface = null;
            }
            else
            {
                HalfComposed = true;
            }
        }
Ejemplo n.º 7
0
        void MakeAlarmValueTexture()
        {
            float alarmValueRel = (float)(alarmValue - minValue) / (maxValue - minValue);

            alarmTextureRect = new Rectangled()
            {
                X = padding + (Bounds.InnerWidth - 2 * padding) * alarmValueRel, Y = padding, Width = (Bounds.InnerWidth - 2 * padding) * (1 - alarmValueRel), Height = Bounds.InnerHeight - 2 * padding
            };


            ImageSurface surface = new ImageSurface(Format.Argb32, (int)alarmTextureRect.Width, (int)alarmTextureRect.Height);
            Context      ctx     = genContext(surface);

            ctx.SetSourceRGBA(1, 0, 1, 0.4);

            RoundRectangle(ctx, 0, 0, alarmTextureRect.Width, alarmTextureRect.Height, GuiStyle.ElementBGRadius);
            ctx.Fill();

            generateTexture(surface, ref alarmValueTexture.TextureId);
            ctx.Dispose();
            surface.Dispose();
        }
Ejemplo n.º 8
0
        ImageInfo CreateBlur(ImageInfo source)
        {
            double scale = Math.Max(256 / (double)source.Bounds.Width,
                                    256 / (double)source.Bounds.Height);

            var small = new Gdk.Rectangle(0, 0,
                                          (int)Math.Ceiling(source.Bounds.Width * scale),
                                          (int)Math.Ceiling(source.Bounds.Height * scale));

            var image = new ImageSurface(Format.Argb32,
                                         small.Width,
                                         small.Height);

            var ctx = new Context(image)
            {
                Matrix   = source.Fit(small),
                Operator = Operator.Source
            };
            Pattern p = new SurfacePattern(source.Surface);

            ctx.SetSource(p);

            ctx.Paint();
            p.Dispose();
            ctx.Dispose();

            ImageInfo overlay;

            using (var normal = image.ToPixbuf())
            {
                using (var pixbufBlur = PixbufUtils.Blur(normal, 3, null))
                {
                    overlay = new ImageInfo(pixbufBlur);
                }
            }

            image.Dispose();
            return(overlay);
        }
Ejemplo n.º 9
0
        protected override void OnDeactivate(bool close)
        {
            if (close)
            {
                List <BblTabState> tabStates = new List <BblTabState>();

                foreach (var i in Items)
                {
                    var tab = i as TabViewModel;
                    tab.TabState.isActive = i.IsActive;
                    if (tab.SelectedFolder != null)
                    {
                        tab.TabState.navigated = tab.SelectedFolder.FullName;
                    }
                    foreach (var fsbm in tab.Bookmarks)
                    {
                        var bm = (BblBookmark)fsbm.UserData;
                        if (!bm.destroyOnClose)
                        {
                            tab.TabState.savedBookmarks.Add(bm);
                        }
                    }
                    tabStates.Add(tab.TabState);
                }

                BblTabState.WriteToRegistry(tabStates);
                TabOptions.WriteToRegistry(_savedOptions);

                if (ImageSurface != null && !ImageSurface.IsDisposed)
                {
                    ImageSurface.nextPageRequested         -= OnNextPageRequested;
                    ImageSurface.prevPageRequested         -= OnPrevPageRequested;
                    ImageSurface.fullscreenToggleRequested -= OnFullScreenToggleRequested;
                    ImageSurface.Dispose();
                }
            }
            base.OnDeactivate(close);
        }
Ejemplo n.º 10
0
        internal virtual void RecomposeHandle()
        {
            Bounds.CalcWorldBounds();

            int w = (int)Bounds.InnerWidth;
            int h = (int)currentHandleHeight;

            ImageSurface surface = new ImageSurface(Format.Argb32, w, h);
            Context      ctx     = genContext(surface);

            RoundRectangle(ctx, 0, 0, w, h, 1);
            ctx.SetSourceRGBA(GuiStyle.DialogHighlightColor);
            ctx.FillPreserve();
            ctx.SetSourceRGBA(0, 0, 0, 0.4);
            ctx.Fill();

            EmbossRoundRectangleElement(ctx, 0, 0, w, h, false, 2, 1);

            generateTexture(surface, ref handleTexture);

            ctx.Dispose();
            surface.Dispose();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Save the current Render data as a PNG image.
        /// </summary>
        public void SaveImage()
        {
            if (Running)
            {
                Logger.Say("Please stop the simulation first.");
                return;
            }
            if (ImageData == null)
            {
                Logger.Say("Image output is empty.");
                return;
            }

            var rand  = new Random();
            var title = "render-" + Instance.GetTitle().Replace(" ", "_") + "-" +
                        Math.Truncate(rand.NextDouble() * 100000000);

            var surface = new ImageSurface(ImageData, Format.ARGB32,
                                           RenderWidth, RenderHeight, 4 * RenderWidth);

            surface.WriteToPng(Path.Combine(_dataLogger.FileDir, title + ".png"));
            surface.Dispose();
        }
Ejemplo n.º 12
0
        private void imagepatternToolStripMenuItem_Click(object sender, EventArgs e)
        {
            lastSelected  = "imagepattern";
            OnPaintAction = cr =>
            {
                int          w, h;
                ImageSurface image;

                Pattern pattern;
                Matrix  matrix = new Matrix();

                image = new ImageSurface(romedalenPngData);
                w     = image.Width;
                h     = image.Height;

                pattern        = new SurfacePattern(image);
                pattern.Extend = Extend.Repeat;

                cr.Translate(128.0, 128.0);
                cr.Rotate(Math.PI / 4);
                cr.Scale(1 / Math.Sqrt(2), 1 / Math.Sqrt(2));
                cr.Translate(-128.0, -128.0);

                matrix.InitScale(w / 256.0 * 5.0, h / 256.0 * 5.0);
                pattern.Matrix = matrix;

                cr.SetSource(pattern);

                cr.Rectangle(0, 0, 256.0, 256.0);
                cr.Fill();

                pattern.Dispose();
                image.Dispose();
            };

            Invalidate();
        }
Ejemplo n.º 13
0
        private void imageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            lastSelected  = "image";
            OnPaintAction = cr =>
            {
                int          w, h;
                ImageSurface image;

                image = new ImageSurface(romedalenPngData);
                w     = image.Width;
                h     = image.Height;

                cr.Translate(128.0, 128.0);
                cr.Rotate(45 * Math.PI / 180);
                cr.Scale(256.0 / w, 256.0 / h);
                cr.Translate(-0.5 * w, -0.5 * h);

                cr.SetSource(image, 0, 0);
                cr.Paint();
                image.Dispose();
            };

            Invalidate();
        }
Ejemplo n.º 14
0
        public override void OnMapOpenedClient()
        {
            if (texture == null)
            {
                ImageSurface surface = new ImageSurface(Format.Argb32, 16, 16);
                Context      ctx     = new Context(surface);
                ctx.SetSourceRGBA(0, 0, 0, 0);
                ctx.Paint();

                ctx.Arc(8, 8, 8, 0, 2 * Math.PI);
                ctx.SetSourceRGBA(1, 1, 1, 1);
                ctx.FillPreserve();
                ctx.LineWidth = 1.5;
                ctx.SetSourceRGBA(0.5, 0.5, 0.5, 1);
                ctx.Stroke();

                texture = new LoadedTexture(api as ICoreClientAPI, (api as ICoreClientAPI).Gui.LoadCairoTexture(surface, false), 6, 6);
                ctx.Dispose();
                surface.Dispose();
            }


            RebuildMapComponents();
        }
Ejemplo n.º 15
0
        internal void ComposeHoverTextElement()
        {
            ElementBounds bounds = new ElementBounds().WithFixedPadding(7).WithParent(ElementBounds.Empty);

            textElem = new GuiElementStaticText(api, currentValue + unit, EnumTextOrientation.Center, bounds, CairoFont.WhiteMediumText());
            textElem.Font.UnscaledFontsize = GuiStyle.SmallishFontSize;
            textElem.AutoBoxSize();
            textElem.Bounds.CalcWorldBounds();

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

            ctx.SetSourceRGBA(1, 1, 1, 0);
            ctx.Paint();
            ctx.SetSourceRGBA(0, 0, 0, 0.3);
            RoundRectangle(ctx, 0, 0, bounds.OuterWidth, bounds.OuterHeight, GuiStyle.ElementBGRadius);
            ctx.Fill();

            textElem.ComposeElements(ctx, surface);

            generateTexture(surface, ref hoverTextTextureId);
            ctx.Dispose();
            surface.Dispose();
        }
Ejemplo n.º 16
0
        public void Recompose()
        {
            composed = true;

            stackNameTextElem.Compose();
            priceTextElem.Compose();
            expireTextElem.Compose();
            sellerTextElem.Compose();

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

            ctx.NewPath();
            ctx.LineTo(0, 0);
            ctx.LineTo(2, 0);
            ctx.LineTo(2, 2);
            ctx.LineTo(0, 2);
            ctx.ClosePath();
            ctx.SetSourceRGBA(0, 0, 0, 0.15);
            ctx.Fill();
            generateTexture(surface, ref hoverTexture);
            ctx.Dispose();
            surface.Dispose();
        }
Ejemplo n.º 17
0
        public override void ComposeTextElements(Context ctx, ImageSurface surface)
        {
            EmbossRoundRectangleElement(ctx, Bounds, true, 2, 1);
            ctx.SetSourceRGBA(0, 0, 0, 0.3);
            ElementRoundRectangle(ctx, Bounds, false, 1);
            ctx.Fill();


            ImageSurface surfaceHighlight = new ImageSurface(Format.Argb32, (int)Bounds.OuterWidth, (int)Bounds.OuterHeight);
            Context      ctxHighlight     = genContext(surfaceHighlight);

            ctxHighlight.SetSourceRGBA(1, 1, 1, 0.3);
            ctxHighlight.Paint();

            generateTexture(surfaceHighlight, ref highlightTexture);

            ctxHighlight.Dispose();
            surfaceHighlight.Dispose();

            highlightBounds = Bounds.CopyOffsetedSibling().WithFixedPadding(0, 0).FixedGrow(2 * Bounds.absPaddingX, 2 * Bounds.absPaddingY);
            highlightBounds.CalcWorldBounds();

            RecomposeText();
        }
Ejemplo n.º 18
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();
        }
Ejemplo n.º 19
0
        public override void ComposeTextElements(Context ctxStatic, ImageSurface surfaceStatic)
        {
            Bounds.CalcWorldBounds();

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

            double radius  = scaled(1);
            double spacing = scaled(unscaledTabSpacing);
            double padding = scaled(unscaledTabPadding);

            tabHeight = scaled(unscaledTabHeight);

            double xpos = 0; // bounds.drawX + spacing;
            double ypos = 0; // bounds.drawY;


            Font.Color[3] = 0.85;
            Font.SetupContext(ctx);
            textOffsetY = (tabHeight + 1 - Font.GetFontExtents().Height) / 2;

            double maxWidth = 0;

            for (int i = 0; i < tabs.Length; i++)
            {
                double w = (int)(ctx.TextExtents(tabs[i].Name).Width + 1 + 2 * padding);

                maxWidth = Math.Max(w, maxWidth);
            }


            for (int i = 0; i < tabs.Length; i++)
            {
                tabWidths[i] = (int)maxWidth + 1;

                if (right)
                {
                    xpos  = 1;
                    ypos += tabs[i].PaddingTop;

                    ctx.NewPath();
                    ctx.MoveTo(xpos, ypos + tabHeight);
                    ctx.LineTo(xpos, ypos);
                    ctx.LineTo(xpos + tabWidths[i] + radius, ypos);
                    ctx.ArcNegative(xpos + tabWidths[i], ypos + radius, radius, 270 * GameMath.DEG2RAD, 180 * GameMath.DEG2RAD);
                    ctx.ArcNegative(xpos + tabWidths[i], ypos - radius + tabHeight, radius, 180 * GameMath.DEG2RAD, 90 * GameMath.DEG2RAD);
                }
                else
                {
                    xpos  = (int)Bounds.InnerWidth + 1;
                    ypos += tabs[i].PaddingTop;

                    ctx.NewPath();
                    ctx.MoveTo(xpos, ypos + tabHeight);
                    ctx.LineTo(xpos, ypos);
                    ctx.LineTo(xpos - tabWidths[i] + radius, ypos);
                    ctx.ArcNegative(xpos - tabWidths[i], ypos + radius, radius, 270 * GameMath.DEG2RAD, 180 * GameMath.DEG2RAD);
                    ctx.ArcNegative(xpos - tabWidths[i], ypos - radius + tabHeight, radius, 180 * GameMath.DEG2RAD, 90 * GameMath.DEG2RAD);
                }

                ctx.ClosePath();
                double[] color = GuiStyle.DialogDefaultBgColor;
                ctx.SetSourceRGBA(color[0], color[1], color[2], color[3]);

                ctx.FillPreserve();

                ShadePath(ctx, 2);

                Font.SetupContext(ctx);

                DrawTextLineAt(ctx, tabs[i].Name, xpos - (right ? 0 : tabWidths[i]) + padding, ypos + textOffsetY);

                ypos += tabHeight + spacing;
            }

            Font.Color[3] = 1;

            ComposeOverlays();

            generateTexture(surface, ref baseTexture);

            ctx.Dispose();
            surface.Dispose();
        }
Ejemplo n.º 20
0
        private void ComposeOverlays()
        {
            double radius  = scaled(1);
            double padding = scaled(unscaledTabPadding);
            double width;

            for (int i = 0; i < tabs.Length; i++)
            {
                ImageSurface surface = new ImageSurface(Format.Argb32, tabWidths[i] + 1, (int)tabHeight + 1);
                Context      ctx     = genContext(surface);

                width = tabWidths[i] + 1;

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

                ctx.NewPath();
                ctx.MoveTo(width, tabHeight + 1);
                ctx.LineTo(width, 0);
                ctx.LineTo(radius, 0);
                ctx.ArcNegative(0, radius, radius, 270 * GameMath.DEG2RAD, 180 * GameMath.DEG2RAD);
                ctx.ArcNegative(0, tabHeight - radius, radius, 180 * GameMath.DEG2RAD, 90 * GameMath.DEG2RAD);
                ctx.ClosePath();

                double[] color = GuiStyle.DialogDefaultBgColor;
                ctx.SetSourceRGBA(color[0], color[1], color[2], color[3]);
                ctx.Fill();

                ctx.NewPath();
                if (right)
                {
                    ctx.LineTo(1, 1);
                    ctx.LineTo(width, 1);
                    ctx.LineTo(width, 1 + tabHeight - 1);
                    ctx.LineTo(1, tabHeight - 1);
                }
                else
                {
                    ctx.LineTo(1 + width, 1);
                    ctx.LineTo(1, 1);
                    ctx.LineTo(1, tabHeight - 1);
                    ctx.LineTo(1 + width, 1 + tabHeight - 1);
                }



                float strokeWidth = 2;
                ctx.SetSourceRGBA(GuiStyle.DialogLightBgColor[0] * 1.6, GuiStyle.DialogStrongBgColor[1] * 1.6, GuiStyle.DialogStrongBgColor[2] * 1.6, 1);
                ctx.LineWidth = strokeWidth * 1.75;
                ctx.StrokePreserve();
                surface.Blur(3, 0, 0, (int)width - 1, (int)tabHeight - 1);

                ctx.SetSourceRGBA(new double[] { 45 / 255.0, 35 / 255.0, 33 / 255.0, 1 });
                ctx.LineWidth = strokeWidth;
                ctx.Stroke();


                selectedFont.SetupContext(ctx);

                DrawTextLineAt(ctx, tabs[i].Name, padding + 2, textOffsetY);


                generateTexture(surface, ref hoverTextures[i]);

                ctx.Dispose();
                surface.Dispose();
            }
        }
Ejemplo n.º 21
0
 public void Dispose()
 {
     //clear_images();
     _temp_surface.Dispose();
     _temp_cr.Dispose();
 }
Ejemplo n.º 22
0
        void Recompose()
        {
            if (curSlot?.Itemstack == null)
            {
                return;
            }

            readyToRender = false;

            string title = curSlot.GetStackName();
            string desc  = OnRequireInfoText(curSlot);

            desc.TrimEnd();


            titleElement.SetNewText(title, titleFont);
            descriptionElement.SetNewText(desc, Font);

            RecalcBounds(title, desc);


            Bounds.CalcWorldBounds();

            ElementBounds textBounds = Bounds.CopyOnlySize();

            textBounds.CalcWorldBounds();

            TyronThreadPool.QueueTask(() =>
            {
                /*int i = 0;
                 * while (i < 5 && titleElement.HalfComposed) System.Threading.Thread.Sleep(5);*/

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

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

                ctx.SetSourceRGBA(backTint[0], backTint[1], backTint[2], backTint[3]);
                RoundRectangle(ctx, textBounds.bgDrawX, textBounds.bgDrawY, textBounds.OuterWidthInt, textBounds.OuterHeightInt, GuiStyle.DialogBGRadius);
                ctx.FillPreserve();

                ctx.SetSourceRGBA(GuiStyle.DialogLightBgColor[0] * 1.4, GuiStyle.DialogStrongBgColor[1] * 1.4, GuiStyle.DialogStrongBgColor[2] * 1.4, 1);
                ctx.LineWidth = 3 * 1.75;
                ctx.StrokePreserve();
                surface.Blur(8.2);

                ctx.SetSourceRGBA(backTint[0] / 2, backTint[1] / 2, backTint[2] / 2, backTint[3]);
                ctx.Stroke();


                int w = (int)(scaled(ItemStackSize) + scaled(40));
                int h = (int)(scaled(ItemStackSize) + scaled(40));

                ImageSurface shSurface = new ImageSurface(Format.Argb32, w, h);
                Context shCtx          = genContext(shSurface);

                shCtx.SetSourceRGBA(GuiStyle.DialogSlotBackColor);
                RoundRectangle(shCtx, 0, 0, w, h, 0);
                shCtx.FillPreserve();

                shCtx.SetSourceRGBA(GuiStyle.DialogSlotFrontColor);
                shCtx.LineWidth = 5;
                shCtx.Stroke();
                shSurface.Blur(7);
                shSurface.Blur(7);
                shSurface.Blur(7);
                EmbossRoundRectangleElement(shCtx, 0, 0, w, h, true);


                ctx.SetSourceSurface(shSurface, (int)(textBounds.drawX), (int)(textBounds.drawY + scaled(MarginTop)));
                ctx.Rectangle(textBounds.drawX, textBounds.drawY + scaled(MarginTop), w, h);
                ctx.Fill();

                shCtx.Dispose();
                shSurface.Dispose();


                api.Event.EnqueueMainThreadTask(() =>
                {
                    //titleElement.genTexture();
                    //descriptionElement.genTexture();

                    titleElement.Compose(false);
                    descriptionElement.Compose(false);

                    generateTexture(surface, ref texture);

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

                    double offset = (int)(30 + ItemStackSize / 2);
                    scissorBounds = ElementBounds.Fixed(4 + offset - ItemStackSize, 2 + offset + MarginTop - ItemStackSize, ItemStackSize + 38, ItemStackSize + 38).WithParent(Bounds);
                    scissorBounds.CalcWorldBounds();

                    readyToRender = true;
                }, "genstackinfotexture");
            });
        }
Ejemplo n.º 23
0
 public override void Dispose()
 {
     ImageSurface?.Dispose();
 }
Ejemplo n.º 24
0
        /// <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();
        }
Ejemplo n.º 25
0
        void ComposeCurrentValue()
        {
            double width = Bounds.InnerWidth;

            valueWidth  = (int)((Bounds.InnerWidth - scaled(20)) * Scale);
            valueHeight = (int)(scaled(30) * Scale);

            // Current value
            ImageSurface surface = new ImageSurface(Format.Argb32, valueWidth, valueHeight);
            Context      ctx     = genContext(surface);

            Font.SetupContext(ctx);
            ctx.SetSourceRGBA(GuiStyle.DialogDefaultTextColor);

            string text   = "";
            double height = Font.GetFontExtents().Height;

            if (listMenu.SelectedIndices.Length > 1)
            {
                for (int i = 0; i < listMenu.SelectedIndices.Length; i++)
                {
                    int    index   = listMenu.SelectedIndices[i];
                    string addText = "";

                    if (text.Length > 0)
                    {
                        addText += ", ";
                    }
                    addText += listMenu.Names[index];

                    int cntleft = listMenu.SelectedIndices.Length - i;
                    int cnt     = listMenu.SelectedIndices.Length;

                    string moreText =
                        text.Length > 0 ?
                        (" " + (cntleft == 1 ? Lang.Get(SingularMoreNameCode, cntleft) : Lang.Get(PluralMoreNameCode, cntleft))) :
                        (cnt == 1 ? Lang.Get(SingularNameCode, cnt) : Lang.Get(PluralNameCode, cnt))
                    ;

                    if (Font.GetTextExtents(text + addText + Lang.Get(PluralMoreNameCode, cntleft)).Width < width)
                    {
                        text += addText;
                    }
                    else
                    {
                        text = text + moreText;
                        break;
                    }
                }
            }
            else
            {
                if (listMenu.SelectedIndices.Length == 1)
                {
                    text = listMenu.Names[listMenu.SelectedIndex];
                }
            }


            richTextElem.SetNewTextWithoutRecompose(text, Font);
            richTextElem.BeforeCalcBounds();
            richTextElem.Bounds.fixedX = 5;
            richTextElem.Bounds.fixedY = (valueHeight - height) / 2 / RuntimeEnv.GUIScale;
            richTextElem.BeforeCalcBounds();
            richTextElem.Bounds.CalcWorldBounds();
            richTextElem.ComposeFor(richTextElem.Bounds, ctx, surface);

            generateTexture(surface, ref currentValueTexture);

            ctx.Dispose();
            surface.Dispose();
        }
Ejemplo n.º 26
0
        private void ComposeDynamicElements()
        {
            // Released Button
            int btnWidth  = (int)(scaled(20) * Scale);
            int btnHeight = (int)(Bounds.InnerHeight);

            ImageSurface surface = new ImageSurface(Format.Argb32, btnWidth, btnHeight);
            Context      ctx     = genContext(surface);

            ctx.SetSourceRGB(GuiStyle.DialogDefaultBgColor[0], GuiStyle.DialogDefaultBgColor[1], GuiStyle.DialogDefaultBgColor[2]);
            RoundRectangle(ctx, 0, 0, btnWidth, btnHeight, GuiStyle.ElementBGRadius);
            ctx.FillPreserve();
            ctx.SetSourceRGBA(1, 1, 1, 0.1);
            ctx.Fill();

            EmbossRoundRectangleElement(ctx, 0, 0, btnWidth, btnHeight, false, 2, 1);

            ctx.SetSourceRGBA(GuiStyle.DialogHighlightColor);
            RoundRectangle(ctx, 0, 0, btnWidth, btnHeight, 1);
            ctx.Fill();

            ctx.NewPath();
            ctx.LineTo(btnWidth - scaled(17) * Scale, scaled(10) * Scale);
            ctx.LineTo(btnWidth - scaled(3) * Scale, scaled(10) * Scale);
            ctx.LineTo(btnWidth - scaled(10) * Scale, scaled(20) * Scale);
            ctx.ClosePath();
            ctx.SetSourceRGBA(1, 1, 1, 0.6);
            ctx.Fill();

            generateTexture(surface, ref arrowDownButtonReleased);

            // Pressed Button
            ctx.Operator = Operator.Clear;
            ctx.SetSourceRGBA(0, 0, 0, 0);
            ctx.Paint();
            ctx.Operator = Operator.Over;

            ctx.SetSourceRGB(GuiStyle.DialogDefaultBgColor[0], GuiStyle.DialogDefaultBgColor[1], GuiStyle.DialogDefaultBgColor[2]);
            RoundRectangle(ctx, 0, 0, btnWidth, btnHeight, GuiStyle.ElementBGRadius);
            ctx.FillPreserve();
            ctx.SetSourceRGBA(0, 0, 0, 0.1);
            ctx.Fill();

            EmbossRoundRectangleElement(ctx, 0, 0, btnWidth, btnHeight, true, 2, 1);

            ctx.SetSourceRGBA(GuiStyle.DialogHighlightColor);
            RoundRectangle(ctx, 0, 0, btnWidth, btnHeight, 1);
            ctx.Fill();

            ctx.NewPath();
            ctx.LineTo(btnWidth - scaled(17) * Scale, scaled(10) * Scale);
            ctx.LineTo(btnWidth - scaled(3) * Scale, scaled(10) * Scale);
            ctx.LineTo(btnWidth - scaled(10) * Scale, scaled(20) * Scale);
            ctx.ClosePath();
            ctx.SetSourceRGBA(1, 1, 1, 0.4);
            ctx.Fill();

            generateTexture(surface, ref arrowDownButtonPressed);

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



            // Highlight overlay
            ImageSurface surfaceHighlight = new ImageSurface(Format.Argb32, (int)Bounds.OuterWidth - btnWidth, (int)Bounds.OuterHeight);
            Context      ctxHighlight     = genContext(surfaceHighlight);

            ctxHighlight.SetSourceRGBA(1, 1, 1, 0.3);
            ctxHighlight.Paint();

            generateTexture(surfaceHighlight, ref highlightTexture);

            ctxHighlight.Dispose();
            surfaceHighlight.Dispose();

            highlightBounds             = Bounds.CopyOffsetedSibling().WithFixedPadding(0, 0).FixedGrow(2 * Bounds.absPaddingX, 2 * Bounds.absPaddingY);
            highlightBounds.fixedWidth -= btnWidth;
            highlightBounds.CalcWorldBounds();

            ComposeCurrentValue();
        }
Ejemplo n.º 27
0
        void ComposeInteractiveElements()
        {
            slotBounds           = new ElementBounds[availableSlots.Count];
            scissorBounds        = new ElementBounds[availableSlots.Count];
            slotQuantityTextures = new LoadedTexture[availableSlots.Count];
            for (int k = 0; k < slotQuantityTextures.Length; k++)
            {
                slotQuantityTextures[k] = new LoadedTexture(this.api);
            }

            this.rows = (int)Math.Ceiling(1f * availableSlots.Count / cols);

            Bounds.CalcWorldBounds();

            double unscaledSlotWidth  = GuiElementPassiveItemSlot.unscaledSlotSize;
            double unscaledSlotHeight = GuiElementPassiveItemSlot.unscaledSlotSize;

            // Slot sizes
            double absSlotPadding = scaled(unscaledSlotPadding);
            double absSlotWidth   = scaled(GuiElementPassiveItemSlot.unscaledSlotSize);
            double absSlotHeight  = scaled(GuiElementPassiveItemSlot.unscaledSlotSize);

            ElementBounds textBounds = ElementBounds
                                       .Fixed(0, GuiElementPassiveItemSlot.unscaledSlotSize - GuiStyle.SmallishFontSize - 2, GuiElementPassiveItemSlot.unscaledSlotSize - 5, GuiElementPassiveItemSlot.unscaledSlotSize - 5)
                                       .WithEmptyParent();

            CairoFont font = CairoFont.WhiteSmallText().WithFontSize((float)GuiStyle.SmallishFontSize);

            font.FontWeight  = FontWeight.Bold;
            font.Color       = new double[] { 1, 1, 1, 1 };
            font.StrokeColor = new double[] { 0, 0, 0, 1 };
            font.StrokeWidth = RuntimeEnv.GUIScale;

            textComposer = new GuiElementStaticText(api, "", EnumTextOrientation.Right, textBounds, font);


            // 1. draw generic slot
            ImageSurface slotSurface = new ImageSurface(Format.Argb32, (int)absSlotWidth, (int)absSlotWidth);
            Context      slotCtx     = genContext(slotSurface);

            slotCtx.SetSourceRGBA(GuiStyle.DialogSlotBackColor);
            RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius);
            slotCtx.Fill();

            slotCtx.SetSourceRGBA(GuiStyle.DialogSlotFrontColor);
            RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius);
            slotCtx.LineWidth = scaled(4.5);
            slotCtx.Stroke();
            slotSurface.Blur(scaled(4), true);
            slotSurface.Blur(scaled(4), true);

            RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, 1);
            slotCtx.LineWidth = scaled(4.5);
            slotCtx.SetSourceRGBA(0, 0, 0, 0.8);
            slotCtx.Stroke();



            generateTexture(slotSurface, ref slotTexture, true);

            slotCtx.Dispose();
            slotSurface.Dispose();

            // 2. draw slots with backgrounds
            foreach (var val in availableSlots)
            {
                ItemSlot slot = val.Value;
                string   key  = slot.BackgroundIcon + "-" + slot.HexBackgroundColor;

                if ((slot.BackgroundIcon == null && slot.HexBackgroundColor == null) || slotTextureIdsByBgIconAndColor.ContainsKey(key))
                {
                    continue;
                }


                slotSurface = new ImageSurface(Format.Argb32, (int)absSlotWidth, (int)absSlotWidth);
                slotCtx     = genContext(slotSurface);

                if (slot.HexBackgroundColor != null)
                {
                    double[] bgcolor = ColorUtil.Hex2Doubles(slot.HexBackgroundColor);

                    slotCtx.SetSourceRGBA(bgcolor);
                    RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius);
                    slotCtx.Fill();

                    slotCtx.SetSourceRGBA(bgcolor[0] * 0.25, bgcolor[1] * 0.25, bgcolor[2] * 0.25, 1);
                    RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius);
                    slotCtx.LineWidth = scaled(4.5);
                    slotCtx.Stroke();
                    slotSurface.Blur(scaled(4), true);
                    slotSurface.Blur(scaled(4), true);

                    slotCtx.SetSourceRGBA(0, 0, 0, 0.8);
                    RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, 1);
                    slotCtx.LineWidth = scaled(4.5);
                    slotCtx.Stroke();
                }
                else
                {
                    slotCtx.SetSourceRGBA(GuiStyle.DialogSlotBackColor);
                    RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius);
                    slotCtx.Fill();

                    slotCtx.SetSourceRGBA(GuiStyle.DialogSlotFrontColor);
                    RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius);
                    slotCtx.LineWidth = scaled(4.5);
                    slotCtx.Stroke();
                    slotSurface.Blur(scaled(4), true);
                    slotSurface.Blur(scaled(4), true);

                    RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, 1);
                    slotCtx.LineWidth = scaled(4.5);
                    slotCtx.SetSourceRGBA(0, 0, 0, 0.8);
                    slotCtx.Stroke();
                }


                if (slot.BackgroundIcon != null)
                {
                    DrawIconHandler?.Invoke(
                        slotCtx, slot.BackgroundIcon, 2 * (int)absSlotPadding, 2 * (int)absSlotPadding,
                        (int)(absSlotWidth - 4 * absSlotPadding), (int)(absSlotHeight - 4 * absSlotPadding),
                        new double[] { 0, 0, 0, 0.2 }
                        );
                }

                int texId = 0;
                generateTexture(slotSurface, ref texId, true);

                slotCtx.Dispose();
                slotSurface.Dispose();

                slotTextureIdsByBgIconAndColor[key] = texId;
            }

            // 3. Crossed out overlay
            int csize = (int)absSlotWidth - 4;

            slotSurface = new ImageSurface(Format.Argb32, (int)csize, (int)csize);
            slotCtx     = genContext(slotSurface);

            slotCtx.SetSourceRGBA(0, 0, 0, 0.8);
            api.Gui.Icons.DrawCross(slotCtx, 4, 4, 7, csize - 18, true);
            slotCtx.SetSourceRGBA(1, 0.2, 0.2, 0.8);
            slotCtx.LineWidth = 2;
            slotCtx.Stroke();
            generateTexture(slotSurface, ref crossedOutTexture);
            slotCtx.Dispose();
            slotSurface.Dispose();


            // 4. Slot highlight overlay
            slotSurface = new ImageSurface(Format.Argb32, (int)absSlotWidth + 4, (int)absSlotWidth + 4);
            slotCtx     = genContext(slotSurface);

            slotCtx.SetSourceRGBA(GuiStyle.ActiveSlotColor);
            RoundRectangle(slotCtx, 0, 0, absSlotWidth + 4, absSlotHeight + 4, GuiStyle.ElementBGRadius);
            slotCtx.LineWidth = scaled(9);
            slotCtx.StrokePreserve();
            slotSurface.Blur(scaled(6), true);
            slotCtx.StrokePreserve();
            slotSurface.Blur(scaled(6), true);

            slotCtx.LineWidth = scaled(3);
            slotCtx.Stroke();

            slotCtx.LineWidth = scaled(1);
            slotCtx.SetSourceRGBA(GuiStyle.ActiveSlotColor);
            slotCtx.Stroke();

            generateTexture(slotSurface, ref highlightSlotTexture);



            slotCtx.Dispose();
            slotSurface.Dispose();

            int slotIndex = 0;

            foreach (var val in availableSlots)
            {
                int col = slotIndex % cols;
                int row = slotIndex / cols;

                double x = col * (unscaledSlotWidth + unscaledSlotPadding);
                double y = row * (unscaledSlotHeight + unscaledSlotPadding);

                ItemSlot slot = inventory[val.Key];

                slotBounds[slotIndex] = ElementBounds.Fixed(x, y, unscaledSlotWidth, unscaledSlotHeight).WithParent(Bounds);
                slotBounds[slotIndex].CalcWorldBounds();

                scissorBounds[slotIndex] = ElementBounds.Fixed(x + 2, y + 2, unscaledSlotWidth - 4, unscaledSlotHeight - 4).WithParent(Bounds);
                scissorBounds[slotIndex].CalcWorldBounds();

                ComposeSlotOverlays(slot, val.Key, slotIndex);

                slotIndex++;
            }
        }
Ejemplo n.º 28
0
        private void ComposeOverlays(bool isNotifyTabs = false)
        {
            double radius  = scaled(1);
            double spacing = scaled(unscaledTabSpacing);
            double padding = scaled(unscaledTabPadding);

            for (int i = 0; i < tabs.Length; i++)
            {
                ImageSurface surface = new ImageSurface(Format.Argb32, tabWidths[i], (int)Bounds.InnerHeight + 1);
                Context      ctx     = genContext(surface);

                double degrees = Math.PI / 180.0;

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

                ctx.NewPath();
                ctx.MoveTo(0, Bounds.InnerHeight + 1);
                ctx.LineTo(0, radius);
                ctx.Arc(radius, radius, radius, 180 * degrees, 270 * degrees);
                ctx.Arc(tabWidths[i] - radius, radius, radius, -90 * degrees, 0 * degrees);
                ctx.LineTo(tabWidths[i], Bounds.InnerHeight + 1);
                ctx.ClosePath();

                double[] color = GuiStyle.DialogDefaultBgColor;
                ctx.SetSourceRGBA(color[0], color[1], color[2], color[3] * 0.75);
                ctx.Fill();

                ctx.NewPath();
                ctx.MoveTo(0, Bounds.InnerHeight);
                ctx.LineTo(0, radius);
                ctx.Arc(radius, radius, radius, 180 * degrees, 270 * degrees);
                ctx.Arc(tabWidths[i] - radius, radius, radius, -90 * degrees, 0 * degrees);
                ctx.LineTo(tabWidths[i], Bounds.InnerHeight);

                ShadePath(ctx, 2);

                if (isNotifyTabs)
                {
                    notifyFont.SetupContext(ctx);
                }
                else
                {
                    selectedFont.SetupContext(ctx);
                }


                DrawTextLineAt(ctx, tabs[i].Name, padding, 1);

                if (isNotifyTabs)
                {
                    generateTexture(surface, ref notifyTextures[i]);
                }
                else
                {
                    generateTexture(surface, ref hoverTextures[i]);
                }


                ctx.Dispose();
                surface.Dispose();
            }
        }
Ejemplo n.º 29
0
        public unsafe void Draw(Cairo.Context context, double scale)
        {
            if (decompressed == null || viewing == null)
            {
                return;
            }

            int texOffsetX = 0;
            int texOffsetY = 0;

            int top, left, right, bottom;

            if (Atlas != null)
            {
                int offsetX = Atlas.TopLeft.X - Atlas.Rect.Left;
                int offsetY = Atlas.TopLeft.Y - Atlas.Rect.Top;

                top    = Atlas.Rect.Top + offsetY;
                left   = Atlas.Rect.Left + offsetX;
                right  = Atlas.Rect.Right + offsetX;
                bottom = Atlas.Rect.Bottom + offsetY;

                texOffsetX = -Atlas.Rect.Left + left;
                texOffsetY = -Atlas.Rect.Top + top;
            }
            else
            {
                top    = 0;
                left   = 0;
                right  = viewing.Texture.Width;
                bottom = viewing.Texture.Height;
            }

            context.MoveTo(left, top);
            context.LineTo(left, bottom);
            context.LineTo(right, bottom);
            context.LineTo(right, top);
            context.LineWidth = 0;

            if (blackBackground.Active)
            {
                context.SetSourceRGB(0, 0, 0);
                context.FillPreserve();
            }

            fixed(byte *decompressedFixed = decompressed)
            {
                var buf = new ImageSurface(
                    (IntPtr)decompressedFixed, Format.ARGB32,
                    viewing.Texture.Width, viewing.Texture.Height,
                    viewing.Texture.Width * 4);

                context.SetSourceSurface(buf, texOffsetX, texOffsetY);
                context.Fill();
                context.SetSourceRGB(1, 0, 0);
                buf.Dispose();
            }

            if (Atlas == null)
            {
                if (showAtlasBoxes.Active)
                {
                    foreach (var e in atlasEntries)
                    {
                        foreach (var sa in e.Entries)
                        {
                            context.MoveTo(sa.Rect.Left, sa.Rect.Top);
                            context.LineTo(sa.Rect.Right, sa.Rect.Top);
                            context.LineTo(sa.Rect.Right, sa.Rect.Bottom);
                            context.LineTo(sa.Rect.Left, sa.Rect.Bottom);
                            context.LineTo(sa.Rect.Left, sa.Rect.Top);
                        }
                    }
                    context.LineWidth = 1 / scale;
                    context.Stroke();
                }

                if (showAtlasLabels.Active)
                {
                    foreach (var e in atlasEntries)
                    {
                        foreach (var sa in e.Entries)
                        {
                            context.MoveTo(sa.Rect.Left, sa.Rect.Bottom);
                            context.SetFontSize(16 / scale);
                            context.ShowText(sa.Name);
                        }
                    }
                }
            }
        }
Ejemplo n.º 30
0
        bool ComposeSlotOverlays(ItemSlot slot, int slotId, int slotIndex)
        {
            if (!availableSlots.ContainsKey(slotId))
            {
                return(false);
            }
            if (slot.Itemstack == null)
            {
                return(true);
            }

            //int slotIndex = availableSlots.IndexOfKey(slotId);

            bool drawItemDamage = slot.Itemstack.Collectible.ShouldDisplayItemDamage(slot.Itemstack);

            if (!drawItemDamage)
            {
                slotQuantityTextures[slotIndex].Dispose();
                slotQuantityTextures[slotIndex] = new LoadedTexture(api);
                return(true);
            }

            // This is pretty slow to do this for every slot. Should be made with an atlas
            ImageSurface textSurface = new ImageSurface(Format.Argb32, (int)slotBounds[slotIndex].InnerWidth, (int)slotBounds[slotIndex].InnerHeight);
            Context      textCtx     = genContext(textSurface);

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


            if (drawItemDamage)
            {
                double x = scaled(4);
                double y = (int)slotBounds[slotIndex].InnerHeight - scaled(3) - scaled(4);
                textCtx.SetSourceRGBA(GuiStyle.DialogStrongBgColor);
                double width  = (slotBounds[slotIndex].InnerWidth - scaled(8));
                double height = scaled(4);
                RoundRectangle(textCtx, x, y, width, height, 1);
                textCtx.FillPreserve();
                ShadePath(textCtx, 2);


                float[] color = ColorUtil.ToRGBAFloats(slot.Itemstack.Collectible.GetItemDamageColor(slot.Itemstack));
                textCtx.SetSourceRGB(color[0], color[1], color[2]);

                int   dura   = slot.Itemstack.Collectible.GetDurability(slot.Itemstack);
                float health = (float)slot.Itemstack.Attributes.GetInt("durability", dura) / dura;

                width = health * (slotBounds[slotIndex].InnerWidth - scaled(8));

                RoundRectangle(textCtx, x, y, width, height, 1);
                textCtx.FillPreserve();
                ShadePath(textCtx, 2);
            }

            generateTexture(textSurface, ref slotQuantityTextures[slotIndex]);
            textCtx.Dispose();
            textSurface.Dispose();

            return(true);
        }