gimp/modules/colorsel_gtk.c
Austin Donnelly 43639fa0b3 iMon Jan 18 23:36:57 1999 Austin Donnelly <austin@gimp.org>
* app/menus.c: include module browser, plus re-instate the 'swap
	     colors' and other options that got killed by mistake.  Clean
	     up the odd extra separator too.

	* app/color_notebook.c: hide newly created colour selectors so we
	     know the GIMP one will be the default page.

	* app/module_db.[ch]: NEW FILEs: module database / browser.
	* app/Makefile.am: add module_db.[ch] stuff
	* app/app_procs.c: initialise the module_db
	* app/commands.[ch]: callback to create a module browser.
	* app/plug_in.c: move module loading out to module_db.c
	* libgimp/gimpmodule.h: API change: module_init() should return
	     additonal info (author, purpose, date, etc.)   Also optional
	     module_unload() function.
	* modules/colorsel_gtk.c: add module info, plus an unload function

	* modules/Makefile.am: build triangle colour selector module
	* modules/colorsel_triangle.c: NEW FILE: colour selector from
	     Simon Budig <Simon.Budig@unix-ag.org>.

	* MAINTAINERS: changed my email address
1999-01-19 00:03:00 +00:00

165 lines
3.9 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* colorsel_gtk module (C) 1998 Austin Donnelly <austin@greenend.org.uk>
*
* 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 <gtk/gtk.h>
#include <libgimp/color_selector.h>
#include <libgimp/gimpmodule.h>
/* prototypes */
static GtkWidget * colorsel_gtk_new (int, int, int,
GimpColorSelector_Callback, void *,
void **);
static void colorsel_gtk_free (void *);
static void colorsel_gtk_setcolor (void *, int, int, int, int);
static void colorsel_gtk_update (GtkWidget *, gpointer);
/* local methods */
static GimpColorSelectorMethods methods =
{
colorsel_gtk_new,
colorsel_gtk_free,
colorsel_gtk_setcolor
};
static GimpModuleInfo info = {
NULL,
"GTK colour selector as a pluggable colour selector",
"Austin Donnelly <austin@gimp.org>",
"v0.02",
"(c) 1999, released under the GPL",
"17 Jan 1999"
};
/* globaly exported init function */
G_MODULE_EXPORT GimpModuleStatus
module_init (GimpModuleInfo **inforet)
{
GimpColorSelectorID id;
id = gimp_color_selector_register ("GTK", &methods);
if (id)
{
info.shutdown_data = id;
*inforet = &info;
return GIMP_MODULE_OK;
}
else
{
return GIMP_MODULE_UNLOAD;
}
}
G_MODULE_EXPORT void
module_unload (void *shutdown_data,
void (*completed_cb)(void *),
void *completed_data)
{
gimp_color_selector_unregister (shutdown_data, completed_cb, completed_data);
}
/**************************************************************/
/* GTK colour selector methods */
typedef struct {
GtkWidget *selector;
GimpColorSelector_Callback callback;
void *client_data;
} ColorselGtk;
static GtkWidget *
colorsel_gtk_new (int r, int g, int b,
GimpColorSelector_Callback callback, void *client_data,
/* RETURNS: */
void **selector_data)
{
ColorselGtk *p;
p = g_malloc (sizeof (ColorselGtk));
p->selector = gtk_color_selection_new ();
p->callback = callback;
p->client_data = client_data;
colorsel_gtk_setcolor (p, r, g, b, FALSE);
gtk_signal_connect (GTK_OBJECT (p->selector), "color_changed",
(GtkSignalFunc) colorsel_gtk_update, p);
(*selector_data) = p;
return p->selector;
}
static void
colorsel_gtk_free (void *data)
{
ColorselGtk *p = data;
/* don't need to gtk_widget_destroy() the selector, since that's
* done for us. */
g_free (p);
}
static void
colorsel_gtk_setcolor (void *data,
int r, int g, int b, int set_current)
{
ColorselGtk *p = data;
double color[3];
color[0] = ((gdouble) r) / 255.999;
color[1] = ((gdouble) g) / 255.999;
color[2] = ((gdouble) b) / 255.999;
gtk_color_selection_set_color (GTK_COLOR_SELECTION (p->selector), color);
}
static void
colorsel_gtk_update (GtkWidget *widget, gpointer data)
{
ColorselGtk *p = data;
int r;
int g;
int b;
double color[3];
gtk_color_selection_get_color (GTK_COLOR_SELECTION (p->selector), color);
r = (int) (color[0] * 255.999);
g = (int) (color[1] * 255.999);
b = (int) (color[2] * 255.999);
p->callback (p->client_data, r, g, b);
}
/* End of colorsel_gtk.c */