#pragma once
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dx9tex.h>
#include <iostream>

using namespace std;

#pragma once
class UIcomponent
{
public:
	bool hasAction;
	IDirect3DSurface9 *surface;
	IDirect3DDevice9 *device;
	RECT rect;

	UIcomponent* next;
	void (*function)();

	void assignFunction(void function());

	void render(void);

	UIcomponent(void);

	UIcomponent(string path, int x, int y, int w, int h, IDirect3DDevice9 *device);

	~UIcomponent(void);
};

extern bool isRunning;
static void exit()
{
	isRunning = false;
}

static bool isInRect(UIcomponent *e, int x, int y)
{
	if(x < e->rect.right && x > e->rect.left && y < e->rect.bottom && y > e->rect.top)
	{
		return true;
	}
	return false;
}

static void UIrespond(UIcomponent *e, int x, int y)
{
	if(isInRect(e, x, y) && e->hasAction)
	{
		if(e->hasAction)
			e->function();
	}
	else
	{
		if(e->next != NULL)
		{
			return UIrespond(e->next, x, y);
		}
		else
		{
			return;
		}

	}
}

