Files
2026-06-04 11:42:34 +02:00

335 lines
9.7 KiB
C#

using System;
namespace UnityEngine.Experimental.UIElements
{
// Token: 0x0200031C RID: 796
internal class IMButtonGrid : IMElement
{
// Token: 0x17000B68 RID: 2920
// (get) Token: 0x0600324B RID: 12875 RVA: 0x0004B4BC File Offset: 0x000496BC
// (set) Token: 0x0600324C RID: 12876 RVA: 0x0004B4D8 File Offset: 0x000496D8
public GUIContent[] contents
{
get
{
return this.m_Contents;
}
set
{
this.m_Contents = value ?? this.s_EmptyContents;
}
}
// Token: 0x17000B69 RID: 2921
// (get) Token: 0x0600324D RID: 12877 RVA: 0x0004B4F0 File Offset: 0x000496F0
// (set) Token: 0x0600324E RID: 12878 RVA: 0x0004B50C File Offset: 0x0004970C
public int xCount { get; set; }
// Token: 0x17000B6A RID: 2922
// (get) Token: 0x0600324F RID: 12879 RVA: 0x0004B518 File Offset: 0x00049718
// (set) Token: 0x06003250 RID: 12880 RVA: 0x0004B534 File Offset: 0x00049734
public int selected { get; set; }
// Token: 0x17000B6B RID: 2923
// (get) Token: 0x06003251 RID: 12881 RVA: 0x0004B540 File Offset: 0x00049740
// (set) Token: 0x06003252 RID: 12882 RVA: 0x0004B55C File Offset: 0x0004975C
public GUIStyle firstStyle
{
get
{
return this.m_FirstStyle;
}
set
{
this.m_FirstStyle = value ?? GUIStyle.none;
}
}
// Token: 0x17000B6C RID: 2924
// (get) Token: 0x06003253 RID: 12883 RVA: 0x0004B574 File Offset: 0x00049774
// (set) Token: 0x06003254 RID: 12884 RVA: 0x0004B590 File Offset: 0x00049790
public GUIStyle midStyle
{
get
{
return this.m_MidStyle;
}
set
{
this.m_MidStyle = value ?? GUIStyle.none;
}
}
// Token: 0x17000B6D RID: 2925
// (get) Token: 0x06003255 RID: 12885 RVA: 0x0004B5A8 File Offset: 0x000497A8
// (set) Token: 0x06003256 RID: 12886 RVA: 0x0004B5C4 File Offset: 0x000497C4
public GUIStyle lastStyle
{
get
{
return this.m_LastStyle;
}
set
{
this.m_LastStyle = value ?? GUIStyle.none;
}
}
// Token: 0x06003257 RID: 12887 RVA: 0x0004B5DC File Offset: 0x000497DC
protected override int DoGenerateControlID()
{
return GUIUtility.GetControlID("IMButtonGrid".GetHashCode(), base.focusType, base.position);
}
// Token: 0x06003258 RID: 12888 RVA: 0x0004B60C File Offset: 0x0004980C
protected override bool DoMouseDown(MouseEventArgs args)
{
if (base.position.Contains(args.mousePosition))
{
int num;
float num2;
float num3;
if (this.ComputeElemDimensions(out num, out num2, out num3))
{
Rect[] array = IMButtonGrid.CalcMouseRects(base.position, num, this.xCount, num2, num3, base.style, this.firstStyle, this.midStyle, this.lastStyle, false);
if (this.GetButtonGridMouseSelection(array, args.mousePosition, true) != -1)
{
GUIUtility.hotControl = base.id;
return true;
}
}
}
return false;
}
// Token: 0x06003259 RID: 12889 RVA: 0x0004B6AC File Offset: 0x000498AC
protected override bool DoMouseDrag(MouseEventArgs args)
{
return GUIUtility.hotControl == base.id;
}
// Token: 0x0600325A RID: 12890 RVA: 0x0004B6DC File Offset: 0x000498DC
protected override bool DoMouseUp(MouseEventArgs args)
{
if (GUIUtility.hotControl == base.id)
{
int num;
float num2;
float num3;
if (this.ComputeElemDimensions(out num, out num2, out num3))
{
GUIUtility.hotControl = 0;
Rect[] array = IMButtonGrid.CalcMouseRects(base.position, num, this.xCount, num2, num3, base.style, this.firstStyle, this.midStyle, this.lastStyle, false);
int buttonGridMouseSelection = this.GetButtonGridMouseSelection(array, args.mousePosition, true);
GUI.changed = true;
this.selected = buttonGridMouseSelection;
return true;
}
}
return false;
}
// Token: 0x0600325B RID: 12891 RVA: 0x0004B774 File Offset: 0x00049974
internal override void DoRepaint(IStylePainter args)
{
int num;
float num2;
float num3;
if (this.ComputeElemDimensions(out num, out num2, out num3))
{
GUIStyle guistyle = GUIStyle.none;
GUIClip.Internal_Push(base.position, Vector2.zero, Vector2.zero, false);
Rect rect = new Rect(0f, 0f, base.position.width, base.position.height);
Rect[] array = IMButtonGrid.CalcMouseRects(rect, num, this.xCount, num2, num3, base.style, this.firstStyle, this.midStyle, this.lastStyle, false);
Vector2 vector = args.mousePosition - base.position.position;
int buttonGridMouseSelection = this.GetButtonGridMouseSelection(array, vector, base.id == GUIUtility.hotControl);
bool flag = rect.Contains(args.mousePosition);
GUIUtility.mouseUsed = GUIUtility.mouseUsed || flag;
for (int i = 0; i < num; i++)
{
GUIStyle guistyle2;
if (i != 0)
{
guistyle2 = this.midStyle;
}
else
{
guistyle2 = this.firstStyle;
}
if (i == num - 1)
{
guistyle2 = this.lastStyle;
}
if (num == 1)
{
guistyle2 = base.style;
}
if (i != this.selected)
{
guistyle2.Draw(array[i], this.contents[i], i == buttonGridMouseSelection && (this.enabled || base.id == GUIUtility.hotControl) && (base.id == GUIUtility.hotControl || GUIUtility.hotControl == 0), base.id == GUIUtility.hotControl && this.enabled, false, false);
}
else
{
guistyle = guistyle2;
}
}
if (this.selected < num && this.selected > -1)
{
guistyle.Draw(array[this.selected], this.contents[this.selected], this.selected == buttonGridMouseSelection && (this.enabled || base.id == GUIUtility.hotControl) && (base.id == GUIUtility.hotControl || GUIUtility.hotControl == 0), base.id == GUIUtility.hotControl, true, false);
}
if (buttonGridMouseSelection >= 0)
{
GUI.tooltip = this.contents[buttonGridMouseSelection].tooltip;
}
GUIClip.Internal_Pop();
}
}
// Token: 0x0600325C RID: 12892 RVA: 0x0004B9FC File Offset: 0x00049BFC
private static Rect[] CalcMouseRects(Rect position, int count, int xCount, float elemWidth, float elemHeight, GUIStyle style, GUIStyle firstStyle, GUIStyle midStyle, GUIStyle lastStyle, bool addBorders)
{
int num = 0;
float num2 = position.xMin;
float num3 = position.yMin;
GUIStyle guistyle = style;
Rect[] array = new Rect[count];
if (count > 1)
{
guistyle = firstStyle;
}
for (int i = 0; i < count; i++)
{
if (!addBorders)
{
array[i] = new Rect(num2, num3, elemWidth, elemHeight);
}
else
{
array[i] = guistyle.margin.Add(new Rect(num2, num3, elemWidth, elemHeight));
}
array[i].width = Mathf.Round(array[i].xMax) - Mathf.Round(array[i].x);
array[i].x = Mathf.Round(array[i].x);
GUIStyle guistyle2 = midStyle;
if (i == count - 2)
{
guistyle2 = lastStyle;
}
num2 += elemWidth + (float)Mathf.Max(guistyle.margin.right, guistyle2.margin.left);
num++;
if (num >= xCount)
{
num = 0;
num3 += elemHeight + (float)Mathf.Max(style.margin.top, style.margin.bottom);
num2 = position.xMin;
}
}
return array;
}
// Token: 0x0600325D RID: 12893 RVA: 0x0004BB60 File Offset: 0x00049D60
private int GetButtonGridMouseSelection(Rect[] buttonRects, Vector2 mousePos, bool findNearest)
{
for (int i = 0; i < buttonRects.Length; i++)
{
if (buttonRects[i].Contains(mousePos))
{
return i;
}
}
if (!findNearest)
{
return -1;
}
float num = float.MaxValue;
int num2 = -1;
for (int j = 0; j < buttonRects.Length; j++)
{
Rect rect = buttonRects[j];
Vector2 vector = new Vector2(Mathf.Clamp(mousePos.x, rect.xMin, rect.xMax), Mathf.Clamp(mousePos.y, rect.yMin, rect.yMax));
float sqrMagnitude = (mousePos - vector).sqrMagnitude;
if (sqrMagnitude < num)
{
num2 = j;
num = sqrMagnitude;
}
}
return num2;
}
// Token: 0x0600325E RID: 12894 RVA: 0x0004BC44 File Offset: 0x00049E44
private int CalcTotalHorizSpacing()
{
int num;
if (this.xCount < 2)
{
num = 0;
}
else if (this.xCount == 2)
{
num = Mathf.Max(this.firstStyle.margin.right, this.lastStyle.margin.left);
}
else
{
int num2 = Mathf.Max(this.midStyle.margin.left, this.midStyle.margin.right);
num = Mathf.Max(this.firstStyle.margin.right, this.midStyle.margin.left) + Mathf.Max(this.midStyle.margin.right, this.lastStyle.margin.left) + num2 * (this.xCount - 3);
}
return num;
}
// Token: 0x0600325F RID: 12895 RVA: 0x0004BD20 File Offset: 0x00049F20
private bool ComputeElemDimensions(out int count, out float elemWidth, out float elemHeight)
{
count = this.contents.Length;
elemWidth = 0f;
elemHeight = 0f;
bool flag;
if (count == 0)
{
flag = false;
}
else if (this.xCount <= 0)
{
Debug.LogWarning("You are trying to create a SelectionGrid with zero or less elements to be displayed in the horizontal direction. Set xCount to a positive value.");
flag = false;
}
else
{
int num = count / this.xCount;
if (count % this.xCount != 0)
{
num++;
}
float num2 = (float)this.CalcTotalHorizSpacing();
float num3 = (float)(Mathf.Max(base.style.margin.top, base.style.margin.bottom) * (num - 1));
elemWidth = (base.position.width - num2) / (float)this.xCount;
elemHeight = (base.position.height - num3) / (float)num;
if (base.style.fixedWidth != 0f)
{
elemWidth = base.style.fixedWidth;
}
if (base.style.fixedHeight != 0f)
{
elemHeight = base.style.fixedHeight;
}
flag = true;
}
return flag;
}
// Token: 0x04000A28 RID: 2600
private GUIContent[] s_EmptyContents = new GUIContent[0];
// Token: 0x04000A29 RID: 2601
private GUIContent[] m_Contents;
// Token: 0x04000A2C RID: 2604
private GUIStyle m_FirstStyle = GUIStyle.none;
// Token: 0x04000A2D RID: 2605
private GUIStyle m_MidStyle = GUIStyle.none;
// Token: 0x04000A2E RID: 2606
private GUIStyle m_LastStyle = GUIStyle.none;
}
}