From d6766afc2fac152c360195516d1578818468186b Mon Sep 17 00:00:00 2001 From: Hombre Date: Tue, 5 Apr 2011 01:07:50 +0200 Subject: [PATCH] Better handling of the autoresize feature of the curve editors. Not ideal yet, but way better. --- rtengine/procparams.cc | 5 ++++ rtgui/curveeditorgroup.h | 1 + rtgui/diagonalcurveeditorsubgroup.cc | 39 +++++++++++++-------------- rtgui/diagonalcurveeditorsubgroup.h | 4 +-- rtgui/flatcurveeditorsubgroup.cc | 14 +++++----- rtgui/flatcurveeditorsubgroup.h | 4 +-- rtgui/mycurve.cc | 2 +- rtgui/mycurve.h | 15 ++++++++--- rtgui/mydiagonalcurve.cc | 22 +++++++++++++-- rtgui/mydiagonalcurve.h | 1 - rtgui/myflatcurve.cc | 40 +++++++++++++--------------- rtgui/myflatcurve.h | 11 -------- 12 files changed, 87 insertions(+), 71 deletions(-) diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 78dc66b38..f57fdfc9f 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -64,6 +65,7 @@ void ProcParams::setDefaults () { toneCurve.hlcomprthresh = 0; toneCurve.shcompr = 25; toneCurve.curve.clear (); + toneCurve.curve.push_back(DCT_Linear); labCurve.brightness = 0; labCurve.contrast = 0; @@ -72,8 +74,11 @@ void ProcParams::setDefaults () { labCurve.enable_saturationlimiter = false; labCurve.saturationlimit = 40; labCurve.lcurve.clear (); + labCurve.lcurve.push_back(DCT_Linear); labCurve.acurve.clear (); + labCurve.acurve.push_back(DCT_Linear); labCurve.bcurve.clear (); + labCurve.bcurve.push_back(DCT_Linear); sharpening.enabled = true; sharpening.radius = 1.0; diff --git a/rtgui/curveeditorgroup.h b/rtgui/curveeditorgroup.h index 97a582e7c..b84347b7c 100644 --- a/rtgui/curveeditorgroup.h +++ b/rtgui/curveeditorgroup.h @@ -109,6 +109,7 @@ protected: virtual void switchGUI() = 0; virtual void removeEditor () = 0; virtual const std::vector getCurveFromGUI (int type) = 0; + }; #endif diff --git a/rtgui/diagonalcurveeditorsubgroup.cc b/rtgui/diagonalcurveeditorsubgroup.cc index 111ff93e5..497243bf8 100644 --- a/rtgui/diagonalcurveeditorsubgroup.cc +++ b/rtgui/diagonalcurveeditorsubgroup.cc @@ -40,23 +40,22 @@ DiagonalCurveEditorSubGroup::DiagonalCurveEditorSubGroup (CurveEditorGroup* prt) // custom curve customCurveBox = new Gtk::HBox (); - Gtk::HBox* tmpa = Gtk::manage (new Gtk::HBox ()); + customCurveBox->set_spacing(4); customCurve = Gtk::manage (new MyDiagonalCurve ()); - //Gtk::AspectFrame* af = Gtk::manage (new Gtk::AspectFrame ("",Gtk::ALIGN_CENTER,Gtk::ALIGN_CENTER,1,false)); customCurve->set_size_request (GRAPH_SIZE+2*RADIUS, GRAPH_SIZE+2*RADIUS); customCurve->setType (DCT_Spline); //customCurve->set_tooltip_text (M("CURVEEDITOR_TOOLTIPMOVESPEED")); - tmpa->pack_start (*customCurve, true, false, 4); - customCurveBox->pack_start (*tmpa, true, true,4); + customCurveBox->pack_start (*customCurve, Gtk::PACK_EXPAND_WIDGET, 0); Gtk::VBox* custombbox = Gtk::manage (new Gtk::VBox ()); + custombbox->set_spacing(4); saveCustom = Gtk::manage (new Gtk::Button ()); saveCustom->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-save"), Gtk::ICON_SIZE_BUTTON))); loadCustom = Gtk::manage (new Gtk::Button ()); loadCustom->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-open"), Gtk::ICON_SIZE_BUTTON))); - custombbox->pack_end (*saveCustom, Gtk::PACK_SHRINK, 4); - custombbox->pack_end (*loadCustom, Gtk::PACK_SHRINK, 4); + custombbox->pack_end (*saveCustom, Gtk::PACK_SHRINK, 0); + custombbox->pack_end (*loadCustom, Gtk::PACK_SHRINK, 0); customCurveBox->pack_end (*custombbox, Gtk::PACK_SHRINK, 0); customCurveBox->show_all (); @@ -68,24 +67,22 @@ DiagonalCurveEditorSubGroup::DiagonalCurveEditorSubGroup (CurveEditorGroup* prt) // NURBS curve NURBSCurveBox = new Gtk::HBox (); - Gtk::HBox* tmpb = Gtk::manage (new Gtk::HBox ()); + NURBSCurveBox->set_spacing(4); NURBSCurve = Gtk::manage (new MyDiagonalCurve ()); - //Gtk::AspectFrame* af = Gtk::manage (new Gtk::AspectFrame ("",Gtk::ALIGN_CENTER,Gtk::ALIGN_CENTER,1,false)); - //af->add (*customCurve); NURBSCurve->set_size_request (GRAPH_SIZE+2*RADIUS, GRAPH_SIZE+2*RADIUS); NURBSCurve->setType (DCT_NURBS); //customCurve->set_tooltip_text (M("CURVEEDITOR_TOOLTIPMOVESPEED")); - tmpb->pack_start (*NURBSCurve, true, false, 4); - NURBSCurveBox->pack_start (*tmpb, true, true,4); + NURBSCurveBox->pack_start (*NURBSCurve, Gtk::PACK_EXPAND_WIDGET, 0); Gtk::VBox* NURBSbbox = Gtk::manage (new Gtk::VBox ()); + NURBSbbox->set_spacing(4); saveNURBS = Gtk::manage (new Gtk::Button ()); saveNURBS->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-save"), Gtk::ICON_SIZE_BUTTON))); loadNURBS = Gtk::manage (new Gtk::Button ()); loadNURBS->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-open"), Gtk::ICON_SIZE_BUTTON))); - NURBSbbox->pack_end (*saveNURBS, Gtk::PACK_SHRINK, 4); - NURBSbbox->pack_end (*loadNURBS, Gtk::PACK_SHRINK, 4); + NURBSbbox->pack_end (*saveNURBS, Gtk::PACK_SHRINK, 0); + NURBSbbox->pack_end (*loadNURBS, Gtk::PACK_SHRINK, 0); NURBSCurveBox->pack_end (*NURBSbbox, Gtk::PACK_SHRINK, 0); NURBSCurveBox->show_all (); @@ -97,21 +94,18 @@ DiagonalCurveEditorSubGroup::DiagonalCurveEditorSubGroup (CurveEditorGroup* prt) // parametric curve paramCurveBox = new Gtk::VBox (); + paramCurveBox->set_spacing(4); paramCurve = Gtk::manage (new MyDiagonalCurve ()); Gtk::Table* paramctab = Gtk::manage (new Gtk::Table (2,1)); - //Gtk::AspectFrame* afp = Gtk::manage (new Gtk::AspectFrame ("",Gtk::ALIGN_CENTER,Gtk::ALIGN_CENTER,1,false)); paramCurve->set_size_request (GRAPH_SIZE+2*RADIUS, GRAPH_SIZE+2*RADIUS); paramCurve->setType (DCT_Parametric); shcSelector = Gtk::manage (new SHCSelector ()); shcSelector->set_size_request (GRAPH_SIZE, 20); - paramctab->attach (*paramCurve, 0, 1, 0, 1, Gtk::FILL, Gtk::SHRINK, 4, 4); - paramctab->attach (*shcSelector, 0, 1, 1, 2, Gtk::FILL, Gtk::SHRINK, RADIUS+4, 0); + paramctab->attach (*paramCurve, 0, 1, 0, 1, Gtk::FILL, Gtk::SHRINK, 0, 0); + paramctab->attach (*shcSelector, 0, 1, 1, 2, Gtk::FILL, Gtk::SHRINK, RADIUS, 0); - Gtk::HBox* tmpc = Gtk::manage (new Gtk::HBox ()); - tmpc->pack_start (*paramctab, true, false); - - paramCurveBox->pack_start (*tmpc, true, true); + paramCurveBox->pack_start (*paramctab, Gtk::PACK_EXPAND_WIDGET, 0); highlights = Gtk::manage (new Adjuster (M("CURVEEDITOR_HIGHLIGHTS"), -100, 100, 1, 0)); lights = Gtk::manage (new Adjuster (M("CURVEEDITOR_LIGHTS"), -100, 100, 1, 0)); @@ -203,6 +197,8 @@ void DiagonalCurveEditorSubGroup::switchGUI() { case (DCT_Spline): customCurve->setPoints (dCurve->customCurveEd); parent->pack_start (*customCurveBox); + customCurveBox->check_resize(); + customCurve->forceResize(); break; case (DCT_Parametric): paramCurve->setPoints (dCurve->paramCurveEd); @@ -216,10 +212,13 @@ void DiagonalCurveEditorSubGroup::switchGUI() { darks->setValue (dCurve->paramCurveEd.at(6)); shadows->setValue (dCurve->paramCurveEd.at(7)); parent->pack_start (*paramCurveBox); + paramCurve->forceResize(); break; case (DCT_NURBS): NURBSCurve->setPoints (dCurve->NURBSCurveEd); parent->pack_start (*NURBSCurveBox); + NURBSCurveBox->check_resize(); + NURBSCurve->forceResize(); break; default: // (DCT_Linear, DCT_Unchanged) // ... do nothing diff --git a/rtgui/diagonalcurveeditorsubgroup.h b/rtgui/diagonalcurveeditorsubgroup.h index 755a9a0e3..4edfce825 100644 --- a/rtgui/diagonalcurveeditorsubgroup.h +++ b/rtgui/diagonalcurveeditorsubgroup.h @@ -28,7 +28,7 @@ class DiagonalCurveEditorSubGroup : public CurveEditorSubGroup, public SHCListen friend class DiagonalCurveEditor; -private: +protected: Gtk::HBox* customCurveBox; Gtk::VBox* paramCurveBox; Gtk::HBox* NURBSCurveBox; @@ -58,7 +58,7 @@ public: virtual void updateBackgroundHistogram (CurveEditor* ce); virtual void setColorProvider (ColorProvider* p); -private: +protected: void storeCurveValues (CurveEditor* ce, const std::vector& p); void storeDisplayedCurve (); void restoreDisplayedHistogram (); diff --git a/rtgui/flatcurveeditorsubgroup.cc b/rtgui/flatcurveeditorsubgroup.cc index d59bb2f4e..c564395db 100644 --- a/rtgui/flatcurveeditorsubgroup.cc +++ b/rtgui/flatcurveeditorsubgroup.cc @@ -38,23 +38,21 @@ FlatCurveEditorSubGroup::FlatCurveEditorSubGroup (CurveEditorGroup* prt) { // ControlPoints curve CPointsCurveBox = new Gtk::HBox (); - //Gtk::HBox* tmpb = Gtk::manage (new Gtk::HBox ()); + CPointsCurveBox->set_spacing(4); CPointsCurve = Gtk::manage (new MyFlatCurve ()); - //Gtk::AspectFrame* af = Gtk::manage (new Gtk::AspectFrame ("",Gtk::ALIGN_CENTER,Gtk::ALIGN_CENTER,1,false)); //CPointsCurve->set_size_request (GRAPH_SIZE+2*RADIUS+1, GRAPH_SIZE+2*RADIUS+1); CPointsCurve->setType (FCT_MinMaxCPoints); - //tmpb->pack_start (*CPointsCurve, Gtk::PACK_EXPAND_WIDGET, 4); - CPointsCurveBox->pack_start (*CPointsCurve, Gtk::PACK_EXPAND_WIDGET,4); - //CPointsCurveBox->pack_start (*tmpb, Gtk::PACK_EXPAND_WIDGET,4); + CPointsCurveBox->pack_start (*CPointsCurve, Gtk::PACK_EXPAND_WIDGET, 0); Gtk::VBox* CPointsbbox = Gtk::manage (new Gtk::VBox ()); + CPointsbbox->set_spacing(4); saveCPoints = Gtk::manage (new Gtk::Button ()); saveCPoints->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-save"), Gtk::ICON_SIZE_BUTTON))); loadCPoints = Gtk::manage (new Gtk::Button ()); loadCPoints->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-open"), Gtk::ICON_SIZE_BUTTON))); - CPointsbbox->pack_end (*saveCPoints, Gtk::PACK_SHRINK, 4); - CPointsbbox->pack_end (*loadCPoints, Gtk::PACK_SHRINK, 4); + CPointsbbox->pack_end (*saveCPoints, Gtk::PACK_SHRINK, 0); + CPointsbbox->pack_end (*loadCPoints, Gtk::PACK_SHRINK, 0); CPointsCurveBox->pack_end (*CPointsbbox, Gtk::PACK_SHRINK, 0); CPointsCurveBox->show_all (); @@ -103,6 +101,8 @@ void FlatCurveEditorSubGroup::switchGUI() { case (FCT_MinMaxCPoints): CPointsCurve->setPoints (dCurve->controlPointsCurveEd); parent->pack_start (*CPointsCurveBox); + CPointsCurveBox->check_resize(); + CPointsCurve->forceResize(); break; default: // (DCT_Linear, DCT_Unchanged) // ... do nothing diff --git a/rtgui/flatcurveeditorsubgroup.h b/rtgui/flatcurveeditorsubgroup.h index 62d6b2c62..f94b7ca23 100644 --- a/rtgui/flatcurveeditorsubgroup.h +++ b/rtgui/flatcurveeditorsubgroup.h @@ -28,7 +28,7 @@ class FlatCurveEditorSubGroup: public CurveEditorSubGroup { friend class FlatCurveEditor; -private: +protected: Gtk::HBox* CPointsCurveBox; MyFlatCurve* CPointsCurve; @@ -44,7 +44,7 @@ public: //virtual void updateBackgroundHistogram (CurveEditor* ce); virtual void setColorProvider (ColorProvider* p); -private: +protected: void storeCurveValues (CurveEditor* ce, const std::vector& p); void storeDisplayedCurve (); void restoreDisplayedHistogram (); diff --git a/rtgui/mycurve.cc b/rtgui/mycurve.cc index e91a75856..167971897 100644 --- a/rtgui/mycurve.cc +++ b/rtgui/mycurve.cc @@ -30,7 +30,7 @@ MyCurve::MyCurve () : listener(NULL) { buttonPressed = false; snapTo = ST_None; colorProvider = NULL; - sized = false; + sized = RS_Pending; set_extension_events(Gdk::EXTENSION_EVENTS_ALL); add_events(Gdk::EXPOSURE_MASK | Gdk::POINTER_MOTION_MASK | Gdk::POINTER_MOTION_HINT_MASK | Gdk::ENTER_NOTIFY_MASK | Gdk::LEAVE_NOTIFY_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK); diff --git a/rtgui/mycurve.h b/rtgui/mycurve.h index 02167af52..e1dfdc91c 100644 --- a/rtgui/mycurve.h +++ b/rtgui/mycurve.h @@ -41,6 +41,13 @@ enum SnapToType { ST_Identity, // Point snapped to the identity curve ST_Neighbors // Point snapped to the neighbor points }; + +enum ResizeState { + RS_Pending = 1, // Resize has to occure + RS_Done = 2, // Resize has been done + RS_Force = 4 // Resize has to occure even without CONFIGURE event +}; + class MyCurveIdleHelper; class MyCurve : public Gtk::DrawingArea { @@ -64,7 +71,10 @@ class MyCurve : public Gtk::DrawingArea { bool buttonPressed; enum SnapToType snapTo; MyCurveIdleHelper* mcih; - bool sized; + enum ResizeState sized; + + virtual std::vector get_vector (int veclen) = 0; + int getGraphMinSize() { return GRAPH_SIZE + RADIUS + 1; } public: MyCurve (); @@ -74,12 +84,11 @@ class MyCurve : public Gtk::DrawingArea { void setColorProvider (ColorProvider* cp) { colorProvider = cp; } void notifyListener (); void updateBackgroundHistogram (unsigned int* hist) {return;} ; + void forceResize() { sized = RS_Force; } virtual std::vector getPoints () = 0; virtual void setPoints (const std::vector& p) = 0; virtual bool handleEvents (GdkEvent* event) = 0; virtual void reset () = 0; - protected: - virtual std::vector get_vector (int veclen) = 0; }; class MyCurveIdleHelper { diff --git a/rtgui/mydiagonalcurve.cc b/rtgui/mydiagonalcurve.cc index 913793ae9..4255be0c1 100644 --- a/rtgui/mydiagonalcurve.cc +++ b/rtgui/mydiagonalcurve.cc @@ -243,6 +243,13 @@ void MyDiagonalCurve::draw (int handle) { get_window()->draw_drawable (style->get_fg_gc (state), pixmap, 0, 0, 0, 0, innerWidth + RADIUS * 2, innerHeight + RADIUS * 2); } +/*void MyDiagonalCurve::graphSizeRequest (Gtk::Requisition* req) { + req->width = getGraphMinSize(); + // The real height request should take care of the presence of the vertical + // scroll bar and its width + req->height = sized ? getGraphMinSize() : get_allocation().get_width(); +}*/ + bool MyDiagonalCurve::handleEvents (GdkEvent* event) { CursorShape new_type = cursor_type; @@ -263,13 +270,24 @@ bool MyDiagonalCurve::handleEvents (GdkEvent* event) { return false; switch (event->type) { - case Gdk::CONFIGURE: + case Gdk::CONFIGURE: { + // Happen when the the window is resized + if (sized & (RS_Pending | RS_Force)) { + int size = get_allocation().get_width(); + set_size_request(-1, size); + sized = RS_Done; + } if (pixmap) pixmap.clear (); retval = true; break; - + } case Gdk::EXPOSE: + if (sized & (RS_Pending | RS_Force)) { + int size = get_allocation().get_width(); + set_size_request(-1, size); + } + sized = RS_Pending; if (!pixmap) { pixmap = Gdk::Pixmap::create (get_window(), get_allocation().get_width(), get_allocation().get_height()); interpolate (); diff --git a/rtgui/mydiagonalcurve.h b/rtgui/mydiagonalcurve.h index 3a7764b31..9aee97358 100644 --- a/rtgui/mydiagonalcurve.h +++ b/rtgui/mydiagonalcurve.h @@ -77,7 +77,6 @@ class MyDiagonalCurve : public MyCurve { void setActiveParam (int ac); void reset (); void updateBackgroundHistogram (unsigned int* hist); - }; #endif diff --git a/rtgui/myflatcurve.cc b/rtgui/myflatcurve.cc index 015a79266..88bcb40e9 100644 --- a/rtgui/myflatcurve.cc +++ b/rtgui/myflatcurve.cc @@ -195,7 +195,7 @@ void MyFlatCurve::draw () { double x = (double)RADIUS+0.5 + innerWidth*curve.x[i]; if (i == lit_point && editedHandle&(FCT_EditedHandle_CPointUD|FCT_EditedHandle_CPoint|FCT_EditedHandle_CPointX)) { - cr->set_line_width (2.0); + cr->set_line_width (4.0); } cr->move_to (x, (double)RADIUS+0.5); cr->line_to (x, (double)RADIUS+0.5 + innerHeight); @@ -208,7 +208,7 @@ void MyFlatCurve::draw () { if (area&(FCT_Area_H|FCT_Area_V|FCT_Area_Point) || editedHandle==FCT_EditedHandle_CPointUD) { if (editedHandle&(FCT_EditedHandle_CPointUD|FCT_EditedHandle_CPoint|FCT_EditedHandle_CPointY)) { - cr->set_line_width (2.0); + cr->set_line_width (4.0); } colorProvider->colorForValue(curve.x[i], curve.y[i]); @@ -467,7 +467,6 @@ bool MyFlatCurve::getHandles(int n) { return true; } - bool MyFlatCurve::handleEvents (GdkEvent* event) { CursorShape new_type = cursor_type; @@ -489,11 +488,11 @@ bool MyFlatCurve::handleEvents (GdkEvent* event) { switch (event->type) { case Gdk::CONFIGURE: { - GdkEventConfigure* cEvent = (GdkEventConfigure*)event; - if (!sized) { + // Happen when the the window is resized + if (sized & (RS_Pending | RS_Force)) { int size = get_allocation().get_width(); - set_size_request(size, size); - sized = true; + set_size_request(-1, size); + sized = RS_Done; } if (pixmap) pixmap.clear (); @@ -501,10 +500,11 @@ bool MyFlatCurve::handleEvents (GdkEvent* event) { break; } case Gdk::EXPOSE: - if (!sized) { - set_size_request(GRAPH_SIZE + RADIUS + 1, GRAPH_SIZE + RADIUS + 1); + if (sized & (RS_Pending | RS_Force)) { + int size = get_allocation().get_width(); + set_size_request(-1, size); } - sized = false; + sized = RS_Pending; if (!pixmap) { pixmap = Gdk::Pixmap::create (get_window(), get_allocation().get_width(), get_allocation().get_height()); interpolate (); @@ -694,8 +694,15 @@ bool MyFlatCurve::handleEvents (GdkEvent* event) { case Gdk::MOTION_NOTIFY: if (curve.type == FCT_Linear || curve.type == FCT_MinMaxCPoints) { + + int leftNeigborPoint = -1; + int rightNeigborPoint = -1; + double leftNeigborY = -1.; + double rightNeigborY = -1.; + int previous_lit_point = lit_point; enum MouseOverAreas prevArea = area; + // get the pointer position getCursorPosition(event); getMouseOverArea(); @@ -1092,7 +1099,7 @@ void MyFlatCurve::getCursorPosition(GdkEvent* event) { void MyFlatCurve::getMouseOverArea () { // When dragging an element, editedHandle keep its value - if (editedHandle == FCT_EditedHandle_None) { + if (editedHandle == FCT_EditedHandle_None) { // && curve.type!=Parametric double minDist = 1000; // used to find out the point pointed by the cursor (over it) double minDistX = 1000; // used to find out the closest point @@ -1103,17 +1110,6 @@ void MyFlatCurve::getMouseOverArea () { // NB: this function assume that the graph's shape is a square - //if (curve.type!=Parametric) { - - // we first check first if the cursor is still over a tangent handle - /*if (area = (FCT_Area_LeftTan|FCT_Area_RightTan)) { - if (still over a tangent handle) { - - } - area = FCT_Area_None; - return; - }*/ - // Check if the cursor is over a tangent handle if (tanHandlesDisplayed) { diff --git a/rtgui/myflatcurve.h b/rtgui/myflatcurve.h index 5d5de7621..9cf81641e 100644 --- a/rtgui/myflatcurve.h +++ b/rtgui/myflatcurve.h @@ -65,15 +65,6 @@ class FlatCurveDescr { rightTangent; // Range: [0.0 - 1.0], where 1.0 = distance from this to next point }; -class RectArea { - - public: - double top; - double left; - double bottom; - double right; -}; - class HandlePosition { public: @@ -102,8 +93,6 @@ class MyFlatCurve : public MyCurve { double minDistanceX; // X minimal distance before point suppression double minDistanceY; // Y minimal distance before point suppression double deletedPointX; // Backup of the X value of the edited point, when deleted while being dragged - //RectArea leftTanHandle; // XY coordinate if the upper left and bottom right corner of the left tangent handle - //RectArea rightTanHandle; // XY coordinate if the upper left and bottom right corner of the right tangent handle HandlePosition leftTanHandle; // XY coordinate if the upper left and bottom right corner of the left tangent handle HandlePosition rightTanHandle; // XY coordinate if the upper left and bottom right corner of the right tangent handle bool tanHandlesDisplayed; // True if the tangent handles are displayed