Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
RectangleWidget.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
5 public class RectangleWidget : Widget {
7
8 public bool m_textureWrap;
9
11
13
15
16 public Vector2 Size { get; set; }
17
18 public float Depth {
19 get;
20 // ReSharper disable UnusedAutoPropertyAccessor.Global
21 set;
22 // ReSharper restore UnusedAutoPropertyAccessor.Global
23 }
24
25 public bool DepthWriteEnabled {
27 // ReSharper disable PropertyCanBeMadeInitOnly.Global
28 set => m_depthWriteEnabled = value;
29 // ReSharper restore PropertyCanBeMadeInitOnly.Global
30 }
31
33 get => m_subtexture;
34 set => m_subtexture = value;
35 }
36
37 public bool TextureWrap {
38 get => m_textureWrap;
39 // ReSharper disable UnusedMember.Global
40 set => m_textureWrap = value;
41 // ReSharper restore UnusedMember.Global
42 }
43
44 public bool TextureLinearFilter {
46 set => m_textureLinearFilter = value;
47 }
48
51 set => m_textureAnisotropicFilter = value;
52 }
53
54 public bool FlipHorizontal { get; set; }
55
56 public bool FlipVertical {
57 get;
58 // ReSharper disable UnusedAutoPropertyAccessor.Global
59 set;
60 // ReSharper restore UnusedAutoPropertyAccessor.Global
61 }
62
63 public Color FillColor { get; set; }
64
65 public Color OutlineColor { get; set; }
66
67 public float OutlineThickness { get; set; }
68
69 public Vector2 Texcoord1 { get; set; }
70
71 public Vector2 Texcoord2 { get; set; }
72
74
75 public RectangleWidget() {
76 Size = new Vector2(float.PositiveInfinity);
81 IsHitTestVisible = false;
84 }
85
86 public override void Draw(DrawContext dc) {
87 if (FillColor.A == 0
88 && (OutlineColor.A == 0 || OutlineThickness <= 0f)) {
89 return;
90 }
94 Vector2 v2 = new(ActualSize.X, 0f);
96 Vector2 v4 = new(0f, ActualSize.Y);
97 Vector2.Transform(ref v, ref m, out Vector2 result);
98 Vector2.Transform(ref v2, ref m, out Vector2 result2);
99 Vector2.Transform(ref v3, ref m, out Vector2 result3);
100 Vector2.Transform(ref v4, ref m, out Vector2 result4);
102 if (color.A != 0) {
103 if (Subtexture != null) {
104 SamplerState samplerState;
107 }
108 else {
111 }
113 Subtexture.Texture,
114 true,
115 0,
116 depthStencilState,
117 null,
119 samplerState
120 );
121 Vector2 zero = default;
122 Vector2 texCoord;
123 Vector2 texCoord2 = default;
124 Vector2 texCoord3;
125 if (TextureWrap) {
126 zero = Vector2.Zero;
127 texCoord = new Vector2(ActualSize.X / Subtexture.Texture.Width, 0f);
128 texCoord2 = new Vector2(ActualSize.X / Subtexture.Texture.Width, ActualSize.Y / Subtexture.Texture.Height);
129 texCoord3 = new Vector2(0f, ActualSize.Y / Subtexture.Texture.Height);
130 }
131 else {
132 zero.X = MathUtils.Lerp(Subtexture.TopLeft.X, Subtexture.BottomRight.X, Texcoord1.X);
133 zero.Y = MathUtils.Lerp(Subtexture.TopLeft.Y, Subtexture.BottomRight.Y, Texcoord1.Y);
134 texCoord2.X = MathUtils.Lerp(Subtexture.TopLeft.X, Subtexture.BottomRight.X, Texcoord2.X);
135 texCoord2.Y = MathUtils.Lerp(Subtexture.TopLeft.Y, Subtexture.BottomRight.Y, Texcoord2.Y);
136 texCoord = new Vector2(texCoord2.X, zero.Y);
137 texCoord3 = new Vector2(zero.X, texCoord2.Y);
138 }
139 if (FlipHorizontal) {
140 Utilities.Swap(ref zero.X, ref texCoord.X);
141 Utilities.Swap(ref texCoord2.X, ref texCoord3.X);
142 }
143 if (FlipVertical) {
144 Utilities.Swap(ref zero.Y, ref texCoord2.Y);
145 Utilities.Swap(ref texCoord.Y, ref texCoord3.Y);
146 }
147 texturedBatch2D.QueueQuad(
148 result,
149 result2,
150 result3,
151 result4,
152 Depth,
153 zero,
154 texCoord,
155 texCoord2,
156 texCoord3,
157 color
158 );
159 }
160 else {
161 dc.PrimitivesRenderer2D.FlatBatch(1, depthStencilState).QueueQuad(result, result2, result3, result4, Depth, color);
162 }
163 }
165 if (color2.A != 0
166 && OutlineThickness > 0f) {
167 FlatBatch2D flatBatch2D = dc.PrimitivesRenderer2D.FlatBatch(1, depthStencilState);
168 Vector2 vector = Vector2.Normalize(GlobalTransform.Right.XY);
170 int num = (int)MathUtils.Max(MathF.Round(OutlineThickness * GlobalTransform.Right.Length()), 1f);
171 for (int i = 0; i < num; i++) {
172 flatBatch2D.QueueLine(result, result2, Depth, color2);
173 flatBatch2D.QueueLine(result2, result3, Depth, color2);
174 flatBatch2D.QueueLine(result3, result4, Depth, color2);
175 flatBatch2D.QueueLine(result4, result, Depth, color2);
176 result += vector - v5;
177 result2 += -vector - v5;
178 result3 += -vector + v5;
179 result4 += vector + v5;
180 }
181 }
182 }
183
184 public override void MeasureOverride(Vector2 parentAvailableSize) {
185 IsDrawRequired = FillColor.A != 0 || (OutlineColor.A != 0 && OutlineThickness > 0f);
187 }
188 }
189}
static readonly BlendState AlphaBlend
static readonly DepthStencilState None
static readonly DepthStencilState DepthWrite
void QueueQuad(Vector2 corner1, Vector2 corner2, float depth, Color color)
void QueueLine(Vector2 p1, Vector2 p2, float depth, Color color)
TexturedBatch2D TexturedBatch(Texture2D texture, bool useAlphaTest=false, int layer=0, DepthStencilState depthStencilState=null, RasterizerState rasterizerState=null, BlendState blendState=null, SamplerState samplerState=null)
FlatBatch2D FlatBatch(int layer=0, DepthStencilState depthStencilState=null, RasterizerState rasterizerState=null, BlendState blendState=null)
static SamplerState AnisotropicWrap
static SamplerState AnisotropicClamp
void QueueQuad(Vector2 corner1, Vector2 corner2, float depth, Vector2 texCoord1, Vector2 texCoord2, Color color)
static int Max(int x1, int x2)
static float Lerp(float x1, float x2, float f)
override void MeasureOverride(Vector2 parentAvailableSize)
override void Draw(DrawContext dc)
readonly PrimitivesRenderer2D PrimitivesRenderer2D
Color GlobalColorTransform
Vector2 DesiredSize
bool IsDrawRequired
virtual bool IsHitTestVisible
Vector2 ActualSize
Matrix GlobalTransform
static Color White
static Color Black
定义 Color.cs:7
static readonly Vector2 Zero
static readonly Vector2 One
static Vector2 Transform(Vector2 v, Matrix m)
static Vector2 Normalize(Vector2 v)