Skip to content

Instantly share code, notes, and snippets.

@gmich
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmich/aee2e5cd3e7866df1446 to your computer and use it in GitHub Desktop.
Save gmich/aee2e5cd3e7866df1446 to your computer and use it in GitHub Desktop.
Gem Gui Example
private GemGui gui;
protected override void LoadContent()
{
//initialize a new gui
gui = new GemGui(this,800,480);
//don't scale
gui.Settings.ScaleCalculator = resolution => Vector2.One;
//add a font to the container
gui.Fonts.Add("segoe-10",
container => container.Load<SpriteFont>(@"Fonts/segoe-10"));
//add a texture the the container
gui.Textures.Add("buttonTexture",
container => container.Load<Texture2D>(@"Common/buttonTexture"));
//initialize a button
var firstButton =
gui.Button(x: 20, y: 20,
sizeX: 100, sizeY: 100,
style: Style.Transparent
pattern: Pattern.SolidColor)
.Sprite("Common",gui.Textures["buttonTexture"])
.Color(Color.White)
.Text("Go to the first screen", 0, 0, gui.Fonts["segoe-10"])
.TextColor(Color.Red)
.TextHorizontalAlignment(HorizontalAlignment.Center)
.TextVerticalAlignment(VerticalAlignment.Bottom)
.ScreenAlignment(HorizontalAlignment.Center,
VerticalAlignment.Center);
.OnClick((sender, args) => gui.Swap("FirstScreen", "SecondScreen"));
//add the button to a gui host
gui.AddGuiHost("FirstScreen", firstButton);
//initialize another button
var secondButton =
gui.Button(x: 50, y: 50,
sizeX: 200, sizeY: 200,
style: Style.Transparent)
.Color(Color.White)
.Text("Go to the second screen", 0, 0, gui.Fonts["segoe-10"])
.TextColor(Color.Black)
.TextHorizontalAlignment(HorizontalAlignment.Left)
.TextVerticalAlignment(VerticalAlignment.Center)
//add an OnClick event that swaps two GuiHosts
.OnClick((sender, args) => gui.Swap("SecondScreen", "FirstScreen"));
//add an OnFocus event that transforms the control's color by lerping it to Red
secondButton.Events.GotFocus +=
(sender, args) =>
control.AddTransformation(
new PredicateTransformation(
expirationPredicate: control =>
control.RenderParameters.Color == Color.Red,
transformer: (deltaTime,control) =>
control.RenderParameters.Color = Color.Lerp(Color.Red,
control.RenderParameters.Color,
deltaTime)));
//add the second control to a different host
gui.AddGuiHost("SecondScreen", secondButton);
//change the second host's transition to fade-in / fade-out in 0.5 seconds
gui["SecondScreen"].Transition = new TimedTransition(TimeSpan.FromSeconds(0.5),
(state, progress, target, batch) =>
batch.Draw(target, Vector2.Zero, Color.White * progress));
//draw "i'm a background" in the gui's background
gui.DrawWith += (sender, batch) =>
batch.DrawString(gui.Fonts["segoe-10"], "i'm a background", new Vector2(20, 20), Color.White);
//begin by drawing only the first host
gui.Show("FirstScreen");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment