|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
using Unity.UIWidgets.widgets; |
|
|
|
using UnityEngine; |
|
|
|
using Color = Unity.UIWidgets.ui.Color; |
|
|
|
using Gradient = Unity.UIWidgets.ui.Gradient; |
|
|
|
|
|
|
const float _indicatorFraction = 0.1f; |
|
|
|
const float _indicatorFontSizePixels = 7.5f; |
|
|
|
const float _indicatorLabelPaddingPixels = 1.0f; |
|
|
|
|
|
|
|
static readonly TextStyle _indicatorTextStyle = new TextStyle( |
|
|
|
color: new Color(0xFF900000), |
|
|
|
fontSize: _indicatorFontSizePixels, |
|
|
|
fontWeight: FontWeight.w800 |
|
|
|
); |
|
|
|
|
|
|
|
static readonly Paint _indicatorPaint = new Paint(); |
|
|
|
|
|
|
|
static readonly Paint _labelBackgroundPaint = new Paint(); |
|
|
|
|
|
|
|
static readonly List<TextPainter> _indicatorLabel = new List<TextPainter>(4); |
|
|
|
|
|
|
|
static DebugOverflowIndicatorMixin() { |
|
|
|
_indicatorPaint.shader = Gradient.linear( |
|
|
|
new Offset(0.0f, 0.0f), |
|
|
|
new Offset(10.0f, 10.0f), |
|
|
|
new List<Color> {_black, _yellow, _yellow, _black}, |
|
|
|
new List<float> {0.25f, 0.25f, 0.75f, 0.75f}, |
|
|
|
TileMode.repeated |
|
|
|
); |
|
|
|
_labelBackgroundPaint.color = new Color(0xFFFFFFFF); |
|
|
|
_OverflowSide e = new _OverflowSide(); |
|
|
|
var len = Enum.GetNames(e.GetType()).Length; |
|
|
|
for (int i = 0; i < len; i++) { |
|
|
|
_indicatorLabel.Add(new TextPainter(textDirection: TextDirection.ltr)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static readonly Dictionary<RenderObject, bool> _overflowReportNeeded = new Dictionary<RenderObject, Boolean>(); |
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
TextStyle _indicatorTextStyle = new TextStyle( |
|
|
|
color: new Color(0xFF900000), |
|
|
|
fontSize: _indicatorFontSizePixels, |
|
|
|
fontWeight: FontWeight.w800 |
|
|
|
); |
|
|
|
|
|
|
|
Paint _indicatorPaint = new Paint{ shader = Gradient.linear( |
|
|
|
new Offset(0.0f, 0.0f), |
|
|
|
new Offset(10.0f, 10.0f), |
|
|
|
new List<Color> {_black, _yellow, _yellow, _black}, |
|
|
|
new List<float> {0.25f, 0.25f, 0.75f, 0.75f}, |
|
|
|
TileMode.repeated |
|
|
|
)}; |
|
|
|
|
|
|
|
Paint _labelBackgroundPaint = new Paint{color = new Color(0xFFFFFFFF)}; |
|
|
|
|
|
|
|
|
|
|
|
TextSpan textSpan = _indicatorLabel[(int) region.side].text as TextSpan; |
|
|
|
if (textSpan?.text != region.label) { |
|
|
|
_indicatorLabel[(int) region.side].text = new TextSpan( |
|
|
|
var textPainter = new TextPainter(textDirection: TextDirection.ltr) { |
|
|
|
text = new TextSpan( |
|
|
|
style: _indicatorTextStyle |
|
|
|
); |
|
|
|
_indicatorLabel[(int) region.side].layout(); |
|
|
|
} |
|
|
|
style: _indicatorTextStyle) |
|
|
|
}; |
|
|
|
textPainter.layout(); |
|
|
|
Offset centerOffset = new Offset(-_indicatorLabel[(int) region.side].width / 2.0f, 0.0f); |
|
|
|
Rect textBackgroundRect = centerOffset & _indicatorLabel[(int) region.side].size; |
|
|
|
Offset centerOffset = new Offset(-textPainter.width / 2.0f, 0.0f); |
|
|
|
Rect textBackgroundRect = centerOffset & textPainter.size; |
|
|
|
_indicatorLabel[(int) region.side].paint(context.canvas, centerOffset); |
|
|
|
textPainter.paint(context.canvas, centerOffset); |
|
|
|
context.canvas.restore(); |
|
|
|
} |
|
|
|
|
|
|
|