index 6012f4e2004ebdb02d320c448c3d429c245e8dc0..2e36a024e858a5f75c694ee42b58b3a78a21ef50 100644 (file)
}
}
+static void resizeHSVWheel( GtkHSV *hsv, GtkAllocation *allocation )
+{
+ gint diam = std::min(allocation->width, allocation->height);
+
+ // drop a little for resizing
+ diam -= 4;
+
+ GtkStyle *style = gtk_widget_get_style( GTK_WIDGET(hsv) );
+ if ( style ) {
+ gint thick = std::max(style->xthickness, style->ythickness);
+ if (thick > 0) {
+ diam -= thick * 2;
+ }
+ }
+ gint padding = -1;
+ gtk_widget_style_get( GTK_WIDGET(hsv),
+ "focus-padding", &padding,
+ NULL );
+ if (padding > 0) {
+ diam -= padding * 2;
+ }
+
+ diam = std::max(20, diam);
+ gint ring = static_cast<gint>( static_cast<gdouble>(diam) / (4.0 * 1.618) );
+ gtk_hsv_set_metrics( hsv, diam, ring );
+}
+
+#if GTK_CHECK_VERSION(2,18,0)
+static void handleWheelStyleSet(GtkHSV *hsv, GtkStyle* /*previous*/, gpointer /*userData*/)
+{
+ GtkAllocation allocation = {0, 0, 0, 0};
+ gtk_widget_get_allocation( GTK_WIDGET(hsv), &allocation );
+ resizeHSVWheel( hsv, &allocation );
+}
+#endif // GTK_CHECK_VERSION(2,18,0)
+
+static void handleWheelAllocation(GtkHSV *hsv, GtkAllocation *allocation, gpointer /*userData*/)
+{
+ resizeHSVWheel( hsv, allocation );
+}
+
void ColorWheelSelector::init()
{
GtkWidget *t;
/* Create components */
row = 0;
- _wheel = sp_color_wheel_new ();
- gtk_widget_show (_wheel);
- gtk_table_attach (GTK_TABLE (t), _wheel, 0, 3, row, row + 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), XPAD, YPAD);
+ _wheel = gtk_hsv_new();
+ gtk_hsv_set_metrics( GTK_HSV(_wheel), 48, 8 );
+ gtk_widget_show( _wheel );
+ gtk_table_attach( GTK_TABLE(t), _wheel, 0, 3, row, row + 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), XPAD, YPAD);
row++;
/* Label */
- _label = gtk_label_new_with_mnemonic (_("_A"));
+ _label = gtk_label_new_with_mnemonic (_("_A:"));
gtk_misc_set_alignment (GTK_MISC (_label), 1.0, 0.5);
gtk_widget_show (_label);
gtk_table_attach (GTK_TABLE (t), _label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, XPAD, YPAD);
gtk_signal_connect (GTK_OBJECT (_slider), "changed",
GTK_SIGNAL_FUNC (_sliderChanged), _csel);
- gtk_signal_connect (GTK_OBJECT(_wheel), "changed",
- GTK_SIGNAL_FUNC (_wheelChanged), _csel);
+ gtk_signal_connect( GTK_OBJECT(_wheel), "changed",
+ GTK_SIGNAL_FUNC(_wheelChanged), _csel );
+
+
+ // GTK does not automatically scale the color wheel, so we have to add that in:
+ gtk_signal_connect( GTK_OBJECT(_wheel), "size-allocate",
+ GTK_SIGNAL_FUNC(handleWheelAllocation), _csel );
+#if GTK_CHECK_VERSION(2,18,0)
+ gtk_signal_connect( GTK_OBJECT(_wheel), "style-set",
+ GTK_SIGNAL_FUNC(handleWheelStyleSet), _csel );
+#endif // GTK_CHECK_VERSION(2,18,0)
}
static void
g_message("ColorWheelSelector::_colorChanged( this=%p, %f, %f, %f, %f)", this, color.v.c[0], color.v.c[1], color.v.c[2], alpha );
#endif
_updating = TRUE;
- sp_color_wheel_set_color( SP_COLOR_WHEEL( _wheel ), &_color );
+ {
+ gdouble h = 0;
+ gdouble s = 0;
+ gdouble v = 0;
+ gtk_rgb_to_hsv( _color.v.c[0], _color.v.c[1], _color.v.c[2], &h, &s, &v );
+ gtk_hsv_set_color( GTK_HSV(_wheel), h, s, v );
+ }
guint32 start = _color.toRGBA32( 0x00 );
guint32 mid = _color.toRGBA32( 0x7f );
@@ -284,12 +341,21 @@ void ColorWheelSelector::_sliderChanged( SPColorSlider *slider, SPColorWheelSele
wheelSelector->_updateInternals( wheelSelector->_color, ColorScales::getScaled( wheelSelector->_adj ), wheelSelector->_dragging );
}
-void ColorWheelSelector::_wheelChanged( SPColorWheel *wheel, SPColorWheelSelector *cs )
+void ColorWheelSelector::_wheelChanged( GtkHSV *hsv, SPColorWheelSelector *cs )
{
- ColorWheelSelector* wheelSelector = (ColorWheelSelector*)(SP_COLOR_SELECTOR(cs)->base);
- SPColor color;
+ ColorWheelSelector* wheelSelector = static_cast<ColorWheelSelector*>(SP_COLOR_SELECTOR(cs)->base);
+
+ gdouble h = 0;
+ gdouble s = 0;
+ gdouble v = 0;
+ gtk_hsv_get_color( hsv, &h, &s, &v );
+
+ gdouble r = 0;
+ gdouble g = 0;
+ gdouble b = 0;
+ gtk_hsv_to_rgb(h, s, v, &r, &g, &b);
- sp_color_wheel_get_color( wheel, &color );
+ SPColor color(r, g, b);
guint32 start = color.toRGBA32( 0x00 );
guint32 mid = color.toRGBA32( 0x7f );
@@ -298,7 +364,7 @@ void ColorWheelSelector::_wheelChanged( SPColorWheel *wheel, SPColorWheelSelecto
sp_color_slider_set_colors (SP_COLOR_SLIDER(wheelSelector->_slider), start, mid, end);
preserve_icc(&color, cs);
- wheelSelector->_updateInternals( color, wheelSelector->_alpha, sp_color_wheel_is_adjusting( wheel ) );
+ wheelSelector->_updateInternals( color, wheelSelector->_alpha, gtk_hsv_is_adjusting( hsv ) );
}
@@ -311,4 +377,4 @@ void ColorWheelSelector::_wheelChanged( SPColorWheel *wheel, SPColorWheelSelecto
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :