#include <unistd.h>
#include "graphics.h"
#include "allegro.h"


/*****************************************************************************
* Create a screen of type "type".  Return 0 if the screen was created,
* 1 if the screen could not be created.
*/
int create_screen(int type)
{
	const static int widths[] = { 320, 640, 800, 1024 };
	const static int heights[] = { 240, 480, 600, 768 };

	int bpp = type & 0xff;
	int width = widths[type >> 8];
	int height = heights[type >> 8];
	int err = 0;

	err = allegro_init();
	if(!err)
	{
		set_color_depth(bpp);
		err = set_gfx_mode(GFX_SAFE, width, height, 0, 0);

		if(err) allegro_exit();
	}

	if(!err) return 0;
	else return 1;
}


/*****************************************************************************
* Destroy the previously created screen.
*/
int destroy_screen()
{
	allegro_exit();

	return 0;
}


/*****************************************************************************
* Draw a filled box in specified region and color.
*/
int draw_box(int x, int y, int w, int h, int color)
{
	int r = (color >> 16) & 0xff;
	int g = (color >> 8) & 0xff;
	int b = (color >> 0) & 0xff;

	rectfill(screen, x, y, x+w-1, y+h-1, makecol(r, g, b));

	return 0;
}


/*****************************************************************************
* Freezes the graphics library for s seconds.
*/
int g_sleep(int s)
{
	sleep(s);

	return 0;
}


/* vim:ts=3
*/
