/**
 * @file TestWindow.h
 * @brief 窗口系统测试用例实现。
 */
#pragma once
#include "Test.h"
#include "..\Platform\Platform.h"
#include "..\Platform\PlatformTypes.h"

using namespace XEngine;

platform::window _windows[4];

LRESULT win_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	switch (msg)
	{
	case WM_DESTROY:
	{
		bool all_closed{ true };
		for (u32 i{ 0 }; i < _countof(_windows); ++i)
		{
			if (!_windows[i].is_closed())
			{
				all_closed = false;
			}
		}
		if (all_closed)
		{
			PostQuitMessage(0);
			return 0;
		}
	}
	case WM_SYSCHAR:
		if (wparam == VK_RETURN && (HIWORD(lparam) & KF_ALTDOWN))
		{
			platform::window win{ platform::window_id{(id::id_type)GetWindowLongPtr(hwnd, GWLP_USERDATA)} };
			win.set_fullscreen(!win.is_fullscreen());
			return 0;
		 }
	default:
		break;
	}

	return DefWindowProc(hwnd, msg, wparam, lparam);
}

class engine_test :public Test
{
public:
	bool initialize() override
	{
		platform::window_init_info info[]
		{
			{&win_proc, nullptr, L"Test Window 1", 100,100,400,800},
			{&win_proc, nullptr, L"Test Window 2", 150,200,400,700},
			{&win_proc, nullptr, L"Test Window 3", 200,300,400,600},
			{&win_proc, nullptr, L"Test Window 4", 150,400,400,500},
		};
		static_assert(_countof(info) == _countof(_windows));
		for (u32 i{ 0 }; i < _countof(_windows); ++i)
			_windows[i] = platform::create_window(&info[i]);
		return true;
	}
	void run() override
	{
		std::this_thread::sleep_for(std::chrono::milliseconds(10));
	}
	bool shutdown() override
	{
		for (u32 i{ 0 }; i < _countof(_windows); ++i)
			platform::remove_window(_windows[i].get_id());
		return true;
	}



};
