sp-color-scales.cpp revision 53650c4839343807b95444a86e89225fc71de648
/*
* bulia byak <buliabyak@users.sf.net>
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <math.h>
#include "../dialogs/dialog-events.h"
#include "sp-color-scales.h"
#define CSC_CHANNEL_R (1 << 0)
#define CSC_CHANNEL_H (1 << 0)
#define CSC_CHANNEL_C (1 << 0)
#define CSC_CHANNELS_ALL 0
static const gchar *sp_color_scales_hue_map (void);
static SPColorSelectorClass *parent_class;
#define XPAD 4
#define YPAD 1
#define noDUMP_CHANGE_INFO 1
sp_color_scales_get_type (void)
{
if (!type) {
sizeof (SPColorScalesClass),
NULL, /* base_init */
NULL, /* base_finalize */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (SPColorScales),
0, /* n_preallocs */
};
"SPColorScales",
&info,
static_cast< GTypeFlags > (0) );
}
return type;
}
static void
{
}
: ColorSelector( csel ),
_rangeLimit( 255.0 ),
{
for (gint i = 0; i < 5; i++) {
_l[i] = 0;
_a[i] = 0;
_s[i] = 0;
_b[i] = 0;
}
}
{
for (gint i = 0; i < 5; i++) {
_l[i] = 0;
_a[i] = 0;
_s[i] = 0;
_b[i] = 0;
}
}
{
{
}
}
void ColorScales::init()
{
GtkWidget *t;
gint i;
_tt = gtk_tooltips_new();
gtk_widget_show (t);
/* Create components */
/* Label */
gtk_widget_show (_l[i]);
/* Adjustment */
/* Slider */
gtk_widget_show (_s[i]);
gtk_table_attach (GTK_TABLE (t), _s[i], 1, 2, i, i + 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)GTK_FILL, XPAD, YPAD);
/* Spinbutton */
sp_dialog_defocus_on_enter (_b[i]);
gtk_widget_show (_b[i]);
gtk_table_attach (GTK_TABLE (t), _b[i], 2, 3, i, i + 1, (GtkAttachOptions)0, (GtkAttachOptions)0, XPAD, YPAD);
/* Attach channel value to adjustment */
/* Signals */
}
/* Initial mode is none, so it works */
}
static void
{
}
static void
{
}
static void
{
}
sp_color_scales_new (void)
{
return GTK_WIDGET (csel);
}
{
if ( changing )
{
gfloat c[5];
switch (_mode) {
case SP_COLOR_SCALES_MODE_RGB:
case SP_COLOR_SCALES_MODE_HSV:
_getRgbaFloatv(c);
alpha = c[3];
break;
{
_getCmykaFloatv( c );
float rgb[3];
alpha = c[4];
break;
}
default:
break;
}
}
else
{
}
}
/* Helpers for setting color value */
{
return val;
}
{
gtk_adjustment_set_value( a, val );
}
{
_rangeLimit = upper;
gtk_adjustment_changed( _a[i] );
}
}
void ColorScales::_colorChanged()
{
#ifdef DUMP_CHANGE_INFO
g_message("ColorScales::_colorChanged( this=%p, %f, %f, %f, %f)", this, _color.v.c[0], _color.v.c[1], _color.v.c[2], _alpha );
#endif
switch (_mode) {
case SP_COLOR_SCALES_MODE_RGB:
sp_color_get_rgb_floatv( &_color, c );
c[3] = _alpha;
c[4] = 0.0;
break;
case SP_COLOR_SCALES_MODE_HSV:
c[3] = _alpha;
c[4] = 0.0;
break;
sp_color_get_cmyk_floatv( &_color, c );
c[4] = _alpha;
break;
default:
break;
}
}
{
switch (_mode) {
case SP_COLOR_SCALES_MODE_RGB:
break;
case SP_COLOR_SCALES_MODE_HSV:
break;
sp_color_cmyk_to_rgb_floatv (rgba, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), getScaled(_a[3]));
break;
default:
break;
}
}
{
switch (_mode) {
case SP_COLOR_SCALES_MODE_RGB:
break;
case SP_COLOR_SCALES_MODE_HSV:
break;
break;
default:
break;
}
}
{
gfloat c[4];
_getRgbaFloatv(c);
return rgba;
}
{
gfloat c[4];
if ((_mode == SP_COLOR_SCALES_MODE_RGB) ||
(_mode == SP_COLOR_SCALES_MODE_HSV) ||
(_mode == SP_COLOR_SCALES_MODE_CMYK)) {
} else {
}
switch (mode) {
case SP_COLOR_SCALES_MODE_RGB:
_setRangeLimit(255.0);
break;
case SP_COLOR_SCALES_MODE_HSV:
_setRangeLimit(255.0);
c[0] = 0.0;
break;
_setRangeLimit(100.0);
break;
default:
break;
}
}
{
return _mode;
}
{
switch ( submode )
{
default:
case 0:
break;
case 1:
break;
case 2:
break;
}
}
{
switch ( _mode )
{
case SP_COLOR_SCALES_MODE_HSV:
submode = 1;
break;
submode = 2;
break;
case SP_COLOR_SCALES_MODE_RGB:
default:
submode = 0;
}
return submode;
}
{
}
{
(void)slider;
}
}
{
(void)slider;
}
}
{
(void)slider;
}
{
}
{
#ifdef SPCS_PREVIEW
#endif
switch (_mode) {
case SP_COLOR_SCALES_MODE_RGB:
/* Update red */
}
/* Update green */
}
/* Update blue */
}
if (channels != CSC_CHANNEL_A) {
/* Update alpha */
}
break;
case SP_COLOR_SCALES_MODE_HSV:
/* Hue is never updated */
/* Update saturation */
}
/* Update value */
}
if (channels != CSC_CHANNEL_A) {
/* Update alpha */
}
break;
/* Update C */
}
/* Update M */
}
/* Update Y */
}
/* Update K */
}
if (channels != CSC_CHANNEL_CMYKA) {
/* Update alpha */
sp_color_cmyk_to_rgb_floatv (rgb0, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), getScaled(_a[3]));
}
break;
default:
break;
}
// Force the internal color to be updated
if ( !_updating )
{
_recalcColor( TRUE );
}
#ifdef SPCS_PREVIEW
#endif
}
static const gchar *
sp_color_scales_hue_map (void)
{
if (!map) {
gchar *p;
gint h;
p = map;
for (h = 0; h < 1024; h++) {
*p++ = SP_COLOR_F_TO_U (rgb[0]);
*p++ = 255;
}
}
return map;
}