internal UIVisibleObject(TextureID2D[] tid, string id = "", int layer = 0) : base(id, layer) { // Use TextureID to describe the texture. new VisibleUIObject(new TextureID( // int groupIndex // Filename index in the array Datahandler.TextureFiles // , int idx // Index in the sheet // , int wunits=1, int hunits=1 width and hight units, default 1*1)) if (tid == null || tid.Length == 0 || !DataHandler.isValid(tid[0])) { sprite = null; } else { sprite = tid; size = new Vector2(tid[0].TotalWidth, tid[0].TotalHeight); } }
internal override void Draw(SpriteBatch batch, Camera2D cam = null) { base.Draw(batch, cam); if (!visible) { return; } // Draw overlay if (DataHandler.isValid(overlay)) { RectangleF rect = LocalBoundingBox.Inflate(-Width * border, -Height * border); if (cam == null) { batch.Draw(DataHandler.getTexture(overlay.RefKey) /*Texture2D from file*/, cam == null ? rect.ToRectangle() : cam.Transform(rect).ToRectangle() /*on-screen box*/, DataHandler.getTextureSource(overlay) /*Rectange on the sheet*/, Color.White /*white=no tint*/); } else if (cam.isInsideView(rect)) { RectangleF nocrop; RectangleF cropped = cam.TransformWithCropping(rect, out nocrop); RectangleF source = DataHandler.getTextureSource(overlay); source = source.Mask(nocrop, cropped); batch.Draw(DataHandler.getTexture(overlay.RefKey) /*Texture2D from file*/, cropped.Offset(parent.GlobalPosition).ToRectangle() /*on-screen box*/, source.ToRectangle() /*Rectange on the sheet*/, Color.White /*white=no tint*/); } } // Siblings foreach (UIVisibleObject obj in siblings.Where(t => t is UIVisibleObject)) { obj.Draw(batch, cam); } // Children foreach (UIVisibleObject obj in children.Where(t => t is UIVisibleObject)) { obj.Draw(batch, cam); } // Draw text if (text != "" && text != "\0") { Vector2 tsize = font.MeasureString(text); if (cam == null || cam.isInsideView(LocalCenter)) { batch.DrawString(font, text, GlobalCenter - tsize / 2 - cam.ActualView.Location, color); } } }