Fix runtime color alpha composition
This commit is contained in:
@@ -12,6 +12,11 @@ import '../models/runtime_node.dart';
|
||||
import '../protocol/runtime_protocol.dart';
|
||||
import '../resources/game_resource_manager.dart';
|
||||
|
||||
@visibleForTesting
|
||||
Color composeRuntimeColorAlpha(Color color, double alpha) {
|
||||
return color.withValues(alpha: color.a * alpha.clamp(0.0, 1.0));
|
||||
}
|
||||
|
||||
class RuntimeComponent extends PositionComponent
|
||||
with HasVisibility, TapCallbacks {
|
||||
RuntimeComponent({
|
||||
@@ -156,7 +161,10 @@ class RuntimeComponent extends PositionComponent
|
||||
}
|
||||
|
||||
final paint = Paint()
|
||||
..color = (_node.color ?? _defaultColor()).withValues(alpha: renderAlpha);
|
||||
..color = composeRuntimeColorAlpha(
|
||||
_node.color ?? _defaultColor(),
|
||||
renderAlpha,
|
||||
);
|
||||
|
||||
canvas.save();
|
||||
canvas.transform(Float64List.fromList(transform.transformMatrix.storage));
|
||||
@@ -177,7 +185,10 @@ class RuntimeComponent extends PositionComponent
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
final paint = Paint()
|
||||
..color = (_node.color ?? _defaultColor()).withValues(alpha: renderAlpha);
|
||||
..color = composeRuntimeColorAlpha(
|
||||
_node.color ?? _defaultColor(),
|
||||
renderAlpha,
|
||||
);
|
||||
|
||||
switch (_node.type) {
|
||||
case RuntimeNodeType.circle:
|
||||
@@ -224,7 +235,7 @@ class RuntimeComponent extends PositionComponent
|
||||
final rect = Rect.fromLTWH(0, 0, size.x, size.y);
|
||||
final radius = Radius.circular(_node.radius ?? 4);
|
||||
final backgroundPaint = Paint()
|
||||
..color = const Color(0x33475569).withValues(alpha: renderAlpha);
|
||||
..color = composeRuntimeColorAlpha(const Color(0x33475569), renderAlpha);
|
||||
canvas.drawRRect(RRect.fromRectAndRadius(rect, radius), backgroundPaint);
|
||||
|
||||
final value = _node.value ?? 0;
|
||||
@@ -327,11 +338,15 @@ class RuntimeComponent extends PositionComponent
|
||||
final contentRect = _listViewContentRect();
|
||||
final scrollbars = _listViewScrollbarVisibility();
|
||||
final trackPaint = Paint()
|
||||
..color = (_node.scrollbarTrackColor ?? const Color(0x33475569))
|
||||
.withValues(alpha: renderAlpha);
|
||||
..color = composeRuntimeColorAlpha(
|
||||
_node.scrollbarTrackColor ?? const Color(0x33475569),
|
||||
renderAlpha,
|
||||
);
|
||||
final thumbPaint = Paint()
|
||||
..color = (_node.scrollbarThumbColor ?? const Color(0xaa94a3b8))
|
||||
.withValues(alpha: renderAlpha);
|
||||
..color = composeRuntimeColorAlpha(
|
||||
_node.scrollbarThumbColor ?? const Color(0xaa94a3b8),
|
||||
renderAlpha,
|
||||
);
|
||||
|
||||
final contentHeight = _node.contentHeight;
|
||||
if (scrollbars.vertical &&
|
||||
@@ -415,7 +430,7 @@ class RuntimeComponent extends PositionComponent
|
||||
image,
|
||||
Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble()),
|
||||
rect,
|
||||
Paint()..color = Colors.white.withValues(alpha: renderAlpha),
|
||||
Paint()..color = composeRuntimeColorAlpha(Colors.white, renderAlpha),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -948,7 +963,7 @@ class RuntimeComponent extends PositionComponent
|
||||
final text = label ?? '';
|
||||
final color = _textColor(node);
|
||||
final style = TextStyle(
|
||||
color: color.withValues(alpha: renderAlpha),
|
||||
color: composeRuntimeColorAlpha(color, renderAlpha),
|
||||
fontSize: node.fontSize ?? 18,
|
||||
fontWeight: node.type == RuntimeNodeType.button
|
||||
? FontWeight.w600
|
||||
|
||||
Reference in New Issue
Block a user