diff --git a/rtgui/curveeditor.cc b/rtgui/curveeditor.cc index ebac4b8b6..5044fc1c6 100644 --- a/rtgui/curveeditor.cc +++ b/rtgui/curveeditor.cc @@ -22,14 +22,22 @@ #include #include +extern Glib::ustring argv0; + CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false), curveTypeIx(-1) { Gtk::HBox* tsbox = Gtk::manage (new Gtk::HBox ()); Gtk::Label* tslab = Gtk::manage (new Gtk::Label (M("CURVEEDITOR_TYPE"))); curveType = Gtk::manage (new Gtk::ComboBoxText ()); - + curve_reset = Gtk::manage (new Gtk::Button ()); + curve_reset->add (*Gtk::manage (new Gtk::Image (argv0+"/images/undo.png"))); + curve_reset->set_relief (Gtk::RELIEF_NONE); + curve_reset->set_border_width (0); + curve_reset->set_tooltip_text (M("CURVEEDITOR_TOOLTIPLINEAR")); + tsbox->pack_start (*tslab, Gtk::PACK_SHRINK, 8); tsbox->pack_start (*curveType); + tsbox->pack_start (*curve_reset, Gtk::PACK_SHRINK, 0); pack_start (*tsbox); @@ -37,7 +45,9 @@ CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false), curveType->append_text (M("CURVEEDITOR_PARAMETRIC")); curveType->append_text (M("CURVEEDITOR_CUSTOM")); curveType->set_active (0); - + + curve_reset->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::curveResetPressed) ); + // custom curve customCurveBox = new Gtk::VBox (); Gtk::HBox* tmpa = Gtk::manage (new Gtk::HBox ()); @@ -47,16 +57,16 @@ CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false), //af->add (*customCurve); customCurve->set_size_request (GRAPH_SIZE+2*RADIUS, GRAPH_SIZE+2*RADIUS); customCurve->setType (Spline); + //customCurve->set_tooltip_text (M("CURVEEDITOR_TOOLTIPMOVESPEED")); tmpa->pack_start (*customCurve, true, false, 4); customCurveBox->pack_start (*tmpa, true, true,4); - //customCurveBox->set_size_request (0, -1); Gtk::HBox* bbox = Gtk::manage (new Gtk::HBox ()); save = Gtk::manage (new Gtk::Button ()); save->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-save"), Gtk::ICON_SIZE_BUTTON))); load = Gtk::manage (new Gtk::Button ()); load->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-open"), Gtk::ICON_SIZE_BUTTON))); - + bbox->pack_end (*save, Gtk::PACK_EXPAND_WIDGET, 4); bbox->pack_end (*load, Gtk::PACK_EXPAND_WIDGET, 4); @@ -67,7 +77,7 @@ CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false), load->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::loadPressed) ); save->set_tooltip_text (M("CURVEEDITOR_TOOLTIPSAVE")); load->set_tooltip_text (M("CURVEEDITOR_TOOLTIPLOAD")); - + // parametric curve paramCurveBox = new Gtk::VBox (); paramCurve = Gtk::manage (new MyCurve ()); @@ -79,8 +89,8 @@ CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false), shcSelector = Gtk::manage (new SHCSelector ()); shcSelector->set_size_request (GRAPH_SIZE, 20); - paramctab->attach (*paramCurve, 0, 1, 0, 1, Gtk::FILL, Gtk::SHRINK, RADIUS+2, RADIUS+2); - paramctab->attach (*shcSelector, 0, 1, 1, 2, Gtk::FILL, Gtk::SHRINK, RADIUS+2, 2); + 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); Gtk::HBox* tmpb = Gtk::manage (new Gtk::HBox ()); tmpb->pack_start (*paramctab, true, false); @@ -331,6 +341,25 @@ void CurveEditor::curveChanged () { cl->curveChanged (); } +void CurveEditor::curveResetPressed () { + switch (curveTypeIx) { + case 2 : // Custom + customCurve->reset (); + break; + case 1 : // Parametric + highlights->resetPressed(); + lights->resetPressed(); + darks->resetPressed(); + shadows->resetPressed(); + shcSelector->reset(); + paramCurve->reset (); + break; + default: + break; + } + curveChanged (); +} + void CurveEditor::shcChanged () { paramCurve->setPoints (getCurve()); diff --git a/rtgui/curveeditor.h b/rtgui/curveeditor.h index 33fcabe3c..d989e4929 100644 --- a/rtgui/curveeditor.h +++ b/rtgui/curveeditor.h @@ -27,6 +27,7 @@ class CurveEditor : public Gtk::VBox, public CurveListener, public SHCListener, public AdjusterListener { Gtk::ComboBoxText* curveType; + Gtk::Button* curve_reset; Gtk::VBox* paramCurveBox; Gtk::VBox* customCurveBox; @@ -68,6 +69,7 @@ class CurveEditor : public Gtk::VBox, public CurveListener, public SHCListener, void setCurve (const std::vector& c); std::vector getCurve (); void curveChanged (); + void curveResetPressed (); void shcChanged (); void adjusterChanged (Adjuster* a, double newval); bool adjusterEntered (GdkEventCrossing* ev, int ac); diff --git a/rtgui/mycurve.cc b/rtgui/mycurve.cc index 9f3b7b1e8..e7baafdeb 100644 --- a/rtgui/mycurve.cc +++ b/rtgui/mycurve.cc @@ -603,3 +603,26 @@ void MyCurve::updateBackgroundHistogram (unsigned int* hist) { } +void MyCurve::reset() { + int width = get_allocation().get_width() - RADIUS * 2; + int height = get_allocation().get_height() - RADIUS * 2; + + switch (curve.type) { + case Spline : + curve.x.clear(); + curve.y.clear(); + curve.x.push_back(0.); + curve.y.push_back(0.); + curve.x.push_back(1.); + curve.y.push_back(1.); + grab_point = -1; + lit_point = -1; + interpolate (width, height); + break; + case Parametric : + // Nothing to do (?) + default: + break; + } + //draw(width, height, -1); +} diff --git a/rtgui/mycurve.h b/rtgui/mycurve.h index 0e297be31..21802127e 100644 --- a/rtgui/mycurve.h +++ b/rtgui/mycurve.h @@ -83,6 +83,7 @@ class MyCurve : public Gtk::DrawingArea { void notifyListener (); void setActiveParam (int ac); void updateBackgroundHistogram (unsigned int* hist); + void reset (); }; #endif diff --git a/rtgui/shcselector.cc b/rtgui/shcselector.cc index 0b699e052..c11b67b10 100644 --- a/rtgui/shcselector.cc +++ b/rtgui/shcselector.cc @@ -19,6 +19,7 @@ #include #include +#include SHCSelector::SHCSelector() : movingPosition(-1), cl(NULL) { @@ -99,18 +100,22 @@ bool SHCSelector::on_expose_event(GdkEventExpose* event) { cr->set_line_width (0.5); if (movingPosition >= 0) { int i = movingPosition; + int offset; + int layout_width, layout_height; Glib::RefPtr layout = create_pango_layout(Glib::ustring::format(std::setprecision(2), positions[i])); - cr->move_to (w*positions[i]+wslider/2-0.5, 0); + layout->get_pixel_size(layout_width, layout_height); + offset = positions[i] > 0.5 ? -layout_width-1-wslider/2 : 1+wslider/2; + cr->move_to (w*positions[i]+offset-0.5, 0); cr->set_source_rgb (bgc.get_red_p(), bgc.get_green_p(), bgc.get_blue_p()); layout->add_to_cairo_context (cr); cr->fill_preserve (); cr->stroke (); - cr->move_to (w*positions[i]+wslider/2+0.5, 1); + cr->move_to (w*positions[i]+offset+0.5, 1); layout->add_to_cairo_context (cr); cr->fill_preserve (); cr->stroke (); cr->set_source_rgb (fgc.get_red_p(), fgc.get_green_p(), fgc.get_blue_p()); - cr->move_to (w*positions[i]+wslider/2, 0.5); + cr->move_to (w*positions[i]+offset, 0.5); layout->add_to_cairo_context (cr); cr->fill_preserve (); cr->stroke (); @@ -164,3 +169,10 @@ void SHCSelector::styleChanged (const Glib::RefPtr& style) { queue_draw (); } + +void SHCSelector::reset () { // : movingPosition(-1), cl(NULL) { + positions[0] = 0.25; + positions[1] = 0.5; + positions[2] = 0.75; + queue_draw (); +} diff --git a/rtgui/shcselector.h b/rtgui/shcselector.h index 3199e4ae9..17e177a64 100644 --- a/rtgui/shcselector.h +++ b/rtgui/shcselector.h @@ -55,6 +55,7 @@ class SHCSelector : public Gtk::DrawingArea { bool on_button_release_event (GdkEventButton* event); bool on_motion_notify_event (GdkEventMotion* event); void styleChanged (const Glib::RefPtr& style); + void reset (); }; #endif