Skip to content

Commit

Permalink
Merge branch 'develop' into feature/heavy-js
Browse files Browse the repository at this point in the history
  • Loading branch information
dromer committed Nov 7, 2024
2 parents 09a8ca6 + 8ab69e9 commit 6cc7272
Show file tree
Hide file tree
Showing 31 changed files with 199 additions and 287 deletions.
2 changes: 1 addition & 1 deletion Libraries/nanovg
Submodule nanovg updated 4 files
+26 −39 src/nanovg.cpp
+17 −21 src/nanovg.h
+147 −246 src/nanovg_gl.h
+62 −130 src/nanovg_mtl.m
2 changes: 1 addition & 1 deletion Libraries/pure-data
Submodule pure-data updated 1 files
+4 −1 src/s_inter.c
23 changes: 13 additions & 10 deletions Source/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ Canvas::Canvas(PluginEditor* parent, pd::Patch::Ptr p, Component* parentGraph)

if (auto patchPtr = patch.getPointer()) {
isGraphChild = glist_isgraph(patchPtr.get());
hideNameAndArgs = static_cast<bool>(patchPtr->gl_hidetext);
xRange = VarArray { var(patchPtr->gl_x1), var(patchPtr->gl_x2) };
yRange = VarArray { var(patchPtr->gl_y2), var(patchPtr->gl_y1) };
}

hideNameAndArgs = static_cast<bool>(patch.getPointer()->gl_hidetext);
xRange = VarArray { var(patch.getPointer()->gl_x1), var(patch.getPointer()->gl_x2) };
yRange = VarArray { var(patch.getPointer()->gl_y2), var(patch.getPointer()->gl_y1) };

pd->registerMessageListener(patch.getUncheckedPointer(), this);

isGraphChild.addListener(this);
Expand Down Expand Up @@ -153,9 +152,9 @@ Canvas::Canvas(PluginEditor* parent, pd::Patch::Ptr p, Component* parentGraph)
// Start in unlocked mode if the patch is empty
if (objects.empty()) {
locked = false;
patch.getPointer()->gl_edit = false;
if(auto patchPtr = patch.getPointer()) patchPtr->gl_edit = false;
} else {
locked = !patch.getPointer()->gl_edit;
if(auto patchPtr = patch.getPointer()) locked = !patchPtr->gl_edit;
}

locked.addListener(this);
Expand All @@ -178,7 +177,9 @@ Canvas::Canvas(PluginEditor* parent, pd::Patch::Ptr p, Component* parentGraph)
parameters.addParamInt("Width", cDimensions, &patchWidth, 527, onInteractionFn);
parameters.addParamInt("Height", cDimensions, &patchHeight, 327, onInteractionFn);

patch.setVisible(true);
if(!isGraph) {
patch.setVisible(true);
}

lookAndFeelChanged();
}
Expand All @@ -193,6 +194,7 @@ Canvas::~Canvas()
zoomScale.removeListener(this);
editor->removeModifierKeyListener(this);
pd->unregisterMessageListener(patch.getUncheckedPointer(), this);
patch.setVisible(false);
}

void Canvas::lookAndFeelChanged()
Expand Down Expand Up @@ -824,8 +826,8 @@ void Canvas::save(std::function<void()> const& nestedCallback)
if (canvasToSave->patch.getCurrentFile().existsAsFile()) {
canvasToSave->patch.savePatch();
SettingsFile::getInstance()->addToRecentlyOpened(canvasToSave->patch.getCurrentFile());
nestedCallback();
pd->titleChanged();
nestedCallback();
} else {
saveAs(nestedCallback);
}
Expand Down Expand Up @@ -2251,8 +2253,9 @@ void Canvas::valueChanged(Value& v)
snprintf(buf, MAXPDSTRING - 1, ".x%lx", (unsigned long)cnv.get());
pd->sendMessage(buf, "setbounds", { x1, y1, x2, y2 });
}

patch.getPointer()->gl_screenx2 = getValue<int>(patchWidth) + patch.getPointer()->gl_screenx1;
if(auto patchPtr = patch.getPointer()) {
patchPtr->gl_screenx2 = getValue<int>(patchWidth) + patchPtr->gl_screenx1;
}
repaint();
} else if (v.refersToSameSourceAs(patchHeight)) {
patchHeight = jmax(11, getValue<int>(patchHeight));
Expand Down
16 changes: 8 additions & 8 deletions Source/Canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,27 @@ class Canvas : public Component

std::unique_ptr<Viewport> viewport = nullptr;

bool connectingWithDrag = false;
bool connectionCancelled = false;
bool connectingWithDrag:1 = false;
bool connectionCancelled:1 = false;
SafePointer<Iolet> nearestIolet;

std::unique_ptr<SuggestionComponent> suggestor;

pd::Patch::Ptr refCountedPatch;
pd::Patch& patch;

Value locked = SynchronousValue();
Value commandLocked;
Value presentationMode;

SmallArray<juce::WeakReference<NVGComponent>> drawables;

// Needs to be allocated before object and connection so they can deselect themselves in the destructor
SelectedItemSet<WeakReference<Component>> selectedComponents;
PooledPtrArray<Object> objects;
PooledPtrArray<Connection> connections;
PooledPtrArray<ConnectionBeingCreated> connectionsBeingCreated;

Value locked = SynchronousValue();
Value commandLocked;
Value presentationMode;

bool showOrigin : 1 = false;
bool showBorder : 1 = false;
bool showConnectionOrder : 1 = false;
Expand Down Expand Up @@ -267,8 +269,6 @@ class Canvas : public Component
NVGImage resizeHandleImage;
NVGImage presentationShadowImage;

SmallArray<juce::WeakReference<NVGComponent>> drawables;

NVGcolor canvasBackgroundCol;
Colour canvasBackgroundColJuce;
NVGcolor canvasMarkingsCol;
Expand Down
4 changes: 3 additions & 1 deletion Source/Components/ConnectionMessageDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ class ConnectionMessageDisplay
if (activeConnection == nullptr && connection == nullptr)
return;

if (editor->pluginMode || (connection && connection->inobj && getValue<bool>(connection->inobj->cnv->presentationMode)))
if (editor->pluginMode || (connection && connection->inobj && getValue<bool>(connection->inobj->cnv->presentationMode))) {
hideDisplay();
return;
}

auto clearSignalDisplayBuffer = [this]() {
SignalBlock sample;
Expand Down
82 changes: 44 additions & 38 deletions Source/Components/DraggableNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ class DraggableNumber : public Label
protected:
int16 decimalDrag = 0;
int16 hoveredDecimal = -1;
float dragValue = 0.0;
double dragValue = 0.0;
Rectangle<float> hoveredDecimalPosition;

float lastValue = 0.0;
float logarithmicHeight = 256.0f;
double lastValue = 0.0;
double logarithmicHeight = 256.0;
int16 lastLogarithmicDragPosition = 0;
float min = 0.0, max = 0.0;
double min = 0.0, max = 0.0;

DragMode dragMode:2 = Regular;
bool isMinLimited:1 = false;
bool isMaxLimited:1 = false;
bool resetOnCommandClick:1 = false;
bool wasReset:1 = false;
bool showEllipses:1 = true;
float valueToResetTo = 0.0;
float valueToRevertTo = 0.0;
double valueToResetTo = 0.0;
double valueToRevertTo = 0.0;
Colour outlineColour, textColour;

std::unique_ptr<NanoVGGraphicsContext> nvgCtx;

public:
std::function<void(float)> onValueChange = [](float) { };
std::function<void(double)> onValueChange = [](double) { };
std::function<void()> dragStart = []() { };
std::function<void()> dragEnd = []() { };

Expand Down Expand Up @@ -106,13 +106,13 @@ class DraggableNumber : public Label
setInterceptsMouseClicks(true, true);
}

void setMaximum(float maximum)
void setMaximum(double maximum)
{
isMaxLimited = true;
max = maximum;
}

void setMinimum(float minimum)
void setMinimum(double minimum)
{
isMinLimited = true;
min = minimum;
Expand Down Expand Up @@ -151,32 +151,32 @@ class DraggableNumber : public Label
}

if (!isEditableOnSingleClick() && !getCurrentTextEditor() && key.isKeyCode(KeyPress::upKey)) {
setValue(getText().getFloatValue() + 1.0);
setValue(getText().getDoubleValue() + 1.0);
return true;
}
if (!isEditableOnSingleClick() && !getCurrentTextEditor() && key.isKeyCode(KeyPress::downKey)) {
setValue(getText().getFloatValue() - 1.0);
setValue(getText().getDoubleValue() - 1.0);
return true;
}

return false;
}

void setValue(float newValue, NotificationType notification = sendNotification)
void setValue(double newValue, NotificationType notification = sendNotification)
{
wasReset = false;

newValue = limitValue(newValue);

if (!approximatelyEqual(lastValue, newValue)) {
lastValue = newValue;

setText(String(newValue, 8), notification);
setText(formatNumber(newValue, decimalDrag), notification);

if (!approximatelyEqual(lastValue, newValue) && notification != dontSendNotification) {
onValueChange(newValue);
lastValue = newValue;
}
}

float getValue() const
double getValue() const
{
return lastValue;
}
Expand All @@ -186,7 +186,7 @@ class DraggableNumber : public Label
resetOnCommandClick = enableReset;
}

void setResetValue(float resetValue)
void setResetValue(double resetValue)
{
valueToResetTo = resetValue;
}
Expand Down Expand Up @@ -256,7 +256,7 @@ class DraggableNumber : public Label

// For integer or logarithmic drag mode, draw the highlighted area around the whole number
if (dragMode != Regular) {
auto text = dragMode == Integer ? getText().upToFirstOccurrenceOf(".", false, false) : String(getText().getFloatValue());
auto text = dragMode == Integer ? getText().upToFirstOccurrenceOf(".", false, false) : String(getText().getDoubleValue());

GlyphArrangement glyphs;
glyphs.addFittedText(getFont(), text, textArea.getX(), 0., 99999, getHeight(), 1, 1.0f);
Expand All @@ -273,8 +273,9 @@ class DraggableNumber : public Label
}

GlyphArrangement glyphs;
auto formattedNumber = formatNumber(getText().getFloatValue());
auto fullNumber = formattedNumber + String("000000");
auto fullNumber = getText() + String("000000");
fullNumber = fullNumber.substring(0, fullNumber.indexOf(".") + 7);

glyphs.addFittedText(getFont(), fullNumber, textArea.getX(), 0., 99999, getHeight(), 1, 1.0f);
int draggedDecimal = -1;

Expand Down Expand Up @@ -336,8 +337,8 @@ class DraggableNumber : public Label
}

auto font = getFont();
auto textArea = getBorderSize().subtractedFrom(getLocalBounds()).toFloat();
auto numberText = formatNumber(getText().getDoubleValue(), decimalDrag);
auto textArea = getBorderSize().subtractedFrom(getLocalBounds()).toDouble();
auto numberText = getText();
auto extraNumberText = String();
auto numDecimals = numberText.fromFirstOccurrenceOf(".", false, false).length();
auto numberTextLength = CachedFontStringWidth::get()->calculateSingleLineWidth(font, numberText);
Expand Down Expand Up @@ -381,7 +382,7 @@ class DraggableNumber : public Label
auto font = getFont();
if (!isBeingEdited()) {
auto textArea = getBorderSize().subtractedFrom(getLocalBounds()).toFloat();
auto numberText = formatNumber(getText().getFloatValue(), decimalDrag);
auto numberText = getText();
auto extraNumberText = String();
auto numDecimals = numberText.fromFirstOccurrenceOf(".", false, false).length();
auto numberTextLength = CachedFontStringWidth::get()->calculateSingleLineWidth(font, numberText);
Expand Down Expand Up @@ -442,8 +443,8 @@ class DraggableNumber : public Label
mouseSource.enableUnboundedMouseMovement(true, true);

if (dragMode == Logarithmic) {
float logMin = min;
float logMax = max;
double logMin = min;
double logMax = max;

if ((logMin == 0.0f) && (logMax == 0.0f))
logMax = 1.0f;
Expand All @@ -455,19 +456,19 @@ class DraggableNumber : public Label
logMax = 0.01f * logMin;
}

float dy = lastLogarithmicDragPosition - e.y;
float k = std::exp(log(logMax / logMin) / std::max(logarithmicHeight, 10.0f));
float factor = std::pow(k, dy);
double dy = lastLogarithmicDragPosition - e.y;
double k = std::exp(log(logMax / logMin) / std::max(logarithmicHeight, 10.0));
double factor = std::pow(k, dy);
setValue(std::clamp(getValue(), logMin, logMax) * factor);

lastLogarithmicDragPosition = e.y;
} else {
int const decimal = decimalDrag + e.mods.isShiftDown();
float const increment = (decimal == 0) ? 1. : (1. / std::pow(10.f, decimal));
float const deltaY = (e.y - e.mouseDownPosition.y) * 0.7f;
double const increment = (decimal == 0) ? 1. : (1. / std::pow(10.f, decimal));
double const deltaY = (e.y - e.mouseDownPosition.y) * 0.7f;

// truncate value and set
float newValue = dragValue + (increment * -deltaY);
double newValue = dragValue + (increment * -deltaY);

if (decimal > 0) {
int const sign = (newValue > 0) ? 1 : -1;
Expand All @@ -481,7 +482,7 @@ class DraggableNumber : public Label
}
}

float limitValue(float valueToLimit) const
double limitValue(double valueToLimit) const
{
if (min == 0.0 && max == 0.0)
return valueToLimit;
Expand Down Expand Up @@ -525,7 +526,12 @@ class DraggableNumber : public Label
if (dragMode != Integer) {
if (!text.containsChar('.'))
text << '.';
text = text.trimCharactersAtEnd("0");
if(precision <= 0) {
text = text.trimCharactersAtEnd("0");
}
else {
text = text.dropLastCharacters(std::floor(std::log10(std::max(1, text.getTrailingIntValue())) + 1) - precision);
}
}

return text;
Expand Down Expand Up @@ -580,10 +586,10 @@ struct DraggableListNumber : public DraggableNumber {
auto mouseSource = Desktop::getInstance().getMainMouseSource();
mouseSource.enableUnboundedMouseMovement(true, true);

float const deltaY = (e.y - e.mouseDownPosition.y) * 0.7;
float const increment = e.mods.isShiftDown() ? (0.01 * std::floor(-deltaY)) : std::floor(-deltaY);
double const deltaY = (e.y - e.mouseDownPosition.y) * 0.7;
double const increment = e.mods.isShiftDown() ? (0.01 * std::floor(-deltaY)) : std::floor(-deltaY);

float newValue = dragValue + increment;
double newValue = dragValue + increment;

newValue = limitValue(newValue);

Expand Down Expand Up @@ -722,7 +728,7 @@ struct DraggableListNumber : public DraggableNumber {

if (position)
*position = glyphs.getBoundingBox(i, j - i, false).translated(0, 2);
return { i, j, number.getFloatValue() };
return { i, j, number.getDoubleValue() };
}

// Move start to end of current item
Expand Down
2 changes: 1 addition & 1 deletion Source/Dialogs/Dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ void Dialogs::showCanvasRightClickMenu(Canvas* cnv, Component* originalComponent
if (originalComponent == cnv) {
SmallArray<ObjectParameters, 6> parameters = { cnv->getInspectorParameters() };
editor->sidebar->showParameters("canvas", parameters);
} else if (object && object->gui) {
} else if (object && object->gui && object->getPointer()) {

cnv->pd->lockAudioThread();
// this makes sure that objects can handle the "properties" message as well if they like, for example for [else/properties]
Expand Down
11 changes: 6 additions & 5 deletions Source/Dialogs/ThemeSettingsPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class ThemeSettingsPanel : public SettingsDialogPanel

Value fontValue;

UnorderedMap<String, UnorderedMap<String, Value>> swatches;
UnorderedMap<String, UnorderedSegmentedMap<String, Value>> swatches;

PropertiesPanel::ActionComponent* newButton = nullptr;
PropertiesPanel::ActionComponent* loadButton = nullptr;
Expand Down Expand Up @@ -245,13 +245,14 @@ class ThemeSettingsPanel : public SettingsDialogPanel
// Loop over themes
for (int i = 0; i < 2; i++) {
auto const& themeName = PlugDataLook::selectedThemes[i];
swatchesToAdd.add(&(swatches[themeName][colourId]));
auto* swatch = swatchesToAdd.back();
auto& themeSwatches = swatches[themeName];
auto& swatch = themeSwatches[colourId];
swatchesToAdd.add(&swatch);

auto value = SettingsFile::getInstance()->getColourThemesTree().getChildWithProperty("theme", themeName).getPropertyAsValue(colourId, nullptr);

swatch->referTo(value);
swatch->addListener(this);
swatch.referTo(value);
swatch.addListener(this);
}

// Add a multi colour component to the properties panel
Expand Down
Loading

0 comments on commit 6cc7272

Please sign in to comment.