Applied changes suggested by @Floessie, #5320
This commit is contained in:
@@ -25,16 +25,30 @@
|
|||||||
#include "guiutils.h"
|
#include "guiutils.h"
|
||||||
#include "rtimage.h"
|
#include "rtimage.h"
|
||||||
|
|
||||||
#define MIN_RESET_BUTTON_HEIGHT 17
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
constexpr int MIN_RESET_BUTTON_HEIGHT = 17;
|
||||||
|
|
||||||
double one2one(double val)
|
double one2one(double val)
|
||||||
{
|
{
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Adjuster::Adjuster (Glib::ustring vlabel, double vmin, double vmax, double vstep, double vdefault, Gtk::Image *imgIcon1, Gtk::Image *imgIcon2, double2double_fun slider2value_, double2double_fun value2slider_) :
|
Adjuster::Adjuster (
|
||||||
|
Glib::ustring vlabel,
|
||||||
|
double vmin,
|
||||||
|
double vmax,
|
||||||
|
double vstep,
|
||||||
|
double vdefault,
|
||||||
|
Gtk::Image *imgIcon1,
|
||||||
|
Gtk::Image *imgIcon2,
|
||||||
|
double2double_fun slider2value,
|
||||||
|
double2double_fun value2slider)
|
||||||
|
|
||||||
|
:
|
||||||
|
|
||||||
adjustmentName(std::move(vlabel)),
|
adjustmentName(std::move(vlabel)),
|
||||||
grid(nullptr),
|
grid(nullptr),
|
||||||
label(nullptr),
|
label(nullptr),
|
||||||
@@ -52,8 +66,8 @@ Adjuster::Adjuster (Glib::ustring vlabel, double vmin, double vmax, double vstep
|
|||||||
logBase(0),
|
logBase(0),
|
||||||
logPivot(0),
|
logPivot(0),
|
||||||
logAnchorMiddle(false),
|
logAnchorMiddle(false),
|
||||||
value2slider(value2slider_ ? value2slider_ : one2one),
|
value2slider(value2slider ? value2slider : &one2one),
|
||||||
slider2value(slider2value_ ? slider2value_ : one2one),
|
slider2value(slider2value ? slider2value : &one2one),
|
||||||
delay(options.adjusterMinDelay)
|
delay(options.adjusterMinDelay)
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -156,13 +170,12 @@ Adjuster::~Adjuster ()
|
|||||||
delayConnection.block(true);
|
delayConnection.block(true);
|
||||||
adjusterListener = nullptr;
|
adjusterListener = nullptr;
|
||||||
|
|
||||||
delete automatic;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Adjuster::addAutoButton (Glib::ustring tooltip)
|
void Adjuster::addAutoButton (const Glib::ustring &tooltip)
|
||||||
{
|
{
|
||||||
if (!automatic) {
|
if (!automatic) {
|
||||||
automatic = new Gtk::CheckButton();
|
automatic = Gtk::manage(new Gtk::CheckButton());
|
||||||
//automatic->add (*Gtk::manage (new RTImage ("gears.png")));
|
//automatic->add (*Gtk::manage (new RTImage ("gears.png")));
|
||||||
automatic->set_tooltip_markup(tooltip.length() ? Glib::ustring::compose("<b>%1</b>\n\n%2", M("GENERAL_AUTO"), tooltip) : M("GENERAL_AUTO"));
|
automatic->set_tooltip_markup(tooltip.length() ? Glib::ustring::compose("<b>%1</b>\n\n%2", M("GENERAL_AUTO"), tooltip) : M("GENERAL_AUTO"));
|
||||||
setExpandAlignProperties(automatic, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER);
|
setExpandAlignProperties(automatic, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER);
|
||||||
@@ -302,8 +315,8 @@ void Adjuster::resetPressed (GdkEventButton* event)
|
|||||||
|
|
||||||
double Adjuster::shapeValue (double a) const
|
double Adjuster::shapeValue (double a) const
|
||||||
{
|
{
|
||||||
const double pow10 = pow(10.0, digits);
|
const double pow10 = std::pow(10.0, digits);
|
||||||
const double val = round(a * pow10) / pow10;
|
const double val = std::round(a * pow10) / pow10;
|
||||||
return val == -0.0 ? 0.0 : val;
|
return val == -0.0 ? 0.0 : val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,7 +326,7 @@ void Adjuster::setLimits (double vmin, double vmax, double vstep, double vdefaul
|
|||||||
spinChange.block(true);
|
spinChange.block(true);
|
||||||
|
|
||||||
double pow10 = vstep;
|
double pow10 = vstep;
|
||||||
for (digits = 0; fabs(pow10 - floor(pow10)) > 0.000000000001; digits++, pow10 *= 10.0);
|
for (digits = 0; std::fabs(pow10 - floor(pow10)) > 0.000000000001; digits++, pow10 *= 10.0);
|
||||||
|
|
||||||
const double shapeVal = shapeValue(vdefault);
|
const double shapeVal = shapeValue(vdefault);
|
||||||
spin->set_digits(digits);
|
spin->set_digits(digits);
|
||||||
@@ -557,7 +570,6 @@ void Adjuster::showEditedCB ()
|
|||||||
|
|
||||||
void Adjuster::editedToggled ()
|
void Adjuster::editedToggled ()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (adjusterListener && !blocked) {
|
if (adjusterListener && !blocked) {
|
||||||
adjusterListener->adjusterChanged(this, spin->get_value());
|
adjusterListener->adjusterChanged(this, spin->get_value());
|
||||||
}
|
}
|
||||||
@@ -567,26 +579,20 @@ void Adjuster::editedToggled ()
|
|||||||
|
|
||||||
void Adjuster::trimValue (double &val) const
|
void Adjuster::trimValue (double &val) const
|
||||||
{
|
{
|
||||||
|
|
||||||
val = rtengine::LIM(val, vMin, vMax);
|
val = rtengine::LIM(val, vMin, vMax);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Adjuster::trimValue (int &val) const
|
void Adjuster::trimValue (int &val) const
|
||||||
{
|
{
|
||||||
|
|
||||||
val = rtengine::LIM<int>(val, vMin, vMax);
|
val = rtengine::LIM<int>(val, vMin, vMax);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Adjuster::trimValue (float &val) const
|
void Adjuster::trimValue (float &val) const
|
||||||
{
|
{
|
||||||
|
|
||||||
val = rtengine::LIM<float>(val, vMin, vMax);
|
val = rtengine::LIM<float>(val, vMin, vMax);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double Adjuster::getSliderValue() const
|
double Adjuster::getSliderValue() const
|
||||||
{
|
{
|
||||||
double val = slider->get_value();
|
double val = slider->get_value();
|
||||||
if (logBase) {
|
if (logBase) {
|
||||||
@@ -596,29 +602,28 @@ inline double Adjuster::getSliderValue() const
|
|||||||
if (val >= mmid) {
|
if (val >= mmid) {
|
||||||
double range = vMax - mmid;
|
double range = vMax - mmid;
|
||||||
double x = (val - mmid) / range;
|
double x = (val - mmid) / range;
|
||||||
val = logPivot + (pow(logBase, x) - 1.0) / (logBase - 1.0) * (vMax - logPivot);
|
val = logPivot + (std::pow(logBase, x) - 1.0) / (logBase - 1.0) * (vMax - logPivot);
|
||||||
} else {
|
} else {
|
||||||
double range = mmid - vMin;
|
double range = mmid - vMin;
|
||||||
double x = (mmid - val) / range;
|
double x = (mmid - val) / range;
|
||||||
val = logPivot - (pow(logBase, x) - 1.0) / (logBase - 1.0) * (logPivot - vMin);
|
val = logPivot - (std::pow(logBase, x) - 1.0) / (logBase - 1.0) * (logPivot - vMin);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (val >= logPivot) {
|
if (val >= logPivot) {
|
||||||
double range = vMax - logPivot;
|
double range = vMax - logPivot;
|
||||||
double x = (val - logPivot) / range;
|
double x = (val - logPivot) / range;
|
||||||
val = logPivot + (pow(logBase, x) - 1.0) / (logBase - 1.0) * range;
|
val = logPivot + (std::pow(logBase, x) - 1.0) / (logBase - 1.0) * range;
|
||||||
} else {
|
} else {
|
||||||
double range = logPivot - vMin;
|
double range = logPivot - vMin;
|
||||||
double x = (logPivot - val) / range;
|
double x = (logPivot - val) / range;
|
||||||
val = logPivot - (pow(logBase, x) - 1.0) / (logBase - 1.0) * range;
|
val = logPivot - (std::pow(logBase, x) - 1.0) / (logBase - 1.0) * range;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Adjuster::setSliderValue(double val)
|
||||||
inline void Adjuster::setSliderValue(double val)
|
|
||||||
{
|
{
|
||||||
if (logBase) {
|
if (logBase) {
|
||||||
if (logAnchorMiddle) {
|
if (logAnchorMiddle) {
|
||||||
@@ -626,28 +631,27 @@ inline void Adjuster::setSliderValue(double val)
|
|||||||
if (val >= logPivot) {
|
if (val >= logPivot) {
|
||||||
double range = vMax - logPivot;
|
double range = vMax - logPivot;
|
||||||
double x = (val - logPivot) / range;
|
double x = (val - logPivot) / range;
|
||||||
val = (vMin + mid) + log(x * (logBase - 1.0) + 1.0) / log(logBase) * mid;
|
val = (vMin + mid) + std::log(x * (logBase - 1.0) + 1.0) / std::log(logBase) * mid;
|
||||||
} else {
|
} else {
|
||||||
double range = logPivot - vMin;
|
double range = logPivot - vMin;
|
||||||
double x = (logPivot - val) / range;
|
double x = (logPivot - val) / range;
|
||||||
val = (vMin + mid) - log(x * (logBase - 1.0) + 1.0) / log(logBase) * mid;
|
val = (vMin + mid) - std::log(x * (logBase - 1.0) + 1.0) / std::log(logBase) * mid;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (val >= logPivot) {
|
if (val >= logPivot) {
|
||||||
double range = vMax - logPivot;
|
double range = vMax - logPivot;
|
||||||
double x = (val - logPivot) / range;
|
double x = (val - logPivot) / range;
|
||||||
val = logPivot + log(x * (logBase - 1.0) + 1.0) / log(logBase) * range;
|
val = logPivot + std::log(x * (logBase - 1.0) + 1.0) / std::log(logBase) * range;
|
||||||
} else {
|
} else {
|
||||||
double range = logPivot - vMin;
|
double range = logPivot - vMin;
|
||||||
double x = (logPivot - val) / range;
|
double x = (logPivot - val) / range;
|
||||||
val = logPivot - log(x * (logBase - 1.0) + 1.0) / log(logBase) * range;
|
val = logPivot - std::log(x * (logBase - 1.0) + 1.0) / std::log(logBase) * range;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
slider->set_value(val);
|
slider->set_value(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Adjuster::setLogScale(double base, double pivot, bool anchorMiddle)
|
void Adjuster::setLogScale(double base, double pivot, bool anchorMiddle)
|
||||||
{
|
{
|
||||||
spinChange.block(true);
|
spinChange.block(true);
|
||||||
@@ -662,3 +666,61 @@ void Adjuster::setLogScale(double base, double pivot, bool anchorMiddle)
|
|||||||
sliderChange.block(false);
|
sliderChange.block(false);
|
||||||
spinChange.block(false);
|
spinChange.block(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Adjuster::getAutoValue() const
|
||||||
|
{
|
||||||
|
return automatic ? automatic->get_active() : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Adjuster::setAutoInconsistent(bool i)
|
||||||
|
{
|
||||||
|
if (automatic) {
|
||||||
|
automatic->set_inconsistent(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adjuster::getAutoInconsistent() const
|
||||||
|
{
|
||||||
|
return automatic ? automatic->get_inconsistent() : true /* we have to return something */;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Adjuster::setAdjusterListener (AdjusterListener* alistener)
|
||||||
|
{
|
||||||
|
adjusterListener = alistener;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Adjuster::getValue() const
|
||||||
|
{
|
||||||
|
return shapeValue(spin->get_value());
|
||||||
|
}
|
||||||
|
|
||||||
|
int Adjuster::getIntValue() const
|
||||||
|
{
|
||||||
|
return spin->get_value_as_int();
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::ustring Adjuster::getTextValue() const
|
||||||
|
{
|
||||||
|
if (addMode) {
|
||||||
|
return Glib::ustring::compose("<i>%1</i>", spin->get_text());
|
||||||
|
} else {
|
||||||
|
return spin->get_text();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Adjuster::setLabel(const Glib::ustring &lbl)
|
||||||
|
{
|
||||||
|
label->set_label(lbl);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adjuster::block(bool isBlocked)
|
||||||
|
{
|
||||||
|
bool oldValue = blocked;
|
||||||
|
blocked = isBlocked;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adjuster::getAddMode() const
|
||||||
|
{
|
||||||
|
return addMode;
|
||||||
|
}
|
||||||
|
@@ -83,87 +83,40 @@ public:
|
|||||||
|
|
||||||
int delay;
|
int delay;
|
||||||
|
|
||||||
Adjuster (Glib::ustring vlabel, double vmin, double vmax, double vstep, double vdefault, Gtk::Image *imgIcon1 = nullptr, Gtk::Image *imgIcon2 = nullptr, double2double_fun slider2value_ = nullptr, double2double_fun value2slider_ = nullptr);
|
Adjuster (Glib::ustring vlabel, double vmin, double vmax, double vstep, double vdefault, Gtk::Image *imgIcon1 = nullptr, Gtk::Image *imgIcon2 = nullptr, double2double_fun slider2value = nullptr, double2double_fun value2slider = nullptr);
|
||||||
~Adjuster () override;
|
~Adjuster () override;
|
||||||
|
|
||||||
// Add an "Automatic" checkbox next to the reset button.
|
// Add an "Automatic" checkbox next to the reset button.
|
||||||
void addAutoButton(Glib::ustring tooltip = "");
|
void addAutoButton(const Glib::ustring &tooltip = "");
|
||||||
// Send back the value of og the Auto checkbox
|
// Send back the value of og the Auto checkbox
|
||||||
bool getAutoValue ()
|
bool getAutoValue() const;
|
||||||
{
|
void setAutoValue(bool a);
|
||||||
return automatic ? automatic->get_active() : false;
|
bool notifyListenerAutoToggled();
|
||||||
}
|
void autoToggled();
|
||||||
void setAutoValue (bool a);
|
void setAutoInconsistent(bool i);
|
||||||
bool notifyListenerAutoToggled ();
|
bool getAutoInconsistent() const;
|
||||||
void autoToggled ();
|
void setAdjusterListener(AdjusterListener* alistener);
|
||||||
void setAutoInconsistent (bool i)
|
|
||||||
{
|
|
||||||
if (automatic) {
|
|
||||||
automatic->set_inconsistent(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bool getAutoInconsistent () const
|
|
||||||
{
|
|
||||||
return automatic ? automatic->get_inconsistent() : true /* we have to return something */;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAdjusterListener (AdjusterListener* alistener)
|
|
||||||
{
|
|
||||||
adjusterListener = alistener;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the value trimmed to the limits at construction time
|
// return the value trimmed to the limits at construction time
|
||||||
double getValue () const
|
double getValue() const;
|
||||||
{
|
|
||||||
return shapeValue(spin->get_value());
|
|
||||||
}
|
|
||||||
// return the value trimmed to the limits at construction time
|
// return the value trimmed to the limits at construction time
|
||||||
int getIntValue () const
|
int getIntValue() const;
|
||||||
{
|
|
||||||
return spin->get_value_as_int();
|
|
||||||
}
|
|
||||||
// return the value trimmed to the limits at construction time,
|
// return the value trimmed to the limits at construction time,
|
||||||
// method only used by the history manager, so decoration is added if addMode=true
|
// method only used by the history manager, so decoration is added if addMode=true
|
||||||
Glib::ustring getTextValue () const
|
Glib::ustring getTextValue() const;
|
||||||
{
|
void setLabel (const Glib::ustring &lbl);
|
||||||
if (addMode) {
|
|
||||||
return Glib::ustring::compose("<i>%1</i>", spin->get_text());
|
|
||||||
} else {
|
|
||||||
return spin->get_text();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setLabel (const Glib::ustring &lbl)
|
|
||||||
{
|
|
||||||
label->set_label(lbl);
|
|
||||||
}
|
|
||||||
void setValue (double a);
|
void setValue (double a);
|
||||||
void setLimits (double vmin, double vmax, double vstep, double vdefault);
|
void setLimits (double vmin, double vmax, double vstep, double vdefault);
|
||||||
void setEnabled (bool enabled);
|
void setEnabled (bool enabled);
|
||||||
void setDefault (double def);
|
void setDefault (double def);
|
||||||
// will let the adjuster throw it's "changed" signal when the mouse button is released. Can work altogether with the delay value.
|
// will let the adjuster throw it's "changed" signal when the mouse button is released. Can work altogether with the delay value.
|
||||||
void throwOnButtonRelease(bool throwOnBRelease = true);
|
void throwOnButtonRelease(bool throwOnBRelease = true);
|
||||||
void setNbDisplayedChars (int nbr)
|
|
||||||
{
|
|
||||||
spin->set_width_chars(nbr);
|
|
||||||
spin->set_max_width_chars(nbr);
|
|
||||||
}
|
|
||||||
void setEditedState (EditedState eState);
|
void setEditedState (EditedState eState);
|
||||||
EditedState getEditedState ();
|
EditedState getEditedState ();
|
||||||
void setDefaultEditedState (EditedState eState);
|
void setDefaultEditedState (EditedState eState);
|
||||||
void showEditedCB ();
|
void showEditedCB ();
|
||||||
bool block(bool isBlocked)
|
bool block(bool isBlocked);
|
||||||
{
|
|
||||||
bool oldValue = blocked;
|
|
||||||
blocked = isBlocked;
|
|
||||||
return oldValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAddMode(bool addM);
|
void setAddMode(bool addM);
|
||||||
bool getAddMode() const
|
bool getAddMode() const;
|
||||||
{
|
|
||||||
return addMode;
|
|
||||||
};
|
|
||||||
void spinChanged ();
|
void spinChanged ();
|
||||||
void sliderChanged ();
|
void sliderChanged ();
|
||||||
bool notifyListener ();
|
bool notifyListener ();
|
||||||
@@ -175,7 +128,6 @@ public:
|
|||||||
void trimValue (double &val) const;
|
void trimValue (double &val) const;
|
||||||
void trimValue (float &val) const;
|
void trimValue (float &val) const;
|
||||||
void trimValue (int &val) const;
|
void trimValue (int &val) const;
|
||||||
|
|
||||||
void setLogScale(double base, double pivot, bool anchorMiddle = false);
|
void setLogScale(double base, double pivot, bool anchorMiddle = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user