#include "Window.h"

#include "IPlatformWindow.h"
#include "PaintEvent.h"
#include "MouseEvent.h"
#include "VisualLayer.h"
#include "KeyboardEvent.h"

namespace mt
{

Window::Window()
    :mWidth(400),
     mHeight(300),
     mWidget()
{

}

Window::~Window()
{

}

std::unique_ptr<Window> Window::Create()
{
    return std::make_unique<Window>();
}

std::vector<VisualLayer*> Window::GetLayers()
{
    return mWidget->GetLayers();
}

void Window::OnMouseEvent(const MouseEvent* event)
{
    mWidget->OnMouseEvent(event);
}

void Window::OnKeyboardEvent(const KeyboardEvent* event)
{
    mWidget->OnKeyboardEvent(event);
}

void Window::OnPaint(const PaintEvent* event)
{
    mWidget->SetBounds(mWidth, mHeight);
    mWidget->OnPaintEvent(event);
}

void Window::AddWidget(WidgetUPtr widget)
{
    mWidget = std::move(widget);
}

Widget* Window::GetWidget() const
{
    return mWidget.get();
}

unsigned Window::GetWidth() const
{
    return mWidth;
}

unsigned Window::GetHeight() const
{
    return mHeight;
}

void Window::SetSize(unsigned width, unsigned height)
{
    mWidth = width;
    mHeight = height;
}

IPlatformWindow* Window::GetPlatformWindow() const
{
    if (mPlatformWindow)
    {
        return mPlatformWindow.get();
    }
    return nullptr;
}

void Window::SetPlatformWindow(IPlatformWindowPtr window)
{
    mPlatformWindow = std::move(window);
}

}
