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();
        }
Exemple #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 (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;
            }
        }
Exemple #3
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();
        }
Exemple #4
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);
            }
        }
        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);
            }
        }
Exemple #6
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();
        }
        public static List <DataboundAsset> HandleChildren(BaseScreen.Resources screenResources, XmlNode node, DataboundAsset parentAsset = null, BaseScreen screen = null)
        {
            List <DataboundAsset> results = new List <DataboundAsset>();
            List <Type>           types   = ReflectionHelpers.TypesImplementingInterface(typeof(DataboundAsset)).ToList();

            foreach (XmlNode childNode in node.ChildNodes)
            {
                Type type = types.FirstOrDefault(t => t.Name == childNode.Name);
                if (type != null)
                {
                    DataboundAsset asset = DataboundAsset.CreateFromXml(childNode.Attributes, type, parentAsset, screen);
                    asset.ParentAsset = parentAsset;

                    if (asset is DataboundAssetWhereChildIsContentAsset masterAsset && !string.IsNullOrEmpty(childNode.InnerText))
                    {
                        masterAsset.LoadContent(childNode.InnerText);
                    }

                    if (asset is DataboundContainterAsset containerAsset)
                    {
                        containerAsset.Children.Value.AddRange(HandleChildren(screenResources, childNode, asset));
                    }

                    results.Add(asset);
                }
                else
                {
                    if (childNode.Name.ToLower() == "resources")
                    {
                        foreach (XmlNode xmlNode in childNode.ChildNodes)
                        {
                            if (xmlNode.Name.ToLower() == "template")
                            {
                                string nm = (string)xmlNode.Attributes.GetNamedItem("Name").Value;

                                string templateAsString = xmlNode.InnerXml;
                                screenResources.TemplateXMLs.Add(nm, templateAsString);
                            }
                        }
                    }
                }
            }

            return(results);
        }
        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();
        }
Exemple #9
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();
        }
        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;
            }
        }
Exemple #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 (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);
            }
        }
Exemple #12
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));
 }
 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;
 }
Exemple #15
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();
 }
        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);
        }