Right now, on macOS, the MTKView is added at position (0, 0) in the top-left corner of the parent NSView. On Windows and Linux it probably does the same.
I'd like to have a function setWindowOrigin(int x, int y) on visage::ApplicationWindow, similar to setWindowDimensions. On macOS this would do [view_ setFrameOrigin:CGPointMake(x, y)]; inside of WindowMac.
The reason I ask is that this allows adding Visage into a JUCE AudioProcessorEditor using the following class, which acts just like any other JUCE Component. It can be sized and positioned inside the window but still leave room for regular JUCE components. This is especially useful for when you want to use Visage for drawing a smooth spectrum visualizer etc but use plain JUCE knobs for the controls. (It is also necessary to make Visage usable in a JUCE standalone app since right now the MTKView obscures the title bar that JUCE draws on the window.)
The VisageComponent class is as follows. Right now this doesn't compile because of the missing setWindowOrigin() function.
#pragma once
#include <JuceHeader.h>
#include <visage/app.h>
class VisageComponent : public juce::Component, private juce::ComponentMovementWatcher
{
public:
VisageComponent(visage::ApplicationWindow& appWindow) : ComponentMovementWatcher(this), appWindow_(appWindow) { }
void paint(juce::Graphics& g) override
{
g.fillAll(backgroundColor_);
}
void resized() override
{
const auto bounds = getTopLevelComponent()->getLocalArea(this, getLocalBounds());
appWindow_.setWindowOrigin(bounds.getX(), bounds.getY());
appWindow_.setWindowDimensions(bounds.getWidth(), bounds.getHeight());
}
void setBackgroundColor(const juce::Colour& color)
{
backgroundColor_ = color;
}
private:
void componentPeerChanged() override
{
if (getPeer()) {
appWindow_.show(100, 100, getPeer()->getNativeHandle());
resized();
}
}
void componentMovedOrResized(bool, bool) override { }
void componentVisibilityChanged() override { }
visage::ApplicationWindow& appWindow_;
juce::Colour backgroundColor_ = juce::Colours::black;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VisageComponent)
};
I implemented a basic setWindowOrigin() that just calls [view_ setFrameOrigin:...]; to verify this works, but you might want to approach this differently. If you want I can submit a PR but I don't have implementations for Windows or Linux.
(P.S. This setWindowOrigin function could also be useful for programmatically moving the top-level window if this runs in a standalone app rather than in a plug-in environment.)
Right now, on macOS, the MTKView is added at position (0, 0) in the top-left corner of the parent NSView. On Windows and Linux it probably does the same.
I'd like to have a function
setWindowOrigin(int x, int y)onvisage::ApplicationWindow, similar tosetWindowDimensions. On macOS this would do[view_ setFrameOrigin:CGPointMake(x, y)];inside ofWindowMac.The reason I ask is that this allows adding Visage into a JUCE AudioProcessorEditor using the following class, which acts just like any other JUCE Component. It can be sized and positioned inside the window but still leave room for regular JUCE components. This is especially useful for when you want to use Visage for drawing a smooth spectrum visualizer etc but use plain JUCE knobs for the controls. (It is also necessary to make Visage usable in a JUCE standalone app since right now the MTKView obscures the title bar that JUCE draws on the window.)
The
VisageComponentclass is as follows. Right now this doesn't compile because of the missingsetWindowOrigin()function.I implemented a basic
setWindowOrigin()that just calls[view_ setFrameOrigin:...];to verify this works, but you might want to approach this differently. If you want I can submit a PR but I don't have implementations for Windows or Linux.(P.S. This
setWindowOriginfunction could also be useful for programmatically moving the top-level window if this runs in a standalone app rather than in a plug-in environment.)