Skip to content

Commit 73f34ee

Browse files
committed
example: add BackgroundEffect
1 parent d24b95c commit 73f34ee

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

example/BackgroundEffect.uno

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Uno;
2+
using Uno.UX;
3+
using Uno.Graphics;
4+
using Uno.Diagnostics;
5+
using Uno.Math;
6+
using Uno.Vector;
7+
8+
using Fuse;
9+
using Fuse.Controls.Graphics;
10+
using Fuse.Drawing.Planar;
11+
12+
public class BackgroundEffect : Fuse.Controls.Graphics.Visual
13+
{
14+
static readonly float3 Color1 = Uno.Color.Parse("#1d3042").XYZ;
15+
static readonly float3 Color2 = Uno.Color.Parse("#5e8e8e").XYZ * .75f;
16+
17+
float2 _drawSize;
18+
19+
protected override void OnRooted()
20+
{
21+
base.OnRooted();
22+
UpdateManager.AddAction(InvalidateVisual);
23+
}
24+
25+
protected override void OnUnrooted()
26+
{
27+
UpdateManager.RemoveAction(InvalidateVisual);
28+
base.OnUnrooted();
29+
}
30+
31+
protected sealed override float2 OnArrangeMarginBox(float2 position, LayoutParams lp)
32+
{
33+
return _drawSize = base.OnArrangeMarginBox(position, lp);
34+
}
35+
36+
public sealed override void Draw(DrawContext dc)
37+
{
38+
var t = Clock.GetSeconds() * .3;
39+
var a1 = (float) Mod(t, PI * 2);
40+
var a2 = (float) Mod(t * .3, PI * 2);
41+
42+
draw Rectangle
43+
{
44+
DrawContext:
45+
dc;
46+
Visual:
47+
this;
48+
Size:
49+
_drawSize;
50+
float Gradient:
51+
Sin(pixel Rotate(VertexData, a2).Y * PIf - a1) * .5f + .5f;
52+
PixelColor:
53+
float4(Lerp(Color1, Color2, Gradient), 1);
54+
};
55+
}
56+
}

example/Main.ux

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<!-- Pressed buttons -->
44
<StackPanel Orientation="Horizontal" Alignment="TopCenter" Margin="10" ItemSpacing="5">
55
<Each Items="{pressed}">
6-
<Rectangle CornerRadius="6" Color="#8888" Padding="12, 0" Height="24">
6+
<Rectangle CornerRadius="6" Color="#444" Padding="12, 0" Height="24">
77
<Text Value="{data()}" FontSize="14" Color="#EEEE" Alignment="Center"/>
88
</Rectangle>
99
</Each>
@@ -15,4 +15,9 @@
1515
<Thumbstick Grid.Column="1" Index="Right" />
1616
</Grid>
1717

18+
<!-- Background effect -->
19+
<Rectangle>
20+
<BackgroundEffect />
21+
</Rectangle>
22+
1823
</App>

0 commit comments

Comments
 (0)