implement feature request #1489 (custom crop ratio by holding shift while resizing the crop area)

This commit is contained in:
Alberto Griggio
2017-04-10 21:14:45 +02:00
parent 14f544fcc2
commit 7a25641139
4 changed files with 50 additions and 48 deletions

View File

@@ -836,7 +836,7 @@ void Crop::cropMoved (int &X, int &Y, int &W, int &H)
// Glib::signal_idle().connect (sigc::mem_fun(*this, &Crop::refreshSpins)); // Glib::signal_idle().connect (sigc::mem_fun(*this, &Crop::refreshSpins));
} }
void Crop::cropWidth1Resized (int &X, int &Y, int &W, int &H) void Crop::cropWidth1Resized (int &X, int &Y, int &W, int &H, float custom_ratio)
{ {
int oldXR = nx + nw; int oldXR = nx + nw;
@@ -849,8 +849,8 @@ void Crop::cropWidth1Resized (int &X, int &Y, int &W, int &H)
W = oldXR; W = oldXR;
} }
if (fixr->get_active()) { if (fixr->get_active() || custom_ratio > 0) {
double r = getRatio(); double r = custom_ratio > 0 ? custom_ratio : getRatio();
H = (int)round(W / r); H = (int)round(W / r);
int Hmax = min(ny + nh, maxh - ny); int Hmax = min(ny + nh, maxh - ny);
@@ -879,7 +879,7 @@ void Crop::cropWidth1Resized (int &X, int &Y, int &W, int &H)
idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false)); idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false));
} }
void Crop::cropWidth2Resized (int &X, int &Y, int &W, int &H) void Crop::cropWidth2Resized (int &X, int &Y, int &W, int &H, float custom_ratio)
{ {
if (W < 0) { if (W < 0) {
@@ -890,8 +890,8 @@ void Crop::cropWidth2Resized (int &X, int &Y, int &W, int &H)
W = maxw - nx; W = maxw - nx;
} }
if (fixr->get_active()) { if (fixr->get_active() || custom_ratio > 0) {
double r = getRatio(); double r = custom_ratio > 0 ? custom_ratio : getRatio();
H = (int)round(W / r); H = (int)round(W / r);
int Hmax = min(ny + nh, maxh - ny); int Hmax = min(ny + nh, maxh - ny);
@@ -919,7 +919,7 @@ void Crop::cropWidth2Resized (int &X, int &Y, int &W, int &H)
idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false)); idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false));
} }
void Crop::cropHeight1Resized (int &X, int &Y, int &W, int &H) void Crop::cropHeight1Resized (int &X, int &Y, int &W, int &H, float custom_ratio)
{ {
int oldYB = ny + nh; int oldYB = ny + nh;
@@ -932,8 +932,8 @@ void Crop::cropHeight1Resized (int &X, int &Y, int &W, int &H)
H = oldYB; H = oldYB;
} }
if (fixr->get_active()) { if (fixr->get_active() || custom_ratio > 0) {
double r = getRatio(); double r = custom_ratio > 0 ? custom_ratio : getRatio();
W = (int)round(H * r); W = (int)round(H * r);
int Wmax = min(nx + nw, maxw - nx); int Wmax = min(nx + nw, maxw - nx);
@@ -962,7 +962,7 @@ void Crop::cropHeight1Resized (int &X, int &Y, int &W, int &H)
idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false)); idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false));
} }
void Crop::cropHeight2Resized (int &X, int &Y, int &W, int &H) void Crop::cropHeight2Resized (int &X, int &Y, int &W, int &H, float custom_ratio)
{ {
if (H < 0) { if (H < 0) {
@@ -973,8 +973,8 @@ void Crop::cropHeight2Resized (int &X, int &Y, int &W, int &H)
H = maxh - ny; H = maxh - ny;
} }
if (fixr->get_active()) { if (fixr->get_active() || custom_ratio > 0) {
double r = getRatio(); double r = custom_ratio > 0 ? custom_ratio : getRatio();
W = (int)round(H * r); W = (int)round(H * r);
int Wmax = min(nx + nw, maxw - nx); int Wmax = min(nx + nw, maxw - nx);
@@ -1002,7 +1002,7 @@ void Crop::cropHeight2Resized (int &X, int &Y, int &W, int &H)
idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false)); idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false));
} }
void Crop::cropTopLeftResized (int &X, int &Y, int &W, int &H) void Crop::cropTopLeftResized (int &X, int &Y, int &W, int &H, float custom_ratio)
{ {
int oldXR = nx + nw; // right side int oldXR = nx + nw; // right side
@@ -1024,8 +1024,8 @@ void Crop::cropTopLeftResized (int &X, int &Y, int &W, int &H)
H = oldYB; H = oldYB;
} }
if (fixr->get_active()) { if (fixr->get_active() || custom_ratio > 0) {
double r = getRatio(); double r = custom_ratio > 0 ? custom_ratio : getRatio();
W = (int)round(H * r); W = (int)round(H * r);
if (W > oldXR) { if (W > oldXR) {
@@ -1044,7 +1044,7 @@ void Crop::cropTopLeftResized (int &X, int &Y, int &W, int &H)
idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false)); idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false));
} }
void Crop::cropTopRightResized (int &X, int &Y, int &W, int &H) void Crop::cropTopRightResized (int &X, int &Y, int &W, int &H, float custom_ratio)
{ {
int oldYB = ny + nh; int oldYB = ny + nh;
@@ -1065,8 +1065,8 @@ void Crop::cropTopRightResized (int &X, int &Y, int &W, int &H)
H = oldYB; H = oldYB;
} }
if (fixr->get_active()) { if (fixr->get_active() || custom_ratio > 0) {
double r = getRatio(); double r = custom_ratio > 0 ? custom_ratio : getRatio();
W = (int)round(H * r); W = (int)round(H * r);
if (W > maxw - nx) { if (W > maxw - nx) {
@@ -1084,7 +1084,7 @@ void Crop::cropTopRightResized (int &X, int &Y, int &W, int &H)
idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false)); idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false));
} }
void Crop::cropBottomLeftResized (int &X, int &Y, int &W, int &H) void Crop::cropBottomLeftResized (int &X, int &Y, int &W, int &H, float custom_ratio)
{ {
int oldXR = nx + nw; int oldXR = nx + nw;
@@ -1105,8 +1105,8 @@ void Crop::cropBottomLeftResized (int &X, int &Y, int &W, int &H)
H = maxh - ny; H = maxh - ny;
} }
if (fixr->get_active()) { if (fixr->get_active() || custom_ratio > 0) {
double r = getRatio(); double r = custom_ratio > 0 ? custom_ratio : getRatio();
W = (int)round(H * r); W = (int)round(H * r);
if (W > oldXR) { if (W > oldXR) {
@@ -1124,7 +1124,7 @@ void Crop::cropBottomLeftResized (int &X, int &Y, int &W, int &H)
idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false)); idle_register.add(refreshSpinsUI, new RefreshSpinHelper(this, false));
} }
void Crop::cropBottomRightResized (int &X, int &Y, int &W, int &H) void Crop::cropBottomRightResized (int &X, int &Y, int &W, int &H, float custom_ratio)
{ {
if (W < 0) { if (W < 0) {
@@ -1143,8 +1143,8 @@ void Crop::cropBottomRightResized (int &X, int &Y, int &W, int &H)
H = maxh - ny; H = maxh - ny;
} }
if (fixr->get_active()) { if (fixr->get_active() || custom_ratio > 0) {
double r = getRatio(); double r = custom_ratio > 0 ? custom_ratio : getRatio();
W = (int)round(H * r); W = (int)round(H * r);
if (W > maxw - nx) { if (W > maxw - nx) {

View File

@@ -69,14 +69,14 @@ public:
void writeOptions (); void writeOptions ();
void cropMoved (int &x, int &y, int &w, int &h); void cropMoved (int &x, int &y, int &w, int &h);
void cropWidth1Resized (int &x, int &y, int &w, int &h); void cropWidth1Resized (int &x, int &y, int &w, int &h, float custom_ratio=0.f);
void cropWidth2Resized (int &x, int &y, int &w, int &h); void cropWidth2Resized (int &x, int &y, int &w, int &h, float custom_ratio=0.f);
void cropHeight1Resized (int &x, int &y, int &w, int &h); void cropHeight1Resized (int &x, int &y, int &w, int &h, float custom_ratio=0.f);
void cropHeight2Resized (int &x, int &y, int &w, int &h); void cropHeight2Resized (int &x, int &y, int &w, int &h, float custom_ratio=0.f);
void cropTopLeftResized (int &x, int &y, int &w, int &h); void cropTopLeftResized (int &x, int &y, int &w, int &h, float custom_ratio=0.f);
void cropTopRightResized (int &x, int &y, int &w, int &h); void cropTopRightResized (int &x, int &y, int &w, int &h, float custom_ratio=0.f);
void cropBottomLeftResized (int &x, int &y, int &w, int &h); void cropBottomLeftResized (int &x, int &y, int &w, int &h, float custom_ratio=0.f);
void cropBottomRightResized (int &x, int &y, int &w, int &h); void cropBottomRightResized (int &x, int &y, int &w, int &h, float custom_ratio=0.f);
void cropInit (int &x, int &y, int &w, int &h); void cropInit (int &x, int &y, int &w, int &h);
void cropResized (int &x, int &y, int& x2, int& y2); void cropResized (int &x, int &y, int& x2, int& y2);
void cropManipReady (); void cropManipReady ();

View File

@@ -25,14 +25,14 @@ class CropGUIListener
public: public:
virtual ~CropGUIListener() {} virtual ~CropGUIListener() {}
virtual void cropMoved (int &x, int &y, int &w, int &h) = 0; virtual void cropMoved (int &x, int &y, int &w, int &h) = 0;
virtual void cropWidth1Resized (int &x, int &y, int &w, int &h) = 0; virtual void cropWidth1Resized (int &x, int &y, int &w, int &h, float custom_ratio=0.f) = 0;
virtual void cropWidth2Resized (int &x, int &y, int &w, int &h) = 0; virtual void cropWidth2Resized (int &x, int &y, int &w, int &h, float custom_ratio=0.f) = 0;
virtual void cropHeight1Resized (int &x, int &y, int &w, int &h) = 0; virtual void cropHeight1Resized (int &x, int &y, int &w, int &h, float custom_ratio=0.f) = 0;
virtual void cropHeight2Resized (int &x, int &y, int &w, int &h) = 0; virtual void cropHeight2Resized (int &x, int &y, int &w, int &h, float custom_ratio=0.f) = 0;
virtual void cropTopLeftResized (int &x, int &y, int &w, int &h) = 0; virtual void cropTopLeftResized (int &x, int &y, int &w, int &h, float custom_ratio=0.f) = 0;
virtual void cropTopRightResized (int &x, int &y, int &w, int &h) = 0; virtual void cropTopRightResized (int &x, int &y, int &w, int &h, float custom_ratio=0.f) = 0;
virtual void cropBottomLeftResized (int &x, int &y, int &w, int &h) = 0; virtual void cropBottomLeftResized (int &x, int &y, int &w, int &h, float custom_ratio=0.f) = 0;
virtual void cropBottomRightResized (int &x, int &y, int &w, int &h) = 0; virtual void cropBottomRightResized (int &x, int &y, int &w, int &h, float custom_ratio=0.f) = 0;
virtual void cropInit (int &x, int &y, int &w, int &h) = 0; virtual void cropInit (int &x, int &y, int &w, int &h) = 0;
virtual void cropResized (int &x, int &y, int& x2, int& y2) = 0; virtual void cropResized (int &x, int &y, int& x2, int& y2) = 0;
virtual void cropManipReady () = 0; virtual void cropManipReady () = 0;

View File

@@ -759,6 +759,8 @@ void CropWindow::pointerMoved (int bstate, int x, int y)
EditSubscriber *editSubscriber = iarea->getCurrSubscriber(); EditSubscriber *editSubscriber = iarea->getCurrSubscriber();
float cur_crop_ratio = (bstate & GDK_SHIFT_MASK) && cropHandler.cropParams.w > 0 && cropHandler.cropParams.h > 0 ? float(cropHandler.cropParams.w) / float(cropHandler.cropParams.h) : 0.0;
if (state == SCropWinMove) { if (state == SCropWinMove) {
setPosition (press_x + x - action_x, press_y + y - action_y); setPosition (press_x + x - action_x, press_y + y - action_y);
iarea->redraw (); iarea->redraw ();
@@ -807,21 +809,21 @@ void CropWindow::pointerMoved (int bstate, int x, int y)
int oy = cropHandler.cropParams.y; int oy = cropHandler.cropParams.y;
cropHandler.cropParams.y = action_y + (y - press_y) / zoomSteps[cropZoom].zoom; cropHandler.cropParams.y = action_y + (y - press_y) / zoomSteps[cropZoom].zoom;
cropHandler.cropParams.h += oy - cropHandler.cropParams.y; cropHandler.cropParams.h += oy - cropHandler.cropParams.y;
cropgl->cropHeight1Resized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h); cropgl->cropHeight1Resized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h, cur_crop_ratio);
iarea->redraw (); iarea->redraw ();
} else if (state == SResizeH2 && cropgl) { } else if (state == SResizeH2 && cropgl) {
cropHandler.cropParams.h = action_y + (y - press_y) / zoomSteps[cropZoom].zoom; cropHandler.cropParams.h = action_y + (y - press_y) / zoomSteps[cropZoom].zoom;
cropgl->cropHeight2Resized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h); cropgl->cropHeight2Resized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h, cur_crop_ratio);
iarea->redraw (); iarea->redraw ();
} else if (state == SResizeW1 && cropgl) { } else if (state == SResizeW1 && cropgl) {
int ox = cropHandler.cropParams.x; int ox = cropHandler.cropParams.x;
cropHandler.cropParams.x = action_x + (x - press_x) / zoomSteps[cropZoom].zoom; cropHandler.cropParams.x = action_x + (x - press_x) / zoomSteps[cropZoom].zoom;
cropHandler.cropParams.w += ox - cropHandler.cropParams.x; cropHandler.cropParams.w += ox - cropHandler.cropParams.x;
cropgl->cropWidth1Resized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h); cropgl->cropWidth1Resized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h, cur_crop_ratio);
iarea->redraw (); iarea->redraw ();
} else if (state == SResizeW2 && cropgl) { } else if (state == SResizeW2 && cropgl) {
cropHandler.cropParams.w = action_x + (x - press_x) / zoomSteps[cropZoom].zoom; cropHandler.cropParams.w = action_x + (x - press_x) / zoomSteps[cropZoom].zoom;
cropgl->cropWidth2Resized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h); cropgl->cropWidth2Resized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h, cur_crop_ratio);
iarea->redraw (); iarea->redraw ();
} else if (state == SResizeTL && cropgl) { } else if (state == SResizeTL && cropgl) {
int ox = cropHandler.cropParams.x; int ox = cropHandler.cropParams.x;
@@ -830,26 +832,26 @@ void CropWindow::pointerMoved (int bstate, int x, int y)
int oy = cropHandler.cropParams.y; int oy = cropHandler.cropParams.y;
cropHandler.cropParams.y = action_y + (y - press_y) / zoomSteps[cropZoom].zoom; cropHandler.cropParams.y = action_y + (y - press_y) / zoomSteps[cropZoom].zoom;
cropHandler.cropParams.h += oy - cropHandler.cropParams.y; cropHandler.cropParams.h += oy - cropHandler.cropParams.y;
cropgl->cropTopLeftResized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h); cropgl->cropTopLeftResized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h, cur_crop_ratio);
iarea->redraw (); iarea->redraw ();
} else if (state == SResizeTR && cropgl) { } else if (state == SResizeTR && cropgl) {
cropHandler.cropParams.w = action_x + (x - press_x) / zoomSteps[cropZoom].zoom; cropHandler.cropParams.w = action_x + (x - press_x) / zoomSteps[cropZoom].zoom;
int oy = cropHandler.cropParams.y; int oy = cropHandler.cropParams.y;
cropHandler.cropParams.y = action_y + (y - press_y) / zoomSteps[cropZoom].zoom; cropHandler.cropParams.y = action_y + (y - press_y) / zoomSteps[cropZoom].zoom;
cropHandler.cropParams.h += oy - cropHandler.cropParams.y; cropHandler.cropParams.h += oy - cropHandler.cropParams.y;
cropgl->cropTopRightResized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h); cropgl->cropTopRightResized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h, cur_crop_ratio);
iarea->redraw (); iarea->redraw ();
} else if (state == SResizeBL && cropgl) { } else if (state == SResizeBL && cropgl) {
int ox = cropHandler.cropParams.x; int ox = cropHandler.cropParams.x;
cropHandler.cropParams.x = action_x + (x - press_x) / zoomSteps[cropZoom].zoom; cropHandler.cropParams.x = action_x + (x - press_x) / zoomSteps[cropZoom].zoom;
cropHandler.cropParams.w += ox - cropHandler.cropParams.x; cropHandler.cropParams.w += ox - cropHandler.cropParams.x;
cropHandler.cropParams.h = action_y + (y - press_y) / zoomSteps[cropZoom].zoom; cropHandler.cropParams.h = action_y + (y - press_y) / zoomSteps[cropZoom].zoom;
cropgl->cropBottomLeftResized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h); cropgl->cropBottomLeftResized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h, cur_crop_ratio);
iarea->redraw (); iarea->redraw ();
} else if (state == SResizeBR && cropgl) { } else if (state == SResizeBR && cropgl) {
cropHandler.cropParams.w = action_x + (x - press_x) / zoomSteps[cropZoom].zoom; cropHandler.cropParams.w = action_x + (x - press_x) / zoomSteps[cropZoom].zoom;
cropHandler.cropParams.h = action_y + (y - press_y) / zoomSteps[cropZoom].zoom; cropHandler.cropParams.h = action_y + (y - press_y) / zoomSteps[cropZoom].zoom;
cropgl->cropBottomRightResized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h); cropgl->cropBottomRightResized (cropHandler.cropParams.x, cropHandler.cropParams.y, cropHandler.cropParams.w, cropHandler.cropParams.h, cur_crop_ratio);
iarea->redraw (); iarea->redraw ();
} else if (state == SCropMove && cropgl) { } else if (state == SCropMove && cropgl) {
cropHandler.cropParams.x = action_x + (x - press_x) / zoomSteps[cropZoom].zoom; cropHandler.cropParams.x = action_x + (x - press_x) / zoomSteps[cropZoom].zoom;