/*Copyright (C) 2010 Deveaux Duncan

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 Pblic Licensue
along with Hikou no mizu.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "Button.hpp"

Button::Button()
{
    Button(100, 50, sf::Color());
}

Button::Button(float width, float height, const sf::Color &borderColor) :
m_width(width), m_height(height), m_backgroundEnabled(true), m_borderEnabled(true)
{
    m_background = sf::Shape::Rectangle(0, 0, width, height, borderColor);
}

bool Button::mouseHitTest(const sf::Vector2f &mousePosition)
{
    float buttonWidth = m_width * GetScale().x;
    float buttonHeight = m_height * GetScale().y;
    
    sf::FloatRect collisionTest(GetPosition().x, GetPosition().y, buttonWidth, buttonHeight);
    if (collisionTest.Contains(mousePosition))
        return true;
    
    return false;
}

void Button::Render(sf::RenderTarget& target, sf::Renderer& renderer) const
{
    target.Draw(m_background);
}

void Button::enableBackground(bool background)
{
    m_background.EnableFill(background);
    m_backgroundEnabled = background;
}

bool Button::backgroundEnabled() const
{
    return m_backgroundEnabled;
}

void Button::enableBorder(bool border)
{
    m_background.EnableOutline(border);
    m_borderEnabled = border;
}

bool Button::borderEnabled() const
{
    return m_borderEnabled;
}

//Get and set methods
void Button::setBackgroundColor(const sf::Color &backgroundColor)
{
    for (int i = 0; i < m_background.GetPointsCount(); i++)
    {
        m_background.SetPointColor(i, backgroundColor);
    }
}

const sf::Color &Button::getBackgroundColor() const
{
    return m_background.GetPointColor(0);
}

void Button::setBorderColor(const sf::Color &borderColor)
{
    for (int i = 0; i < m_background.GetPointsCount(); i++)
    {
        m_background.SetPointOutlineColor(i, borderColor);
    }
}

const sf::Color &Button::getBorderColor() const
{
    return m_background.GetPointOutlineColor(0);
}

void Button::setBorderSize(float borderSize)
{
    m_background.SetOutlineThickness(borderSize);
}

float Button::getBorderSize() const
{
    return m_background.GetOutlineThickness();
}

float Button::getWidth() const
{
    return m_width;
}

float Button::getHeight() const
{
    return m_height;
}