Hello,
Here's a quite old but really useful button struct snippet I made for my project last summer. It uses kBessa's LightText plugin because of its great usability. You are going to need to change couple of things to make it compile in your project, but it should be fairly simple by looking at the errors.
¨ struct SimpleButton
{
private DarkGDK.Basic2D.Image button;
private DarkGDK.Basic2D.Sprite sprButton;
private string value;
private int posx, posy, stretchX,stretchY;
private LightPlugins.Text.AdvancedText btnTextWriter;
public delegate void MouseDownEvent();
MouseDownEvent OnClick;
public SimpleButton(int btnPosX, int btnPosY, string buttonLabel, MouseDownEvent onClickEvent)
{
button = new DarkGDK.Basic2D.Image("PATH/TO/BUTTONIMAGE.png");
btnTextWriter = new LightPlugins.Text.AdvancedText("Arial", 9.0f, System.Drawing.Color.LightGray);
sprButton = new DarkGDK.Basic2D.Sprite(0, 0, button);
sprButton.Visible = false;
value = buttonLabel;
posx = btnPosX;
posy = btnPosY;
stretchX = 0;
stretchY = 0;
OnClick = new MouseDownEvent(onClickEvent);
}
public void Stretch(int PStretchX, int PStretchY)
{
this.stretchX = PStretchX;
this.stretchY = PStretchY;
}
public void Dispose()
{
this.button.Delete();
this.sprButton.Delete();
// this.btnTextWriter.Dispose();
}
public void Render()
{
try
{
sprButton.Stretch(0 + DarkGDK.Text.Width(value) + 10 + stretchX, 80 + stretchY);
sprButton.Paste(posx, posy);
Eyeone.Graphics.Text.WriterShadow12px.Write(posx, posy + sprButton.Height / 2 - DarkGDK.Text.Height(value) / 2 + 1, sprButton.Width, sprButton.Height, value, LightPlugins.Text.TextFormat.Center); //Optional neat shadow thingy!
btnTextWriter.Write(posx, posy + sprButton.Height / 2 - DarkGDK.Text.Height(value) / 2, sprButton.Width, sprButton.Height, value, LightPlugins.Text.TextFormat.Center);
if (DarkGDK.IO.Mouse.X > posx && DarkGDK.IO.Mouse.Y > posy && DarkGDK.IO.Mouse.Y < posy + this.sprButton.Height && DarkGDK.IO.Mouse.X < posx + this.sprButton.Width)
{
btnTextWriter.Color = System.Drawing.Color.LightBlue;
if (SingleLeftClick())
{
OnClick();
}
}
else
btnTextWriter.Color = Graphics.Text.c;
}
catch (NullReferenceException NotFound)
{
// Do Nothing
}
}
};
Using this snippet you can easily make for example a menu button like this:
SimpleButton btnMyMenuButton = new SimpleButton(posX, posY, "This is a menu button", onClickDoSomethingFunctionHere);
And then just place it inside your loop and use
btnMyMenuButton.Render();