/*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(100, 50, Color())
{
    
}

TextButton::TextButton(const std::string &text, Font &textFont, float width, float height, const Color &color) :
Button(width, height, color), m_textField( Text(text, textFont) )
{
    centerText();
}

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

void TextButton::centerText()
{
    m_textField.setXPosition((getWidth() - m_textField.getWidth()) / 2);
    m_textField.setYPosition((getHeight() - m_textField.getHeight()) / 2);
}

//Get and set methods
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);
}

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();
}
