#include "Bouton.h"

Bouton::Bouton(SDL_Surface *objetImg, SDL_Surface *screen, int const x, int const y)
:m_x(x),m_y(y),m_selectImg(0)
{
    m_objetImg = objetImg;
    m_screen = screen;

    m_blitImg = m_objetImg;
}///Constructeur

Bouton::~Bouton()
{
    SDL_FreeSurface(m_objetImg);
    if (m_selectImg != 0)
        SDL_FreeSurface(m_selectImg);
}

void Bouton::attribuerImg(SDL_Surface *selectImg)
{
    m_selectImg = selectImg;
}///attribuerImg

bool Bouton::calculer(int const xSouris, int const ySouris)
{
    if (m_selectImg != 0)
    {/**if**/
        if (m_x < xSouris && xSouris < m_x+m_objetImg->w)
        {///if
            if (m_y < ySouris && ySouris < m_y+m_objetImg->h)
            {//if
                m_blitImg = m_selectImg;
                return true;//Souris dessus !
            }//if
            else
            {//else
                m_blitImg = m_objetImg;
                return false;//Rien
            }//else
        }///if
        else
        {//else
            m_blitImg = m_objetImg;
            return false;//Rien
        }//else
    }/**if**/

    return false;//Il y a pas de seconde image patate !
}///calculer

void Bouton::afficher()
{
    // [1] Attribution des positions
    SDL_Rect position;
    position.x=m_x;
    position.y=m_y;

    // [2] Collage
    SDL_BlitSurface(m_blitImg, 0, m_screen, &position);
}///afficher

bool Bouton::estClique(int const xSouris, int const ySouris)
{
    if (m_x < xSouris && xSouris < m_x+m_objetImg->w)
        if (m_y < ySouris && ySouris < m_y+m_objetImg->h)
            return true;
    return false;
}///estClique