From 02240ae5044401944463d2022c2ac712570afe93 Mon Sep 17 00:00:00 2001 From: Hombre Date: Sat, 14 Jun 2014 15:18:25 +0200 Subject: [PATCH] Adding more possibilities to the ColorProvider class --- rtgui/blackwhite.cc | 5 ++++- rtgui/blackwhite.h | 2 +- rtgui/colorappearance.cc | 6 +++++- rtgui/colorappearance.h | 2 +- rtgui/coloredbar.cc | 8 ++++---- rtgui/colorprovider.h | 8 +++++++- rtgui/defringe.cc | 6 +++++- rtgui/defringe.h | 2 +- rtgui/guiutils.h | 5 +++++ rtgui/hsvequalizer.cc | 5 ++++- rtgui/hsvequalizer.h | 2 +- rtgui/labcurve.cc | 6 +++++- rtgui/labcurve.h | 2 +- rtgui/myflatcurve.cc | 8 ++++---- rtgui/thresholdadjuster.cc | 19 ++++++++++++++++--- rtgui/thresholdadjuster.h | 2 ++ rtgui/thresholdselector.cc | 24 ++++++++++++++++++++---- rtgui/thresholdselector.h | 2 ++ 18 files changed, 88 insertions(+), 26 deletions(-) diff --git a/rtgui/blackwhite.cc b/rtgui/blackwhite.cc index 224f0bade..6d8ba108f 100644 --- a/rtgui/blackwhite.cc +++ b/rtgui/blackwhite.cc @@ -662,10 +662,13 @@ bool BlackWhite::curveMode1Changed2_ () { return false; } */ -void BlackWhite::colorForValue (double valX, double valY, int callerId, ColorCaller* caller) { +void BlackWhite::colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller* caller) { float r, g, b; + if (elemType == ColorCaller::CCET_VERTICAL_BAR) + valY = 0.5f; + if (callerId == 1) { // Hue = f(Hue) float h = float((valY - 0.5) * 2. + valX); diff --git a/rtgui/blackwhite.h b/rtgui/blackwhite.h index 033b936b9..dc3bb597f 100644 --- a/rtgui/blackwhite.h +++ b/rtgui/blackwhite.h @@ -122,7 +122,7 @@ class BlackWhite : public ToolParamBlock, public AdjusterListener, public Foldab void methodChanged (); void filterChanged (); void settingChanged (); - virtual void colorForValue (double valX, double valY, int callerId, ColorCaller* caller); + virtual void colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller* caller); void BWChanged (double redbw, double greenbw, double bluebw); bool BWComputed_ (); void curveChanged (CurveEditor* ce); diff --git a/rtgui/colorappearance.cc b/rtgui/colorappearance.cc index b0cb8c031..1f2d5cb29 100644 --- a/rtgui/colorappearance.cc +++ b/rtgui/colorappearance.cc @@ -932,9 +932,13 @@ bool ColorAppearance::adapCamComputed_ () { } -void ColorAppearance::colorForValue (double valX, double valY, int callerId, ColorCaller *caller) { +void ColorAppearance::colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller *caller) { float R, G, B; + + if (elemType==ColorCaller::CCET_VERTICAL_BAR) + valY = 0.5; + if (callerId == 1) { // cc - bottom bar float value = (1.f - 0.7f) * float(valX) + 0.7f; diff --git a/rtgui/colorappearance.h b/rtgui/colorappearance.h index 3fd053076..39a5b84cb 100644 --- a/rtgui/colorappearance.h +++ b/rtgui/colorappearance.h @@ -134,7 +134,7 @@ class ColorAppearance : public ToolParamBlock, public AdjusterListener, public F void setAdjusterBehavior (bool degreeadd, bool adapscenadd, bool adaplumadd, bool badpixsladd, bool jlightadd, bool chromaadd, bool contrastadd, bool rstprotectionadd, bool qbrightadd, bool qcontrastadd, bool schromaadd, bool mchromaadd, bool colorhadd); void trimValues (rtengine::procparams::ProcParams* pp); void updateCurveBackgroundHistogram (LUTu & histToneCurve, LUTu & histLCurve, LUTu & histCCurve,/* LUTu & histCLurve, LUTu & histLLCurve,*/ LUTu & histLCAM, LUTu & histCCAM, LUTu & histRed, LUTu & histGreen, LUTu & histBlue, LUTu & histLuma); - virtual void colorForValue (double valX, double valY, int callerId, ColorCaller *caller); + virtual void colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller *caller); }; #endif diff --git a/rtgui/coloredbar.cc b/rtgui/coloredbar.cc index 6f005c437..2e48034c8 100644 --- a/rtgui/coloredbar.cc +++ b/rtgui/coloredbar.cc @@ -104,7 +104,7 @@ void ColoredBar::draw() { double y_ = double((h-1)-y); double x01 = x_ /double(w-1); double y01 = double(y)/double(h-1); - colorProvider->colorForValue (x01, y01, colorCallerId, this); + colorProvider->colorForValue (x01, y01, CCET_BACKGROUND, colorCallerId, this); cr->set_source_rgb(ccRed, ccGreen, ccBlue); cr->rectangle(x_, y_, 1., 1.); cr->fill(); @@ -118,7 +118,7 @@ void ColoredBar::draw() { double y_ = double((h-1)-y); double x01 = double(x)/double(w-1); double y01 = double(y)/double(h-1); - colorProvider->colorForValue (x01, y01, colorCallerId, this); + colorProvider->colorForValue (x01, y01, CCET_BACKGROUND, colorCallerId, this); cr->set_source_rgb(ccRed, ccGreen, ccBlue); cr->rectangle(x_, y_, 1., 1.); cr->fill(); @@ -132,7 +132,7 @@ void ColoredBar::draw() { double y_ = double((h-1)-y); double x01 = double(x)/double(w-1); double y01 = double(y)/double(h-1); - colorProvider->colorForValue (y01, x01, colorCallerId, this); + colorProvider->colorForValue (y01, x01, CCET_BACKGROUND, colorCallerId, this); cr->set_source_rgb(ccRed, ccGreen, ccBlue); cr->rectangle(x_, y_, 1., 1.); cr->fill(); @@ -147,7 +147,7 @@ void ColoredBar::draw() { double y_ = double( y); double x01 = x_/double(w-1); double y01 = y_/double(h-1); - colorProvider->colorForValue (y01, x01, colorCallerId, this); + colorProvider->colorForValue (y01, x01, CCET_BACKGROUND, colorCallerId, this); cr->set_source_rgb(ccRed, ccGreen, ccBlue); cr->rectangle(x_, y_, 1., 1.); cr->fill(); diff --git a/rtgui/colorprovider.h b/rtgui/colorprovider.h index a1f8e1085..f2ad08205 100644 --- a/rtgui/colorprovider.h +++ b/rtgui/colorprovider.h @@ -34,6 +34,12 @@ class ColorCaller { ColorProvider* colorProvider; public: + enum ElemType { + CCET_POINT, + CCET_VERTICAL_BAR, + CCET_HORIZONTAL_BAR, + CCET_BACKGROUND + }; double ccRed; double ccGreen; double ccBlue; @@ -52,7 +58,7 @@ class ColorProvider { public: virtual ~ColorProvider() {}; - virtual void colorForValue (double valX, double valY, int callerId, ColorCaller* caller) {}; + virtual void colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller* caller) {}; }; #endif diff --git a/rtgui/defringe.cc b/rtgui/defringe.cc index 4ff612d28..fd8460780 100644 --- a/rtgui/defringe.cc +++ b/rtgui/defringe.cc @@ -73,9 +73,13 @@ Defringe::~Defringe () { delete curveEditorPF; } -void Defringe::colorForValue (double valX, double valY, int callerId, ColorCaller *caller) { +void Defringe::colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller *caller) { float R, G, B; + + if (elemType==ColorCaller::CCET_VERTICAL_BAR) + valY = 0.5; + if (callerId == 1) { // ch Color::hsv2rgb01(float(valX), float(valY), 0.5f, R, G, B); } diff --git a/rtgui/defringe.h b/rtgui/defringe.h index fd60a1e99..ba4dba66b 100644 --- a/rtgui/defringe.h +++ b/rtgui/defringe.h @@ -53,7 +53,7 @@ class Defringe : public ToolParamBlock, public AdjusterListener, public Foldable void adjusterChanged (Adjuster* a, double newval); void enabledChanged (); - virtual void colorForValue (double valX, double valY, int callerId, ColorCaller* caller); + virtual void colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller* caller); }; diff --git a/rtgui/guiutils.h b/rtgui/guiutils.h index 3891b29b9..3dae41d1e 100644 --- a/rtgui/guiutils.h +++ b/rtgui/guiutils.h @@ -177,6 +177,11 @@ private: }; +typedef enum RTUpdatePolicy { + RTUP_STATIC, + RTUP_DYNAMIC +} eUpdatePolicy; + typedef enum RTOrientation { RTO_Left2Right, RTO_Bottom2Top, diff --git a/rtgui/hsvequalizer.cc b/rtgui/hsvequalizer.cc index e56683690..58e0781d0 100644 --- a/rtgui/hsvequalizer.cc +++ b/rtgui/hsvequalizer.cc @@ -134,10 +134,13 @@ void HSVEqualizer::curveChanged (CurveEditor* ce) { } } -void HSVEqualizer::colorForValue (double valX, double valY, int callerId, ColorCaller* caller) { +void HSVEqualizer::colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller* caller) { float r, g, b; + if (elemType==ColorCaller::CCET_VERTICAL_BAR) + valY = 0.5; + if (callerId == 1) { // Hue = f(Hue) float h = float((valY - 0.5) * 2. + valX); diff --git a/rtgui/hsvequalizer.h b/rtgui/hsvequalizer.h index 7ba04d883..b35bb1337 100644 --- a/rtgui/hsvequalizer.h +++ b/rtgui/hsvequalizer.h @@ -51,7 +51,7 @@ public: void setBatchMode (bool batchMode); void setEditProvider (EditDataProvider *provider); void autoOpenCurve (); - virtual void colorForValue (double valX, double valY, int callerId, ColorCaller* caller); + virtual void colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller* caller); //void adjusterChanged (Adjuster* a, double newval); }; diff --git a/rtgui/labcurve.cc b/rtgui/labcurve.cc index 244b603f7..e8ef7a3c2 100644 --- a/rtgui/labcurve.cc +++ b/rtgui/labcurve.cc @@ -489,9 +489,13 @@ void LCurve::adjusterChanged (Adjuster* a, double newval) { } } -void LCurve::colorForValue (double valX, double valY, int callerId, ColorCaller *caller) { +void LCurve::colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller *caller) { float R, G, B; + + if (elemType==ColorCaller::CCET_VERTICAL_BAR) + valY = 0.5; + if (callerId == 1) { // ch - main curve Color::hsv2rgb01(float(valX), float(valY), 0.5f, R, G, B); diff --git a/rtgui/labcurve.h b/rtgui/labcurve.h index 7be63adfe..573a6b587 100644 --- a/rtgui/labcurve.h +++ b/rtgui/labcurve.h @@ -75,7 +75,7 @@ class LCurve : public ToolParamBlock, public AdjusterListener, public FoldableTo void updateCurveBackgroundHistogram (LUTu & histToneCurve, LUTu & histLCurve, LUTu & histCCurve,/* LUTu & histCLurve, LUTu & histLLCurve,*/ LUTu & histLCAM, LUTu & histCCAM, LUTu & histRed, LUTu & histGreen, LUTu & histBlue, LUTu & histLuma); - virtual void colorForValue (double valX, double valY, int callerId, ColorCaller* caller); + virtual void colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller* caller); }; #endif diff --git a/rtgui/myflatcurve.cc b/rtgui/myflatcurve.cc index 7360bcb2d..60e116794 100644 --- a/rtgui/myflatcurve.cc +++ b/rtgui/myflatcurve.cc @@ -216,7 +216,7 @@ void MyFlatCurve::draw () { int coloredLineWidth = min( max(75,graphW)/75, 8 ); cr->set_line_width (coloredLineWidth); - colorProvider->colorForValue(curve.x.at(i), 0.5, colorCallerId, this); + colorProvider->colorForValue(curve.x.at(i), curve.y.at(i), CCET_VERTICAL_BAR, colorCallerId, this); cr->set_source_rgb (ccRed, ccGreen, ccBlue); if ( i==lit_point && (editedHandle&(FCT_EditedHandle_CPointUD|FCT_EditedHandle_CPoint|FCT_EditedHandle_CPointX)) ) { @@ -236,7 +236,7 @@ void MyFlatCurve::draw () { cr->set_line_width (2*coloredLineWidth); } - colorProvider->colorForValue(curve.x.at(i), curve.y.at(i), colorCallerId, this); + colorProvider->colorForValue(curve.x.at(i), curve.y.at(i), CCET_HORIZONTAL_BAR, colorCallerId, this); cr->set_source_rgb (ccRed, ccGreen, ccBlue); cr->move_to (double(graphX+1) , double(graphY-1) - innerH*curve.y.at(lit_point)); @@ -252,7 +252,7 @@ void MyFlatCurve::draw () { else { cr->set_source_rgb (0.5, 0.0, 0.0); - if ( (area&(FCT_Area_H|FCT_Area_V|FCT_Area_Point)) || editedHandle==FCT_EditedHandle_CPointUD ) { + if ((lit_point>-1) && ((area&(FCT_Area_H|FCT_Area_V|FCT_Area_Point)) || editedHandle==FCT_EditedHandle_CPointUD) ) { // draw the lit_point's vertical line if (editedHandle&(FCT_EditedHandle_CPointUD|FCT_EditedHandle_CPoint|FCT_EditedHandle_CPointY)) { cr->set_line_width (2.0); @@ -364,7 +364,7 @@ void MyFlatCurve::draw () { if (curve.x.at(i) != -1.) { if (i == lit_point) { if (colorProvider) { - colorProvider->colorForValue(curve.x.at(i), curve.y.at(i), colorCallerId, this); + colorProvider->colorForValue(curve.x.at(i), curve.y.at(i), CCET_POINT, colorCallerId, this); cr->set_source_rgb (ccRed, ccGreen, ccBlue); } else diff --git a/rtgui/thresholdadjuster.cc b/rtgui/thresholdadjuster.cc index 75ac57c83..6b413294b 100644 --- a/rtgui/thresholdadjuster.cc +++ b/rtgui/thresholdadjuster.cc @@ -211,11 +211,24 @@ void ThresholdAdjuster::setValue (double bottomLeft, double topLeft, double bott afterReset = false; } -inline void ThresholdAdjuster::getValue (Glib::ustring& bottom, Glib::ustring& top) { +void ThresholdAdjuster::getValue (double& bottom, double& top) { + tSelector.getPositions (bottom, top); +} +void ThresholdAdjuster::getValue (double& bottomLeft, double& topLeft, double& bottomRight, double& topRight) { + tSelector.getPositions (bottomLeft, topLeft, bottomRight, topRight); +} +void ThresholdAdjuster::getValue (int& bottom, int& top) { + tSelector.getPositions (bottom, top); +} +void ThresholdAdjuster::getValue (int& bottomLeft, int& topLeft, int& bottomRight, int& topRight) { + tSelector.getPositions (bottomLeft, topLeft, bottomRight, topRight); +} + +void ThresholdAdjuster::getValue (Glib::ustring& bottom, Glib::ustring& top) { tSelector.getPositions (bottom, top); } -inline void ThresholdAdjuster::getValue (Glib::ustring& bottomLeft, Glib::ustring& topLeft, Glib::ustring& bottomRight, Glib::ustring& topRight) { +void ThresholdAdjuster::getValue (Glib::ustring& bottomLeft, Glib::ustring& topLeft, Glib::ustring& bottomRight, Glib::ustring& topRight) { tSelector.getPositions (bottomLeft, topLeft, bottomRight, topRight); } @@ -228,7 +241,7 @@ bool ThresholdAdjuster::notifyListener () { return false; } -inline void ThresholdAdjuster::setBgCurveProvider (ThresholdCurveProvider* provider) { +void ThresholdAdjuster::setBgCurveProvider (ThresholdCurveProvider* provider) { tSelector.setBgCurveProvider(provider); } diff --git a/rtgui/thresholdadjuster.h b/rtgui/thresholdadjuster.h index 8b8c965ae..63cc02b74 100644 --- a/rtgui/thresholdadjuster.h +++ b/rtgui/thresholdadjuster.h @@ -119,6 +119,8 @@ class ThresholdAdjuster : public Gtk::VBox { void showEditedCB (); void block(bool isBlocked) { blocked = isBlocked; } void setBgGradient (const std::vector &milestones) { tSelector.setBgGradient (milestones); } + void setBgColorProvider (ColorProvider *cp, int i) { tSelector.setColorProvider(cp, i); } + void setUpdatePolicy (eUpdatePolicy policy) { tSelector.setUpdatePolicy(policy); } //void spinChanged (); void selectorChanged (); diff --git a/rtgui/thresholdselector.cc b/rtgui/thresholdselector.cc index c5786e3f4..b87233fe8 100644 --- a/rtgui/thresholdselector.cc +++ b/rtgui/thresholdselector.cc @@ -132,6 +132,7 @@ ThresholdSelector::ThresholdSelector(double minValue, double maxValue, double de void ThresholdSelector::initValues () { + updatePolicy = RTUP_STATIC; additionalTTip = ""; oldLitCursor = litCursor = TS_UNDEFINED; movedCursor = TS_UNDEFINED; @@ -141,6 +142,7 @@ void ThresholdSelector::initValues () { set_name("ThresholdSelector"); set_can_focus(false); set_app_paintable(true); + setDirty(true); updateTooltip(); } @@ -150,6 +152,8 @@ void ThresholdSelector::initValues () { void ThresholdSelector::setPositions (double bottom, double top) { setPositions(bottom, top, maxValBottom, maxValTop); + if (updatePolicy==RTUP_DYNAMIC) + setDirty(true); } /* @@ -165,6 +169,8 @@ void ThresholdSelector::setPositions (double bottomLeft, double topLeft, double positions[TS_TOPRIGHT] = topRight; if (different) { + if (updatePolicy==RTUP_DYNAMIC) + setDirty(true); sig_val_changed.emit(); updateTooltip(); queue_draw (); @@ -267,6 +273,7 @@ bool ThresholdSelector::on_expose_event(GdkEventExpose* event) { } else { + if (!separatedSliders) { double yStart = initalEq1 ? double(int(float(h)*1.5f/7.f))+1.5 : double(int(float(h)*5.5f/7.f))-0.5; double yEnd = initalEq1 ? double(int(float(h)*5.5f/7.f))-0.5 : double(int(float(h)*1.5f/7.f))+1.5; ThreshCursorId p[4]; @@ -287,6 +294,7 @@ bool ThresholdSelector::on_expose_event(GdkEventExpose* event) { cr->line_to (hb+hwslider+iw+0.5, yStart); } } + } if (is_sensitive() && bgGradient.size()>1) { // draw surrounding curve c = style->get_bg (state); @@ -444,6 +452,10 @@ bool ThresholdSelector::on_motion_notify_event (GdkEventMotion* event) { // set the new reference value for the next move tmpX = event->x; + // ask to redraw the background + if (updatePolicy==RTUP_DYNAMIC) + setDirty(true); + // update the tooltip updateTooltip(); @@ -597,11 +609,15 @@ void ThresholdSelector::reset () { positions[1] = defPos[1]; positions[2] = defPos[2]; positions[3] = defPos[3]; + + if (updatePolicy==RTUP_DYNAMIC) + setDirty(true); + updateTooltip(); queue_draw (); } -inline double ThresholdSelector::to01(ThreshCursorId cursorId) { +double ThresholdSelector::to01(ThreshCursorId cursorId) { double rVal; if (cursorId==TS_BOTTOMLEFT || cursorId==TS_BOTTOMRIGHT) @@ -613,15 +629,15 @@ inline double ThresholdSelector::to01(ThreshCursorId cursorId) { return rVal; } -inline void ThresholdSelector::setBgCurveProvider (ThresholdCurveProvider* provider) { +void ThresholdSelector::setBgCurveProvider (ThresholdCurveProvider* provider) { bgCurveProvider = provider; } -inline void ThresholdSelector::setSeparatedSliders(bool separated) { +void ThresholdSelector::setSeparatedSliders(bool separated) { separatedSliders = separated; } -inline bool ThresholdSelector::getSeparatedSliders() { +bool ThresholdSelector::getSeparatedSliders() { return separatedSliders; } diff --git a/rtgui/thresholdselector.h b/rtgui/thresholdselector.h index e17aca595..f4db16e2e 100644 --- a/rtgui/thresholdselector.h +++ b/rtgui/thresholdselector.h @@ -97,6 +97,7 @@ class ThresholdSelector : public Gtk::DrawingArea, public ColoredBar { double defPos[4]; double positions[4]; unsigned short wslider; + eUpdatePolicy updatePolicy; const static int hb = 3; // horizontal border const static int vb = 2; // vertical border @@ -194,6 +195,7 @@ class ThresholdSelector : public Gtk::DrawingArea, public ColoredBar { void styleChanged (const Glib::RefPtr& style); unsigned int getPrecision () { return precisionTop; } void reset (); + void setUpdatePolicy (eUpdatePolicy policy) { updatePolicy = policy; } void set_tooltip_markup(const Glib::ustring& markup); // this set_tooltip_text method is to set_tooltip_markup, and text can contain markups void set_tooltip_text(const Glib::ustring& text);