Center new spot inside preview area, fixes #5220
When adding/duplicating spot, new spot is now centered according to the preview area. Moreover ellipse/rectangle size takes into account the preview area size (but it is saturated at maximum at 250 for a creation, at duplicated spot size for a duplication). Center circle radius is unchanged
This commit is contained in:
@@ -193,4 +193,6 @@ public:
|
||||
int getPipetteRectSize () const;
|
||||
EditSubscriber* getCurrSubscriber() const;
|
||||
virtual void getImageSize (int &w, int&h) = 0;
|
||||
virtual void getPreviewCenterPos(int &x, int &y) = 0;
|
||||
virtual void getPreviewSize(int &w, int &h) = 0;
|
||||
};
|
||||
|
@@ -409,6 +409,34 @@ void ImageArea::getImageSize (int &w, int&h)
|
||||
}
|
||||
}
|
||||
|
||||
void ImageArea::getPreviewCenterPos(int &x, int &y)
|
||||
{
|
||||
if (mainCropWindow) {
|
||||
// Getting crop window size
|
||||
int cW, cH;
|
||||
mainCropWindow->getSize(cW, cH);
|
||||
|
||||
// Converting center coord of crop window to image coord
|
||||
const int cX = cW / 2;
|
||||
const int cY = cH / 2;
|
||||
mainCropWindow->screenCoordToImage(cX, cY, x, y);
|
||||
} else {
|
||||
x = y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageArea::getPreviewSize(int &w, int &h)
|
||||
{
|
||||
if (mainCropWindow) {
|
||||
int tmpW, tmpH;
|
||||
mainCropWindow->getSize(tmpW, tmpH);
|
||||
w = mainCropWindow->scaleValueToImage(tmpW);
|
||||
h = mainCropWindow->scaleValueToImage(tmpH);
|
||||
} else {
|
||||
w = h = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageArea::grabFocus (CropWindow* cw)
|
||||
{
|
||||
|
||||
|
@@ -143,6 +143,8 @@ public:
|
||||
void subscribe(EditSubscriber *subscriber) override;
|
||||
void unsubscribe() override;
|
||||
void getImageSize (int &w, int&h) override;
|
||||
void getPreviewCenterPos(int &x, int &y) override;
|
||||
void getPreviewSize(int &w, int &h) override;
|
||||
|
||||
// CropWindowListener interface
|
||||
void cropPositionChanged (CropWindow* cw) override;
|
||||
|
@@ -1467,6 +1467,11 @@ void Locallab::write(ProcParams* pp, ParamsEdited* pedited)
|
||||
ControlSpotPanel::SpotRow* r;
|
||||
LocallabParams::LocallabSpot* newSpot;
|
||||
|
||||
int imW, imH; // Size of image
|
||||
int prW, prH; // Size of preview area
|
||||
int prX, prY; // Coord of preview area center
|
||||
EditDataProvider* const provider = expsettings->getEditProvider();
|
||||
|
||||
switch (spotPanelEvent) {
|
||||
case (ControlSpotPanel::SpotCreation): // Spot creation event
|
||||
// Spot creation (default initialization)
|
||||
@@ -1503,12 +1508,30 @@ void Locallab::write(ProcParams* pp, ParamsEdited* pedited)
|
||||
r->shapeMethod = 3;
|
||||
}
|
||||
|
||||
// Calculate spot size and center position according to preview area
|
||||
if (provider && !batchMode) {
|
||||
provider->getImageSize(imW, imH);
|
||||
provider->getPreviewCenterPos(prX, prY);
|
||||
provider->getPreviewSize(prW, prH);
|
||||
|
||||
if (imW && imH) { // Image loaded
|
||||
// Spot center position computation
|
||||
newSpot->centerX = rtengine::LIM(int(int((double)prX - (double)imW / 2.) * 2000. / (double)imW), -1000, 1000);
|
||||
newSpot->centerY = rtengine::LIM(int(int((double)prY - (double)imH / 2.) * 2000. / (double)imH), -1000, 1000);
|
||||
// Ellipse/rectangle size computation
|
||||
newSpot->locX = rtengine::LIM(int(((double)prW / 2. - 5.) * 2000. / (double)imW), 2, newSpot->locX);
|
||||
newSpot->locXL = rtengine::LIM(int(((double)prW / 2. - 5.) * 2000. / (double)imW), 2, newSpot->locXL);
|
||||
newSpot->locY = rtengine::LIM(int(((double)prH / 2. - 5.) * 2000. / (double)imH), 2, newSpot->locY);
|
||||
newSpot->locYT = rtengine::LIM(int(((double)prH / 2. - 5.) * 2000. / (double)imH), 2, newSpot->locYT);
|
||||
}
|
||||
}
|
||||
r->locX = newSpot->locX;
|
||||
r->locXL = newSpot->locXL;
|
||||
r->locY = newSpot->locY;
|
||||
r->locYT = newSpot->locYT;
|
||||
r->centerX = newSpot->centerX;
|
||||
r->centerY = newSpot->centerY;
|
||||
|
||||
r->circrad = newSpot->circrad;
|
||||
|
||||
if (newSpot->qualityMethod == "enh") {
|
||||
@@ -1699,12 +1722,30 @@ void Locallab::write(ProcParams* pp, ParamsEdited* pedited)
|
||||
r->shapeMethod = 3;
|
||||
}
|
||||
|
||||
// Calculate spot size and center position according to preview area
|
||||
if (provider && !batchMode) {
|
||||
provider->getImageSize(imW, imH);
|
||||
provider->getPreviewCenterPos(prX, prY);
|
||||
provider->getPreviewSize(prW, prH);
|
||||
|
||||
if (imW && imH) { // Image loaded
|
||||
// Spot center position computation
|
||||
newSpot->centerX = rtengine::LIM(int(int((double)prX - (double)imW / 2.) * 2000. / (double)imW), -1000, 1000);
|
||||
newSpot->centerY = rtengine::LIM(int(int((double)prY - (double)imH / 2.) * 2000. / (double)imH), -1000, 1000);
|
||||
// Ellipse/rectangle size computation
|
||||
newSpot->locX = rtengine::LIM(int(((double)prW / 2. - 5.) * 2000. / (double)imW), 2, newSpot->locX);
|
||||
newSpot->locXL = rtengine::LIM(int(((double)prW / 2. - 5.) * 2000. / (double)imW), 2, newSpot->locXL);
|
||||
newSpot->locY = rtengine::LIM(int(((double)prH / 2. - 5.) * 2000. / (double)imH), 2, newSpot->locY);
|
||||
newSpot->locYT = rtengine::LIM(int(((double)prH / 2. - 5.) * 2000. / (double)imH), 2, newSpot->locYT);
|
||||
}
|
||||
}
|
||||
r->locX = newSpot->locX;
|
||||
r->locXL = newSpot->locXL;
|
||||
r->locY = newSpot->locY;
|
||||
r->locYT = newSpot->locYT;
|
||||
r->centerX = newSpot->centerX;
|
||||
r->centerY = newSpot->centerY;
|
||||
|
||||
r->circrad = newSpot->circrad;
|
||||
|
||||
if (newSpot->qualityMethod == "enh") {
|
||||
|
Reference in New Issue
Block a user