Edit on double click
This commit is contained in:
parent
3431642cd2
commit
5b278bafdf
2 changed files with 46 additions and 12 deletions
|
|
@ -518,6 +518,12 @@ void SStyledKnob::setFontColor(CColor fontColor)
|
||||||
invalid();
|
invalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SStyledKnob::setValueToStringFunction(ValueToStringFunction func)
|
||||||
|
{
|
||||||
|
valueToStringFunction_ = std::move(func);
|
||||||
|
invalid();
|
||||||
|
}
|
||||||
|
|
||||||
void SStyledKnob::draw(CDrawContext* dc)
|
void SStyledKnob::draw(CDrawContext* dc)
|
||||||
{
|
{
|
||||||
const CCoord lineWidth = 4.0;
|
const CCoord lineWidth = 4.0;
|
||||||
|
|
@ -576,6 +582,15 @@ void SStyledKnob::draw(CDrawContext* dc)
|
||||||
dc->setLineStyle(kLineSolid);
|
dc->setLineStyle(kLineSolid);
|
||||||
dc->drawLine(p1, p2);
|
dc->drawLine(p1, p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (valueToStringFunction_ && fontColor_.alpha > 0 && !hideValue_) {
|
||||||
|
std::string text;
|
||||||
|
if (valueToStringFunction_(getValue(), text)) {
|
||||||
|
dc->setFont(font_);
|
||||||
|
dc->setFontColor(fontColor_);
|
||||||
|
dc->drawString(text.c_str(), bounds);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFilledRect::draw(CDrawContext* dc)
|
void CFilledRect::draw(CDrawContext* dc)
|
||||||
|
|
@ -622,7 +637,7 @@ SKnobCCBox::SKnobCCBox(const CRect& size, IControlListener* listener, int32_t ta
|
||||||
valueEdit_->setFontColor(CColor(0x00, 0x00, 0x00, 0xff));
|
valueEdit_->setFontColor(CColor(0x00, 0x00, 0x00, 0xff));
|
||||||
valueEdit_->registerViewListener(this);
|
valueEdit_->registerViewListener(this);
|
||||||
setHDMode(false);
|
setHDMode(false);
|
||||||
valueEdit_->setVisible(true);
|
valueEdit_->setVisible(false);
|
||||||
|
|
||||||
shadingRectangle_->setVisible(false);
|
shadingRectangle_->setVisible(false);
|
||||||
|
|
||||||
|
|
@ -648,11 +663,16 @@ SKnobCCBox::~SKnobCCBox()
|
||||||
void SKnobCCBox::setHDMode(bool mode)
|
void SKnobCCBox::setHDMode(bool mode)
|
||||||
{
|
{
|
||||||
if (mode) {
|
if (mode) {
|
||||||
valueEdit_->setValueToStringFunction2([](float value, std::string& text, VSTGUI::CParamDisplay*) -> bool {
|
auto valueToString = [](float value, std::string& text, VSTGUI::CParamDisplay*) -> bool {
|
||||||
std::string s = std::to_string(value + 0.005f);
|
std::string s = std::to_string(value + 0.005f);
|
||||||
text = s.substr(0, 4);
|
text = s.substr(0, 4);
|
||||||
return true;
|
return true;
|
||||||
|
};
|
||||||
|
knob_->setValueToStringFunction([valueToString](float value, std::string& text) {
|
||||||
|
return valueToString(value, text, nullptr);
|
||||||
});
|
});
|
||||||
|
valueEdit_->setValueToStringFunction2(valueToString);
|
||||||
|
|
||||||
valueEdit_->setStringToValueFunction([](UTF8StringPtr txt, float& result, CTextEdit*) -> bool {
|
valueEdit_->setStringToValueFunction([](UTF8StringPtr txt, float& result, CTextEdit*) -> bool {
|
||||||
float value;
|
float value;
|
||||||
if (absl::SimpleAtof(txt, &value)) {
|
if (absl::SimpleAtof(txt, &value)) {
|
||||||
|
|
@ -664,10 +684,15 @@ void SKnobCCBox::setHDMode(bool mode)
|
||||||
});
|
});
|
||||||
menuEntry_->setTitle("Use low-res. CC");
|
menuEntry_->setTitle("Use low-res. CC");
|
||||||
} else {
|
} else {
|
||||||
valueEdit_->setValueToStringFunction2([](float value, std::string& text, VSTGUI::CParamDisplay*) -> bool {
|
auto valueToString = [](float value, std::string& text, VSTGUI::CParamDisplay*) -> bool {
|
||||||
text = std::to_string(std::lround(value * 127));
|
text = std::to_string(std::lround(value * 127));
|
||||||
return true;
|
return true;
|
||||||
|
};
|
||||||
|
knob_->setValueToStringFunction([valueToString](float value, std::string& text) {
|
||||||
|
return valueToString(value, text, nullptr);
|
||||||
});
|
});
|
||||||
|
valueEdit_->setValueToStringFunction2(valueToString);
|
||||||
|
|
||||||
valueEdit_->setStringToValueFunction([](UTF8StringPtr txt, float& result, CTextEdit*) -> bool {
|
valueEdit_->setStringToValueFunction([](UTF8StringPtr txt, float& result, CTextEdit*) -> bool {
|
||||||
float value;
|
float value;
|
||||||
if (absl::SimpleAtof(txt, &value)) {
|
if (absl::SimpleAtof(txt, &value)) {
|
||||||
|
|
@ -708,6 +733,12 @@ CMouseEventResult SKnobCCBox::onMouseDown(CPoint& where, const CButtonState& but
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return kMouseEventHandled;
|
return kMouseEventHandled;
|
||||||
|
} else if (buttons.isDoubleClick() && !valueEdit_->isVisible()) {
|
||||||
|
valueEdit_->setVisible(true);
|
||||||
|
shadingRectangle_->setVisible(true);
|
||||||
|
knob_->setHideValue(true);
|
||||||
|
valueEdit_->takeFocus();
|
||||||
|
invalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
return CViewContainer::onMouseDown(where, buttons);
|
return CViewContainer::onMouseDown(where, buttons);
|
||||||
|
|
@ -717,14 +748,8 @@ void SKnobCCBox::viewLostFocus (CView* view)
|
||||||
{
|
{
|
||||||
if (view == valueEdit_.get()) {
|
if (view == valueEdit_.get()) {
|
||||||
shadingRectangle_->setVisible(false);
|
shadingRectangle_->setVisible(false);
|
||||||
invalid();
|
valueEdit_->setVisible(false);
|
||||||
}
|
knob_->setHideValue(false);
|
||||||
}
|
|
||||||
|
|
||||||
void SKnobCCBox::viewTookFocus (CView* view)
|
|
||||||
{
|
|
||||||
if (view == valueEdit_.get()) {
|
|
||||||
shadingRectangle_->setVisible(true);
|
|
||||||
invalid();
|
invalid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -231,6 +231,12 @@ public:
|
||||||
void setFontColor(CColor fontColor);
|
void setFontColor(CColor fontColor);
|
||||||
CColor getFontColor() const { return fontColor_; }
|
CColor getFontColor() const { return fontColor_; }
|
||||||
|
|
||||||
|
using ValueToStringFunction = std::function<bool(float value, std::string& result)>;
|
||||||
|
void setValueToStringFunction(ValueToStringFunction func);
|
||||||
|
|
||||||
|
void setHideValue(bool hide) { hideValue_ = hide; invalid(); }
|
||||||
|
bool getHideValue() const { return hideValue_; }
|
||||||
|
|
||||||
CLASS_METHODS(SStyledKnob, CKnobBase)
|
CLASS_METHODS(SStyledKnob, CKnobBase)
|
||||||
protected:
|
protected:
|
||||||
void draw(CDrawContext* dc) override;
|
void draw(CDrawContext* dc) override;
|
||||||
|
|
@ -239,9 +245,12 @@ private:
|
||||||
CColor activeTrackColor_;
|
CColor activeTrackColor_;
|
||||||
CColor inactiveTrackColor_;
|
CColor inactiveTrackColor_;
|
||||||
CColor lineIndicatorColor_;
|
CColor lineIndicatorColor_;
|
||||||
|
bool hideValue_ { false };
|
||||||
|
|
||||||
SharedPointer<CFontDesc> font_ = kNormalFont;
|
SharedPointer<CFontDesc> font_ = kNormalFont;
|
||||||
CColor fontColor_ { 0x00, 0x00, 0x00 };
|
CColor fontColor_ { 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
|
ValueToStringFunction valueToStringFunction_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CFilledRect : public CView
|
class CFilledRect : public CView
|
||||||
|
|
@ -319,8 +328,8 @@ public:
|
||||||
void setKnobFontColor(CColor color) { knob_->setFontColor(color); knob_->invalid(); }
|
void setKnobFontColor(CColor color) { knob_->setFontColor(color); knob_->invalid(); }
|
||||||
CColor getKnobFontColor() const { return knob_->getFontColor(); }
|
CColor getKnobFontColor() const { return knob_->getFontColor(); }
|
||||||
|
|
||||||
|
// Edit box listener
|
||||||
void viewLostFocus (CView* view) override;
|
void viewLostFocus (CView* view) override;
|
||||||
void viewTookFocus (CView* view) override;
|
|
||||||
|
|
||||||
bool isHD() const noexcept { return hdMode_; }
|
bool isHD() const noexcept { return hdMode_; }
|
||||||
void setHDMode(bool mode);
|
void setHDMode(bool mode);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue