Ported module loading to GTypeModule, getting rid of all own module
2002-10-20 Michael Natterer <mitch@gimp.org> Ported module loading to GTypeModule, getting rid of all own module registering/bookkeeping stuff for color selectors and display filters. The modules now simply register GimpColorSelector and GimpColorDisplay subclasses, the list of registered subclasses can then be obtained calling g_type_children() on the abstract base classes. This is work in progress and just the first working state after I started breaking everything... * app/gui/color-select.[ch] * libgimp/gimpcolordisplay.h * libgimp/gimpcolorselector.h: removed. * app/gui/Makefile.am * libgimp/Makefile.am: changed accordingly. * libgimp/gimpmodule.h: massively simplified. All voodoo is gone. * libgimpwidgets/gimpcolordisplay.[ch] * libgimpwidgets/gimpcolorselector.[ch]: new abstract base classes which need to be subclassed by modules. * libgimpwidgets/gimpcolorselect.[ch]: the built-in color selector from app/gui/color-select.* ported to be a GimpColorSelector subclass. * libgimpwidgets/Makefile.am * libgimpwidgets/gimpwidgets.h * libgimpwidgets/gimpwidgetsmarshal.list * libgimpwidgets/gimpwidgetstypes.h: changed accordingly. * app/core/gimpmoduleinfo.[ch]: made it a GTypeModule subclass * app/core/gimpmodules.c: changed accordingly. * app/core/gimpcontainer.c * app/core/gimplist.c: HACKED around to allow GimpLists of GObjects (not GimpObjects). This is EEKy, so I will either make gimp->modules a simple GList and revert this bit of change, or allow GObjects all over the place in GimpContainer land... * app/display/gimpdisplayshell-filter.[ch] * app/gui/color-notebook.c: removed all module stuff and use g_type_children() to get the list of available color_selectors and display_filters. * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-render.c * app/gui/module-browser.c: changed accordingly. * app/gui/gui.c: ref the built-in color selector's class before the modules are queried so it appears first in the list of GimpColorSelector's children. * modules/Makefile.am: build the water color selector again. * modules/cdisplay_gamma.c * modules/cdisplay_highcontrast.c * modules/colorsel_triangle.c * modules/colorsel_water.c: ported them all to the new API. * modules/gimpmodregister.[ch]: removed the old EMX module hack.
This commit is contained in:

committed by
Michael Natterer

parent
921d265270
commit
d7055a3351
@ -2,8 +2,6 @@
|
||||
|
||||
libdir = $(gimpplugindir)/modules
|
||||
|
||||
AM_CPPFLAGS = -DMODULE_COMPILATION
|
||||
|
||||
INCLUDES = \
|
||||
-I$(top_srcdir) \
|
||||
$(GTK_CFLAGS) \
|
||||
@ -14,17 +12,15 @@ EXTRA_DIST = \
|
||||
makefile.mingw.in \
|
||||
makefile.msc \
|
||||
module.def \
|
||||
gimpmodregister.c \
|
||||
gimpmodregister.h \
|
||||
colorsel_water.c
|
||||
|
||||
lib_LTLIBRARIES = \
|
||||
libcolorsel_triangle.la \
|
||||
libcdisplay_gamma.la \
|
||||
libcdisplay_highcontrast.la
|
||||
libcdisplay_highcontrast.la \
|
||||
libcolorsel_water.la
|
||||
|
||||
## libcolorsel_gtk.la \
|
||||
## libcolorsel_water.la \
|
||||
|
||||
EXTRA_LTLIBRARIES =
|
||||
|
||||
@ -36,9 +32,9 @@ libcolorsel_triangle_la_SOURCES = colorsel_triangle.c
|
||||
libcolorsel_triangle_la_LDFLAGS = -avoid-version -module
|
||||
libcolorsel_triangle_la_LIBADD = $(GTK_LIBS)
|
||||
|
||||
## libcolorsel_water_la_SOURCES = colorsel_water.c
|
||||
## libcolorsel_water_la_LDFLAGS = -avoid-version -module
|
||||
## libcolorsel_water_la_LIBADD = $(GTK_LIBS)
|
||||
libcolorsel_water_la_SOURCES = colorsel_water.c
|
||||
libcolorsel_water_la_LDFLAGS = -avoid-version -module
|
||||
libcolorsel_water_la_LIBADD = $(GTK_LIBS)
|
||||
|
||||
libcdisplay_gamma_la_SOURCES = cdisplay_gamma.c
|
||||
libcdisplay_gamma_la_LDFLAGS = -avoid-version -module
|
||||
|
@ -15,6 +15,7 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
@ -23,74 +24,77 @@
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
#include "libgimpmath/gimpmath.h"
|
||||
#include "libgimp/gimpmodule.h"
|
||||
#include "libgimp/gimpcolordisplay.h"
|
||||
#include "libgimpwidgets/gimpwidgets.h"
|
||||
|
||||
#include "gimpmodregister.h"
|
||||
#include "libgimp/gimpmodule.h"
|
||||
|
||||
#include "libgimp/gimpintl.h"
|
||||
|
||||
|
||||
#define COLOR_DISPLAY_NAME _("Gamma")
|
||||
#define CDISPLAY_TYPE_GAMMA (cdisplay_gamma_type)
|
||||
#define CDISPLAY_GAMMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CDISPLAY_TYPE_GAMMA, CdisplayGamma))
|
||||
#define CDISPLAY_GAMMA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CDISPLAY_TYPE_GAMMA, CdisplayGammaClass))
|
||||
#define CDISPLAY_IS_GAMMA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CDISPLAY_TYPE_GAMMA))
|
||||
#define CDISPLAY_IS_GAMMA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CDISPLAY_TYPE_GAMMA))
|
||||
|
||||
typedef struct _GammaContext GammaContext;
|
||||
|
||||
struct _GammaContext
|
||||
typedef struct _CdisplayGamma CdisplayGamma;
|
||||
typedef struct _CdisplayGammaClass CdisplayGammaClass;
|
||||
|
||||
struct _CdisplayGamma
|
||||
{
|
||||
GFunc ok_func;
|
||||
gpointer ok_data;
|
||||
GFunc cancel_func;
|
||||
gpointer cancel_data;
|
||||
GimpColorDisplay parent_instance;
|
||||
|
||||
gdouble gamma;
|
||||
guchar *lookup;
|
||||
GFunc ok_func;
|
||||
gpointer ok_data;
|
||||
GFunc cancel_func;
|
||||
gpointer cancel_data;
|
||||
|
||||
GtkWidget *shell;
|
||||
GtkWidget *spinner;
|
||||
gdouble gamma;
|
||||
guchar *lookup;
|
||||
|
||||
GtkWidget *shell;
|
||||
GtkWidget *spinner;
|
||||
};
|
||||
|
||||
static gpointer gamma_new (int type);
|
||||
static gpointer gamma_clone (gpointer cd_ID);
|
||||
static void gamma_create_lookup_table (GammaContext *context);
|
||||
static void gamma_destroy (gpointer cd_ID);
|
||||
static void gamma_convert (gpointer cd_ID,
|
||||
guchar *buf,
|
||||
int w,
|
||||
int h,
|
||||
int bpp,
|
||||
int bpl);
|
||||
static void gamma_load (gpointer cd_ID,
|
||||
GimpParasite *state);
|
||||
static GimpParasite * gamma_save (gpointer cd_ID);
|
||||
static void gamma_configure_ok_callback (GtkWidget *widget,
|
||||
gpointer data);
|
||||
static void gamma_configure_cancel_callback (GtkWidget *widget,
|
||||
gpointer data);
|
||||
static void gamma_configure (gpointer cd_ID,
|
||||
GFunc ok_func,
|
||||
gpointer ok_data,
|
||||
GFunc cancel_func,
|
||||
gpointer cancel_data);
|
||||
static void gamma_configure_cancel (gpointer cd_ID);
|
||||
|
||||
static GimpColorDisplayMethods methods =
|
||||
struct _CdisplayGammaClass
|
||||
{
|
||||
NULL,
|
||||
gamma_new,
|
||||
gamma_clone,
|
||||
gamma_convert,
|
||||
gamma_destroy,
|
||||
NULL,
|
||||
gamma_load,
|
||||
gamma_save,
|
||||
gamma_configure,
|
||||
gamma_configure_cancel
|
||||
GimpColorDisplayClass parent_instance;
|
||||
};
|
||||
|
||||
static GimpModuleInfo info =
|
||||
|
||||
static GType cdisplay_gamma_get_type (GTypeModule *module);
|
||||
static void cdisplay_gamma_class_init (CdisplayGammaClass *klass);
|
||||
static void cdisplay_gamma_init (CdisplayGamma *gamma);
|
||||
|
||||
static void cdisplay_gamma_finalize (GObject *object);
|
||||
|
||||
static GimpColorDisplay * cdisplay_gamma_clone (GimpColorDisplay *display);
|
||||
static void cdisplay_gamma_convert (GimpColorDisplay *display,
|
||||
guchar *buf,
|
||||
gint w,
|
||||
gint h,
|
||||
gint bpp,
|
||||
gint bpl);
|
||||
static void cdisplay_gamma_load_state (GimpColorDisplay *display,
|
||||
GimpParasite *state);
|
||||
static GimpParasite * cdisplay_gamma_save_state (GimpColorDisplay *display);
|
||||
static void cdisplay_gamma_configure (GimpColorDisplay *display,
|
||||
GFunc ok_func,
|
||||
gpointer ok_data,
|
||||
GFunc cancel_func,
|
||||
gpointer cancel_data);
|
||||
static void cdisplay_gamma_configure_cancel (GimpColorDisplay *display);
|
||||
|
||||
static void gamma_create_lookup_table (CdisplayGamma *gamma);
|
||||
static void gamma_configure_ok_callback (GtkWidget *widget,
|
||||
CdisplayGamma *gamma);
|
||||
static void gamma_configure_cancel_callback (GtkWidget *widget,
|
||||
CdisplayGamma *gamma);
|
||||
|
||||
|
||||
static GimpModuleInfo cdisplay_gamma_info =
|
||||
{
|
||||
NULL,
|
||||
N_("Gamma color display filter"),
|
||||
"Manish Singh <yosh@gimp.org>",
|
||||
"v0.2",
|
||||
@ -98,111 +102,137 @@ static GimpModuleInfo info =
|
||||
"October 14, 2000"
|
||||
};
|
||||
|
||||
G_MODULE_EXPORT GimpModuleStatus
|
||||
module_init (GimpModuleInfo **inforet)
|
||||
static GType cdisplay_gamma_type = 0;
|
||||
static GimpColorDisplayClass *parent_class = NULL;
|
||||
|
||||
|
||||
G_MODULE_EXPORT gboolean
|
||||
gimp_module_register (GTypeModule *module,
|
||||
GimpModuleInfo **inforet)
|
||||
{
|
||||
#ifndef __EMX__
|
||||
if (gimp_color_display_register (COLOR_DISPLAY_NAME, &methods))
|
||||
#else
|
||||
if (mod_color_display_register (COLOR_DISPLAY_NAME, &methods))
|
||||
#endif
|
||||
cdisplay_gamma_get_type (module);
|
||||
|
||||
if (inforet)
|
||||
*inforet = &cdisplay_gamma_info;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GType
|
||||
cdisplay_gamma_get_type (GTypeModule *module)
|
||||
{
|
||||
if (! cdisplay_gamma_type)
|
||||
{
|
||||
*inforet = &info;
|
||||
return GIMP_MODULE_OK;
|
||||
static const GTypeInfo select_info =
|
||||
{
|
||||
sizeof (CdisplayGammaClass),
|
||||
(GBaseInitFunc) NULL,
|
||||
(GBaseFinalizeFunc) NULL,
|
||||
(GClassInitFunc) cdisplay_gamma_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (CdisplayGamma),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) cdisplay_gamma_init,
|
||||
};
|
||||
|
||||
cdisplay_gamma_type =
|
||||
g_type_module_register_type (module,
|
||||
GIMP_TYPE_COLOR_DISPLAY,
|
||||
"CdisplayGamma",
|
||||
&select_info, 0);
|
||||
}
|
||||
else
|
||||
return GIMP_MODULE_UNLOAD;
|
||||
|
||||
return cdisplay_gamma_type;
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT void
|
||||
module_unload (void *shutdown_data,
|
||||
void (*completed_cb) (void *),
|
||||
void *completed_data)
|
||||
static void
|
||||
cdisplay_gamma_class_init (CdisplayGammaClass *klass)
|
||||
{
|
||||
#ifndef __EMX__
|
||||
gimp_color_display_unregister (COLOR_DISPLAY_NAME);
|
||||
#else
|
||||
mod_color_display_unregister (COLOR_DISPLAY_NAME);
|
||||
#endif
|
||||
GObjectClass *object_class;
|
||||
GimpColorDisplayClass *display_class;
|
||||
|
||||
object_class = G_OBJECT_CLASS (klass);
|
||||
display_class = GIMP_COLOR_DISPLAY_CLASS (klass);
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
object_class->finalize = cdisplay_gamma_finalize;
|
||||
|
||||
display_class->name = _("Gamma");
|
||||
display_class->help_page = "modules/gamma.html";
|
||||
display_class->clone = cdisplay_gamma_clone;
|
||||
display_class->convert = cdisplay_gamma_convert;
|
||||
display_class->load_state = cdisplay_gamma_load_state;
|
||||
display_class->save_state = cdisplay_gamma_save_state;
|
||||
display_class->configure = cdisplay_gamma_configure;
|
||||
display_class->configure_cancel = cdisplay_gamma_configure_cancel;
|
||||
}
|
||||
|
||||
|
||||
static gpointer
|
||||
gamma_new (int type)
|
||||
static void
|
||||
cdisplay_gamma_init (CdisplayGamma *gamma)
|
||||
{
|
||||
int i;
|
||||
GammaContext *context;
|
||||
gint i;
|
||||
|
||||
context = g_new0 (GammaContext, 1);
|
||||
context->gamma = 1.0;
|
||||
context->lookup = g_new (guchar, 256);
|
||||
gamma->gamma = 1.0;
|
||||
gamma->lookup = g_new (guchar, 256);
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
context->lookup[i] = i;
|
||||
|
||||
return context;
|
||||
gamma->lookup[i] = i;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
gamma_clone (gpointer cd_ID)
|
||||
static void
|
||||
cdisplay_gamma_finalize (GObject *object)
|
||||
{
|
||||
GammaContext *src_context = cd_ID;
|
||||
GammaContext *context;
|
||||
CdisplayGamma *gamma;
|
||||
|
||||
context = gamma_new (0);
|
||||
context->gamma = src_context->gamma;
|
||||
gamma = CDISPLAY_GAMMA (object);
|
||||
|
||||
if (gamma->shell)
|
||||
{
|
||||
gtk_widget_destroy (gamma->shell);
|
||||
gamma->shell = NULL;
|
||||
}
|
||||
|
||||
if (gamma->lookup)
|
||||
{
|
||||
g_free (gamma->lookup);
|
||||
gamma->lookup = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
||||
static GimpColorDisplay *
|
||||
cdisplay_gamma_clone (GimpColorDisplay *display)
|
||||
{
|
||||
CdisplayGamma *gamma;
|
||||
CdisplayGamma *copy;
|
||||
|
||||
gamma = CDISPLAY_GAMMA (display);
|
||||
|
||||
copy = CDISPLAY_GAMMA (gimp_color_display_new (G_TYPE_FROM_INSTANCE (gamma)));
|
||||
|
||||
copy->gamma = gamma->gamma;
|
||||
|
||||
memcpy (context->lookup, src_context->lookup, sizeof (guchar) * 256);
|
||||
memcpy (copy->lookup, gamma->lookup, sizeof (guchar) * 256);
|
||||
|
||||
return context;
|
||||
return GIMP_COLOR_DISPLAY (copy);
|
||||
}
|
||||
|
||||
static void
|
||||
gamma_create_lookup_table (GammaContext *context)
|
||||
cdisplay_gamma_convert (GimpColorDisplay *display,
|
||||
guchar *buf,
|
||||
gint width,
|
||||
gint height,
|
||||
gint bpp,
|
||||
gint bpl)
|
||||
{
|
||||
gdouble one_over_gamma;
|
||||
gdouble ind;
|
||||
gint i;
|
||||
CdisplayGamma *gamma;
|
||||
gint i, j = height;
|
||||
|
||||
if (context->gamma == 0.0)
|
||||
context->gamma = 1.0;
|
||||
|
||||
one_over_gamma = 1.0 / context->gamma;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
ind = (double) i / 255.0;
|
||||
context->lookup[i] = (guchar) (gint) (255 * pow (ind, one_over_gamma));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gamma_destroy (gpointer cd_ID)
|
||||
{
|
||||
GammaContext *context = cd_ID;
|
||||
|
||||
if (context->shell)
|
||||
{
|
||||
#if 0
|
||||
dialog_unregister (context->shell);
|
||||
#endif
|
||||
gtk_widget_destroy (context->shell);
|
||||
}
|
||||
|
||||
g_free (context->lookup);
|
||||
g_free (context);
|
||||
}
|
||||
|
||||
static void
|
||||
gamma_convert (gpointer cd_ID,
|
||||
guchar *buf,
|
||||
gint width,
|
||||
gint height,
|
||||
gint bpp,
|
||||
gint bpl)
|
||||
{
|
||||
guchar *lookup = ((GammaContext *) cd_ID)->lookup;
|
||||
gint i, j = height;
|
||||
gamma = CDISPLAY_GAMMA (display);
|
||||
|
||||
/* You will not be using the entire buffer most of the time.
|
||||
* Hence, the simplistic code for this is as follows:
|
||||
@ -223,7 +253,7 @@ gamma_convert (gpointer cd_ID,
|
||||
i = width;
|
||||
while (i--)
|
||||
{
|
||||
*buf = lookup[*buf];
|
||||
*buf = gamma->lookup[*buf];
|
||||
buf++;
|
||||
}
|
||||
buf += bpl;
|
||||
@ -231,36 +261,44 @@ gamma_convert (gpointer cd_ID,
|
||||
}
|
||||
|
||||
static void
|
||||
gamma_load (gpointer cd_ID,
|
||||
GimpParasite *state)
|
||||
cdisplay_gamma_load_state (GimpColorDisplay *display,
|
||||
GimpParasite *state)
|
||||
{
|
||||
GammaContext *context = cd_ID;
|
||||
CdisplayGamma *gamma;
|
||||
|
||||
gamma = CDISPLAY_GAMMA (display);
|
||||
|
||||
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
||||
memcpy (&context->gamma, gimp_parasite_data (state), sizeof (gdouble));
|
||||
memcpy (&gamma->gamma, gimp_parasite_data (state), sizeof (gdouble));
|
||||
#else
|
||||
guint32 buf[2], *data = gimp_parasite_data (state);
|
||||
{
|
||||
guint32 buf[2], *data = gimp_parasite_data (state);
|
||||
|
||||
buf[0] = g_ntohl (data[1]);
|
||||
buf[1] = g_ntohl (data[0]);
|
||||
buf[0] = g_ntohl (data[1]);
|
||||
buf[1] = g_ntohl (data[0]);
|
||||
|
||||
memcpy (&context->gamma, buf, sizeof (gdouble));
|
||||
memcpy (&gamma->gamma, buf, sizeof (gdouble));
|
||||
}
|
||||
#endif
|
||||
|
||||
gamma_create_lookup_table (context);
|
||||
gamma_create_lookup_table (gamma);
|
||||
}
|
||||
|
||||
static GimpParasite *
|
||||
gamma_save (gpointer cd_ID)
|
||||
cdisplay_gamma_save_state (GimpColorDisplay *display)
|
||||
{
|
||||
GammaContext *context = cd_ID;
|
||||
guint32 buf[2];
|
||||
CdisplayGamma *gamma;
|
||||
guint32 buf[2];
|
||||
|
||||
memcpy (buf, &context->gamma, sizeof (double));
|
||||
gamma = CDISPLAY_GAMMA (display);
|
||||
|
||||
memcpy (buf, &gamma->gamma, sizeof (double));
|
||||
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
{
|
||||
guint32 tmp = g_htonl (buf[0]);
|
||||
guint32 tmp;
|
||||
|
||||
tmp = g_htonl (buf[0]);
|
||||
buf[0] = g_htonl (buf[1]);
|
||||
buf[1] = tmp;
|
||||
}
|
||||
@ -271,113 +309,113 @@ gamma_save (gpointer cd_ID)
|
||||
}
|
||||
|
||||
static void
|
||||
gamma_configure_ok_callback (GtkWidget *widget,
|
||||
gpointer data)
|
||||
cdisplay_gamma_configure (GimpColorDisplay *display,
|
||||
GFunc ok_func,
|
||||
gpointer ok_data,
|
||||
GFunc cancel_func,
|
||||
gpointer cancel_data)
|
||||
{
|
||||
GammaContext *context = data;
|
||||
CdisplayGamma *gamma;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *label;
|
||||
GtkObject *adjustment;
|
||||
|
||||
context->gamma =
|
||||
gtk_spin_button_get_value (GTK_SPIN_BUTTON (context->spinner));
|
||||
gamma_create_lookup_table (context);
|
||||
gamma = CDISPLAY_GAMMA (display);
|
||||
|
||||
#if 0
|
||||
dialog_unregister (context->shell);
|
||||
#endif
|
||||
|
||||
gtk_widget_destroy (GTK_WIDGET (context->shell));
|
||||
context->shell = NULL;
|
||||
|
||||
if (context->ok_func)
|
||||
context->ok_func (context, context->ok_data);
|
||||
}
|
||||
|
||||
static void
|
||||
gamma_configure_cancel_callback (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
GammaContext *context = data;
|
||||
|
||||
#if 0
|
||||
dialog_unregister (context->shell);
|
||||
#endif
|
||||
|
||||
gtk_widget_destroy (GTK_WIDGET (context->shell));
|
||||
context->shell = NULL;
|
||||
|
||||
if (context->cancel_func)
|
||||
context->cancel_func (context, context->cancel_data);
|
||||
}
|
||||
|
||||
static void
|
||||
gamma_configure (gpointer cd_ID,
|
||||
GFunc ok_func,
|
||||
gpointer ok_data,
|
||||
GFunc cancel_func,
|
||||
gpointer cancel_data)
|
||||
{
|
||||
GammaContext *context = cd_ID;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *label;
|
||||
GtkObject *adjustment;
|
||||
|
||||
if (!context->shell)
|
||||
if (!gamma->shell)
|
||||
{
|
||||
context->ok_func = ok_func;
|
||||
context->ok_data = ok_data;
|
||||
context->cancel_func = cancel_func;
|
||||
context->cancel_data = cancel_data;
|
||||
gamma->ok_func = ok_func;
|
||||
gamma->ok_data = ok_data;
|
||||
gamma->cancel_func = cancel_func;
|
||||
gamma->cancel_data = cancel_data;
|
||||
|
||||
context->shell =
|
||||
gamma->shell =
|
||||
gimp_dialog_new (_("Gamma"), "gamma",
|
||||
gimp_standard_help_func, "modules/gamma.html",
|
||||
GTK_WIN_POS_MOUSE,
|
||||
FALSE, TRUE, FALSE,
|
||||
|
||||
GTK_STOCK_CANCEL, gamma_configure_cancel_callback,
|
||||
cd_ID, NULL, NULL, FALSE, TRUE,
|
||||
gamma, NULL, NULL, FALSE, TRUE,
|
||||
|
||||
GTK_STOCK_OK, gamma_configure_ok_callback,
|
||||
cd_ID, NULL, NULL, TRUE, FALSE,
|
||||
gamma, NULL, NULL, TRUE, FALSE,
|
||||
|
||||
NULL);
|
||||
|
||||
#if 0
|
||||
dialog_register (context->shell);
|
||||
#endif
|
||||
|
||||
hbox = gtk_hbox_new (FALSE, 2);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
|
||||
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (context->shell)->vbox),
|
||||
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (gamma->shell)->vbox),
|
||||
hbox, FALSE, FALSE, 0);
|
||||
|
||||
label = gtk_label_new ( _("Gamma:"));
|
||||
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
|
||||
|
||||
adjustment = gtk_adjustment_new (context->gamma, 0.01, 10.0, 0.01, 0.1, 0.0);
|
||||
context->spinner = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment),
|
||||
adjustment = gtk_adjustment_new (gamma->gamma, 0.01, 10.0, 0.01, 0.1, 0.0);
|
||||
gamma->spinner = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment),
|
||||
0.1, 3);
|
||||
gtk_widget_set_size_request (context->spinner, 100, -1);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), context->spinner, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), gamma->spinner, FALSE, FALSE, 0);
|
||||
}
|
||||
|
||||
gtk_widget_show_all (context->shell);
|
||||
gtk_widget_show_all (gamma->shell);
|
||||
}
|
||||
|
||||
static void
|
||||
gamma_configure_cancel (gpointer cd_ID)
|
||||
cdisplay_gamma_configure_cancel (GimpColorDisplay *display)
|
||||
{
|
||||
GammaContext *context = cd_ID;
|
||||
CdisplayGamma *gamma;
|
||||
|
||||
if (context->shell)
|
||||
gamma = CDISPLAY_GAMMA (display);
|
||||
|
||||
if (gamma->shell)
|
||||
{
|
||||
#if 0
|
||||
dialog_unregister (context->shell);
|
||||
#endif
|
||||
gtk_widget_destroy (context->shell);
|
||||
context->shell = NULL;
|
||||
gtk_widget_destroy (gamma->shell);
|
||||
gamma->shell = NULL;
|
||||
}
|
||||
|
||||
if (context->cancel_func)
|
||||
context->cancel_func (context, context->cancel_data);
|
||||
if (gamma->cancel_func)
|
||||
gamma->cancel_func (gamma, gamma->cancel_data);
|
||||
}
|
||||
|
||||
static void
|
||||
gamma_create_lookup_table (CdisplayGamma *gamma)
|
||||
{
|
||||
gdouble one_over_gamma;
|
||||
gdouble ind;
|
||||
gint i;
|
||||
|
||||
if (gamma->gamma == 0.0)
|
||||
gamma->gamma = 1.0;
|
||||
|
||||
one_over_gamma = 1.0 / gamma->gamma;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
ind = (gdouble) i / 255.0;
|
||||
gamma->lookup[i] = (guchar) (gint) (255 * pow (ind, one_over_gamma));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gamma_configure_ok_callback (GtkWidget *widget,
|
||||
CdisplayGamma *gamma)
|
||||
{
|
||||
gamma->gamma =
|
||||
gtk_spin_button_get_value (GTK_SPIN_BUTTON (gamma->spinner));
|
||||
|
||||
gamma_create_lookup_table (gamma);
|
||||
|
||||
gtk_widget_destroy (GTK_WIDGET (gamma->shell));
|
||||
gamma->shell = NULL;
|
||||
|
||||
if (gamma->ok_func)
|
||||
gamma->ok_func (gamma, gamma->ok_data);
|
||||
}
|
||||
|
||||
static void
|
||||
gamma_configure_cancel_callback (GtkWidget *widget,
|
||||
CdisplayGamma *gamma)
|
||||
{
|
||||
gimp_color_display_configure_cancel (GIMP_COLOR_DISPLAY (gamma));
|
||||
}
|
||||
|
@ -24,74 +24,77 @@
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
#include "libgimpmath/gimpmath.h"
|
||||
#include "libgimp/gimpmodule.h"
|
||||
#include "libgimp/gimpcolordisplay.h"
|
||||
#include "libgimpwidgets/gimpwidgets.h"
|
||||
|
||||
#include "gimpmodregister.h"
|
||||
#include "libgimp/gimpmodule.h"
|
||||
|
||||
#include "libgimp/gimpintl.h"
|
||||
|
||||
|
||||
#define COLOR_DISPLAY_NAME _("High Contrast")
|
||||
#define CDISPLAY_TYPE_CONTRAST (cdisplay_contrast_type)
|
||||
#define CDISPLAY_CONTRAST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CDISPLAY_TYPE_CONTRAST, CdisplayContrast))
|
||||
#define CDISPLAY_CONTRAST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CDISPLAY_TYPE_CONTRAST, CdisplayContrastClass))
|
||||
#define CDISPLAY_IS_CONTRAST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CDISPLAY_TYPE_CONTRAST))
|
||||
#define CDISPLAY_IS_CONTRAST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CDISPLAY_TYPE_CONTRAST))
|
||||
|
||||
typedef struct _ContrastContext ContrastContext;
|
||||
|
||||
struct _ContrastContext
|
||||
typedef struct _CdisplayContrast CdisplayContrast;
|
||||
typedef struct _CdisplayContrastClass CdisplayContrastClass;
|
||||
|
||||
struct _CdisplayContrast
|
||||
{
|
||||
GFunc ok_func;
|
||||
gpointer ok_data;
|
||||
GFunc cancel_func;
|
||||
gpointer cancel_data;
|
||||
GimpColorDisplay parent_instance;
|
||||
|
||||
gdouble contrast;
|
||||
guchar *lookup;
|
||||
GFunc ok_func;
|
||||
gpointer ok_data;
|
||||
GFunc cancel_func;
|
||||
gpointer cancel_data;
|
||||
|
||||
GtkWidget *shell;
|
||||
GtkWidget *spinner;
|
||||
gdouble contrast;
|
||||
guchar *lookup;
|
||||
|
||||
GtkWidget *shell;
|
||||
GtkWidget *spinner;
|
||||
};
|
||||
|
||||
static gpointer contrast_new (gint type);
|
||||
static gpointer contrast_clone (gpointer cd_ID);
|
||||
static void contrast_create_lookup_table (ContrastContext *context);
|
||||
static void contrast_destroy (gpointer cd_ID);
|
||||
static void contrast_convert (gpointer cd_ID,
|
||||
guchar *buf,
|
||||
gint w,
|
||||
gint h,
|
||||
gint bpp,
|
||||
gint bpl);
|
||||
static void contrast_load (gpointer cd_ID,
|
||||
GimpParasite *state);
|
||||
static GimpParasite * contrast_save (gpointer cd_ID);
|
||||
static void contrast_configure_ok_callback (GtkWidget *widget,
|
||||
gpointer data);
|
||||
static void contrast_configure_cancel_callback (GtkWidget *widget,
|
||||
gpointer data);
|
||||
static void contrast_configure (gpointer cd_ID,
|
||||
GFunc ok_func,
|
||||
gpointer ok_data,
|
||||
GFunc cancel_func,
|
||||
gpointer cancel_data);
|
||||
static void contrast_configure_cancel (gpointer cd_ID);
|
||||
|
||||
static GimpColorDisplayMethods methods =
|
||||
struct _CdisplayContrastClass
|
||||
{
|
||||
NULL,
|
||||
contrast_new,
|
||||
contrast_clone,
|
||||
contrast_convert,
|
||||
contrast_destroy,
|
||||
NULL,
|
||||
contrast_load,
|
||||
contrast_save,
|
||||
contrast_configure,
|
||||
contrast_configure_cancel
|
||||
GimpColorDisplayClass parent_instance;
|
||||
};
|
||||
|
||||
static GimpModuleInfo info =
|
||||
|
||||
static GType cdisplay_contrast_get_type (GTypeModule *module);
|
||||
static void cdisplay_contrast_class_init (CdisplayContrastClass *klass);
|
||||
static void cdisplay_contrast_init (CdisplayContrast *contrast);
|
||||
|
||||
static void cdisplay_contrast_finalize (GObject *object);
|
||||
|
||||
static GimpColorDisplay * cdisplay_contrast_clone (GimpColorDisplay *display);
|
||||
static void cdisplay_contrast_convert (GimpColorDisplay *display,
|
||||
guchar *buf,
|
||||
gint w,
|
||||
gint h,
|
||||
gint bpp,
|
||||
gint bpl);
|
||||
static void cdisplay_contrast_load_state (GimpColorDisplay *display,
|
||||
GimpParasite *state);
|
||||
static GimpParasite * cdisplay_contrast_save_state (GimpColorDisplay *display);
|
||||
static void cdisplay_contrast_configure (GimpColorDisplay *display,
|
||||
GFunc ok_func,
|
||||
gpointer ok_data,
|
||||
GFunc cancel_func,
|
||||
gpointer cancel_data);
|
||||
static void cdisplay_contrast_configure_cancel (GimpColorDisplay *display);
|
||||
|
||||
static void contrast_create_lookup_table (CdisplayContrast *contrast);
|
||||
static void contrast_configure_ok_callback (GtkWidget *widget,
|
||||
CdisplayContrast *contrast);
|
||||
static void contrast_configure_cancel_callback (GtkWidget *widget,
|
||||
CdisplayContrast *contrast);
|
||||
|
||||
|
||||
static GimpModuleInfo cdisplay_contrast_info =
|
||||
{
|
||||
NULL,
|
||||
N_("High Contrast color display filter"),
|
||||
"Jay Cox <jaycox@earthlink.net>",
|
||||
"v0.2",
|
||||
@ -99,105 +102,134 @@ static GimpModuleInfo info =
|
||||
"October 14, 2000"
|
||||
};
|
||||
|
||||
G_MODULE_EXPORT GimpModuleStatus
|
||||
module_init (GimpModuleInfo **inforet)
|
||||
static GType cdisplay_contrast_type = 0;
|
||||
static GimpColorDisplayClass *parent_class = NULL;
|
||||
|
||||
|
||||
G_MODULE_EXPORT gboolean
|
||||
gimp_module_register (GTypeModule *module,
|
||||
GimpModuleInfo **inforet)
|
||||
{
|
||||
#ifndef __EMX__
|
||||
if (gimp_color_display_register (COLOR_DISPLAY_NAME, &methods))
|
||||
#else
|
||||
if (mod_color_display_register (COLOR_DISPLAY_NAME, &methods))
|
||||
#endif
|
||||
cdisplay_contrast_get_type (module);
|
||||
|
||||
if (inforet)
|
||||
*inforet = &cdisplay_contrast_info;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GType
|
||||
cdisplay_contrast_get_type (GTypeModule *module)
|
||||
{
|
||||
if (! cdisplay_contrast_type)
|
||||
{
|
||||
*inforet = &info;
|
||||
return GIMP_MODULE_OK;
|
||||
static const GTypeInfo select_info =
|
||||
{
|
||||
sizeof (CdisplayContrastClass),
|
||||
(GBaseInitFunc) NULL,
|
||||
(GBaseFinalizeFunc) NULL,
|
||||
(GClassInitFunc) cdisplay_contrast_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (CdisplayContrast),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) cdisplay_contrast_init,
|
||||
};
|
||||
|
||||
cdisplay_contrast_type =
|
||||
g_type_module_register_type (module,
|
||||
GIMP_TYPE_COLOR_DISPLAY,
|
||||
"CdisplayContrast",
|
||||
&select_info, 0);
|
||||
}
|
||||
else
|
||||
return GIMP_MODULE_UNLOAD;
|
||||
|
||||
return cdisplay_contrast_type;
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT void
|
||||
module_unload (void *shutdown_data,
|
||||
void (*completed_cb) (void *),
|
||||
void *completed_data)
|
||||
static void
|
||||
cdisplay_contrast_class_init (CdisplayContrastClass *klass)
|
||||
{
|
||||
#ifndef __EMX__
|
||||
gimp_color_display_unregister (COLOR_DISPLAY_NAME);
|
||||
#else
|
||||
mod_color_display_unregister (COLOR_DISPLAY_NAME);
|
||||
#endif
|
||||
GObjectClass *object_class;
|
||||
GimpColorDisplayClass *display_class;
|
||||
|
||||
object_class = G_OBJECT_CLASS (klass);
|
||||
display_class = GIMP_COLOR_DISPLAY_CLASS (klass);
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
object_class->finalize = cdisplay_contrast_finalize;
|
||||
|
||||
display_class->name = _("Contrast");
|
||||
display_class->help_page = "modules/contrast.html";
|
||||
display_class->clone = cdisplay_contrast_clone;
|
||||
display_class->convert = cdisplay_contrast_convert;
|
||||
display_class->load_state = cdisplay_contrast_load_state;
|
||||
display_class->save_state = cdisplay_contrast_save_state;
|
||||
display_class->configure = cdisplay_contrast_configure;
|
||||
display_class->configure_cancel = cdisplay_contrast_configure_cancel;
|
||||
}
|
||||
|
||||
static void
|
||||
cdisplay_contrast_init (CdisplayContrast *contrast)
|
||||
{
|
||||
contrast->contrast = 4.0;
|
||||
contrast->lookup = g_new (guchar, 256);
|
||||
|
||||
contrast_create_lookup_table (contrast);
|
||||
}
|
||||
|
||||
static void
|
||||
cdisplay_contrast_finalize (GObject *object)
|
||||
{
|
||||
CdisplayContrast *contrast;
|
||||
|
||||
contrast = CDISPLAY_CONTRAST (object);
|
||||
|
||||
if (contrast->shell)
|
||||
{
|
||||
gtk_widget_destroy (contrast->shell);
|
||||
contrast->shell = NULL;
|
||||
}
|
||||
|
||||
if (contrast->lookup)
|
||||
{
|
||||
g_free (contrast->lookup);
|
||||
contrast->lookup = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
||||
static gpointer
|
||||
contrast_new (gint type)
|
||||
static GimpColorDisplay *
|
||||
cdisplay_contrast_clone (GimpColorDisplay *display)
|
||||
{
|
||||
ContrastContext *context;
|
||||
CdisplayContrast *contrast;
|
||||
CdisplayContrast *copy;
|
||||
|
||||
context = g_new0 (ContrastContext, 1);
|
||||
context->contrast = 4.0;
|
||||
context->lookup = g_new (guchar, 256);
|
||||
contrast = CDISPLAY_CONTRAST (display);
|
||||
|
||||
contrast_create_lookup_table (context);
|
||||
copy = CDISPLAY_CONTRAST (gimp_color_display_new (G_TYPE_FROM_INSTANCE (contrast)));
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
contrast_clone (gpointer cd_ID)
|
||||
{
|
||||
ContrastContext *src_context = cd_ID;
|
||||
ContrastContext *context;
|
||||
|
||||
context = contrast_new (0);
|
||||
context->contrast = src_context->contrast;
|
||||
copy->contrast = contrast->contrast;
|
||||
|
||||
memcpy (context->lookup, src_context->lookup, sizeof (guchar) * 256);
|
||||
memcpy (copy->lookup, contrast->lookup, sizeof (guchar) * 256);
|
||||
|
||||
return context;
|
||||
return GIMP_COLOR_DISPLAY (copy);
|
||||
}
|
||||
|
||||
static void
|
||||
contrast_create_lookup_table (ContrastContext *context)
|
||||
cdisplay_contrast_convert (GimpColorDisplay *display,
|
||||
guchar *buf,
|
||||
gint width,
|
||||
gint height,
|
||||
gint bpp,
|
||||
gint bpl)
|
||||
{
|
||||
gint i;
|
||||
CdisplayContrast *contrast;
|
||||
gint i, j = height;
|
||||
|
||||
if (context->contrast == 0.0)
|
||||
context->contrast = 1.0;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
context->lookup[i]
|
||||
= (guchar) (int)(255 * .5 * (1 + sin(context->contrast*2*G_PI*i/255.0)));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
contrast_destroy (gpointer cd_ID)
|
||||
{
|
||||
ContrastContext *context = cd_ID;
|
||||
|
||||
if (context->shell)
|
||||
{
|
||||
#if 0
|
||||
dialog_unregister (context->shell);
|
||||
#endif
|
||||
gtk_widget_destroy (context->shell);
|
||||
}
|
||||
|
||||
g_free (context->lookup);
|
||||
g_free (context);
|
||||
}
|
||||
|
||||
static void
|
||||
contrast_convert (gpointer cd_ID,
|
||||
guchar *buf,
|
||||
gint width,
|
||||
gint height,
|
||||
gint bpp,
|
||||
gint bpl)
|
||||
{
|
||||
guchar *lookup = ((ContrastContext *) cd_ID)->lookup;
|
||||
gint i, j = height;
|
||||
contrast = CDISPLAY_CONTRAST (display);
|
||||
|
||||
/* You will not be using the entire buffer most of the time.
|
||||
* Hence, the simplistic code for this is as follows:
|
||||
@ -218,7 +250,7 @@ contrast_convert (gpointer cd_ID,
|
||||
i = width;
|
||||
while (i--)
|
||||
{
|
||||
*buf = lookup[*buf];
|
||||
*buf = contrast->lookup[*buf];
|
||||
buf++;
|
||||
}
|
||||
buf += bpl;
|
||||
@ -226,151 +258,157 @@ contrast_convert (gpointer cd_ID,
|
||||
}
|
||||
|
||||
static void
|
||||
contrast_load (gpointer cd_ID,
|
||||
GimpParasite *state)
|
||||
cdisplay_contrast_load_state (GimpColorDisplay *display,
|
||||
GimpParasite *state)
|
||||
{
|
||||
ContrastContext *context = cd_ID;
|
||||
CdisplayContrast *contrast;
|
||||
|
||||
contrast = CDISPLAY_CONTRAST (display);
|
||||
|
||||
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
||||
memcpy (&context->contrast, gimp_parasite_data (state), sizeof (gdouble));
|
||||
memcpy (&contrast->contrast, gimp_parasite_data (state), sizeof (gdouble));
|
||||
#else
|
||||
guint32 buf[2], *data = gimp_parasite_data (state);
|
||||
{
|
||||
guint32 buf[2], *data = gimp_parasite_data (state);
|
||||
|
||||
buf[0] = g_ntohl (data[1]);
|
||||
buf[1] = g_ntohl (data[0]);
|
||||
buf[0] = g_ntohl (data[1]);
|
||||
buf[1] = g_ntohl (data[0]);
|
||||
|
||||
memcpy (&context->contrast, buf, sizeof (gdouble));
|
||||
memcpy (&contrast->contrast, buf, sizeof (gdouble));
|
||||
}
|
||||
#endif
|
||||
|
||||
contrast_create_lookup_table (context);
|
||||
contrast_create_lookup_table (contrast);
|
||||
}
|
||||
|
||||
static GimpParasite *
|
||||
contrast_save (gpointer cd_ID)
|
||||
cdisplay_contrast_save_state (GimpColorDisplay *display)
|
||||
{
|
||||
ContrastContext *context = cd_ID;
|
||||
guint32 buf[2];
|
||||
CdisplayContrast *contrast;
|
||||
guint32 buf[2];
|
||||
|
||||
memcpy (buf, &context->contrast, sizeof (gdouble));
|
||||
contrast = CDISPLAY_CONTRAST (display);
|
||||
|
||||
memcpy (buf, &contrast->contrast, sizeof (double));
|
||||
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
{
|
||||
guint32 tmp = g_htonl (buf[0]);
|
||||
guint32 tmp;
|
||||
|
||||
tmp = g_htonl (buf[0]);
|
||||
buf[0] = g_htonl (buf[1]);
|
||||
buf[1] = tmp;
|
||||
}
|
||||
#endif
|
||||
|
||||
return gimp_parasite_new ("Display/Contrast", GIMP_PARASITE_PERSISTENT,
|
||||
sizeof (gdouble), &buf);
|
||||
sizeof (double), &buf);
|
||||
}
|
||||
|
||||
static void
|
||||
contrast_configure_ok_callback (GtkWidget *widget,
|
||||
gpointer data)
|
||||
cdisplay_contrast_configure (GimpColorDisplay *display,
|
||||
GFunc ok_func,
|
||||
gpointer ok_data,
|
||||
GFunc cancel_func,
|
||||
gpointer cancel_data)
|
||||
{
|
||||
ContrastContext *context = data;
|
||||
CdisplayContrast *contrast;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *label;
|
||||
GtkObject *adjustment;
|
||||
|
||||
context->contrast =
|
||||
gtk_spin_button_get_value (GTK_SPIN_BUTTON (context->spinner));
|
||||
contrast_create_lookup_table (context);
|
||||
contrast = CDISPLAY_CONTRAST (display);
|
||||
|
||||
#if 0
|
||||
dialog_unregister (context->shell);
|
||||
#endif
|
||||
gtk_widget_destroy (GTK_WIDGET (context->shell));
|
||||
context->shell = NULL;
|
||||
|
||||
if (context->ok_func)
|
||||
context->ok_func (context, context->ok_data);
|
||||
}
|
||||
|
||||
static void
|
||||
contrast_configure_cancel_callback (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
ContrastContext *context = data;
|
||||
|
||||
#if 0
|
||||
dialog_unregister (context->shell);
|
||||
#endif
|
||||
gtk_widget_destroy (GTK_WIDGET (context->shell));
|
||||
context->shell = NULL;
|
||||
|
||||
if (context->cancel_func)
|
||||
context->cancel_func (context, context->cancel_data);
|
||||
}
|
||||
|
||||
static void
|
||||
contrast_configure (gpointer cd_ID,
|
||||
GFunc ok_func,
|
||||
gpointer ok_data,
|
||||
GFunc cancel_func,
|
||||
gpointer cancel_data)
|
||||
{
|
||||
ContrastContext *context = cd_ID;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *label;
|
||||
GtkObject *adjustment;
|
||||
|
||||
if (!context->shell)
|
||||
if (!contrast->shell)
|
||||
{
|
||||
context->ok_func = ok_func;
|
||||
context->ok_data = ok_data;
|
||||
context->cancel_func = cancel_func;
|
||||
context->cancel_data = cancel_data;
|
||||
contrast->ok_func = ok_func;
|
||||
contrast->ok_data = ok_data;
|
||||
contrast->cancel_func = cancel_func;
|
||||
contrast->cancel_data = cancel_data;
|
||||
|
||||
context->shell =
|
||||
gimp_dialog_new (_("High Contrast"), "high contrast",
|
||||
contrast->shell =
|
||||
gimp_dialog_new (_("High Contrast"), "high_contrast",
|
||||
gimp_standard_help_func, "modules/highcontrast.html",
|
||||
GTK_WIN_POS_MOUSE,
|
||||
FALSE, TRUE, FALSE,
|
||||
|
||||
GTK_STOCK_CANCEL, contrast_configure_cancel_callback,
|
||||
cd_ID, NULL, NULL, FALSE, TRUE,
|
||||
contrast, NULL, NULL, FALSE, TRUE,
|
||||
|
||||
GTK_STOCK_OK, contrast_configure_ok_callback,
|
||||
cd_ID, NULL, NULL, TRUE, FALSE,
|
||||
contrast, NULL, NULL, TRUE, FALSE,
|
||||
|
||||
NULL);
|
||||
|
||||
#if 0
|
||||
dialog_register (context->shell);
|
||||
#endif
|
||||
|
||||
hbox = gtk_hbox_new (FALSE, 2);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
|
||||
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (context->shell)->vbox),
|
||||
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (contrast->shell)->vbox),
|
||||
hbox, FALSE, FALSE, 0);
|
||||
|
||||
label = gtk_label_new ( _("Contrast Cycles:"));
|
||||
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
|
||||
|
||||
adjustment = gtk_adjustment_new (context->contrast, 1.0, 20.0, 0.5, 1.0, 0.0);
|
||||
context->spinner = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment),
|
||||
adjustment = gtk_adjustment_new (contrast->contrast, 0.01, 10.0, 0.01, 0.1, 0.0);
|
||||
contrast->spinner = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment),
|
||||
0.1, 3);
|
||||
gtk_widget_set_size_request (context->spinner, 100, -1);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), context->spinner, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), contrast->spinner, FALSE, FALSE, 0);
|
||||
}
|
||||
|
||||
gtk_widget_show_all (context->shell);
|
||||
gtk_widget_show_all (contrast->shell);
|
||||
}
|
||||
|
||||
static void
|
||||
contrast_configure_cancel (gpointer cd_ID)
|
||||
cdisplay_contrast_configure_cancel (GimpColorDisplay *display)
|
||||
{
|
||||
ContrastContext *context = cd_ID;
|
||||
CdisplayContrast *contrast;
|
||||
|
||||
if (context->shell)
|
||||
contrast = CDISPLAY_CONTRAST (display);
|
||||
|
||||
if (contrast->shell)
|
||||
{
|
||||
#if 0
|
||||
dialog_unregister (context->shell);
|
||||
#endif
|
||||
gtk_widget_destroy (context->shell);
|
||||
context->shell = NULL;
|
||||
gtk_widget_destroy (contrast->shell);
|
||||
contrast->shell = NULL;
|
||||
}
|
||||
|
||||
if (context->cancel_func)
|
||||
context->cancel_func (context, context->cancel_data);
|
||||
if (contrast->cancel_func)
|
||||
contrast->cancel_func (contrast, contrast->cancel_data);
|
||||
}
|
||||
|
||||
static void
|
||||
contrast_create_lookup_table (CdisplayContrast *contrast)
|
||||
{
|
||||
gint i;
|
||||
|
||||
if (contrast->contrast == 0.0)
|
||||
contrast->contrast = 1.0;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
contrast->lookup[i] = (guchar) (gint)
|
||||
(255 * .5 * (1 + sin (contrast->contrast * 2 * G_PI * i / 255.0)));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
contrast_configure_ok_callback (GtkWidget *widget,
|
||||
CdisplayContrast *contrast)
|
||||
{
|
||||
contrast->contrast =
|
||||
gtk_spin_button_get_value (GTK_SPIN_BUTTON (contrast->spinner));
|
||||
|
||||
contrast_create_lookup_table (contrast);
|
||||
|
||||
gtk_widget_destroy (GTK_WIDGET (contrast->shell));
|
||||
contrast->shell = NULL;
|
||||
|
||||
if (contrast->ok_func)
|
||||
contrast->ok_func (contrast, contrast->ok_data);
|
||||
}
|
||||
|
||||
static void
|
||||
contrast_configure_cancel_callback (GtkWidget *widget,
|
||||
CdisplayContrast *contrast)
|
||||
{
|
||||
gimp_color_display_configure_cancel (GIMP_COLOR_DISPLAY (contrast));
|
||||
}
|
||||
|
@ -22,65 +22,92 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __GNUC__
|
||||
#warning GTK_DISABLE_DEPRECATED
|
||||
#endif
|
||||
#undef GTK_DISABLE_DEPRECATED
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#include "libgimpcolor/gimpcolor.h"
|
||||
#include "libgimpmath/gimpmath.h"
|
||||
#include "libgimpwidgets/gimpwidgets.h"
|
||||
|
||||
#include "gimpmodregister.h"
|
||||
|
||||
#include "libgimp/gimpcolorselector.h"
|
||||
#include "libgimp/gimpmodule.h"
|
||||
|
||||
#include "libgimp/gimpintl.h"
|
||||
|
||||
|
||||
/* prototypes */
|
||||
static GtkWidget * colorsel_triangle_new (const GimpHSV *hsv,
|
||||
const GimpRGB *rgb,
|
||||
gboolean show_alpha,
|
||||
GimpColorSelectorCallback callback,
|
||||
gpointer callback_data,
|
||||
gpointer *selector_data);
|
||||
|
||||
static void colorsel_triangle_free (gpointer selector_data);
|
||||
|
||||
static void colorsel_triangle_set_color (gpointer selector_data,
|
||||
const GimpHSV *hsv,
|
||||
const GimpRGB *rgb);
|
||||
static void colorsel_xy_to_triangle_buf (const gint x,
|
||||
const gint y,
|
||||
const gdouble hue,
|
||||
guchar *buf,
|
||||
const gint sx,
|
||||
const gint sy,
|
||||
const gint vx,
|
||||
const gint vy,
|
||||
const gint hx,
|
||||
const gint hy);
|
||||
#define COLORWHEELRADIUS (GIMP_COLOR_SELECTOR_SIZE / 2)
|
||||
#define COLORTRIANGLERADIUS (COLORWHEELRADIUS - GIMP_COLOR_SELECTOR_BAR_SIZE)
|
||||
#define PREVIEWSIZE (2 * COLORWHEELRADIUS + 1)
|
||||
#define BGCOLOR 180
|
||||
#define PREVIEW_MASK (GDK_EXPOSURE_MASK | \
|
||||
GDK_BUTTON_PRESS_MASK | \
|
||||
GDK_BUTTON_RELEASE_MASK | \
|
||||
GDK_BUTTON_MOTION_MASK )
|
||||
|
||||
|
||||
/* local methods */
|
||||
static GimpColorSelectorMethods methods =
|
||||
#define COLORSEL_TYPE_TRIANGLE (colorsel_triangle_type)
|
||||
#define COLORSEL_TRIANGLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COLORSEL_TYPE_TRIANGLE, ColorselTriangle))
|
||||
#define COLORSEL_TRIANGLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COLORSEL_TYPE_TRIANGLE, ColorselTriangleClass))
|
||||
#define COLORSEL_IS_TRIANGLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COLORSEL_TYPE_TRIANGLE))
|
||||
#define COLORSEL_IS_TRIANGLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COLORSEL_TYPE_TRIANGLE))
|
||||
|
||||
|
||||
typedef struct _ColorselTriangle ColorselTriangle;
|
||||
typedef struct _ColorselTriangleClass ColorselTriangleClass;
|
||||
|
||||
struct _ColorselTriangle
|
||||
{
|
||||
colorsel_triangle_new,
|
||||
colorsel_triangle_free,
|
||||
colorsel_triangle_set_color,
|
||||
NULL /* set_channel */
|
||||
GimpColorSelector parent_instance;
|
||||
|
||||
GimpHSV hsv;
|
||||
GimpRGB rgb;
|
||||
|
||||
gdouble oldsat;
|
||||
gdouble oldval;
|
||||
gint mode;
|
||||
GtkWidget *preview;
|
||||
};
|
||||
|
||||
struct _ColorselTriangleClass
|
||||
{
|
||||
GimpColorSelectorClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
static GimpModuleInfo info =
|
||||
static GType colorsel_triangle_get_type (GTypeModule *module);
|
||||
static void colorsel_triangle_class_init (ColorselTriangleClass *klass);
|
||||
static void colorsel_triangle_init (ColorselTriangle *triangle);
|
||||
|
||||
static void colorsel_triangle_finalize (GObject *object);
|
||||
|
||||
static void colorsel_triangle_set_color (GimpColorSelector *selector,
|
||||
const GimpRGB *rgb,
|
||||
const GimpHSV *hsv);
|
||||
|
||||
static void colorsel_xy_to_triangle_buf (gint x,
|
||||
gint y,
|
||||
gdouble hue,
|
||||
guchar *buf,
|
||||
gint sx,
|
||||
gint sy,
|
||||
gint vx,
|
||||
gint vy,
|
||||
gint hx,
|
||||
gint hy);
|
||||
|
||||
static GtkWidget *colorsel_triangle_create_preview (ColorselTriangle *triangle);
|
||||
static void colorsel_triangle_update_previews (ColorselTriangle *triangle,
|
||||
gboolean hue_changed);
|
||||
static gboolean colorsel_triangle_event (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
ColorselTriangle *triangle);
|
||||
|
||||
|
||||
static GimpModuleInfo colorsel_triangle_info =
|
||||
{
|
||||
NULL,
|
||||
N_("Painter-style color selector as a pluggable color selector"),
|
||||
"Simon Budig <Simon.Budig@unix-ag.org>",
|
||||
"v0.03",
|
||||
@ -94,178 +121,163 @@ static const GtkTargetEntry targets[] =
|
||||
};
|
||||
|
||||
|
||||
#define COLORWHEELRADIUS (GIMP_COLOR_SELECTOR_SIZE / 2)
|
||||
#define COLORTRIANGLERADIUS (COLORWHEELRADIUS - GIMP_COLOR_SELECTOR_BAR_SIZE)
|
||||
#define PREVIEWSIZE (2 * COLORWHEELRADIUS + 1)
|
||||
static GType colorsel_triangle_type = 0;
|
||||
static GimpColorSelectorClass *parent_class = NULL;
|
||||
|
||||
#define BGCOLOR 180
|
||||
|
||||
#define PREVIEW_MASK GDK_EXPOSURE_MASK | \
|
||||
GDK_BUTTON_PRESS_MASK | \
|
||||
GDK_BUTTON_RELEASE_MASK | \
|
||||
GDK_BUTTON_MOTION_MASK
|
||||
|
||||
typedef enum
|
||||
G_MODULE_EXPORT gboolean
|
||||
gimp_module_register (GTypeModule *module,
|
||||
GimpModuleInfo **info_return)
|
||||
{
|
||||
HUE = 0,
|
||||
SATURATION,
|
||||
VALUE,
|
||||
RED,
|
||||
GREEN,
|
||||
BLUE,
|
||||
ALPHA
|
||||
} ColorSelectFillType;
|
||||
colorsel_triangle_get_type (module);
|
||||
|
||||
struct _ColorSelect
|
||||
{
|
||||
GimpHSV hsv;
|
||||
GimpRGB rgb;
|
||||
if (info_return)
|
||||
*info_return = &colorsel_triangle_info;
|
||||
|
||||
gdouble oldsat;
|
||||
gdouble oldval;
|
||||
gint mode;
|
||||
GtkWidget *preview;
|
||||
GimpColorSelectorCallback callback;
|
||||
gpointer data;
|
||||
};
|
||||
|
||||
typedef struct _ColorSelect ColorSelect;
|
||||
|
||||
|
||||
static GtkWidget * create_preview (ColorSelect *coldata);
|
||||
|
||||
static void update_previews (ColorSelect *coldata,
|
||||
gboolean hue_changed);
|
||||
|
||||
|
||||
/*************************************************************/
|
||||
|
||||
/* globaly exported init function */
|
||||
G_MODULE_EXPORT GimpModuleStatus
|
||||
module_init (GimpModuleInfo **inforet)
|
||||
{
|
||||
GimpColorSelectorID id;
|
||||
|
||||
#ifndef __EMX__
|
||||
id = gimp_color_selector_register (_("Triangle"), "triangle.html", &methods);
|
||||
#else
|
||||
id = mod_color_selector_register (_("Triangle"), "triangle.html", &methods);
|
||||
#endif
|
||||
|
||||
if (id)
|
||||
{
|
||||
info.shutdown_data = id;
|
||||
*inforet = &info;
|
||||
return GIMP_MODULE_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return GIMP_MODULE_UNLOAD;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT void
|
||||
module_unload (gpointer shutdown_data,
|
||||
GimpColorSelectorFinishedCB completed_cb,
|
||||
gpointer completed_data)
|
||||
static GType
|
||||
colorsel_triangle_get_type (GTypeModule *module)
|
||||
{
|
||||
#ifndef __EMX__
|
||||
gimp_color_selector_unregister (shutdown_data, completed_cb, completed_data);
|
||||
#else
|
||||
mod_color_selector_unregister (shutdown_data, completed_cb, completed_data);
|
||||
#endif
|
||||
if (! colorsel_triangle_type)
|
||||
{
|
||||
static const GTypeInfo select_info =
|
||||
{
|
||||
sizeof (ColorselTriangleClass),
|
||||
(GBaseInitFunc) NULL,
|
||||
(GBaseFinalizeFunc) NULL,
|
||||
(GClassInitFunc) colorsel_triangle_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (ColorselTriangle),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) colorsel_triangle_init,
|
||||
};
|
||||
|
||||
colorsel_triangle_type =
|
||||
g_type_module_register_type (module,
|
||||
GIMP_TYPE_COLOR_SELECTOR,
|
||||
"ColorselTriangle",
|
||||
&select_info, 0);
|
||||
}
|
||||
|
||||
return colorsel_triangle_type;
|
||||
}
|
||||
|
||||
/*************************************************************/
|
||||
/* methods */
|
||||
|
||||
static GtkWidget *
|
||||
colorsel_triangle_new (const GimpHSV *hsv,
|
||||
const GimpRGB *rgb,
|
||||
gboolean show_alpha,
|
||||
GimpColorSelectorCallback callback,
|
||||
gpointer callback_data,
|
||||
/* RETURNS: */
|
||||
gpointer *selector_data)
|
||||
static void
|
||||
colorsel_triangle_class_init (ColorselTriangleClass *klass)
|
||||
{
|
||||
ColorSelect *coldata;
|
||||
GtkWidget *preview;
|
||||
GtkWidget *frame;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *vbox;
|
||||
GObjectClass *object_class;
|
||||
GimpColorSelectorClass *selector_class;
|
||||
|
||||
coldata = g_new (ColorSelect, 1);
|
||||
object_class = G_OBJECT_CLASS (klass);
|
||||
selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
|
||||
|
||||
coldata->hsv = *hsv;
|
||||
coldata->rgb = *rgb;
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
coldata->oldsat = 0;
|
||||
coldata->oldval = 0;
|
||||
object_class->finalize = colorsel_triangle_finalize;
|
||||
|
||||
coldata->mode = 0;
|
||||
selector_class->name = _("Triangle");
|
||||
selector_class->help_page = "triangle.html";
|
||||
selector_class->set_color = colorsel_triangle_set_color;
|
||||
}
|
||||
|
||||
coldata->callback = callback;
|
||||
coldata->data = callback_data;
|
||||
static void
|
||||
colorsel_triangle_init (ColorselTriangle *triangle)
|
||||
{
|
||||
GtkWidget *frame;
|
||||
GtkWidget *hbox;
|
||||
|
||||
preview = create_preview (coldata);
|
||||
coldata->preview = preview;
|
||||
gimp_rgba_set (&triangle->rgb, 1.0, 1.0, 1.0, 1.0);
|
||||
gimp_rgb_to_hsv (&triangle->rgb, &triangle->hsv);
|
||||
|
||||
update_previews (coldata, TRUE);
|
||||
|
||||
*selector_data = coldata;
|
||||
|
||||
vbox = gtk_vbox_new (FALSE, 0);
|
||||
triangle->oldsat = 0;
|
||||
triangle->oldval = 0;
|
||||
triangle->mode = 0;
|
||||
|
||||
hbox = gtk_hbox_new (FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (triangle), hbox, TRUE, FALSE, 0);
|
||||
gtk_widget_show (hbox);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
||||
gtk_container_add (GTK_CONTAINER (frame), preview);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, FALSE, 0);
|
||||
gtk_widget_show_all (vbox);
|
||||
gtk_widget_show (frame);
|
||||
|
||||
return vbox;
|
||||
triangle->preview = colorsel_triangle_create_preview (triangle);
|
||||
gtk_container_add (GTK_CONTAINER (frame), triangle->preview);
|
||||
gtk_widget_show (triangle->preview);
|
||||
|
||||
colorsel_triangle_update_previews (triangle, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
colorsel_triangle_free (gpointer selector_data)
|
||||
colorsel_triangle_finalize (GObject *object)
|
||||
{
|
||||
/* anything else needed to go? */
|
||||
g_free (selector_data);
|
||||
ColorselTriangle *triangle;
|
||||
|
||||
triangle = COLORSEL_TRIANGLE (object);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
colorsel_triangle_set_color (gpointer selector_data,
|
||||
const GimpHSV *hsv,
|
||||
const GimpRGB *rgb)
|
||||
colorsel_triangle_set_color (GimpColorSelector *selector,
|
||||
const GimpRGB *rgb,
|
||||
const GimpHSV *hsv)
|
||||
{
|
||||
ColorSelect *coldata;
|
||||
ColorselTriangle *triangle;
|
||||
|
||||
coldata = selector_data;
|
||||
triangle = COLORSEL_TRIANGLE (selector);
|
||||
|
||||
coldata->hsv = *hsv;
|
||||
coldata->rgb = *rgb;
|
||||
triangle->rgb = *rgb;
|
||||
triangle->hsv = *hsv;
|
||||
|
||||
update_previews (coldata, TRUE);
|
||||
colorsel_triangle_update_previews (triangle, TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************/
|
||||
/* helper functions */
|
||||
|
||||
static void
|
||||
update_previews (ColorSelect *coldata,
|
||||
gint hue_changed)
|
||||
static GtkWidget *
|
||||
colorsel_triangle_create_preview (ColorselTriangle *triangle)
|
||||
{
|
||||
GtkWidget *preview;
|
||||
guchar buf[3 * PREVIEWSIZE];
|
||||
gint x, y, k, r2, dx, col;
|
||||
gint x0, y0;
|
||||
gdouble hue, sat, val, atn;
|
||||
gint hx,hy, sx,sy, vx,vy;
|
||||
gint i;
|
||||
|
||||
hue = (gdouble) coldata->hsv.h * 2 * G_PI;
|
||||
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||
gtk_preview_set_dither (GTK_PREVIEW (preview), GDK_RGB_DITHER_MAX);
|
||||
gtk_widget_set_events (GTK_WIDGET (preview), PREVIEW_MASK );
|
||||
gtk_preview_size (GTK_PREVIEW (preview), PREVIEWSIZE, PREVIEWSIZE);
|
||||
|
||||
g_signal_connect (G_OBJECT (preview), "motion_notify_event",
|
||||
G_CALLBACK (colorsel_triangle_event),
|
||||
triangle);
|
||||
g_signal_connect (G_OBJECT (preview), "button_press_event",
|
||||
G_CALLBACK (colorsel_triangle_event),
|
||||
triangle);
|
||||
g_signal_connect (G_OBJECT (preview), "button_release_event",
|
||||
G_CALLBACK (colorsel_triangle_event),
|
||||
triangle);
|
||||
|
||||
for (i=0; i < 3 * PREVIEWSIZE; i += 3)
|
||||
buf[i] = buf[i+1] = buf[i+2] = BGCOLOR;
|
||||
for (i=0; i < PREVIEWSIZE; i++)
|
||||
gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, PREVIEWSIZE);
|
||||
|
||||
return preview;
|
||||
}
|
||||
|
||||
static void
|
||||
colorsel_triangle_update_previews (ColorselTriangle *triangle,
|
||||
gboolean hue_changed)
|
||||
{
|
||||
guchar buf[3 * PREVIEWSIZE];
|
||||
gint x, y, k, r2, dx, col;
|
||||
gint x0, y0;
|
||||
gdouble hue, sat, val, atn;
|
||||
gint hx,hy, sx,sy, vx,vy;
|
||||
|
||||
hue = (gdouble) triangle->hsv.h * 2 * G_PI;
|
||||
|
||||
/* Colored point (value = 1, saturation = 1) */
|
||||
hx = RINT (sin (hue) * COLORTRIANGLERADIUS);
|
||||
@ -279,8 +291,7 @@ update_previews (ColorSelect *coldata,
|
||||
vx = RINT (sin (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS);
|
||||
vy = RINT (cos (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS);
|
||||
|
||||
hue = coldata->hsv.h * 360.0;
|
||||
preview = coldata->preview;
|
||||
hue = triangle->hsv.h * 360.0;
|
||||
|
||||
if (hue_changed)
|
||||
{
|
||||
@ -310,7 +321,7 @@ update_previews (ColorSelect *coldata,
|
||||
k += 3;
|
||||
}
|
||||
|
||||
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
|
||||
gtk_preview_draw_row (GTK_PREVIEW (triangle->preview), buf,
|
||||
COLORWHEELRADIUS - dx,
|
||||
COLORWHEELRADIUS - y, 2 * dx + 1);
|
||||
}
|
||||
@ -352,7 +363,7 @@ update_previews (ColorSelect *coldata,
|
||||
k += 3;
|
||||
}
|
||||
|
||||
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
|
||||
gtk_preview_draw_row (GTK_PREVIEW (triangle->preview), buf,
|
||||
COLORWHEELRADIUS + x0 - 4,
|
||||
COLORWHEELRADIUS - y, 9);
|
||||
}
|
||||
@ -361,8 +372,8 @@ update_previews (ColorSelect *coldata,
|
||||
{
|
||||
/* delete marker in triangle */
|
||||
|
||||
sat = coldata->oldsat;
|
||||
val = coldata->oldval;
|
||||
sat = triangle->oldsat;
|
||||
val = triangle->oldval;
|
||||
x0 = RINT (sx + (vx - sx) * val + (hx - vx) * sat * val);
|
||||
y0 = RINT (sy + (vy - sy) * val + (hy - vy) * sat * val);
|
||||
|
||||
@ -388,7 +399,7 @@ update_previews (ColorSelect *coldata,
|
||||
k += 3;
|
||||
}
|
||||
|
||||
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
|
||||
gtk_preview_draw_row (GTK_PREVIEW (triangle->preview), buf,
|
||||
COLORWHEELRADIUS + x0 - 4,
|
||||
COLORWHEELRADIUS - y, 9);
|
||||
}
|
||||
@ -396,10 +407,10 @@ update_previews (ColorSelect *coldata,
|
||||
|
||||
/* marker in triangle */
|
||||
|
||||
col = gimp_rgb_intensity (&coldata->rgb) > 0.5 ? 0 : 255;
|
||||
col = gimp_rgb_intensity (&triangle->rgb) > 0.5 ? 0 : 255;
|
||||
|
||||
sat = coldata->oldsat = coldata->hsv.s;
|
||||
val = coldata->oldval = coldata->hsv.v;
|
||||
sat = triangle->oldsat = triangle->hsv.s;
|
||||
val = triangle->oldval = triangle->hsv.v;
|
||||
|
||||
x0 = RINT (sx + (vx - sx) * val + (hx - vx) * sat * val);
|
||||
y0 = RINT (sy + (vy - sy) * val + (hy - vy) * sat * val);
|
||||
@ -433,20 +444,25 @@ update_previews (ColorSelect *coldata,
|
||||
k += 3;
|
||||
}
|
||||
|
||||
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
|
||||
gtk_preview_draw_row (GTK_PREVIEW (triangle->preview), buf,
|
||||
COLORWHEELRADIUS + x0 - 4,
|
||||
COLORWHEELRADIUS - y, 9);
|
||||
}
|
||||
|
||||
gtk_widget_draw (preview, NULL);
|
||||
gtk_widget_queue_draw (triangle->preview);
|
||||
}
|
||||
|
||||
static void
|
||||
colorsel_xy_to_triangle_buf (const gint x, const gint y,
|
||||
const gdouble hue, guchar *buf,
|
||||
const gint hx, const gint hy, /* colored point */
|
||||
const gint sx, const gint sy, /* black point */
|
||||
const gint vx, const gint vy) /* white point */
|
||||
colorsel_xy_to_triangle_buf (gint x,
|
||||
gint y,
|
||||
gdouble hue,
|
||||
guchar *buf,
|
||||
gint hx,
|
||||
gint hy, /* colored point */
|
||||
gint sx,
|
||||
gint sy, /* black point */
|
||||
gint vx,
|
||||
gint vy) /* white point */
|
||||
{
|
||||
gdouble sat, val;
|
||||
|
||||
@ -476,21 +492,15 @@ colorsel_xy_to_triangle_buf (const gint x, const gint y,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Color Preview
|
||||
*/
|
||||
|
||||
static gint
|
||||
color_selection_callback (GtkWidget *widget,
|
||||
GdkEvent *event)
|
||||
static gboolean
|
||||
colorsel_triangle_event (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
ColorselTriangle *triangle)
|
||||
{
|
||||
ColorSelect *coldata;
|
||||
gint x,y, angle, mousex, mousey;
|
||||
gdouble r;
|
||||
gdouble hue, sat, val;
|
||||
gint hx,hy, sx,sy, vx,vy;
|
||||
|
||||
coldata = g_object_get_data (G_OBJECT (widget), "colorselect");
|
||||
gint x,y, angle, mousex, mousey;
|
||||
gdouble r;
|
||||
gdouble hue, sat, val;
|
||||
gint hx,hy, sx,sy, vx,vy;
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
@ -501,9 +511,9 @@ color_selection_callback (GtkWidget *widget,
|
||||
r = sqrt ((gdouble) (x * x + y * y));
|
||||
angle = ((gint) RINT (atan2 (x, y) / G_PI * 180) + 360 ) % 360;
|
||||
if ( /* r <= COLORWHEELRADIUS && */ r > COLORTRIANGLERADIUS)
|
||||
coldata->mode = 1; /* Dragging in the Ring */
|
||||
triangle->mode = 1; /* Dragging in the Ring */
|
||||
else
|
||||
coldata->mode = 2; /* Dragging in the Triangle */
|
||||
triangle->mode = 2; /* Dragging in the Triangle */
|
||||
break;
|
||||
|
||||
case GDK_MOTION_NOTIFY:
|
||||
@ -514,13 +524,13 @@ color_selection_callback (GtkWidget *widget,
|
||||
break;
|
||||
|
||||
case GDK_BUTTON_RELEASE:
|
||||
coldata->mode = 0;
|
||||
triangle->mode = 0;
|
||||
gtk_grab_remove (widget);
|
||||
|
||||
/* callback the user */
|
||||
(* coldata->callback) (coldata->data,
|
||||
&coldata->hsv,
|
||||
&coldata->rgb);
|
||||
gimp_color_selector_color_changed (GIMP_COLOR_SELECTOR (triangle),
|
||||
&triangle->rgb,
|
||||
&triangle->hsv);
|
||||
|
||||
return FALSE;
|
||||
break;
|
||||
@ -539,25 +549,25 @@ color_selection_callback (GtkWidget *widget,
|
||||
(mousex != event->motion.x || mousey != event->motion.y)))
|
||||
return FALSE;
|
||||
|
||||
if (coldata->mode == 1 ||
|
||||
if (triangle->mode == 1 ||
|
||||
(r > COLORWHEELRADIUS &&
|
||||
(abs (angle - coldata->hsv.h * 360.0) < 30 ||
|
||||
abs (abs (angle - coldata->hsv.h * 360.0) - 360) < 30)))
|
||||
(abs (angle - triangle->hsv.h * 360.0) < 30 ||
|
||||
abs (abs (angle - triangle->hsv.h * 360.0) - 360) < 30)))
|
||||
{
|
||||
coldata->hsv.h = angle / 360.0;
|
||||
gimp_hsv_to_rgb (&coldata->hsv, &coldata->rgb);
|
||||
update_previews (coldata, TRUE);
|
||||
triangle->hsv.h = angle / 360.0;
|
||||
gimp_hsv_to_rgb (&triangle->hsv, &triangle->rgb);
|
||||
colorsel_triangle_update_previews (triangle, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
hue = coldata->hsv.h * 2 * G_PI;
|
||||
hue = triangle->hsv.h * 2 * G_PI;
|
||||
hx = sin (hue) * COLORTRIANGLERADIUS;
|
||||
hy = cos (hue) * COLORTRIANGLERADIUS;
|
||||
sx = sin (hue - 2 * G_PI / 3) * COLORTRIANGLERADIUS;
|
||||
sy = cos (hue - 2 * G_PI / 3) * COLORTRIANGLERADIUS;
|
||||
vx = sin (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS;
|
||||
vy = cos (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS;
|
||||
hue = coldata->hsv.h * 360.0;
|
||||
hue = triangle->hsv.h * 360.0;
|
||||
|
||||
if ((x - sx) * vx + (y - sy) * vy < 0)
|
||||
{
|
||||
@ -613,50 +623,16 @@ color_selection_callback (GtkWidget *widget,
|
||||
}
|
||||
}
|
||||
|
||||
coldata->hsv.s = sat;
|
||||
coldata->hsv.v = val;
|
||||
gimp_hsv_to_rgb (&coldata->hsv, &coldata->rgb);
|
||||
update_previews (coldata, FALSE);
|
||||
triangle->hsv.s = sat;
|
||||
triangle->hsv.v = val;
|
||||
gimp_hsv_to_rgb (&triangle->hsv, &triangle->rgb);
|
||||
colorsel_triangle_update_previews (triangle, FALSE);
|
||||
}
|
||||
|
||||
/* callback the user */
|
||||
(* coldata->callback) (coldata->data,
|
||||
&coldata->hsv,
|
||||
&coldata->rgb);
|
||||
gimp_color_selector_color_changed (GIMP_COLOR_SELECTOR (triangle),
|
||||
&triangle->rgb,
|
||||
&triangle->hsv);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
create_preview (ColorSelect *coldata)
|
||||
{
|
||||
GtkWidget *preview;
|
||||
guchar buf[3 * PREVIEWSIZE];
|
||||
gint i;
|
||||
|
||||
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||
gtk_preview_set_dither (GTK_PREVIEW (preview), GDK_RGB_DITHER_MAX);
|
||||
gtk_widget_set_events (GTK_WIDGET (preview), PREVIEW_MASK );
|
||||
gtk_preview_size (GTK_PREVIEW (preview), PREVIEWSIZE, PREVIEWSIZE);
|
||||
|
||||
g_object_set_data (G_OBJECT (preview), "colorselect", coldata);
|
||||
|
||||
g_signal_connect (G_OBJECT (preview), "motion_notify_event",
|
||||
G_CALLBACK (color_selection_callback),
|
||||
NULL);
|
||||
g_signal_connect (G_OBJECT (preview), "button_press_event",
|
||||
G_CALLBACK (color_selection_callback),
|
||||
NULL);
|
||||
g_signal_connect (G_OBJECT (preview), "button_release_event",
|
||||
G_CALLBACK (color_selection_callback),
|
||||
NULL);
|
||||
|
||||
for (i=0; i < 3 * PREVIEWSIZE; i += 3)
|
||||
buf[i] = buf[i+1] = buf[i+2] = BGCOLOR;
|
||||
for (i=0; i < PREVIEWSIZE; i++)
|
||||
gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, PREVIEWSIZE);
|
||||
|
||||
gtk_widget_draw (preview, NULL);
|
||||
|
||||
return preview;
|
||||
}
|
||||
|
@ -22,19 +22,19 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __GNUC__
|
||||
#warning GTK_DISABLE_DEPRECATED
|
||||
#endif
|
||||
#undef GTK_DISABLE_DEPRECATED
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "libgimpcolor/gimpcolor.h"
|
||||
#include "libgimpmath/gimpmath.h"
|
||||
#include "libgimpwidgets/gimpwidgets.h"
|
||||
|
||||
#include "libgimp/gimpuitypes.h"
|
||||
|
||||
#include "libgimp/gimpcolorselector.h"
|
||||
#include "libgimp/gimpmodule.h"
|
||||
|
||||
#include "gimpmodregister.h"
|
||||
|
||||
#include "libgimp/gimpintl.h"
|
||||
|
||||
|
||||
@ -42,49 +42,69 @@
|
||||
|
||||
#define IMAGE_SIZE GIMP_COLOR_SELECTOR_SIZE
|
||||
|
||||
typedef struct
|
||||
|
||||
#define COLORSEL_TYPE_WATER (colorsel_water_type)
|
||||
#define COLORSEL_WATER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COLORSEL_TYPE_WATER, ColorselWater))
|
||||
#define COLORSEL_WATER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COLORSEL_TYPE_WATER, ColorselWaterClass))
|
||||
#define COLORSEL_IS_WATER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COLORSEL_TYPE_WATER))
|
||||
#define COLORSEL_IS_WATER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COLORSEL_TYPE_WATER))
|
||||
|
||||
|
||||
typedef struct _ColorselWater ColorselWater;
|
||||
typedef struct _ColorselWaterClass ColorselWaterClass;
|
||||
|
||||
struct _ColorselWater
|
||||
{
|
||||
GimpRGB rgb;
|
||||
gdouble last_x;
|
||||
gdouble last_y;
|
||||
gdouble last_pressure;
|
||||
GimpColorSelector parent_instance;
|
||||
|
||||
gfloat pressure_adjust;
|
||||
guint32 motion_time;
|
||||
gint button_state;
|
||||
GimpRGB rgb;
|
||||
|
||||
GimpColorSelectorCallback callback;
|
||||
gpointer data;
|
||||
} ColorselWater;
|
||||
gdouble last_x;
|
||||
gdouble last_y;
|
||||
gdouble last_pressure;
|
||||
|
||||
gfloat pressure_adjust;
|
||||
guint32 motion_time;
|
||||
gint button_state;
|
||||
};
|
||||
|
||||
/* prototypes */
|
||||
static GtkWidget * colorsel_water_new (const GimpHSV *hsv,
|
||||
const GimpRGB *rgb,
|
||||
gboolean show_alpha,
|
||||
GimpColorSelectorCallback,
|
||||
gpointer ,
|
||||
gpointer *);
|
||||
static void colorsel_water_free (gpointer data);
|
||||
static void colorsel_water_set_color (gpointer data,
|
||||
const GimpHSV *hsv,
|
||||
const GimpRGB *rgb);
|
||||
static void colorsel_water_update (ColorselWater *colorsel);
|
||||
|
||||
|
||||
/* local methods */
|
||||
static GimpColorSelectorMethods methods =
|
||||
struct _ColorselWaterClass
|
||||
{
|
||||
colorsel_water_new,
|
||||
colorsel_water_free,
|
||||
colorsel_water_set_color,
|
||||
NULL /* set_channel */
|
||||
GimpColorSelectorClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
static GimpModuleInfo info =
|
||||
static GType colorsel_water_get_type (GTypeModule *module);
|
||||
static void colorsel_water_class_init (ColorselWaterClass *klass);
|
||||
static void colorsel_water_init (ColorselWater *water);
|
||||
|
||||
static void colorsel_water_finalize (GObject *object);
|
||||
|
||||
static void colorsel_water_set_color (GimpColorSelector *selector,
|
||||
const GimpRGB *rgb,
|
||||
const GimpHSV *hsv);
|
||||
|
||||
static void colorsel_water_update (ColorselWater *water);
|
||||
|
||||
static void select_area_draw (GtkWidget *preview);
|
||||
static gboolean button_press_event (GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
ColorselWater *water);
|
||||
static gboolean button_release_event (GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
ColorselWater *water);
|
||||
static gboolean motion_notify_event (GtkWidget *widget,
|
||||
GdkEventMotion *event,
|
||||
ColorselWater *water);
|
||||
static gboolean proximity_out_event (GtkWidget *widget,
|
||||
GdkEventProximity *event,
|
||||
ColorselWater *water);
|
||||
static void pressure_adjust_update (GtkAdjustment *adj,
|
||||
ColorselWater *water);
|
||||
|
||||
|
||||
static GimpModuleInfo colorsel_water_info =
|
||||
{
|
||||
NULL,
|
||||
N_("Watercolor style color selector as a pluggable module"),
|
||||
"Raph Levien <raph@acm.org>, Sven Neumann <sven@gimp.org>",
|
||||
"v0.3",
|
||||
@ -92,52 +112,196 @@ static GimpModuleInfo info =
|
||||
"May, 10 1999"
|
||||
};
|
||||
|
||||
|
||||
static const GtkTargetEntry targets[] =
|
||||
{
|
||||
{ "application/x-color", 0 }
|
||||
};
|
||||
|
||||
/*************************************************************/
|
||||
|
||||
/* globaly exported init function */
|
||||
G_MODULE_EXPORT GimpModuleStatus
|
||||
module_init (GimpModuleInfo **inforet)
|
||||
static GType colorsel_water_type = 0;
|
||||
static GimpColorSelectorClass *parent_class = NULL;
|
||||
|
||||
|
||||
G_MODULE_EXPORT gboolean
|
||||
gimp_module_register (GTypeModule *module,
|
||||
GimpModuleInfo **info_return)
|
||||
{
|
||||
GimpColorSelectorID id;
|
||||
colorsel_water_get_type (module);
|
||||
|
||||
#ifndef __EMX__
|
||||
id = gimp_color_selector_register (_("Watercolor"), "watercolor.html",
|
||||
&methods);
|
||||
#else
|
||||
id = mod_color_selector_register (_("Watercolor"), "watercolor.html",
|
||||
&methods);
|
||||
#endif
|
||||
if (info_return)
|
||||
*info_return = &colorsel_water_info;
|
||||
|
||||
if (id)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GType
|
||||
colorsel_water_get_type (GTypeModule *module)
|
||||
{
|
||||
if (! colorsel_water_type)
|
||||
{
|
||||
info.shutdown_data = id;
|
||||
*inforet = &info;
|
||||
return GIMP_MODULE_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return GIMP_MODULE_UNLOAD;
|
||||
static const GTypeInfo select_info =
|
||||
{
|
||||
sizeof (ColorselWaterClass),
|
||||
(GBaseInitFunc) NULL,
|
||||
(GBaseFinalizeFunc) NULL,
|
||||
(GClassInitFunc) colorsel_water_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (ColorselWater),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) colorsel_water_init,
|
||||
};
|
||||
|
||||
colorsel_water_type =
|
||||
g_type_module_register_type (module,
|
||||
GIMP_TYPE_COLOR_SELECTOR,
|
||||
"ColorselWater",
|
||||
&select_info, 0);
|
||||
}
|
||||
|
||||
return colorsel_water_type;
|
||||
}
|
||||
|
||||
static void
|
||||
colorsel_water_class_init (ColorselWaterClass *klass)
|
||||
{
|
||||
GObjectClass *object_class;
|
||||
GimpColorSelectorClass *selector_class;
|
||||
|
||||
object_class = G_OBJECT_CLASS (klass);
|
||||
selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
object_class->finalize = colorsel_water_finalize;
|
||||
|
||||
selector_class->name = _("Watercolor");
|
||||
selector_class->help_page = "watercolor.html";
|
||||
selector_class->set_color = colorsel_water_set_color;
|
||||
}
|
||||
|
||||
static void
|
||||
colorsel_water_init (ColorselWater *water)
|
||||
{
|
||||
GtkWidget *preview;
|
||||
GtkWidget *event_box;
|
||||
GtkWidget *frame;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *hbox2;
|
||||
GtkObject *adj;
|
||||
GtkWidget *scale;
|
||||
|
||||
water->pressure_adjust = 1.0;
|
||||
|
||||
hbox = gtk_hbox_new (FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (water), hbox, TRUE, FALSE, 0);
|
||||
|
||||
hbox2 = gtk_hbox_new (FALSE, 4);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), hbox2, TRUE, FALSE, 0);
|
||||
|
||||
/* the event box */
|
||||
frame = gtk_frame_new (NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
||||
gtk_box_pack_start (GTK_BOX (hbox2), frame, FALSE, FALSE, 0);
|
||||
|
||||
event_box = gtk_event_box_new ();
|
||||
gtk_container_add (GTK_CONTAINER (frame), event_box);
|
||||
|
||||
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||
gtk_preview_size (GTK_PREVIEW (preview), IMAGE_SIZE, IMAGE_SIZE);
|
||||
gtk_container_add (GTK_CONTAINER (event_box), preview);
|
||||
select_area_draw (preview);
|
||||
|
||||
/* Event signals */
|
||||
g_signal_connect (G_OBJECT (event_box), "motion_notify_event",
|
||||
G_CALLBACK (motion_notify_event),
|
||||
water);
|
||||
g_signal_connect (G_OBJECT (event_box), "button_press_event",
|
||||
G_CALLBACK (button_press_event),
|
||||
water);
|
||||
g_signal_connect (G_OBJECT (event_box), "button_release_event",
|
||||
G_CALLBACK (button_release_event),
|
||||
water);
|
||||
g_signal_connect (G_OBJECT (event_box), "proximity_out_event",
|
||||
G_CALLBACK (proximity_out_event),
|
||||
water);
|
||||
|
||||
gtk_widget_set_events (event_box,
|
||||
GDK_EXPOSURE_MASK |
|
||||
GDK_LEAVE_NOTIFY_MASK |
|
||||
GDK_BUTTON_PRESS_MASK |
|
||||
GDK_KEY_PRESS_MASK |
|
||||
GDK_POINTER_MOTION_MASK |
|
||||
GDK_POINTER_MOTION_HINT_MASK |
|
||||
GDK_PROXIMITY_OUT_MASK);
|
||||
|
||||
/* The following call enables tracking and processing of extension
|
||||
* events for the drawing area
|
||||
*/
|
||||
gtk_widget_set_extension_events (event_box, GDK_EXTENSION_EVENTS_ALL);
|
||||
gtk_widget_grab_focus (event_box);
|
||||
|
||||
adj = gtk_adjustment_new (200.0 - water->pressure_adjust * 100.0,
|
||||
0.0, 200.0, 1.0, 1.0, 0.0);
|
||||
g_signal_connect (G_OBJECT (adj), "value_changed",
|
||||
G_CALLBACK (pressure_adjust_update),
|
||||
water);
|
||||
scale = gtk_vscale_new (GTK_ADJUSTMENT (adj));
|
||||
gtk_scale_set_digits (GTK_SCALE (scale), 0);
|
||||
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
|
||||
gimp_help_set_help_data (scale, _("Pressure"), NULL);
|
||||
gtk_box_pack_start (GTK_BOX (hbox2), scale, FALSE, FALSE, 0);
|
||||
|
||||
gtk_widget_show_all (hbox);
|
||||
}
|
||||
|
||||
static void
|
||||
colorsel_water_finalize (GObject *object)
|
||||
{
|
||||
ColorselWater *water;
|
||||
|
||||
water = COLORSEL_WATER (object);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
colorsel_water_set_color (GimpColorSelector *selector,
|
||||
const GimpRGB *rgb,
|
||||
const GimpHSV *hsv)
|
||||
{
|
||||
ColorselWater *water;
|
||||
|
||||
water = COLORSEL_WATER (selector);
|
||||
|
||||
water->rgb = *rgb;
|
||||
}
|
||||
|
||||
static void
|
||||
colorsel_water_update (ColorselWater *water)
|
||||
{
|
||||
GimpHSV hsv;
|
||||
|
||||
gimp_rgb_to_hsv (&water->rgb, &hsv);
|
||||
|
||||
gimp_color_selector_color_changed (GIMP_COLOR_SELECTOR (water),
|
||||
&water->rgb, &hsv);
|
||||
}
|
||||
|
||||
|
||||
G_MODULE_EXPORT void
|
||||
module_unload (gpointer shutdown_data,
|
||||
GimpColorSelectorFinishedCB completed_cb,
|
||||
gpointer completed_data)
|
||||
{
|
||||
#ifndef __EMX__
|
||||
gimp_color_selector_unregister (shutdown_data, completed_cb, completed_data);
|
||||
#else
|
||||
mod_color_selector_unregister (shutdown_data, completed_cb, completed_data);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static gdouble
|
||||
@ -250,260 +414,121 @@ draw_brush (ColorselWater *colorsel,
|
||||
|
||||
add_pigment (colorsel, erase, x, y, much);
|
||||
|
||||
colorsel->last_x = x;
|
||||
colorsel->last_y = y;
|
||||
colorsel->last_x = x;
|
||||
colorsel->last_y = y;
|
||||
colorsel->last_pressure = pressure;
|
||||
}
|
||||
|
||||
static gint
|
||||
static gboolean
|
||||
button_press_event (GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
gpointer data)
|
||||
ColorselWater *water)
|
||||
{
|
||||
ColorselWater *colorsel;
|
||||
gboolean erase;
|
||||
gboolean erase = FALSE;
|
||||
|
||||
colorsel = (ColorselWater *) data;
|
||||
water->last_x = event->x;
|
||||
water->last_y = event->y;
|
||||
water->last_pressure = 1.0; /* FIXME: event->pressure */
|
||||
|
||||
colorsel->last_x = event->x;
|
||||
colorsel->last_y = event->y;
|
||||
colorsel->last_pressure = event->pressure;
|
||||
water->button_state |= 1 << event->button;
|
||||
|
||||
colorsel->button_state |= 1 << event->button;
|
||||
erase = (event->button != 1) || FALSE;
|
||||
/* FIXME: (event->source == GDK_SOURCE_ERASER) */
|
||||
|
||||
erase = (event->button != 1) ||
|
||||
(event->source == GDK_SOURCE_ERASER);
|
||||
|
||||
add_pigment (colorsel, erase, event->x, event->y, 0.05);
|
||||
colorsel->motion_time = event->time;
|
||||
add_pigment (water, erase, event->x, event->y, 0.05);
|
||||
water->motion_time = event->time;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gint
|
||||
static gboolean
|
||||
button_release_event (GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
gpointer data)
|
||||
ColorselWater *water)
|
||||
{
|
||||
ColorselWater *colorsel;
|
||||
|
||||
colorsel = (ColorselWater *) data;
|
||||
|
||||
colorsel->button_state &= ~(1 << event->button);
|
||||
water->button_state &= ~(1 << event->button);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gint
|
||||
static gboolean
|
||||
motion_notify_event (GtkWidget *widget,
|
||||
GdkEventMotion *event,
|
||||
gpointer data)
|
||||
ColorselWater *water)
|
||||
{
|
||||
ColorselWater *colorsel;
|
||||
GdkTimeCoord *coords;
|
||||
GdkTimeCoord **coords;
|
||||
gint nevents;
|
||||
gint i;
|
||||
gboolean erase;
|
||||
|
||||
colorsel = (ColorselWater *) data;
|
||||
|
||||
if (event->state & (GDK_BUTTON1_MASK |
|
||||
GDK_BUTTON2_MASK |
|
||||
GDK_BUTTON3_MASK |
|
||||
GDK_BUTTON4_MASK))
|
||||
{
|
||||
coords = gdk_input_motion_events (event->window, event->deviceid,
|
||||
colorsel->motion_time, event->time,
|
||||
&nevents);
|
||||
erase = (event->state &
|
||||
(GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK)) ||
|
||||
(event->source == GDK_SOURCE_ERASER);
|
||||
guint32 last_motion_time;
|
||||
|
||||
colorsel->motion_time = event->time;
|
||||
last_motion_time = event->time;
|
||||
|
||||
if (coords)
|
||||
{
|
||||
for (i=0; i<nevents; i++)
|
||||
draw_brush (colorsel, widget,
|
||||
erase,
|
||||
coords[i].x,
|
||||
coords[i].y,
|
||||
coords[i].pressure);
|
||||
erase = ((event->state &
|
||||
(GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK)) ||
|
||||
FALSE);
|
||||
/* FIXME: (event->source == GDK_SOURCE_ERASER) */
|
||||
|
||||
water->motion_time = event->time;
|
||||
|
||||
if (gdk_device_get_history (event->device,
|
||||
event->window,
|
||||
last_motion_time,
|
||||
event->time,
|
||||
&coords,
|
||||
&nevents))
|
||||
{
|
||||
for (i = 0; i < nevents; i++)
|
||||
{
|
||||
gdouble x = 0.0;
|
||||
gdouble y = 0.0;
|
||||
gdouble pressure = 0.5;
|
||||
|
||||
gdk_device_get_axis (event->device, coords[i]->axes,
|
||||
GDK_AXIS_X, &x);
|
||||
gdk_device_get_axis (event->device, coords[i]->axes,
|
||||
GDK_AXIS_Y, &y);
|
||||
gdk_device_get_axis (event->device, coords[i]->axes,
|
||||
GDK_AXIS_PRESSURE, &pressure);
|
||||
|
||||
draw_brush (water, widget, erase, x, y, pressure);
|
||||
}
|
||||
|
||||
g_free (coords);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (event->is_hint)
|
||||
gdk_input_window_get_pointer (event->window, event->deviceid,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
gdouble pressure = 0.5;
|
||||
|
||||
draw_brush (colorsel, widget,
|
||||
erase,
|
||||
event->x,
|
||||
event->y,
|
||||
event->pressure);
|
||||
gdk_event_get_axis ((GdkEvent *) event, GDK_AXIS_PRESSURE, &pressure);
|
||||
|
||||
draw_brush (water, widget, erase, event->x, event->y, pressure);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gdk_input_window_get_pointer (event->window, event->deviceid,
|
||||
&event->x, &event->y,
|
||||
NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
if (event->is_hint)
|
||||
gdk_device_get_state (event->device, event->window, NULL, NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gint
|
||||
static gboolean
|
||||
proximity_out_event (GtkWidget *widget,
|
||||
GdkEventProximity *event,
|
||||
gpointer data)
|
||||
ColorselWater *water)
|
||||
{
|
||||
ColorselWater *colorsel;
|
||||
|
||||
colorsel = (ColorselWater *) data;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
pressure_adjust_update (GtkAdjustment *adj,
|
||||
gpointer data)
|
||||
ColorselWater *water)
|
||||
{
|
||||
ColorselWater *colorsel;
|
||||
|
||||
colorsel = (ColorselWater *) data;
|
||||
|
||||
colorsel->pressure_adjust = (adj->upper - adj->value) / 100.0;
|
||||
}
|
||||
|
||||
|
||||
/***********/
|
||||
/* methods */
|
||||
|
||||
|
||||
static GtkWidget*
|
||||
colorsel_water_new (const GimpHSV *hsv,
|
||||
const GimpRGB *rgb,
|
||||
gboolean show_alpha,
|
||||
GimpColorSelectorCallback callback,
|
||||
gpointer callback_data,
|
||||
/* RETURNS: */
|
||||
gpointer *selector_data)
|
||||
{
|
||||
ColorselWater *coldata;
|
||||
GtkWidget *preview;
|
||||
GtkWidget *event_box;
|
||||
GtkWidget *frame;
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *hbox2;
|
||||
GtkObject *adj;
|
||||
GtkWidget *scale;
|
||||
|
||||
coldata = g_new (ColorselWater, 1);
|
||||
|
||||
coldata->pressure_adjust = 1.0;
|
||||
|
||||
coldata->callback = callback;
|
||||
coldata->data = callback_data;
|
||||
|
||||
*selector_data = coldata;
|
||||
|
||||
vbox = gtk_vbox_new (FALSE, 0);
|
||||
|
||||
hbox = gtk_hbox_new (FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
|
||||
|
||||
hbox2 = gtk_hbox_new (FALSE, 4);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), hbox2, TRUE, FALSE, 0);
|
||||
|
||||
/* the event box */
|
||||
frame = gtk_frame_new (NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
||||
gtk_box_pack_start (GTK_BOX (hbox2), frame, FALSE, FALSE, 0);
|
||||
|
||||
event_box = gtk_event_box_new ();
|
||||
gtk_container_add (GTK_CONTAINER (frame), event_box);
|
||||
|
||||
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||
gtk_preview_size (GTK_PREVIEW (preview), IMAGE_SIZE, IMAGE_SIZE);
|
||||
gtk_container_add (GTK_CONTAINER (event_box), preview);
|
||||
select_area_draw (preview);
|
||||
|
||||
/* Event signals */
|
||||
g_signal_connect (G_OBJECT (event_box), "motion_notify_event",
|
||||
G_CALLBACK (motion_notify_event),
|
||||
coldata);
|
||||
g_signal_connect (G_OBJECT (event_box), "button_press_event",
|
||||
G_CALLBACK (button_press_event),
|
||||
coldata);
|
||||
g_signal_connect (G_OBJECT (event_box), "button_release_event",
|
||||
G_CALLBACK (button_release_event),
|
||||
coldata);
|
||||
g_signal_connect (G_OBJECT (event_box), "proximity_out_event",
|
||||
G_CALLBACK (proximity_out_event),
|
||||
coldata);
|
||||
|
||||
gtk_widget_set_events (event_box,
|
||||
GDK_EXPOSURE_MASK |
|
||||
GDK_LEAVE_NOTIFY_MASK |
|
||||
GDK_BUTTON_PRESS_MASK |
|
||||
GDK_KEY_PRESS_MASK |
|
||||
GDK_POINTER_MOTION_MASK |
|
||||
GDK_POINTER_MOTION_HINT_MASK |
|
||||
GDK_PROXIMITY_OUT_MASK);
|
||||
|
||||
/* The following call enables tracking and processing of extension
|
||||
* events for the drawing area
|
||||
*/
|
||||
gtk_widget_set_extension_events (event_box, GDK_EXTENSION_EVENTS_ALL);
|
||||
gtk_widget_grab_focus (event_box);
|
||||
|
||||
adj = gtk_adjustment_new (200.0 - coldata->pressure_adjust * 100.0,
|
||||
0.0, 200.0, 1.0, 1.0, 0.0);
|
||||
g_signal_connect (G_OBJECT (adj), "value_changed",
|
||||
G_CALLBACK (pressure_adjust_update),
|
||||
coldata);
|
||||
scale = gtk_vscale_new (GTK_ADJUSTMENT (adj));
|
||||
gtk_scale_set_digits (GTK_SCALE (scale), 0);
|
||||
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
|
||||
gimp_help_set_help_data (scale, _("Pressure"), NULL);
|
||||
gtk_box_pack_start (GTK_BOX (hbox2), scale, FALSE, FALSE, 0);
|
||||
|
||||
gtk_widget_show_all (vbox);
|
||||
|
||||
colorsel_water_set_color (coldata, hsv, rgb);
|
||||
|
||||
return vbox;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
colorsel_water_free (gpointer selector_data)
|
||||
{
|
||||
g_free (selector_data);
|
||||
}
|
||||
|
||||
static void
|
||||
colorsel_water_set_color (gpointer data,
|
||||
const GimpHSV *hsv,
|
||||
const GimpRGB *rgb)
|
||||
{
|
||||
ColorselWater *colorsel;
|
||||
|
||||
colorsel = (ColorselWater *) data;
|
||||
|
||||
colorsel->rgb = *rgb;
|
||||
}
|
||||
|
||||
static void
|
||||
colorsel_water_update (ColorselWater *colorsel)
|
||||
{
|
||||
GimpHSV hsv;
|
||||
|
||||
gimp_rgb_to_hsv (&colorsel->rgb, &hsv);
|
||||
|
||||
colorsel->callback (colorsel->data, &hsv, &colorsel->rgb);
|
||||
water->pressure_adjust = (adj->upper - adj->value) / 100.0;
|
||||
}
|
||||
|
@ -1,127 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
#ifdef __EMX__
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <libgimp/gimpmodule.h>
|
||||
#include <math.h>
|
||||
#include "gimpmodregister.h"
|
||||
|
||||
struct main_funcs_struc *gimp_main_funcs = NULL;
|
||||
|
||||
gpointer get_main_func(gchar *name)
|
||||
{
|
||||
struct main_funcs_struc *x;
|
||||
if (gimp_main_funcs == NULL)
|
||||
return NULL;
|
||||
for (x = gimp_main_funcs; x->name; x++)
|
||||
{
|
||||
if (!strcmp(x->name, name))
|
||||
return (gpointer) x->func;
|
||||
}
|
||||
}
|
||||
|
||||
GimpColorSelectorID
|
||||
mod_color_selector_register (const char *name,
|
||||
const char *help_page,
|
||||
GimpColorSelectorMethods *methods)
|
||||
{
|
||||
GimpColorSelectorID id;
|
||||
color_reg_func reg_func;
|
||||
|
||||
reg_func = (color_reg_func) get_main_func("gimp_color_selector_register");
|
||||
if (!reg_func)
|
||||
return 0;
|
||||
id = (*reg_func) (name, help_page, methods);
|
||||
return (id);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT gboolean
|
||||
mod_color_display_register (const char *name,
|
||||
GimpColorDisplayMethods *methods)
|
||||
{
|
||||
gboolean retval;
|
||||
display_reg_func reg_func;
|
||||
|
||||
reg_func = (display_reg_func) get_main_func("gimp_color_display_register");
|
||||
if (!reg_func)
|
||||
return 0;
|
||||
retval = (*reg_func) (name, methods);
|
||||
return (retval);
|
||||
|
||||
}
|
||||
|
||||
gboolean
|
||||
mod_color_selector_unregister (GimpColorSelectorID id,
|
||||
void (*callback)(void *data),
|
||||
void *data)
|
||||
{
|
||||
color_unreg_func unreg_func;
|
||||
gboolean status;
|
||||
|
||||
unreg_func = (color_unreg_func) get_main_func("gimp_color_selector_unregister");
|
||||
if (unreg_func)
|
||||
{
|
||||
status = (*unreg_func) (id, callback, data);
|
||||
}
|
||||
else
|
||||
status = FALSE;
|
||||
return (status);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT gboolean
|
||||
mod_color_display_unregister (const char *name)
|
||||
{
|
||||
display_unreg_func unreg_func;
|
||||
gboolean status;
|
||||
|
||||
unreg_func = (display_unreg_func) get_main_func("gimp_color_display_unregister");
|
||||
if (unreg_func)
|
||||
{
|
||||
status = (*unreg_func) (name);
|
||||
}
|
||||
else
|
||||
status = FALSE;
|
||||
return (status);
|
||||
}
|
||||
|
||||
void mod_dialog_register (GtkWidget *dialog)
|
||||
{
|
||||
dialog_reg_func reg_func;
|
||||
|
||||
reg_func = (dialog_reg_func) get_main_func("dialog_register");
|
||||
if (!reg_func)
|
||||
return;
|
||||
(*reg_func) (dialog);
|
||||
}
|
||||
|
||||
void mod_dialog_unregister (GtkWidget *dialog)
|
||||
{
|
||||
dialog_reg_func reg_func;
|
||||
|
||||
reg_func = (dialog_reg_func) get_main_func("dialog_unregister");
|
||||
if (!reg_func)
|
||||
return;
|
||||
(*reg_func) (dialog);
|
||||
}
|
||||
|
||||
#endif
|
@ -1,70 +0,0 @@
|
||||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef __MODREGISTER_H__
|
||||
#define __MODREGISTER_H__
|
||||
|
||||
|
||||
#ifdef __EMX__
|
||||
|
||||
#include <libgimp/gimptypes.h>
|
||||
#include <libgimp/gimpcolordisplay.h>
|
||||
#include <libgimp/gimpcolorselector.h>
|
||||
|
||||
struct main_funcs_struc {
|
||||
gchar *name;
|
||||
void (*func)();
|
||||
};
|
||||
|
||||
typedef GimpColorSelectorID (*color_reg_func)(const char *,
|
||||
const char *,
|
||||
GimpColorSelectorMethods *);
|
||||
typedef G_MODULE_EXPORT gboolean (*display_reg_func)
|
||||
(const char *,GimpColorDisplayMethods *);
|
||||
|
||||
typedef gboolean (*color_unreg_func) (GimpColorSelectorID,
|
||||
void (*)(void *),
|
||||
void *);
|
||||
typedef G_MODULE_EXPORT gboolean (*display_unreg_func) (const char *name);
|
||||
|
||||
typedef void (*dialog_reg_func) (GtkWidget *dialog);
|
||||
|
||||
void mod_dialog_register (GtkWidget *dialog);
|
||||
void mod_dialog_unregister (GtkWidget *dialog);
|
||||
#define dialog_register mod_dialog_register
|
||||
#define dialog_unregister mod_dialog_unregister
|
||||
|
||||
GimpColorSelectorID
|
||||
mod_color_selector_register (const char *name,
|
||||
const char *help_page,
|
||||
GimpColorSelectorMethods *methods);
|
||||
gboolean
|
||||
mod_color_selector_unregister (GimpColorSelectorID id,
|
||||
void (*callback)(void *data),
|
||||
void *data);
|
||||
|
||||
G_MODULE_EXPORT gboolean
|
||||
mod_color_display_register (const char *name,
|
||||
GimpColorDisplayMethods *methods);
|
||||
|
||||
G_MODULE_EXPORT gboolean
|
||||
mod_color_display_unregister (const char *name);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __MODREGISTER_H__ */
|
Reference in New Issue
Block a user