index 9d92077da478c1b85469b154c20c3eea852e7d31..44de40115796f95124f17ac78dd87deb9b001234 100644 (file)
#define __SP_COLOR_NOTEBOOK_C__
/*
#define __SP_COLOR_NOTEBOOK_C__
/*
- * A block of 3 color sliders plus spinbuttons
+ * A notebook with RGB, CMYK, CMS, HSL, and Wheel pages
*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
*/
#undef SPCS_PREVIEW
*/
#undef SPCS_PREVIEW
+#define noDUMP_CHANGE_INFO
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-#include <string.h>
-#include <stdlib.h>
+
+#include <cstring>
+#include <string>
+#include <cstdlib>
#include <gtk/gtk.h>
#include <glibmm/i18n.h>
#include <gtk/gtk.h>
#include <glibmm/i18n.h>
+
#include "../dialogs/dialog-events.h"
#include "../dialogs/dialog-events.h"
-#include "../prefs-utils.h"
+#include "../preferences.h"
#include "sp-color-notebook.h"
#include "spw-utilities.h"
#include "sp-color-notebook.h"
#include "spw-utilities.h"
-
#include "sp-color-scales.h"
#include "sp-color-scales.h"
+#include "sp-color-icc-selector.h"
#include "sp-color-wheel-selector.h"
struct SPColorNotebookTracker {
#include "sp-color-wheel-selector.h"
struct SPColorNotebookTracker {
};
static void sp_color_notebook_class_init (SPColorNotebookClass *klass);
};
static void sp_color_notebook_class_init (SPColorNotebookClass *klass);
-static void sp_color_notebook_init (SPColorNotebook *slider);
+static void sp_color_notebook_init (SPColorNotebook *colorbook);
static void sp_color_notebook_destroy (GtkObject *object);
static void sp_color_notebook_show_all (GtkWidget *widget);
static void sp_color_notebook_destroy (GtkObject *object);
static void sp_color_notebook_show_all (GtkWidget *widget);
#define XPAD 4
#define YPAD 1
#define XPAD 4
#define YPAD 1
-GtkType
-sp_color_notebook_get_type (void)
+GType sp_color_notebook_get_type(void)
{
{
- static GtkType type = 0;
- if (!type) {
- GtkTypeInfo info = {
- "SPColorNotebook",
- sizeof (SPColorNotebook),
- sizeof (SPColorNotebookClass),
- (GtkClassInitFunc) sp_color_notebook_class_init,
- (GtkObjectInitFunc) sp_color_notebook_init,
- NULL, NULL, NULL
- };
- type = gtk_type_unique (SP_TYPE_COLOR_SELECTOR, &info);
- }
- return type;
+ static GtkType type = 0;
+ if (!type) {
+ GTypeInfo info = {
+ sizeof(SPColorNotebookClass),
+ 0, // base_init
+ 0, // base_finalize
+ (GClassInitFunc)sp_color_notebook_class_init,
+ 0, // class_finalize
+ 0, // class_data
+ sizeof(SPColorNotebook),
+ 0, // n_preallocs
+ (GInstanceInitFunc)sp_color_notebook_init,
+ 0 // value_table
+ };
+ type = g_type_register_static(SP_TYPE_COLOR_SELECTOR, "SPColorNotebook", &info, static_cast<GTypeFlags>(0));
+ }
+ return type;
}
static void
}
static void
static void
sp_color_notebook_switch_page(GtkNotebook *notebook,
static void
sp_color_notebook_switch_page(GtkNotebook *notebook,
- GtkNotebookPage *page,
- guint page_num,
- SPColorNotebook *colorbook)
+ GtkNotebookPage *page,
+ guint page_num,
+ SPColorNotebook *colorbook)
{
{
- if ( colorbook )
- {
+ if ( colorbook )
+ {
ColorNotebook* nb = (ColorNotebook*)(SP_COLOR_SELECTOR(colorbook)->base);
nb->switchPage( notebook, page, page_num );
ColorNotebook* nb = (ColorNotebook*)(SP_COLOR_SELECTOR(colorbook)->base);
nb->switchPage( notebook, page, page_num );
- // remember the page we seitched to
- prefs_set_int_attribute ("colorselector", "page", page_num);
-
- }
+ // remember the page we seitched to
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ prefs->setInt("/colorselector/page", page_num);
+ }
}
void ColorNotebook::switchPage(GtkNotebook*,
}
void ColorNotebook::switchPage(GtkNotebook*,
/* tempory hardcoding to get types loaded */
SP_TYPE_COLOR_SCALES;
SP_TYPE_COLOR_WHEEL_SELECTOR;
/* tempory hardcoding to get types loaded */
SP_TYPE_COLOR_SCALES;
SP_TYPE_COLOR_WHEEL_SELECTOR;
+#if ENABLE_LCMS
+ SP_TYPE_COLOR_ICC_SELECTOR;
+#endif // ENABLE_LCMS
- /* REJON: Comment out the next line to not use the normal GTK Color
+ /* REJON: Comment out the next line to not use the normal GTK Color
wheel. */
// SP_TYPE_COLOR_GTKSELECTOR;
wheel. */
// SP_TYPE_COLOR_GTKSELECTOR;
for ( i = 0; i < _trackerList->len; i++ )
{
for ( i = 0; i < _trackerList->len; i++ )
{
- SPColorNotebookTracker *entry =
+ SPColorNotebookTracker *entry =
reinterpret_cast< SPColorNotebookTracker* > (g_ptr_array_index (_trackerList, i));
if ( entry )
{
reinterpret_cast< SPColorNotebookTracker* > (g_ptr_array_index (_trackerList, i));
if ( entry )
{
XPAD, YPAD);
// restore the last active page
XPAD, YPAD);
// restore the last active page
- gtk_notebook_set_current_page (GTK_NOTEBOOK (_book), prefs_get_int_attribute ("colorselector", "page", 0));
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (_book), prefs->getInt("/colorselector/page", 0));
{
gboolean found = FALSE;
{
gboolean found = FALSE;
gtk_widget_show (align);
gtk_container_add (GTK_CONTAINER (align), _btn);
gtk_widget_show (align);
gtk_container_add (GTK_CONTAINER (align), _btn);
- // uncomment to reenable the "show/hide modes" menu,
+ // uncomment to reenable the "show/hide modes" menu,
// but first fix it so it remembers its settings in prefs and does not take that much space (entire vertical column!)
//gtk_table_attach (GTK_TABLE (table), align, 2, 3, row, row + 1, GTK_FILL, GTK_FILL, XPAD, YPAD);
// but first fix it so it remembers its settings in prefs and does not take that much space (entire vertical column!)
//gtk_table_attach (GTK_TABLE (table), align, 2, 3, row, row + 1, GTK_FILL, GTK_FILL, XPAD, YPAD);
row++;
row++;
- /* Create RGBA entry and color preview */
GtkWidget *rgbabox = gtk_hbox_new (FALSE, 0);
GtkWidget *rgbabox = gtk_hbox_new (FALSE, 0);
+ /* Create color management icons */
+ _box_colormanaged = gtk_event_box_new ();
+ GtkWidget *colormanaged = gtk_image_new_from_icon_name ("color-management-icon", GTK_ICON_SIZE_SMALL_TOOLBAR);
+ gtk_container_add (GTK_CONTAINER (_box_colormanaged), colormanaged);
+ GtkTooltips *tooltips_colormanaged = gtk_tooltips_new ();
+ gtk_tooltips_set_tip (tooltips_colormanaged, _box_colormanaged, _("Color Managed"), "");
+ gtk_widget_set_sensitive (_box_colormanaged, false);
+ gtk_box_pack_start(GTK_BOX(rgbabox), _box_colormanaged, TRUE, FALSE, 2);
+
+ _box_outofgamut = gtk_event_box_new ();
+ GtkWidget *outofgamut = gtk_image_new_from_icon_name ("out-of-gamut-icon", GTK_ICON_SIZE_SMALL_TOOLBAR);
+ gtk_container_add (GTK_CONTAINER (_box_outofgamut), outofgamut);
+ GtkTooltips *tooltips_outofgamut = gtk_tooltips_new ();
+ gtk_tooltips_set_tip (tooltips_outofgamut, _box_outofgamut, _("Out of gamut!"), "");
+ gtk_widget_set_sensitive (_box_outofgamut, false);
+ gtk_box_pack_start(GTK_BOX(rgbabox), _box_outofgamut, TRUE, FALSE, 2);
+ /* Create RGBA entry and color preview */
_rgbal = gtk_label_new_with_mnemonic (_("RGBA_:"));
gtk_misc_set_alignment (GTK_MISC (_rgbal), 1.0, 0.5);
gtk_box_pack_start(GTK_BOX(rgbabox), _rgbal, TRUE, TRUE, 2);
_rgbal = gtk_label_new_with_mnemonic (_("RGBA_:"));
gtk_misc_set_alignment (GTK_MISC (_rgbal), 1.0, 0.5);
gtk_box_pack_start(GTK_BOX(rgbabox), _rgbal, TRUE, TRUE, 2);
return csel;
}
return csel;
}
-void ColorNotebook::_colorChanged(const SPColor& color, gfloat alpha)
+void ColorNotebook::_colorChanged()
{
{
- SPColorSelector* cselPage = 0;
-
- g_return_if_fail (_csel != NULL);
- g_return_if_fail (SP_IS_COLOR_NOTEBOOK (_csel));
- g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) );
-
- cselPage = getCurrentSelector();
- if ( cselPage )
- {
- cselPage->base->setColorAlpha( color, alpha );
- }
+ SPColorSelector* cselPage = getCurrentSelector();
+ if ( cselPage )
+ {
+ cselPage->base->setColorAlpha( _color, _alpha );
+ }
- _updateRgbaEntry( color, alpha );
+ _updateRgbaEntry( _color, _alpha );
}
void ColorNotebook::_rgbaEntryChangedHook(GtkEntry *entry, SPColorNotebook *colorbook)
}
void ColorNotebook::_rgbaEntryChangedHook(GtkEntry *entry, SPColorNotebook *colorbook)
@@ -437,34 +458,51 @@ void ColorNotebook::_rgbaEntryChangedHook(GtkEntry *entry, SPColorNotebook *colo
void ColorNotebook::_rgbaEntryChanged(GtkEntry* entry)
{
void ColorNotebook::_rgbaEntryChanged(GtkEntry* entry)
{
- const gchar *t;
- gchar *e;
- SPColor color;
- guint rgba;
-
- if (_updating) return;
- if (_updatingrgba) return;
-
- t = gtk_entry_get_text (entry);
-
- if (t) {
- rgba = strtoul (t, &e, 16);
- if ( e != t ) {
- ptrdiff_t len=e-t;
- if ( len < 8 ) {
- rgba = rgba << ( 4 * ( 8 - len ) );
- }
- _updatingrgba = TRUE;
- sp_color_set_rgb_rgba32 (&color, rgba);
- setColorAlpha( color, SP_RGBA32_A_F(rgba), true);
- _updatingrgba = FALSE;
- }
- }
+ if (_updating) return;
+ if (_updatingrgba) return;
+
+ const gchar *t = gtk_entry_get_text( entry );
+
+ if (t) {
+ Glib::ustring text = t;
+ bool changed = false;
+ if (!text.empty() && text[0] == '#') {
+ changed = true;
+ text.erase(0,1);
+ if (text.size() == 6) {
+ // it was a standard RGB hex
+ unsigned int alph = SP_COLOR_F_TO_U(_alpha);
+ gchar* tmp = g_strdup_printf("%02x", alph);
+ text += tmp;
+ g_free(tmp);
+ }
+ }
+ gchar* str = g_strdup(text.c_str());
+ gchar* end = 0;
+ guint64 rgba = g_ascii_strtoull( str, &end, 16 );
+ if ( end != str ) {
+ ptrdiff_t len = end - str;
+ if ( len < 8 ) {
+ rgba = rgba << ( 4 * ( 8 - len ) );
+ }
+ _updatingrgba = TRUE;
+ if ( changed ) {
+ gtk_entry_set_text( entry, str );
+ }
+ SPColor color( rgba );
+ setColorAlpha( color, SP_RGBA32_A_F(rgba), true );
+ _updatingrgba = FALSE;
+ }
+ g_free(str);
+ }
}
void ColorNotebook::_updateRgbaEntry( const SPColor& color, gfloat alpha )
{
g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) );
}
void ColorNotebook::_updateRgbaEntry( const SPColor& color, gfloat alpha )
{
g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) );
+
+ /* update color management icon*/
+ gtk_widget_set_sensitive (_box_colormanaged, color.icc != NULL);
if ( !_updatingrgba )
{
if ( !_updatingrgba )
{
guint32 rgba;
/* Update RGBA entry */
guint32 rgba;
/* Update RGBA entry */
- rgba = sp_color_get_rgba32_falpha (&color, alpha);
+ rgba = color.toRGBA32( alpha );
g_snprintf (s, 32, "%08x", rgba);
const gchar* oldText = gtk_entry_get_text( GTK_ENTRY( _rgbae ) );
g_snprintf (s, 32, "%08x", rgba);
const gchar* oldText = gtk_entry_get_text( GTK_ENTRY( _rgbae ) );
{
GtkWidget *page;
{
GtkWidget *page;
- page = sp_color_selector_new ( page_type, SP_COLORSPACE_TYPE_NONE);
+ page = sp_color_selector_new( page_type );
if ( page )
{
GtkWidget* tab_label = 0;
if ( page )
{
GtkWidget* tab_label = 0;
}
}
}
}
}
}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :