1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-21 09:27:59 +02:00
Beef/IDE/src/ui/WelcomePanel.bf

134 lines
3.4 KiB
Beef
Raw Normal View History

2019-09-23 09:41:21 -07:00
using Beefy.gfx;
using Beefy.theme.dark;
using System;
using Beefy.widgets;
namespace IDE.ui
{
class WelcomePanel : Panel
{
class SampleButton : Widget
{
public Image mImage;
public String mLabel ~ delete _;
public Font mFont;
public String mPath ~ delete _;
public override void Draw(Graphics g)
{
using (g.PushColor(mMouseOver ? 0xFFFFFFFF : 0x80FFFFFF))
using (g.PushScale(DarkTheme.sScale, DarkTheme.sScale))
g.Draw(mImage);
g.SetFont(mFont);
g.DrawString(mLabel, 0, GS!(240), .Centered, mWidth);
}
public override void MouseEnter()
{
base.MouseEnter();
gApp.SetCursor(.Hand);
}
public override void MouseLeave()
{
base.MouseLeave();
gApp.SetCursor(.Pointer);
}
2020-03-21 07:09:21 -07:00
public override void MouseClicked(float x, float y, float origX, float origY, int32 btn)
2019-09-23 09:41:21 -07:00
{
2020-03-21 07:09:21 -07:00
base.MouseClicked(x, y, origX, origY, btn);
2019-09-23 09:41:21 -07:00
gApp.[Friend]mDeferredOpen = .Workspace;
String.NewOrSet!(gApp.[Friend]mDeferredOpenFileName, mPath);
}
}
Font mLargeFont ~ delete _;
Font mMedFont ~ delete _;
Image mSampleImg0 ~ delete _;
Image mSampleImg1 ~ delete _;
SampleButton mSampleBtn0;
SampleButton mSampleBtn1;
public override bool WantsSerialization
{
get
{
return false;
}
}
2019-09-23 11:50:11 -07:00
public float YOfs
{
get
{
return Math.Max(0, (mHeight - GS!(520)) * 0.35f);
}
}
2019-09-23 09:41:21 -07:00
public this()
{
mSampleImg0 = Image.LoadFromFile(scope String()..AppendF(@"{}\images\welcome_sample0.png", gApp.mInstallDir));
mSampleImg1 = Image.LoadFromFile(scope String()..AppendF(@"{}\images\welcome_sample1.png", gApp.mInstallDir));
mSampleBtn0 = new .();
2019-09-23 11:50:11 -07:00
mSampleBtn0.mPath = new String()..AppendF(@"{}\..\Samples\SpaceGame\BeefSpace.toml", gApp.mInstallDir);
2019-09-23 09:41:21 -07:00
mSampleBtn0.mLabel = new String("Space Game");
mSampleBtn0.mImage = mSampleImg0;
AddWidget(mSampleBtn0);
mSampleBtn1 = new .();
2019-09-23 11:50:11 -07:00
mSampleBtn1.mPath = new String()..AppendF(@"{}\..\Samples\HelloWorld\BeefSpace.toml", gApp.mInstallDir);
2019-09-23 09:41:21 -07:00
mSampleBtn1.mLabel = new String("Hello World");
mSampleBtn1.mImage = mSampleImg1;
AddWidget(mSampleBtn1);
2019-09-23 11:50:11 -07:00
mClipGfx = true;
2019-09-23 09:41:21 -07:00
}
public override void RehupScale(float oldScale, float newScale)
{
base.RehupScale(oldScale, newScale);
DeleteAndNullify!(mLargeFont);
DeleteAndNullify!(mMedFont);
}
public override void DrawAll(Graphics g)
{
if (mLargeFont == null)
mLargeFont = new Font()..Load("Segoe UI Bold", 60.0f * DarkTheme.sScale); //8.8
if (mMedFont == null)
mMedFont = new Font()..Load("Segoe UI Bold", 24.0f * DarkTheme.sScale); //8.8
mSampleBtn0.mFont = mMedFont;
mSampleBtn1.mFont = mMedFont;
base.DrawAll(g);
}
public override void Draw(Graphics g)
{
2019-09-23 11:50:11 -07:00
using (g.PushColor(0x40000000))
g.FillRect(mWidth/2 - GS!(500), YOfs - GS!(24), GS!(500)*2, GS!(570));
2019-09-23 11:50:11 -07:00
2019-09-23 09:41:21 -07:00
g.SetFont(mLargeFont);
using (g.PushColor(0xFFE0E0FF))
2019-09-23 11:50:11 -07:00
g.DrawString("Welcome to Beef", 0, GS!(0) + YOfs, .Centered, mWidth);
2019-09-23 09:41:21 -07:00
g.SetFont(mMedFont);
2019-09-23 11:50:11 -07:00
g.DrawString(scope String()..AppendF("Click on a sample projects below\n{}or{}\nCreate a project from the File menu", Font.EncodeColor(0xFFA0A0A0), Font.EncodePopColor()),
GS!(32), GS!(95) + YOfs, .Centered, mWidth - GS!(64));
2019-09-23 09:41:21 -07:00
}
public override void Update()
{
base.Update();
2019-09-23 11:50:11 -07:00
mSampleBtn0.Resize(mWidth / 2 - GS!(32 + 320), GS!(224) + YOfs, GS!(320), GS!(240));
mSampleBtn1.Resize(mWidth / 2 + GS!(32), GS!(224) + YOfs, GS!(320), GS!(240));
2019-09-23 09:41:21 -07:00
}
}
}