-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImage.cs
More file actions
64 lines (56 loc) · 1.75 KB
/
Image.cs
File metadata and controls
64 lines (56 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using JetBrains.Annotations;
using SharpEngine.Core.Math;
using SharpEngine.Core.Renderer;
using SharpEngine.Core.Utils;
namespace SharpEngine.Core.Widget;
/// <summary>
/// Class which display Image
/// </summary>
/// <param name="position">Image Position</param>
/// <param name="texture">Image Texture ("")</param>
/// <param name="scale">Image Scale (Vec2(1))</param>
/// <param name="rotation">Image Rotation (0)</param>
/// <param name="zLayer">Z Layer</param>
public class Image(
Vec2 position,
string texture = "",
Vec2? scale = null,
int rotation = 0,
int zLayer = 0
) : Widget(position, zLayer)
{
/// <summary>
/// Name of Texture which be displayed
/// </summary>
[UsedImplicitly]
public string Texture { get; set; } = texture;
/// <summary>
/// Scale of Image
/// </summary>
[UsedImplicitly]
public Vec2 Scale { get; set; } = scale ?? Vec2.One;
/// <summary>
/// Rotation of Image
/// </summary>
[UsedImplicitly]
public int Rotation { get; set; } = rotation;
/// <inheritdoc />
public override void Draw()
{
base.Draw();
var window = Scene?.Window;
if (!Displayed || Texture.Length <= 0 || window == null)
return;
var finalTexture = window.TextureManager.GetTexture(Texture);
SERender.DrawTexture(
finalTexture,
new Rect(0, 0, finalTexture.Width, finalTexture.Height),
new Rect(RealPosition.X, RealPosition.Y, finalTexture.Width * Scale.X, finalTexture.Height * Scale.Y),
new Vec2(finalTexture.Width / 2f * Scale.X, finalTexture.Height / 2f * Scale.Y),
Rotation,
Color.White,
InstructionSource.Ui,
ZLayer
);
}
}