#include "button.h"

Gombik::Gombik(char str1[],char str2[],void(*smernik)(),BITMAP *act,BITMAP *unact,BITMAP *buff,SAMPLE *sound,SAMPLE *click_sound,ALFONT_FONT * font_ac,ALFONT_FONT * font_un,int farba1,int farba2,int x, int y, int sirka, int vyska,int fx,int fy)
{
  pf = smernik;
  active=act;
  unactive=unact;
  buffer=buff;
  zvuk=sound;
  click_zvuk=click_sound;
  left=x;
  top=y;
  right=x+sirka;
  bottom=y+vyska;
  width=sirka;
  height=vyska;
  zahral=FALSE;
  font1=font_ac;
  font2=font_un;
  col1=farba1;
  col2=farba2;
  text1=str1;
  text2=str2;
  fontx=fx;
  fonty=fy;
}

void Gombik::Krok()
{
  Nakresli();
  if(Zmacknute())
  {
     if(click_zvuk!=NULL) play_sample(click_zvuk,255,128,1000,FALSE);
     rest(100);
     pf();
  }
}

void Gombik::Nakresli()
{
  if(JeNadoMnouMys())
  {
    if(zahral==FALSE) 
    {
      zahral=TRUE; 
      if(zvuk!=NULL) play_sample(zvuk,255,128,1000,FALSE);
    }
    if(active!=NULL) draw_sprite(buffer,active,left,top);
    show_mouse(NULL);
    alfont_text_mode(-1);
    alfont_textout_aa(buffer,font1,text1,fontx,fonty,col1);
  }
  else
  {
    zahral=FALSE;
    if(unactive!=NULL) draw_sprite(buffer,unactive,left,top);
    show_mouse(NULL);
    alfont_text_mode(-1);
    alfont_textout_aa(buffer,font2,text2,fontx,fonty,col2);
  }  
}

bool Gombik::JeNadoMnouMys()
{
  if(((mouse_x>=left)&& (mouse_x<=right)) && ((mouse_y>=top)&&(mouse_y<=bottom)) )
  {
    return TRUE;
  }
  else
    return FALSE;
}

bool Gombik::Zmacknute()
{
  if(mouse_b&1)
  {
    if(((mouse_x>=left)&& (mouse_x<=right)) && ((mouse_y>=top)&&(mouse_y<=bottom)) )
    {
      return TRUE;
    }
    else
      return FALSE;
  }
  else 
    return FALSE;
}
