コード例 #1
0
 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);
         }
     }
 }