Add reset rotation button and rotation with mouse

pull/170/head
James Ball 2023-07-05 14:14:27 +01:00
rodzic e2f9a6c4a4
commit af0cd0e8d0
3 zmienionych plików z 59 dodań i 8 usunięć

Wyświetl plik

@ -5,6 +5,8 @@
ObjComponent::ObjComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessorEditor& editor) : audioProcessor(p), pluginEditor(editor) {
setText("3D .obj File Settings");
juce::Desktop::getInstance().addGlobalMouseListener(this);
addAndMakeVisible(focalLength);
addAndMakeVisible(rotateX);
addAndMakeVisible(rotateY);
@ -35,14 +37,57 @@ ObjComponent::ObjComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessor
audioProcessor.rotateSpeed.setValue(rotateSpeed.slider.getValue());
audioProcessor.rotateSpeed.apply();
};
addAndMakeVisible(resetRotation);
addAndMakeVisible(mouseRotate);
resetRotation.onClick = [this] {
rotateX.slider.setValue(0);
rotateY.slider.setValue(0);
rotateZ.slider.setValue(0);
mouseRotate.setToggleState(false, juce::NotificationType::dontSendNotification);
};
}
ObjComponent::~ObjComponent() {
juce::Desktop::getInstance().removeGlobalMouseListener(this);
}
// listen for mouse movement and rotate the object if mouseRotate is enabled
void ObjComponent::mouseMove(const juce::MouseEvent& e) {
if (mouseRotate.getToggleState()) {
auto globalEvent = e.getEventRelativeTo(&pluginEditor);
auto width = pluginEditor.getWidth();
auto height = pluginEditor.getHeight();
auto x = globalEvent.position.getX();
auto y = globalEvent.position.getY();
rotateX.slider.setValue(2 * x / width - 1);
rotateY.slider.setValue(1 - 2 * y / height);
}
}
// listen for when escape is pressed to disable mouse rotation
bool ObjComponent::keyPressed(const juce::KeyPress& key) {
if (key == juce::KeyPress::escapeKey) {
mouseRotate.setToggleState(false, juce::NotificationType::dontSendNotification);
}
return true;
}
void ObjComponent::resized() {
auto area = getLocalBounds().reduced(20);
double sliderHeight = 30;
focalLength.setBounds(area.removeFromTop(sliderHeight));
rotateX.setBounds(area.removeFromTop(sliderHeight));
rotateY.setBounds(area.removeFromTop(sliderHeight));
rotateZ.setBounds(area.removeFromTop(sliderHeight));
rotateSpeed.setBounds(area.removeFromTop(sliderHeight));
double rowHeight = 30;
focalLength.setBounds(area.removeFromTop(rowHeight));
rotateX.setBounds(area.removeFromTop(rowHeight));
rotateY.setBounds(area.removeFromTop(rowHeight));
rotateZ.setBounds(area.removeFromTop(rowHeight));
rotateSpeed.setBounds(area.removeFromTop(rowHeight));
area.removeFromTop(10);
auto row = area.removeFromTop(rowHeight);
resetRotation.setBounds(row.removeFromLeft(120));
row.removeFromLeft(20);
mouseRotate.setBounds(row);
}

Wyświetl plik

@ -5,11 +5,14 @@
#include "components/EffectComponent.h"
class OscirenderAudioProcessorEditor;
class ObjComponent : public juce::GroupComponent {
class ObjComponent : public juce::GroupComponent, public juce::MouseListener {
public:
ObjComponent(OscirenderAudioProcessor&, OscirenderAudioProcessorEditor&);
~ObjComponent();
void resized() override;
void mouseMove(const juce::MouseEvent& event) override;
bool keyPressed(const juce::KeyPress& key) override;
private:
OscirenderAudioProcessor& audioProcessor;
OscirenderAudioProcessorEditor& pluginEditor;
@ -20,5 +23,8 @@ private:
EffectComponent rotateZ{-1, 1, 0.01, audioProcessor.rotateZ, false};
EffectComponent rotateSpeed{-1, 1, 0.01, audioProcessor.rotateSpeed, false};
juce::TextButton resetRotation{"Reset Rotation"};
juce::ToggleButton mouseRotate{"Rotate with Mouse (Esc to disable)"};
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ObjComponent)
};

Wyświetl plik

@ -23,7 +23,7 @@ public:
private:
void componentSetup();
bool checkboxVisible = false;
bool checkboxVisible = true;
juce::Rectangle<int> textBounds;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(EffectComponent)