Code simplification + bugfix

This commit is contained in:
Hombre
2016-10-07 02:18:52 +02:00
parent 5383a7ab71
commit 103091e2c9
4 changed files with 36 additions and 66 deletions

View File

@@ -279,15 +279,11 @@ void CropWindow::scroll (int state, GdkScrollDirection direction, int x, int y)
// resizing a color picker // resizing a color picker
if (direction == GDK_SCROLL_UP) { if (direction == GDK_SCROLL_UP) {
hoveredPicker->incSize(); hoveredPicker->incSize();
rtengine::Coord imgPos; updateHoveredPicker();
screenCoordToImage(x, y, imgPos.x, imgPos.y);
updateHoveredPicker(imgPos);
iarea->redraw (); iarea->redraw ();
}else if (direction == GDK_SCROLL_DOWN) { }else if (direction == GDK_SCROLL_DOWN) {
hoveredPicker->decSize(); hoveredPicker->decSize();
rtengine::Coord imgPos; updateHoveredPicker();
screenCoordToImage(x, y, imgPos.x, imgPos.y);
updateHoveredPicker(imgPos);
iarea->redraw (); iarea->redraw ();
} }
} else { } else {
@@ -352,9 +348,7 @@ void CropWindow::buttonPress (int button, int type, int bstate, int x, int y)
if (hoveredPicker) { if (hoveredPicker) {
if ((bstate & GDK_CONTROL_MASK) && !(bstate & GDK_SHIFT_MASK)) { if ((bstate & GDK_CONTROL_MASK) && !(bstate & GDK_SHIFT_MASK)) {
hoveredPicker->decSize(); hoveredPicker->decSize();
rtengine::Coord imgPos; updateHoveredPicker();
screenCoordToImage(x, y, imgPos.x, imgPos.y);
updateHoveredPicker(imgPos);
needRedraw = true; needRedraw = true;
} else if (!(bstate & GDK_CONTROL_MASK) && (bstate & GDK_SHIFT_MASK)) { } else if (!(bstate & GDK_CONTROL_MASK) && (bstate & GDK_SHIFT_MASK)) {
hoveredPicker->rollDisplayedValues(); hoveredPicker->rollDisplayedValues();
@@ -367,10 +361,10 @@ void CropWindow::buttonPress (int button, int type, int bstate, int x, int y)
// Add a new Color Picker // Add a new Color Picker
rtengine::Coord imgPos; rtengine::Coord imgPos;
screenCoordToImage(x, y, imgPos.x, imgPos.y); screenCoordToImage(x, y, imgPos.x, imgPos.y);
LockableColorPicker *newPicker = new LockableColorPicker(imgPos.x, imgPos.y, LockableColorPicker::Size::S15, 0., 0., 0., this, &cropHandler.colorParams.output, &cropHandler.colorParams.working); LockableColorPicker *newPicker = new LockableColorPicker(this, &cropHandler.colorParams.output, &cropHandler.colorParams.working);
colorPickers.push_back(newPicker); colorPickers.push_back(newPicker);
hoveredPicker = newPicker; hoveredPicker = newPicker;
updateHoveredPicker(imgPos); updateHoveredPicker(&imgPos);
state = SDragPicker; state = SDragPicker;
press_x = x; press_x = x;
press_y = y; press_y = y;
@@ -502,11 +496,10 @@ void CropWindow::buttonPress (int button, int type, int bstate, int x, int y)
} }
} else if (iarea->getToolMode () == TMColorPicker && hoveredPicker) { } else if (iarea->getToolMode () == TMColorPicker && hoveredPicker) {
if ((bstate & GDK_CONTROL_MASK) && !(bstate & GDK_SHIFT_MASK)) { if ((bstate & GDK_CONTROL_MASK) && !(bstate & GDK_SHIFT_MASK)) {
hoveredPicker->decSize(); if (hoveredPicker->decSize()) {
rtengine::Coord imgPos; updateHoveredPicker();
screenCoordToImage(x, y, imgPos.x, imgPos.y); needRedraw = true;
updateHoveredPicker(imgPos); }
needRedraw = true;
} else if (!(bstate & GDK_CONTROL_MASK) && (bstate & GDK_SHIFT_MASK)) { } else if (!(bstate & GDK_CONTROL_MASK) && (bstate & GDK_SHIFT_MASK)) {
hoveredPicker->rollDisplayedValues(); hoveredPicker->rollDisplayedValues();
} else if (!(bstate & GDK_CONTROL_MASK) && !(bstate & GDK_SHIFT_MASK)) { } else if (!(bstate & GDK_CONTROL_MASK) && !(bstate & GDK_SHIFT_MASK)) {
@@ -568,11 +561,10 @@ void CropWindow::buttonPress (int button, int type, int bstate, int x, int y)
state = SDeletePicker; state = SDeletePicker;
needRedraw = true; needRedraw = true;
} else if ((bstate & GDK_CONTROL_MASK) && !(bstate & GDK_SHIFT_MASK)) { } else if ((bstate & GDK_CONTROL_MASK) && !(bstate & GDK_SHIFT_MASK)) {
hoveredPicker->incSize(); if (hoveredPicker->incSize()) {
rtengine::Coord imgPos; updateHoveredPicker();
screenCoordToImage(x, y, imgPos.x, imgPos.y); needRedraw = true;
updateHoveredPicker(imgPos); }
needRedraw = true;
} else if (!(bstate & GDK_CONTROL_MASK) && !(bstate & GDK_SHIFT_MASK)) { } else if (!(bstate & GDK_CONTROL_MASK) && !(bstate & GDK_SHIFT_MASK)) {
// Deleting the hovered picker // Deleting the hovered picker
for (std::vector<LockableColorPicker*>::iterator i = colorPickers.begin(); i != colorPickers.end(); i++) { for (std::vector<LockableColorPicker*>::iterator i = colorPickers.begin(); i != colorPickers.end(); i++) {
@@ -898,7 +890,7 @@ void CropWindow::pointerMoved (int bstate, int x, int y)
action_y = new_action_y; action_y = new_action_y;
iarea->redraw (); iarea->redraw ();
} else if (state == SDragPicker) { } else if (state == SDragPicker) {
Coord imgPos, cropPos; Coord imgPos;
action_x = x - press_x; action_x = x - press_x;
action_x = y - press_y; action_x = y - press_y;
screenCoordToImage (x, y, imgPos.x, imgPos.y); screenCoordToImage (x, y, imgPos.x, imgPos.y);
@@ -912,15 +904,7 @@ void CropWindow::pointerMoved (int bstate, int x, int y)
}else if (imgPos.y >= iarea->getImProcCoordinator()->getFullHeight()) { }else if (imgPos.y >= iarea->getImProcCoordinator()->getFullHeight()) {
imgPos.y = iarea->getImProcCoordinator()->getFullHeight()-1; imgPos.y = iarea->getImProcCoordinator()->getFullHeight()-1;
} }
imageCoordToCropImage(imgPos.x, imgPos.y, cropPos.x, cropPos.y); updateHoveredPicker (&imgPos);
float r=0.f, g=0.f, b=0.f;
float rpreview=0.f, gpreview=0.f, bpreview=0.f;
LockableColorPicker::Validity validity = checkValidity (hoveredPicker, cropPos);
hoveredPicker->setValidity (validity);
if (validity == LockableColorPicker::Validity::INSIDE) {
cropHandler.colorPick(cropPos, r, g, b, rpreview, gpreview, bpreview, hoveredPicker->getSize());
}
hoveredPicker->setPosition (imgPos, r, g, b, rpreview, gpreview, bpreview);
iarea->redraw (); iarea->redraw ();
} else if (state == SNormal && iarea->getToolMode () == TMColorPicker && onArea(ColorPicker, x, y)) { } else if (state == SNormal && iarea->getToolMode () == TMColorPicker && onArea(ColorPicker, x, y)) {
// TODO: we could set the hovered picker as Highlighted here // TODO: we could set the hovered picker as Highlighted here
@@ -2071,7 +2055,7 @@ void CropWindow::redrawNeeded (LWButton* button)
iarea->redraw (); iarea->redraw ();
} }
void CropWindow::updateHoveredPicker (rtengine::Coord &imgPos) void CropWindow::updateHoveredPicker (rtengine::Coord *imgPos)
{ {
if (!hoveredPicker) { if (!hoveredPicker) {
@@ -2079,9 +2063,16 @@ void CropWindow::updateHoveredPicker (rtengine::Coord &imgPos)
} }
rtengine::Coord cropPos; rtengine::Coord cropPos;
imageCoordToCropImage(imgPos.x, imgPos.y, cropPos.x, cropPos.y);
float r=0.f, g=0.f, b=0.f; float r=0.f, g=0.f, b=0.f;
float rpreview=0.f, gpreview=0.f, bpreview=0.f; float rpreview=0.f, gpreview=0.f, bpreview=0.f;
if (imgPos) {
imageCoordToCropImage(imgPos->x, imgPos->y, cropPos.x, cropPos.y);
hoveredPicker->setPosition (*imgPos);
} else {
rtengine::Coord imgPos2;
hoveredPicker->getImagePosition(imgPos2);
imageCoordToCropImage(imgPos2.x, imgPos2.y, cropPos.x, cropPos.y);
}
LockableColorPicker::Validity validity = checkValidity (hoveredPicker, cropPos); LockableColorPicker::Validity validity = checkValidity (hoveredPicker, cropPos);
hoveredPicker->setValidity (validity); hoveredPicker->setValidity (validity);
if (validity == LockableColorPicker::Validity::INSIDE) { if (validity == LockableColorPicker::Validity::INSIDE) {

View File

@@ -103,7 +103,7 @@ class CropWindow : public LWButtonListener, public CropDisplayHandler, public Ed
void drawUnscaledSpotRectangle (Cairo::RefPtr<Cairo::Context> cr, int rectSize); void drawUnscaledSpotRectangle (Cairo::RefPtr<Cairo::Context> cr, int rectSize);
void drawObservedFrame (Cairo::RefPtr<Cairo::Context> cr, int rw = 0, int rh = 0); void drawObservedFrame (Cairo::RefPtr<Cairo::Context> cr, int rw = 0, int rh = 0);
void changeZoom (int zoom, bool notify = true, int centerx = -1, int centery = -1); void changeZoom (int zoom, bool notify = true, int centerx = -1, int centery = -1);
void updateHoveredPicker (rtengine::Coord &imgPos); void updateHoveredPicker (rtengine::Coord *imgPos = nullptr);
void cycleRGB (); void cycleRGB ();
void cycleHSV (); void cycleHSV ();

View File

@@ -28,20 +28,11 @@
extern Options options; extern Options options;
LockableColorPicker::LockableColorPicker (CropWindow* cropWindow, Glib::ustring *oProfile, Glib::ustring *wProfile) LockableColorPicker::LockableColorPicker (CropWindow* cropWindow, Glib::ustring *oProfile, Glib::ustring *wProfile)
: cropWindow(cropWindow), displayedValues(ColorPickerType::RGB), position(0, 0), size(Size::S20), : cropWindow(cropWindow), displayedValues(ColorPickerType::RGB), position(0, 0), size(Size::S15),
outputProfile(oProfile), workingProfile(wProfile), validity(Validity::OUTSIDE), outputProfile(oProfile), workingProfile(wProfile), validity(Validity::OUTSIDE),
r(0.f), g(0.f), b(0.f), rpreview(0.f), gpreview(0.f), bpreview(0.f), h(0.f), s(0.f), v(0.f), L(0.f), a(0.f), bb(0.f) r(0.f), g(0.f), b(0.f), rpreview(0.f), gpreview(0.f), bpreview(0.f), h(0.f), s(0.f), v(0.f), L(0.f), a(0.f), bb(0.f)
{} {}
LockableColorPicker::LockableColorPicker (int x, int y, Size size, const float R, const float G, const float B, CropWindow* cropWindow, Glib::ustring *oProfile, Glib::ustring *wProfile)
: cropWindow(cropWindow), displayedValues(ColorPickerType::RGB), position(x, y), size(size),
outputProfile(oProfile), workingProfile(wProfile), validity(Validity::OUTSIDE),
r(R), g(G), b(B), rpreview(R), gpreview(G), bpreview(B), L(0.f), a(0.f), bb(0.f)
{
rtengine::Color::rgb2hsv(r*65535.f, g*65535.f, b*65535.f, h, s, v);
rtengine::Color::rgb2lab (*outputProfile, *workingProfile, r * 65535.f, g * 65535.f, b * 65535.f, L, a, bb, options.rtSettings.HistogramWorking); // TODO: Really sure this function works?
}
void LockableColorPicker::updateBackBuffer () void LockableColorPicker::updateBackBuffer ()
{ {
int newW, newH; int newW, newH;
@@ -263,25 +254,10 @@ void LockableColorPicker::draw (Cairo::RefPtr<Cairo::Context> &cr)
copySurface(cr); copySurface(cr);
} }
void LockableColorPicker::setPosition (const rtengine::Coord &newPos, const float R, const float G, float B, const float previewR, const float previewG, const float previewB) void LockableColorPicker::setPosition (const rtengine::Coord &newPos)
{ {
// we're not checking bounds here, this will be done at rendering time // we're not checking bounds here, this will be done at rendering time
position = newPos; position = newPos;
r = R;
g = G;
b = B;
rpreview = previewR;
gpreview = previewG;
bpreview = previewB;
rtengine::Color::rgb2hsv(r*65535.f, g*65535.f, b*65535.f, h, s, v);
rtengine::Color::rgb2lab (*outputProfile, *workingProfile, r * 65535.f, g * 65535.f, b * 65535.f, L, a, bb, options.rtSettings.HistogramWorking); // TODO: Really sure this function works?
if (validity != Validity::OUTSIDE) {
setDirty(true);
}
} }
void LockableColorPicker::setRGB (const float R, const float G, const float B, const float previewR, const float previewG, const float previewB) void LockableColorPicker::setRGB (const float R, const float G, const float B, const float previewR, const float previewG, const float previewB)
@@ -366,20 +342,24 @@ void LockableColorPicker::rollDisplayedValues ()
} }
void LockableColorPicker::incSize () bool LockableColorPicker::incSize ()
{ {
if (size < Size::S30) { if (size < Size::S30) {
size = (Size)((int)size + 5); size = (Size)((int)size + 5);
setDirty(true); setDirty(true);
return true;
} }
return false;
} }
void LockableColorPicker::decSize () bool LockableColorPicker::decSize ()
{ {
if (size > Size::S5) { if (size > Size::S5) {
size = (Size)((int)size - 5); size = (Size)((int)size - 5);
setDirty(true); setDirty(true);
return true;
} }
return false;
} }
// return true if the picker has to be redrawn // return true if the picker has to be redrawn

View File

@@ -75,12 +75,11 @@ private:
public: public:
LockableColorPicker (CropWindow* cropWindow, Glib::ustring *oProfile, Glib::ustring *wProfile); LockableColorPicker (CropWindow* cropWindow, Glib::ustring *oProfile, Glib::ustring *wProfile);
LockableColorPicker (int x, int y, Size size, const float R, const float G, const float B, CropWindow* cropWindow, Glib::ustring *oProfile, Glib::ustring *wProfile);
void draw (Cairo::RefPtr<Cairo::Context> &cr); void draw (Cairo::RefPtr<Cairo::Context> &cr);
// Used to update the RGB color, the HSV values will be updated accordingly // Used to update the RGB color, the HSV values will be updated accordingly
void setPosition (const rtengine::Coord &newPos, const float R, const float G, float B, const float previewR, const float previewG, const float previewB); void setPosition (const rtengine::Coord &newPos);
void setRGB (const float R, const float G, const float B, const float previewR, const float previewG, const float previewB); void setRGB (const float R, const float G, const float B, const float previewR, const float previewG, const float previewB);
void getImagePosition (rtengine::Coord &imgPos); void getImagePosition (rtengine::Coord &imgPos);
void getScreenPosition (rtengine::Coord &screenPos); void getScreenPosition (rtengine::Coord &screenPos);
@@ -89,8 +88,8 @@ public:
void setValidity (Validity isValid); void setValidity (Validity isValid);
void setSize (Size newSize); void setSize (Size newSize);
void rollDisplayedValues (); void rollDisplayedValues ();
void incSize (); bool incSize ();
void decSize (); bool decSize ();
bool cycleRGB (); bool cycleRGB ();
bool cycleHSV (); bool cycleHSV ();
}; };