Add glowing lines
This commit is contained in:
parent
65cd227f46
commit
cdb32287e3
4 changed files with 57 additions and 4 deletions
|
|
@ -1668,16 +1668,23 @@ void GraphEditorWidget::updateMeters() {
|
|||
m_masterMeterR->setLevel(master.value.peak_right);
|
||||
}
|
||||
|
||||
bool anyActive = false;
|
||||
for (auto &[nodeId, row] : m_nodeMeters) {
|
||||
const WarpNodeData *data = m_model->warpNodeData(nodeId);
|
||||
if (!data || !row.meter)
|
||||
continue;
|
||||
auto peak = m_client->NodeMeterPeak(data->info.id);
|
||||
if (peak.ok()) {
|
||||
row.meter->setLevel(
|
||||
std::max(peak.value.peak_left, peak.value.peak_right));
|
||||
float level = std::max(peak.value.peak_left, peak.value.peak_right);
|
||||
row.meter->setLevel(level);
|
||||
m_model->setNodePeakLevel(nodeId, level);
|
||||
if (level > 0.001f)
|
||||
anyActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (anyActive && m_scene)
|
||||
m_scene->update();
|
||||
}
|
||||
|
||||
void GraphEditorWidget::rebuildNodeMeters() {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "SquareConnectionPainter.h"
|
||||
#include "WarpGraphModel.h"
|
||||
|
||||
#include <QtNodes/internal/BasicGraphicsScene.hpp>
|
||||
#include <QtNodes/internal/ConnectionGraphicsObject.hpp>
|
||||
|
|
@ -187,6 +188,30 @@ void SquareConnectionPainter::paint(
|
|||
|
||||
auto path = orthogonalPath(cgo);
|
||||
|
||||
float peakLevel = 0.0f;
|
||||
auto *scene = cgo.nodeScene();
|
||||
if (scene) {
|
||||
auto *model = dynamic_cast<WarpGraphModel *>(&scene->graphModel());
|
||||
if (model) {
|
||||
auto cId = cgo.connectionId();
|
||||
peakLevel = std::max(model->nodePeakLevel(cId.outNodeId),
|
||||
model->nodePeakLevel(cId.inNodeId));
|
||||
}
|
||||
}
|
||||
|
||||
auto activeColor = [&](QColor base) -> QColor {
|
||||
if (peakLevel < 0.005f)
|
||||
return base;
|
||||
float t = std::min(peakLevel * 2.0f, 1.0f);
|
||||
int r = static_cast<int>(base.red() + t * (60 - base.red()));
|
||||
int g = static_cast<int>(base.green() + t * (210 - base.green()));
|
||||
int b = static_cast<int>(base.blue() + t * (80 - base.blue()));
|
||||
return QColor(std::clamp(r, 0, 255),
|
||||
std::clamp(g, 0, 255),
|
||||
std::clamp(b, 0, 255),
|
||||
base.alpha());
|
||||
};
|
||||
|
||||
if (hovered || selected) {
|
||||
QPen pen;
|
||||
pen.setWidth(static_cast<int>(2 * style.lineWidth()));
|
||||
|
|
@ -205,9 +230,15 @@ void SquareConnectionPainter::paint(
|
|||
painter->setBrush(Qt::NoBrush);
|
||||
painter->drawPath(path);
|
||||
} else {
|
||||
QColor base = selected ? style.selectedColor() : style.normalColor();
|
||||
QColor color = activeColor(base);
|
||||
float width = style.lineWidth();
|
||||
if (peakLevel > 0.005f)
|
||||
width += peakLevel * 1.5f;
|
||||
|
||||
QPen pen;
|
||||
pen.setWidth(style.lineWidth());
|
||||
pen.setColor(selected ? style.selectedColor() : style.normalColor());
|
||||
pen.setWidthF(width);
|
||||
pen.setColor(color);
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->drawPath(path);
|
||||
|
|
|
|||
|
|
@ -965,6 +965,17 @@ WarpGraphModel::nodeVolumeState(QtNodes::NodeId nodeId) const {
|
|||
return {};
|
||||
}
|
||||
|
||||
void WarpGraphModel::setNodePeakLevel(QtNodes::NodeId nodeId, float level) {
|
||||
constexpr float kDecay = 0.82f;
|
||||
float &stored = m_peakLevels[nodeId];
|
||||
stored = std::max(level, stored * kDecay);
|
||||
}
|
||||
|
||||
float WarpGraphModel::nodePeakLevel(QtNodes::NodeId nodeId) const {
|
||||
auto it = m_peakLevels.find(nodeId);
|
||||
return it != m_peakLevels.end() ? it->second : 0.0f;
|
||||
}
|
||||
|
||||
void WarpGraphModel::saveLayout(const QString &path) const {
|
||||
ViewState vs{};
|
||||
saveLayout(path, vs);
|
||||
|
|
|
|||
|
|
@ -95,6 +95,9 @@ public:
|
|||
void setNodeVolumeState(QtNodes::NodeId nodeId, const NodeVolumeState &state);
|
||||
NodeVolumeState nodeVolumeState(QtNodes::NodeId nodeId) const;
|
||||
|
||||
void setNodePeakLevel(QtNodes::NodeId nodeId, float level);
|
||||
float nodePeakLevel(QtNodes::NodeId nodeId) const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void beginBatchUpdate();
|
||||
void endBatchUpdate();
|
||||
|
|
@ -169,4 +172,5 @@ private:
|
|||
std::unordered_map<QtNodes::NodeId, NodeVolumeState> m_volumeStates;
|
||||
std::unordered_map<QtNodes::NodeId, QPointer<QWidget>> m_volumeWidgets;
|
||||
mutable std::unordered_map<QtNodes::NodeId, QVariant> m_styleCache;
|
||||
std::unordered_map<QtNodes::NodeId, float> m_peakLevels;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue