Cosmetic of the parametric curve editor + reset button added for the curves

This commit is contained in:
Hombre
2010-07-07 10:51:30 +02:00
parent 757fa3b54e
commit d95cf20c98
6 changed files with 78 additions and 10 deletions

View File

@@ -22,14 +22,22 @@
#include <guiutils.h>
#include <multilangmgr.h>
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);
@@ -38,6 +46,8 @@ CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false),
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,9 +57,9 @@ 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 ());
@@ -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());

View File

@@ -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<double>& c);
std::vector<double> getCurve ();
void curveChanged ();
void curveResetPressed ();
void shcChanged ();
void adjusterChanged (Adjuster* a, double newval);
bool adjusterEntered (GdkEventCrossing* ev, int ac);

View File

@@ -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);
}

View File

@@ -83,6 +83,7 @@ class MyCurve : public Gtk::DrawingArea {
void notifyListener ();
void setActiveParam (int ac);
void updateBackgroundHistogram (unsigned int* hist);
void reset ();
};
#endif

View File

@@ -19,6 +19,7 @@
#include <shcselector.h>
#include <iomanip>
#include <mycurve.h>
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<Pango::Layout> 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<Gtk::Style>& style) {
queue_draw ();
}
void SHCSelector::reset () { // : movingPosition(-1), cl(NULL) {
positions[0] = 0.25;
positions[1] = 0.5;
positions[2] = 0.75;
queue_draw ();
}

View File

@@ -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<Gtk::Style>& style);
void reset ();
};
#endif