#include "Label.h"


Label::Label(Window* parent, bool mouseHighlight)
: Window(parent), _mouseHighlight(mouseHighlight), _highlighted(false)
{
    setPosition(Point(0.0f, 0.0f));
    setSize(Size(64.0f, 16.0f));

    _normalTexture = 0;
    _highlightedTexture = ResourceManager::instance().loadTexture(L"textures/gui/label_highlighted.dds");

    _texture = _normalTexture;

    _caption->setFont(L"Microsoft Sans Serif", L"000000", 13.0f, Text::FONT_STYLE_REGULAR, Text::H_ALIGN_LEFT | Text::V_ALIGN_CENTER);

    connectEvent(Event::MOUSE_ENTER, this, (EventHandler)&Label::onMouseEnter);
    connectEvent(Event::MOUSE_LEAVE, this, (EventHandler)&Label::onMouseLeave);
}

Label::~Label()
{
}

bool Label::isHighlighted()
{
    return _highlighted;
}

void Label::highlight(bool highlighted)
{
    lock();

    _highlighted = highlighted;

    if (_highlighted) {
        _texture = _highlightedTexture;
    }
    else {
        _texture = _normalTexture;
    }

    unlock();
}

bool Label::isMouseHighlightEnabled()
{
    return _mouseHighlight;
}

void Label::enableMouseHighlight(bool mouseHighlight)
{
    _mouseHighlight = mouseHighlight;
}

void Label::onMouseEnter(Event& event)
{
    if (_mouseHighlight) {
        highlight(true);
    }
}
void Label::onMouseLeave(Event& event)
{
    if (_mouseHighlight) {
        highlight(false);
    }
}