sp-color-scales.cpp revision 73433c28659cc79c3d2afde123b6f2fd84f3ec4c
/*
* bulia byak <buliabyak@users.sf.net>
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "sp-color-scales.h"
#include <math.h>
#include <gtkmm/adjustment.h>
#include "../dialogs/dialog-events.h"
#include "svg/svg-icc-color.h"
#include "ui/widget/color-slider.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
N_("None"),
N_("RGB"),
N_("HSL"),
N_("CMYK")
};
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()
{
gint i;
#if GTK_CHECK_VERSION(3,0,0)
GtkWidget *t = gtk_grid_new();
#else
#endif
gtk_widget_show (t);
/* Create components */
/* Label */
gtk_widget_show (_l[i]);
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
/* Adjustment */
/* Slider */
#if GTK_CHECK_VERSION(3,0,0)
_s[i]->set_hexpand(true);
#else
gtk_table_attach (GTK_TABLE (t), _s[i]->gobj(), 1, 2, i, i + 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), GTK_FILL, XPAD, YPAD);
#endif
/* Spinbutton */
sp_dialog_defocus_on_enter (_b[i]);
gtk_widget_show (_b[i]);
#if GTK_CHECK_VERSION(3,0,0)
#else
gtk_table_attach (GTK_TABLE (t), _b[i], 2, 3, i, i + 1, (GtkAttachOptions)0, (GtkAttachOptions)0, XPAD, YPAD);
#endif
/* Attach channel value to adjustment */
/* Signals */
}
/* Initial mode is none, so it works */
}
{
}
static 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;
}
/* Preserve ICC */
}
else
{
}
}
/* Helpers for setting color value */
{
/ gtk_adjustment_get_upper (const_cast<GtkAdjustment*>(a));
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 ColorScales::_sliderAnyGrabbed()
{
if (!_dragging) {
_grabbed();
_recalcColor( FALSE );
}
}
void ColorScales::_sliderAnyReleased()
{
if (_dragging) {
_released();
_recalcColor( FALSE );
}
}
void ColorScales::_sliderAnyChanged()
{
_recalcColor( TRUE );
}
{
}
{
#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;
}
{
}
}
csel = SP_COLOR_SELECTOR (w);
if ( _submode > 0 )
{
}
return wrapped;
}
}