Beispiel #1
0
        public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
        {
            ctx = 0;
            var    items = Items?.Value();
            string hash  = "";

            hash = items?.GetHashCode().ToString();

            if (previousHash != hash)
            {
                this.Children.Value = new List <DataboundAsset>();
                if (items != null)
                {
                    foreach (VirtualizedDataContext dataContext in items)
                    {
                        var newItem = screenResources.GetTemplate(Template.Value());
                        newItem.VirtualizedDataContext = dataContext;
                        newItem.ParentAsset            = this;

                        this.Children.Value.Add(newItem);
                    }
                }

                this.FixParentChildRelationship();
                this.FixBinds();
                previousHash = hash;
            }


            SetChildrenOriginToMyOrigin();
        }
Beispiel #2
0
        public static async Task <DialogButton> ShowDialog(SmartSpriteBatch spriteBatch, string title, string body, List <DialogButton> buttons)
        {
            TaskCompletionSource <DialogButton> completionSource = new TaskCompletionSource <DialogButton>();
            XuiDialog    dialog = new XuiDialog();
            DialogScreen screen = new DialogScreen
            {
                Buttons = new List <StaticButtonAsset>()
            };

            float margin = 0.005f;

            List <StaticButtonAsset> buttonStack = ButtonHelpers.CreateButtonHorizontalStack(new FloatRectangle(0.15f, 0.75f - margin - margin, 0.75f, 0.1f),
                                                                                             0.1f, margin,
                                                                                             buttons.Select(t => new ButtonBasics(t.Text, (args) =>
            {
                dialog.HandleClick(t, completionSource, screen);
            })).ToList());

            screen.Buttons.AddRange(buttonStack);
            screen.Title = title;
            screen.Body  = body;
            await screen.Initialise();

            Solids.Instance.ScreenManager.Add(screen);
            Solids.Instance.ScreenManager.BringToFront(screen);

            return(await completionSource.Task);
        }
Beispiel #3
0
        public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
        {
            string txt = Text.Value();

            if (!string.IsNullOrWhiteSpace(Symbol.Value()))
            {
                MDL2Symbols symbol = (MDL2Symbols)Enum.Parse(typeof(MDL2Symbols), Symbol.Value());
                txt = symbol.AsChar();
            }

            if (FontName.Value != null)
            {
                this.ActualSize = DrawFontAsset(spriteBatch, screen, opacity, txt, FontColor.Value(),
                                                ActualPosition, FontSize.Value(), LineHeight.Value(), FontName.Value(), PseudoAntiAlias.Value(), WordWrap.Value(),
                                                Justification.Value(), FontMargin.Value(), Margin.Value(), OutlineColor.Value(), Clip, bgTexture, scrollOffset, CaretPos.Value(),
                                                MultiLine.Value(), ScissorRect);
            }


            if (Position.Value.Height == 0)
            {
                autoSize = true;
            }

            if (autoSize)
            {
                this.Position.Value = new FloatRectangle(Position.Value.X, Position.Value.Y, Position.Value.Width, ActualSize.Y);
            }
        }
Beispiel #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 (this.Children.Value == null || this.Children.Value.Count == 0)
            {
                return;
            }

            foreach (DataboundAsset databoundAsset in this.Children.Value)
            {
                databoundAsset.IsHidden.Value = true;
            }

            DataboundAsset select = this.Children.Value.First();

            if (this.State.Value == ButtonState.Hover && this.Children.Value.Count > 1)
            {
                select = this.Children.Value[1];
            }
            if (this.State.Value == ButtonState.Pressing && this.Children.Value.Count > 2)
            {
                select = this.Children.Value[2];
            }

            select.IsHidden.Value = false;

            SetChildrenOriginToMyOrigin();

            if (this.ActualSize == Vector2.Zero)
            {
                this.ActualSize = this.Children.Value.First().ActualSize;
            }
        }
Beispiel #5
0
        public override void Draw(SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null)
        {
            int y = (int)BaseScreen.AllAssets.Max(t => t.Position.Bottom);
            var x = (int)BaseScreen.AllAssets.Max(t => t.Position.Right);

            if (BaseScreen.RenderTarget == null || BaseScreen.RenderTarget.Width != (int)x || BaseScreen.RenderTarget.Height != (int)y)
            {
                BaseScreen.RenderTarget = new RenderTarget2D(Solids.SpriteBatch.GraphicsDevice, x, y);
            }

            Solids.SpriteBatch.GraphicsDevice.SetRenderTarget(BaseScreen.RenderTarget);
            Solids.SpriteBatch.GraphicsDevice.Clear(Color.Transparent);
            //  Solids.SpriteBatch.ForceBegin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.AnisotropicClamp, DepthStencilState.None, RasterizerState.CullNone, null, null);
            using (new SmartSpriteBatchManager(Solids.SpriteBatch))
            {
                BaseScreen.Draw(new GameTime(), BaseScreen.OpenCloseOpacity, null);
            }

            Solids.SpriteBatch.GraphicsDevice.SetRenderTarget(ParentScreen.RenderTarget);

            //  Solids.SpriteBatch.ForceEnd();

            //previousTexture = screen.RenderTarget;

            base.Draw(spriteBatch, screen, opacity, clip, bgTexture);
        }
Beispiel #6
0
        public void DrawText(SmartSpriteBatch spriteBatch, float x, float y, string text, Color?color = null, float scale = 1, float rotation = 1, float depth = 1, SpriteEffects effect = SpriteEffects.None)
        {
            if (_texture == null || text == null)
            {
                return;
            }
            Color col = Color.White;

            if (color != null)
            {
                col = (Color)color;
            }
            float currentX = x;
            float currentY = y;

            foreach (char c in text)
            {
                FontChar fontChar;
                if (_characterMap.TryGetValue(c, out fontChar))
                {
                    var sourceRectangle = new Rectangle(fontChar.X, fontChar.Y, fontChar.Width, fontChar.Height);
                    var position        = new Vector2(currentX + (fontChar.XOffset * scale), currentY + (fontChar.YOffset * scale));

                    spriteBatch.Draw(_texture, position, sourceRectangle, col, rotation, Vector2.Zero, scale, effect, depth);
                    currentX += (fontChar.XAdvance * scale);
                }
            }
        }
        public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
        {
            ctx = 0;
            var    items = Items?.Value();
            string hash  = "";

            hash = items?.GetHashCode().ToString();

            if (previousHash != hash)
            {
                this.Children.Value = new List <DataboundAsset>();
                foreach (VirtualizedDataContext dataContext in items)
                {
                    var newItem = screenResources.GetTemplate(Template.Value());
                    newItem.VirtualizedDataContext = dataContext;
                    newItem.ParentAsset            = this;

                    this.Children.Value.Add(newItem);
                }

                this.FixParentChildRelationship();
                this.FixBinds();
                previousHash = hash;
            }

            float pos = 0;

            foreach (DataboundAsset item in Children.Value)
            {
                if (item.Margin != null && item.Margin.Value != null)
                {
                    pos = pos + item.Margin.Value.Top;
                }


                float width = item.Position.Value.Width;
                if (item.ActualSize.Y > 0)
                {
                    width = item.ActualSize.X;
                }

                float lm = 0;
                float bm = 0;
                float rm = 0;
                if (item.Margin != null && item.Margin.Value != null)
                {
                    lm = item.Margin.Value.Left;
                    bm = item.Margin.Value.Bottom;
                    rm = item.Margin.Value.Right;
                }

                item.Position.Value = new FloatRectangle(lm + pos, 0, item.Position.Value.Width, item.Position.Value.Height);

                pos = pos + width + rm;
            }

            this.ActualSize = new Vector2(this.Position.Value.Width, pos - this.Position.ToVector2().Y);

            SetChildrenOriginToMyOrigin();
        }
Beispiel #8
0
        public static async Task <int> ShowDialog(SmartSpriteBatch spriteBatch, string title, string body,
                                                  List <string> buttons)
        {
            TaskCompletionSource <int> completionSource = new TaskCompletionSource <int>();
            XuiDialog    dialog = new XuiDialog();
            DialogScreen screen = new DialogScreen
            {
                Buttons = new List <StaticButtonAsset>()
            };

            List <StaticButtonAsset> buttonStack = ButtonHelpers.CreateButtonHorizontalStack(new Vector2(0.2f, 0.65f), 0.3f,
                                                                                             0.1f, 0.025f,
                                                                                             buttons.Select(t => new ButtonBasics(t, (args) =>
            {
                dialog.HandleClick(t, buttons.IndexOf(t), completionSource, screen);
            })).ToList());

            screen.Buttons.AddRange(buttonStack);
            screen.Title = title;
            screen.Body  = body;
            await screen.Initialise();

            Solids.Instance.ScreenManager.Add(screen);

            return(await completionSource.Task);
        }
Beispiel #9
0
 public static void DrawBorder(this SmartSpriteBatch spriteBatch, FloatRectangle rect, Color color, int brushSize, FloatRectangle?clip)
 {
     for (int x = 0; x < brushSize; x++)
     {
         for (int y = 0; y < brushSize; y++)
         {
             FloatRectangle r = new FloatRectangle(rect.X + x, rect.Y + y, rect.Width - x - x, rect.Height - y - y);
             spriteBatch.DrawRectangle(r, color, clip: clip);
         }
     }
 }
        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);
            }
        }
Beispiel #11
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();
        }
Beispiel #12
0
        public Texture2D PerformGaussianBlur(Texture2D srcTexture, SmartSpriteBatch spriteBatch)
        {
            RenderTarget2D renderTarget1 = new RenderTarget2D(Solids.Instance.SpriteBatch.GraphicsDevice, srcTexture.Width, srcTexture.Height, false, Solids.Instance.SpriteBatch.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None);

            game.GraphicsDevice.SetRenderTarget(renderTarget1);

            Effect.CurrentTechnique = Effect.Techniques["Technique1"];
            Effect.Parameters["wifth"].SetValue(srcTexture.Width);
            Effect.Parameters["hight"].SetValue(srcTexture.Height);

            using (new SmartSpriteBatchManager(spriteBatch, 0, BlendState.Opaque, null, null, null, Effect))
            {
                spriteBatch.Draw(srcTexture, new Rectangle(0, 0, srcTexture.Width, srcTexture.Height), Color.White);
            }

            game.GraphicsDevice.SetRenderTarget(null);
            return(renderTarget1);
        }
Beispiel #13
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();
        }
Beispiel #14
0
        public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
        {
            float pos = 0;

            foreach (DataboundAsset item in Children.Value.Where(x => !x.IsHiddenOrParentHidden()))
            {
                if (item.Margin != null && item.Margin.Value != null)
                {
                    pos = pos + item.Margin.Value.Top;
                }


                float height = item.Position.Value.Height;
                if (item.ActualSize.Y > 0)
                {
                    height = item.ActualSize.Y;
                }

                if (height == 0)
                {
                    Debug.WriteLine("oops");
                }

                float lm = 0;
                float bm = 0;

                if (item.Margin != null && item.Margin.Value != null)
                {
                    lm = item.Margin.Value.Left;
                    bm = item.Margin.Value.Bottom;
                }

                item.Position.Value = new FloatRectangle(lm, pos, item.Position.Value.Width, item.Position.Value.Height);

                pos = pos + height + bm;
            }

            this.ActualSize = new Vector2(this.Position.Value.Width, pos - this.Position.ToVector2().Y);

            SetChildrenOriginToMyOrigin();
        }
Beispiel #15
0
        public void  DrawText(SmartSpriteBatch spriteBatch, float x, float y, string text, Color?color = null, Vector2?scale = null, float rotation = 1, float depth = 1, SpriteEffects effect = SpriteEffects.None, FloatRectangle?clip = null)
        {
            if (_texture == null || text == null)
            {
                return;
            }
            Vector2 scaling = Vector2.One;
            float   xscale  = 1;
            float   yscale  = 1;

            if (scale != null)
            {
                xscale  = ((Vector2)scale).X;
                yscale  = ((Vector2)scale).Y;
                scaling = (Vector2)scale;
            }
            Color col = Color.White;

            if (color != null)
            {
                col = (Color)color;
            }
            float currentX = x;
            float currentY = y;

            foreach (char c in text)
            {
                FontChar fontChar;
                if (_characterMap.TryGetValue(c, out fontChar))
                {
                    Rectangle sourceRectangle = new Rectangle(fontChar.X, fontChar.Y, fontChar.Width, fontChar.Height);
                    Vector2   position        = new Vector2(currentX + (fontChar.XOffset * xscale), currentY + (fontChar.YOffset * yscale));
                    Rectangle positionRect    = new Rectangle((int)position.X, (int)position.Y, (int)(fontChar.Width * scaling.X), (int)(fontChar.Height * scaling.Y));

                    spriteBatch.Draw(_texture, positionRect, sourceRectangle, col, rotation, Vector2.Zero, effect, depth);

                    currentX += (fontChar.XAdvance * xscale);
                }
            }
        }
Beispiel #16
0
        public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
        {
            if (!haveLoadedTemplate)
            {
                string template = Template.Value();

                List <DataboundAsset> children = this.Children.Value;

                DataboundAsset templateContent = screenResources.GetTemplate(template);
                templateContent.ParentAsset = this;

                if (templateContent is DataboundContainterAsset containerAsset)
                {
                    //containerAsset.Children.Value = children;

                    List <DataboundAsset> contentAssets = containerAsset.FindChildrenOfType <ContentAsset>();
                    if (contentAssets.Count > 0)
                    {
                        foreach (var contentAsset in contentAssets)
                        {
                            ((DataboundContainterAsset)contentAsset.ParentAsset).Children.Value = children;
                        }
                    }
                }

                this.Children.Value = new List <DataboundAsset> {
                    templateContent
                };
                this.FixParentChildRelationship();

                this.FixBinds();
                haveLoadedTemplate = true;
            }

            SetChildrenOriginToMyOrigin();
            if (ActualSize == Vector2.Zero)
            {
                this.ActualSize = this.Children.Value.First().ActualSize;
            }
        }
Beispiel #17
0
        public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
        {
            //    if (approxPoints == null)

            if (Points == null || Points.Value() == null)
            {
                return;
            }

            SetPoints(Points.Value());

            var drawPoints = approxPoints.Select(screen.Translate).ToArray();

            if (ToColor.HasValue())
            {
                spriteBatch.DrawLine(drawPoints, Color.Value(), ToColor.Value(), null, BrushSize.Value);
            }
            else
            {
                spriteBatch.DrawLine(drawPoints, Color.Value(), null, BrushSize.Value);
            }
        }
Beispiel #18
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);
                }
            }
        }
 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));
 }
Beispiel #20
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);
                        }
                    }
                }
            }
        }
Beispiel #22
0
 public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
 {
     SetChildrenOriginToMyOrigin();
     this.ActualSize = this.Children.Value.First().ActualSize;
 }
Beispiel #23
0
 public static void DrawTexturedRectangle(this SmartSpriteBatch spriteBatch, FloatRectangle rect, Color color, string fillTexture, FloatRectangle?clip = null)
 {
     DrawTexturedRectangle(spriteBatch, rect, color, Solids.Instance.AssetLibrary.GetTexture(fillTexture), clip: clip);
 }
Beispiel #24
0
        public static void DrawTexturedRectangle(this SmartSpriteBatch spriteBatch, FloatRectangle trect, Color color, Texture2D fillTexture2D, TileMode tileMode = TileMode.JustStretch, FloatRectangle?clip = null)
        {
            // using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch))
            {
                FloatRectangle rect = trect.Clip(clip);

                switch (tileMode)
                {
                case (TileMode.Tile):
                {
                    for (int y = 0; y < rect.Height; y = y + fillTexture2D.Height)
                    {
                        for (int x = 0; x < rect.Width; x = x + fillTexture2D.Width)
                        {
                            float twidth  = fillTexture2D.Width;
                            float theight = fillTexture2D.Height;

                            float rX = x + rect.X;
                            float rY = y + rect.Y;

                            if (x + twidth > rect.Width)
                            {
                                twidth = fillTexture2D.Width - ((x + twidth) - rect.Width);
                            }

                            if (y + theight > rect.Height)
                            {
                                theight = fillTexture2D.Height - ((y + theight) - rect.Height);
                            }

                            Rectangle sourceRectangle = new Rectangle(0, 0, (int)twidth, (int)theight);
                            Rectangle destRectangle   = new Rectangle((int)rX, (int)rY, (int)twidth, (int)theight);

                            spriteBatch.Draw(fillTexture2D, destRectangle, sourceRectangle, color);
                        }
                    }
                    break;
                }

                case (TileMode.JustStretch):
                {
                    spriteBatch.Draw(fillTexture2D, rect.ToRectangle, color);
                    break;
                }

                case (TileMode.StretchToFill):
                {
                    float rectAspectRatio = (float)rect.Width / (float)rect.Height;
                    float aspectRatio     = (float)fillTexture2D.Width / (float)fillTexture2D.Height;
                    float sw = 0;
                    float sh = 0;
                    int   xo = 0;
                    int   yo = 0;
                    sw = fillTexture2D.Width;
                    sh = sw / rectAspectRatio;
                    yo = (int)((fillTexture2D.Height - sh) / 2f);

                    if (sh > fillTexture2D.Height)
                    {
                        sh = fillTexture2D.Height;
                        sw = sh * rectAspectRatio;

                        yo = 0;
                        xo = (int)((fillTexture2D.Width - sw) / 2f);
                    }

                    Rectangle sourceRect = new Rectangle((int)xo, (int)yo, (int)sw, (int)sh);

                    spriteBatch.Draw(fillTexture2D, rect.ToRectangle, sourceRect, color);
                    break;
                }
                }
            }
        }
        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);
        }
Beispiel #26
0
 public void DrawText(SmartSpriteBatch spriteBatch, Vector2 pos, string text, Color?color = null, Vector2?scale = null, float rotation = 0, float depth = 1, SpriteEffects effect = SpriteEffects.None)
 {
     Renderer.DrawText(spriteBatch, pos.X, pos.Y, text, color, scale, rotation, depth, effect);
 }
Beispiel #27
0
 public void DrawText(SmartSpriteBatch spriteBatch, float x, float y, string text, Color?color = null, float scale = 1, float rotation = 0, float depth = 1, SpriteEffects effect = SpriteEffects.None)
 {
     Renderer.DrawText(spriteBatch, x, y, text, color, scale, rotation, depth, effect);
 }
Beispiel #28
0
 public virtual void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
 {
     throw new NotImplementedException();
 }