alot of people, perhaps they don't know how to do mouseable buttons so easily, yes?
but perhaps they would like to use them like crazy, no?
Here is a "pot shot" at a little lib for doing buttons just like crazy.
What you do is, to create a button on the screen that will call myfunction() when clicked, you code such as
Butts_New( x, y, "button01.bmp", "myfunction" );
and then in your main loop of the moment you call Butts() before your Showpage()...
alright?
#define BUTTS_MAXBUTTONS 256
struct Butts_Button
{
int x;
int y;
int x2;
int y2;
int depressed;
int img;
string func;
}
Butts_Button Butts_Buttons[BUTTS_MAXBUTTONS];
int Butts_Count;
int Butts_mbpressed;
void Butts_New( int x, int y, string img, string func )
{
int c;
if( Butts_Count < BUTTS_MAXBUTTONS )
{
c = Butts_Count;
Butts_Buttons[c].img = LoadImage(img);
Butts_Buttons[c].func = func;
Butts_Buttons[c].x = x;
Butts_Buttons[c].y = y;
Butts_Buttons[c].x2 = x + ImageWidth(Butts_Buttons[c].img);
Butts_Buttons[c].y2 = y + ImageHeight(Butts_Buttons[c].img);
Butts_Buttons[c].depressed = 0;
Butts_Count++;
return;
}
}
void Butts_Clear()
{
int a;
for( a = 0; a < Butts_Count; a++ )
FreeImage(Butts_Buttons[a].img);
Butts_Count = 0;
}
void Butts()
{
int a, b, pressing;
if( mouse.l )
{
Butts_mbpressed = 1;
for( a = 0; a < Butts_Count; a++ )
{
pressing = 0;
if(mouse.y > Butts_Buttons[a].y)
{
if(mouse.y < Butts_Buttons[a].y2)
{
if(mouse.x > Butts_Buttons[a].x)
{
if(mouse.x < Butts_Buttons[a].x2)
pressing = 1;
}
}
}
if(pressing) Butts_Buttons[a].depressed = 1;
else Butts_Buttons[a].depressed = 0;
}
}
else
{
if( Butts_mbpressed )
{
Butts_mbpressed = 0;
for( a = 0; a < Butts_Count; a++ )
{
if(Butts_Buttons[a].depressed)
{
CallFunction(Butts_Buttons[a].func);
Butts_Buttons[a].depressed = 0;
a = Butts_Count-1;
}
}
}
}
// draw now i reckon
for( a = 0; a < Butts_Count; a++ )
{
b = Butts_Buttons[a].depressed;
TBlit(Butts_Buttons[a].x+b,Butts_Buttons[a].y+b,Butts_Buttons[a].img,screen);
}
}
//---------------- MY SYSTEM.VC CODE OK ----------------
void drawmymousepointer()
{
Rect(mouse.x-4,mouse.y-4,mouse.x+4,mouse.y+4,0-1,screen);
}
void coolfunc()
{
Butts_Clear();
Exit("hihi! yea it worx");
}
void autoexec()
{
Butts_New(20,20,"omfg.png","coolfunc");
Butts_New(400,20,"omfg.png","exit"); // ok so this doesn't work...
while(!key[SCAN_ESC])
{
RectFill(0,0,800,600,0,screen);
Butts();
drawmymousepointer();
ShowPage();
}
}
Okay?
i would like feedback. what's wrong with it? what should be done better and what should be added to it? be cruel!
k
k
t
h
x