Code

use a function instead of copy-pasting code
authorJucaBlues <JucaBlues@users.sourceforge.net>
Fri, 14 Aug 2009 03:33:33 +0000 (03:33 +0000)
committerJucaBlues <JucaBlues@users.sourceforge.net>
Fri, 14 Aug 2009 03:33:33 +0000 (03:33 +0000)
src/widgets/sp-color-wheel-selector.cpp

index bc8c4763bc4826dd6ac38a3d42563978588e14c8..6012f4e2004ebdb02d320c448c3d429c245e8dc0 100644 (file)
@@ -206,6 +206,11 @@ sp_color_wheel_selector_new (void)
 
 /* Helpers for setting color value */
 
+static void preserve_icc(SPColor *color, SPColorWheelSelector *cs){
+    ColorSelector* selector = (ColorSelector*)(SP_COLOR_SELECTOR(cs)->base);
+    color->icc = selector->getColor().icc ? new SVGICCColor(*selector->getColor().icc) : 0;
+}
+
 void ColorWheelSelector::_colorChanged()
 {
 #ifdef DUMP_CHANGE_INFO
@@ -238,10 +243,7 @@ void ColorWheelSelector::_adjustmentChanged( GtkAdjustment *adjustment, SPColorW
 
     wheelSelector->_updating = TRUE;
 
-    /* Preserve ICC color */
-    ColorSelector* selector = (ColorSelector*)(SP_COLOR_SELECTOR(cs)->base);
-    wheelSelector->_color.icc = selector->getColor().icc ? new SVGICCColor(*selector->getColor().icc) : 0;
-
+    preserve_icc(&wheelSelector->_color, cs);
     wheelSelector->_updateInternals( wheelSelector->_color, ColorScales::getScaled( wheelSelector->_adj ), wheelSelector->_dragging );
 
     wheelSelector->_updating = FALSE;
@@ -255,10 +257,7 @@ void ColorWheelSelector::_sliderGrabbed( SPColorSlider *slider, SPColorWheelSele
         wheelSelector->_dragging = TRUE;
         wheelSelector->_grabbed();
 
-        /* Preserve ICC color */
-        ColorSelector* selector = (ColorSelector*)(SP_COLOR_SELECTOR(cs)->base);
-        wheelSelector->_color.icc = selector->getColor().icc ? new SVGICCColor(*selector->getColor().icc) : 0;
-
+        preserve_icc(&wheelSelector->_color, cs);
         wheelSelector->_updateInternals( wheelSelector->_color, ColorScales::getScaled( wheelSelector->_adj ), wheelSelector->_dragging );
     }
 }
@@ -271,10 +270,7 @@ void ColorWheelSelector::_sliderReleased( SPColorSlider *slider, SPColorWheelSel
         wheelSelector->_dragging = FALSE;
         wheelSelector->_released();
 
-        /* Preserve ICC color */
-        ColorSelector* selector = (ColorSelector*)(SP_COLOR_SELECTOR(cs)->base);
-        wheelSelector->_color.icc = selector->getColor().icc ? new SVGICCColor(*selector->getColor().icc) : 0;
-
+        preserve_icc(&wheelSelector->_color, cs);
         wheelSelector->_updateInternals( wheelSelector->_color, ColorScales::getScaled( wheelSelector->_adj ), wheelSelector->_dragging );
     }
 }
@@ -284,10 +280,7 @@ void ColorWheelSelector::_sliderChanged( SPColorSlider *slider, SPColorWheelSele
     (void)slider;
     ColorWheelSelector* wheelSelector = (ColorWheelSelector*)(SP_COLOR_SELECTOR(cs)->base);
 
-    /* Preserve ICC color */
-    ColorSelector* selector = (ColorSelector*)(SP_COLOR_SELECTOR(cs)->base);
-    wheelSelector->_color.icc = selector->getColor().icc ? new SVGICCColor(*selector->getColor().icc) : 0;
-
+    preserve_icc(&wheelSelector->_color, cs);
     wheelSelector->_updateInternals( wheelSelector->_color, ColorScales::getScaled( wheelSelector->_adj ), wheelSelector->_dragging );
 }
 
@@ -304,10 +297,7 @@ void ColorWheelSelector::_wheelChanged( SPColorWheel *wheel, SPColorWheelSelecto
 
     sp_color_slider_set_colors (SP_COLOR_SLIDER(wheelSelector->_slider), start, mid, end);
 
-    /* Preserve ICC color */
-    ColorSelector* selector = (ColorSelector*)(SP_COLOR_SELECTOR(cs)->base);
-    color.icc = selector->getColor().icc ? new SVGICCColor(*selector->getColor().icc) : 0;
-
+    preserve_icc(&color, cs);
     wheelSelector->_updateInternals( color, wheelSelector->_alpha, sp_color_wheel_is_adjusting( wheel ) );
 }