Umsci
Upmix Spatial Control Interface — OCA/OCP.1 spatial audio utility
Loading...
Searching...
No Matches
UmsciPaintNControlComponentBase.h
Go to the documentation of this file.
1/* Copyright (c) 2026, Christian Ahrens
2 *
3 * This file is part of Umsci <https://github.com/ChristianAhrens/Umsci>
4 *
5 * This tool is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License version 3.0 as published
7 * by the Free Software Foundation.
8 *
9 * This tool is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this tool; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#pragma once
20
21#include <JuceHeader.h>
22
23
77class UmsciPaintNControlComponentBase : public juce::Component
78{
79public:
81 enum class ControlsSize { S, M, L };
82
84 virtual ~UmsciPaintNControlComponentBase() override;
85
86 //==============================================================================
94 void setBoundsRealRef(const juce::Rectangle<float>& boundsRealRef);
95
96 //==============================================================================
98 virtual void setControlsSize(ControlsSize size);
101 float getControlsSizeMultiplier() const;
102
103 //==============================================================================
111 void setZoom(float factor, juce::Point<float> normalizedPanOffset = {});
112 float getZoomFactor() const;
114 void resetZoom();
115
121 std::function<void(float, juce::Point<float>)> onViewportZoomChanged;
122
134 void simulatePinchZoom(float scaleFactor, juce::Point<float> centre);
135
136protected:
137 //==============================================================================
144 juce::Point<float> GetPointForRealCoordinate(const std::array<float, 3>& realCoordinate);
145
150 std::array<float, 3> GetRealCoordinateForPoint(const juce::Point<float>& screenPoint);
151
152 //==============================================================================
154 void mouseDoubleClick(const juce::MouseEvent&) override;
156 void mouseWheelMove(const juce::MouseEvent&, const juce::MouseWheelDetails&) override;
158 void mouseMagnify(const juce::MouseEvent&, float scaleFactor) override;
159
183 bool processPinchGesture(const juce::MouseEvent& e, bool isDown, bool isUp);
184
192 virtual void onZoomChanged();
193
194private:
195 //==============================================================================
197 juce::Rectangle<float> computeBaseContentBounds() const;
199 juce::Rectangle<float> getContentBounds() const;
200
206 void applyZoomAtScreenPoint(float newFactor, juce::Point<float> screenFocus);
207
208 juce::Rectangle<float> m_boundsRealRef;
209 ControlsSize m_controlsSize = ControlsSize::S;
210
211 float m_zoomFactor = 1.0f;
212 juce::Point<float> m_zoomPanOffset;
213
214 // Two-touch pinch state (used by processPinchGesture).
215 juce::Point<float> m_pinchPos[2] = {};
216 bool m_pinchDown[2] = { false, false };
217 float m_pinchStartDistance = 0.0f;
218 float m_pinchStartZoom = 1.0f;
219 bool m_pinchActive = false;
220
221 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UmsciPaintNControlComponentBase)
222};
223
Abstract base class for all three overlaid visualisation layers in UmsciControlComponent.
void mouseMagnify(const juce::MouseEvent &, float scaleFactor) override
Trackpad pinch-to-zoom (macOS).
ControlsSize
Visual size of source/speaker icons. Multiplier accessible via getControlsSizeMultiplier().
void setZoom(float factor, juce::Point< float > normalizedPanOffset={})
Silently applies zoom without firing onViewportZoomChanged. Used by UmsciControlComponent to synchron...
virtual void onZoomChanged()
Called after any zoom state change.
void mouseDoubleClick(const juce::MouseEvent &) override
Double-click resets zoom to 1.0 via resetZoom().
bool processPinchGesture(const juce::MouseEvent &e, bool isDown, bool isUp)
JUCE-level two-touch pinch-zoom fallback for platforms where neither mouseMagnify nor a native gestur...
std::array< float, 3 > GetRealCoordinateForPoint(const juce::Point< float > &screenPoint)
Inverse of GetPointForRealCoordinate — converts a screen pixel point back to a 3D real-world coordina...
void mouseWheelMove(const juce::MouseEvent &, const juce::MouseWheelDetails &) override
Mouse-wheel zooms about the cursor position.
std::function< void(float, juce::Point< float >)> onViewportZoomChanged
Fired after every user-initiated zoom/pan change (wheel, pinch, double-click). Parameters: (newFactor...
void simulatePinchZoom(float scaleFactor, juce::Point< float > centre)
Applies an incremental pinch-zoom step, as if the user performed a native pinch gesture centred at ce...
juce::Point< float > GetPointForRealCoordinate(const std::array< float, 3 > &realCoordinate)
Converts a 3D real-world coordinate to a 2D screen pixel point.
virtual void setControlsSize(ControlsSize size)
Updates the icon size; derived classes may override to re-prerender.
void resetZoom()
Resets zoom to 1.0 / no pan and fires onViewportZoomChanged.
void setBoundsRealRef(const juce::Rectangle< float > &boundsRealRef)
Sets the real-world rectangle that the component's pixel bounds map to.
float getControlsSizeMultiplier() const
Returns a multiplier (e.g. 0.5 / 1.0 / 1.5) for S/M/L icon sizes.