Texture.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using System;
  4. namespace OpenVIII.IGMDataItem
  5. {
  6. public class Texture : Base, I_Data<Texture2D>, I_Color
  7. {
  8. #region Constructors
  9. public Texture()
  10. {
  11. Color = Color.White;
  12. Faded_Color = Color;
  13. Blink_Adjustment = 1f;
  14. }
  15. #endregion Constructors
  16. #region Properties
  17. public override bool Blink { get => base.Blink && (Color != Faded_Color); set => base.Blink = value; }
  18. public Texture2D Data { get; set; }
  19. public Rectangle Restriction { get; set; }
  20. #endregion Properties
  21. #region Methods
  22. public override void Draw()
  23. {
  24. if (Enabled)
  25. {
  26. var p = Pos;
  27. var src = new Rectangle(0, 0, Data.Width, Data.Height);
  28. if (!Restriction.IsEmpty)
  29. {
  30. p = Rectangle.Intersect(p, Restriction);
  31. if (p != Pos)
  32. {
  33. var missing = new Rectangle(
  34. Math.Abs(p.X - Pos.X),
  35. Math.Abs(p.Y - Pos.Y),
  36. Pos.Width - p.Width,
  37. Pos.Height - p.Height
  38. );
  39. var scale = new Vector2(
  40. (float)Width / Data.Width,
  41. (float)Height / Data.Height);
  42. var ploc = (src.Location.ToVector2() * scale + missing.Location.ToVector2()) / scale;
  43. var pSize = (src.Size.ToVector2() * scale - missing.Size.ToVector2()) / scale;
  44. src.Location = ploc.ToPoint();
  45. src.Size = pSize.ToPoint();
  46. }
  47. }
  48. if (!Blink)
  49. Memory.SpriteBatch.Draw(Data, p, src, Color * Fade);
  50. else
  51. Memory.SpriteBatch.Draw(Data, p, src, Color.Lerp(Color, Faded_Color, Menu.Blink_Amount) * Blink_Adjustment * Fade);
  52. // if (Blink) Memory.spriteBatch.Draw(Data, Pos, null, Faded_Color * Fade *
  53. // Blink_Amount * Blink_Adjustment);
  54. }
  55. }
  56. #endregion Methods
  57. }
  58. }