Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIImageWithBorder.cs
Go to the documentation of this file.
4using Terraria.UI;
5
7
9{
11
13
15 : base(texture)
16 {
17 SetBorder(borderTexture);
18 }
19
20 public UIImageWithBorder(Texture2D nonReloadingTexture, Texture2D nonReloadingBorderTexture)
21 : base(nonReloadingTexture)
22 {
23 SetBorder(nonReloadingBorderTexture);
24 }
25
26 public void SetBorder(Asset<Texture2D> texture)
27 {
28 _borderTexture = texture;
30 Width.Set(_borderTexture.Width(), 0f);
31 Height.Set(_borderTexture.Height(), 0f);
32 }
33
34 public void SetBorder(Texture2D nonReloadingTexture)
35 {
36 _borderTexture = null;
37 _nonReloadingBorderTexture = nonReloadingTexture;
40 }
41
42 protected override void DrawSelf(SpriteBatch spriteBatch)
43 {
44 base.DrawSelf(spriteBatch);
45 CalculatedStyle dimensions = GetDimensions();
46 Texture2D texture2D = null;
47 if (_borderTexture != null)
48 {
49 texture2D = _borderTexture.Value;
50 }
52 {
54 }
55 if (ScaleToFit)
56 {
57 spriteBatch.Draw(texture2D, dimensions.ToRectangle(), Color);
58 return;
59 }
60 Vector2 vector = texture2D.Size();
61 Vector2 vector2 = dimensions.Position() + vector * (1f - ImageScale) / 2f + vector * NormalizedOrigin;
63 {
64 vector2 = vector2.Floor();
65 }
66 spriteBatch.Draw(texture2D, vector2, null, Color, Rotation, vector * NormalizedOrigin, ImageScale, SpriteEffects.None, 0f);
67 }
68}
void Draw(Texture2D texture, Vector2 position, Color color)
override void DrawSelf(SpriteBatch spriteBatch)
UIImageWithBorder(Asset< Texture2D > texture, Asset< Texture2D > borderTexture)
void SetBorder(Texture2D nonReloadingTexture)
UIImageWithBorder(Texture2D nonReloadingTexture, Texture2D nonReloadingBorderTexture)
StyleDimension Height
Definition UIElement.cs:29
StyleDimension Width
Definition UIElement.cs:27
CalculatedStyle GetDimensions()
Definition UIElement.cs:382
void Set(float pixels, float precent)