public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
        {
            float width    = ActualPosition.Width;
            float height   = ActualPosition.Height;
            float barWidth = BarWidth.Value();

            if (barWidth == 0)
            {
                barWidth = 0.001f;
            }


            float availableWidth = width - barWidth;

            float percentage = Value.Value() / MaxValue.Value();

            float sliderHeight = SliderHeight.Value();

            if (sliderHeight == 0)
            {
                sliderHeight = 0.001f;
            }

            float sliderTop = (height / 2f) - (sliderHeight / 2f);

            FloatRectangle sliderRect = new FloatRectangle(0 + ActualPosition.X, sliderTop + ActualPosition.Y, width, sliderHeight);
            FloatRectangle barRect    = new FloatRectangle(availableWidth * percentage + ActualPosition.X, ActualPosition.Y, barWidth, height);

            if (SliderTexture.HasValue())
            {
                using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch))
                {
                    spriteBatch.Draw(Solids.Instance.AssetLibrary.GetTexture(SliderTexture.Value(), true), screen.Translate(sliderRect).Value.ToRectangle, Color.White);
                }
            }
            else
            {
                spriteBatch.DrawSolidRectangle(screen.Translate(sliderRect).Value, SliderColor.Value().Value *opacity, clip);
            }

            if (BarTexture.HasValue())
            {
                using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch))
                {
                    spriteBatch.Draw(Solids.Instance.AssetLibrary.GetTexture(BarTexture.Value(), true), screen.Translate(barRect).Value.ToRectangle, Color.White);
                }
            }
            else
            {
                spriteBatch.DrawSolidRectangle(screen.Translate(barRect).Value, BarColor.Value().Value *opacity, clip);
            }
        }
Example #2
0
        public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
        {
            if (clip.HasValue && ParentPosition.HasValue)
            {
                clip = clip.Value.ConstrainTo(ParentPosition.Value);
            }

            clip = screen.Translate(clip);

            var t = Position.Value();

            FloatRectangle tmp = screen.Translate(ActualPosition.AdjustForMargin(Margin)).Value;

            if (clip.HasValue)
            {
                if (tmp.Right < clip.Value.X || tmp.X > clip.Value.Right)
                {
                    return;
                }
            }

            if (BlurAmount.Value() > 0)
            {
                Solids.GaussianBlur.DoBlur(bgTexture, BlurAmount.Value(), (BackgroundColor.Value().Value *opacity) * ((BlurAmount.Value() / Solids.MaxBlur)), tmp.ToRectangle, ScissorRect, clip, NoisePerc.Value());
            }

            if (BackgroundColor.Value().HasValue&& FillTexture.Value() == null)
            {
                spriteBatch.DrawSolidRectangle(tmp, BackgroundColor.Value().Value *opacity, clip);
            }

            if (FillTexture.Value() != null)
            {
                using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch))
                {
                    spriteBatch.DrawTexturedRectangle(tmp, BackgroundColor.Value().Value *opacity, Solids.Instance.AssetLibrary.GetTexture(FillTexture.Value()), TilingMode.Value, clip);
                }
            }

            if (BrushSize.Value() > 0)
            {
                spriteBatch.DrawBorder(tmp, BorderColor.Value() * opacity, BrushSize.Value(), clip);
            }

            this.ActualSize = new Vector2(Position.Value().Width, Position.Value().Height).PadForMargin(Margin);

            SetChildrenOriginToMyOrigin();
        }
        List <SmartSpriteBatch.Line> TranslateLines(List <SmartSpriteBatch.Line> lines, ScreenAbstractor screen, float opacity, Vector2?scrollOffset = null)
        {
            List <SmartSpriteBatch.Line> result = new List <SmartSpriteBatch.Line>();

            foreach (SmartSpriteBatch.Line line in lines)
            {
                result.Add(new SmartSpriteBatch.Line(screen.Translate(line.Start.Move(scrollOffset)), screen.Translate(line.End.Move(scrollOffset)), line.Color * opacity, line.BrushSize));
            }

            return(result);
        }
Example #4
0
        public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
        {
            if (Solids.Instance.InputService.IsPressed(InputService.ShiftKeys.LeftShift1))
            {
                //   return;
            }

            if (Texture2D != null)
            {
                FloatRectangle?pos            = screen.Translate(Position.Value.Move(scrollOffset));
                FloatRectangle?translatedClip = screen.Translate(clip);

                Rectangle?fixedSource = SourceRectangle.Value;

                (Rectangle position, Rectangle? source)thing = TextureHelpers.GetAdjustedDestAndSourceAfterClip(pos, fixedSource, translatedClip);
                using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch))
                {
                    //spriteBatch.Draw(Texture2D.Value, thing.Item1, thing.Item2, ImageColor.Value * opacity, Rotation.Value, new Vector2(thing.Item1.Width/2f, thing.Item1.Height/2f),SpriteEffects.None,1f);

                    spriteBatch.Draw(Texture2D.Value, pos.Value.ToRectangle, null, ImageColor.Value * opacity);
                }
            }
        }
Example #5
0
        public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
        {
            using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch))
            {
                Rectangle tmp = screen.Translate(Position.Value.Move(scrollOffset)).ToRectangle().Clip(screen.Translate(clip));

                int borderSize = (int)(Math.Min(tmp.Width, tmp.Height) * BorderSizePercentage.Value);

                spriteBatch.Draw(Solids.Instance.AssetLibrary.GetTexture("Images\\9grid\\tl.png"), new Rectangle(tmp.X - borderSize, tmp.Y - borderSize, borderSize, borderSize), Color.Value * opacity);
                spriteBatch.Draw(Solids.Instance.AssetLibrary.GetTexture("Images\\9grid\\tr.png"), new Rectangle(tmp.Right, tmp.Y - borderSize, borderSize, borderSize), Color.Value * opacity);
                spriteBatch.Draw(Solids.Instance.AssetLibrary.GetTexture("Images\\9grid\\bl.png"), new Rectangle(tmp.X - borderSize, tmp.Bottom, borderSize, borderSize), Color.Value * opacity);
                spriteBatch.Draw(Solids.Instance.AssetLibrary.GetTexture("Images\\9grid\\br.png"), new Rectangle(tmp.Right, tmp.Bottom, borderSize, borderSize), Color.Value * opacity);
                spriteBatch.Draw(Solids.Instance.AssetLibrary.GetTexture("Images\\9grid\\t.png"), new Rectangle(tmp.X, tmp.Y - borderSize, tmp.Width, borderSize), Color.Value * opacity);
                spriteBatch.Draw(Solids.Instance.AssetLibrary.GetTexture("Images\\9grid\\b.png"), new Rectangle(tmp.X, tmp.Bottom, tmp.Width, borderSize), Color.Value * opacity);
                spriteBatch.Draw(Solids.Instance.AssetLibrary.GetTexture("Images\\9grid\\l.png"), new Rectangle(tmp.X - borderSize, tmp.Y, borderSize, tmp.Height), Color.Value * opacity);
                spriteBatch.Draw(Solids.Instance.AssetLibrary.GetTexture("Images\\9grid\\r.png"), new Rectangle(tmp.Right, tmp.Y, borderSize, tmp.Height), Color.Value * opacity);
            }

            SetChildrenOriginToMyOrigin();
        }
Example #6
0
        public static Vector2 DrawFontAsset(
            SmartSpriteBatch spriteBatch,
            ScreenAbstractor screen,
            float opacity,
            string text,
            Color?fontColor,
            FloatRectangle?position,
            float fontSize,
            float?lineHeight,
            string fontName,
            bool pseudoAntiAlias,
            bool wordWrap,
            FontJustification justification,
            float fontMargin,
            Thickness margin      = null,
            Color?outlineColor    = null,
            FloatRectangle?clip   = null,
            Texture2D bgTexture   = null,
            Vector2?scrollOffset  = null,
            int?caretPos          = null,
            bool multiLine        = false,
            Rectangle?scissorRect = null)
        {
            if (position == null)
            {
                return(Vector2.Zero);
            }

            if (string.IsNullOrWhiteSpace(text))
            {
                return(Vector2.Zero);
            }

            List <string> textValues = new List <string> {
                text
            };

            if (multiLine)
            {
                textValues = text.ToList();
            }

            if (fontSize == 0)
            {
                fontSize = 24;
            }

            float lHeight = fontSize * 1.25f;

            if (lineHeight.HasValue)
            {
                lHeight = lineHeight.Value;
            }

            float      translatedBaseSize = screen.Translate(new Vector2(1f, 1f)).Y;
            float      fontSizeRatio      = (translatedBaseSize / 1080f);
            float      translatedFontSize = fontSizeRatio * fontSize;
            FontFamily fontFamily         = Solids.Instance.Fonts.Fonts[fontName];

            if (fontFamily == null)
            {
                return(Vector2.Zero);
            }

            string currentKey = translatedFontSize.ToString() + fontFamily.ToString();


            BMFont myFont = fontFamily.GetFont((int)translatedFontSize);

            Vector2 sizeOfI = myFont.MeasureString("Igj'#" + FontSystem.MDL2Symbols.Download.AsChar());

            float translatedWidth = screen.Translate(position).Value.Width;

            float wordWrapWidth = translatedWidth;

            if (margin != null)
            {
                wordWrapWidth = wordWrapWidth - screen.Translate(new Vector2(margin.Left + margin.Right, 0)).X;
                position      = new FloatRectangle(position.Value.X, position.Value.Y + margin.Top, position.Value.Width, position.Value.Height);
            }

            Vector2 size = myFont.MeasureString(text);

            float scale = translatedFontSize / sizeOfI.Y;

            if (wordWrap && multiLine)
            {
                List <string> lines = textValues.ToList();

                textValues = new List <string>();

                string reconstructedLine = "";
                foreach (string line in lines)
                {
                    string[] words = line.Split(' ');

                    for (int i = 0; i < words.Length; i++)
                    {
                        string withoutCurrentWord = reconstructedLine;
                        reconstructedLine = reconstructedLine + words[i] + " ";

                        Vector2 wwSize = myFont.MeasureString(reconstructedLine);
                        if (wwSize.X * scale > wordWrapWidth)
                        {
                            textValues.Add(withoutCurrentWord);
                            reconstructedLine = "";
                            i = i - 1;
                        }
                    }
                }

                textValues.Add(reconstructedLine);
            }



            float   ulHeight = lHeight / translatedBaseSize;
            Vector2 calcSize = Vector2.Zero;

            for (int i = 0; i < textValues.Count; i++)
            {
                FloatRectangle positionValue = new FloatRectangle(position.Value.X, position.Value.Y + (ulHeight * i), position.Value.Width, ulHeight);
                FloatRectangle fontPos       = new FloatRectangle(positionValue.X, positionValue.Y + fontMargin, positionValue.Width, positionValue.Height - (fontMargin * 2f));

                string textValue = textValues[i];

                FloatRectangle?tclip = screen.Translate(clip);

                FloatRectangle positionRectangle = new FloatRectangle();

                FloatRectangle translatedPosition = screen.Translate(fontPos).Value;

                if (tclip.HasValue)
                {
                    if (translatedPosition.Right < tclip.Value.X || translatedPosition.X > tclip.Value.Right)
                    {
                        return(Vector2.Zero);
                    }
                }

                if (string.IsNullOrWhiteSpace(fontName))
                {
                    return(Vector2.Zero);
                }

                float width = size.X * scale;

                switch (justification)
                {
                case FontJustification.Left:
                {
                    positionRectangle = new FloatRectangle(translatedPosition.X, translatedPosition.Y, width, translatedPosition.Height);
                    break;
                }

                case FontJustification.Right:
                {
                    positionRectangle = new FloatRectangle(translatedPosition.Right - width, translatedPosition.Y, width, translatedPosition.Height);
                    break;
                }

                case FontJustification.Center:
                {
                    positionRectangle = new FloatRectangle(translatedPosition.X + (translatedPosition.Width / 2f) - (width / 2f), translatedPosition.Y, width, translatedPosition.Height);
                    break;
                }
                }

                if (caretPos != null)
                {
                    using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch, scissorRect: tclip))
                    {
                        float actualCarotPos = (width / text.Length) * caretPos.Value;

                        float oppax = (DateTime.Now.Millisecond % 250) / 250f;
                        spriteBatch.DrawLine(
                            new Vector2(positionRectangle.X + actualCarotPos, positionRectangle.Y),
                            new Vector2(positionRectangle.X + actualCarotPos, positionRectangle.Bottom),
                            Color.White * oppax, tclip, 1f);
                    }
                }

                Rectangle source = new Rectangle(0, 0, (int)size.X, (int)size.Y);

                tclip = tclip?.Clamp(scissorRect);

                (Rectangle position, Rectangle? source)translator = TextureHelpers.GetAdjustedDestAndSourceAfterClip(positionRectangle, source, tclip);

                Solids.Instance.SpriteBatch.Scissor = tclip.ToRectangle();

                Rectangle tmp = Solids.Instance.Bounds;
                if (tclip.HasValue)
                {
                    tmp = tclip.Clamp(scissorRect).ToRectangle;
                }

                Solids.Instance.SpriteBatch.Scissor = tmp;

                using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch))
                {
                    if ((pseudoAntiAlias || outlineColor.HasValue))
                    {
                        Color?cl = fontColor * opacity * 0.3f;

                        if (outlineColor.HasValue)
                        {
                            cl = outlineColor.Value * opacity;
                        }

                        for (int y = -1; y <= 1; y = y + 2)
                        {
                            for (int x = -1; x <= 1; x = x + 2)
                            {
                                myFont.DrawText(Solids.Instance.SpriteBatch, translator.position.X + x, translator.position.Y + y, textValue, cl, scale);
                            }
                        }
                    }

                    myFont.DrawText(Solids.Instance.SpriteBatch, translator.position.X, translator.position.Y, textValue, fontColor * opacity, scale);
                    calcSize = new Vector2(position.Value.Width, calcSize.Y + lHeight);
                }

                Solids.Instance.SpriteBatch.Scissor = null;
            }


            float actHeight = screen.Untranslate(calcSize.Y);

            if (margin != null)
            {
                calcSize.Y = calcSize.Y + margin.Bottom;
            }

            return(new Vector2(position.Value.Width, actHeight));
        }
        public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
        {
            if (texture != null)
            {
                if (aspectRatio == 0)
                {
                    aspectRatio = texture.Width / (float)texture.Height;
                }
            }

            if (Texture.HasValue() && (texture == null || loadedTexture != Texture.Value()))
            {
                loadedTexture = Texture.Value();
                texture       = Solids.Instance.AssetLibrary.GetTexture(loadedTexture, true);
            }

            Rectangle rect = screen.Translate(ActualPosition).ToRectangle(); //.Move(scrollOffset)

            if (ScalingMode.Value == ScaleMode.BestFit)
            {
                float newWidth  = rect.Width;
                float newHeight = newWidth / aspectRatio;

                if (newHeight > rect.Height)
                {
                    newHeight = rect.Height;
                    newWidth  = newHeight * aspectRatio;
                }

                float xOffset = (rect.Width - newWidth) / 2f;
                float yOffset = (rect.Height - newHeight) / 2f;

                rect = new Rectangle((int)(rect.X + xOffset), (int)(rect.Y + yOffset), (int)newWidth, (int)newHeight);
            }

            if (ScalingMode.Value == ScaleMode.Fill)
            {
                float newWidth  = rect.Width;
                float newHeight = newWidth / aspectRatio;

                if (newHeight < rect.Height)
                {
                    newHeight = rect.Height;
                    newWidth  = newHeight * aspectRatio;
                }

                float xOffset = (rect.Width - newWidth) / 2f;
                float yOffset = (rect.Height - newHeight) / 2f;

                rect = new Rectangle((int)(rect.X + xOffset), (int)(rect.Y + yOffset), (int)newWidth, (int)newHeight);
            }

            if (ScalingMode.Value == ScaleMode.None)
            {
                rect.Width  = texture.Width;
                rect.Height = texture.Height;
            }

            if (texture != null)
            {
                Color c = Color.White;
                if (Colorize.HasValue())
                {
                    if (Colorize.Value() != null)
                    {
                        c = Colorize.Value().Value;
                    }
                }

                using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch))
                {
                    if (clip == null)
                    {
                        rect = new Rectangle(rect.X + (int)(rect.Width / 2f), rect.Y + (int)(rect.Height / 2f), rect.Width, rect.Height);
                        spriteBatch.Draw(texture, rect, null, c * opacity, Rotation.Value, new Vector2(texture.Width / 2, texture.Height / 2), SpriteEffects.None, 1f);
                    }
                    else
                    {
                        FloatRectangle?tclip  = screen.Translate(clip);
                        Rectangle      source = new Rectangle(0, 0, texture.Width, texture.Height);
                        (Rectangle position, Rectangle? source)translator = TextureHelpers.GetAdjustedDestAndSourceAfterClip(new FloatRectangle(rect), source, tclip);
                        using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch))
                        {
                            spriteBatch.Draw(texture, translator.position, translator.source, c * opacity, Rotation.Value, new Vector2(translator.source.Value.Width / 2f, translator.source.Value.Height / 2f), SpriteEffects.None, 1f);
                        }
                    }
                }
            }
        }
        public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
        {
            if (Solids.Instance.InputService.IsPressed(InputService.ShiftKeys.LeftShift1))
            {
                //  return;
            }

            Vector2 sp = new Vector2(StartPositon.X, StartPositon.Y).Move(scrollOffset);
            Vector2 ep = new Vector2(EndPositon.X, EndPositon.Y).Move(scrollOffset);



            if (clip != null && sp.X < clip.Value.X)
            {
                sp.X = clip.Value.X;
            }
            if (clip != null && sp.X > clip.Value.BottomRight.X)
            {
                sp.X = clip.Value.BottomRight.X;
            }
            if (clip != null && ep.X < clip.Value.X)
            {
                ep.X = clip.Value.X;
            }
            if (clip != null && ep.X > clip.Value.BottomRight.X)
            {
                ep.X = clip.Value.BottomRight.X;
            }


            if (clip != null && sp.Y < clip.Value.Y)
            {
                sp.Y = clip.Value.Y;
            }
            if (clip != null && sp.Y > clip.Value.BottomRight.Y)
            {
                sp.Y = clip.Value.BottomRight.Y;
            }
            if (clip != null && ep.Y < clip.Value.Y)
            {
                ep.Y = clip.Value.Y;
            }
            if (clip != null && ep.Y > clip.Value.BottomRight.Y)
            {
                ep.Y = clip.Value.BottomRight.Y;
            }


            Vector2 start = screen.Translate(sp);
            Vector2 end   = screen.Translate(ep);

            FloatRectangle?tclip = screen.Translate(clip);

            if (tclip.HasValue)
            {
                if ((start.X < tclip.Value.X && end.X < tclip.Value.X) || (start.X > tclip.Value.Right && end.X > tclip.Value.Right))
                {
                    return;
                }
            }

            spriteBatch.DrawLine(new Vector2(start.X, start.Y), new Vector2(end.X, end.Y), Color, null, BrushSize);
        }
 public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
 {
     spriteBatch.DrawLines(TranslateLines(Lines, screen, opacity, scrollOffset), screen.Translate(clip));
 }