/*
 * ButtonBox - a program launcher
 *
 * Copyright (C) 2000 Paul Collins
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 *
 */

#include <stdio.h>

#include "assertions.h"
#include "colour.h"

#include <X11/Xlib.h>




static Display* colour_display = NULL;
static Colormap colour_colourmap = None;



void
colour_init (Display* d)
{
	I (d != NULL);
	colour_display = d;
	
	if ((colour_colourmap =
	     DefaultColormap (colour_display, DefaultScreen (colour_display))) == None) {
		L("Unable to get the default colormap.\n");
	}
}




Bool
colour_allocate (char* name, unsigned long* pixel_return)
{
	XColor xc_screen;
	XColor xc_exact;

	I (name != NULL);
	I (pixel_return != NULL);
	if (XAllocNamedColor (colour_display, colour_colourmap, name, &xc_screen, &xc_exact)) {
		*pixel_return = xc_screen.pixel;
		return True;
	} else {
		L ("colour_allocate: unable to allocate colour \"%s\"", name);
		return False;
	}
}




unsigned long
colour_get_black_pixel (void)
{
	return BlackPixel (colour_display, DefaultScreen (colour_display));
}



unsigned long
colour_get_white_pixel (void)
{
	return WhitePixel (colour_display, DefaultScreen (colour_display));
}



void
colour_free (unsigned int pixel)
{
	/* This is a no-op until I actually need to do this. */
}

