Ок, разобрался:
class button{
public:
button(int nx, int ny, int nw, int nh, void (*nc)());
~button();
int getX(){ return x; };
int getY(){ return y; };
int getW(){ return w; };
int getH(){ return h; };
void setX(int nx){ x = nx; };
void setY(int ny){ y = ny; };
void setW(int nw){ w = nw; };
void setH(int nh){ h = nh; };
void check(SDL_Event *event);
wigetState getState(){ return state; };
private:
int x;
int y;
int h;
int w;
wigetState state;
void (*callBack)();
};
button::button(int nx, int ny, int nw, int nh, void (*nc)())
{
x = nx;
y = ny;
w = nw;
h = nh;
state = MOUSEOUT;
callBack = nc;
}
button::~button()
{
}
void button::check(SDL_Event* event)
{
int mx, my;
SDL_GetMouseState(&mx, &my);
switch(event->type){
case SDL_MOUSEBUTTONDOWN:
if(mx >= x && mx <= x + w && my >= y && my <= y + h){
state = PRESSED;
}
break;
case SDL_MOUSEMOTION:
if(mx >= x && mx <= x + w && my >= y && my <= y + h){
state = MOUSEENTER;
}
else
state = MOUSEOUT;
break;
case SDL_MOUSEBUTTONUP: if(mx >= x && mx <= x + w && my >= y && my <= y + h){ state = MOUSEENTER; callBack(); }break;
}
}
Использование:
button Button(0, 0, 100, 30, onCallBack());
...
в цикле
...
Button.check(&event);
if(PauseMenuButtons[0].getState() == MOUSEOUT) onMouseOut(); else onHover();