/*Copyright (C) 2010-2012 Duncan Deveaux

This file is part of Hikou no mizu.

Hikou no mizu is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Hikou no mizu is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Hikou no mizu.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "ImageButton.hpp"

ImageButton::ImageButton() : Button(100, 50, Color())
{
    
}

ImageButton::ImageButton(const Sprite &image, float width, float height, const Color &color) :
Button(width, height, color), m_image(image)
{
    centerImage();
}

void ImageButton::draw()
{
    //Update matrix
    Drawable::pushMatrix();
    Drawable::updateMatrix();
    
    //Draw elements
    m_background.draw();
    m_image.draw();
    
    Drawable::popMatrix();
}

void ImageButton::centerImage()
{
    m_image.setXPosition((m_width - m_image.getWidth()) / 2);
    m_image.setYPosition((m_height - m_image.getHeight()) / 2);
}

void ImageButton::setImage(const Sprite &image)
{
    m_image = image;
    centerImage();
}

const Sprite &ImageButton::getImage() const
{
    return m_image;
}
