Credits Stevepwns
I started with micros button struct and made this,
It can be a little laggy when you draw to many (more than 10 or 15) but it works pretty good and is easy to use.
I figured I'd share it and hope some can learn from it, its seems to be a good start.
use what ever text and rect render method your familiar with. I left mime for example code.
Credits to Micro and Me if you use this please
Enjoy:
//In Declerations::
//create your button
Code:
struct Buttons
{
int num;
char *caption;
int x;
int y;
int w;
int h;
bool clicked;
bool mOver;
}; Buttons Button[20];
//In Initialize::
//call as such
Code:
initbtn( 1, "option", 25, 100, 125, 20);
//Function your calling
Code:
void initbtn(int bnum, char *bcaption, int bx, int by, int bw, int bh )
{
Button[bnum].num = bnum;
Button[bnum].caption = bcaption;
Button[bnum].x = bx;
Button[bnum].y = by;
Button[bnum].w = bw;
Button[bnum].h = bh;
Button[bnum].clicked = false;
}
//In End Scene::
//Call as such
Code:
RenderButton( m_pD3Ddev, 1); //or create array to draw multiple buttons
//Function your calling
Code:
void RenderButton( IDirect3DDevice9 *pD3Ddev, int butnum )
{
int mw = Button[butnum].x + Button[butnum].w;
int mh = Button[butnum].y + Button[butnum].h;
//Defualt apperance
drawguibox( Button[butnum].x, Button[butnum].y, Button[butnum].w, Button[butnum].h, 0, 0, 0, 255, 0, 0, 255, 100 );
DrawText( Button[butnum].x + 15, Button[butnum].y + 3, Button[butnum].caption, 0, 0, 0);
POINT cur;
GetCursorPos( &cur );
//if the mouse coords are
//the same as the buttons coords
if ( cur.x >= Button[butnum].x && cur.x <= mw && cur.y >= Button[butnum].y && cur.y <= mh )
{
//draw with higher opacity
drawguibox( Button[butnum].x, Button[butnum].y, Button[butnum].w, Button[butnum].h, 255, 255, 255, 125, 0, 0, 255, 125 );
DrawText( Button[butnum].x + 15, Button[butnum].y + 3, Button[butnum].caption, 255, 0, 0);
//if mouse button is clicked
if ( GetAsyncKeyState( VK_LBUTTON ) &1 )
{
//then the button has been clicked
Button[butnum].clicked = !Button[butnum].clicked;
}
}
if ( Button[butnum].clicked )
{
//the buttton has been clicked and the text
//color changes to show its been clicked
DrawText( Button[butnum].x + 15, Button[butnum].y + 3, Button[butnum].caption, 0, 255, 0);
}
}