- Library code update
- project update (added Eigen) git-svn-id: http://moon:8086/svn/software/trunk/projects/mpsk_rx_gui@94 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -49,7 +49,7 @@ void ComponentDragger::dragComponent (Component* const componentToDrag, const Mo
|
||||
// so their coordinates become wrong after the first one moves the window, so in that case, we'll use
|
||||
// the current mouse position instead of the one that the event contains...
|
||||
if (componentToDrag->isOnDesktop())
|
||||
bounds += componentToDrag->getLocalPoint (nullptr, e.source.getScreenPosition()) - mouseDownWithinTarget;
|
||||
bounds += componentToDrag->getLocalPoint (nullptr, e.source.getScreenPosition()).roundToInt() - mouseDownWithinTarget;
|
||||
else
|
||||
bounds += e.getEventRelativeTo (componentToDrag).getPosition() - mouseDownWithinTarget;
|
||||
|
||||
|
||||
@@ -69,6 +69,8 @@ public:
|
||||
if (current->isInterestedInDragSource (sourceDetails))
|
||||
current->itemDragExit (sourceDetails);
|
||||
}
|
||||
|
||||
owner.dragOperationEnded();
|
||||
}
|
||||
|
||||
void paint (Graphics& g) override
|
||||
@@ -164,14 +166,14 @@ public:
|
||||
|
||||
if (sourceDetails.sourceComponent == nullptr)
|
||||
{
|
||||
delete this;
|
||||
deleteSelf();
|
||||
}
|
||||
else if (! isMouseButtonDownAnywhere())
|
||||
{
|
||||
if (mouseDragSource != nullptr)
|
||||
mouseDragSource->removeMouseListener (this);
|
||||
|
||||
delete this;
|
||||
deleteSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +182,7 @@ public:
|
||||
if (key == KeyPress::escapeKey)
|
||||
{
|
||||
dismissWithAnimation (true);
|
||||
delete this;
|
||||
deleteSelf();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -212,7 +214,22 @@ private:
|
||||
|
||||
DragAndDropTarget* getCurrentlyOver() const noexcept
|
||||
{
|
||||
return dynamic_cast <DragAndDropTarget*> (currentlyOverComp.get());
|
||||
return dynamic_cast<DragAndDropTarget*> (currentlyOverComp.get());
|
||||
}
|
||||
|
||||
static Component* findDesktopComponentBelow (Point<int> screenPos)
|
||||
{
|
||||
Desktop& desktop = Desktop::getInstance();
|
||||
|
||||
for (int i = desktop.getNumComponents(); --i >= 0;)
|
||||
{
|
||||
Component* c = desktop.getComponent(i);
|
||||
|
||||
if (Component* hit = c->getComponentAt (c->getLocalPoint (nullptr, screenPos)))
|
||||
return hit;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DragAndDropTarget* findTarget (Point<int> screenPos, Point<int>& relativePos,
|
||||
@@ -221,7 +238,7 @@ private:
|
||||
Component* hit = getParentComponent();
|
||||
|
||||
if (hit == nullptr)
|
||||
hit = Desktop::getInstance().findComponentAt (screenPos);
|
||||
hit = findDesktopComponentBelow (screenPos);
|
||||
else
|
||||
hit = hit->getComponentAt (hit->getLocalPoint (nullptr, screenPos));
|
||||
|
||||
@@ -231,7 +248,7 @@ private:
|
||||
|
||||
while (hit != nullptr)
|
||||
{
|
||||
if (DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit))
|
||||
if (DragAndDropTarget* const ddt = dynamic_cast<DragAndDropTarget*> (hit))
|
||||
{
|
||||
if (ddt->isInterestedInDragSource (details))
|
||||
{
|
||||
@@ -296,12 +313,17 @@ private:
|
||||
&& ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
|
||||
{
|
||||
(new ExternalDragAndDropMessage (files, canMoveFiles))->post();
|
||||
delete this;
|
||||
deleteSelf();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void deleteSelf()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void dismissWithAnimation (const bool shouldSnapBack)
|
||||
{
|
||||
setVisible (true);
|
||||
@@ -353,7 +375,7 @@ void DragAndDropContainer::startDragging (const var& sourceDescription,
|
||||
return;
|
||||
}
|
||||
|
||||
const Point<int> lastMouseDown (draggingSource->getLastMouseDownPosition());
|
||||
const Point<int> lastMouseDown (draggingSource->getLastMouseDownPosition().roundToInt());
|
||||
Point<int> imageOffset;
|
||||
|
||||
if (dragImage.isNull())
|
||||
@@ -383,7 +405,7 @@ void DragAndDropContainer::startDragging (const var& sourceDescription,
|
||||
{
|
||||
const float alpha = (distance > hi) ? 0
|
||||
: (hi - distance) / (float) (hi - lo)
|
||||
+ random.nextFloat() * 0.008f;
|
||||
+ random.nextFloat() * 0.008f;
|
||||
|
||||
dragImage.multiplyAlphaAt (x, y, alpha);
|
||||
}
|
||||
@@ -414,7 +436,7 @@ void DragAndDropContainer::startDragging (const var& sourceDescription,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Component* const thisComp = dynamic_cast <Component*> (this))
|
||||
if (Component* const thisComp = dynamic_cast<Component*> (this))
|
||||
{
|
||||
thisComp->addChildComponent (dragImageComponent);
|
||||
}
|
||||
@@ -425,8 +447,7 @@ void DragAndDropContainer::startDragging (const var& sourceDescription,
|
||||
}
|
||||
}
|
||||
|
||||
static_cast <DragImageComponent*> (dragImageComponent.get())->updateLocation (false, lastMouseDown);
|
||||
dragImageComponent->setVisible (true);
|
||||
static_cast<DragImageComponent*> (dragImageComponent.get())->updateLocation (false, lastMouseDown);
|
||||
dragImageComponent->enterModalState();
|
||||
|
||||
#if JUCE_WINDOWS
|
||||
@@ -435,6 +456,8 @@ void DragAndDropContainer::startDragging (const var& sourceDescription,
|
||||
if (ComponentPeer* const peer = dragImageComponent->getPeer())
|
||||
peer->performAnyPendingRepaintsNow();
|
||||
#endif
|
||||
|
||||
dragOperationStarted();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,6 +482,9 @@ bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const DragAndDr
|
||||
return false;
|
||||
}
|
||||
|
||||
void DragAndDropContainer::dragOperationStarted() {}
|
||||
void DragAndDropContainer::dragOperationEnded() {}
|
||||
|
||||
//==============================================================================
|
||||
DragAndDropTarget::SourceDetails::SourceDetails (const var& desc, Component* comp, Point<int> pos) noexcept
|
||||
: description (desc),
|
||||
|
||||
@@ -165,6 +165,12 @@ protected:
|
||||
virtual bool shouldDropFilesWhenDraggedExternally (const DragAndDropTarget::SourceDetails& sourceDetails,
|
||||
StringArray& files, bool& canMoveFiles);
|
||||
|
||||
/** Subclasses can override this to be told when a drag starts. */
|
||||
virtual void dragOperationStarted();
|
||||
|
||||
/** Subclasses can override this to be told when a drag finishes. */
|
||||
virtual void dragOperationEnded();
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
class DragImageComponent;
|
||||
|
||||
@@ -128,7 +128,7 @@ private:
|
||||
SpinLock MouseCursor::SharedCursorHandle::lock;
|
||||
|
||||
//==============================================================================
|
||||
MouseCursor::MouseCursor()
|
||||
MouseCursor::MouseCursor() noexcept
|
||||
: cursorHandle (nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -72,10 +72,10 @@ public:
|
||||
|
||||
//==============================================================================
|
||||
/** Creates the standard arrow cursor. */
|
||||
MouseCursor();
|
||||
MouseCursor() noexcept;
|
||||
|
||||
/** Creates one of the standard mouse cursor */
|
||||
MouseCursor (StandardCursorType type);
|
||||
MouseCursor (StandardCursorType);
|
||||
|
||||
/** Creates a custom cursor from an image.
|
||||
|
||||
|
||||
@@ -23,17 +23,18 @@
|
||||
*/
|
||||
|
||||
MouseEvent::MouseEvent (MouseInputSource inputSource,
|
||||
Point<int> position,
|
||||
Point<float> pos,
|
||||
ModifierKeys modKeys,
|
||||
Component* const eventComp,
|
||||
Component* const originator,
|
||||
Time time,
|
||||
Point<int> downPos,
|
||||
Point<float> downPos,
|
||||
Time downTime,
|
||||
const int numClicks,
|
||||
const bool mouseWasDragged) noexcept
|
||||
: x (position.x),
|
||||
y (position.y),
|
||||
: position (pos),
|
||||
x (roundToInt (pos.x)),
|
||||
y (roundToInt (pos.y)),
|
||||
mods (modKeys),
|
||||
eventComponent (eventComp),
|
||||
originalComponent (originator),
|
||||
@@ -55,19 +56,26 @@ MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) cons
|
||||
{
|
||||
jassert (otherComponent != nullptr);
|
||||
|
||||
return MouseEvent (source, otherComponent->getLocalPoint (eventComponent, getPosition()),
|
||||
return MouseEvent (source, otherComponent->getLocalPoint (eventComponent, position),
|
||||
mods, otherComponent, originalComponent, eventTime,
|
||||
otherComponent->getLocalPoint (eventComponent, mouseDownPos),
|
||||
mouseDownTime, numberOfClicks, wasMovedSinceMouseDown != 0);
|
||||
}
|
||||
|
||||
MouseEvent MouseEvent::withNewPosition (Point<int> newPosition) const noexcept
|
||||
MouseEvent MouseEvent::withNewPosition (Point<float> newPosition) const noexcept
|
||||
{
|
||||
return MouseEvent (source, newPosition, mods, eventComponent, originalComponent,
|
||||
eventTime, mouseDownPos, mouseDownTime,
|
||||
numberOfClicks, wasMovedSinceMouseDown != 0);
|
||||
}
|
||||
|
||||
MouseEvent MouseEvent::withNewPosition (Point<int> newPosition) const noexcept
|
||||
{
|
||||
return MouseEvent (source, newPosition.toFloat(), mods, eventComponent, originalComponent,
|
||||
eventTime, mouseDownPos, mouseDownTime,
|
||||
numberOfClicks, wasMovedSinceMouseDown != 0);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
bool MouseEvent::mouseWasClicked() const noexcept
|
||||
{
|
||||
@@ -86,17 +94,17 @@ int MouseEvent::getLengthOfMousePress() const noexcept
|
||||
Point<int> MouseEvent::getPosition() const noexcept { return Point<int> (x, y); }
|
||||
Point<int> MouseEvent::getScreenPosition() const { return eventComponent->localPointToGlobal (getPosition()); }
|
||||
|
||||
Point<int> MouseEvent::getMouseDownPosition() const noexcept { return mouseDownPos; }
|
||||
Point<int> MouseEvent::getMouseDownScreenPosition() const { return eventComponent->localPointToGlobal (mouseDownPos); }
|
||||
Point<int> MouseEvent::getMouseDownPosition() const noexcept { return mouseDownPos.roundToInt(); }
|
||||
Point<int> MouseEvent::getMouseDownScreenPosition() const { return eventComponent->localPointToGlobal (mouseDownPos).roundToInt(); }
|
||||
|
||||
Point<int> MouseEvent::getOffsetFromDragStart() const noexcept { return getPosition() - mouseDownPos; }
|
||||
int MouseEvent::getDistanceFromDragStart() const noexcept { return mouseDownPos.getDistanceFrom (getPosition()); }
|
||||
Point<int> MouseEvent::getOffsetFromDragStart() const noexcept { return (position - mouseDownPos).roundToInt(); }
|
||||
int MouseEvent::getDistanceFromDragStart() const noexcept { return roundToInt (mouseDownPos.getDistanceFrom (position)); }
|
||||
|
||||
int MouseEvent::getMouseDownX() const noexcept { return mouseDownPos.x; }
|
||||
int MouseEvent::getMouseDownY() const noexcept { return mouseDownPos.y; }
|
||||
int MouseEvent::getMouseDownX() const noexcept { return roundToInt (mouseDownPos.x); }
|
||||
int MouseEvent::getMouseDownY() const noexcept { return roundToInt (mouseDownPos.y); }
|
||||
|
||||
int MouseEvent::getDistanceFromDragStartX() const noexcept { return x - mouseDownPos.x; }
|
||||
int MouseEvent::getDistanceFromDragStartY() const noexcept { return y - mouseDownPos.y; }
|
||||
int MouseEvent::getDistanceFromDragStartX() const noexcept { return getOffsetFromDragStart().x; }
|
||||
int MouseEvent::getDistanceFromDragStartY() const noexcept { return getOffsetFromDragStart().y; }
|
||||
|
||||
int MouseEvent::getScreenX() const { return getScreenPosition().x; }
|
||||
int MouseEvent::getScreenY() const { return getScreenPosition().y; }
|
||||
|
||||
@@ -57,12 +57,12 @@ public:
|
||||
@param mouseWasDragged whether the mouse has been dragged significantly since the previous mouse-down
|
||||
*/
|
||||
MouseEvent (MouseInputSource source,
|
||||
Point<int> position,
|
||||
Point<float> position,
|
||||
ModifierKeys modifiers,
|
||||
Component* eventComponent,
|
||||
Component* originator,
|
||||
Time eventTime,
|
||||
Point<int> mouseDownPos,
|
||||
Point<float> mouseDownPos,
|
||||
Time mouseDownTime,
|
||||
int numberOfClicks,
|
||||
bool mouseWasDragged) noexcept;
|
||||
@@ -71,10 +71,22 @@ public:
|
||||
~MouseEvent() noexcept;
|
||||
|
||||
//==============================================================================
|
||||
/** The position of the mouse when the event occurred.
|
||||
|
||||
This value is relative to the top-left of the component to which the
|
||||
event applies (as indicated by the MouseEvent::eventComponent field).
|
||||
|
||||
This is a more accurate floating-point version of the position returned by
|
||||
getPosition() and the integer x and y member variables.
|
||||
*/
|
||||
const Point<float> position;
|
||||
|
||||
/** The x-position of the mouse when the event occurred.
|
||||
|
||||
This value is relative to the top-left of the component to which the
|
||||
event applies (as indicated by the MouseEvent::eventComponent field).
|
||||
|
||||
For a floating-point coordinate, see MouseEvent::position
|
||||
*/
|
||||
const int x;
|
||||
|
||||
@@ -82,6 +94,8 @@ public:
|
||||
|
||||
This value is relative to the top-left of the component to which the
|
||||
event applies (as indicated by the MouseEvent::eventComponent field).
|
||||
|
||||
For a floating-point coordinate, see MouseEvent::position
|
||||
*/
|
||||
const int y;
|
||||
|
||||
@@ -130,25 +144,19 @@ public:
|
||||
|
||||
//==============================================================================
|
||||
/** Returns the x coordinate of the last place that a mouse was pressed.
|
||||
|
||||
The coordinate is relative to the component specified in MouseEvent::component.
|
||||
|
||||
@see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked
|
||||
*/
|
||||
int getMouseDownX() const noexcept;
|
||||
|
||||
/** Returns the y coordinate of the last place that a mouse was pressed.
|
||||
|
||||
The coordinate is relative to the component specified in MouseEvent::component.
|
||||
|
||||
@see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked
|
||||
*/
|
||||
int getMouseDownY() const noexcept;
|
||||
|
||||
/** Returns the coordinates of the last place that a mouse was pressed.
|
||||
|
||||
The coordinates are relative to the component specified in MouseEvent::component.
|
||||
|
||||
@see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked
|
||||
*/
|
||||
Point<int> getMouseDownPosition() const noexcept;
|
||||
@@ -221,6 +229,8 @@ public:
|
||||
|
||||
This position is relative to the top-left of the component to which the
|
||||
event applies (as indicated by the MouseEvent::eventComponent field).
|
||||
|
||||
For a floating-point position, see MouseEvent::position
|
||||
*/
|
||||
Point<int> getPosition() const noexcept;
|
||||
|
||||
@@ -269,6 +279,12 @@ public:
|
||||
*/
|
||||
MouseEvent getEventRelativeTo (Component* newComponent) const noexcept;
|
||||
|
||||
/** Creates a copy of this event with a different position.
|
||||
All other members of the event object are the same, but the x and y are
|
||||
replaced with these new values.
|
||||
*/
|
||||
MouseEvent withNewPosition (Point<float> newPosition) const noexcept;
|
||||
|
||||
/** Creates a copy of this event with a different position.
|
||||
All other members of the event object are the same, but the x and y are
|
||||
replaced with these new values.
|
||||
@@ -297,7 +313,7 @@ public:
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
const Point<int> mouseDownPos;
|
||||
const Point<float> mouseDownPos;
|
||||
const uint8 numberOfClicks, wasMovedSinceMouseDown;
|
||||
|
||||
MouseEvent& operator= (const MouseEvent&);
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
return lastPeer;
|
||||
}
|
||||
|
||||
static Point<int> screenPosToLocalPos (Component& comp, Point<int> pos)
|
||||
static Point<float> screenPosToLocalPos (Component& comp, Point<float> pos)
|
||||
{
|
||||
if (ComponentPeer* const peer = comp.getPeer())
|
||||
{
|
||||
@@ -70,23 +70,25 @@ public:
|
||||
return comp.getLocalPoint (nullptr, ScalingHelpers::unscaledScreenPosToScaled (comp, pos));
|
||||
}
|
||||
|
||||
Component* findComponentAt (Point<int> screenPos)
|
||||
Component* findComponentAt (Point<float> screenPos)
|
||||
{
|
||||
if (ComponentPeer* const peer = getPeer())
|
||||
{
|
||||
Point<int> relativePos (ScalingHelpers::unscaledScreenPosToScaled (peer->getComponent(),
|
||||
peer->globalToLocal (screenPos)));
|
||||
Point<float> relativePos (ScalingHelpers::unscaledScreenPosToScaled (peer->getComponent(),
|
||||
peer->globalToLocal (screenPos)));
|
||||
Component& comp = peer->getComponent();
|
||||
|
||||
const Point<int> pos (relativePos.roundToInt());
|
||||
|
||||
// (the contains() call is needed to test for overlapping desktop windows)
|
||||
if (comp.contains (relativePos))
|
||||
return comp.getComponentAt (relativePos);
|
||||
if (comp.contains (pos))
|
||||
return comp.getComponentAt (pos);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Point<int> getScreenPosition() const
|
||||
Point<float> getScreenPosition() const
|
||||
{
|
||||
// This needs to return the live position if possible, but it mustn't update the lastScreenPos
|
||||
// value, because that can cause continuity problems.
|
||||
@@ -95,63 +97,63 @@ public:
|
||||
: lastScreenPos));
|
||||
}
|
||||
|
||||
void setScreenPosition (Point<int> p)
|
||||
void setScreenPosition (Point<float> p)
|
||||
{
|
||||
MouseInputSource::setRawMousePosition (ScalingHelpers::scaledScreenPosToUnscaled (p));
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
#if JUCE_DUMP_MOUSE_EVENTS
|
||||
#define JUCE_MOUSE_EVENT_DBG(desc) DBG ("Mouse " desc << " #" << source.getIndex() \
|
||||
#define JUCE_MOUSE_EVENT_DBG(desc) DBG ("Mouse " << desc << " #" << index \
|
||||
<< ": " << screenPosToLocalPos (comp, screenPos).toString() \
|
||||
<< " - Comp: " << String::toHexString ((int) &comp));
|
||||
<< " - Comp: " << String::toHexString ((pointer_sized_int) &comp));
|
||||
#else
|
||||
#define JUCE_MOUSE_EVENT_DBG(desc)
|
||||
#endif
|
||||
|
||||
void sendMouseEnter (Component& comp, Point<int> screenPos, Time time)
|
||||
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<int> screenPos, Time 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<int> screenPos, Time 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<int> screenPos, Time time)
|
||||
void sendMouseDown (Component& comp, Point<float> screenPos, Time time)
|
||||
{
|
||||
JUCE_MOUSE_EVENT_DBG ("down")
|
||||
comp.internalMouseDown (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time);
|
||||
}
|
||||
|
||||
void sendMouseDrag (Component& comp, Point<int> screenPos, Time time)
|
||||
void sendMouseDrag (Component& comp, Point<float> screenPos, Time time)
|
||||
{
|
||||
JUCE_MOUSE_EVENT_DBG ("drag")
|
||||
comp.internalMouseDrag (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time);
|
||||
}
|
||||
|
||||
void sendMouseUp (Component& comp, Point<int> screenPos, Time time, const ModifierKeys oldMods)
|
||||
void sendMouseUp (Component& comp, Point<float> screenPos, Time time, const ModifierKeys oldMods)
|
||||
{
|
||||
JUCE_MOUSE_EVENT_DBG ("up")
|
||||
comp.internalMouseUp (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time, oldMods);
|
||||
}
|
||||
|
||||
void sendMouseWheel (Component& comp, Point<int> screenPos, Time time, const MouseWheelDetails& wheel)
|
||||
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<int> screenPos, Time time, const float amount)
|
||||
void sendMagnifyGesture (Component& comp, Point<float> screenPos, Time time, const float amount)
|
||||
{
|
||||
JUCE_MOUSE_EVENT_DBG ("magnify")
|
||||
comp.internalMagnifyGesture (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time, amount);
|
||||
@@ -159,7 +161,7 @@ public:
|
||||
|
||||
//==============================================================================
|
||||
// (returns true if the button change caused a modal event loop)
|
||||
bool setButtons (Point<int> screenPos, Time time, const ModifierKeys newButtonState)
|
||||
bool setButtons (Point<float> screenPos, Time time, const ModifierKeys newButtonState)
|
||||
{
|
||||
if (buttonState == newButtonState)
|
||||
return false;
|
||||
@@ -209,7 +211,7 @@ public:
|
||||
return lastCounter != mouseEventCounter;
|
||||
}
|
||||
|
||||
void setComponentUnderMouse (Component* const newComponent, Point<int> screenPos, Time time)
|
||||
void setComponentUnderMouse (Component* const newComponent, Point<float> screenPos, Time time)
|
||||
{
|
||||
Component* current = getComponentUnderMouse();
|
||||
|
||||
@@ -242,7 +244,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void setPeer (ComponentPeer& newPeer, Point<int> screenPos, Time time)
|
||||
void setPeer (ComponentPeer& newPeer, Point<float> screenPos, Time time)
|
||||
{
|
||||
ModifierKeys::updateCurrentModifiers();
|
||||
|
||||
@@ -254,7 +256,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void setScreenPos (Point<int> newScreenPos, Time time, const bool forceUpdate)
|
||||
void setScreenPos (Point<float> newScreenPos, Time time, const bool forceUpdate)
|
||||
{
|
||||
if (! isDragging())
|
||||
setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
|
||||
@@ -272,7 +274,7 @@ public:
|
||||
sendMouseDrag (*current, newScreenPos + unboundedMouseOffset, time);
|
||||
|
||||
if (isUnboundedMouseModeOn)
|
||||
handleUnboundedDrag (current);
|
||||
handleUnboundedDrag (*current);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -285,11 +287,11 @@ public:
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void handleEvent (ComponentPeer& newPeer, Point<int> positionWithinPeer, Time time, const ModifierKeys newMods)
|
||||
void handleEvent (ComponentPeer& newPeer, Point<float> positionWithinPeer, Time time, const ModifierKeys newMods)
|
||||
{
|
||||
lastTime = time;
|
||||
++mouseEventCounter;
|
||||
const Point<int> screenPos (newPeer.localToGlobal (positionWithinPeer));
|
||||
const Point<float> screenPos (newPeer.localToGlobal (positionWithinPeer));
|
||||
|
||||
if (isDragging() && newMods.isAnyMouseButtonDown())
|
||||
{
|
||||
@@ -311,8 +313,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
Component* getTargetForGesture (ComponentPeer& peer, Point<int> positionWithinPeer,
|
||||
Time time, Point<int>& screenPos)
|
||||
Component* getTargetForGesture (ComponentPeer& peer, Point<float> positionWithinPeer,
|
||||
Time time, Point<float>& screenPos)
|
||||
{
|
||||
lastTime = time;
|
||||
++mouseEventCounter;
|
||||
@@ -325,27 +327,27 @@ public:
|
||||
return isDragging() ? nullptr : getComponentUnderMouse();
|
||||
}
|
||||
|
||||
void handleWheel (ComponentPeer& peer, Point<int> positionWithinPeer,
|
||||
void handleWheel (ComponentPeer& peer, Point<float> positionWithinPeer,
|
||||
Time time, const MouseWheelDetails& wheel)
|
||||
{
|
||||
Desktop::getInstance().incrementMouseWheelCounter();
|
||||
|
||||
Point<int> screenPos;
|
||||
Point<float> screenPos;
|
||||
if (Component* current = getTargetForGesture (peer, positionWithinPeer, time, screenPos))
|
||||
sendMouseWheel (*current, screenPos, time, wheel);
|
||||
}
|
||||
|
||||
void handleMagnifyGesture (ComponentPeer& peer, Point<int> positionWithinPeer,
|
||||
void handleMagnifyGesture (ComponentPeer& peer, Point<float> positionWithinPeer,
|
||||
Time time, const float scaleFactor)
|
||||
{
|
||||
Point<int> screenPos;
|
||||
Point<float> screenPos;
|
||||
if (Component* current = getTargetForGesture (peer, positionWithinPeer, time, screenPos))
|
||||
sendMagnifyGesture (*current, screenPos, time, scaleFactor);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
Time getLastMouseDownTime() const noexcept { return mouseDowns[0].time; }
|
||||
Point<int> getLastMouseDownPosition() const noexcept { return ScalingHelpers::unscaledScreenPosToScaled (mouseDowns[0].position); }
|
||||
Point<float> getLastMouseDownPosition() const noexcept { return ScalingHelpers::unscaledScreenPosToScaled (mouseDowns[0].position); }
|
||||
|
||||
int getNumberOfMultipleClicks() const noexcept
|
||||
{
|
||||
@@ -397,33 +399,34 @@ public:
|
||||
{
|
||||
// when released, return the mouse to within the component's bounds
|
||||
if (Component* current = getComponentUnderMouse())
|
||||
Desktop::setMousePosition (current->getScreenBounds()
|
||||
.getConstrainedPoint (lastScreenPos));
|
||||
setScreenPosition (current->getScreenBounds().toFloat()
|
||||
.getConstrainedPoint (ScalingHelpers::unscaledScreenPosToScaled (lastScreenPos)));
|
||||
}
|
||||
|
||||
isUnboundedMouseModeOn = enable;
|
||||
unboundedMouseOffset = Point<int>();
|
||||
unboundedMouseOffset = Point<float>();
|
||||
|
||||
revealCursor (true);
|
||||
}
|
||||
}
|
||||
|
||||
void handleUnboundedDrag (Component* current)
|
||||
void handleUnboundedDrag (Component& current)
|
||||
{
|
||||
const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
|
||||
const Rectangle<float> componentScreenBounds
|
||||
= ScalingHelpers::scaledScreenPosToUnscaled (current.getParentMonitorArea().reduced (2, 2).toFloat());
|
||||
|
||||
if (! screenArea.contains (lastScreenPos))
|
||||
if (! componentScreenBounds.contains (lastScreenPos))
|
||||
{
|
||||
const Point<int> componentCentre (current->getScreenBounds().getCentre());
|
||||
unboundedMouseOffset += (lastScreenPos - componentCentre);
|
||||
Desktop::setMousePosition (componentCentre);
|
||||
const Point<float> componentCentre (current.getScreenBounds().toFloat().getCentre());
|
||||
unboundedMouseOffset += (lastScreenPos - ScalingHelpers::scaledScreenPosToUnscaled (componentCentre));
|
||||
setScreenPosition (componentCentre);
|
||||
}
|
||||
else if (isCursorVisibleUntilOffscreen
|
||||
&& (! unboundedMouseOffset.isOrigin())
|
||||
&& screenArea.contains (lastScreenPos + unboundedMouseOffset))
|
||||
&& componentScreenBounds.contains (lastScreenPos + unboundedMouseOffset))
|
||||
{
|
||||
Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset);
|
||||
unboundedMouseOffset = Point<int>();
|
||||
MouseInputSource::setRawMousePosition (lastScreenPos + unboundedMouseOffset);
|
||||
unboundedMouseOffset = Point<float>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,10 +464,9 @@ public:
|
||||
//==============================================================================
|
||||
const int index;
|
||||
const bool isMouseDevice;
|
||||
Point<int> lastScreenPos;
|
||||
Point<float> lastScreenPos, unboundedMouseOffset; // NB: these are unscaled coords
|
||||
ModifierKeys buttonState;
|
||||
|
||||
Point<int> unboundedMouseOffset;
|
||||
bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
|
||||
|
||||
private:
|
||||
@@ -478,7 +480,7 @@ private:
|
||||
{
|
||||
RecentMouseDown() noexcept : peerID (0) {}
|
||||
|
||||
Point<int> position;
|
||||
Point<float> position;
|
||||
Time time;
|
||||
ModifierKeys buttons;
|
||||
uint32 peerID;
|
||||
@@ -486,8 +488,8 @@ private:
|
||||
bool canBePartOfMultipleClickWith (const RecentMouseDown& other, const int maxTimeBetweenMs) const
|
||||
{
|
||||
return time - other.time < RelativeTime::milliseconds (maxTimeBetweenMs)
|
||||
&& abs (position.x - other.position.x) < 8
|
||||
&& abs (position.y - other.position.y) < 8
|
||||
&& std::abs (position.x - other.position.x) < 8
|
||||
&& std::abs (position.y - other.position.y) < 8
|
||||
&& buttons == other.buttons
|
||||
&& peerID == other.peerID;
|
||||
}
|
||||
@@ -497,7 +499,7 @@ private:
|
||||
Time lastTime;
|
||||
bool mouseMovedSignificantlySincePressed;
|
||||
|
||||
void registerMouseDown (Point<int> screenPos, Time time,
|
||||
void registerMouseDown (Point<float> screenPos, Time time,
|
||||
Component& component, const ModifierKeys modifiers) noexcept
|
||||
{
|
||||
for (int i = numElementsInArray (mouseDowns); --i > 0;)
|
||||
@@ -515,7 +517,7 @@ private:
|
||||
mouseMovedSignificantlySincePressed = false;
|
||||
}
|
||||
|
||||
void registerMouseDrag (Point<int> screenPos) noexcept
|
||||
void registerMouseDrag (Point<float> screenPos) noexcept
|
||||
{
|
||||
mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
|
||||
|| mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
|
||||
@@ -535,47 +537,44 @@ MouseInputSource& MouseInputSource::operator= (const MouseInputSource& other) no
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
|
||||
bool MouseInputSource::isTouch() const { return ! isMouse(); }
|
||||
bool MouseInputSource::canHover() const { return isMouse(); }
|
||||
bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
|
||||
int MouseInputSource::getIndex() const { return pimpl->index; }
|
||||
bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
|
||||
Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
|
||||
ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
|
||||
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<int> MouseInputSource::getLastMouseDownPosition() const noexcept { return pimpl->getLastMouseDownPosition(); }
|
||||
bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
|
||||
bool MouseInputSource::isTouch() const { return ! isMouse(); }
|
||||
bool MouseInputSource::canHover() const { return isMouse(); }
|
||||
bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
|
||||
int MouseInputSource::getIndex() const { return pimpl->index; }
|
||||
bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
|
||||
Point<float> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
|
||||
ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
|
||||
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::hasMouseMovedSignificantlySincePressed() const noexcept { return pimpl->hasMouseMovedSignificantlySincePressed(); }
|
||||
bool MouseInputSource::canDoUnboundedMovement() const noexcept { return isMouse(); }
|
||||
bool MouseInputSource::canDoUnboundedMovement() const noexcept { return isMouse(); }
|
||||
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 isMouse(); }
|
||||
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<int> p) { pimpl->setScreenPosition (p); }
|
||||
{ pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); }
|
||||
bool MouseInputSource::isUnboundedMouseMovementEnabled() const { return pimpl->isUnboundedMouseModeOn; }
|
||||
bool MouseInputSource::hasMouseCursor() const noexcept { return isMouse(); }
|
||||
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<int> positionWithinPeer,
|
||||
const int64 time, const ModifierKeys mods)
|
||||
void MouseInputSource::handleEvent (ComponentPeer& peer, Point<float> pos, int64 time, ModifierKeys mods)
|
||||
{
|
||||
pimpl->handleEvent (peer, positionWithinPeer, Time (time), mods.withOnlyMouseButtons());
|
||||
pimpl->handleEvent (peer, pos, Time (time), mods.withOnlyMouseButtons());
|
||||
}
|
||||
|
||||
void MouseInputSource::handleWheel (ComponentPeer& peer, Point<int> positionWithinPeer,
|
||||
const int64 time, const MouseWheelDetails& wheel)
|
||||
void MouseInputSource::handleWheel (ComponentPeer& peer, Point<float> pos, int64 time, const MouseWheelDetails& wheel)
|
||||
{
|
||||
pimpl->handleWheel (peer, positionWithinPeer, Time (time), wheel);
|
||||
pimpl->handleWheel (peer, pos, Time (time), wheel);
|
||||
}
|
||||
|
||||
void MouseInputSource::handleMagnifyGesture (ComponentPeer& peer, Point<int> positionWithinPeer,
|
||||
const int64 time, const float scaleFactor)
|
||||
void MouseInputSource::handleMagnifyGesture (ComponentPeer& peer, Point<float> pos, int64 time, float scaleFactor)
|
||||
{
|
||||
pimpl->handleMagnifyGesture (peer, positionWithinPeer, Time (time), scaleFactor);
|
||||
pimpl->handleMagnifyGesture (peer, pos, Time (time), scaleFactor);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
bool isDragging() const;
|
||||
|
||||
/** Returns the last-known screen position of this source. */
|
||||
Point<int> getScreenPosition() const;
|
||||
Point<float> getScreenPosition() const;
|
||||
|
||||
/** Returns a set of modifiers that indicate which buttons are currently
|
||||
held down on this device.
|
||||
@@ -114,7 +114,7 @@ public:
|
||||
Time getLastMouseDownTime() const noexcept;
|
||||
|
||||
/** Returns the screen position at which the last mouse-down occurred. */
|
||||
Point<int> getLastMouseDownPosition() const noexcept;
|
||||
Point<float> getLastMouseDownPosition() const noexcept;
|
||||
|
||||
/** Returns true if this mouse is currently down, and if it has been dragged more
|
||||
than a couple of pixels from the place it was pressed.
|
||||
@@ -162,7 +162,7 @@ public:
|
||||
bool isUnboundedMouseMovementEnabled() const;
|
||||
|
||||
/** Attempts to set this mouse pointer's screen position. */
|
||||
void setScreenPosition (Point<int> newPosition);
|
||||
void setScreenPosition (Point<float> newPosition);
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
@@ -174,12 +174,12 @@ private:
|
||||
struct SourceList;
|
||||
|
||||
explicit MouseInputSource (MouseInputSourceInternal*) noexcept;
|
||||
void handleEvent (ComponentPeer&, Point<int>, int64 time, const ModifierKeys);
|
||||
void handleWheel (ComponentPeer&, Point<int>, int64 time, const MouseWheelDetails&);
|
||||
void handleMagnifyGesture (ComponentPeer&, Point<int>, int64 time, float scaleFactor);
|
||||
void handleEvent (ComponentPeer&, Point<float>, int64 time, ModifierKeys);
|
||||
void handleWheel (ComponentPeer&, Point<float>, int64 time, const MouseWheelDetails&);
|
||||
void handleMagnifyGesture (ComponentPeer&, Point<float>, int64 time, float scaleFactor);
|
||||
|
||||
static Point<int> getCurrentRawMousePosition();
|
||||
static void setRawMousePosition (Point<int>);
|
||||
static Point<float> getCurrentRawMousePosition();
|
||||
static void setRawMousePosition (Point<float>);
|
||||
|
||||
JUCE_LEAK_DETECTOR (MouseInputSource)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user