Skip to content

Commit

Permalink
Inspector fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Dec 9, 2024
1 parent b8a22c5 commit 8187d89
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 33 deletions.
43 changes: 23 additions & 20 deletions Source/Components/ColourPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,17 @@ class Eyedropper : public Timer
}
}

void showEyedropper(Component* topLevelComponent, std::function<void(Colour)> cb)
void showEyedropper(PluginEditor* targetEditor, Component* topLevelComponent, std::function<void(Colour)> cb)
{
callback = std::move(cb);
colourDisplayer.show();
topLevel = topLevelComponent;
topLevel->addMouseListener(this, true);

editor = targetEditor;

timerCount = 0;
timerCallback();
startTimerHz(60);
startTimerHz(20);
}

void hideEyedropper()
Expand All @@ -118,16 +119,22 @@ class Eyedropper : public Timer

void timerCallback() override
{
timerCount--;
if (timerCount <= 0) {
componentImage = topLevel->createComponentSnapshot(topLevel->getLocalBounds(), false, 1.0f);
timerCount = 20;
}

auto position = topLevel->getMouseXYRelative();
auto surfaceMousePosition = editor->nvgSurface.getLocalPoint(topLevel, position);
auto mouseOverSurface = editor->nvgSurface.getLocalBounds().contains(surfaceMousePosition);

if(mouseOverSurface) {
editor->nvgSurface.setRenderThroughImage(true);
editor->nvgSurface.render();
}

componentImage = topLevel->createComponentSnapshot(topLevel->getLocalBounds(), false, 1.0f);
colourDisplayer.setTopLeftPosition(topLevel->localPointToGlobal(position).translated(-20, -20));
setColour(componentImage.getPixelAt(position.x, position.y));

if(mouseOverSurface) {
editor->nvgSurface.setRenderThroughImage(false);
}
}

std::function<void(Colour)> callback;
Expand All @@ -137,6 +144,7 @@ class Eyedropper : public Timer
EyedropperDisplayComponnent colourDisplayer;
Image componentImage;
Colour currentColour;
PluginEditor* editor;
};

class ColourPicker : public Component {
Expand Down Expand Up @@ -178,20 +186,14 @@ class ColourPicker : public Component {
};

public:
void show(Component* topLevelComponent, bool onlySendCallbackOnClose, Colour currentColour, Rectangle<int> bounds, std::function<void(Colour)> const& colourCallback)
void show(PluginEditor* editorComponent, Component* topLevelComponent, bool onlySendCallbackOnClose, Colour currentColour, Rectangle<int> bounds, std::function<void(Colour)> const& colourCallback)
{
callback = colourCallback;
onlyCallBackOnClose = onlySendCallbackOnClose;

editor = editorComponent;

_topLevelComponent = topLevelComponent;

/*
Component* parent = nullptr;
if (!ProjectInfo::canUseSemiTransparentWindows()) {
parent = topLevelComponent;
bounds = topLevelComponent->getLocalArea(nullptr, bounds);
} */

setCurrentColour(currentColour);

// we need to put the selector into a holder, as launchAsynchronously will delete the component when its done
Expand Down Expand Up @@ -248,7 +250,7 @@ class ColourPicker : public Component {
_topLevelComponent = getTopLevelComponent();

showEyedropper.onClick = [this]() mutable {
eyedropper.showEyedropper(_topLevelComponent, [this](Colour pickedColour) {
eyedropper.showEyedropper(editor, _topLevelComponent, [this](Colour pickedColour) {
setCurrentColour(pickedColour);
});
};
Expand Down Expand Up @@ -733,7 +735,8 @@ class ColourPicker : public Component {
Eyedropper eyedropper;

Component* _topLevelComponent;

PluginEditor* editor;

bool onlyCallBackOnClose;

std::function<void(Colour)> callback = [](Colour) { };
Expand Down
8 changes: 4 additions & 4 deletions Source/Components/PropertiesPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ class PropertiesPanel : public Component {
bool isDown = getValue<bool>(toggleStateValue);

auto bounds = getLocalBounds().toFloat().removeFromRight(getWidth() / (2.0f - hideLabel));
auto buttonBounds = bounds.reduced(6);
auto buttonBounds = bounds.reduced(4);

auto contrast = isDown ? 0.2f : 0.05f;
if(isMouseOver()) contrast += 0.025;
Expand Down Expand Up @@ -717,7 +717,7 @@ class PropertiesPanel : public Component {

void resized() override
{
auto bounds = getLocalBounds().removeFromRight(getWidth() / (2 - hideLabel)).reduced(6);
auto bounds = getLocalBounds().removeFromRight(getWidth() / (2 - hideLabel)).reduced(4);
swatchComponent.setBounds(bounds);
hexValueEditor.setBounds(bounds);
}
Expand All @@ -738,7 +738,7 @@ class PropertiesPanel : public Component {
}
else {
auto pickerBounds = getScreenBounds().expanded(5);
ColourPicker::getInstance().show(getTopLevelComponent(), false, Colour::fromString(currentColour.toString()), pickerBounds, [_this = SafePointer(this)](Colour c) {
ColourPicker::getInstance().show(findParentComponentOfClass<PluginEditor>(), getTopLevelComponent(), false, Colour::fromString(currentColour.toString()), pickerBounds, [_this = SafePointer(this)](Colour c) {
if (!_this)
return;

Expand Down Expand Up @@ -788,7 +788,7 @@ class PropertiesPanel : public Component {
void mouseDown(MouseEvent const& e) override
{
auto pickerBounds = getScreenBounds().expanded(5);
ColourPicker::getInstance().show(getTopLevelComponent(), false, Colour::fromString(colourValue.toString()), pickerBounds, [_this = SafePointer(this)](Colour c) {
ColourPicker::getInstance().show(findParentComponentOfClass<PluginEditor>(), getTopLevelComponent(), false, Colour::fromString(colourValue.toString()), pickerBounds, [_this = SafePointer(this)](Colour c) {
if (!_this)
return;

Expand Down
2 changes: 1 addition & 1 deletion Source/Objects/CanvasObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CanvasObject final : public ObjectBase {

objectParameters.addParamSize(&sizeProperty);
objectParameters.addParamInt("Active area size", ParameterCategory::cDimensions, &hitAreaSize, 15);
objectParameters.addParamColour("Canvas color", cGeneral, &iemHelper.secondaryColour, PlugDataColour::guiObjectInternalOutlineColour);
objectParameters.addParamColour("Background", cGeneral, &iemHelper.secondaryColour, PlugDataColour::guiObjectInternalOutlineColour);
iemHelper.addIemParameters(objectParameters, false, true, 20, 12, 14);
setRepaintsOnMouseActivity(true);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Objects/ColourPickerObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ColourPickerObject final : public TextBase {
sscanf(colors->x_color, "#%02x%02x%02x", &red, &green, &blue);
}

ColourPicker::getInstance().show(getTopLevelComponent(), true, Colour(red, green, blue), object->getScreenBounds(), [_this = SafePointer(this)](Colour c) {
ColourPicker::getInstance().show(findParentComponentOfClass<PluginEditor>(), getTopLevelComponent(), true, Colour(red, green, blue), object->getScreenBounds(), [_this = SafePointer(this)](Colour c) {
if (!_this)
return;

Expand Down
2 changes: 1 addition & 1 deletion Source/Objects/KnobObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class KnobObject final : public ObjectBase {
objectParameters.addParamColourFG(&primaryColour);
objectParameters.addParamColourBG(&secondaryColour);

objectParameters.addParamColour("Arc color", cAppearance, &arcColour, PlugDataColour::guiObjectInternalOutlineColour);
objectParameters.addParamColour("Arc", cAppearance, &arcColour, PlugDataColour::guiObjectInternalOutlineColour);
objectParameters.addParamBool("Fill background", cAppearance, &outline, { "No", "Yes" }, 1);
objectParameters.addParamBool("Show arc", cAppearance, &showArc, { "No", "Yes" }, 1);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Objects/MessboxObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MessboxObject final : public ObjectBase
editor.setReadOnly(!isLocked);

objectParameters.addParamSize(&sizeProperty);
objectParameters.addParamColour("Text color", cAppearance, &primaryColour, PlugDataColour::canvasTextColourId);
objectParameters.addParamColour("Text", cAppearance, &primaryColour, PlugDataColour::canvasTextColourId);
objectParameters.addParamColourBG(&secondaryColour);
objectParameters.addParamInt("Font size", cAppearance, &fontSize, 12);
objectParameters.addParamBool("Bold", cAppearance, &bold, { "No", "Yes" }, 0);
Expand Down
2 changes: 1 addition & 1 deletion Source/Objects/NoteObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class NoteObject final : public ObjectBase {
};

objectParameters.addParamInt("Width", cDimensions, &width);
objectParameters.addParamColour("Text color", cAppearance, &primaryColour, PlugDataColour::canvasTextColourId);
objectParameters.addParamColour("Text", cAppearance, &primaryColour, PlugDataColour::canvasTextColourId);
objectParameters.addParamColourBG(&secondaryColour);
objectParameters.addParamFont("Font", cAppearance, &font, "Inter");
objectParameters.addParamInt("Font size", cAppearance, &fontSize, 14);
Expand Down
2 changes: 1 addition & 1 deletion Source/Objects/ScopeObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ScopeObject final : public ObjectBase

objectParameters.addParamSize(&sizeProperty);
objectParameters.addParamColourFG(&primaryColour);
objectParameters.addParamColour("Grid color", cAppearance, &gridColour, PlugDataColour::guiObjectInternalOutlineColour);
objectParameters.addParamColour("Grid", cAppearance, &gridColour, PlugDataColour::guiObjectInternalOutlineColour);
objectParameters.addParamColourBG(&secondaryColour);
objectParameters.addParamCombo("Trigger mode", cGeneral, &triggerMode, { "None", "Up", "Down" }, 1);
objectParameters.addParamFloat("Trigger value", cGeneral, &triggerValue, 0.0f);
Expand Down
2 changes: 1 addition & 1 deletion Source/Objects/VUMeterObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class VUMeterObject final : public ObjectBase {
objectParameters.addParamSize(&sizeProperty);
objectParameters.addParamReceiveSymbol(&iemHelper.receiveSymbol);
objectParameters.addParamBool("Show scale", ParameterCategory::cAppearance, &showScale, { "No", "Yes" }, 1);
objectParameters.addParamColour("Background color", ParameterCategory::cAppearance, &iemHelper.secondaryColour);
objectParameters.addParamColour("Background", ParameterCategory::cAppearance, &iemHelper.secondaryColour);
iemHelper.addIemParameters(objectParameters, false, false, -1);

updateLabel();
Expand Down
4 changes: 2 additions & 2 deletions Source/Sidebar/Inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ class Inspector : public Component {

else if (objectParameters.size() == 1) {
auto newPanel = createPanel(type, name, value, options, onInteractionFn);
newPanel->setPreferredHeight(32);
newPanel->setPreferredHeight(30);
panels.add(newPanel);
} else {
auto* redirectedProperty = redirector.addProperty(value, otherValues);
auto newPanel = createPanel(type, name, redirectedProperty, options);
newPanel->setPreferredHeight(32);
newPanel->setPreferredHeight(30);
panels.add(newPanel);
}
}
Expand Down

0 comments on commit 8187d89

Please sign in to comment.