#pragma once
#include "StdAfx.h"
#include "UIcomponent.h"

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

using namespace std;

extern IDirect3DSurface9* LoadSurfaceFromFile(std::string FileName);

UIcomponent::UIcomponent(void)
{
}


UIcomponent::~UIcomponent(void)
{
}

void UIcomponent::render(void)
{
	{
		static IDirect3DSurface9* backBuffer;
		device->GetBackBuffer(0,NULL, D3DBACKBUFFER_TYPE_MONO, &backBuffer);
		if(NULL == device)
		{
			return;
		}

		device->StretchRect(surface, NULL, backBuffer, &rect, D3DTEXF_NONE);

	}
}

UIcomponent::UIcomponent(string path, int x, int y, int w, int h, IDirect3DDevice9 *device)
{
	hasAction = false;
	this->device = device;
	RECT rect;
	rect.top = y;
	rect.left = x;
	rect.right = x+w;
	rect.bottom = y+h;
	this->rect = rect;
	this->surface = LoadSurfaceFromFile(path);
	next = NULL;
}

void UIcomponent::assignFunction(void function())
{
	this->hasAction = true;
	this->function = function;
}