/*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 "TextButton.hpp"

TextButton::TextButton() : Button()
{
    
}

TextButton::TextButton(const Sprite &background, const Box &contentBox) :
Button(background, contentBox)
{
    
}

TextButton::TextButton(const std::string &text, const Sprite &background, const Box &contentBox) :
Button(background, contentBox)
{
    setText(text);
}

void TextButton::draw()
{
    //Update matrix
    Drawable::pushMatrix();
    Drawable::updateMatrix();
    
    m_background.draw();
    m_textField.draw();
    
    Drawable::popMatrix();
}

void TextButton::centerText()
{
    m_textField.setXPosition(m_contentBox.left + (m_contentBox.width - m_textField.getWidth()) / 2);
    m_textField.setYPosition(m_contentBox.top + (m_contentBox.height - m_textField.getHeight()) / 2);
}

void TextButton::setText(const std::string &text)
{
    m_textField.setText(text);
    centerText();
}

const std::string &TextButton::getText() const
{
    return m_textField.getText();
}

void TextButton::setTextFont(Font &textFont)
{
    m_textField.setFont(textFont);
    centerText();
}

const Font &TextButton::getTextFont() const
{
    return m_textField.getFont();
}

void TextButton::setTextColor(const Color &textColor)
{
    m_textField.setColor(textColor);
}

const Color &TextButton::getTextColor() const
{
    return m_textField.getColor();
}

//Inherited methods
void TextButton::setContentBox(const Box &contentBox)
{
    Button::setContentBox(contentBox);
    centerText();
}
