Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIImageButton.cs
Go to the documentation of this file.
5using Terraria.UI;
6
8
9public class UIImageButton : UIElement
10{
12
13 private float _visibilityActive = 1f;
14
15 private float _visibilityInactive = 0.4f;
16
18
20 {
21 _texture = texture;
22 Width.Set(_texture.Width(), 0f);
23 Height.Set(_texture.Height(), 0f);
24 }
25
26 public void SetHoverImage(Asset<Texture2D> texture)
27 {
28 _borderTexture = texture;
29 }
30
31 public void SetImage(Asset<Texture2D> texture)
32 {
33 _texture = texture;
34 Width.Set(_texture.Width(), 0f);
35 Height.Set(_texture.Height(), 0f);
36 }
37
38 protected override void DrawSelf(SpriteBatch spriteBatch)
39 {
40 CalculatedStyle dimensions = GetDimensions();
41 spriteBatch.Draw(_texture.Value, dimensions.Position(), Color.White * (base.IsMouseHovering ? _visibilityActive : _visibilityInactive));
42 if (_borderTexture != null && base.IsMouseHovering)
43 {
44 spriteBatch.Draw(_borderTexture.Value, dimensions.Position(), Color.White);
45 }
46 }
47
48 public override void MouseOver(UIMouseEvent evt)
49 {
50 base.MouseOver(evt);
52 }
53
54 public override void MouseOut(UIMouseEvent evt)
55 {
56 base.MouseOut(evt);
57 }
58
59 public void SetVisibility(float whenActive, float whenInactive)
60 {
61 _visibilityActive = MathHelper.Clamp(whenActive, 0f, 1f);
62 _visibilityInactive = MathHelper.Clamp(whenInactive, 0f, 1f);
63 }
64}
void Draw(Texture2D texture, Vector2 position, Color color)
static float Clamp(float value, float min, float max)
Definition MathHelper.cs:46
static void PlaySound(int type, Vector2 position, int style=1)
void SetVisibility(float whenActive, float whenInactive)
void SetHoverImage(Asset< Texture2D > texture)
override void MouseOut(UIMouseEvent evt)
override void MouseOver(UIMouseEvent evt)
override void DrawSelf(SpriteBatch spriteBatch)
void SetImage(Asset< Texture2D > texture)
StyleDimension Height
Definition UIElement.cs:29
StyleDimension Width
Definition UIElement.cs:27
CalculatedStyle GetDimensions()
Definition UIElement.cs:382
void Set(float pixels, float precent)