From e29ff3cce2ab5c8922b1468aa0e6a88255a1486f Mon Sep 17 00:00:00 2001 From: Alberto Griggio Date: Sat, 1 Dec 2018 11:47:47 +0100 Subject: [PATCH] crop: added new locked ratio "Current" --- rtdata/languages/default | 1 + rtgui/crop.cc | 79 +++++++++++++++++++++++++++++++++++----- rtgui/crop.h | 4 +- 3 files changed, 73 insertions(+), 11 deletions(-) diff --git a/rtdata/languages/default b/rtdata/languages/default index 10c8ed730..da79ec3ac 100644 --- a/rtdata/languages/default +++ b/rtdata/languages/default @@ -223,6 +223,7 @@ GENERAL_AUTO;Automatic GENERAL_BEFORE;Before GENERAL_CANCEL;Cancel GENERAL_CLOSE;Close +GENERAL_CURRENT;Current GENERAL_DISABLE;Disable GENERAL_DISABLED;Disabled GENERAL_ENABLE;Enable diff --git a/rtgui/crop.cc b/rtgui/crop.cc index a6b418bd7..a06965840 100644 --- a/rtgui/crop.cc +++ b/rtgui/crop.cc @@ -52,12 +52,29 @@ int notifyListenerUI (void* data) return 0; } + +inline void get_custom_ratio(int w, int h, double &rw, double &rh) +{ + if (w < h) { + double r = double(h) / double(w); + int rr = r * 100 + 0.5; + rw = 1.0; + rh = rr / 100.0; + } else { + double r = double(w) / double(h); + int rr = r * 100 + 0.5; + rw = rr / 100.0; + rh = 1.0; + } } +} // namespace + Crop::Crop(): FoldableToolPanel(this, "crop", M("TP_CROP_LABEL"), false, true), crop_ratios{ {M("GENERAL_ASIMAGE"), 0.0}, + {M("GENERAL_CURRENT"), -1.0}, {"3:2", 3.0 / 2.0}, // L1.5, P0.666... {"4:3", 4.0 / 3.0}, // L1.333..., P0.75 {"16:9", 16.0 / 9.0}, // L1.777..., P0.5625 @@ -176,10 +193,17 @@ Crop::Crop(): guide = Gtk::manage (new MyComboBoxText ()); setExpandAlignProperties(guide, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER); - + + customRatioLabel = Gtk::manage(new Gtk::Label("")); + customRatioLabel->hide(); + Gtk::HBox *hb = Gtk::manage(new Gtk::HBox()); + hb->pack_start(*orientation); + hb->pack_start(*customRatioLabel); + + settingsgrid->set_column_homogeneous(true); settingsgrid->attach (*fixr, 0, 0, 1, 1); settingsgrid->attach (*ratio, 1, 0, 1, 1); - settingsgrid->attach (*orientation, 2, 0, 1, 1); + settingsgrid->attach (*hb, 2, 0, 1, 1); settingsgrid->attach (*guidelab, 0, 1, 1, 1); settingsgrid->attach (*guide, 1, 1, 2, 1); pack_start (*settingsgrid, Gtk::PACK_SHRINK, 0 ); @@ -349,13 +373,6 @@ void Crop::read (const ProcParams* pp, const ParamsEdited* pedited) setDimensions (pp->crop.x + pp->crop.w, pp->crop.y + pp->crop.h); } - if (pp->crop.ratio == "As Image") { - ratio->set_active(0); - } else { - ratio->set_active_text (pp->crop.ratio); - } - fixr->set_active (pp->crop.fixratio); - const bool flip_orientation = pp->crop.fixratio && crop_ratios[ratio->get_active_row_number()].value > 0 && crop_ratios[ratio->get_active_row_number()].value < 1.0; if (pp->crop.orientation == "Landscape") { @@ -396,6 +413,20 @@ void Crop::read (const ProcParams* pp, const ParamsEdited* pedited) nw = pp->crop.w; nh = pp->crop.h; + customRatioLabel->hide(); + orientation->show(); + if (pp->crop.ratio == "As Image") { + ratio->set_active(0); + } else if (pp->crop.ratio == "Current") { + ratio->set_active(1); + updateCurrentRatio(); + customRatioLabel->show(); + orientation->hide(); + } else { + ratio->set_active_text (pp->crop.ratio); + } + fixr->set_active (pp->crop.fixratio); + lastRotationDeg = pp->coarse.rotate; wDirty = false; @@ -448,7 +479,13 @@ void Crop::write (ProcParams* pp, ParamsEdited* pedited) pp->crop.w = nw; pp->crop.h = nh; pp->crop.fixratio = fixr->get_active (); - pp->crop.ratio = ratio->get_active_text (); + if (ratio->get_active_row_number() == 0) { + pp->crop.ratio = "As Image"; + } else if (ratio->get_active_row_number() == 1) { + pp->crop.ratio = "Current"; + } else { + pp->crop.ratio = ratio->get_active_text (); + } // for historical reasons we store orientation different if ratio is written as 2:3 instead of 3:2, but in GUI 'landscape' is always long side horizontal regardless of the ratio is written short or long side first. const bool flip_orientation = fixr->get_active() && crop_ratios[ratio->get_active_row_number()].value > 0 && crop_ratios[ratio->get_active_row_number()].value < 1.0; @@ -701,6 +738,15 @@ void Crop::ratioFixedChanged () // change to orientation or ration void Crop::ratioChanged () { + if (ratio->get_active_row_number() == 1) { + orientation->hide(); + updateCurrentRatio(); + customRatioLabel->show(); + } else { + orientation->show(); + customRatioLabel->hide(); + } + if (!fixr->get_active ()) { fixr->set_active(true); // will adjust ratio anyway } else { @@ -880,6 +926,10 @@ bool Crop::refreshSpins (bool notify) wconn.block (false); hconn.block (false); + if (ratio->get_active_row_number() == 1 && !fixr->get_active()) { + updateCurrentRatio(); + } + refreshSize (); if (notify) { @@ -1405,3 +1455,12 @@ void Crop::setBatchMode (bool batchMode) removeIfThere (methodgrid, selectCrop); removeIfThere (methodgrid, resetCrop); } + + +void Crop::updateCurrentRatio() +{ + double rw, rh; + get_custom_ratio(w->get_value(), h->get_value(), rw, rh); + customRatioLabel->set_text(Glib::ustring::compose("%1:%2", rw, rh)); + crop_ratios[1].value = double(w->get_value())/double(h->get_value()); +} diff --git a/rtgui/crop.h b/rtgui/crop.h index a16683d1b..ed0661598 100644 --- a/rtgui/crop.h +++ b/rtgui/crop.h @@ -95,9 +95,10 @@ private: double value; }; - const std::vector crop_ratios; + std::vector crop_ratios; void adjustCropToRatio(); + void updateCurrentRatio(); Gtk::CheckButton* fixr; MyComboBoxText* ratio; @@ -117,6 +118,7 @@ private: Gtk::Label* sizein; Gtk::Grid* ppigrid; Gtk::Grid* methodgrid; + Gtk::Label *customRatioLabel; int maxw, maxh; double nx, ny;