Signed-off-by: falkTX <falktx@falktx.com>tags/2021-03-15
@@ -296,7 +296,7 @@ | |||
You must respect the FFTW license when enabling this option. | |||
*/ | |||
#define JUCE_DSP_USE_SHARED_FFTW 0 | |||
#define JUCE_DSP_USE_SHARED_FFTW 1 | |||
/** Config: JUCE_DSP_USE_STATIC_FFTW | |||
@@ -425,6 +425,8 @@ | |||
//============================================================================= | |||
// juce_opengl | |||
#define JUCE_OPENGL3 1 | |||
//============================================================================= | |||
// drowaudio | |||
@@ -387,6 +387,10 @@ struct Component::ComponentHelpers | |||
template <typename PointOrRect> | |||
static PointOrRect convertCoordinate (const Component* target, const Component* source, PointOrRect p) | |||
{ | |||
float total_scaling = source->getTotalPixelScaling(); | |||
Component* top = nullptr; | |||
if (source) | |||
top = source->getTopLevelComponent(); | |||
while (source != nullptr) | |||
{ | |||
if (source == target) | |||
@@ -395,6 +399,9 @@ struct Component::ComponentHelpers | |||
if (source->isParentOf (target)) | |||
return convertFromDistantParentSpace (source, *target, p); | |||
if (source == top) | |||
p /= total_scaling; | |||
p = convertToParentSpace (*source, p); | |||
source = source->getParentComponent(); | |||
} | |||
@@ -1390,13 +1397,14 @@ bool Component::reallyContains (Point<int> point, bool returnTrueIfWithinAChild) | |||
Component* Component::getComponentAt (Point<int> position) | |||
{ | |||
Point<int> scale = (position.toFloat() * getPixelScaling()).roundToInt(); | |||
if (flags.visibleFlag && ComponentHelpers::hitTest (*this, position)) | |||
{ | |||
for (int i = childComponentList.size(); --i >= 0;) | |||
{ | |||
auto* child = childComponentList.getUnchecked(i); | |||
child = child->getComponentAt (ComponentHelpers::convertFromParentSpace (*child, position)); | |||
child = child->getComponentAt (ComponentHelpers::convertFromParentSpace (*child, scale)); | |||
if (child != nullptr) | |||
return child; | |||
@@ -0,0 +1,39 @@ | |||
--- modules/juce_gui_basics/components/juce_Component.cpp | |||
+++ modules/juce_gui_basics/components/juce_Component.cpp | |||
@@ -387,6 +387,10 @@ struct Component::ComponentHelpers | |||
template <typename PointOrRect> | |||
static PointOrRect convertCoordinate (const Component* target, const Component* source, PointOrRect p) | |||
{ | |||
+ float total_scaling = source->getTotalPixelScaling(); | |||
+ Component* top = nullptr; | |||
+ if (source) | |||
+ top = source->getTopLevelComponent(); | |||
while (source != nullptr) | |||
{ | |||
if (source == target) | |||
@@ -395,6 +399,9 @@ struct Component::ComponentHelpers | |||
if (source->isParentOf (target)) | |||
return convertFromDistantParentSpace (source, *target, p); | |||
+ if (source == top) | |||
+ p /= total_scaling; | |||
+ | |||
p = convertToParentSpace (*source, p); | |||
source = source->getParentComponent(); | |||
} | |||
@@ -1390,13 +1397,14 @@ bool Component::reallyContains (Point<int> point, bool returnTrueIfWithinAChild) | |||
Component* Component::getComponentAt (Point<int> position) | |||
{ | |||
+ Point<int> scale = (position.toFloat() * getPixelScaling()).roundToInt(); | |||
if (flags.visibleFlag && ComponentHelpers::hitTest (*this, position)) | |||
{ | |||
for (int i = childComponentList.size(); --i >= 0;) | |||
{ | |||
auto* child = childComponentList.getUnchecked(i); | |||
- child = child->getComponentAt (ComponentHelpers::convertFromParentSpace (*child, position)); | |||
+ child = child->getComponentAt (ComponentHelpers::convertFromParentSpace (*child, scale)); | |||
if (child != nullptr) | |||
return child; |
@@ -2284,6 +2284,17 @@ public: | |||
*/ | |||
bool getViewportIgnoreDragFlag() const noexcept { return flags.viewportIgnoreDragFlag; } | |||
virtual float getPixelScaling() const { return 1.0f; } | |||
float getTotalPixelScaling() const { | |||
const Component* component = this; | |||
float pixel_scaling = 1.0f; | |||
while (component) { | |||
pixel_scaling *= component->getPixelScaling(); | |||
component = component->getParentComponent(); | |||
} | |||
return pixel_scaling; | |||
} | |||
private: | |||
//============================================================================== | |||
friend class ComponentPeer; | |||
@@ -0,0 +1,20 @@ | |||
--- modules/juce_gui_basics/components/juce_Component.h | |||
+++ modules/juce_gui_basics/components/juce_Component.h | |||
@@ -2284,6 +2284,17 @@ class JUCE_API Component : public MouseListener | |||
*/ | |||
bool getViewportIgnoreDragFlag() const noexcept { return flags.viewportIgnoreDragFlag; } | |||
+ virtual float getPixelScaling() const { return 1.0f; } | |||
+ float getTotalPixelScaling() const { | |||
+ const Component* component = this; | |||
+ float pixel_scaling = 1.0f; | |||
+ while (component) { | |||
+ pixel_scaling *= component->getPixelScaling(); | |||
+ component = component->getParentComponent(); | |||
+ } | |||
+ return pixel_scaling; | |||
+ } | |||
+ | |||
private: | |||
//============================================================================== | |||
friend class ComponentPeer; |
@@ -61,7 +61,7 @@ public: | |||
{ | |||
if (auto* peer = comp.getPeer()) | |||
{ | |||
pos = peer->globalToLocal (pos); | |||
pos = peer->globalToLocal (pos) * comp.getTotalPixelScaling(); | |||
auto& peerComp = peer->getComponent(); | |||
return comp.getLocalPoint (&peerComp, ScalingHelpers::unscaledScreenPosToScaled (peerComp, pos)); | |||
} | |||
@@ -0,0 +1,781 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
class MouseInputSourceInternal : private AsyncUpdater | |||
{ | |||
public: | |||
MouseInputSourceInternal (int i, MouseInputSource::InputSourceType type) : index (i), inputType (type) | |||
{ | |||
} | |||
//============================================================================== | |||
bool isDragging() const noexcept | |||
{ | |||
return buttonState.isAnyMouseButtonDown(); | |||
} | |||
Component* getComponentUnderMouse() const noexcept | |||
{ | |||
return componentUnderMouse.get(); | |||
} | |||
ModifierKeys getCurrentModifiers() const noexcept | |||
{ | |||
return ModifierKeys::currentModifiers.withoutMouseButtons().withFlags (buttonState.getRawFlags()); | |||
} | |||
ComponentPeer* getPeer() noexcept | |||
{ | |||
if (! ComponentPeer::isValidPeer (lastPeer)) | |||
lastPeer = nullptr; | |||
return lastPeer; | |||
} | |||
static Point<float> screenPosToLocalPos (Component& comp, Point<float> pos) | |||
{ | |||
if (auto* peer = comp.getPeer()) | |||
{ | |||
pos = peer->globalToLocal (pos); | |||
auto& peerComp = peer->getComponent(); | |||
return comp.getLocalPoint (&peerComp, ScalingHelpers::unscaledScreenPosToScaled (peerComp, pos)); | |||
} | |||
return comp.getLocalPoint (nullptr, ScalingHelpers::unscaledScreenPosToScaled (comp, pos)); | |||
} | |||
Component* findComponentAt (Point<float> screenPos) | |||
{ | |||
if (auto* peer = getPeer()) | |||
{ | |||
auto relativePos = ScalingHelpers::unscaledScreenPosToScaled (peer->getComponent(), | |||
peer->globalToLocal (screenPos)); | |||
auto& comp = peer->getComponent(); | |||
auto pos = relativePos.roundToInt(); | |||
// (the contains() call is needed to test for overlapping desktop windows) | |||
if (comp.contains (pos)) | |||
return comp.getComponentAt (pos); | |||
} | |||
return nullptr; | |||
} | |||
Point<float> getScreenPosition() const noexcept | |||
{ | |||
// This needs to return the live position if possible, but it mustn't update the lastScreenPos | |||
// value, because that can cause continuity problems. | |||
return ScalingHelpers::unscaledScreenPosToScaled (getRawScreenPosition()); | |||
} | |||
Point<float> getRawScreenPosition() const noexcept | |||
{ | |||
return unboundedMouseOffset + (inputType != MouseInputSource::InputSourceType::touch ? MouseInputSource::getCurrentRawMousePosition() | |||
: lastScreenPos); | |||
} | |||
void setScreenPosition (Point<float> p) | |||
{ | |||
MouseInputSource::setRawMousePosition (ScalingHelpers::scaledScreenPosToUnscaled (p)); | |||
} | |||
bool isPressureValid() const noexcept { return pressure >= 0.0f && pressure <= 1.0f; } | |||
bool isOrientationValid() const noexcept { return orientation >= 0.0f && orientation <= MathConstants<float>::twoPi; } | |||
bool isRotationValid() const noexcept { return rotation >= 0.0f && rotation <= MathConstants<float>::twoPi; } | |||
bool isTiltValid (bool isX) const noexcept { return isX ? (tiltX >= -1.0f && tiltX <= 1.0f) : (tiltY >= -1.0f && tiltY <= 1.0f); } | |||
//============================================================================== | |||
#if JUCE_DUMP_MOUSE_EVENTS | |||
#define JUCE_MOUSE_EVENT_DBG(desc) DBG ("Mouse " << desc << " #" << index \ | |||
<< ": " << screenPosToLocalPos (comp, screenPos).toString() \ | |||
<< " - Comp: " << String::toHexString ((pointer_sized_int) &comp)); | |||
#else | |||
#define JUCE_MOUSE_EVENT_DBG(desc) | |||
#endif | |||
void sendMouseEnter (Component& comp, Point<float> screenPos, Time time) | |||
{ | |||
JUCE_MOUSE_EVENT_DBG ("enter") | |||
comp.internalMouseEnter (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time); | |||
} | |||
void sendMouseExit (Component& comp, Point<float> screenPos, Time time) | |||
{ | |||
JUCE_MOUSE_EVENT_DBG ("exit") | |||
comp.internalMouseExit (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time); | |||
} | |||
void sendMouseMove (Component& comp, Point<float> screenPos, Time time) | |||
{ | |||
JUCE_MOUSE_EVENT_DBG ("move") | |||
comp.internalMouseMove (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time); | |||
} | |||
void sendMouseDown (Component& comp, Point<float> screenPos, Time time) | |||
{ | |||
JUCE_MOUSE_EVENT_DBG ("down") | |||
comp.internalMouseDown (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time, pressure, orientation, rotation, tiltX, tiltY); | |||
} | |||
void sendMouseDrag (Component& comp, Point<float> screenPos, Time time) | |||
{ | |||
JUCE_MOUSE_EVENT_DBG ("drag") | |||
comp.internalMouseDrag (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time, pressure, orientation, rotation, tiltX, tiltY); | |||
} | |||
void sendMouseUp (Component& comp, Point<float> screenPos, Time time, ModifierKeys oldMods) | |||
{ | |||
JUCE_MOUSE_EVENT_DBG ("up") | |||
comp.internalMouseUp (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time, oldMods, pressure, orientation, rotation, tiltX, tiltY); | |||
} | |||
void sendMouseWheel (Component& comp, Point<float> screenPos, Time time, const MouseWheelDetails& wheel) | |||
{ | |||
JUCE_MOUSE_EVENT_DBG ("wheel") | |||
comp.internalMouseWheel (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time, wheel); | |||
} | |||
void sendMagnifyGesture (Component& comp, Point<float> screenPos, Time time, float amount) | |||
{ | |||
JUCE_MOUSE_EVENT_DBG ("magnify") | |||
comp.internalMagnifyGesture (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time, amount); | |||
} | |||
//============================================================================== | |||
// (returns true if the button change caused a modal event loop) | |||
bool setButtons (Point<float> screenPos, Time time, ModifierKeys newButtonState) | |||
{ | |||
if (buttonState == newButtonState) | |||
return false; | |||
// (avoid sending a spurious mouse-drag when we receive a mouse-up) | |||
if (! (isDragging() && ! newButtonState.isAnyMouseButtonDown())) | |||
setScreenPos (screenPos, time, false); | |||
// (ignore secondary clicks when there's already a button down) | |||
if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown()) | |||
{ | |||
buttonState = newButtonState; | |||
return false; | |||
} | |||
auto lastCounter = mouseEventCounter; | |||
if (buttonState.isAnyMouseButtonDown()) | |||
{ | |||
if (auto* current = getComponentUnderMouse()) | |||
{ | |||
auto oldMods = getCurrentModifiers(); | |||
buttonState = newButtonState; // must change this before calling sendMouseUp, in case it runs a modal loop | |||
sendMouseUp (*current, screenPos + unboundedMouseOffset, time, oldMods); | |||
if (lastCounter != mouseEventCounter) | |||
return true; // if a modal loop happened, then newButtonState is no longer valid. | |||
} | |||
enableUnboundedMouseMovement (false, false); | |||
} | |||
buttonState = newButtonState; | |||
if (buttonState.isAnyMouseButtonDown()) | |||
{ | |||
Desktop::getInstance().incrementMouseClickCounter(); | |||
if (auto* current = getComponentUnderMouse()) | |||
{ | |||
registerMouseDown (screenPos, time, *current, buttonState, | |||
inputType == MouseInputSource::InputSourceType::touch); | |||
sendMouseDown (*current, screenPos, time); | |||
} | |||
} | |||
return lastCounter != mouseEventCounter; | |||
} | |||
void setComponentUnderMouse (Component* newComponent, Point<float> screenPos, Time time) | |||
{ | |||
auto* current = getComponentUnderMouse(); | |||
if (newComponent != current) | |||
{ | |||
WeakReference<Component> safeNewComp (newComponent); | |||
auto originalButtonState = buttonState; | |||
if (current != nullptr) | |||
{ | |||
WeakReference<Component> safeOldComp (current); | |||
setButtons (screenPos, time, ModifierKeys()); | |||
if (auto oldComp = safeOldComp.get()) | |||
{ | |||
componentUnderMouse = safeNewComp; | |||
sendMouseExit (*oldComp, screenPos, time); | |||
} | |||
buttonState = originalButtonState; | |||
} | |||
componentUnderMouse = safeNewComp.get(); | |||
current = safeNewComp.get(); | |||
if (current != nullptr) | |||
sendMouseEnter (*current, screenPos, time); | |||
revealCursor (false); | |||
setButtons (screenPos, time, originalButtonState); | |||
} | |||
} | |||
void setPeer (ComponentPeer& newPeer, Point<float> screenPos, Time time) | |||
{ | |||
if (&newPeer != lastPeer) | |||
{ | |||
setComponentUnderMouse (nullptr, screenPos, time); | |||
lastPeer = &newPeer; | |||
setComponentUnderMouse (findComponentAt (screenPos), screenPos, time); | |||
} | |||
} | |||
void setScreenPos (Point<float> newScreenPos, Time time, bool forceUpdate) | |||
{ | |||
if (! isDragging()) | |||
setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time); | |||
if (newScreenPos != lastScreenPos || forceUpdate) | |||
{ | |||
cancelPendingUpdate(); | |||
if (newScreenPos != MouseInputSource::offscreenMousePos) | |||
lastScreenPos = newScreenPos; | |||
if (auto* current = getComponentUnderMouse()) | |||
{ | |||
if (isDragging()) | |||
{ | |||
registerMouseDrag (newScreenPos); | |||
sendMouseDrag (*current, newScreenPos + unboundedMouseOffset, time); | |||
if (isUnboundedMouseModeOn) | |||
handleUnboundedDrag (*current); | |||
} | |||
else | |||
{ | |||
sendMouseMove (*current, newScreenPos, time); | |||
} | |||
} | |||
revealCursor (false); | |||
} | |||
} | |||
//============================================================================== | |||
void handleEvent (ComponentPeer& newPeer, Point<float> positionWithinPeer, Time time, | |||
const ModifierKeys newMods, float newPressure, float newOrientation, PenDetails pen) | |||
{ | |||
lastTime = time; | |||
const bool pressureChanged = (pressure != newPressure); | |||
pressure = newPressure; | |||
const bool orientationChanged = (orientation != newOrientation); | |||
orientation = newOrientation; | |||
const bool rotationChanged = (rotation != pen.rotation); | |||
rotation = pen.rotation; | |||
const bool tiltChanged = (tiltX != pen.tiltX || tiltY != pen.tiltY); | |||
tiltX = pen.tiltX; | |||
tiltY = pen.tiltY; | |||
const bool shouldUpdate = (pressureChanged || orientationChanged || rotationChanged || tiltChanged); | |||
++mouseEventCounter; | |||
auto screenPos = newPeer.localToGlobal (positionWithinPeer); | |||
if (isDragging() && newMods.isAnyMouseButtonDown()) | |||
{ | |||
setScreenPos (screenPos, time, shouldUpdate); | |||
} | |||
else | |||
{ | |||
setPeer (newPeer, screenPos, time); | |||
if (auto* peer = getPeer()) | |||
{ | |||
if (setButtons (screenPos, time, newMods)) | |||
return; // some modal events have been dispatched, so the current event is now out-of-date | |||
peer = getPeer(); | |||
if (peer != nullptr) | |||
setScreenPos (screenPos, time, shouldUpdate); | |||
} | |||
} | |||
} | |||
Component* getTargetForGesture (ComponentPeer& peer, Point<float> positionWithinPeer, | |||
Time time, Point<float>& screenPos) | |||
{ | |||
lastTime = time; | |||
++mouseEventCounter; | |||
screenPos = peer.localToGlobal (positionWithinPeer); | |||
setPeer (peer, screenPos, time); | |||
setScreenPos (screenPos, time, false); | |||
triggerFakeMove(); | |||
return getComponentUnderMouse(); | |||
} | |||
void handleWheel (ComponentPeer& peer, Point<float> positionWithinPeer, | |||
Time time, const MouseWheelDetails& wheel) | |||
{ | |||
Desktop::getInstance().incrementMouseWheelCounter(); | |||
Point<float> screenPos; | |||
// This will make sure that when the wheel spins in its inertial phase, any events | |||
// continue to be sent to the last component that the mouse was over when it was being | |||
// actively controlled by the user. This avoids confusion when scrolling through nested | |||
// scrollable components. | |||
if (lastNonInertialWheelTarget == nullptr || ! wheel.isInertial) | |||
lastNonInertialWheelTarget = getTargetForGesture (peer, positionWithinPeer, time, screenPos); | |||
else | |||
screenPos = peer.localToGlobal (positionWithinPeer); | |||
if (auto target = lastNonInertialWheelTarget.get()) | |||
sendMouseWheel (*target, screenPos, time, wheel); | |||
} | |||
void handleMagnifyGesture (ComponentPeer& peer, Point<float> positionWithinPeer, | |||
Time time, const float scaleFactor) | |||
{ | |||
Point<float> screenPos; | |||
if (auto* current = getTargetForGesture (peer, positionWithinPeer, time, screenPos)) | |||
sendMagnifyGesture (*current, screenPos, time, scaleFactor); | |||
} | |||
//============================================================================== | |||
Time getLastMouseDownTime() const noexcept { return mouseDowns[0].time; } | |||
Point<float> getLastMouseDownPosition() const noexcept { return ScalingHelpers::unscaledScreenPosToScaled (mouseDowns[0].position); } | |||
int getNumberOfMultipleClicks() const noexcept | |||
{ | |||
int numClicks = 1; | |||
if (! isLongPressOrDrag()) | |||
{ | |||
for (int i = 1; i < numElementsInArray (mouseDowns); ++i) | |||
{ | |||
if (mouseDowns[0].canBePartOfMultipleClickWith (mouseDowns[i], MouseEvent::getDoubleClickTimeout() * jmin (i, 2))) | |||
++numClicks; | |||
else | |||
break; | |||
} | |||
} | |||
return numClicks; | |||
} | |||
bool isLongPressOrDrag() const noexcept | |||
{ | |||
return movedSignificantly || lastTime > mouseDowns[0].time + RelativeTime::milliseconds (300); | |||
} | |||
bool hasMovedSignificantlySincePressed() const noexcept | |||
{ | |||
return movedSignificantly; | |||
} | |||
// Deprecated method | |||
bool hasMouseMovedSignificantlySincePressed() const noexcept | |||
{ | |||
return isLongPressOrDrag(); | |||
} | |||
//============================================================================== | |||
void triggerFakeMove() | |||
{ | |||
triggerAsyncUpdate(); | |||
} | |||
void handleAsyncUpdate() override | |||
{ | |||
setScreenPos (lastScreenPos, jmax (lastTime, Time::getCurrentTime()), true); | |||
} | |||
//============================================================================== | |||
void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen) | |||
{ | |||
enable = enable && isDragging(); | |||
isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen; | |||
if (enable != isUnboundedMouseModeOn) | |||
{ | |||
if ((! enable) && ((! isCursorVisibleUntilOffscreen) || ! unboundedMouseOffset.isOrigin())) | |||
{ | |||
// when released, return the mouse to within the component's bounds | |||
if (auto* current = getComponentUnderMouse()) | |||
setScreenPosition (current->getScreenBounds().toFloat() | |||
.getConstrainedPoint (ScalingHelpers::unscaledScreenPosToScaled (lastScreenPos))); | |||
} | |||
isUnboundedMouseModeOn = enable; | |||
unboundedMouseOffset = {}; | |||
revealCursor (true); | |||
} | |||
} | |||
void handleUnboundedDrag (Component& current) | |||
{ | |||
auto componentScreenBounds = ScalingHelpers::scaledScreenPosToUnscaled (current.getParentMonitorArea().reduced (2, 2).toFloat()); | |||
if (! componentScreenBounds.contains (lastScreenPos)) | |||
{ | |||
auto componentCentre = current.getScreenBounds().toFloat().getCentre(); | |||
unboundedMouseOffset += (lastScreenPos - ScalingHelpers::scaledScreenPosToUnscaled (componentCentre)); | |||
setScreenPosition (componentCentre); | |||
} | |||
else if (isCursorVisibleUntilOffscreen | |||
&& (! unboundedMouseOffset.isOrigin()) | |||
&& componentScreenBounds.contains (lastScreenPos + unboundedMouseOffset)) | |||
{ | |||
MouseInputSource::setRawMousePosition (lastScreenPos + unboundedMouseOffset); | |||
unboundedMouseOffset = {}; | |||
} | |||
} | |||
//============================================================================== | |||
void showMouseCursor (MouseCursor cursor, bool forcedUpdate) | |||
{ | |||
if (isUnboundedMouseModeOn && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen)) | |||
{ | |||
cursor = MouseCursor::NoCursor; | |||
forcedUpdate = true; | |||
} | |||
if (forcedUpdate || cursor.getHandle() != currentCursorHandle) | |||
{ | |||
currentCursorHandle = cursor.getHandle(); | |||
cursor.showInWindow (getPeer()); | |||
} | |||
} | |||
void hideCursor() | |||
{ | |||
showMouseCursor (MouseCursor::NoCursor, true); | |||
} | |||
void revealCursor (bool forcedUpdate) | |||
{ | |||
MouseCursor mc (MouseCursor::NormalCursor); | |||
if (auto* current = getComponentUnderMouse()) | |||
mc = current->getLookAndFeel().getMouseCursorFor (*current); | |||
showMouseCursor (mc, forcedUpdate); | |||
} | |||
//============================================================================== | |||
const int index; | |||
const MouseInputSource::InputSourceType inputType; | |||
Point<float> lastScreenPos, unboundedMouseOffset; // NB: these are unscaled coords | |||
ModifierKeys buttonState; | |||
float pressure = 0; | |||
float orientation = 0; | |||
float rotation = 0; | |||
float tiltX = 0; | |||
float tiltY = 0; | |||
bool isUnboundedMouseModeOn = false, isCursorVisibleUntilOffscreen = false; | |||
private: | |||
WeakReference<Component> componentUnderMouse, lastNonInertialWheelTarget; | |||
ComponentPeer* lastPeer = nullptr; | |||
void* currentCursorHandle = nullptr; | |||
int mouseEventCounter = 0; | |||
struct RecentMouseDown | |||
{ | |||
RecentMouseDown() = default; | |||
Point<float> position; | |||
Time time; | |||
ModifierKeys buttons; | |||
uint32 peerID = 0; | |||
bool isTouch = false; | |||
bool canBePartOfMultipleClickWith (const RecentMouseDown& other, int maxTimeBetweenMs) const noexcept | |||
{ | |||
return time - other.time < RelativeTime::milliseconds (maxTimeBetweenMs) | |||
&& std::abs (position.x - other.position.x) < (float) getPositionToleranceForInputType() | |||
&& std::abs (position.y - other.position.y) < (float) getPositionToleranceForInputType() | |||
&& buttons == other.buttons | |||
&& peerID == other.peerID; | |||
} | |||
int getPositionToleranceForInputType() const noexcept { return isTouch ? 25 : 8; } | |||
}; | |||
RecentMouseDown mouseDowns[4]; | |||
Time lastTime; | |||
bool movedSignificantly = false; | |||
void registerMouseDown (Point<float> screenPos, Time time, Component& component, | |||
const ModifierKeys modifiers, bool isTouchSource) noexcept | |||
{ | |||
for (int i = numElementsInArray (mouseDowns); --i > 0;) | |||
mouseDowns[i] = mouseDowns[i - 1]; | |||
mouseDowns[0].position = screenPos; | |||
mouseDowns[0].time = time; | |||
mouseDowns[0].buttons = modifiers.withOnlyMouseButtons(); | |||
mouseDowns[0].isTouch = isTouchSource; | |||
if (auto* peer = component.getPeer()) | |||
mouseDowns[0].peerID = peer->getUniqueID(); | |||
else | |||
mouseDowns[0].peerID = 0; | |||
movedSignificantly = false; | |||
lastNonInertialWheelTarget = nullptr; | |||
} | |||
void registerMouseDrag (Point<float> screenPos) noexcept | |||
{ | |||
movedSignificantly = movedSignificantly || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4; | |||
} | |||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MouseInputSourceInternal) | |||
}; | |||
//============================================================================== | |||
MouseInputSource::MouseInputSource (MouseInputSourceInternal* s) noexcept : pimpl (s) {} | |||
MouseInputSource::MouseInputSource (const MouseInputSource& other) noexcept : pimpl (other.pimpl) {} | |||
MouseInputSource::~MouseInputSource() noexcept {} | |||
MouseInputSource& MouseInputSource::operator= (const MouseInputSource& other) noexcept | |||
{ | |||
pimpl = other.pimpl; | |||
return *this; | |||
} | |||
MouseInputSource::InputSourceType MouseInputSource::getType() const noexcept { return pimpl->inputType; } | |||
bool MouseInputSource::isMouse() const noexcept { return (getType() == MouseInputSource::InputSourceType::mouse); } | |||
bool MouseInputSource::isTouch() const noexcept { return (getType() == MouseInputSource::InputSourceType::touch); } | |||
bool MouseInputSource::isPen() const noexcept { return (getType() == MouseInputSource::InputSourceType::pen); } | |||
bool MouseInputSource::canHover() const noexcept { return ! isTouch(); } | |||
bool MouseInputSource::hasMouseWheel() const noexcept { return ! isTouch(); } | |||
int MouseInputSource::getIndex() const noexcept { return pimpl->index; } | |||
bool MouseInputSource::isDragging() const noexcept { return pimpl->isDragging(); } | |||
Point<float> MouseInputSource::getScreenPosition() const noexcept { return pimpl->getScreenPosition(); } | |||
Point<float> MouseInputSource::getRawScreenPosition() const noexcept { return pimpl->getRawScreenPosition(); } | |||
ModifierKeys MouseInputSource::getCurrentModifiers() const noexcept { return pimpl->getCurrentModifiers(); } | |||
float MouseInputSource::getCurrentPressure() const noexcept { return pimpl->pressure; } | |||
bool MouseInputSource::isPressureValid() const noexcept { return pimpl->isPressureValid(); } | |||
float MouseInputSource::getCurrentOrientation() const noexcept { return pimpl->orientation; } | |||
bool MouseInputSource::isOrientationValid() const noexcept { return pimpl->isOrientationValid(); } | |||
float MouseInputSource::getCurrentRotation() const noexcept { return pimpl->rotation; } | |||
bool MouseInputSource::isRotationValid() const noexcept { return pimpl->isRotationValid(); } | |||
float MouseInputSource::getCurrentTilt (bool tiltX) const noexcept { return tiltX ? pimpl->tiltX : pimpl->tiltY; } | |||
bool MouseInputSource::isTiltValid (bool isX) const noexcept { return pimpl->isTiltValid (isX); } | |||
Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); } | |||
void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); } | |||
int MouseInputSource::getNumberOfMultipleClicks() const noexcept { return pimpl->getNumberOfMultipleClicks(); } | |||
Time MouseInputSource::getLastMouseDownTime() const noexcept { return pimpl->getLastMouseDownTime(); } | |||
Point<float> MouseInputSource::getLastMouseDownPosition() const noexcept { return pimpl->getLastMouseDownPosition(); } | |||
bool MouseInputSource::isLongPressOrDrag() const noexcept { return pimpl->isLongPressOrDrag(); } | |||
bool MouseInputSource::hasMovedSignificantlySincePressed() const noexcept { return pimpl->hasMovedSignificantlySincePressed(); } | |||
bool MouseInputSource::canDoUnboundedMovement() const noexcept { return ! isTouch(); } | |||
void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) const | |||
{ pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); } | |||
bool MouseInputSource::isUnboundedMouseMovementEnabled() const { return pimpl->isUnboundedMouseModeOn; } | |||
bool MouseInputSource::hasMouseCursor() const noexcept { return ! isTouch(); } | |||
void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); } | |||
void MouseInputSource::hideCursor() { pimpl->hideCursor(); } | |||
void MouseInputSource::revealCursor() { pimpl->revealCursor (false); } | |||
void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); } | |||
void MouseInputSource::setScreenPosition (Point<float> p) { pimpl->setScreenPosition (p); } | |||
void MouseInputSource::handleEvent (ComponentPeer& peer, Point<float> pos, int64 time, ModifierKeys mods, | |||
float pressure, float orientation, const PenDetails& penDetails) | |||
{ | |||
pimpl->handleEvent (peer, pos, Time (time), mods.withOnlyMouseButtons(), pressure, orientation, penDetails); | |||
} | |||
void MouseInputSource::handleWheel (ComponentPeer& peer, Point<float> pos, int64 time, const MouseWheelDetails& wheel) | |||
{ | |||
pimpl->handleWheel (peer, pos, Time (time), wheel); | |||
} | |||
void MouseInputSource::handleMagnifyGesture (ComponentPeer& peer, Point<float> pos, int64 time, float scaleFactor) | |||
{ | |||
pimpl->handleMagnifyGesture (peer, pos, Time (time), scaleFactor); | |||
} | |||
const float MouseInputSource::invalidPressure = 0.0f; | |||
const float MouseInputSource::invalidOrientation = 0.0f; | |||
const float MouseInputSource::invalidRotation = 0.0f; | |||
const float MouseInputSource::invalidTiltX = 0.0f; | |||
const float MouseInputSource::invalidTiltY = 0.0f; | |||
const Point<float> MouseInputSource::offscreenMousePos { -10.0f, -10.0f }; | |||
// Deprecated method | |||
bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const noexcept { return pimpl->hasMouseMovedSignificantlySincePressed(); } | |||
//============================================================================== | |||
struct MouseInputSource::SourceList : public Timer | |||
{ | |||
SourceList() | |||
{ | |||
#if JUCE_ANDROID || JUCE_IOS | |||
auto mainMouseInputType = MouseInputSource::InputSourceType::touch; | |||
#else | |||
auto mainMouseInputType = MouseInputSource::InputSourceType::mouse; | |||
#endif | |||
addSource (0, mainMouseInputType); | |||
} | |||
bool addSource(); | |||
bool canUseTouch(); | |||
MouseInputSource* addSource (int index, MouseInputSource::InputSourceType type) | |||
{ | |||
auto* s = new MouseInputSourceInternal (index, type); | |||
sources.add (s); | |||
sourceArray.add (MouseInputSource (s)); | |||
return &sourceArray.getReference (sourceArray.size() - 1); | |||
} | |||
MouseInputSource* getMouseSource (int index) noexcept | |||
{ | |||
return isPositiveAndBelow (index, sourceArray.size()) ? &sourceArray.getReference (index) | |||
: nullptr; | |||
} | |||
MouseInputSource* getOrCreateMouseInputSource (MouseInputSource::InputSourceType type, int touchIndex = 0) | |||
{ | |||
if (type == MouseInputSource::InputSourceType::mouse || type == MouseInputSource::InputSourceType::pen) | |||
{ | |||
for (auto& m : sourceArray) | |||
if (type == m.getType()) | |||
return &m; | |||
addSource (0, type); | |||
} | |||
else if (type == MouseInputSource::InputSourceType::touch) | |||
{ | |||
jassert (touchIndex >= 0 && touchIndex < 100); // sanity-check on number of fingers | |||
for (auto& m : sourceArray) | |||
if (type == m.getType() && touchIndex == m.getIndex()) | |||
return &m; | |||
if (canUseTouch()) | |||
return addSource (touchIndex, type); | |||
} | |||
return nullptr; | |||
} | |||
int getNumDraggingMouseSources() const noexcept | |||
{ | |||
int num = 0; | |||
for (auto* s : sources) | |||
if (s->isDragging()) | |||
++num; | |||
return num; | |||
} | |||
MouseInputSource* getDraggingMouseSource (int index) noexcept | |||
{ | |||
int num = 0; | |||
for (auto& s : sourceArray) | |||
{ | |||
if (s.isDragging()) | |||
{ | |||
if (index == num) | |||
return &s; | |||
++num; | |||
} | |||
} | |||
return nullptr; | |||
} | |||
void beginDragAutoRepeat (int interval) | |||
{ | |||
if (interval > 0) | |||
{ | |||
if (getTimerInterval() != interval) | |||
startTimer (interval); | |||
} | |||
else | |||
{ | |||
stopTimer(); | |||
} | |||
} | |||
void timerCallback() override | |||
{ | |||
bool anyDragging = false; | |||
for (auto* s : sources) | |||
{ | |||
// NB: when doing auto-repeat, we need to force an update of the current position and button state, | |||
// because on some OSes the queue can get overloaded with messages so that mouse-events don't get through.. | |||
if (s->isDragging() && ComponentPeer::getCurrentModifiersRealtime().isAnyMouseButtonDown()) | |||
{ | |||
s->lastScreenPos = s->getRawScreenPosition(); | |||
s->triggerFakeMove(); | |||
anyDragging = true; | |||
} | |||
} | |||
if (! anyDragging) | |||
stopTimer(); | |||
} | |||
OwnedArray<MouseInputSourceInternal> sources; | |||
Array<MouseInputSource> sourceArray; | |||
}; | |||
} // namespace juce |
@@ -0,0 +1,11 @@ | |||
--- modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp | |||
+++ modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp | |||
@@ -61,7 +61,7 @@ class MouseInputSourceInternal : private AsyncUpdater | |||
{ | |||
if (auto* peer = comp.getPeer()) | |||
{ | |||
- pos = peer->globalToLocal (pos); | |||
+ pos = peer->globalToLocal (pos) * comp.getTotalPixelScaling(); | |||
auto& peerComp = peer->getComponent(); | |||
return comp.getLocalPoint (&peerComp, ScalingHelpers::unscaledScreenPosToScaled (peerComp, pos)); | |||
} |
@@ -474,7 +474,7 @@ bool ComponentPeer::handleDragMove (const ComponentPeer::DragInfo& info) | |||
if (DragHelpers::isSuitableTarget (info, newTarget)) | |||
{ | |||
dragAndDropTargetComponent = newTarget; | |||
auto pos = newTarget->getLocalPoint (&component, info.position); | |||
auto pos = newTarget->getLocalPoint (&component, info.position * newTarget->getTotalPixelScaling()); | |||
if (DragHelpers::isFileDrag (info)) | |||
dynamic_cast<FileDragAndDropTarget*> (newTarget)->fileDragEnter (info.files, pos.x, pos.y); | |||
@@ -491,7 +491,7 @@ bool ComponentPeer::handleDragMove (const ComponentPeer::DragInfo& info) | |||
if (! DragHelpers::isSuitableTarget (info, newTarget)) | |||
return false; | |||
auto pos = newTarget->getLocalPoint (&component, info.position); | |||
auto pos = newTarget->getLocalPoint (&component, info.position * newTarget->getTotalPixelScaling()); | |||
if (DragHelpers::isFileDrag (info)) | |||
dynamic_cast<FileDragAndDropTarget*> (newTarget)->fileDragMove (info.files, pos.x, pos.y); | |||
@@ -0,0 +1,593 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
static uint32 lastUniquePeerID = 1; | |||
//============================================================================== | |||
ComponentPeer::ComponentPeer (Component& comp, int flags) | |||
: component (comp), | |||
styleFlags (flags), | |||
uniqueID (lastUniquePeerID += 2) // increment by 2 so that this can never hit 0 | |||
{ | |||
Desktop::getInstance().peers.add (this); | |||
} | |||
ComponentPeer::~ComponentPeer() | |||
{ | |||
auto& desktop = Desktop::getInstance(); | |||
desktop.peers.removeFirstMatchingValue (this); | |||
desktop.triggerFocusCallback(); | |||
} | |||
//============================================================================== | |||
int ComponentPeer::getNumPeers() noexcept | |||
{ | |||
return Desktop::getInstance().peers.size(); | |||
} | |||
ComponentPeer* ComponentPeer::getPeer (const int index) noexcept | |||
{ | |||
return Desktop::getInstance().peers [index]; | |||
} | |||
ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) noexcept | |||
{ | |||
for (auto* peer : Desktop::getInstance().peers) | |||
if (&(peer->getComponent()) == component) | |||
return peer; | |||
return nullptr; | |||
} | |||
bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) noexcept | |||
{ | |||
return Desktop::getInstance().peers.contains (const_cast<ComponentPeer*> (peer)); | |||
} | |||
void ComponentPeer::updateBounds() | |||
{ | |||
setBounds (ScalingHelpers::scaledScreenPosToUnscaled (component, component.getBoundsInParent()), false); | |||
} | |||
bool ComponentPeer::isKioskMode() const | |||
{ | |||
return Desktop::getInstance().getKioskModeComponent() == &component; | |||
} | |||
//============================================================================== | |||
void ComponentPeer::handleMouseEvent (MouseInputSource::InputSourceType type, Point<float> pos, ModifierKeys newMods, | |||
float newPressure, float newOrientation, int64 time, PenDetails pen, int touchIndex) | |||
{ | |||
if (auto* mouse = Desktop::getInstance().mouseSources->getOrCreateMouseInputSource (type, touchIndex)) | |||
MouseInputSource (*mouse).handleEvent (*this, pos, time, newMods, newPressure, newOrientation, pen); | |||
} | |||
void ComponentPeer::handleMouseWheel (MouseInputSource::InputSourceType type, Point<float> pos, int64 time, const MouseWheelDetails& wheel, int touchIndex) | |||
{ | |||
if (auto* mouse = Desktop::getInstance().mouseSources->getOrCreateMouseInputSource (type, touchIndex)) | |||
MouseInputSource (*mouse).handleWheel (*this, pos, time, wheel); | |||
} | |||
void ComponentPeer::handleMagnifyGesture (MouseInputSource::InputSourceType type, Point<float> pos, int64 time, float scaleFactor, int touchIndex) | |||
{ | |||
if (auto* mouse = Desktop::getInstance().mouseSources->getOrCreateMouseInputSource (type, touchIndex)) | |||
MouseInputSource (*mouse).handleMagnifyGesture (*this, pos, time, scaleFactor); | |||
} | |||
//============================================================================== | |||
void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo) | |||
{ | |||
Graphics g (contextToPaintTo); | |||
if (component.isTransformed()) | |||
g.addTransform (component.getTransform()); | |||
auto peerBounds = getBounds(); | |||
auto componentBounds = component.getLocalBounds(); | |||
if (component.isTransformed()) | |||
componentBounds = componentBounds.transformedBy (component.getTransform()); | |||
if (peerBounds.getWidth() != componentBounds.getWidth() || peerBounds.getHeight() != componentBounds.getHeight()) | |||
// Tweak the scaling so that the component's integer size exactly aligns with the peer's scaled size | |||
g.addTransform (AffineTransform::scale ((float) peerBounds.getWidth() / (float) componentBounds.getWidth(), | |||
(float) peerBounds.getHeight() / (float) componentBounds.getHeight())); | |||
#if JUCE_ENABLE_REPAINT_DEBUGGING | |||
#ifdef JUCE_IS_REPAINT_DEBUGGING_ACTIVE | |||
if (JUCE_IS_REPAINT_DEBUGGING_ACTIVE) | |||
#endif | |||
{ | |||
g.saveState(); | |||
} | |||
#endif | |||
JUCE_TRY | |||
{ | |||
component.paintEntireComponent (g, true); | |||
} | |||
JUCE_CATCH_EXCEPTION | |||
#if JUCE_ENABLE_REPAINT_DEBUGGING | |||
#ifdef JUCE_IS_REPAINT_DEBUGGING_ACTIVE | |||
if (JUCE_IS_REPAINT_DEBUGGING_ACTIVE) | |||
#endif | |||
{ | |||
// enabling this code will fill all areas that get repainted with a colour overlay, to show | |||
// clearly when things are being repainted. | |||
g.restoreState(); | |||
static Random rng; | |||
g.fillAll (Colour ((uint8) rng.nextInt (255), | |||
(uint8) rng.nextInt (255), | |||
(uint8) rng.nextInt (255), | |||
(uint8) 0x50)); | |||
} | |||
#endif | |||
/** If this fails, it's probably be because your CPU floating-point precision mode has | |||
been set to low.. This setting is sometimes changed by things like Direct3D, and can | |||
mess up a lot of the calculations that the library needs to do. | |||
*/ | |||
jassert (roundToInt (10.1f) == 10); | |||
} | |||
Component* ComponentPeer::getTargetForKeyPress() | |||
{ | |||
auto* c = Component::getCurrentlyFocusedComponent(); | |||
if (c == nullptr) | |||
c = &component; | |||
if (c->isCurrentlyBlockedByAnotherModalComponent()) | |||
if (auto* currentModalComp = Component::getCurrentlyModalComponent()) | |||
c = currentModalComp; | |||
return c; | |||
} | |||
bool ComponentPeer::handleKeyPress (const int keyCode, const juce_wchar textCharacter) | |||
{ | |||
return handleKeyPress (KeyPress (keyCode, | |||
ModifierKeys::currentModifiers.withoutMouseButtons(), | |||
textCharacter)); | |||
} | |||
bool ComponentPeer::handleKeyPress (const KeyPress& keyInfo) | |||
{ | |||
bool keyWasUsed = false; | |||
for (auto* target = getTargetForKeyPress(); target != nullptr; target = target->getParentComponent()) | |||
{ | |||
const WeakReference<Component> deletionChecker (target); | |||
if (auto* keyListeners = target->keyListeners.get()) | |||
{ | |||
for (int i = keyListeners->size(); --i >= 0;) | |||
{ | |||
keyWasUsed = keyListeners->getUnchecked(i)->keyPressed (keyInfo, target); | |||
if (keyWasUsed || deletionChecker == nullptr) | |||
return keyWasUsed; | |||
i = jmin (i, keyListeners->size()); | |||
} | |||
} | |||
keyWasUsed = target->keyPressed (keyInfo); | |||
if (keyWasUsed || deletionChecker == nullptr) | |||
break; | |||
if (auto* currentlyFocused = Component::getCurrentlyFocusedComponent()) | |||
{ | |||
const bool isTab = (keyInfo == KeyPress::tabKey); | |||
const bool isShiftTab = (keyInfo == KeyPress (KeyPress::tabKey, ModifierKeys::shiftModifier, 0)); | |||
if (isTab || isShiftTab) | |||
{ | |||
currentlyFocused->moveKeyboardFocusToSibling (isTab); | |||
keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent()); | |||
if (keyWasUsed || deletionChecker == nullptr) | |||
break; | |||
} | |||
} | |||
} | |||
return keyWasUsed; | |||
} | |||
bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown) | |||
{ | |||
bool keyWasUsed = false; | |||
for (auto* target = getTargetForKeyPress(); target != nullptr; target = target->getParentComponent()) | |||
{ | |||
const WeakReference<Component> deletionChecker (target); | |||
keyWasUsed = target->keyStateChanged (isKeyDown); | |||
if (keyWasUsed || deletionChecker == nullptr) | |||
break; | |||
if (auto* keyListeners = target->keyListeners.get()) | |||
{ | |||
for (int i = keyListeners->size(); --i >= 0;) | |||
{ | |||
keyWasUsed = keyListeners->getUnchecked(i)->keyStateChanged (isKeyDown, target); | |||
if (keyWasUsed || deletionChecker == nullptr) | |||
return keyWasUsed; | |||
i = jmin (i, keyListeners->size()); | |||
} | |||
} | |||
} | |||
return keyWasUsed; | |||
} | |||
void ComponentPeer::handleModifierKeysChange() | |||
{ | |||
auto* target = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse(); | |||
if (target == nullptr) | |||
target = Component::getCurrentlyFocusedComponent(); | |||
if (target == nullptr) | |||
target = &component; | |||
target->internalModifierKeysChanged(); | |||
} | |||
TextInputTarget* ComponentPeer::findCurrentTextInputTarget() | |||
{ | |||
auto* c = Component::getCurrentlyFocusedComponent(); | |||
if (c == &component || component.isParentOf (c)) | |||
if (auto* ti = dynamic_cast<TextInputTarget*> (c)) | |||
if (ti->isTextInputActive()) | |||
return ti; | |||
return nullptr; | |||
} | |||
void ComponentPeer::dismissPendingTextInput() {} | |||
//============================================================================== | |||
void ComponentPeer::handleBroughtToFront() | |||
{ | |||
component.internalBroughtToFront(); | |||
} | |||
void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) noexcept | |||
{ | |||
constrainer = newConstrainer; | |||
} | |||
void ComponentPeer::handleMovedOrResized() | |||
{ | |||
const bool nowMinimised = isMinimised(); | |||
if (component.flags.hasHeavyweightPeerFlag && ! nowMinimised) | |||
{ | |||
const WeakReference<Component> deletionChecker (&component); | |||
auto newBounds = Component::ComponentHelpers::rawPeerPositionToLocal (component, getBounds()); | |||
auto oldBounds = component.getBounds(); | |||
const bool wasMoved = (oldBounds.getPosition() != newBounds.getPosition()); | |||
const bool wasResized = (oldBounds.getWidth() != newBounds.getWidth() || oldBounds.getHeight() != newBounds.getHeight()); | |||
if (wasMoved || wasResized) | |||
{ | |||
component.boundsRelativeToParent = newBounds; | |||
if (wasResized) | |||
component.repaint(); | |||
component.sendMovedResizedMessages (wasMoved, wasResized); | |||
if (deletionChecker == nullptr) | |||
return; | |||
} | |||
} | |||
if (isWindowMinimised != nowMinimised) | |||
{ | |||
isWindowMinimised = nowMinimised; | |||
component.minimisationStateChanged (nowMinimised); | |||
component.sendVisibilityChangeMessage(); | |||
} | |||
if (! isFullScreen()) | |||
lastNonFullscreenBounds = component.getBounds(); | |||
} | |||
void ComponentPeer::handleFocusGain() | |||
{ | |||
if (component.isParentOf (lastFocusedComponent) | |||
&& lastFocusedComponent->isShowing() | |||
&& lastFocusedComponent->getWantsKeyboardFocus()) | |||
{ | |||
Component::currentlyFocusedComponent = lastFocusedComponent; | |||
Desktop::getInstance().triggerFocusCallback(); | |||
lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly); | |||
} | |||
else | |||
{ | |||
if (! component.isCurrentlyBlockedByAnotherModalComponent()) | |||
component.grabKeyboardFocus(); | |||
else | |||
ModalComponentManager::getInstance()->bringModalComponentsToFront(); | |||
} | |||
} | |||
void ComponentPeer::handleFocusLoss() | |||
{ | |||
if (component.hasKeyboardFocus (true)) | |||
{ | |||
lastFocusedComponent = Component::currentlyFocusedComponent; | |||
if (lastFocusedComponent != nullptr) | |||
{ | |||
Component::currentlyFocusedComponent = nullptr; | |||
Desktop::getInstance().triggerFocusCallback(); | |||
lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick); | |||
} | |||
} | |||
} | |||
Component* ComponentPeer::getLastFocusedSubcomponent() const noexcept | |||
{ | |||
return (component.isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing()) | |||
? static_cast<Component*> (lastFocusedComponent) | |||
: &component; | |||
} | |||
void ComponentPeer::handleScreenSizeChange() | |||
{ | |||
component.parentSizeChanged(); | |||
handleMovedOrResized(); | |||
} | |||
void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) noexcept | |||
{ | |||
lastNonFullscreenBounds = newBounds; | |||
} | |||
const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const noexcept | |||
{ | |||
return lastNonFullscreenBounds; | |||
} | |||
Point<int> ComponentPeer::localToGlobal (Point<int> p) { return localToGlobal (p.toFloat()).roundToInt(); } | |||
Point<int> ComponentPeer::globalToLocal (Point<int> p) { return globalToLocal (p.toFloat()).roundToInt(); } | |||
Rectangle<int> ComponentPeer::localToGlobal (const Rectangle<int>& relativePosition) | |||
{ | |||
return relativePosition.withPosition (localToGlobal (relativePosition.getPosition())); | |||
} | |||
Rectangle<int> ComponentPeer::globalToLocal (const Rectangle<int>& screenPosition) | |||
{ | |||
return screenPosition.withPosition (globalToLocal (screenPosition.getPosition())); | |||
} | |||
Rectangle<float> ComponentPeer::localToGlobal (const Rectangle<float>& relativePosition) | |||
{ | |||
return relativePosition.withPosition (localToGlobal (relativePosition.getPosition())); | |||
} | |||
Rectangle<float> ComponentPeer::globalToLocal (const Rectangle<float>& screenPosition) | |||
{ | |||
return screenPosition.withPosition (globalToLocal (screenPosition.getPosition())); | |||
} | |||
Rectangle<int> ComponentPeer::getAreaCoveredBy (Component& subComponent) const | |||
{ | |||
return ScalingHelpers::scaledScreenPosToUnscaled | |||
(component, component.getLocalArea (&subComponent, subComponent.getLocalBounds())); | |||
} | |||
//============================================================================== | |||
namespace DragHelpers | |||
{ | |||
static bool isFileDrag (const ComponentPeer::DragInfo& info) | |||
{ | |||
return ! info.files.isEmpty(); | |||
} | |||
static bool isSuitableTarget (const ComponentPeer::DragInfo& info, Component* target) | |||
{ | |||
return isFileDrag (info) ? dynamic_cast<FileDragAndDropTarget*> (target) != nullptr | |||
: dynamic_cast<TextDragAndDropTarget*> (target) != nullptr; | |||
} | |||
static bool isInterested (const ComponentPeer::DragInfo& info, Component* target) | |||
{ | |||
return isFileDrag (info) ? dynamic_cast<FileDragAndDropTarget*> (target)->isInterestedInFileDrag (info.files) | |||
: dynamic_cast<TextDragAndDropTarget*> (target)->isInterestedInTextDrag (info.text); | |||
} | |||
static Component* findDragAndDropTarget (Component* c, const ComponentPeer::DragInfo& info, Component* lastOne) | |||
{ | |||
for (; c != nullptr; c = c->getParentComponent()) | |||
if (isSuitableTarget (info, c) && (c == lastOne || isInterested (info, c))) | |||
return c; | |||
return nullptr; | |||
} | |||
} | |||
bool ComponentPeer::handleDragMove (const ComponentPeer::DragInfo& info) | |||
{ | |||
auto* compUnderMouse = component.getComponentAt (info.position); | |||
auto* lastTarget = dragAndDropTargetComponent.get(); | |||
Component* newTarget = nullptr; | |||
if (compUnderMouse != lastDragAndDropCompUnderMouse) | |||
{ | |||
lastDragAndDropCompUnderMouse = compUnderMouse; | |||
newTarget = DragHelpers::findDragAndDropTarget (compUnderMouse, info, lastTarget); | |||
if (newTarget != lastTarget) | |||
{ | |||
if (lastTarget != nullptr) | |||
{ | |||
if (DragHelpers::isFileDrag (info)) | |||
dynamic_cast<FileDragAndDropTarget*> (lastTarget)->fileDragExit (info.files); | |||
else | |||
dynamic_cast<TextDragAndDropTarget*> (lastTarget)->textDragExit (info.text); | |||
} | |||
dragAndDropTargetComponent = nullptr; | |||
if (DragHelpers::isSuitableTarget (info, newTarget)) | |||
{ | |||
dragAndDropTargetComponent = newTarget; | |||
auto pos = newTarget->getLocalPoint (&component, info.position); | |||
if (DragHelpers::isFileDrag (info)) | |||
dynamic_cast<FileDragAndDropTarget*> (newTarget)->fileDragEnter (info.files, pos.x, pos.y); | |||
else | |||
dynamic_cast<TextDragAndDropTarget*> (newTarget)->textDragEnter (info.text, pos.x, pos.y); | |||
} | |||
} | |||
} | |||
else | |||
{ | |||
newTarget = lastTarget; | |||
} | |||
if (! DragHelpers::isSuitableTarget (info, newTarget)) | |||
return false; | |||
auto pos = newTarget->getLocalPoint (&component, info.position); | |||
if (DragHelpers::isFileDrag (info)) | |||
dynamic_cast<FileDragAndDropTarget*> (newTarget)->fileDragMove (info.files, pos.x, pos.y); | |||
else | |||
dynamic_cast<TextDragAndDropTarget*> (newTarget)->textDragMove (info.text, pos.x, pos.y); | |||
return true; | |||
} | |||
bool ComponentPeer::handleDragExit (const ComponentPeer::DragInfo& info) | |||
{ | |||
DragInfo info2 (info); | |||
info2.position.setXY (-1, -1); | |||
const bool used = handleDragMove (info2); | |||
jassert (dragAndDropTargetComponent == nullptr); | |||
lastDragAndDropCompUnderMouse = nullptr; | |||
return used; | |||
} | |||
bool ComponentPeer::handleDragDrop (const ComponentPeer::DragInfo& info) | |||
{ | |||
handleDragMove (info); | |||
if (WeakReference<Component> targetComp = dragAndDropTargetComponent) | |||
{ | |||
dragAndDropTargetComponent = nullptr; | |||
lastDragAndDropCompUnderMouse = nullptr; | |||
if (DragHelpers::isSuitableTarget (info, targetComp)) | |||
{ | |||
if (targetComp->isCurrentlyBlockedByAnotherModalComponent()) | |||
{ | |||
targetComp->internalModalInputAttempt(); | |||
if (targetComp->isCurrentlyBlockedByAnotherModalComponent()) | |||
return true; | |||
} | |||
ComponentPeer::DragInfo infoCopy (info); | |||
infoCopy.position = targetComp->getLocalPoint (&component, info.position); | |||
// We'll use an async message to deliver the drop, because if the target decides | |||
// to run a modal loop, it can gum-up the operating system.. | |||
MessageManager::callAsync ([=] | |||
{ | |||
if (auto* c = targetComp.get()) | |||
{ | |||
if (DragHelpers::isFileDrag (info)) | |||
dynamic_cast<FileDragAndDropTarget*> (c)->filesDropped (infoCopy.files, infoCopy.position.x, infoCopy.position.y); | |||
else | |||
dynamic_cast<TextDragAndDropTarget*> (c)->textDropped (infoCopy.text, infoCopy.position.x, infoCopy.position.y); | |||
} | |||
}); | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
//============================================================================== | |||
void ComponentPeer::handleUserClosingWindow() | |||
{ | |||
component.userTriedToCloseWindow(); | |||
} | |||
bool ComponentPeer::setDocumentEditedStatus (bool) | |||
{ | |||
return false; | |||
} | |||
void ComponentPeer::setRepresentedFile (const File&) | |||
{ | |||
} | |||
//============================================================================== | |||
int ComponentPeer::getCurrentRenderingEngine() const { return 0; } | |||
void ComponentPeer::setCurrentRenderingEngine (int index) { jassert (index == 0); ignoreUnused (index); } | |||
//============================================================================== | |||
std::function<ModifierKeys()> ComponentPeer::getNativeRealtimeModifiers = nullptr; | |||
ModifierKeys ComponentPeer::getCurrentModifiersRealtime() noexcept | |||
{ | |||
if (getNativeRealtimeModifiers != nullptr) | |||
return getNativeRealtimeModifiers(); | |||
return ModifierKeys::currentModifiers; | |||
} | |||
//============================================================================== | |||
void ComponentPeer::forceDisplayUpdate() | |||
{ | |||
Desktop::getInstance().displays->refresh(); | |||
} | |||
} // namespace juce |
@@ -0,0 +1,20 @@ | |||
--- modules/juce_gui_basics/windows/juce_ComponentPeer.cpp | |||
+++ modules/juce_gui_basics/windows/juce_ComponentPeer.cpp | |||
@@ -474,7 +474,7 @@ bool ComponentPeer::handleDragMove (const ComponentPeer::DragInfo& info) | |||
if (DragHelpers::isSuitableTarget (info, newTarget)) | |||
{ | |||
dragAndDropTargetComponent = newTarget; | |||
- auto pos = newTarget->getLocalPoint (&component, info.position); | |||
+ auto pos = newTarget->getLocalPoint (&component, info.position * newTarget->getTotalPixelScaling()); | |||
if (DragHelpers::isFileDrag (info)) | |||
dynamic_cast<FileDragAndDropTarget*> (newTarget)->fileDragEnter (info.files, pos.x, pos.y); | |||
@@ -491,7 +491,7 @@ bool ComponentPeer::handleDragMove (const ComponentPeer::DragInfo& info) | |||
if (! DragHelpers::isSuitableTarget (info, newTarget)) | |||
return false; | |||
- auto pos = newTarget->getLocalPoint (&component, info.position); | |||
+ auto pos = newTarget->getLocalPoint (&component, info.position * newTarget->getTotalPixelScaling()); | |||
if (DragHelpers::isFileDrag (info)) | |||
dynamic_cast<FileDragAndDropTarget*> (newTarget)->fileDragMove (info.files, pos.x, pos.y); |
@@ -83,7 +83,13 @@ namespace juce | |||
USE_FUNCTION (glCheckFramebufferStatus, GLenum, (GLenum p1), (p1))\ | |||
USE_FUNCTION (glFramebufferTexture2D, void, (GLenum p1, GLenum p2, GLenum p3, GLuint p4, GLint p5), (p1, p2, p3, p4, p5))\ | |||
USE_FUNCTION (glFramebufferRenderbuffer, void, (GLenum p1, GLenum p2, GLenum p3, GLuint p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glGetFramebufferAttachmentParameteriv, void, (GLenum p1, GLenum p2, GLenum p3, GLint* p4), (p1, p2, p3, p4)) | |||
USE_FUNCTION (glGetFramebufferAttachmentParameteriv, void, (GLenum p1, GLenum p2, GLenum p3, GLint* p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glTransformFeedbackVaryings, void, (GLuint p1, GLsizei p2, const char **p3, GLenum p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glBeginTransformFeedback, void, (GLenum p1), (p1))\ | |||
USE_FUNCTION (glEndTransformFeedback, void, (), ())\ | |||
USE_FUNCTION (glBindBufferBase, void, (GLenum p1, GLuint p2, GLuint p3), (p1, p2, p3))\ | |||
USE_FUNCTION (glMapBufferRange, void*, (GLenum p1, GLintptr p2, GLsizeiptr p3, GLbitfield p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glUnmapBuffer, GLboolean, (GLenum p1), (p1)); | |||
/** @internal This macro contains a list of GL extension functions that need to be dynamically loaded on Windows/Linux. | |||
@see OpenGLExtensionFunctions | |||
@@ -0,0 +1,160 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
/** @internal This macro contains a list of GL extension functions that need to be dynamically loaded on Windows/Linux. | |||
@see OpenGLExtensionFunctions | |||
*/ | |||
#define JUCE_GL_BASE_FUNCTIONS(USE_FUNCTION) \ | |||
USE_FUNCTION (glActiveTexture, void, (GLenum p1), (p1))\ | |||
USE_FUNCTION (glBindBuffer, void, (GLenum p1, GLuint p2), (p1, p2))\ | |||
USE_FUNCTION (glDeleteBuffers, void, (GLsizei p1, const GLuint* p2), (p1, p2))\ | |||
USE_FUNCTION (glGenBuffers, void, (GLsizei p1, GLuint* p2), (p1, p2))\ | |||
USE_FUNCTION (glBufferData, void, (GLenum p1, GLsizeiptr p2, const GLvoid* p3, GLenum p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glBufferSubData, void, (GLenum p1, GLintptr p2, GLsizeiptr p3, const GLvoid* p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glCreateProgram, GLuint, (), ())\ | |||
USE_FUNCTION (glDeleteProgram, void, (GLuint p1), (p1))\ | |||
USE_FUNCTION (glCreateShader, GLuint, (GLenum p1), (p1))\ | |||
USE_FUNCTION (glDeleteShader, void, (GLuint p1), (p1))\ | |||
USE_FUNCTION (glShaderSource, void, (GLuint p1, GLsizei p2, const GLchar** p3, const GLint* p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glCompileShader, void, (GLuint p1), (p1))\ | |||
USE_FUNCTION (glAttachShader, void, (GLuint p1, GLuint p2), (p1, p2))\ | |||
USE_FUNCTION (glLinkProgram, void, (GLuint p1), (p1))\ | |||
USE_FUNCTION (glUseProgram, void, (GLuint p1), (p1))\ | |||
USE_FUNCTION (glGetShaderiv, void, (GLuint p1, GLenum p2, GLint* p3), (p1, p2, p3))\ | |||
USE_FUNCTION (glGetShaderInfoLog, void, (GLuint p1, GLsizei p2, GLsizei* p3, GLchar* p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glGetProgramInfoLog, void, (GLuint p1, GLsizei p2, GLsizei* p3, GLchar* p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glGetProgramiv, void, (GLuint p1, GLenum p2, GLint* p3), (p1, p2, p3))\ | |||
USE_FUNCTION (glGetUniformLocation, GLint, (GLuint p1, const GLchar* p2), (p1, p2))\ | |||
USE_FUNCTION (glGetAttribLocation, GLint, (GLuint p1, const GLchar* p2), (p1, p2))\ | |||
USE_FUNCTION (glVertexAttribPointer, void, (GLuint p1, GLint p2, GLenum p3, GLboolean p4, GLsizei p5, const GLvoid* p6), (p1, p2, p3, p4, p5, p6))\ | |||
USE_FUNCTION (glEnableVertexAttribArray, void, (GLuint p1), (p1))\ | |||
USE_FUNCTION (glDisableVertexAttribArray, void, (GLuint p1), (p1))\ | |||
USE_FUNCTION (glUniform1f, void, (GLint p1, GLfloat p2), (p1, p2))\ | |||
USE_FUNCTION (glUniform1i, void, (GLint p1, GLint p2), (p1, p2))\ | |||
USE_FUNCTION (glUniform2f, void, (GLint p1, GLfloat p2, GLfloat p3), (p1, p2, p3))\ | |||
USE_FUNCTION (glUniform3f, void, (GLint p1, GLfloat p2, GLfloat p3, GLfloat p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glUniform4f, void, (GLint p1, GLfloat p2, GLfloat p3, GLfloat p4, GLfloat p5), (p1, p2, p3, p4, p5))\ | |||
USE_FUNCTION (glUniform4i, void, (GLint p1, GLint p2, GLint p3, GLint p4, GLint p5), (p1, p2, p3, p4, p5))\ | |||
USE_FUNCTION (glUniform1fv, void, (GLint p1, GLsizei p2, const GLfloat* p3), (p1, p2, p3))\ | |||
USE_FUNCTION (glUniformMatrix2fv, void, (GLint p1, GLsizei p2, GLboolean p3, const GLfloat* p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glUniformMatrix3fv, void, (GLint p1, GLsizei p2, GLboolean p3, const GLfloat* p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glUniformMatrix4fv, void, (GLint p1, GLsizei p2, GLboolean p3, const GLfloat* p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glBindAttribLocation, void, (GLuint p1, GLuint p2, const GLchar* p3), (p1, p2, p3)) | |||
/** @internal This macro contains a list of GL extension functions that need to be dynamically loaded on Windows/Linux. | |||
@see OpenGLExtensionFunctions | |||
*/ | |||
#define JUCE_GL_EXTENSION_FUNCTIONS(USE_FUNCTION) \ | |||
USE_FUNCTION (glIsRenderbuffer, GLboolean, (GLuint p1), (p1))\ | |||
USE_FUNCTION (glBindRenderbuffer, void, (GLenum p1, GLuint p2), (p1, p2))\ | |||
USE_FUNCTION (glDeleteRenderbuffers, void, (GLsizei p1, const GLuint* p2), (p1, p2))\ | |||
USE_FUNCTION (glGenRenderbuffers, void, (GLsizei p1, GLuint* p2), (p1, p2))\ | |||
USE_FUNCTION (glRenderbufferStorage, void, (GLenum p1, GLenum p2, GLsizei p3, GLsizei p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glGetRenderbufferParameteriv, void, (GLenum p1, GLenum p2, GLint* p3), (p1, p2, p3))\ | |||
USE_FUNCTION (glIsFramebuffer, GLboolean, (GLuint p1), (p1))\ | |||
USE_FUNCTION (glBindFramebuffer, void, (GLenum p1, GLuint p2), (p1, p2))\ | |||
USE_FUNCTION (glDeleteFramebuffers, void, (GLsizei p1, const GLuint* p2), (p1, p2))\ | |||
USE_FUNCTION (glGenFramebuffers, void, (GLsizei p1, GLuint* p2), (p1, p2))\ | |||
USE_FUNCTION (glCheckFramebufferStatus, GLenum, (GLenum p1), (p1))\ | |||
USE_FUNCTION (glFramebufferTexture2D, void, (GLenum p1, GLenum p2, GLenum p3, GLuint p4, GLint p5), (p1, p2, p3, p4, p5))\ | |||
USE_FUNCTION (glFramebufferRenderbuffer, void, (GLenum p1, GLenum p2, GLenum p3, GLuint p4), (p1, p2, p3, p4))\ | |||
USE_FUNCTION (glGetFramebufferAttachmentParameteriv, void, (GLenum p1, GLenum p2, GLenum p3, GLint* p4), (p1, p2, p3, p4)) | |||
/** @internal This macro contains a list of GL extension functions that need to be dynamically loaded on Windows/Linux. | |||
@see OpenGLExtensionFunctions | |||
*/ | |||
#define JUCE_GL_VERTEXBUFFER_FUNCTIONS(USE_FUNCTION) \ | |||
USE_FUNCTION (glGenVertexArrays, void, (GLsizei p1, GLuint* p2), (p1, p2))\ | |||
USE_FUNCTION (glDeleteVertexArrays, void, (GLsizei p1, const GLuint* p2), (p1, p2))\ | |||
USE_FUNCTION (glBindVertexArray, void, (GLuint p1), (p1)) | |||
/** This class contains a generated list of OpenGL extension functions, which are either dynamically loaded | |||
for a specific GL context, or simply call-through to the appropriate OS function where available. | |||
@tags{OpenGL} | |||
*/ | |||
struct OpenGLExtensionFunctions | |||
{ | |||
void initialise(); | |||
#if JUCE_WINDOWS && ! DOXYGEN | |||
typedef char GLchar; | |||
typedef pointer_sized_int GLsizeiptr; | |||
typedef pointer_sized_int GLintptr; | |||
#endif | |||
//============================================================================== | |||
#if JUCE_WINDOWS | |||
#define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) typedef returnType (__stdcall *type_ ## name) params; type_ ## name name; | |||
JUCE_GL_BASE_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION) | |||
JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION) | |||
#if JUCE_OPENGL3 | |||
JUCE_GL_VERTEXBUFFER_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION) | |||
#endif | |||
//============================================================================== | |||
#elif JUCE_LINUX | |||
#define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) typedef returnType (*type_ ## name) params; type_ ## name name; | |||
JUCE_GL_BASE_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION) | |||
JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION) | |||
#if JUCE_OPENGL3 | |||
JUCE_GL_VERTEXBUFFER_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION) | |||
#endif | |||
//============================================================================== | |||
#elif JUCE_OPENGL_ES | |||
#define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) static returnType name params noexcept; | |||
JUCE_GL_BASE_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION) | |||
JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION) | |||
JUCE_GL_VERTEXBUFFER_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION) | |||
//============================================================================== | |||
#else | |||
#define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) static returnType name params noexcept { return ::name callparams; } | |||
JUCE_GL_BASE_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION) | |||
#ifndef GL3_PROTOTYPES | |||
#undef JUCE_DECLARE_GL_FUNCTION | |||
#define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) static returnType name params noexcept { return ::name ## EXT callparams; } | |||
#endif | |||
JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION) | |||
#if JUCE_OPENGL3 | |||
#ifndef GL3_PROTOTYPES | |||
#undef JUCE_DECLARE_GL_FUNCTION | |||
#define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) static returnType name params noexcept { return ::name ## APPLE callparams; } | |||
#endif | |||
JUCE_GL_VERTEXBUFFER_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION) | |||
#endif | |||
#endif | |||
#undef JUCE_DECLARE_GL_FUNCTION | |||
}; | |||
} // namespace juce |
@@ -0,0 +1,17 @@ | |||
--- modules/juce_opengl/native/juce_OpenGLExtensions.h | |||
+++ modules/juce_opengl/native/juce_OpenGLExtensions.h | |||
@@ -83,7 +83,13 @@ namespace juce | |||
USE_FUNCTION (glCheckFramebufferStatus, GLenum, (GLenum p1), (p1))\ | |||
USE_FUNCTION (glFramebufferTexture2D, void, (GLenum p1, GLenum p2, GLenum p3, GLuint p4, GLint p5), (p1, p2, p3, p4, p5))\ | |||
USE_FUNCTION (glFramebufferRenderbuffer, void, (GLenum p1, GLenum p2, GLenum p3, GLuint p4), (p1, p2, p3, p4))\ | |||
- USE_FUNCTION (glGetFramebufferAttachmentParameteriv, void, (GLenum p1, GLenum p2, GLenum p3, GLint* p4), (p1, p2, p3, p4)) | |||
+ USE_FUNCTION (glGetFramebufferAttachmentParameteriv, void, (GLenum p1, GLenum p2, GLenum p3, GLint* p4), (p1, p2, p3, p4))\ | |||
+ USE_FUNCTION (glTransformFeedbackVaryings, void, (GLuint p1, GLsizei p2, const char **p3, GLenum p4), (p1, p2, p3, p4))\ | |||
+ USE_FUNCTION (glBeginTransformFeedback, void, (GLenum p1), (p1))\ | |||
+ USE_FUNCTION (glEndTransformFeedback, void, (), ())\ | |||
+ USE_FUNCTION (glBindBufferBase, void, (GLenum p1, GLuint p2, GLuint p3), (p1, p2, p3))\ | |||
+ USE_FUNCTION (glMapBufferRange, void*, (GLenum p1, GLintptr p2, GLsizeiptr p3, GLbitfield p4), (p1, p2, p3, p4))\ | |||
+ USE_FUNCTION (glUnmapBuffer, GLboolean, (GLenum p1), (p1)); | |||
/** @internal This macro contains a list of GL extension functions that need to be dynamically loaded on Windows/Linux. | |||
@see OpenGLExtensionFunctions |