Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIPanel.cs
Go to the documentation of this file.
4using Terraria.UI;
5
7
8public class UIPanel : UIElement
9{
10 private int _cornerSize = 12;
11
12 private int _barSize = 4;
13
15
17
19
20 public Color BackgroundColor = new Color(63, 82, 151) * 0.7f;
21
22 public UIPanel()
23 {
24 if (_borderTexture == null)
25 {
26 _borderTexture = Main.Assets.Request<Texture2D>("Images/UI/PanelBorder", (AssetRequestMode)1);
27 }
28 if (_backgroundTexture == null)
29 {
30 _backgroundTexture = Main.Assets.Request<Texture2D>("Images/UI/PanelBackground", (AssetRequestMode)1);
31 }
33 }
34
35 public UIPanel(Asset<Texture2D> customBackground, Asset<Texture2D> customborder, int customCornerSize = 12, int customBarSize = 4)
36 {
37 if (_borderTexture == null)
38 {
39 _borderTexture = customborder;
40 }
41 if (_backgroundTexture == null)
42 {
43 _backgroundTexture = customBackground;
44 }
45 _cornerSize = customCornerSize;
46 _barSize = customBarSize;
48 }
49
50 private void DrawPanel(SpriteBatch spriteBatch, Texture2D texture, Color color)
51 {
52 CalculatedStyle dimensions = GetDimensions();
53 Point point = new Point((int)dimensions.X, (int)dimensions.Y);
54 Point point2 = new Point(point.X + (int)dimensions.Width - _cornerSize, point.Y + (int)dimensions.Height - _cornerSize);
55 int width = point2.X - point.X - _cornerSize;
56 int height = point2.Y - point.Y - _cornerSize;
57 spriteBatch.Draw(texture, new Rectangle(point.X, point.Y, _cornerSize, _cornerSize), new Rectangle(0, 0, _cornerSize, _cornerSize), color);
58 spriteBatch.Draw(texture, new Rectangle(point2.X, point.Y, _cornerSize, _cornerSize), new Rectangle(_cornerSize + _barSize, 0, _cornerSize, _cornerSize), color);
59 spriteBatch.Draw(texture, new Rectangle(point.X, point2.Y, _cornerSize, _cornerSize), new Rectangle(0, _cornerSize + _barSize, _cornerSize, _cornerSize), color);
60 spriteBatch.Draw(texture, new Rectangle(point2.X, point2.Y, _cornerSize, _cornerSize), new Rectangle(_cornerSize + _barSize, _cornerSize + _barSize, _cornerSize, _cornerSize), color);
61 spriteBatch.Draw(texture, new Rectangle(point.X + _cornerSize, point.Y, width, _cornerSize), new Rectangle(_cornerSize, 0, _barSize, _cornerSize), color);
62 spriteBatch.Draw(texture, new Rectangle(point.X + _cornerSize, point2.Y, width, _cornerSize), new Rectangle(_cornerSize, _cornerSize + _barSize, _barSize, _cornerSize), color);
63 spriteBatch.Draw(texture, new Rectangle(point.X, point.Y + _cornerSize, _cornerSize, height), new Rectangle(0, _cornerSize, _cornerSize, _barSize), color);
64 spriteBatch.Draw(texture, new Rectangle(point2.X, point.Y + _cornerSize, _cornerSize, height), new Rectangle(_cornerSize + _barSize, _cornerSize, _cornerSize, _barSize), color);
65 spriteBatch.Draw(texture, new Rectangle(point.X + _cornerSize, point.Y + _cornerSize, width, height), new Rectangle(_cornerSize, _cornerSize, _barSize, _barSize), color);
66 }
67
68 protected override void DrawSelf(SpriteBatch spriteBatch)
69 {
70 if (_backgroundTexture != null)
71 {
73 }
74 if (_borderTexture != null)
75 {
77 }
78 }
79}
void Draw(Texture2D texture, Vector2 position, Color color)
UIPanel(Asset< Texture2D > customBackground, Asset< Texture2D > customborder, int customCornerSize=12, int customBarSize=4)
Definition UIPanel.cs:35
override void DrawSelf(SpriteBatch spriteBatch)
Definition UIPanel.cs:68
void DrawPanel(SpriteBatch spriteBatch, Texture2D texture, Color color)
Definition UIPanel.cs:50
Asset< Texture2D > _backgroundTexture
Definition UIPanel.cs:16
static IAssetRepository Assets
Definition Main.cs:209
CalculatedStyle GetDimensions()
Definition UIElement.cs:382
void SetPadding(float pixels)
Definition UIElement.cs:361