1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-24 02:28:01 +02:00
Beef/IDE/src/ui/LocatorAnim.bf

98 lines
2.1 KiB
Beef
Raw Normal View History

2019-08-23 11:56:54 -07:00
using System;
using System.Collections;
2019-08-23 11:56:54 -07:00
using System.Text;
using System.Threading.Tasks;
using Beefy;
using Beefy.gfx;
using Beefy.widgets;
using Beefy.theme.dark;
namespace IDE.ui
{
public enum LocatorType
{
None,
Smart,
2019-12-13 14:25:15 -08:00
Always,
Extra
2019-08-23 11:56:54 -07:00
}
public class LocatorAnim : Widget
{
2019-12-13 14:25:15 -08:00
LocatorType mType;
2019-08-23 11:56:54 -07:00
float mPct;
2019-12-13 14:25:15 -08:00
public this()
{
}
2019-08-23 11:56:54 -07:00
public override void Draw(Graphics g)
{
base.Draw(g);
2019-12-13 14:25:15 -08:00
bool isExtra = mType == .Extra;
2019-08-23 11:56:54 -07:00
int32 circleCount = 2;
for (int32 i = 0; i < circleCount; i++)
{
float sepPct = 0.3f;
float maxSep = (circleCount - 2) * sepPct;
float pct = (mPct - maxSep + (i * 0.3f)) / (1.0f - maxSep);
2019-12-13 14:25:15 -08:00
if (isExtra)
pct *= 1.2f;
2019-08-23 11:56:54 -07:00
if ((pct < 0.0f) || (pct > 1.0f))
continue;
float scale = (float)Math.Sin(pct * Math.PI_f / 2) * 0.5f;
float alpha = Math.Min(0.3f, (1.0f - (float)Math.Sin(pct * Math.PI_f / 2)) * 1.0f);
2019-12-13 14:25:15 -08:00
if (isExtra)
{
scale *= 1.2f;
alpha *= 1.2f;
}
2019-08-23 11:56:54 -07:00
using (g.PushColor(Color.Get(alpha)))
{
using (g.PushScale(scale, scale, GS!(32), GS!(32)))
g.Draw(IDEApp.sApp.mCircleImage);
}
}
}
public override void Update()
{
base.Update();
2019-12-13 14:25:15 -08:00
mPct += (mType == .Extra) ? 0.02f : 0.03f;
2019-08-23 11:56:54 -07:00
if (mPct >= 1.0f)
{
RemoveSelf();
//DeferDelete();
gApp.DeferDelete(this);
}
MarkDirty();
}
2019-12-13 14:25:15 -08:00
public static void Show(LocatorType locatorType, Widget refWidget, float x, float y)
2019-08-23 11:56:54 -07:00
{
if (!gApp.mSettings.mEditorSettings.mShowLocatorAnim)
return;
float xOfs = GS!(-32.0f);
float yOfs = GS!(-32.0f);
LocatorAnim anim = new LocatorAnim();
2019-12-13 14:25:15 -08:00
anim.mType = locatorType;
2019-08-23 11:56:54 -07:00
anim.mX = x + xOfs;
anim.mY = y + yOfs;
refWidget.AddWidget(anim);
}
}
}