Patch from issue 1359: "Munsell correction - Lab adjustements" credits: jdesmis

Bundled new features besid the Lab tool enhancement (by jdesmis) :
   - curve to control skin tones in vibrance tool, credits: jdesmis
   - right click over SHCSelector (below the parametric curve) to reset to default values, credits: Hombre
   - colored bars around curves, credits: Hombre
This commit is contained in:
natureh
2012-07-21 00:47:24 +02:00
parent 61f287b364
commit caf53b95a3
75 changed files with 4905 additions and 3336 deletions

View File

@@ -18,14 +18,34 @@
*/
#include "shcselector.h"
#include "multilangmgr.h"
#include <iomanip>
#include "mycurve.h"
SHCSelector::SHCSelector() : movingPosition(-1), cl(NULL) {
SHCSelector::SHCSelector() : ColoredBar(RTO_Left2Right), movingPosition(-1), cl(NULL) {
positions[0] = 0.25;
positions[1] = 0.5;
positions[2] = 0.75;
positions[0] = defaults[0] = 0.25;
positions[1] = defaults[1] = 0.5;
positions[2] = defaults[2] = 0.75;
leftMargin = RADIUS;
rightMargin = RADIUS;
// TODO: This is a hack :) ; change this name to a specific one and create a new entry in all gtkrc theme files
set_name("ThresholdSelector");
set_can_focus(false);
set_size_request (-1, 12);
set_tooltip_text(M("SHCSELECTOR_TOOLTIP"));
}
void SHCSelector::setMargins(int left, int right) {
leftMargin = left;
rightMargin = right;
}
void SHCSelector::setDefaults (double spos, double cpos, double hpos) {
defaults[0] = spos;
defaults[1] = cpos;
defaults[2] = hpos;
}
void SHCSelector::setPositions (double spos, double cpos, double hpos) {
@@ -53,46 +73,64 @@ void SHCSelector::on_realize() {
bool SHCSelector::on_expose_event(GdkEventExpose* event) {
Gdk::Color c;
Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context();
int w = get_width () - RADIUS*2;
int w = get_width () - leftMargin - rightMargin;
int h = get_height ();
wslider = h *2.0 / 5.0;
wslider = std::max(int(h / 5), 10);
double hwslider = double(wslider)/2.;
Gdk::Color bgc = get_style()->get_bg (Gtk::STATE_NORMAL);
Gdk::Color fgc = get_style()->get_text (Gtk::STATE_NORMAL);
Gtk::StateType state = !is_sensitive() ? Gtk::STATE_INSENSITIVE : Gtk::STATE_NORMAL;
Glib::RefPtr<Gtk::Style> style = get_style();
// clear bg
cr->set_source_rgb (bgc.get_red_p(), bgc.get_green_p(), bgc.get_blue_p());
cr->rectangle (0, 0, w, h);
cr->fill();
// draw gradient background
Cairo::RefPtr< Cairo::LinearGradient > bggradient = Cairo::LinearGradient::create (0, 0, w, 0);
bggradient->add_color_stop_rgb (0, 0, 0, 0);
bggradient->add_color_stop_rgb (1, 1, 1, 1);
// set the box's colors
cr->set_line_width (1.0);
cr->set_line_cap(Cairo::LINE_CAP_BUTT);
if (is_sensitive() && canGetColors()) {
// gradient background
Glib::RefPtr<Gdk::Window> win = get_window();
// this will eventually create/update the off-screen pixmap
setDrawRectangle(win, leftMargin+1, 1, w-2, int(float(h)*5.5f/7.f+0.5f));
// that we're displaying here
ColoredBar::expose(win);
}
else {
// solid background
c = style->get_bg (state);
cr->set_source_rgb (c.get_red_p()*0.85, c.get_green_p()*0.85, c.get_blue_p()*0.85);
cr->set_line_width (1.0);
cr->set_source (bggradient);
cr->rectangle (0.5+RADIUS, h*2.0/7.0 + 0.5, w-0.5, h*3.0/7.0-0.5);
cr->fill_preserve();
cr->set_source_rgb (fgc.get_red_p(), fgc.get_green_p(), fgc.get_blue_p());
cr->stroke ();
// draw the box's background
cr->rectangle (leftMargin+1, 1, w-2, int(float(h)*5.5f/7.f+0.5f));
cr->fill();
}
// draw the box's borders
cr->set_line_width (1.);
cr->rectangle (leftMargin+0.5, 0.5, w-1, int(float(h)*5.5f/7.f+0.5f)+1);
c = style->get_bg (state);
cr->set_source_rgb (c.get_red_p()*0.7, c.get_green_p()*0.7, c.get_blue_p()*0.7);
cr->stroke ();
// draw sliders
cr->set_line_width (1.0);
//cr->set_line_width (1.0);
for (int i=0; i<3; i++) {
cr->move_to (RADIUS+w*positions[i]-wslider/2+0.5, h-0.5);
cr->line_to (RADIUS+w*positions[i]-wslider/2+0.5, wslider/2 + 0.5);
cr->line_to (RADIUS+w*positions[i], 0.5);
cr->line_to (RADIUS+w*positions[i]+wslider/2-0.5, wslider/2 + 0.5);
cr->line_to (RADIUS+w*positions[i]+wslider/2-0.5, h-0.5);
cr->line_to (RADIUS+w*positions[i]-wslider/2+0.5, h-0.5);
cr->set_source_rgb (bgc.get_red_p(), bgc.get_green_p(), bgc.get_blue_p());
cr->fill_preserve ();
cr->set_source_rgb (fgc.get_red_p(), fgc.get_green_p(), fgc.get_blue_p());
cr->stroke ();
cr->move_to (leftMargin+0.5+(w-1)*positions[i]+hwslider, double(h)-0.5);
cr->rel_line_to (0., double(-h/3));
cr->rel_line_to (-hwslider, double(-h/3));
cr->rel_line_to (-hwslider, double(h/3));
cr->rel_line_to (0., double(h/3));
cr->close_path();
// normal
c = style->get_bg (is_sensitive() ? Gtk::STATE_ACTIVE : Gtk::STATE_INSENSITIVE);
cr->set_source_rgb (c.get_red_p(), c.get_green_p(), c.get_blue_p());
cr->fill_preserve ();
c = style->get_bg (state);
cr->set_source_rgb (c.get_red_p()*0.7, c.get_green_p()*0.7, c.get_blue_p()*0.7);
cr->stroke ();
}
// draw text for the slider that is being moved
@@ -104,21 +142,20 @@ bool SHCSelector::on_expose_event(GdkEventExpose* event) {
int layout_width, layout_height;
Glib::RefPtr<Pango::Layout> layout = create_pango_layout(Glib::ustring::format(std::setprecision(2), positions[i]));
layout->get_pixel_size(layout_width, layout_height);
offset = positions[i] > 0.5 ? -layout_width-1-wslider/2 : 1+wslider/2;
cr->move_to (RADIUS+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 (RADIUS+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 (RADIUS+w*positions[i]+offset, 0.5);
layout->add_to_cairo_context (cr);
cr->fill_preserve ();
cr->stroke ();
offset = positions[i] > 0.5 ? -layout_width-1-hwslider : 1+hwslider;
c = style->get_bg (state);
cr->set_source_rgb (c.get_red_p(), c.get_green_p(), c.get_blue_p());
cr->set_line_width(3.);
cr->set_line_join(Cairo::LINE_JOIN_ROUND);
cr->set_line_cap(Cairo::LINE_CAP_ROUND);
cr->move_to (leftMargin+w*positions[i]+offset, 0.);
layout->add_to_cairo_context (cr);
cr->stroke_preserve();
c = style->get_fg (Gtk::STATE_PRELIGHT);
cr->set_source_rgb (c.get_red_p(), c.get_green_p(), c.get_blue_p());
cr->fill ();
}
return true;
}
@@ -126,10 +163,10 @@ bool SHCSelector::on_expose_event(GdkEventExpose* event) {
bool SHCSelector::on_button_press_event (GdkEventButton* event) {
// check if a slider is under the cursor
int w = get_width ();
double w = double(get_width ()-leftMargin-rightMargin);
movingPosition = -1;
for (int i=0; i<3; i++)
if (event->x > w*positions[i]-wslider/2 && event->x < w*positions[i]+wslider/2) {
if (event->x > double(leftMargin)+w*positions[i]-wslider/2. && event->x < double(leftMargin)+w*positions[i]+wslider/2) {
movingPosition = i;
tmpX = event->x;
tmpPos = positions[i];
@@ -141,9 +178,21 @@ bool SHCSelector::on_button_press_event (GdkEventButton* event) {
bool SHCSelector::on_button_release_event (GdkEventButton* event) {
if (movingPosition >= 0) {
movingPosition = -1;
queue_draw ();
if (event->button == 1) {
if (movingPosition >= 0) {
movingPosition = -1;
queue_draw ();
}
}
else if (event->button == 3) {
if (movingPosition >= 0)
movingPosition = -1;
// right mouse button reset the selector to the stored default values
if (reset()) {
// rest has modified the values
if (cl)
cl->shcChanged ();
}
}
return true;
}
@@ -174,9 +223,17 @@ 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 ();
bool SHCSelector::reset () { // : movingPosition(-1), cl(NULL) {
if ( positions[0] != defaults[0] ||
positions[1] != defaults[1] ||
positions[2] != defaults[2]
) {
positions[0] = defaults[0];
positions[1] = defaults[1];
positions[2] = defaults[2];
queue_draw ();
return true;
}
return false;
}