Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIImage.cs
Go to the documentation of this file.
4using Terraria.UI;
5
7
8public class UIImage : UIElement
9{
11
12 public float ImageScale = 1f;
13
14 public float Rotation;
15
16 public bool ScaleToFit;
17
18 public bool AllowResizingDimensions = true;
19
21
23
25
27
28 public UIImage(Asset<Texture2D> texture)
29 {
30 SetImage(texture);
31 }
32
33 public UIImage(Texture2D nonReloadingTexture)
34 {
35 SetImage(nonReloadingTexture);
36 }
37
38 public void SetImage(Asset<Texture2D> texture)
39 {
40 _texture = texture;
43 {
44 Width.Set(_texture.Width(), 0f);
45 Height.Set(_texture.Height(), 0f);
46 }
47 }
48
49 public void SetImage(Texture2D nonReloadingTexture)
50 {
51 _texture = null;
52 _nonReloadingTexture = nonReloadingTexture;
54 {
57 }
58 }
59
60 protected override void DrawSelf(SpriteBatch spriteBatch)
61 {
62 CalculatedStyle dimensions = GetDimensions();
63 Texture2D texture2D = null;
64 if (_texture != null)
65 {
66 texture2D = _texture.Value;
67 }
68 if (_nonReloadingTexture != null)
69 {
70 texture2D = _nonReloadingTexture;
71 }
72 if (ScaleToFit)
73 {
74 spriteBatch.Draw(texture2D, dimensions.ToRectangle(), Color);
75 return;
76 }
77 Vector2 vector = texture2D.Size();
78 Vector2 vector2 = dimensions.Position() + vector * (1f - ImageScale) / 2f + vector * NormalizedOrigin;
80 {
81 vector2 = vector2.Floor();
82 }
83 spriteBatch.Draw(texture2D, vector2, null, Color, Rotation, vector * NormalizedOrigin, ImageScale, SpriteEffects.None, 0f);
84 }
85}
void Draw(Texture2D texture, Vector2 position, Color color)
void SetImage(Asset< Texture2D > texture)
Definition UIImage.cs:38
override void DrawSelf(SpriteBatch spriteBatch)
Definition UIImage.cs:60
UIImage(Asset< Texture2D > texture)
Definition UIImage.cs:28
void SetImage(Texture2D nonReloadingTexture)
Definition UIImage.cs:49
UIImage(Texture2D nonReloadingTexture)
Definition UIImage.cs:33
StyleDimension Height
Definition UIElement.cs:29
StyleDimension Width
Definition UIElement.cs:27
CalculatedStyle GetDimensions()
Definition UIElement.cs:382
void Set(float pixels, float precent)