From 06c63c63aada44c2864541869a6a01e76f18f6a9 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Tue, 16 Feb 2010 18:31:44 +0000 Subject: [PATCH] Changed some methods that were using (x, y) parameters to use Point objects instead. --- juce_amalgamated.cpp | 1164 +++++++---------- juce_amalgamated.h | 367 +++--- src/gui/components/buttons/juce_Button.cpp | 14 +- src/gui/components/controls/juce_ListBox.cpp | 15 +- src/gui/components/controls/juce_ListBox.h | 2 +- src/gui/components/controls/juce_Slider.cpp | 22 +- .../controls/juce_TableHeaderComponent.cpp | 5 +- .../components/controls/juce_TableListBox.cpp | 5 +- .../components/controls/juce_TextEditor.cpp | 3 +- src/gui/components/controls/juce_TreeView.cpp | 9 +- src/gui/components/juce_Component.cpp | 239 ++-- src/gui/components/juce_Component.h | 21 +- src/gui/components/juce_Desktop.cpp | 55 +- src/gui/components/juce_Desktop.h | 14 +- .../juce_ComponentBoundsConstrainer.cpp | 3 +- .../layout/juce_ComponentMovementWatcher.cpp | 13 +- .../layout/juce_ComponentMovementWatcher.h | 2 +- .../menus/juce_MenuBarComponent.cpp | 13 +- src/gui/components/menus/juce_PopupMenu.cpp | 92 +- .../mouse/juce_ComponentDragger.cpp | 21 +- .../components/mouse/juce_ComponentDragger.h | 2 +- .../mouse/juce_DragAndDropContainer.cpp | 100 +- src/gui/components/mouse/juce_MouseEvent.cpp | 80 +- src/gui/components/mouse/juce_MouseEvent.h | 55 +- .../mouse/juce_MouseHoverDetector.cpp | 7 +- .../special/juce_BubbleComponent.cpp | 9 +- .../special/juce_MagnifierComponent.cpp | 28 +- .../special/juce_MidiKeyboardComponent.cpp | 53 +- .../special/juce_MidiKeyboardComponent.h | 6 +- .../special/juce_OpenGLComponent.cpp | 5 +- .../components/windows/juce_ComponentPeer.cpp | 90 +- .../components/windows/juce_ComponentPeer.h | 11 +- .../windows/juce_ResizableWindow.cpp | 3 +- .../components/windows/juce_TooltipWindow.cpp | 27 +- .../components/windows/juce_TooltipWindow.h | 3 +- .../windows/juce_TopLevelWindow.cpp | 11 +- src/gui/graphics/geometry/juce_Point.h | 10 +- src/gui/graphics/geometry/juce_Rectangle.h | 18 + src/native/linux/juce_linux_Windowing.cpp | 81 +- .../mac/juce_iphone_UIViewComponentPeer.mm | 18 +- src/native/mac/juce_mac_MiscUtilities.mm | 9 +- src/native/mac/juce_mac_NSViewComponent.mm | 7 +- .../mac/juce_mac_NSViewComponentPeer.mm | 45 +- .../windows/juce_win32_ActiveXComponent.cpp | 19 +- src/native/windows/juce_win32_Windowing.cpp | 63 +- 45 files changed, 1253 insertions(+), 1586 deletions(-) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index eb02a56a66..11921531a8 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -38511,8 +38511,7 @@ static Array modalReturnValues; static const int customCommandMessage = 0x7fff0001; static const int exitModalStateMessage = 0x7fff0002; -static int unboundedMouseOffsetX = 0; -static int unboundedMouseOffsetY = 0; +static Point unboundedMouseOffset; static bool isUnboundedMouseModeOn = false; static bool isCursorVisibleUntilOffscreen; @@ -38862,8 +38861,7 @@ void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo) jmax (1, getHeight())); #endif - int x = 0, y = 0; - relativePositionToGlobal (x, y); + const Point topLeft (relativePositionToGlobal (Point (0, 0))); bool wasFullscreen = false; bool wasMinimised = false; @@ -38879,7 +38877,7 @@ void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo) removeFromDesktop(); - setTopLeftPosition (x, y); + setTopLeftPosition (topLeft.getX(), topLeft.getY()); } if (parentComponent_ != 0) @@ -38893,8 +38891,8 @@ void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo) Desktop::getInstance().addDesktopComponent (this); - bounds_.setPosition (x, y); - peer->setBounds (x, y, getWidth(), getHeight(), false); + bounds_.setPosition (topLeft); + peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false); peer->setVisible (isVisible()); @@ -39187,57 +39185,60 @@ int Component::getParentHeight() const throw() : getParentMonitorArea().getHeight(); } -int Component::getScreenX() const throw() +int Component::getScreenX() const { - return (parentComponent_ != 0) ? parentComponent_->getScreenX() + getX() - : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenX() - : getX()); + return getScreenPosition().getX(); } -int Component::getScreenY() const throw() +int Component::getScreenY() const { - return (parentComponent_ != 0) ? parentComponent_->getScreenY() + getY() - : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenY() - : getY()); + return getScreenPosition().getY(); } -void Component::relativePositionToGlobal (int& x, int& y) const throw() +const Point Component::getScreenPosition() const +{ + return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition() + : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition() + : getPosition()); +} + +const Point Component::relativePositionToGlobal (const Point& relativePosition) const { const Component* c = this; + Point p (relativePosition); do { if (c->flags.hasHeavyweightPeerFlag) - { - c->getPeer()->relativePositionToGlobal (x, y); - break; - } + return c->getPeer()->relativePositionToGlobal (p); - x += c->getX(); - y += c->getY(); + p += c->getPosition(); c = c->parentComponent_; } while (c != 0); + + return p; } -void Component::globalPositionToRelative (int& x, int& y) const throw() +const Point Component::globalPositionToRelative (const Point& screenPosition) const { if (flags.hasHeavyweightPeerFlag) { - getPeer()->globalPositionToRelative (x, y); + return getPeer()->globalPositionToRelative (screenPosition); } else { if (parentComponent_ != 0) - parentComponent_->globalPositionToRelative (x, y); + return parentComponent_->globalPositionToRelative (screenPosition) - getPosition(); - x -= getX(); - y -= getY(); + return screenPosition - getPosition(); } } -void Component::relativePositionToOtherComponent (const Component* const targetComponent, int& x, int& y) const throw() +const Point Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point& positionRelativeToThis) const { + Point p (positionRelativeToThis); + if (targetComponent != 0) { const Component* c = this; @@ -39245,22 +39246,23 @@ void Component::relativePositionToOtherComponent (const Component* const targetC do { if (c == targetComponent) - return; + return p; if (c->flags.hasHeavyweightPeerFlag) { - c->getPeer()->relativePositionToGlobal (x, y); + p = c->getPeer()->relativePositionToGlobal (p); break; } - x += c->getX(); - y += c->getY(); + p += c->getPosition(); c = c->parentComponent_; } while (c != 0); - targetComponent->globalPositionToRelative (x, y); + p = targetComponent->globalPositionToRelative (p); } + + return p; } void Component::setBounds (int x, int y, int w, int h) @@ -39983,10 +39985,9 @@ void Component::setMouseCursor (const MouseCursor& cursor) throw() if (flags.visibleFlag) { - int mx, my; - getMouseXYRelative (mx, my); + const Point mousePos (getMouseXYRelative()); - if (flags.draggingFlag || reallyContains (mx, my, false)) + if (flags.draggingFlag || reallyContains (mousePos.getX(), mousePos.getY(), false)) { internalUpdateMouseCursor (false); } @@ -40011,9 +40012,8 @@ void Component::internalUpdateMouseCursor (bool forcedUpdate) throw() { MouseCursor mc (getLookAndFeel().getMouseCursorFor (*this)); - if (isUnboundedMouseModeOn && (unboundedMouseOffsetX != 0 - || unboundedMouseOffsetY != 0 - || ! isCursorVisibleUntilOffscreen)) + if (isUnboundedMouseModeOn + && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen)) { mc = MouseCursor::NoCursor; forcedUpdate = true; @@ -40420,22 +40420,18 @@ void Component::getVisibleArea (RectangleList& result, { const Component* const c = getTopLevelComponent(); - int x = 0, y = 0; - c->relativePositionToOtherComponent (this, x, y); - - c->subtractObscuredRegions (result, x, y, + c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point()), Rectangle (0, 0, c->getWidth(), c->getHeight()), this); } - subtractObscuredRegions (result, 0, 0, unclipped, 0); + subtractObscuredRegions (result, Point(), unclipped, 0); result.consolidate(); } } void Component::subtractObscuredRegions (RectangleList& result, - const int deltaX, - const int deltaY, + const Point& delta, const Rectangle& clipRect, const Component* const compToAvoid) const throw() { @@ -40448,7 +40444,7 @@ void Component::subtractObscuredRegions (RectangleList& result, if (c->isOpaque()) { Rectangle childBounds (c->bounds_.getIntersection (clipRect)); - childBounds.translate (deltaX, deltaY); + childBounds.translate (delta.getX(), delta.getY()); result.subtract (childBounds); } @@ -40457,11 +40453,8 @@ void Component::subtractObscuredRegions (RectangleList& result, Rectangle newClip (clipRect.getIntersection (c->bounds_)); newClip.translate (-c->getX(), -c->getY()); - c->subtractObscuredRegions (result, - c->getX() + deltaX, - c->getY() + deltaY, - newClip, - compToAvoid); + c->subtractObscuredRegions (result, c->getPosition() + delta, + newClip, compToAvoid); } } } @@ -40674,11 +40667,11 @@ void Component::internalMouseEnter (int x, int y, int64 time) if (flags.repaintOnMouseActivityFlag) repaint(); - const MouseEvent me (x, y, + const MouseEvent me (Point (x, y), ModifierKeys::getCurrentModifiers(), this, Time (time), - x, y, + Point (x, y), Time (time), 0, false); @@ -40759,11 +40752,11 @@ void Component::internalMouseExit (int x, int y, int64 time) if (flags.repaintOnMouseActivityFlag) repaint(); - const MouseEvent me (x, y, + const MouseEvent me (Point (x, y), ModifierKeys::getCurrentModifiers(), this, Time (time), - x, y, + Point (x, y), Time (time), 0, false); mouseExit (me); @@ -40829,15 +40822,13 @@ public: if (c != 0 && c->isMouseButtonDown()) { - int x, y; - c->getMouseXYRelative (x, y); + const Point mousePos (c->getMouseXYRelative()); // the offsets have been added on, so must be taken off before calling the // drag.. otherwise they'll be added twice - x -= unboundedMouseOffsetX; - y -= unboundedMouseOffsetY; - - c->internalMouseDrag (x, y, Time::currentTimeMillis()); + c->internalMouseDrag (mousePos.getX() - unboundedMouseOffset.getX(), + mousePos.getY() - unboundedMouseOffset.getY(), + Time::currentTimeMillis()); } } @@ -40870,9 +40861,7 @@ void Component::internalMouseDown (const int x, const int y, const int64 time) { Desktop& desktop = Desktop::getInstance(); - int gx = x, gy = y; - relativePositionToGlobal (gx, gy); - desktop.registerMouseDown (Point (gx, gy), time, this); + desktop.registerMouseDown (relativePositionToGlobal (Point (x, y)), time, this); const ComponentDeletionWatcher deletionChecker (this); @@ -40888,11 +40877,11 @@ void Component::internalMouseDown (const int x, const int y, const int64 time) if (isCurrentlyBlockedByAnotherModalComponent()) { // allow blocked mouse-events to go to global listeners.. - const MouseEvent me (x, y, + const MouseEvent me (Point (x, y), ModifierKeys::getCurrentModifiers(), this, Time (time), - x, y, + Point (x, y), desktop.getLastMouseDownTime(), desktop.getNumberOfMultipleClicks(), false); @@ -40941,11 +40930,11 @@ void Component::internalMouseDown (const int x, const int y, const int64 time) if (flags.repaintOnMouseActivityFlag) repaint(); - const MouseEvent me (x, y, + const MouseEvent me (Point (x, y), ModifierKeys::getCurrentModifiers(), this, desktop.getLastMouseDownTime(), - x, y, + Point (x, y), desktop.getLastMouseDownTime(), desktop.getNumberOfMultipleClicks(), false); @@ -41009,29 +40998,24 @@ void Component::internalMouseUp (const int oldModifiers, int x, int y, const int flags.draggingFlag = false; deleteAndZero (dragRepeater); - x += unboundedMouseOffsetX; - y += unboundedMouseOffsetY; + x += unboundedMouseOffset.getX(); + y += unboundedMouseOffset.getY(); - int gx = x, gy = y; - relativePositionToGlobal (gx, gy); - desktop.registerMouseDrag (Point (gx, gy)); + desktop.registerMouseDrag (relativePositionToGlobal (Point (x, y))); const ComponentDeletionWatcher deletionChecker (this); if (flags.repaintOnMouseActivityFlag) repaint(); - int mdx, mdy; - Desktop::getLastMouseDownPosition (mdx, mdy); - globalPositionToRelative (mdx, mdy); - + const Point mouseDownPos (globalPositionToRelative (Desktop::getLastMouseDownPosition())); const Time lastMouseDownTime (desktop.getLastMouseDownTime()); - const MouseEvent me (x, y, + const MouseEvent me (Point (x, y), oldModifiers, this, Time (time), - mdx, mdy, + mouseDownPos, lastMouseDownTime, desktop.getNumberOfMultipleClicks(), desktop.mouseMovedSignificantlySincePressed @@ -41151,26 +41135,21 @@ void Component::internalMouseDrag (int x, int y, const int64 time) flags.mouseOverFlag = reallyContains (x, y, false); - x += unboundedMouseOffsetX; - y += unboundedMouseOffsetY; + x += unboundedMouseOffset.getX(); + y += unboundedMouseOffset.getY(); - int gx = x, gy = y; - relativePositionToGlobal (gx, gy); - desktop.registerMouseDrag (Point (gx, gy)); + desktop.registerMouseDrag (relativePositionToGlobal (Point (x, y))); const ComponentDeletionWatcher deletionChecker (this); - int mdx, mdy; - Desktop::getLastMouseDownPosition (mdx, mdy); - globalPositionToRelative (mdx, mdy); - + const Point mouseDownPos (globalPositionToRelative (Desktop::getLastMouseDownPosition())); const Time lastMouseDownTime (desktop.getLastMouseDownTime()); - const MouseEvent me (x, y, + const MouseEvent me (Point (x, y), ModifierKeys::getCurrentModifiers(), this, Time (time), - mdx, mdy, + mouseDownPos, lastMouseDownTime, desktop.getNumberOfMultipleClicks(), desktop.mouseMovedSignificantlySincePressed @@ -41230,37 +41209,30 @@ void Component::internalMouseDrag (int x, int y, const int64 time) if (isUnboundedMouseModeOn) { Rectangle screenArea (getParentMonitorArea().expanded (-2, -2)); + Point mousePos (Desktop::getMousePosition()); - int mx, my; - Desktop::getMousePosition (mx, my); - - if (! screenArea.contains (mx, my)) + if (! screenArea.contains (mousePos)) { int deltaX = 0, deltaY = 0; - if (mx <= screenArea.getX() || mx >= screenArea.getRight()) - deltaX = getScreenX() + getWidth() / 2 - mx; + if (mousePos.getX() <= screenArea.getX() || mousePos.getX() >= screenArea.getRight()) + deltaX = getScreenX() + getWidth() / 2 - mousePos.getX(); - if (my <= screenArea.getY() || my >= screenArea.getBottom()) - deltaY = getScreenY() + getHeight() / 2 - my; + if (mousePos.getY() <= screenArea.getY() || mousePos.getY() >= screenArea.getBottom()) + deltaY = getScreenY() + getHeight() / 2 - mousePos.getY(); - unboundedMouseOffsetX -= deltaX; - unboundedMouseOffsetY -= deltaY; + unboundedMouseOffset -= Point (deltaX, deltaY); - Desktop::setMousePosition (mx + deltaX, - my + deltaY); + Desktop::setMousePosition (mousePos + Point (deltaX, deltaY)); } else if (isCursorVisibleUntilOffscreen - && (unboundedMouseOffsetX != 0 || unboundedMouseOffsetY != 0) - && screenArea.contains (mx + unboundedMouseOffsetX, - my + unboundedMouseOffsetY)) + && (! unboundedMouseOffset.isOrigin()) + && screenArea.contains (mousePos + unboundedMouseOffset)) { - mx += unboundedMouseOffsetX; - my += unboundedMouseOffsetY; - unboundedMouseOffsetX = 0; - unboundedMouseOffsetY = 0; + mousePos += unboundedMouseOffset; + unboundedMouseOffset = Point(); - Desktop::setMousePosition (mx, my); + Desktop::setMousePosition (mousePos); } } @@ -41277,11 +41249,11 @@ void Component::internalMouseMove (const int x, const int y, const int64 time) { Desktop& desktop = Desktop::getInstance(); - const MouseEvent me (x, y, + const MouseEvent me (Point (x, y), ModifierKeys::getCurrentModifiers(), this, Time (time), - x, y, + Point (x, y), Time (time), 0, false); @@ -41357,14 +41329,13 @@ void Component::internalMouseWheel (const int intAmountX, const int intAmountY, const float wheelIncrementX = intAmountX * (1.0f / 256.0f); const float wheelIncrementY = intAmountY * (1.0f / 256.0f); - int mx, my; - getMouseXYRelative (mx, my); + const Point mousePos (getMouseXYRelative()); - const MouseEvent me (mx, my, + const MouseEvent me (mousePos, ModifierKeys::getCurrentModifiers(), this, Time (time), - mx, my, + mousePos, Time (time), 0, false); @@ -41818,13 +41789,9 @@ bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw() return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(); } -void Component::getMouseXYRelative (int& mx, int& my) const throw() +const Point Component::getMouseXYRelative() const { - Desktop::getMousePosition (mx, my); - globalPositionToRelative (mx, my); - - mx += unboundedMouseOffsetX; - my += unboundedMouseOffsetY; + return globalPositionToRelative (Desktop::getMousePosition()) + unboundedMouseOffset; } void Component::enableUnboundedMouseMovement (bool enable, @@ -41836,25 +41803,15 @@ void Component::enableUnboundedMouseMovement (bool enable, if (enable != isUnboundedMouseModeOn) { if ((! enable) && ((! isCursorVisibleUntilOffscreen) - || unboundedMouseOffsetX != 0 - || unboundedMouseOffsetY != 0)) + || ! unboundedMouseOffset.isOrigin())) { // when released, return the mouse to within the component's bounds - - int mx, my; - getMouseXYRelative (mx, my); - - mx = jlimit (0, getWidth(), mx); - my = jlimit (0, getHeight(), my); - - relativePositionToGlobal (mx, my); - - Desktop::setMousePosition (mx, my); + Desktop::setMousePosition (relativePositionToGlobal (Rectangle (0, 0, getWidth(), getHeight()) + .getConstrainedPoint (getMouseXYRelative()))); } isUnboundedMouseModeOn = enable; - unboundedMouseOffsetX = 0; - unboundedMouseOffsetY = 0; + unboundedMouseOffset = Point(); internalUpdateMouseCursor (true); } @@ -41867,11 +41824,9 @@ Component* JUCE_CALLTYPE Component::getComponentUnderMouse() throw() const Rectangle Component::getParentMonitorArea() const throw() { - int centreX = getWidth() / 2; - int centreY = getHeight() / 2; - relativePositionToGlobal (centreX, centreY); - - return Desktop::getInstance().getMonitorAreaContaining (centreX, centreY); + return Desktop::getInstance() + .getMonitorAreaContaining (relativePositionToGlobal (Point (getWidth() / 2, + getHeight() / 2))); } void Component::addKeyListener (KeyListener* const newListener) throw() @@ -41982,9 +41937,7 @@ END_JUCE_NAMESPACE BEGIN_JUCE_NAMESPACE Desktop::Desktop() throw() - : lastFakeMouseMoveX (0), - lastFakeMouseMoveY (0), - mouseClickCounter (0), + : mouseClickCounter (0), mouseMovedSignificantlySincePressed (false), kioskModeComponent (0) { @@ -42065,7 +42018,7 @@ const Rectangle Desktop::getMainMonitorArea (const bool clippedToWorkArea) return getDisplayMonitorCoordinates (0, clippedToWorkArea); } -const Rectangle Desktop::getMonitorAreaContaining (int cx, int cy, const bool clippedToWorkArea) const throw() +const Rectangle Desktop::getMonitorAreaContaining (const Point& position, const bool clippedToWorkArea) const throw() { Rectangle best (getMainMonitorArea (clippedToWorkArea)); double bestDistance = 1.0e10; @@ -42074,11 +42027,10 @@ const Rectangle Desktop::getMonitorAreaContaining (int cx, int cy, const bo { const Rectangle rect (getDisplayMonitorCoordinates (i, clippedToWorkArea)); - if (rect.contains (cx, cy)) + if (rect.contains (position)) return rect; - const double distance = juce_hypot ((double) (rect.getCentreX() - cx), - (double) (rect.getCentreY() - cy)); + const double distance = rect.getCentre().getDistanceFrom (position); if (distance < bestDistance) { @@ -42100,18 +42052,15 @@ Component* Desktop::getComponent (const int index) const throw() return desktopComponents [index]; } -Component* Desktop::findComponentAt (const int screenX, - const int screenY) const +Component* Desktop::findComponentAt (const Point& screenPosition) const { for (int i = desktopComponents.size(); --i >= 0;) { Component* const c = desktopComponents.getUnchecked(i); + const Point relative (c->globalPositionToRelative (screenPosition)); - int x = screenX, y = screenY; - c->globalPositionToRelative (x, y); - - if (c->contains (x, y)) - return c->getComponentAt (x, y); + if (c->contains (relative.getX(), relative.getY())) + return c->getComponentAt (relative.getX(), relative.getY()); } return 0; @@ -42152,11 +42101,9 @@ void Desktop::componentBroughtToFront (Component* const c) throw() } } -void Desktop::getLastMouseDownPosition (int& x, int& y) throw() +const Point Desktop::getLastMouseDownPosition() throw() { - const Desktop& d = getInstance(); - x = d.mouseDowns[0].position.getX(); - y = d.mouseDowns[0].position.getY(); + return getInstance().mouseDowns[0].position; } int Desktop::getMouseButtonClickCounter() throw() @@ -42268,10 +42215,7 @@ void Desktop::handleAsyncUpdate() void Desktop::timerCallback() { - int x, y; - getMousePosition (x, y); - - if (lastFakeMouseMoveX != x || lastFakeMouseMoveY != y) + if (lastFakeMouseMove != getMousePosition()) sendMouseMove(); } @@ -42281,26 +42225,18 @@ void Desktop::sendMouseMove() { startTimer (20); - int x, y; - getMousePosition (x, y); - lastFakeMouseMoveX = x; - lastFakeMouseMoveY = y; + lastFakeMouseMove = getMousePosition(); - Component* const target = findComponentAt (x, y); + Component* const target = findComponentAt (lastFakeMouseMove); if (target != 0) { - target->globalPositionToRelative (x, y); - ComponentDeletionWatcher deletionChecker (target); + const Point pos (target->globalPositionToRelative (lastFakeMouseMove)); + const Time now (Time::getCurrentTime()); - const MouseEvent me (x, y, - ModifierKeys::getCurrentModifiers(), - target, - Time::getCurrentTime(), - x, y, - Time::getCurrentTime(), - 0, false); + const MouseEvent me (pos, ModifierKeys::getCurrentModifiers(), + target, now, pos, now, 0, false); for (int i = mouseListeners.size(); --i >= 0;) { @@ -42325,7 +42261,7 @@ void Desktop::resetTimer() throw() else startTimer (100); - getMousePosition (lastFakeMouseMoveX, lastFakeMouseMoveY); + lastFakeMouseMove = getMousePosition(); } extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars); @@ -42612,20 +42548,14 @@ Button::ButtonState Button::updateState (const MouseEvent* const e) if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent()) { - int mx, my; + Point mousePos; if (e == 0) - { - getMouseXYRelative (mx, my); - } + mousePos = getMouseXYRelative(); else - { - const MouseEvent e2 (e->getEventRelativeTo (this)); - mx = e2.x; - my = e2.y; - } + mousePos = e->getEventRelativeTo (this).getPosition(); - const bool over = reallyContains (mx, my, true); + const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true); const bool down = isMouseButtonDown(); if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown) @@ -48324,11 +48254,7 @@ void ListBox::mouseMove (const MouseEvent& e) if (mouseMoveSelects) { const MouseEvent e2 (e.getEventRelativeTo (this)); - selectRow (getRowContainingPosition (e2.x, e2.y), true); - - lastMouseX = e2.x; - lastMouseY = e2.y; } } @@ -48419,10 +48345,8 @@ Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY) if (rowComp != 0 && isRowSelected (firstRow + i)) { - int x = 0, y = 0; - rowComp->relativePositionToOtherComponent (this, x, y); - - const Rectangle rowRect (x, y, rowComp->getWidth(), rowComp->getHeight()); + const Point pos (rowComp->relativePositionToOtherComponent (this, Point())); + const Rectangle rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight()); if (imageArea.isEmpty()) imageArea = rowRect; @@ -48442,11 +48366,10 @@ Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY) if (rowComp != 0 && isRowSelected (firstRow + i)) { - int x = 0, y = 0; - rowComp->relativePositionToOtherComponent (this, x, y); + const Point pos (rowComp->relativePositionToOtherComponent (this, Point())); Graphics g (*snapshot); - g.setOrigin (x - imageX, y - imageY); + g.setOrigin (pos.getX() - imageX, pos.getY() - imageY); if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight())) rowComp->paintEntireComponent (g); } @@ -49726,34 +49649,32 @@ void Slider::restoreMouseIfHidden() if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag) { - int x, y, downX, downY; - Desktop::getMousePosition (x, y); - Desktop::getLastMouseDownPosition (downX, downY); + Point mousePos (Desktop::getMousePosition()); + const Point lastMouseDown (Desktop::getLastMouseDownPosition()); if (style == RotaryHorizontalDrag) { const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown); - x = roundToInt (pixelsForFullDragExtent * posDiff + downX); - y = downY; + mousePos = Point (roundToInt (pixelsForFullDragExtent * posDiff + lastMouseDown.getX()), + lastMouseDown.getY()); } else { const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos); - x = downX; - y = roundToInt (pixelsForFullDragExtent * posDiff + downY); + mousePos = Point (lastMouseDown.getX(), + roundToInt (pixelsForFullDragExtent * posDiff + lastMouseDown.getY())); } - Desktop::setMousePosition (x, y); + Desktop::setMousePosition (mousePos); } else { const int pixelPos = (int) getLinearSliderPos (pos); - int x = isHorizontal() ? pixelPos : (getWidth() / 2); - int y = isVertical() ? pixelPos : (getHeight() / 2); + const Point pos (isHorizontal() ? pixelPos : (getWidth() / 2), + isVertical() ? pixelPos : (getHeight() / 2)); - relativePositionToGlobal (x, y); - Desktop::setMousePosition (x, y); + Desktop::setMousePosition (relativePositionToGlobal (pos)); } } } @@ -50768,10 +50689,7 @@ void TableHeaderComponent::mouseUp (const MouseEvent& e) const MouseCursor TableHeaderComponent::getMouseCursor() { - int x, y; - getMouseXYRelative (x, y); - - if (columnIdBeingResized != 0 || (getResizeDraggerAt (x) != 0 && ! isMouseButtonDown())) + if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown())) return MouseCursor (MouseCursor::LeftRightResizeCursor); return Component::getMouseCursor(); @@ -51113,10 +51031,7 @@ public: const String getTooltip() { - int x, y; - getMouseXYRelative (x, y); - - const int columnId = owner.getHeader()->getColumnIdAtX (x); + const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX()); if (columnId != 0 && owner.getModel() != 0) return owner.getModel()->getCellTooltip (row, columnId); @@ -53512,8 +53427,7 @@ void TextEditor::focusGained (FocusChangeType) ComponentPeer* const peer = getPeer(); if (peer != 0 && ! isReadOnly()) - peer->textInputRequired (getScreenX() - peer->getScreenX(), - getScreenY() - peer->getScreenY()); + peer->textInputRequired (getScreenPosition() - peer->getScreenPosition()); } void TextEditor::focusLost (FocusChangeType) @@ -55462,11 +55376,8 @@ public: const String getTooltip() { - int x, y; - getMouseXYRelative (x, y); Rectangle pos; - - TreeViewItem* const item = findItemAt (y, pos); + TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos); if (item != 0) return item->getTooltip(); @@ -55707,10 +55618,8 @@ TreeViewItem* TreeView::getItemOnRow (int index) const TreeViewItem* TreeView::getItemAt (int y) const throw() { TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent(); - int x; - relativePositionToOtherComponent (tc, x, y); Rectangle pos; - return tc->findItemAt (y, pos); + return tc->findItemAt (relativePositionToOtherComponent (tc, Point (0, y)).getY(), pos); } TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const @@ -60858,8 +60767,7 @@ void ComponentBoundsConstrainer::setBoundsForComponent (Component* const compone if (peer != 0) border = peer->getFrameSize(); - limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentreX(), - bounds.getCentreY()); + limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre()); } else { @@ -61127,17 +61035,14 @@ void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMove if (wasMoved) { - int x = 0, y = 0; - component->relativePositionToOtherComponent (component->getTopLevelComponent(), x, y); + const Point pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point())); - wasMoved = (lastX != x || lastY != y); - lastX = x; - lastY = y; + wasMoved = lastBounds.getPosition() != pos; + lastBounds.setPosition (pos); } - wasResized = (lastWidth != component->getWidth() || lastHeight != component->getHeight()); - lastWidth = component->getWidth(); - lastHeight = component->getHeight(); + wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight()); + lastBounds.setSize (component->getWidth(), component->getHeight()); if (wasMoved || wasResized) componentMovedOrResized (wasMoved, wasResized); @@ -67885,9 +67790,8 @@ void MenuBarComponent::showMenu (int index) if (prevCompDeletionChecker != 0 && ! prevCompDeletionChecker->hasBeenDeleted()) prevFocused->grabKeyboardFocus(); - int mx, my; - getMouseXYRelative (mx, my); - updateItemUnderMouse (mx, my); + const Point mousePos (getMouseXYRelative()); + updateItemUnderMouse (mousePos.getX(), mousePos.getY()); repaint(); if (result != 0) @@ -67925,10 +67829,9 @@ void MenuBarComponent::mouseExit (const MouseEvent& e) void MenuBarComponent::mouseDown (const MouseEvent& e) { - const MouseEvent e2 (e.getEventRelativeTo (this)); - if (currentPopupIndex < 0) { + const MouseEvent e2 (e.getEventRelativeTo (this)); updateItemUnderMouse (e2.x, e2.y); currentPopupIndex = -2; @@ -68045,9 +67948,8 @@ void MenuBarComponent::timerCallback() { stopTimer(); - int mx, my; - getMouseXYRelative (mx, my); - updateItemUnderMouse (mx, my); + const Point mousePos (getMouseXYRelative()); + updateItemUnderMouse (mousePos.getX(), mousePos.getY()); } END_JUCE_NAMESPACE @@ -68360,8 +68262,6 @@ public: menuBarComponent (0), managerOfChosenCommand (0), componentAttachedTo (0), - lastMouseX (0), - lastMouseY (0), minimumWidth (0), maximumNumColumns (7), standardItemHeight (0), @@ -68576,7 +68476,7 @@ public: void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY) { alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone)); - lastMouseX = -1; + lastMouse = Point (-1, -1); } bool keyPressed (const KeyPress& key) @@ -68656,10 +68556,9 @@ public: // as they'll expect the menu to go away, and in fact it'll just // come back. So only dismiss synchronously if they're not on the original // comp that we're attached to. - int mx, my; - componentAttachedTo->getMouseXYRelative (mx, my); + const Point mousePos (componentAttachedTo->getMouseXYRelative()); - if (componentAttachedTo->reallyContains (mx, my, true)) + if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true)) { postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously return; @@ -68697,16 +68596,13 @@ public: startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse // move rather than a real timer callback - int mx, my; - Desktop::getMousePosition (mx, my); - - int x = mx, y = my; - globalPositionToRelative (x, y); + const Point globalMousePos (Desktop::getMousePosition()); + const Point localMousePos (globalPositionToRelative (globalMousePos)); const uint32 now = Time::getMillisecondCounter(); if (now > timeEnteredCurrentChildComp + 100 - && reallyContains (x, y, true) + && reallyContains (localMousePos.getX(), localMousePos.getY(), true) && currentChild->isValidComponent() && (! disableMouseMoves) && ! (activeSubMenu != 0 && activeSubMenu->isVisible())) @@ -68714,17 +68610,17 @@ public: showSubMenuFor (currentChild); } - if (mx != lastMouseX || my != lastMouseY || now > lastMouseMoveTime + 350) + if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350) { - highlightItemUnderMouse (mx, my, x, y); + highlightItemUnderMouse (globalMousePos, localMousePos); } bool overScrollArea = false; if (isScrolling() - && (isOver || (isDown && ((unsigned int) x) < (unsigned int) getWidth())) - && ((isScrollZoneActive (false) && y < PopupMenuSettings::scrollZone) - || (isScrollZoneActive (true) && y > getHeight() - PopupMenuSettings::scrollZone))) + && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth())) + && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone) + || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone))) { if (now > lastScroll + 20) { @@ -68734,13 +68630,13 @@ public: for (int i = 0; i < getNumChildComponents() && amount == 0; ++i) amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight(); - alterChildYPos (y < PopupMenuSettings::scrollZone ? -amount : amount); + alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount); lastScroll = now; } overScrollArea = true; - lastMouseX = -1; // trigger a mouse-move + lastMouse = Point (-1, -1); // trigger a mouse-move } else { @@ -68752,7 +68648,7 @@ public: if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0) { - activeSubMenu->updateMouseOverStatus (mx, my); + activeSubMenu->updateMouseOverStatus (globalMousePos); isOverAny = isOverAnyMenu(); } @@ -68798,7 +68694,7 @@ public: else if (wasDown && now > menuCreationTime + 250 && ! (isDown || overScrollArea)) { - isOver = reallyContains (x, y, true); + isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true); if (isOver) { @@ -68841,7 +68737,7 @@ private: Component* componentAttachedTo; ScopedPointer attachedCompWatcher; Rectangle windowPos; - int lastMouseX, lastMouseY; + Point lastMouse; int minimumWidth, maximumNumColumns, standardItemHeight; bool isOver, hasBeenOver, isDown, needsToScroll; bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus; @@ -68870,14 +68766,13 @@ private: && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren())); } - void updateMouseOverStatus (const int mx, const int my) + void updateMouseOverStatus (const Point& globalMousePos) { - int rx = mx, ry = my; - globalPositionToRelative (rx, ry); - isOver = reallyContains (rx, ry, true); + const Point relPos (globalPositionToRelative (globalMousePos)); + isOver = reallyContains (relPos.getX(), relPos.getY(), true); if (activeSubMenu != 0) - activeSubMenu->updateMouseOverStatus (mx, my); + activeSubMenu->updateMouseOverStatus (globalMousePos); } bool treeContains (const Window* const window) const throw() @@ -68903,8 +68798,8 @@ private: const bool alignToRectangle) { const Rectangle mon (Desktop::getInstance() - .getMonitorAreaContaining ((minX + maxX) / 2, - (minY + maxY) / 2, + .getMonitorAreaContaining (Point ((minX + maxX) / 2, + (minY + maxY) / 2), #if JUCE_MAC true)); #else @@ -69075,10 +68970,7 @@ private: windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())), currentY); - const Rectangle mon (Desktop::getInstance() - .getMonitorAreaContaining (windowPos.getX(), - windowPos.getY(), - true)); + const Rectangle mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true)); int deltaY = wantedY - currentY; @@ -69204,15 +69096,13 @@ private: if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu()) { - int left = 0, top = 0; - childComp->relativePositionToGlobal (left, top); - int right = childComp->getWidth(), bottom = childComp->getHeight(); - childComp->relativePositionToGlobal (right, bottom); + const Point topLeft (childComp->relativePositionToGlobal (Point())); + const Point bottomRight (childComp->relativePositionToGlobal (Point (childComp->getWidth(), childComp->getHeight()))); activeSubMenu = Window::create (*(childComp->itemInfo.subMenu), dismissOnMouseUp, this, - left, right, top, bottom, + topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(), 0, maximumNumColumns, standardItemHeight, false, 0, menuBarComponent, @@ -69231,14 +69121,14 @@ private: return false; } - void highlightItemUnderMouse (const int mx, const int my, const int x, const int y) + void highlightItemUnderMouse (const Point& globalMousePos, const Point& localMousePos) { - isOver = reallyContains (x, y, true); + isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true); if (isOver) hasBeenOver = true; - if (abs (lastMouseX - mx) > 2 || abs (lastMouseY - my) > 2) + if (lastMouse.getDistanceFrom (globalMousePos) > 2) { lastMouseMoveTime = Time::getApproximateMillisecondCounter(); @@ -69253,7 +69143,7 @@ private: jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent()) - if (isOver && (activeSubMenu != 0) && (mx != lastMouseX || my != lastMouseY)) + if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse) { // try to intelligently guess whether the user is moving the mouse towards a currently-open // submenu. To do this, look at whether the mouse stays inside a triangular region that @@ -69263,31 +69153,30 @@ private: if (activeSubMenu->getX() > getX()) { - lastMouseX -= 2; // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels + lastMouse -= Point (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels } else { - lastMouseX += 2; + lastMouse += Point (2, 0); subX += activeSubMenu->getWidth(); } Path areaTowardsSubMenu; - areaTowardsSubMenu.addTriangle ((float) lastMouseX, - (float) lastMouseY, + areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(), + (float) lastMouse.getY(), subX, (float) activeSubMenu->getScreenY(), subX, (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight())); - isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) mx, (float) my); + isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY()); } - lastMouseX = mx; - lastMouseY = my; + lastMouse = globalMousePos; if (! isMovingTowardsMenu) { - Component* c = getComponentAt (x, y); + Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY()); if (c == this) c = 0; @@ -69692,10 +69581,9 @@ int PopupMenu::show (const int itemIdThatMustBeVisible, const int maximumNumColumns, const int standardItemHeight) { - int x, y; - Desktop::getMousePosition (x, y); + const Point mousePos (Desktop::getMousePosition()); - return showAt (x, y, + return showAt (mousePos.getX(), mousePos.getY(), itemIdThatMustBeVisible, minimumWidth, maximumNumColumns, @@ -69893,9 +69781,7 @@ END_JUCE_NAMESPACE BEGIN_JUCE_NAMESPACE ComponentDragger::ComponentDragger() - : constrainer (0), - originalX (0), - originalY (0) + : constrainer (0) { } @@ -69911,9 +69797,7 @@ void ComponentDragger::startDraggingComponent (Component* const componentToDrag, if (componentToDrag->isValidComponent()) { constrainer = constrainer_; - originalX = 0; - originalY = 0; - componentToDrag->relativePositionToGlobal (originalX, originalY); + originalPos = componentToDrag->relativePositionToGlobal (Point()); } } @@ -69924,23 +69808,22 @@ void ComponentDragger::dragComponent (Component* const componentToDrag, const Mo if (componentToDrag->isValidComponent()) { - int x = originalX; - int y = originalY; + Point pos (originalPos); int w = componentToDrag->getWidth(); int h = componentToDrag->getHeight(); const Component* const parentComp = componentToDrag->getParentComponent(); if (parentComp != 0) - parentComp->globalPositionToRelative (x, y); + pos = parentComp->globalPositionToRelative (pos); - x += e.getDistanceFromDragStartX(); - y += e.getDistanceFromDragStartY(); + pos += Point (e.getDistanceFromDragStartX(), + e.getDistanceFromDragStartY()); if (constrainer != 0) - constrainer->setBoundsForComponent (componentToDrag, Rectangle (x, y, w, h), + constrainer->setBoundsForComponent (componentToDrag, Rectangle (pos.getX(), pos.getY(), w, h), false, false, false, false); else - componentToDrag->setBounds (x, y, w, h); + componentToDrag->setBounds (pos.getX(), pos.getY(), w, h); } } @@ -69967,7 +69850,7 @@ private: DragAndDropTarget* currentlyOver; String dragDesc; - const int imageX, imageY; + const Point imageOffset; bool hasCheckedForExternalDrag, drawImage; DragImageComponent (const DragImageComponent&); @@ -69978,14 +69861,13 @@ public: const String& desc, Component* const s, DragAndDropContainer* const o, - const int imageX_, const int imageY_) + const Point& imageOffset_) : image (im), source (s), owner (o), currentlyOver (0), dragDesc (desc), - imageX (imageX_), - imageY (imageY_), + imageOffset (imageOffset_), hasCheckedForExternalDrag (false), drawImage (true) { @@ -70034,21 +69916,19 @@ public: } } - DragAndDropTarget* findTarget (const int screenX, const int screenY, - int& relX, int& relY) const + DragAndDropTarget* findTarget (const Point& screenPos, + Point& relativePos) const { Component* hit = getParentComponent(); if (hit == 0) { - hit = Desktop::getInstance().findComponentAt (screenX, screenY); + hit = Desktop::getInstance().findComponentAt (screenPos); } else { - int rx = screenX, ry = screenY; - hit->globalPositionToRelative (rx, ry); - - hit = hit->getComponentAt (rx, ry); + const Point relPos (hit->globalPositionToRelative (screenPos)); + hit = hit->getComponentAt (relPos.getX(), relPos.getY()); } // (note: use a local copy of the dragDesc member in case the callback runs @@ -70061,9 +69941,7 @@ public: if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source)) { - relX = screenX; - relY = screenY; - hit->globalPositionToRelative (relX, relY); + relativePos = hit->globalPositionToRelative (screenPos); return ddt; } @@ -70082,14 +69960,12 @@ public: bool dropAccepted = false; DragAndDropTarget* ddt = 0; - int relX = 0, relY = 0; + Point relPos; if (isVisible()) { setVisible (false); - ddt = findTarget (e.getScreenX(), - e.getScreenY(), - relX, relY); + ddt = findTarget (e.getScreenPosition(), relPos); // fade this component and remove it - it'll be deleted later by the timer callback @@ -70103,17 +69979,15 @@ public: } else { - int targetX = source->getWidth() / 2; - int targetY = source->getHeight() / 2; - source->relativePositionToGlobal (targetX, targetY); + const Point target (source->relativePositionToGlobal (Point (source->getWidth() / 2, + source->getHeight() / 2))); - int ourCentreX = getWidth() / 2; - int ourCentreY = getHeight() / 2; - relativePositionToGlobal (ourCentreX, ourCentreY); + const Point ourCentre (relativePositionToGlobal (Point (getWidth() / 2, + getHeight() / 2))); fadeOutComponent (120, - targetX - ourCentreX, - targetY - ourCentreY); + target.getX() - ourCentre.getX(), + target.getY() - ourCentre.getY()); } } @@ -70129,31 +70003,30 @@ public: currentlyOverWatcher = 0; currentlyOver = 0; - ddt->itemDropped (dragDescLocal, source, relX, relY); + ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY()); } // careful - this object could now be deleted.. } } - void updateLocation (const bool canDoExternalDrag, int x, int y) + void updateLocation (const bool canDoExternalDrag, const Point& screenPos) { // (note: use a local copy of the dragDesc member in case the callback runs // a modal loop and deletes this object before it returns) const String dragDescLocal (dragDesc); - int newX = x + imageX; - int newY = y + imageY; + Point newPos (screenPos + imageOffset); if (getParentComponent() != 0) - getParentComponent()->globalPositionToRelative (newX, newY); + newPos = getParentComponent()->globalPositionToRelative (newPos); //if (newX != getX() || newY != getY()) { - setTopLeftPosition (newX, newY); + setTopLeftPosition (newPos.getX(), newPos.getY()); - int relX = 0, relY = 0; - DragAndDropTarget* const ddt = findTarget (x, y, relX, relY); + Point relPos; + DragAndDropTarget* const ddt = findTarget (screenPos, relPos); drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver(); @@ -70180,7 +70053,7 @@ public: currentlyOverWatcher = new ComponentDeletionWatcher (dynamic_cast (ddt)); if (currentlyOver->isInterestedInDragSource (dragDescLocal, source)) - currentlyOver->itemDragEnter (dragDescLocal, source, relX, relY); + currentlyOver->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY()); } } else if (currentlyOverWatcher != 0 && currentlyOverWatcher->hasBeenDeleted()) @@ -70191,13 +70064,13 @@ public: if (currentlyOver != 0 && currentlyOver->isInterestedInDragSource (dragDescLocal, source)) - currentlyOver->itemDragMove (dragDescLocal, source, relX, relY); + currentlyOver->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY()); if (currentlyOver == 0 && canDoExternalDrag && ! hasCheckedForExternalDrag) { - if (Desktop::getInstance().findComponentAt (x, y) == 0) + if (Desktop::getInstance().findComponentAt (screenPos) == 0) { hasCheckedForExternalDrag = true; StringArray files; @@ -70225,7 +70098,7 @@ public: void mouseDrag (const MouseEvent& e) { if (e.originalComponent != this) - updateLocation (true, e.getScreenX(), e.getScreenY()); + updateLocation (true, e.getScreenPosition()); } void timerCallback() @@ -70267,9 +70140,8 @@ void DragAndDropContainer::startDragging (const String& sourceDescription, if (thisComp != 0) { - int mx, my; - Desktop::getLastMouseDownPosition (mx, my); - int imageX = 0, imageY = 0; + const Point lastMouseDown (Desktop::getLastMouseDownPosition()); + Point imageOffset; if (dragImage == 0) { @@ -70289,18 +70161,17 @@ void DragAndDropContainer::startDragging (const String& sourceDescription, const int lo = 150; const int hi = 400; - int rx = mx, ry = my; - sourceComponent->globalPositionToRelative (rx, ry); - const int cx = jlimit (0, dragImage->getWidth(), rx); - const int cy = jlimit (0, dragImage->getHeight(), ry); + Point relPos (sourceComponent->globalPositionToRelative (lastMouseDown)); + Point clipped (Rectangle (0, 0, dragImage->getWidth(), dragImage->getHeight()) + .getConstrainedPoint (relPos)); for (int y = dragImage->getHeight(); --y >= 0;) { - const double dy = (y - cy) * (y - cy); + const double dy = (y - clipped.getY()) * (y - clipped.getY()); for (int x = dragImage->getWidth(); --x >= 0;) { - const int dx = x - cx; + const int dx = x - clipped.getX(); const int distance = roundToInt (sqrt (dx * dx + dy)); if (distance > lo) @@ -70314,25 +70185,19 @@ void DragAndDropContainer::startDragging (const String& sourceDescription, } } - imageX = -cx; - imageY = -cy; + imageOffset = Point() - clipped; } else { if (imageOffsetFromMouse == 0) - { - imageX = dragImage->getWidth() / -2; - imageY = dragImage->getHeight() / -2; - } + imageOffset = Point (dragImage->getWidth() / -2, + dragImage->getHeight() / -2); else - { - imageX = imageOffsetFromMouse->getX(); - imageY = imageOffsetFromMouse->getY(); - } + imageOffset = *imageOffsetFromMouse; } dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent, - this, imageX, imageY); + this, imageOffset); currentDragDesc = sourceDescription; @@ -70348,7 +70213,7 @@ void DragAndDropContainer::startDragging (const String& sourceDescription, else thisComp->addChildComponent (dragImageComponent); - ((DragImageComponent*) dragImageComponent)->updateLocation (false, mx, my); + ((DragImageComponent*) dragImageComponent)->updateLocation (false, lastMouseDown); dragImageComponent->setVisible (true); } else @@ -70552,24 +70417,21 @@ END_JUCE_NAMESPACE /*** Start of inlined file: juce_MouseEvent.cpp ***/ BEGIN_JUCE_NAMESPACE -MouseEvent::MouseEvent (const int x_, - const int y_, +MouseEvent::MouseEvent (const Point& position, const ModifierKeys& mods_, Component* const originator, const Time& eventTime_, - const int mouseDownX_, - const int mouseDownY_, + const Point mouseDownPos_, const Time& mouseDownTime_, const int numberOfClicks_, const bool mouseWasDragged) throw() - : x (x_), - y (y_), + : x (position.getX()), + y (position.getY()), mods (mods_), eventComponent (originator), originalComponent (originator), eventTime (eventTime_), - mouseDownX (mouseDownX_), - mouseDownY (mouseDownY_), + mouseDownPos (mouseDownPos_), mouseDownTime (mouseDownTime_), numberOfClicks (numberOfClicks_), wasMovedSinceMouseDown (mouseWasDragged) @@ -70587,22 +70449,27 @@ bool MouseEvent::mouseWasClicked() const throw() int MouseEvent::getMouseDownX() const throw() { - return mouseDownX; + return mouseDownPos.getX(); } int MouseEvent::getMouseDownY() const throw() { - return mouseDownY; + return mouseDownPos.getY(); +} + +const Point MouseEvent::getMouseDownPosition() const throw() +{ + return mouseDownPos; } int MouseEvent::getDistanceFromDragStartX() const throw() { - return x - mouseDownX; + return x - mouseDownPos.getX(); } int MouseEvent::getDistanceFromDragStartY() const throw() { - return y - mouseDownY; + return y - mouseDownPos.getY(); } int MouseEvent::getDistanceFromDragStart() const throw() @@ -70619,32 +70486,39 @@ int MouseEvent::getLengthOfMousePress() const throw() return 0; } -int MouseEvent::getScreenX() const throw() +const Point MouseEvent::getPosition() const throw() +{ + return Point (x, y); +} + +int MouseEvent::getScreenX() const { - int sx = x, sy = y; - eventComponent->relativePositionToGlobal (sx, sy); - return sx; + return getScreenPosition().getX(); } -int MouseEvent::getScreenY() const throw() +int MouseEvent::getScreenY() const { - int sx = x, sy = y; - eventComponent->relativePositionToGlobal (sx, sy); - return sy; + return getScreenPosition().getY(); } -int MouseEvent::getMouseDownScreenX() const throw() +const Point MouseEvent::getScreenPosition() const { - int sx = mouseDownX, sy = mouseDownY; - eventComponent->relativePositionToGlobal (sx, sy); - return sx; + return eventComponent->relativePositionToGlobal (Point (x, y)); } -int MouseEvent::getMouseDownScreenY() const throw() +int MouseEvent::getMouseDownScreenX() const { - int sx = mouseDownX, sy = mouseDownY; - eventComponent->relativePositionToGlobal (sx, sy); - return sy; + return getMouseDownScreenPosition().getX(); +} + +int MouseEvent::getMouseDownScreenY() const +{ + return getMouseDownScreenPosition().getY(); +} + +const Point MouseEvent::getMouseDownScreenPosition() const +{ + return eventComponent->relativePositionToGlobal (mouseDownPos); } const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw() @@ -70655,13 +70529,14 @@ const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent return *this; } - MouseEvent me (*this); - - eventComponent->relativePositionToOtherComponent (otherComponent, me.x, me.y); - eventComponent->relativePositionToOtherComponent (otherComponent, me.mouseDownX, me.mouseDownY); - me.eventComponent = otherComponent; - - return me; + return MouseEvent (eventComponent->relativePositionToOtherComponent (otherComponent, Point (x, y)), + mods, + originalComponent, + eventTime, + eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos), + mouseDownTime, + numberOfClicks, + wasMovedSinceMouseDown); } static int doubleClickTimeOutMs = 400; @@ -70729,13 +70604,12 @@ void MouseHoverDetector::hoverTimerCallback() if (source != 0) { - int mx, my; - source->getMouseXYRelative (mx, my); + const Point pos (source->getMouseXYRelative()); - if (source->reallyContains (mx, my, false)) + if (source->reallyContains (pos.getX(), pos.getY(), false)) { hasJustHovered = true; - mouseHovered (mx, my); + mouseHovered (pos.getX(), pos.getY()); } } } @@ -72837,15 +72711,14 @@ void BubbleComponent::setPosition (Component* componentToPointTo) { jassert (componentToPointTo->isValidComponent()); - int tx = 0; - int ty = 0; + Point pos; if (getParentComponent() != 0) - componentToPointTo->relativePositionToOtherComponent (getParentComponent(), tx, ty); + pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos); else - componentToPointTo->relativePositionToGlobal (tx, ty); + pos = componentToPointTo->relativePositionToGlobal (pos); - setPosition (Rectangle (tx, ty, componentToPointTo->getWidth(), componentToPointTo->getHeight())); + setPosition (Rectangle (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight())); } void BubbleComponent::setPosition (const int arrowTipX_, @@ -74024,11 +73897,11 @@ public: peer->grabFocus(); } - void textInputRequired (int x, int y) + void textInputRequired (const Point& position) { ComponentPeer* peer = magnifierComp->getPeer(); if (peer != 0) - peer->textInputRequired (x, y); + peer->textInputRequired (position); } void getBounds (int& x, int& y, int& w, int& h) const @@ -74039,25 +73912,25 @@ public: h = component->getHeight(); } - int getScreenX() const { return magnifierComp->getScreenX(); } - int getScreenY() const { return magnifierComp->getScreenY(); } + const Point getScreenPosition() const + { + return magnifierComp->getScreenPosition(); + } - void relativePositionToGlobal (int& x, int& y) + const Point relativePositionToGlobal (const Point& relativePosition) { const double zoom = magnifierComp->getScaleFactor(); - x = roundToInt (x * zoom); - y = roundToInt (y * zoom); - - magnifierComp->relativePositionToGlobal (x, y); + return magnifierComp->relativePositionToGlobal (Point (roundToInt (relativePosition.getX() * zoom), + roundToInt (relativePosition.getY() * zoom))); } - void globalPositionToRelative (int& x, int& y) + const Point globalPositionToRelative (const Point& screenPosition) { - magnifierComp->globalPositionToRelative (x, y); - + const Point p (magnifierComp->globalPositionToRelative (screenPosition)); const double zoom = magnifierComp->getScaleFactor(); - x = roundToInt (x / zoom); - y = roundToInt (y / zoom); + + return Point (roundToInt (p.getX() / zoom), + roundToInt (p.getY() / zoom)); } bool contains (int x, int y, bool) const @@ -74504,27 +74377,29 @@ int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 }; static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 }; -int MidiKeyboardComponent::xyToNote (int x, int y, float& mousePositionVelocity) +int MidiKeyboardComponent::xyToNote (const Point& pos, float& mousePositionVelocity) { - if (! reallyContains (x, y, false)) + if (! reallyContains (pos.getX(), pos.getY(), false)) return -1; + Point p (pos); + if (orientation != horizontalKeyboard) { - swapVariables (x, y); + p = Point (p.getY(), p.getX()); if (orientation == verticalKeyboardFacingLeft) - y = getWidth() - y; + p = Point (p.getX(), getWidth() - p.getY()); else - x = getHeight() - x; + p = Point (getHeight() - p.getX(), p.getY()); } - return remappedXYToNote (x + xOffset, y, mousePositionVelocity); + return remappedXYToNote (p + Point (xOffset, 0), mousePositionVelocity); } -int MidiKeyboardComponent::remappedXYToNote (int x, int y, float& mousePositionVelocity) const +int MidiKeyboardComponent::remappedXYToNote (const Point& pos, float& mousePositionVelocity) const { - if (y < blackNoteLength) + if (pos.getY() < blackNoteLength) { for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12) { @@ -74538,9 +74413,9 @@ int MidiKeyboardComponent::remappedXYToNote (int x, int y, float& mousePositionV getKeyPos (note, kx, kw); kx += xOffset; - if (x >= kx && x < kx + kw) + if (pos.getX() >= kx && pos.getX() < kx + kw) { - mousePositionVelocity = y / (float) blackNoteLength; + mousePositionVelocity = pos.getY() / (float) blackNoteLength; return note; } } @@ -74560,10 +74435,10 @@ int MidiKeyboardComponent::remappedXYToNote (int x, int y, float& mousePositionV getKeyPos (note, kx, kw); kx += xOffset; - if (x >= kx && x < kx + kw) + if (pos.getX() >= kx && pos.getX() < kx + kw) { const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth(); - mousePositionVelocity = y / (float) whiteNoteLength; + mousePositionVelocity = pos.getY() / (float) whiteNoteLength; return note; } } @@ -74895,7 +74770,7 @@ void MidiKeyboardComponent::resized() float mousePositionVelocity; const int spaceAvailable = w - scrollButtonW * 2; - const int lastStartKey = remappedXYToNote (endOfLastKey - spaceAvailable, 0, mousePositionVelocity) + 1; + const int lastStartKey = remappedXYToNote (Point (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1; if (lastStartKey >= 0 && firstKey > lastStartKey) { @@ -74949,11 +74824,11 @@ void MidiKeyboardComponent::resetAnyKeysInUse() } } -void MidiKeyboardComponent::updateNoteUnderMouse (int x, int y) +void MidiKeyboardComponent::updateNoteUnderMouse (const Point& pos) { float mousePositionVelocity = 0.0f; const int newNote = (mouseDragging || isMouseOver()) - ? xyToNote (x, y, mousePositionVelocity) : -1; + ? xyToNote (pos, mousePositionVelocity) : -1; if (noteUnderMouse != newNote) { @@ -74985,19 +74860,19 @@ void MidiKeyboardComponent::updateNoteUnderMouse (int x, int y) void MidiKeyboardComponent::mouseMove (const MouseEvent& e) { - updateNoteUnderMouse (e.x, e.y); + updateNoteUnderMouse (e.getPosition()); stopTimer(); } void MidiKeyboardComponent::mouseDrag (const MouseEvent& e) { float mousePositionVelocity; - const int newNote = xyToNote (e.x, e.y, mousePositionVelocity); + const int newNote = xyToNote (e.getPosition(), mousePositionVelocity); if (newNote >= 0) mouseDraggedToKey (newNote, e); - updateNoteUnderMouse (e.x, e.y); + updateNoteUnderMouse (e.getPosition()); } bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&) @@ -75012,7 +74887,7 @@ void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const Mou void MidiKeyboardComponent::mouseDown (const MouseEvent& e) { float mousePositionVelocity; - const int newNote = xyToNote (e.x, e.y, mousePositionVelocity); + const int newNote = xyToNote (e.getPosition(), mousePositionVelocity); mouseDragging = false; if (newNote >= 0 && mouseDownOnKey (newNote, e)) @@ -75021,7 +74896,7 @@ void MidiKeyboardComponent::mouseDown (const MouseEvent& e) noteUnderMouse = -1; mouseDragging = true; - updateNoteUnderMouse (e.x, e.y); + updateNoteUnderMouse (e.getPosition()); startTimer (500); } } @@ -75029,19 +74904,19 @@ void MidiKeyboardComponent::mouseDown (const MouseEvent& e) void MidiKeyboardComponent::mouseUp (const MouseEvent& e) { mouseDragging = false; - updateNoteUnderMouse (e.x, e.y); + updateNoteUnderMouse (e.getPosition()); stopTimer(); } void MidiKeyboardComponent::mouseEnter (const MouseEvent& e) { - updateNoteUnderMouse (e.x, e.y); + updateNoteUnderMouse (e.getPosition()); } void MidiKeyboardComponent::mouseExit (const MouseEvent& e) { - updateNoteUnderMouse (e.x, e.y); + updateNoteUnderMouse (e.getPosition()); } void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy) @@ -75051,10 +74926,7 @@ void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float i void MidiKeyboardComponent::timerCallback() { - int mx, my; - getMouseXYRelative (mx, my); - - updateNoteUnderMouse (mx, my); + updateNoteUnderMouse (getMouseXYRelative()); } void MidiKeyboardComponent::clearKeyMappings() @@ -75353,9 +75225,8 @@ void OpenGLComponent::paint (Graphics&) if (peer != 0) { - peer->addMaskedRegion (getScreenX() - peer->getScreenX(), - getScreenY() - peer->getScreenY(), - getWidth(), getHeight()); + const Point topLeft (getScreenPosition() - peer->getScreenPosition()); + peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight()); } } } @@ -76302,24 +76173,22 @@ void ComponentPeer::handleMouseEnter (int x, int y, const int64 time) { jassert (Component::componentUnderMouse->isValidComponent()); - const int oldX = x; - const int oldY = y; - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseExit (x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time); Component::componentUnderMouse = 0; if (deletionChecker.hasBeenDeleted()) return; - c = component->getComponentAt (oldX, oldY); + c = component->getComponentAt (x, y); } Component::componentUnderMouse = c; if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseEnter (x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseEnter (relPos.getX(), relPos.getY(), time); } } @@ -76335,16 +76204,10 @@ void ComponentPeer::handleMouseMove (int x, int y, const int64 time) if (c != Component::componentUnderMouse) { - const int oldX = x; - const int oldY = y; - if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseExit (x, y, time); - x = oldX; - y = oldY; - + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time); Component::componentUnderMouse = 0; if (deletionChecker.hasBeenDeleted()) @@ -76357,10 +76220,8 @@ void ComponentPeer::handleMouseMove (int x, int y, const int64 time) if (c != 0) { - component->relativePositionToOtherComponent (c, x, y); - c->internalMouseEnter (x, y, time); - x = oldX; - y = oldY; + const Point relPos (component->relativePositionToOtherComponent (c, Point (x, y))); + c->internalMouseEnter (relPos.getX(), relPos.getY(), time); if (deletionChecker.hasBeenDeleted()) return; // if this window has just been deleted.. @@ -76369,8 +76230,8 @@ void ComponentPeer::handleMouseMove (int x, int y, const int64 time) if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseMove (x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseMove (relPos.getX(), relPos.getY(), time); } } @@ -76385,8 +76246,8 @@ void ComponentPeer::handleMouseDown (int x, int y, const int64 time) if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseDown (x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseDown (relPos.getX(), relPos.getY(), time); } } } @@ -76397,8 +76258,8 @@ void ComponentPeer::handleMouseDrag (int x, int y, const int64 time) if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseDrag (x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseDrag (relPos.getX(), relPos.getY(), time); } } @@ -76413,39 +76274,34 @@ void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const i if (c != Component::componentUnderMouse) { - const int oldX = x; - const int oldY = y; - if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time); - x = oldX; - y = oldY; + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseUp (oldModifiers, relPos.getX(), relPos.getY(), time); if (Component::componentUnderMouse != 0) - Component::componentUnderMouse->internalMouseExit (x, y, time); + Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time); if (deletionChecker.hasBeenDeleted()) return; - c = component->getComponentAt (oldX, oldY); + c = component->getComponentAt (x, y); } Component::componentUnderMouse = c; if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseEnter (x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseEnter (relPos.getX(), relPos.getY(), time); } } else { if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseUp (oldModifiers, relPos.getX(), relPos.getY(), time); } } } @@ -76458,9 +76314,8 @@ void ComponentPeer::handleMouseExit (int x, int y, const int64 time) if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - - Component::componentUnderMouse->internalMouseExit (x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time); Component::componentUnderMouse = 0; } } @@ -76487,14 +76342,13 @@ void ComponentPeer::sendFakeMouseMove() throw() component->bounds_.setBounds (realX, realY, realW, realH); } - int x, y; - component->getMouseXYRelative (x, y); + const Point pos (component->getMouseXYRelative()); - if (((unsigned int) x) < (unsigned int) component->getWidth() - && ((unsigned int) y) < (unsigned int) component->getHeight() - && contains (x, y, false)) + if (((unsigned int) pos.getX()) < (unsigned int) component->getWidth() + && ((unsigned int) pos.getY()) < (unsigned int) component->getHeight() + && contains (pos.getX(), pos.getY(), false)) { - postMessage (new Message (fakeMouseMoveMessage, x, y, 0)); + postMessage (new Message (fakeMouseMoveMessage, pos.getX(), pos.getY(), 0)); } fakeMouseMessageSent = true; @@ -76823,11 +76677,10 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y) if (newTarget != 0) { Component* const targetComp = dynamic_cast (newTarget); - int mx = x, my = y; - component->relativePositionToOtherComponent (targetComp, mx, my); + const Point pos (component->relativePositionToOtherComponent (targetComp, Point (x, y))); dragAndDropTargetComponent = new ComponentDeletionWatcher (dynamic_cast (newTarget)); - newTarget->fileDragEnter (files, mx, my); + newTarget->fileDragEnter (files, pos.getX(), pos.getY()); } } } @@ -76839,9 +76692,9 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y) if (newTarget != 0) { Component* const targetComp = dynamic_cast (newTarget); - component->relativePositionToOtherComponent (targetComp, x, y); + const Point pos (component->relativePositionToOtherComponent (targetComp, Point (x, y))); - newTarget->fileDragMove (files, x, y); + newTarget->fileDragMove (files, pos.getX(), pos.getY()); } } @@ -76876,8 +76729,8 @@ void ComponentPeer::handleFileDragDrop (const StringArray& files, int x, int y) return; } - component->relativePositionToOtherComponent (targetComp, x, y); - target->filesDropped (files, x, y); + const Point pos (component->relativePositionToOtherComponent (targetComp, Point (x, y))); + target->filesDropped (files, pos.getX(), pos.getY()); } } } @@ -77798,8 +77651,7 @@ bool ResizableWindow::restoreWindowStateFromString (const String& s) if (newPos.isEmpty()) return false; - const Rectangle screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentreX(), - newPos.getCentreY())); + const Rectangle screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre())); ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0; if (peer != 0) @@ -78053,8 +77905,6 @@ TooltipWindow::TooltipWindow (Component* const parentComponent, const int millisecondsBeforeTipAppears_) : Component ("tooltip"), millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_), - mouseX (0), - mouseY (0), lastHideTime (0), lastComponentUnderMouse (0), changedCompsSinceShown (true) @@ -78093,24 +77943,23 @@ void TooltipWindow::showFor (const String& tip) jassert (tip.isNotEmpty()); tipShowing = tip; - int mx, my; - Desktop::getMousePosition (mx, my); + Point mousePos (Desktop::getMousePosition()); if (getParentComponent() != 0) - getParentComponent()->globalPositionToRelative (mx, my); + mousePos = getParentComponent()->globalPositionToRelative (mousePos); int x, y, w, h; getLookAndFeel().getTooltipSize (tip, w, h); - if (mx > getParentWidth() / 2) - x = mx - (w + 12); + if (mousePos.getX() > getParentWidth() / 2) + x = mousePos.getX() - (w + 12); else - x = mx + 24; + x = mousePos.getX() + 24; - if (my > getParentHeight() / 2) - y = my - (h + 6); + if (mousePos.getY() > getParentHeight() / 2) + y = mousePos.getY() - (h + 6); else - y = my + 6; + y = mousePos.getY() + 6; setBounds (x, y, w, h); setVisible (true); @@ -78161,11 +78010,9 @@ void TooltipWindow::timerCallback() const bool mouseWasClicked = clickCount > mouseClicks; mouseClicks = clickCount; - int mx, my; - Desktop::getMousePosition (mx, my); - const bool mouseMovedQuickly = (abs (mx - mouseX) + abs (my - mouseY) > 12); - mouseX = mx; - mouseY = my; + const Point mousePos (Desktop::getMousePosition()); + const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12; + lastMousePos = mousePos; if (tipChanged || mouseWasClicked || mouseMovedQuickly) lastCompChangeTime = now; @@ -78456,22 +78303,21 @@ void TopLevelWindow::centreAroundComponent (Component* c, const int width, const } else { - int x = (c->getWidth() - width) / 2; - int y = (c->getHeight() - height) / 2; - c->relativePositionToGlobal (x, y); + Point p (c->relativePositionToGlobal (Point ((c->getWidth() - width) / 2, + (c->getHeight() - height) / 2))); Rectangle parentArea (c->getParentMonitorArea()); if (getParentComponent() != 0) { - getParentComponent()->globalPositionToRelative (x, y); + p = getParentComponent()->globalPositionToRelative (p); parentArea.setBounds (0, 0, getParentWidth(), getParentHeight()); } parentArea.reduce (12, 12); - setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), x), - jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), y), + setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()), + jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()), width, height); } } @@ -214943,36 +214789,22 @@ public: h -= windowBorder.getTopAndBottom(); } - int getScreenX() const + const Point getScreenPosition() const { RECT r; GetWindowRect (hwnd, &r); - return r.left + windowBorder.getLeft(); + return Point (r.left + windowBorder.getLeft(), + r.top + windowBorder.getTop()); } - int getScreenY() const + const Point relativePositionToGlobal (const Point& relativePosition) { - RECT r; - GetWindowRect (hwnd, &r); - return r.top + windowBorder.getTop(); - } - - void relativePositionToGlobal (int& x, int& y) - { - RECT r; - GetWindowRect (hwnd, &r); - - x += r.left + windowBorder.getLeft(); - y += r.top + windowBorder.getTop(); + return relativePosition + getScreenPosition(); } - void globalPositionToRelative (int& x, int& y) + const Point globalPositionToRelative (const Point& screenPosition) { - RECT r; - GetWindowRect (hwnd, &r); - - x -= r.left + windowBorder.getLeft(); - y -= r.top + windowBorder.getTop(); + return screenPosition - getScreenPosition(); } void setMinimised (bool shouldBeMinimised) @@ -215132,7 +214964,7 @@ public: shouldDeactivateTitleBar = oldDeactivate; } - void textInputRequired (int /*x*/, int /*y*/) + void textInputRequired (const Point&) { if (! hasCreatedCaret) { @@ -216031,9 +215863,8 @@ private: HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect) { updateFileList (pDataObject); - int x = mousePos.x, y = mousePos.y; - owner->globalPositionToRelative (x, y); - owner->handleFileDragMove (files, x, y); + const Point pos (owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); + owner->handleFileDragMove (files, pos.getX(), pos.getY()); *pdwEffect = DROPEFFECT_COPY; return S_OK; } @@ -216046,9 +215877,8 @@ private: HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect) { - int x = mousePos.x, y = mousePos.y; - owner->globalPositionToRelative (x, y); - owner->handleFileDragMove (files, x, y); + const Point pos (owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); + owner->handleFileDragMove (files, pos.getX(), pos.getY()); *pdwEffect = DROPEFFECT_COPY; return S_OK; } @@ -216056,9 +215886,8 @@ private: HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect) { updateFileList (pDataObject); - int x = mousePos.x, y = mousePos.y; - owner->globalPositionToRelative (x, y); - owner->handleFileDragDrop (files, x, y); + const Point pos (owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); + owner->handleFileDragDrop (files, pos.getX(), pos.getY()); *pdwEffect = DROPEFFECT_COPY; return S_OK; } @@ -216335,9 +216164,8 @@ private: if (LOWORD (wParam) == WA_CLICKACTIVE && component->isCurrentlyBlockedByAnotherModalComponent()) { - int mx, my; - component->getMouseXYRelative (mx, my); - Component* const underMouse = component->getComponentAt (mx, my); + const Point mousePos (component->getMouseXYRelative()); + Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY()); if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent()) Component::getCurrentlyModalComponent()->inputAttemptWhenModal(); @@ -216405,8 +216233,8 @@ private: { const int oldModifiers = currentModifiers; - MouseEvent e (0, 0, ModifierKeys::getCurrentModifiersRealtime(), component, - getMouseEventTime(), 0, 0, getMouseEventTime(), 1, false); + MouseEvent e (Point(), ModifierKeys::getCurrentModifiersRealtime(), component, + getMouseEventTime(), Point(), getMouseEventTime(), 1, false); if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK) e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::leftButtonModifier); @@ -216646,17 +216474,16 @@ bool AlertWindow::showNativeDialogBox (const String& title, : MB_OK)) == IDOK; } -void Desktop::getMousePosition (int& x, int& y) throw() +const Point Desktop::getMousePosition() { POINT mousePos; GetCursorPos (&mousePos); - x = mousePos.x; - y = mousePos.y; + return Point (mousePos.x, mousePos.y); } -void Desktop::setMousePosition (int x, int y) throw() +void Desktop::setMousePosition (const Point& newPosition) { - SetCursorPos (x, y); + SetCursorPos (newPosition.getX(), newPosition.getY()); } Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage) @@ -218402,10 +218229,9 @@ public: if (topComp->getPeer() != 0) { - int x = 0, y = 0; - owner->relativePositionToOtherComponent (topComp, x, y); + const Point pos (owner->relativePositionToOtherComponent (topComp, Point())); - owner->setControlBounds (Rectangle (x, y, owner->getWidth(), owner->getHeight())); + owner->setControlBounds (Rectangle (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight())); } } @@ -218567,9 +218393,7 @@ bool ActiveXControlComponent::createControl (const void* controlIID) if (dynamic_cast (peer) != 0) { - int x = 0, y = 0; - relativePositionToOtherComponent (getTopLevelComponent(), x, y); - + const Point pos (relativePositionToOtherComponent (getTopLevelComponent(), Point())); HWND hwnd = (HWND) peer->getNativeHandle(); ScopedPointer info (new ActiveXControlData (hwnd, this)); @@ -218584,15 +218408,15 @@ bool ActiveXControlComponent::createControl (const void* controlIID) if (OleSetContainedObject (info->control, TRUE) == S_OK) { RECT rect; - rect.left = x; - rect.top = y; - rect.right = x + getWidth(); - rect.bottom = y + getHeight(); + rect.left = pos.getX(); + rect.top = pos.getY(); + rect.right = pos.getX() + getWidth(); + rect.bottom = pos.getY() + getHeight(); if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK) { control = info.release(); - setControlBounds (Rectangle (x, y, getWidth(), getHeight())); + setControlBounds (Rectangle (pos.getX(), pos.getY(), getWidth(), getHeight())); ((ActiveXControlData*) control)->controlHWND = getHWND (this); @@ -231674,7 +231498,7 @@ static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | Butto | ExposureMask | StructureNotifyMask | FocusChangeMask; static int pointerMap[5]; -static int lastMousePosX = 0, lastMousePosY = 0; +static Point lastMousePos; enum MouseButtons { @@ -232343,26 +232167,19 @@ public: h = wh; } - int getScreenX() const + const Point getScreenPosition() const { - return wx; + return Point (wx, wy); } - int getScreenY() const + const Point relativePositionToGlobal (const Point& relativePosition) { - return wy; + return relativePosition + getScreenPosition(); } - void relativePositionToGlobal (int& x, int& y) + const Point globalPositionToRelative (const Point& screenPosition) { - x += wx; - y += wy; - } - - void globalPositionToRelative (int& x, int& y) - { - x -= wx; - y -= wy; + return screenPosition - getScreenPosition(); } void setMinimised (bool shouldBeMinimised) @@ -232645,7 +232462,7 @@ public: } } - void textInputRequired (int /*x*/, int /*y*/) + void textInputRequired (const Point&) { } @@ -232905,7 +232722,7 @@ public: getEventTime (buttonPressEvent->time)); } - lastMousePosX = lastMousePosY = 0x100000; + lastMousePos = Point (0x100000, 0x100000); break; } @@ -232929,7 +232746,7 @@ public: buttonRelEvent->x, buttonRelEvent->y, getEventTime (buttonRelEvent->time)); - lastMousePosX = lastMousePosY = 0x100000; + lastMousePos = Point (0x100000, 0x100000); break; } @@ -232939,13 +232756,11 @@ public: updateKeyModifiers (movedEvent->state); - int x, y, mouseMods; - getMousePos (x, y, mouseMods); + Point mousePos (Desktop::getMousePosition()); - if (lastMousePosX != x || lastMousePosY != y) + if (lastMousePos != mousePos) { - lastMousePosX = x; - lastMousePosY = y; + lastMousePos = mousePos; if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0) { @@ -232964,26 +232779,23 @@ public: { parentWindow = wParent; updateBounds(); - x -= getScreenX(); - y -= getScreenY(); + mousePos -= getScreenPosition(); } else { parentWindow = 0; - x -= getScreenX(); - y -= getScreenY(); + mousePos -= getScreenPosition(); } } else { - x -= getScreenX(); - y -= getScreenY(); + mousePos -= getScreenPosition(); } if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0) - handleMouseMove (x, y, getEventTime (movedEvent->time)); + handleMouseMove (mousePos.getX(), mousePos.getY(), getEventTime (movedEvent->time)); else - handleMouseDrag (x, y, getEventTime (movedEvent->time)); + handleMouseDrag (mousePos.getX(), mousePos.getY(), getEventTime (movedEvent->time)); } break; @@ -232991,7 +232803,7 @@ public: case EnterNotify: { - lastMousePosX = lastMousePosY = 0x100000; + lastMousePos = Point (0x100000, 0x100000); const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing; if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0 @@ -233885,7 +233697,7 @@ private: void resetDragAndDrop() { dragAndDropFiles.clear(); - lastDropX = lastDropY = -1; + lastDropPos = Point (-1, -1); dragAndDropCurrentMimeType = 0; dragAndDropSourceWindow = 0; srcMimeTypeAtomList.clear(); @@ -233950,14 +233762,13 @@ private: dragAndDropSourceWindow = clientMsg->data.l[0]; - const int dropX = ((int) clientMsg->data.l[2] >> 16) - getScreenX(); - const int dropY = ((int) clientMsg->data.l[2] & 0xffff) - getScreenY(); + Point dropPos ((int) clientMsg->data.l[2] >> 16, + (int) clientMsg->data.l[2] & 0xffff); + dropPos -= getScreenPosition(); - if (lastDropX != dropX || lastDropY != dropY) + if (lastDropPos != dropPos) { - lastDropX = dropX; - lastDropY = dropY; - + lastDropPos = dropPos; dragAndDropTimestamp = clientMsg->data.l[3]; Atom targetAction = XA_XdndActionCopy; @@ -233977,7 +233788,7 @@ private: updateDraggedFileList (clientMsg); if (dragAndDropFiles.size() > 0) - handleFileDragMove (dragAndDropFiles, dropX, dropY); + handleFileDragMove (dragAndDropFiles, dropPos.getX(), dropPos.getY()); } } @@ -233987,13 +233798,13 @@ private: updateDraggedFileList (clientMsg); const StringArray files (dragAndDropFiles); - const int lastX = lastDropX, lastY = lastDropY; + const Point lastPos (lastDropPos); sendDragAndDropFinish(); resetDragAndDrop(); if (files.size() > 0) - handleFileDragDrop (files, lastX, lastY); + handleFileDragDrop (files, lastPos.getX(), lastPos.getY()); } void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg) @@ -234127,7 +233938,8 @@ private: } StringArray dragAndDropFiles; - int dragAndDropTimestamp, lastDropX, lastDropY; + int dragAndDropTimestamp; + Point lastDropPos; Atom XA_OtherMime, dragAndDropCurrentMimeType; Window dragAndDropSourceWindow; @@ -234280,17 +234092,18 @@ bool Desktop::canUseSemiTransparentWindows() throw() return false; } -void Desktop::getMousePosition (int& x, int& y) throw() +const Point Desktop::getMousePosition() { - int mouseMods; + int x, y, mouseMods; getMousePos (x, y, mouseMods); + return Point (x, y); } -void Desktop::setMousePosition (int x, int y) throw() +void Desktop::setMousePosition (const Point& newPosition) { ScopedXLock xlock; Window root = RootWindow (display, DefaultScreen (display)); - XWarpPointer (display, None, root, 0, 0, 0, 0, x, y); + XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY()); } static bool screenSaverAllowed = true; @@ -239446,20 +239259,19 @@ bool Desktop::canUseSemiTransparentWindows() throw() return true; } -void Desktop::getMousePosition (int& x, int& y) throw() +const Point Desktop::getMousePosition() { const ScopedAutoReleasePool pool; const NSPoint p ([NSEvent mouseLocation]); - x = roundToInt (p.x); - y = roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y); + return Point (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y)); } -void Desktop::setMousePosition (int x, int y) throw() +void Desktop::setMousePosition (const Point& newPosition) { // this rubbish needs to be done around the warp call, to avoid causing a // bizarre glitch.. CGAssociateMouseAndMouseCursorPosition (false); - CGWarpMouseCursorPosition (CGPointMake (x, y)); + CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY())); CGAssociateMouseAndMouseCursorPosition (true); } @@ -240891,10 +240703,9 @@ public: void setBounds (int x, int y, int w, int h, const bool isNowFullScreen); void getBounds (int& x, int& y, int& w, int& h, const bool global) const; void getBounds (int& x, int& y, int& w, int& h) const; - int getScreenX() const; - int getScreenY() const; - void relativePositionToGlobal (int& x, int& y); - void globalPositionToRelative (int& x, int& y); + const Point getScreenPosition() const; + const Point relativePositionToGlobal (const Point& relativePosition); + const Point globalPositionToRelative (const Point& screenPosition); void setMinimised (bool shouldBeMinimised); bool isMinimised() const; void setFullScreen (bool shouldBeFullScreen); @@ -240918,7 +240729,7 @@ public: virtual void viewFocusLoss(); bool isFocused() const; void grabFocus(); - void textInputRequired (int x, int y); + void textInputRequired (const Point& position); void repaint (int x, int y, int w, int h); void performAnyPendingRepaintsNow(); @@ -241501,7 +241312,7 @@ void UIViewComponentPeer::grabFocus() } } -void UIViewComponentPeer::textInputRequired (int /*x*/, int /*y*/) +void UIViewComponentPeer::textInputRequired (const Point&) { } @@ -241595,13 +241406,12 @@ bool Desktop::canUseSemiTransparentWindows() throw() return true; } -void Desktop::getMousePosition (int& x, int& y) throw() +const Point Desktop::getMousePosition() { - x = juce_lastMouseX; - y = juce_lastMouseY; + return Point (juce_lastMouseX, juce_lastMouseY); } -void Desktop::setMousePosition (int x, int y) throw() +void Desktop::setMousePosition (const Point&) { } @@ -245366,10 +245176,9 @@ public: void setBounds (int x, int y, int w, int h, const bool isNowFullScreen); void getBounds (int& x, int& y, int& w, int& h, const bool global) const; void getBounds (int& x, int& y, int& w, int& h) const; - int getScreenX() const; - int getScreenY() const; - void relativePositionToGlobal (int& x, int& y); - void globalPositionToRelative (int& x, int& y); + const Point getScreenPosition() const; + const Point relativePositionToGlobal (const Point& relativePosition); + const Point globalPositionToRelative (const Point& screenPosition); void setMinimised (bool shouldBeMinimised); bool isMinimised() const; void setFullScreen (bool shouldBeFullScreen); @@ -245419,7 +245228,7 @@ public: virtual void viewFocusLoss(); bool isFocused() const; void grabFocus(); - void textInputRequired (int x, int y); + void textInputRequired (const Point& position); void repaint (int x, int y, int w, int h); void performAnyPendingRepaintsNow(); @@ -246065,34 +245874,21 @@ void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const getBounds (x, y, w, h, ! isSharedWindow); } -int NSViewComponentPeer::getScreenX() const -{ - int x, y, w, h; - getBounds (x, y, w, h, true); - return x; -} - -int NSViewComponentPeer::getScreenY() const +const Point NSViewComponentPeer::getScreenPosition() const { int x, y, w, h; getBounds (x, y, w, h, true); - return y; + return Point (x, y); } -void NSViewComponentPeer::relativePositionToGlobal (int& x, int& y) +const Point NSViewComponentPeer::relativePositionToGlobal (const Point& relativePosition) { - int wx, wy, ww, wh; - getBounds (wx, wy, ww, wh, true); - x += wx; - y += wy; + return relativePosition + getScreenPosition(); } -void NSViewComponentPeer::globalPositionToRelative (int& x, int& y) +const Point NSViewComponentPeer::globalPositionToRelative (const Point& screenPosition) { - int wx, wy, ww, wh; - getBounds (wx, wy, ww, wh, true); - x -= wx; - y -= wy; + return screenPosition - getScreenPosition(); } NSRect NSViewComponentPeer::constrainRect (NSRect r) @@ -246331,7 +246127,7 @@ void NSViewComponentPeer::grabFocus() } } -void NSViewComponentPeer::textInputRequired (int /*x*/, int /*y*/) +void NSViewComponentPeer::textInputRequired (const Point&) { } @@ -246493,13 +246289,10 @@ void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev) void NSViewComponentPeer::showArrowCursorIfNeeded() { - if (Component::getComponentUnderMouse() == 0) + if (Component::getComponentUnderMouse() == 0 + && Desktop::getInstance().findComponentAt (Desktop::getInstance().getMousePosition()) == 0) { - int mx, my; - Desktop::getInstance().getMousePosition (mx, my); - - if (Desktop::getInstance().findComponentAt (mx, my) == 0) - [[NSCursor arrowCursor] set]; + [[NSCursor arrowCursor] set]; } } @@ -246995,12 +246788,11 @@ public: if (topComp->getPeer() != 0) { - int x = 0, y = 0; - owner->relativePositionToOtherComponent (topComp, x, y); + const Point pos (owner->relativePositionToOtherComponent (topComp, Point())); NSRect r; - r.origin.x = (float) x; - r.origin.y = (float) y; + r.origin.x = (float) pos.getX(); + r.origin.y = (float) pos.getY(); r.size.width = (float) owner->getWidth(); r.size.height = (float) owner->getHeight(); r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height); diff --git a/juce_amalgamated.h b/juce_amalgamated.h index ba6bf8c276..fbb58c7436 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -9299,16 +9299,154 @@ private: /*** End of inlined file: juce_ModifierKeys.h ***/ + +/*** Start of inlined file: juce_Point.h ***/ +#ifndef __JUCE_POINT_JUCEHEADER__ +#define __JUCE_POINT_JUCEHEADER__ + + +/*** Start of inlined file: juce_AffineTransform.h ***/ +#ifndef __JUCE_AFFINETRANSFORM_JUCEHEADER__ +#define __JUCE_AFFINETRANSFORM_JUCEHEADER__ + +class JUCE_API AffineTransform +{ +public: + + AffineTransform() throw(); + + AffineTransform (const AffineTransform& other) throw(); + + AffineTransform (const float mat00, const float mat01, const float mat02, + const float mat10, const float mat11, const float mat12) throw(); + + const AffineTransform& operator= (const AffineTransform& other) throw(); + + bool operator== (const AffineTransform& other) const throw(); + + bool operator!= (const AffineTransform& other) const throw(); + + static const AffineTransform identity; + + void transformPoint (float& x, + float& y) const throw(); + + void transformPoint (double& x, + double& y) const throw(); + + const AffineTransform translated (const float deltaX, + const float deltaY) const throw(); + + static const AffineTransform translation (const float deltaX, + const float deltaY) throw(); + + const AffineTransform rotated (const float angleInRadians) const throw(); + + const AffineTransform rotated (const float angleInRadians, + const float pivotX, + const float pivotY) const throw(); + + static const AffineTransform rotation (const float angleInRadians) throw(); + + static const AffineTransform rotation (const float angleInRadians, + const float pivotX, + const float pivotY) throw(); + + const AffineTransform scaled (const float factorX, + const float factorY) const throw(); + + static const AffineTransform scale (const float factorX, + const float factorY) throw(); + + const AffineTransform sheared (const float shearX, + const float shearY) const throw(); + + const AffineTransform inverted() const throw(); + + const AffineTransform followedBy (const AffineTransform& other) const throw(); + + bool isIdentity() const throw(); + + bool isSingularity() const throw(); + + bool isOnlyTranslation() const throw(); + + float getTranslationX() const throw() { return mat02; } + + float getTranslationY() const throw() { return mat12; } + + juce_UseDebuggingNewOperator + + float mat00, mat01, mat02; + float mat10, mat11, mat12; + +private: + + const AffineTransform followedBy (const float mat00, const float mat01, const float mat02, + const float mat10, const float mat11, const float mat12) const throw(); +}; + +#endif // __JUCE_AFFINETRANSFORM_JUCEHEADER__ +/*** End of inlined file: juce_AffineTransform.h ***/ + +template +class Point +{ +public: + + Point() throw() : x (0), y (0) {} + + Point (const Point& other) throw() : x (other.x), y (other.y) {} + + Point (const ValueType initialX, const ValueType initialY) throw() : x (initialX), y (initialY) {} + + ~Point() throw() {} + + Point& operator= (const Point& other) throw() { x = other.x; y = other.y; return *this; } + + inline ValueType getX() const throw() { return x; } + + inline ValueType getY() const throw() { return y; } + + inline bool operator== (const Point& other) const throw() { return x == other.x && y == other.y; } + inline bool operator!= (const Point& other) const throw() { return x != other.x || y != other.y; } + + bool isOrigin() const throw() { return x == ValueType() && y == ValueType(); } + + void setXY (const ValueType newX, const ValueType newY) throw() { x = newX; y = newY; } + + void addXY (const ValueType xToAdd, const ValueType yToAdd) throw() { x += xToAdd; y += yToAdd; } + + const Point operator+ (const Point& other) const throw() { return Point (x + other.x, y + other.y); } + + Point& operator+= (const Point& other) throw() { x += other.x; y += other.y; return *this; } + + const Point operator- (const Point& other) const throw() { return Point (x - other.x, y - other.y); } + + Point& operator-= (const Point& other) throw() { x -= other.x; y -= other.y; return *this; } + + ValueType getDistanceFrom (const Point& other) const throw() { return (ValueType) juce_hypot (x - other.x, y - other.y); } + + void applyTransform (const AffineTransform& transform) throw() { transform.transformPoint (x, y); } + + juce_UseDebuggingNewOperator + +private: + ValueType x, y; +}; + +#endif // __JUCE_POINT_JUCEHEADER__ +/*** End of inlined file: juce_Point.h ***/ + class JUCE_API MouseEvent { public: - MouseEvent (const int x, const int y, + MouseEvent (const Point& position, const ModifierKeys& modifiers, Component* const originator, const Time& eventTime, - const int mouseDownX, - const int mouseDownY, + const Point mouseDownPos, const Time& mouseDownTime, const int numberOfClicks, const bool mouseWasDragged) throw(); @@ -9331,6 +9469,8 @@ public: int getMouseDownY() const throw(); + const Point getMouseDownPosition() const throw(); + int getDistanceFromDragStart() const throw(); int getDistanceFromDragStartX() const throw(); @@ -9343,13 +9483,19 @@ public: int getLengthOfMousePress() const throw(); - int getScreenX() const throw(); + const Point getPosition() const throw(); + + int getScreenX() const; - int getScreenY() const throw(); + int getScreenY() const; - int getMouseDownScreenX() const throw(); + const Point getScreenPosition() const; - int getMouseDownScreenY() const throw(); + int getMouseDownScreenX() const; + + int getMouseDownScreenY() const; + + const Point getMouseDownScreenPosition() const; const MouseEvent getEventRelativeTo (Component* const otherComponent) const throw(); @@ -9360,7 +9506,7 @@ public: juce_UseDebuggingNewOperator private: - int mouseDownX, mouseDownY; + Point mouseDownPos; Time mouseDownTime; int numberOfClicks; bool wasMovedSinceMouseDown; @@ -9619,138 +9765,6 @@ public: #define __JUCE_PATH_JUCEHEADER__ -/*** Start of inlined file: juce_AffineTransform.h ***/ -#ifndef __JUCE_AFFINETRANSFORM_JUCEHEADER__ -#define __JUCE_AFFINETRANSFORM_JUCEHEADER__ - -class JUCE_API AffineTransform -{ -public: - - AffineTransform() throw(); - - AffineTransform (const AffineTransform& other) throw(); - - AffineTransform (const float mat00, const float mat01, const float mat02, - const float mat10, const float mat11, const float mat12) throw(); - - const AffineTransform& operator= (const AffineTransform& other) throw(); - - bool operator== (const AffineTransform& other) const throw(); - - bool operator!= (const AffineTransform& other) const throw(); - - static const AffineTransform identity; - - void transformPoint (float& x, - float& y) const throw(); - - void transformPoint (double& x, - double& y) const throw(); - - const AffineTransform translated (const float deltaX, - const float deltaY) const throw(); - - static const AffineTransform translation (const float deltaX, - const float deltaY) throw(); - - const AffineTransform rotated (const float angleInRadians) const throw(); - - const AffineTransform rotated (const float angleInRadians, - const float pivotX, - const float pivotY) const throw(); - - static const AffineTransform rotation (const float angleInRadians) throw(); - - static const AffineTransform rotation (const float angleInRadians, - const float pivotX, - const float pivotY) throw(); - - const AffineTransform scaled (const float factorX, - const float factorY) const throw(); - - static const AffineTransform scale (const float factorX, - const float factorY) throw(); - - const AffineTransform sheared (const float shearX, - const float shearY) const throw(); - - const AffineTransform inverted() const throw(); - - const AffineTransform followedBy (const AffineTransform& other) const throw(); - - bool isIdentity() const throw(); - - bool isSingularity() const throw(); - - bool isOnlyTranslation() const throw(); - - float getTranslationX() const throw() { return mat02; } - - float getTranslationY() const throw() { return mat12; } - - juce_UseDebuggingNewOperator - - float mat00, mat01, mat02; - float mat10, mat11, mat12; - -private: - - const AffineTransform followedBy (const float mat00, const float mat01, const float mat02, - const float mat10, const float mat11, const float mat12) const throw(); -}; - -#endif // __JUCE_AFFINETRANSFORM_JUCEHEADER__ -/*** End of inlined file: juce_AffineTransform.h ***/ - - -/*** Start of inlined file: juce_Point.h ***/ -#ifndef __JUCE_POINT_JUCEHEADER__ -#define __JUCE_POINT_JUCEHEADER__ - -template -class Point -{ -public: - - Point() throw() : x (0), y (0) {} - - Point (const Point& other) throw() : x (other.x), y (other.y) {} - - Point (const ValueType initialX, const ValueType initialY) throw() : x (initialX), y (initialY) {} - - ~Point() throw() {} - - Point& operator= (const Point& other) throw() { x = other.x; y = other.y; return *this; } - - inline ValueType getX() const throw() { return x; } - - inline ValueType getY() const throw() { return y; } - - void setXY (const ValueType newX, const ValueType newY) throw() { x = newX; y = newY; } - - void addXY (const ValueType xToAdd, const ValueType yToAdd) throw() { x += xToAdd; y += yToAdd; } - - const Point operator+ (const Point& other) const throw() { return Point (x + other.x, y + other.y); } - - Point& operator+= (const Point& other) throw() { x += other.x; y += other.y; return *this; } - - const Point operator- (const Point& other) const throw() { return Point (x - other.x, y - other.y); } - - Point& operator-= (const Point& other) throw() { x -= other.x; y -= other.y; return *this; } - - void applyTransform (const AffineTransform& transform) throw() { transform.transformPoint (x, y); } - - juce_UseDebuggingNewOperator - -private: - ValueType x, y; -}; - -#endif // __JUCE_POINT_JUCEHEADER__ -/*** End of inlined file: juce_Point.h ***/ - - /*** Start of inlined file: juce_Rectangle.h ***/ #ifndef __JUCE_RECTANGLE_JUCEHEADER__ #define __JUCE_RECTANGLE_JUCEHEADER__ @@ -9810,10 +9824,14 @@ public: inline ValueType getCentreY() const throw() { return y + h / (ValueType) 2; } + inline const Point getCentre() const throw() { return Point (x + w / (ValueType) 2, y + h / (ValueType) 2); } + bool isEmpty() const throw() { return w <= 0 || h <= 0; } const Point getPosition() const throw() { return Point (x, y); } + void setPosition (const Point& newPos) throw() { x = newPos.getX(); y = newPos.getY(); } + void setPosition (const ValueType newX, const ValueType newY) throw() { x = newX; y = newY; } void setSize (const ValueType newWidth, const ValueType newHeight) throw() { w = newWidth; h = newHeight; } @@ -9910,12 +9928,23 @@ public: return xCoord >= x && yCoord >= y && xCoord < x + w && yCoord < y + h; } + bool contains (const Point point) const throw() + { + return point.getX() >= x && point.getY() >= y && point.getX() < x + w && point.getY() < y + h; + } + bool contains (const Rectangle& other) const throw() { return x <= other.x && y <= other.y && x + w >= other.x + other.w && y + h >= other.y + other.h; } + const Point getConstrainedPoint (const Point& point) const throw() + { + return Point (jlimit (x, x + w, point.getX()), + jlimit (y, y + h, point.getY())); + } + bool intersects (const Rectangle& other) const throw() { return x + w > other.x @@ -12243,13 +12272,11 @@ public: virtual void getBounds (int& x, int& y, int& w, int& h) const = 0; - virtual int getScreenX() const = 0; + virtual const Point getScreenPosition() const = 0; - virtual int getScreenY() const = 0; + virtual const Point relativePositionToGlobal (const Point& relativePosition) = 0; - virtual void relativePositionToGlobal (int& x, int& y) = 0; - - virtual void globalPositionToRelative (int& x, int& y) = 0; + virtual const Point globalPositionToRelative (const Point& screenPosition) = 0; virtual void setMinimised (bool shouldBeMinimised) = 0; @@ -12291,7 +12318,7 @@ public: virtual void grabFocus() = 0; - virtual void textInputRequired (int x, int y) = 0; + virtual void textInputRequired (const Point& position) = 0; void handleFocusGain(); void handleFocusLoss(); @@ -12448,16 +12475,18 @@ public: void getVisibleArea (RectangleList& result, const bool includeSiblings) const; - int getScreenX() const throw(); + int getScreenX() const; + + int getScreenY() const; - int getScreenY() const throw(); + const Point getScreenPosition() const; - void relativePositionToGlobal (int& x, int& y) const throw(); + const Point relativePositionToGlobal (const Point& relativePosition) const; - void globalPositionToRelative (int& x, int& y) const throw(); + const Point globalPositionToRelative (const Point& screenPosition) const; - void relativePositionToOtherComponent (const Component* const targetComponent, - int& x, int& y) const throw(); + const Point relativePositionToOtherComponent (const Component* const targetComponent, + const Point& positionRelativeToThis) const; void setTopLeftPosition (const int x, const int y); @@ -12690,7 +12719,7 @@ public: static bool JUCE_CALLTYPE isMouseButtonDownAnywhere() throw(); - void getMouseXYRelative (int& x, int& y) const throw(); + const Point getMouseXYRelative() const; static Component* JUCE_CALLTYPE getComponentUnderMouse() throw(); @@ -12834,8 +12863,7 @@ private: void sendEnablementChangeMessage(); static void* runModalLoopCallback (void*); static void bringModalComponentToFront(); - void subtractObscuredRegions (RectangleList& result, - const int deltaX, const int deltaY, + void subtractObscuredRegions (RectangleList& result, const Point& delta, const Rectangle& clipRect, const Component* const compToAvoid) const throw(); void clipObscuredRegions (Graphics& g, const Rectangle& clipRect, @@ -13233,13 +13261,13 @@ public: const Rectangle getMainMonitorArea (const bool clippedToWorkArea = true) const throw(); - const Rectangle getMonitorAreaContaining (int x, int y, const bool clippedToWorkArea = true) const throw(); + const Rectangle getMonitorAreaContaining (const Point& position, const bool clippedToWorkArea = true) const throw(); - static void getMousePosition (int& x, int& y) throw(); + static const Point getMousePosition(); - static void setMousePosition (int x, int y) throw(); + static void setMousePosition (const Point& newPosition); - static void getLastMouseDownPosition (int& x, int& y) throw(); + static const Point getLastMouseDownPosition() throw(); static int getMouseButtonClickCounter() throw(); @@ -13264,8 +13292,7 @@ public: Component* getComponent (const int index) const throw(); - Component* findComponentAt (const int screenX, - const int screenY) const; + Component* findComponentAt (const Point& screenPosition) const; juce_UseDebuggingNewOperator @@ -13289,7 +13316,8 @@ private: Array > monitorCoordsClipped, monitorCoordsUnclipped; - int lastFakeMouseMoveX, lastFakeMouseMoveY, mouseClickCounter; + Point lastFakeMouseMove; + int mouseClickCounter; bool mouseMovedSignificantlySincePressed; struct RecentMouseDown @@ -15893,7 +15921,8 @@ public: private: int millisecondsBeforeTipAppears; - int mouseX, mouseY, mouseClicks; + Point lastMousePos; + int mouseClicks; unsigned int lastCompChangeTime, lastHideTime; Component* lastComponentUnderMouse; bool changedCompsSinceShown; @@ -18663,7 +18692,7 @@ private: Component* headerComponent; int totalItems, rowHeight, minimumRowWidth; int outlineThickness; - int lastMouseX, lastMouseY, lastRowSelected; + int lastRowSelected; bool mouseMoveSelects, multipleSelection, hasDoneInitialUpdate; SparseSet selected; @@ -22864,7 +22893,7 @@ public: private: ComponentBoundsConstrainer* constrainer; - int originalX, originalY; + Point originalPos; }; #endif // __JUCE_COMPONENTDRAGGER_JUCEHEADER__ @@ -23800,7 +23829,7 @@ private: ComponentPeer* lastPeer; VoidArray registeredParentComps; bool reentrant; - int lastX, lastY, lastWidth, lastHeight; + Rectangle lastBounds; #ifdef JUCE_DEBUG ScopedPointer deletionWatcher; #endif @@ -26595,10 +26624,10 @@ private: int octaveNumForMiddleC; void getKeyPos (int midiNoteNumber, int& x, int& w) const; - int xyToNote (int x, int y, float& mousePositionVelocity); - int remappedXYToNote (int x, int y, float& mousePositionVelocity) const; + int xyToNote (const Point& pos, float& mousePositionVelocity); + int remappedXYToNote (const Point& pos, float& mousePositionVelocity) const; void resetAnyKeysInUse(); - void updateNoteUnderMouse (int x, int y); + void updateNoteUnderMouse (const Point& pos); void repaintNote (const int midiNoteNumber); MidiKeyboardComponent (const MidiKeyboardComponent&); diff --git a/src/gui/components/buttons/juce_Button.cpp b/src/gui/components/buttons/juce_Button.cpp index 901e3df448..933921c478 100644 --- a/src/gui/components/buttons/juce_Button.cpp +++ b/src/gui/components/buttons/juce_Button.cpp @@ -233,20 +233,14 @@ Button::ButtonState Button::updateState (const MouseEvent* const e) if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent()) { - int mx, my; + Point mousePos; if (e == 0) - { - getMouseXYRelative (mx, my); - } + mousePos = getMouseXYRelative(); else - { - const MouseEvent e2 (e->getEventRelativeTo (this)); - mx = e2.x; - my = e2.y; - } + mousePos = e->getEventRelativeTo (this).getPosition(); - const bool over = reallyContains (mx, my, true); + const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true); const bool down = isMouseButtonDown(); if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown) diff --git a/src/gui/components/controls/juce_ListBox.cpp b/src/gui/components/controls/juce_ListBox.cpp index 97a3116683..cde341f4ca 100644 --- a/src/gui/components/controls/juce_ListBox.cpp +++ b/src/gui/components/controls/juce_ListBox.cpp @@ -802,11 +802,7 @@ void ListBox::mouseMove (const MouseEvent& e) if (mouseMoveSelects) { const MouseEvent e2 (e.getEventRelativeTo (this)); - selectRow (getRowContainingPosition (e2.x, e2.y), true); - - lastMouseX = e2.x; - lastMouseY = e2.y; } } @@ -898,10 +894,8 @@ Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY) if (rowComp != 0 && isRowSelected (firstRow + i)) { - int x = 0, y = 0; - rowComp->relativePositionToOtherComponent (this, x, y); - - const Rectangle rowRect (x, y, rowComp->getWidth(), rowComp->getHeight()); + const Point pos (rowComp->relativePositionToOtherComponent (this, Point())); + const Rectangle rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight()); if (imageArea.isEmpty()) imageArea = rowRect; @@ -921,11 +915,10 @@ Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY) if (rowComp != 0 && isRowSelected (firstRow + i)) { - int x = 0, y = 0; - rowComp->relativePositionToOtherComponent (this, x, y); + const Point pos (rowComp->relativePositionToOtherComponent (this, Point())); Graphics g (*snapshot); - g.setOrigin (x - imageX, y - imageY); + g.setOrigin (pos.getX() - imageX, pos.getY() - imageY); if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight())) rowComp->paintEntireComponent (g); } diff --git a/src/gui/components/controls/juce_ListBox.h b/src/gui/components/controls/juce_ListBox.h index 171363c265..08c14766b5 100644 --- a/src/gui/components/controls/juce_ListBox.h +++ b/src/gui/components/controls/juce_ListBox.h @@ -572,7 +572,7 @@ private: Component* headerComponent; int totalItems, rowHeight, minimumRowWidth; int outlineThickness; - int lastMouseX, lastMouseY, lastRowSelected; + int lastRowSelected; bool mouseMoveSelects, multipleSelection, hasDoneInitialUpdate; SparseSet selected; diff --git a/src/gui/components/controls/juce_Slider.cpp b/src/gui/components/controls/juce_Slider.cpp index 8022c66b8c..f179b757fb 100644 --- a/src/gui/components/controls/juce_Slider.cpp +++ b/src/gui/components/controls/juce_Slider.cpp @@ -1150,34 +1150,32 @@ void Slider::restoreMouseIfHidden() if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag) { - int x, y, downX, downY; - Desktop::getMousePosition (x, y); - Desktop::getLastMouseDownPosition (downX, downY); + Point mousePos (Desktop::getMousePosition()); + const Point lastMouseDown (Desktop::getLastMouseDownPosition()); if (style == RotaryHorizontalDrag) { const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown); - x = roundToInt (pixelsForFullDragExtent * posDiff + downX); - y = downY; + mousePos = Point (roundToInt (pixelsForFullDragExtent * posDiff + lastMouseDown.getX()), + lastMouseDown.getY()); } else { const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos); - x = downX; - y = roundToInt (pixelsForFullDragExtent * posDiff + downY); + mousePos = Point (lastMouseDown.getX(), + roundToInt (pixelsForFullDragExtent * posDiff + lastMouseDown.getY())); } - Desktop::setMousePosition (x, y); + Desktop::setMousePosition (mousePos); } else { const int pixelPos = (int) getLinearSliderPos (pos); - int x = isHorizontal() ? pixelPos : (getWidth() / 2); - int y = isVertical() ? pixelPos : (getHeight() / 2); + const Point pos (isHorizontal() ? pixelPos : (getWidth() / 2), + isVertical() ? pixelPos : (getHeight() / 2)); - relativePositionToGlobal (x, y); - Desktop::setMousePosition (x, y); + Desktop::setMousePosition (relativePositionToGlobal (pos)); } } } diff --git a/src/gui/components/controls/juce_TableHeaderComponent.cpp b/src/gui/components/controls/juce_TableHeaderComponent.cpp index 6de1b91bfa..4e7e063d01 100644 --- a/src/gui/components/controls/juce_TableHeaderComponent.cpp +++ b/src/gui/components/controls/juce_TableHeaderComponent.cpp @@ -797,10 +797,7 @@ void TableHeaderComponent::mouseUp (const MouseEvent& e) const MouseCursor TableHeaderComponent::getMouseCursor() { - int x, y; - getMouseXYRelative (x, y); - - if (columnIdBeingResized != 0 || (getResizeDraggerAt (x) != 0 && ! isMouseButtonDown())) + if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown())) return MouseCursor (MouseCursor::LeftRightResizeCursor); return Component::getMouseCursor(); diff --git a/src/gui/components/controls/juce_TableListBox.cpp b/src/gui/components/controls/juce_TableListBox.cpp index a2ee85a057..5b440ee993 100644 --- a/src/gui/components/controls/juce_TableListBox.cpp +++ b/src/gui/components/controls/juce_TableListBox.cpp @@ -229,10 +229,7 @@ public: const String getTooltip() { - int x, y; - getMouseXYRelative (x, y); - - const int columnId = owner.getHeader()->getColumnIdAtX (x); + const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX()); if (columnId != 0 && owner.getModel() != 0) return owner.getModel()->getCellTooltip (row, columnId); diff --git a/src/gui/components/controls/juce_TextEditor.cpp b/src/gui/components/controls/juce_TextEditor.cpp index 1135910f78..7b06fc5bf7 100644 --- a/src/gui/components/controls/juce_TextEditor.cpp +++ b/src/gui/components/controls/juce_TextEditor.cpp @@ -2126,8 +2126,7 @@ void TextEditor::focusGained (FocusChangeType) ComponentPeer* const peer = getPeer(); if (peer != 0 && ! isReadOnly()) - peer->textInputRequired (getScreenX() - peer->getScreenX(), - getScreenY() - peer->getScreenY()); + peer->textInputRequired (getScreenPosition() - peer->getScreenPosition()); } void TextEditor::focusLost (FocusChangeType) diff --git a/src/gui/components/controls/juce_TreeView.cpp b/src/gui/components/controls/juce_TreeView.cpp index d1f12a15e7..443dd90eb3 100644 --- a/src/gui/components/controls/juce_TreeView.cpp +++ b/src/gui/components/controls/juce_TreeView.cpp @@ -306,11 +306,8 @@ public: const String getTooltip() { - int x, y; - getMouseXYRelative (x, y); Rectangle pos; - - TreeViewItem* const item = findItemAt (y, pos); + TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos); if (item != 0) return item->getTooltip(); @@ -557,10 +554,8 @@ TreeViewItem* TreeView::getItemOnRow (int index) const TreeViewItem* TreeView::getItemAt (int y) const throw() { TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent(); - int x; - relativePositionToOtherComponent (tc, x, y); Rectangle pos; - return tc->findItemAt (y, pos); + return tc->findItemAt (relativePositionToOtherComponent (tc, Point (0, y)).getY(), pos); } TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const diff --git a/src/gui/components/juce_Component.cpp b/src/gui/components/juce_Component.cpp index e530cd7218..2c65bf964b 100644 --- a/src/gui/components/juce_Component.cpp +++ b/src/gui/components/juce_Component.cpp @@ -53,8 +53,7 @@ static const int customCommandMessage = 0x7fff0001; static const int exitModalStateMessage = 0x7fff0002; //============================================================================== -static int unboundedMouseOffsetX = 0; -static int unboundedMouseOffsetY = 0; +static Point unboundedMouseOffset; static bool isUnboundedMouseModeOn = false; static bool isCursorVisibleUntilOffscreen; @@ -412,8 +411,7 @@ void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo) jmax (1, getHeight())); #endif - int x = 0, y = 0; - relativePositionToGlobal (x, y); + const Point topLeft (relativePositionToGlobal (Point (0, 0))); bool wasFullscreen = false; bool wasMinimised = false; @@ -429,7 +427,7 @@ void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo) removeFromDesktop(); - setTopLeftPosition (x, y); + setTopLeftPosition (topLeft.getX(), topLeft.getY()); } if (parentComponent_ != 0) @@ -443,8 +441,8 @@ void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo) Desktop::getInstance().addDesktopComponent (this); - bounds_.setPosition (x, y); - peer->setBounds (x, y, getWidth(), getHeight(), false); + bounds_.setPosition (topLeft); + peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false); peer->setVisible (isVisible()); @@ -741,57 +739,60 @@ int Component::getParentHeight() const throw() : getParentMonitorArea().getHeight(); } -int Component::getScreenX() const throw() +int Component::getScreenX() const { - return (parentComponent_ != 0) ? parentComponent_->getScreenX() + getX() - : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenX() - : getX()); + return getScreenPosition().getX(); } -int Component::getScreenY() const throw() +int Component::getScreenY() const { - return (parentComponent_ != 0) ? parentComponent_->getScreenY() + getY() - : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenY() - : getY()); + return getScreenPosition().getY(); } -void Component::relativePositionToGlobal (int& x, int& y) const throw() +const Point Component::getScreenPosition() const +{ + return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition() + : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition() + : getPosition()); +} + +const Point Component::relativePositionToGlobal (const Point& relativePosition) const { const Component* c = this; + Point p (relativePosition); do { if (c->flags.hasHeavyweightPeerFlag) - { - c->getPeer()->relativePositionToGlobal (x, y); - break; - } + return c->getPeer()->relativePositionToGlobal (p); - x += c->getX(); - y += c->getY(); + p += c->getPosition(); c = c->parentComponent_; } while (c != 0); + + return p; } -void Component::globalPositionToRelative (int& x, int& y) const throw() +const Point Component::globalPositionToRelative (const Point& screenPosition) const { if (flags.hasHeavyweightPeerFlag) { - getPeer()->globalPositionToRelative (x, y); + return getPeer()->globalPositionToRelative (screenPosition); } else { if (parentComponent_ != 0) - parentComponent_->globalPositionToRelative (x, y); + return parentComponent_->globalPositionToRelative (screenPosition) - getPosition(); - x -= getX(); - y -= getY(); + return screenPosition - getPosition(); } } -void Component::relativePositionToOtherComponent (const Component* const targetComponent, int& x, int& y) const throw() +const Point Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point& positionRelativeToThis) const { + Point p (positionRelativeToThis); + if (targetComponent != 0) { const Component* c = this; @@ -799,22 +800,23 @@ void Component::relativePositionToOtherComponent (const Component* const targetC do { if (c == targetComponent) - return; + return p; if (c->flags.hasHeavyweightPeerFlag) { - c->getPeer()->relativePositionToGlobal (x, y); + p = c->getPeer()->relativePositionToGlobal (p); break; } - x += c->getX(); - y += c->getY(); + p += c->getPosition(); c = c->parentComponent_; } while (c != 0); - targetComponent->globalPositionToRelative (x, y); + p = targetComponent->globalPositionToRelative (p); } + + return p; } //============================================================================== @@ -1546,10 +1548,9 @@ void Component::setMouseCursor (const MouseCursor& cursor) throw() if (flags.visibleFlag) { - int mx, my; - getMouseXYRelative (mx, my); + const Point mousePos (getMouseXYRelative()); - if (flags.draggingFlag || reallyContains (mx, my, false)) + if (flags.draggingFlag || reallyContains (mousePos.getX(), mousePos.getY(), false)) { internalUpdateMouseCursor (false); } @@ -1574,9 +1575,8 @@ void Component::internalUpdateMouseCursor (bool forcedUpdate) throw() { MouseCursor mc (getLookAndFeel().getMouseCursorFor (*this)); - if (isUnboundedMouseModeOn && (unboundedMouseOffsetX != 0 - || unboundedMouseOffsetY != 0 - || ! isCursorVisibleUntilOffscreen)) + if (isUnboundedMouseModeOn + && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen)) { mc = MouseCursor::NoCursor; forcedUpdate = true; @@ -1989,22 +1989,18 @@ void Component::getVisibleArea (RectangleList& result, { const Component* const c = getTopLevelComponent(); - int x = 0, y = 0; - c->relativePositionToOtherComponent (this, x, y); - - c->subtractObscuredRegions (result, x, y, + c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point()), Rectangle (0, 0, c->getWidth(), c->getHeight()), this); } - subtractObscuredRegions (result, 0, 0, unclipped, 0); + subtractObscuredRegions (result, Point(), unclipped, 0); result.consolidate(); } } void Component::subtractObscuredRegions (RectangleList& result, - const int deltaX, - const int deltaY, + const Point& delta, const Rectangle& clipRect, const Component* const compToAvoid) const throw() { @@ -2017,7 +2013,7 @@ void Component::subtractObscuredRegions (RectangleList& result, if (c->isOpaque()) { Rectangle childBounds (c->bounds_.getIntersection (clipRect)); - childBounds.translate (deltaX, deltaY); + childBounds.translate (delta.getX(), delta.getY()); result.subtract (childBounds); } @@ -2026,11 +2022,8 @@ void Component::subtractObscuredRegions (RectangleList& result, Rectangle newClip (clipRect.getIntersection (c->bounds_)); newClip.translate (-c->getX(), -c->getY()); - c->subtractObscuredRegions (result, - c->getX() + deltaX, - c->getY() + deltaY, - newClip, - compToAvoid); + c->subtractObscuredRegions (result, c->getPosition() + delta, + newClip, compToAvoid); } } } @@ -2253,11 +2246,11 @@ void Component::internalMouseEnter (int x, int y, int64 time) if (flags.repaintOnMouseActivityFlag) repaint(); - const MouseEvent me (x, y, + const MouseEvent me (Point (x, y), ModifierKeys::getCurrentModifiers(), this, Time (time), - x, y, + Point (x, y), Time (time), 0, false); @@ -2338,11 +2331,11 @@ void Component::internalMouseExit (int x, int y, int64 time) if (flags.repaintOnMouseActivityFlag) repaint(); - const MouseEvent me (x, y, + const MouseEvent me (Point (x, y), ModifierKeys::getCurrentModifiers(), this, Time (time), - x, y, + Point (x, y), Time (time), 0, false); mouseExit (me); @@ -2409,15 +2402,13 @@ public: if (c != 0 && c->isMouseButtonDown()) { - int x, y; - c->getMouseXYRelative (x, y); + const Point mousePos (c->getMouseXYRelative()); // the offsets have been added on, so must be taken off before calling the // drag.. otherwise they'll be added twice - x -= unboundedMouseOffsetX; - y -= unboundedMouseOffsetY; - - c->internalMouseDrag (x, y, Time::currentTimeMillis()); + c->internalMouseDrag (mousePos.getX() - unboundedMouseOffset.getX(), + mousePos.getY() - unboundedMouseOffset.getY(), + Time::currentTimeMillis()); } } @@ -2451,9 +2442,7 @@ void Component::internalMouseDown (const int x, const int y, const int64 time) { Desktop& desktop = Desktop::getInstance(); - int gx = x, gy = y; - relativePositionToGlobal (gx, gy); - desktop.registerMouseDown (Point (gx, gy), time, this); + desktop.registerMouseDown (relativePositionToGlobal (Point (x, y)), time, this); const ComponentDeletionWatcher deletionChecker (this); @@ -2469,11 +2458,11 @@ void Component::internalMouseDown (const int x, const int y, const int64 time) if (isCurrentlyBlockedByAnotherModalComponent()) { // allow blocked mouse-events to go to global listeners.. - const MouseEvent me (x, y, + const MouseEvent me (Point (x, y), ModifierKeys::getCurrentModifiers(), this, Time (time), - x, y, + Point (x, y), desktop.getLastMouseDownTime(), desktop.getNumberOfMultipleClicks(), false); @@ -2522,11 +2511,11 @@ void Component::internalMouseDown (const int x, const int y, const int64 time) if (flags.repaintOnMouseActivityFlag) repaint(); - const MouseEvent me (x, y, + const MouseEvent me (Point (x, y), ModifierKeys::getCurrentModifiers(), this, desktop.getLastMouseDownTime(), - x, y, + Point (x, y), desktop.getLastMouseDownTime(), desktop.getNumberOfMultipleClicks(), false); @@ -2591,29 +2580,24 @@ void Component::internalMouseUp (const int oldModifiers, int x, int y, const int flags.draggingFlag = false; deleteAndZero (dragRepeater); - x += unboundedMouseOffsetX; - y += unboundedMouseOffsetY; + x += unboundedMouseOffset.getX(); + y += unboundedMouseOffset.getY(); - int gx = x, gy = y; - relativePositionToGlobal (gx, gy); - desktop.registerMouseDrag (Point (gx, gy)); + desktop.registerMouseDrag (relativePositionToGlobal (Point (x, y))); const ComponentDeletionWatcher deletionChecker (this); if (flags.repaintOnMouseActivityFlag) repaint(); - int mdx, mdy; - Desktop::getLastMouseDownPosition (mdx, mdy); - globalPositionToRelative (mdx, mdy); - + const Point mouseDownPos (globalPositionToRelative (Desktop::getLastMouseDownPosition())); const Time lastMouseDownTime (desktop.getLastMouseDownTime()); - const MouseEvent me (x, y, + const MouseEvent me (Point (x, y), oldModifiers, this, Time (time), - mdx, mdy, + mouseDownPos, lastMouseDownTime, desktop.getNumberOfMultipleClicks(), desktop.mouseMovedSignificantlySincePressed @@ -2733,26 +2717,21 @@ void Component::internalMouseDrag (int x, int y, const int64 time) flags.mouseOverFlag = reallyContains (x, y, false); - x += unboundedMouseOffsetX; - y += unboundedMouseOffsetY; + x += unboundedMouseOffset.getX(); + y += unboundedMouseOffset.getY(); - int gx = x, gy = y; - relativePositionToGlobal (gx, gy); - desktop.registerMouseDrag (Point (gx, gy)); + desktop.registerMouseDrag (relativePositionToGlobal (Point (x, y))); const ComponentDeletionWatcher deletionChecker (this); - int mdx, mdy; - Desktop::getLastMouseDownPosition (mdx, mdy); - globalPositionToRelative (mdx, mdy); - + const Point mouseDownPos (globalPositionToRelative (Desktop::getLastMouseDownPosition())); const Time lastMouseDownTime (desktop.getLastMouseDownTime()); - const MouseEvent me (x, y, + const MouseEvent me (Point (x, y), ModifierKeys::getCurrentModifiers(), this, Time (time), - mdx, mdy, + mouseDownPos, lastMouseDownTime, desktop.getNumberOfMultipleClicks(), desktop.mouseMovedSignificantlySincePressed @@ -2812,37 +2791,30 @@ void Component::internalMouseDrag (int x, int y, const int64 time) if (isUnboundedMouseModeOn) { Rectangle screenArea (getParentMonitorArea().expanded (-2, -2)); + Point mousePos (Desktop::getMousePosition()); - int mx, my; - Desktop::getMousePosition (mx, my); - - if (! screenArea.contains (mx, my)) + if (! screenArea.contains (mousePos)) { int deltaX = 0, deltaY = 0; - if (mx <= screenArea.getX() || mx >= screenArea.getRight()) - deltaX = getScreenX() + getWidth() / 2 - mx; + if (mousePos.getX() <= screenArea.getX() || mousePos.getX() >= screenArea.getRight()) + deltaX = getScreenX() + getWidth() / 2 - mousePos.getX(); - if (my <= screenArea.getY() || my >= screenArea.getBottom()) - deltaY = getScreenY() + getHeight() / 2 - my; + if (mousePos.getY() <= screenArea.getY() || mousePos.getY() >= screenArea.getBottom()) + deltaY = getScreenY() + getHeight() / 2 - mousePos.getY(); - unboundedMouseOffsetX -= deltaX; - unboundedMouseOffsetY -= deltaY; + unboundedMouseOffset -= Point (deltaX, deltaY); - Desktop::setMousePosition (mx + deltaX, - my + deltaY); + Desktop::setMousePosition (mousePos + Point (deltaX, deltaY)); } else if (isCursorVisibleUntilOffscreen - && (unboundedMouseOffsetX != 0 || unboundedMouseOffsetY != 0) - && screenArea.contains (mx + unboundedMouseOffsetX, - my + unboundedMouseOffsetY)) + && (! unboundedMouseOffset.isOrigin()) + && screenArea.contains (mousePos + unboundedMouseOffset)) { - mx += unboundedMouseOffsetX; - my += unboundedMouseOffsetY; - unboundedMouseOffsetX = 0; - unboundedMouseOffsetY = 0; + mousePos += unboundedMouseOffset; + unboundedMouseOffset = Point(); - Desktop::setMousePosition (mx, my); + Desktop::setMousePosition (mousePos); } } @@ -2859,11 +2831,11 @@ void Component::internalMouseMove (const int x, const int y, const int64 time) { Desktop& desktop = Desktop::getInstance(); - const MouseEvent me (x, y, + const MouseEvent me (Point (x, y), ModifierKeys::getCurrentModifiers(), this, Time (time), - x, y, + Point (x, y), Time (time), 0, false); @@ -2939,14 +2911,13 @@ void Component::internalMouseWheel (const int intAmountX, const int intAmountY, const float wheelIncrementX = intAmountX * (1.0f / 256.0f); const float wheelIncrementY = intAmountY * (1.0f / 256.0f); - int mx, my; - getMouseXYRelative (mx, my); + const Point mousePos (getMouseXYRelative()); - const MouseEvent me (mx, my, + const MouseEvent me (mousePos, ModifierKeys::getCurrentModifiers(), this, Time (time), - mx, my, + mousePos, Time (time), 0, false); @@ -3403,13 +3374,9 @@ bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw() return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(); } -void Component::getMouseXYRelative (int& mx, int& my) const throw() +const Point Component::getMouseXYRelative() const { - Desktop::getMousePosition (mx, my); - globalPositionToRelative (mx, my); - - mx += unboundedMouseOffsetX; - my += unboundedMouseOffsetY; + return globalPositionToRelative (Desktop::getMousePosition()) + unboundedMouseOffset; } void Component::enableUnboundedMouseMovement (bool enable, @@ -3421,25 +3388,15 @@ void Component::enableUnboundedMouseMovement (bool enable, if (enable != isUnboundedMouseModeOn) { if ((! enable) && ((! isCursorVisibleUntilOffscreen) - || unboundedMouseOffsetX != 0 - || unboundedMouseOffsetY != 0)) + || ! unboundedMouseOffset.isOrigin())) { // when released, return the mouse to within the component's bounds - - int mx, my; - getMouseXYRelative (mx, my); - - mx = jlimit (0, getWidth(), mx); - my = jlimit (0, getHeight(), my); - - relativePositionToGlobal (mx, my); - - Desktop::setMousePosition (mx, my); + Desktop::setMousePosition (relativePositionToGlobal (Rectangle (0, 0, getWidth(), getHeight()) + .getConstrainedPoint (getMouseXYRelative()))); } isUnboundedMouseModeOn = enable; - unboundedMouseOffsetX = 0; - unboundedMouseOffsetY = 0; + unboundedMouseOffset = Point(); internalUpdateMouseCursor (true); } @@ -3453,11 +3410,9 @@ Component* JUCE_CALLTYPE Component::getComponentUnderMouse() throw() //============================================================================== const Rectangle Component::getParentMonitorArea() const throw() { - int centreX = getWidth() / 2; - int centreY = getHeight() / 2; - relativePositionToGlobal (centreX, centreY); - - return Desktop::getInstance().getMonitorAreaContaining (centreX, centreY); + return Desktop::getInstance() + .getMonitorAreaContaining (relativePositionToGlobal (Point (getWidth() / 2, + getHeight() / 2))); } //============================================================================== diff --git a/src/gui/components/juce_Component.h b/src/gui/components/juce_Component.h index 1cace660b7..e5218982de 100644 --- a/src/gui/components/juce_Component.h +++ b/src/gui/components/juce_Component.h @@ -343,33 +343,37 @@ public: @see getX, relativePositionToGlobal */ - int getScreenX() const throw(); + int getScreenX() const; /** Returns this component's y co-ordinate relative the the screen's top-left origin. @see getY, relativePositionToGlobal */ - int getScreenY() const throw(); + int getScreenY() const; + + /** Returns the position of this component's top-left corner relative to the screen's top-left. + */ + const Point getScreenPosition() const; /** Converts a position relative to this component's top-left into a screen co-ordinate. @see globalPositionToRelative, relativePositionToOtherComponent */ - void relativePositionToGlobal (int& x, int& y) const throw(); + const Point relativePositionToGlobal (const Point& relativePosition) const; /** Converts a screen co-ordinate into a position relative to this component's top-left. @see relativePositionToGlobal, relativePositionToOtherComponent */ - void globalPositionToRelative (int& x, int& y) const throw(); + const Point globalPositionToRelative (const Point& screenPosition) const; /** Converts a position relative to this component's top-left into a position relative to another component's top-left. @see relativePositionToGlobal, globalPositionToRelative */ - void relativePositionToOtherComponent (const Component* const targetComponent, - int& x, int& y) const throw(); + const Point relativePositionToOtherComponent (const Component* const targetComponent, + const Point& positionRelativeToThis) const; //============================================================================== /** Moves the component to a new position. @@ -1578,7 +1582,7 @@ public: The co-ordinates are relative to the component's top-left corner. */ - void getMouseXYRelative (int& x, int& y) const throw(); + const Point getMouseXYRelative() const; /** Returns the component that's currently underneath the mouse. @@ -1979,8 +1983,7 @@ private: void sendEnablementChangeMessage(); static void* runModalLoopCallback (void*); static void bringModalComponentToFront(); - void subtractObscuredRegions (RectangleList& result, - const int deltaX, const int deltaY, + void subtractObscuredRegions (RectangleList& result, const Point& delta, const Rectangle& clipRect, const Component* const compToAvoid) const throw(); void clipObscuredRegions (Graphics& g, const Rectangle& clipRect, diff --git a/src/gui/components/juce_Desktop.cpp b/src/gui/components/juce_Desktop.cpp index eafe5f11e0..2d55551373 100644 --- a/src/gui/components/juce_Desktop.cpp +++ b/src/gui/components/juce_Desktop.cpp @@ -34,9 +34,7 @@ BEGIN_JUCE_NAMESPACE //============================================================================== Desktop::Desktop() throw() - : lastFakeMouseMoveX (0), - lastFakeMouseMoveY (0), - mouseClickCounter (0), + : mouseClickCounter (0), mouseMovedSignificantlySincePressed (false), kioskModeComponent (0) { @@ -118,7 +116,7 @@ const Rectangle Desktop::getMainMonitorArea (const bool clippedToWorkArea) return getDisplayMonitorCoordinates (0, clippedToWorkArea); } -const Rectangle Desktop::getMonitorAreaContaining (int cx, int cy, const bool clippedToWorkArea) const throw() +const Rectangle Desktop::getMonitorAreaContaining (const Point& position, const bool clippedToWorkArea) const throw() { Rectangle best (getMainMonitorArea (clippedToWorkArea)); double bestDistance = 1.0e10; @@ -127,11 +125,10 @@ const Rectangle Desktop::getMonitorAreaContaining (int cx, int cy, const bo { const Rectangle rect (getDisplayMonitorCoordinates (i, clippedToWorkArea)); - if (rect.contains (cx, cy)) + if (rect.contains (position)) return rect; - const double distance = juce_hypot ((double) (rect.getCentreX() - cx), - (double) (rect.getCentreY() - cy)); + const double distance = rect.getCentre().getDistanceFrom (position); if (distance < bestDistance) { @@ -154,18 +151,15 @@ Component* Desktop::getComponent (const int index) const throw() return desktopComponents [index]; } -Component* Desktop::findComponentAt (const int screenX, - const int screenY) const +Component* Desktop::findComponentAt (const Point& screenPosition) const { for (int i = desktopComponents.size(); --i >= 0;) { Component* const c = desktopComponents.getUnchecked(i); + const Point relative (c->globalPositionToRelative (screenPosition)); - int x = screenX, y = screenY; - c->globalPositionToRelative (x, y); - - if (c->contains (x, y)) - return c->getComponentAt (x, y); + if (c->contains (relative.getX(), relative.getY())) + return c->getComponentAt (relative.getX(), relative.getY()); } return 0; @@ -208,11 +202,9 @@ void Desktop::componentBroughtToFront (Component* const c) throw() } //============================================================================== -void Desktop::getLastMouseDownPosition (int& x, int& y) throw() +const Point Desktop::getLastMouseDownPosition() throw() { - const Desktop& d = getInstance(); - x = d.mouseDowns[0].position.getX(); - y = d.mouseDowns[0].position.getY(); + return getInstance().mouseDowns[0].position; } int Desktop::getMouseButtonClickCounter() throw() @@ -327,10 +319,7 @@ void Desktop::handleAsyncUpdate() //============================================================================== void Desktop::timerCallback() { - int x, y; - getMousePosition (x, y); - - if (lastFakeMouseMoveX != x || lastFakeMouseMoveY != y) + if (lastFakeMouseMove != getMousePosition()) sendMouseMove(); } @@ -340,26 +329,18 @@ void Desktop::sendMouseMove() { startTimer (20); - int x, y; - getMousePosition (x, y); - lastFakeMouseMoveX = x; - lastFakeMouseMoveY = y; + lastFakeMouseMove = getMousePosition(); - Component* const target = findComponentAt (x, y); + Component* const target = findComponentAt (lastFakeMouseMove); if (target != 0) { - target->globalPositionToRelative (x, y); - ComponentDeletionWatcher deletionChecker (target); + const Point pos (target->globalPositionToRelative (lastFakeMouseMove)); + const Time now (Time::getCurrentTime()); - const MouseEvent me (x, y, - ModifierKeys::getCurrentModifiers(), - target, - Time::getCurrentTime(), - x, y, - Time::getCurrentTime(), - 0, false); + const MouseEvent me (pos, ModifierKeys::getCurrentModifiers(), + target, now, pos, now, 0, false); for (int i = mouseListeners.size(); --i >= 0;) { @@ -384,7 +365,7 @@ void Desktop::resetTimer() throw() else startTimer (100); - getMousePosition (lastFakeMouseMoveX, lastFakeMouseMoveY); + lastFakeMouseMove = getMousePosition(); } //============================================================================== diff --git a/src/gui/components/juce_Desktop.h b/src/gui/components/juce_Desktop.h index a42606d53f..187ee658d2 100644 --- a/src/gui/components/juce_Desktop.h +++ b/src/gui/components/juce_Desktop.h @@ -91,7 +91,7 @@ public: If clippedToWorkArea is true, it will exclude any areas like the taskbar on Windows, or the menu bar on Mac. If clippedToWorkArea is false, the entire monitor area is returned. */ - const Rectangle getMonitorAreaContaining (int x, int y, const bool clippedToWorkArea = true) const throw(); + const Rectangle getMonitorAreaContaining (const Point& position, const bool clippedToWorkArea = true) const throw(); //============================================================================== @@ -99,17 +99,17 @@ public: The co-ordinates are relative to the top-left of the main monitor. */ - static void getMousePosition (int& x, int& y) throw(); + static const Point getMousePosition(); /** Makes the mouse pointer jump to a given location. The co-ordinates are relative to the top-left of the main monitor. */ - static void setMousePosition (int x, int y) throw(); + static void setMousePosition (const Point& newPosition); /** Returns the last position at which a mouse button was pressed. */ - static void getLastMouseDownPosition (int& x, int& y) throw(); + static const Point getLastMouseDownPosition() throw(); /** Returns the number of times the mouse button has been clicked since the app started. @@ -218,8 +218,7 @@ public: Returns 0 if the co-ordinates are inside a non-Juce window. */ - Component* findComponentAt (const int screenX, - const int screenY) const; + Component* findComponentAt (const Point& screenPosition) const; //============================================================================== @@ -251,7 +250,8 @@ private: Array > monitorCoordsClipped, monitorCoordsUnclipped; - int lastFakeMouseMoveX, lastFakeMouseMoveY, mouseClickCounter; + Point lastFakeMouseMove; + int mouseClickCounter; bool mouseMovedSignificantlySincePressed; struct RecentMouseDown diff --git a/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp b/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp index 03c02ea4ca..76acf88bdd 100644 --- a/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp +++ b/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp @@ -153,8 +153,7 @@ void ComponentBoundsConstrainer::setBoundsForComponent (Component* const compone if (peer != 0) border = peer->getFrameSize(); - limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentreX(), - bounds.getCentreY()); + limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre()); } else { diff --git a/src/gui/components/layout/juce_ComponentMovementWatcher.cpp b/src/gui/components/layout/juce_ComponentMovementWatcher.cpp index c077cbe2ba..10b77fffe6 100644 --- a/src/gui/components/layout/juce_ComponentMovementWatcher.cpp +++ b/src/gui/components/layout/juce_ComponentMovementWatcher.cpp @@ -98,17 +98,14 @@ void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMove if (wasMoved) { - int x = 0, y = 0; - component->relativePositionToOtherComponent (component->getTopLevelComponent(), x, y); + const Point pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point())); - wasMoved = (lastX != x || lastY != y); - lastX = x; - lastY = y; + wasMoved = lastBounds.getPosition() != pos; + lastBounds.setPosition (pos); } - wasResized = (lastWidth != component->getWidth() || lastHeight != component->getHeight()); - lastWidth = component->getWidth(); - lastHeight = component->getHeight(); + wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight()); + lastBounds.setSize (component->getWidth(), component->getHeight()); if (wasMoved || wasResized) componentMovedOrResized (wasMoved, wasResized); diff --git a/src/gui/components/layout/juce_ComponentMovementWatcher.h b/src/gui/components/layout/juce_ComponentMovementWatcher.h index 612ff2b309..a5c906da59 100644 --- a/src/gui/components/layout/juce_ComponentMovementWatcher.h +++ b/src/gui/components/layout/juce_ComponentMovementWatcher.h @@ -81,7 +81,7 @@ private: ComponentPeer* lastPeer; VoidArray registeredParentComps; bool reentrant; - int lastX, lastY, lastWidth, lastHeight; + Rectangle lastBounds; #ifdef JUCE_DEBUG ScopedPointer deletionWatcher; #endif diff --git a/src/gui/components/menus/juce_MenuBarComponent.cpp b/src/gui/components/menus/juce_MenuBarComponent.cpp index f8298d2f3a..13cb1929ce 100644 --- a/src/gui/components/menus/juce_MenuBarComponent.cpp +++ b/src/gui/components/menus/juce_MenuBarComponent.cpp @@ -279,9 +279,8 @@ void MenuBarComponent::showMenu (int index) if (prevCompDeletionChecker != 0 && ! prevCompDeletionChecker->hasBeenDeleted()) prevFocused->grabKeyboardFocus(); - int mx, my; - getMouseXYRelative (mx, my); - updateItemUnderMouse (mx, my); + const Point mousePos (getMouseXYRelative()); + updateItemUnderMouse (mousePos.getX(), mousePos.getY()); repaint(); if (result != 0) @@ -320,10 +319,9 @@ void MenuBarComponent::mouseExit (const MouseEvent& e) void MenuBarComponent::mouseDown (const MouseEvent& e) { - const MouseEvent e2 (e.getEventRelativeTo (this)); - if (currentPopupIndex < 0) { + const MouseEvent e2 (e.getEventRelativeTo (this)); updateItemUnderMouse (e2.x, e2.y); currentPopupIndex = -2; @@ -440,9 +438,8 @@ void MenuBarComponent::timerCallback() { stopTimer(); - int mx, my; - getMouseXYRelative (mx, my); - updateItemUnderMouse (mx, my); + const Point mousePos (getMouseXYRelative()); + updateItemUnderMouse (mousePos.getX(), mousePos.getY()); } diff --git a/src/gui/components/menus/juce_PopupMenu.cpp b/src/gui/components/menus/juce_PopupMenu.cpp index e8f59b295a..490bbd307b 100644 --- a/src/gui/components/menus/juce_PopupMenu.cpp +++ b/src/gui/components/menus/juce_PopupMenu.cpp @@ -271,8 +271,6 @@ public: menuBarComponent (0), managerOfChosenCommand (0), componentAttachedTo (0), - lastMouseX (0), - lastMouseY (0), minimumWidth (0), maximumNumColumns (7), standardItemHeight (0), @@ -492,7 +490,7 @@ public: void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY) { alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone)); - lastMouseX = -1; + lastMouse = Point (-1, -1); } bool keyPressed (const KeyPress& key) @@ -572,10 +570,9 @@ public: // as they'll expect the menu to go away, and in fact it'll just // come back. So only dismiss synchronously if they're not on the original // comp that we're attached to. - int mx, my; - componentAttachedTo->getMouseXYRelative (mx, my); + const Point mousePos (componentAttachedTo->getMouseXYRelative()); - if (componentAttachedTo->reallyContains (mx, my, true)) + if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true)) { postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously return; @@ -614,16 +611,13 @@ public: startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse // move rather than a real timer callback - int mx, my; - Desktop::getMousePosition (mx, my); - - int x = mx, y = my; - globalPositionToRelative (x, y); + const Point globalMousePos (Desktop::getMousePosition()); + const Point localMousePos (globalPositionToRelative (globalMousePos)); const uint32 now = Time::getMillisecondCounter(); if (now > timeEnteredCurrentChildComp + 100 - && reallyContains (x, y, true) + && reallyContains (localMousePos.getX(), localMousePos.getY(), true) && currentChild->isValidComponent() && (! disableMouseMoves) && ! (activeSubMenu != 0 && activeSubMenu->isVisible())) @@ -631,17 +625,17 @@ public: showSubMenuFor (currentChild); } - if (mx != lastMouseX || my != lastMouseY || now > lastMouseMoveTime + 350) + if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350) { - highlightItemUnderMouse (mx, my, x, y); + highlightItemUnderMouse (globalMousePos, localMousePos); } bool overScrollArea = false; if (isScrolling() - && (isOver || (isDown && ((unsigned int) x) < (unsigned int) getWidth())) - && ((isScrollZoneActive (false) && y < PopupMenuSettings::scrollZone) - || (isScrollZoneActive (true) && y > getHeight() - PopupMenuSettings::scrollZone))) + && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth())) + && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone) + || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone))) { if (now > lastScroll + 20) { @@ -651,13 +645,13 @@ public: for (int i = 0; i < getNumChildComponents() && amount == 0; ++i) amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight(); - alterChildYPos (y < PopupMenuSettings::scrollZone ? -amount : amount); + alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount); lastScroll = now; } overScrollArea = true; - lastMouseX = -1; // trigger a mouse-move + lastMouse = Point (-1, -1); // trigger a mouse-move } else { @@ -669,7 +663,7 @@ public: if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0) { - activeSubMenu->updateMouseOverStatus (mx, my); + activeSubMenu->updateMouseOverStatus (globalMousePos); isOverAny = isOverAnyMenu(); } @@ -715,7 +709,7 @@ public: else if (wasDown && now > menuCreationTime + 250 && ! (isDown || overScrollArea)) { - isOver = reallyContains (x, y, true); + isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true); if (isOver) { @@ -759,7 +753,7 @@ private: Component* componentAttachedTo; ScopedPointer attachedCompWatcher; Rectangle windowPos; - int lastMouseX, lastMouseY; + Point lastMouse; int minimumWidth, maximumNumColumns, standardItemHeight; bool isOver, hasBeenOver, isDown, needsToScroll; bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus; @@ -789,14 +783,13 @@ private: && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren())); } - void updateMouseOverStatus (const int mx, const int my) + void updateMouseOverStatus (const Point& globalMousePos) { - int rx = mx, ry = my; - globalPositionToRelative (rx, ry); - isOver = reallyContains (rx, ry, true); + const Point relPos (globalPositionToRelative (globalMousePos)); + isOver = reallyContains (relPos.getX(), relPos.getY(), true); if (activeSubMenu != 0) - activeSubMenu->updateMouseOverStatus (mx, my); + activeSubMenu->updateMouseOverStatus (globalMousePos); } bool treeContains (const Window* const window) const throw() @@ -823,8 +816,8 @@ private: const bool alignToRectangle) { const Rectangle mon (Desktop::getInstance() - .getMonitorAreaContaining ((minX + maxX) / 2, - (minY + maxY) / 2, + .getMonitorAreaContaining (Point ((minX + maxX) / 2, + (minY + maxY) / 2), #if JUCE_MAC true)); #else @@ -995,10 +988,7 @@ private: windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())), currentY); - const Rectangle mon (Desktop::getInstance() - .getMonitorAreaContaining (windowPos.getX(), - windowPos.getY(), - true)); + const Rectangle mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true)); int deltaY = wantedY - currentY; @@ -1124,15 +1114,13 @@ private: if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu()) { - int left = 0, top = 0; - childComp->relativePositionToGlobal (left, top); - int right = childComp->getWidth(), bottom = childComp->getHeight(); - childComp->relativePositionToGlobal (right, bottom); + const Point topLeft (childComp->relativePositionToGlobal (Point())); + const Point bottomRight (childComp->relativePositionToGlobal (Point (childComp->getWidth(), childComp->getHeight()))); activeSubMenu = Window::create (*(childComp->itemInfo.subMenu), dismissOnMouseUp, this, - left, right, top, bottom, + topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(), 0, maximumNumColumns, standardItemHeight, false, 0, menuBarComponent, @@ -1151,14 +1139,14 @@ private: return false; } - void highlightItemUnderMouse (const int mx, const int my, const int x, const int y) + void highlightItemUnderMouse (const Point& globalMousePos, const Point& localMousePos) { - isOver = reallyContains (x, y, true); + isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true); if (isOver) hasBeenOver = true; - if (abs (lastMouseX - mx) > 2 || abs (lastMouseY - my) > 2) + if (lastMouse.getDistanceFrom (globalMousePos) > 2) { lastMouseMoveTime = Time::getApproximateMillisecondCounter(); @@ -1173,7 +1161,7 @@ private: jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent()) - if (isOver && (activeSubMenu != 0) && (mx != lastMouseX || my != lastMouseY)) + if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse) { // try to intelligently guess whether the user is moving the mouse towards a currently-open // submenu. To do this, look at whether the mouse stays inside a triangular region that @@ -1183,31 +1171,30 @@ private: if (activeSubMenu->getX() > getX()) { - lastMouseX -= 2; // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels + lastMouse -= Point (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels } else { - lastMouseX += 2; + lastMouse += Point (2, 0); subX += activeSubMenu->getWidth(); } Path areaTowardsSubMenu; - areaTowardsSubMenu.addTriangle ((float) lastMouseX, - (float) lastMouseY, + areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(), + (float) lastMouse.getY(), subX, (float) activeSubMenu->getScreenY(), subX, (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight())); - isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) mx, (float) my); + isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY()); } - lastMouseX = mx; - lastMouseY = my; + lastMouse = globalMousePos; if (! isMovingTowardsMenu) { - Component* c = getComponentAt (x, y); + Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY()); if (c == this) c = 0; @@ -1619,10 +1606,9 @@ int PopupMenu::show (const int itemIdThatMustBeVisible, const int maximumNumColumns, const int standardItemHeight) { - int x, y; - Desktop::getMousePosition (x, y); + const Point mousePos (Desktop::getMousePosition()); - return showAt (x, y, + return showAt (mousePos.getX(), mousePos.getY(), itemIdThatMustBeVisible, minimumWidth, maximumNumColumns, diff --git a/src/gui/components/mouse/juce_ComponentDragger.cpp b/src/gui/components/mouse/juce_ComponentDragger.cpp index 9e312a8e45..87bad690e5 100644 --- a/src/gui/components/mouse/juce_ComponentDragger.cpp +++ b/src/gui/components/mouse/juce_ComponentDragger.cpp @@ -33,9 +33,7 @@ BEGIN_JUCE_NAMESPACE //============================================================================== ComponentDragger::ComponentDragger() - : constrainer (0), - originalX (0), - originalY (0) + : constrainer (0) { } @@ -52,9 +50,7 @@ void ComponentDragger::startDraggingComponent (Component* const componentToDrag, if (componentToDrag->isValidComponent()) { constrainer = constrainer_; - originalX = 0; - originalY = 0; - componentToDrag->relativePositionToGlobal (originalX, originalY); + originalPos = componentToDrag->relativePositionToGlobal (Point()); } } @@ -65,23 +61,22 @@ void ComponentDragger::dragComponent (Component* const componentToDrag, const Mo if (componentToDrag->isValidComponent()) { - int x = originalX; - int y = originalY; + Point pos (originalPos); int w = componentToDrag->getWidth(); int h = componentToDrag->getHeight(); const Component* const parentComp = componentToDrag->getParentComponent(); if (parentComp != 0) - parentComp->globalPositionToRelative (x, y); + pos = parentComp->globalPositionToRelative (pos); - x += e.getDistanceFromDragStartX(); - y += e.getDistanceFromDragStartY(); + pos += Point (e.getDistanceFromDragStartX(), + e.getDistanceFromDragStartY()); if (constrainer != 0) - constrainer->setBoundsForComponent (componentToDrag, Rectangle (x, y, w, h), + constrainer->setBoundsForComponent (componentToDrag, Rectangle (pos.getX(), pos.getY(), w, h), false, false, false, false); else - componentToDrag->setBounds (x, y, w, h); + componentToDrag->setBounds (pos.getX(), pos.getY(), w, h); } } diff --git a/src/gui/components/mouse/juce_ComponentDragger.h b/src/gui/components/mouse/juce_ComponentDragger.h index 27ed0cd217..4392ae7f28 100644 --- a/src/gui/components/mouse/juce_ComponentDragger.h +++ b/src/gui/components/mouse/juce_ComponentDragger.h @@ -98,7 +98,7 @@ public: private: ComponentBoundsConstrainer* constrainer; - int originalX, originalY; + Point originalPos; }; #endif // __JUCE_COMPONENTDRAGGER_JUCEHEADER__ diff --git a/src/gui/components/mouse/juce_DragAndDropContainer.cpp b/src/gui/components/mouse/juce_DragAndDropContainer.cpp index a7264e971f..dcbcc0a7f8 100644 --- a/src/gui/components/mouse/juce_DragAndDropContainer.cpp +++ b/src/gui/components/mouse/juce_DragAndDropContainer.cpp @@ -53,7 +53,7 @@ private: DragAndDropTarget* currentlyOver; String dragDesc; - const int imageX, imageY; + const Point imageOffset; bool hasCheckedForExternalDrag, drawImage; DragImageComponent (const DragImageComponent&); @@ -64,14 +64,13 @@ public: const String& desc, Component* const s, DragAndDropContainer* const o, - const int imageX_, const int imageY_) + const Point& imageOffset_) : image (im), source (s), owner (o), currentlyOver (0), dragDesc (desc), - imageX (imageX_), - imageY (imageY_), + imageOffset (imageOffset_), hasCheckedForExternalDrag (false), drawImage (true) { @@ -120,21 +119,19 @@ public: } } - DragAndDropTarget* findTarget (const int screenX, const int screenY, - int& relX, int& relY) const + DragAndDropTarget* findTarget (const Point& screenPos, + Point& relativePos) const { Component* hit = getParentComponent(); if (hit == 0) { - hit = Desktop::getInstance().findComponentAt (screenX, screenY); + hit = Desktop::getInstance().findComponentAt (screenPos); } else { - int rx = screenX, ry = screenY; - hit->globalPositionToRelative (rx, ry); - - hit = hit->getComponentAt (rx, ry); + const Point relPos (hit->globalPositionToRelative (screenPos)); + hit = hit->getComponentAt (relPos.getX(), relPos.getY()); } // (note: use a local copy of the dragDesc member in case the callback runs @@ -147,9 +144,7 @@ public: if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source)) { - relX = screenX; - relY = screenY; - hit->globalPositionToRelative (relX, relY); + relativePos = hit->globalPositionToRelative (screenPos); return ddt; } @@ -168,14 +163,12 @@ public: bool dropAccepted = false; DragAndDropTarget* ddt = 0; - int relX = 0, relY = 0; + Point relPos; if (isVisible()) { setVisible (false); - ddt = findTarget (e.getScreenX(), - e.getScreenY(), - relX, relY); + ddt = findTarget (e.getScreenPosition(), relPos); // fade this component and remove it - it'll be deleted later by the timer callback @@ -189,17 +182,15 @@ public: } else { - int targetX = source->getWidth() / 2; - int targetY = source->getHeight() / 2; - source->relativePositionToGlobal (targetX, targetY); + const Point target (source->relativePositionToGlobal (Point (source->getWidth() / 2, + source->getHeight() / 2))); - int ourCentreX = getWidth() / 2; - int ourCentreY = getHeight() / 2; - relativePositionToGlobal (ourCentreX, ourCentreY); + const Point ourCentre (relativePositionToGlobal (Point (getWidth() / 2, + getHeight() / 2))); fadeOutComponent (120, - targetX - ourCentreX, - targetY - ourCentreY); + target.getX() - ourCentre.getX(), + target.getY() - ourCentre.getY()); } } @@ -215,31 +206,30 @@ public: currentlyOverWatcher = 0; currentlyOver = 0; - ddt->itemDropped (dragDescLocal, source, relX, relY); + ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY()); } // careful - this object could now be deleted.. } } - void updateLocation (const bool canDoExternalDrag, int x, int y) + void updateLocation (const bool canDoExternalDrag, const Point& screenPos) { // (note: use a local copy of the dragDesc member in case the callback runs // a modal loop and deletes this object before it returns) const String dragDescLocal (dragDesc); - int newX = x + imageX; - int newY = y + imageY; + Point newPos (screenPos + imageOffset); if (getParentComponent() != 0) - getParentComponent()->globalPositionToRelative (newX, newY); + newPos = getParentComponent()->globalPositionToRelative (newPos); //if (newX != getX() || newY != getY()) { - setTopLeftPosition (newX, newY); + setTopLeftPosition (newPos.getX(), newPos.getY()); - int relX = 0, relY = 0; - DragAndDropTarget* const ddt = findTarget (x, y, relX, relY); + Point relPos; + DragAndDropTarget* const ddt = findTarget (screenPos, relPos); drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver(); @@ -266,7 +256,7 @@ public: currentlyOverWatcher = new ComponentDeletionWatcher (dynamic_cast (ddt)); if (currentlyOver->isInterestedInDragSource (dragDescLocal, source)) - currentlyOver->itemDragEnter (dragDescLocal, source, relX, relY); + currentlyOver->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY()); } } else if (currentlyOverWatcher != 0 && currentlyOverWatcher->hasBeenDeleted()) @@ -277,13 +267,13 @@ public: if (currentlyOver != 0 && currentlyOver->isInterestedInDragSource (dragDescLocal, source)) - currentlyOver->itemDragMove (dragDescLocal, source, relX, relY); + currentlyOver->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY()); if (currentlyOver == 0 && canDoExternalDrag && ! hasCheckedForExternalDrag) { - if (Desktop::getInstance().findComponentAt (x, y) == 0) + if (Desktop::getInstance().findComponentAt (screenPos) == 0) { hasCheckedForExternalDrag = true; StringArray files; @@ -311,7 +301,7 @@ public: void mouseDrag (const MouseEvent& e) { if (e.originalComponent != this) - updateLocation (true, e.getScreenX(), e.getScreenY()); + updateLocation (true, e.getScreenPosition()); } void timerCallback() @@ -355,9 +345,8 @@ void DragAndDropContainer::startDragging (const String& sourceDescription, if (thisComp != 0) { - int mx, my; - Desktop::getLastMouseDownPosition (mx, my); - int imageX = 0, imageY = 0; + const Point lastMouseDown (Desktop::getLastMouseDownPosition()); + Point imageOffset; if (dragImage == 0) { @@ -377,18 +366,17 @@ void DragAndDropContainer::startDragging (const String& sourceDescription, const int lo = 150; const int hi = 400; - int rx = mx, ry = my; - sourceComponent->globalPositionToRelative (rx, ry); - const int cx = jlimit (0, dragImage->getWidth(), rx); - const int cy = jlimit (0, dragImage->getHeight(), ry); + Point relPos (sourceComponent->globalPositionToRelative (lastMouseDown)); + Point clipped (Rectangle (0, 0, dragImage->getWidth(), dragImage->getHeight()) + .getConstrainedPoint (relPos)); for (int y = dragImage->getHeight(); --y >= 0;) { - const double dy = (y - cy) * (y - cy); + const double dy = (y - clipped.getY()) * (y - clipped.getY()); for (int x = dragImage->getWidth(); --x >= 0;) { - const int dx = x - cx; + const int dx = x - clipped.getX(); const int distance = roundToInt (sqrt (dx * dx + dy)); if (distance > lo) @@ -402,25 +390,19 @@ void DragAndDropContainer::startDragging (const String& sourceDescription, } } - imageX = -cx; - imageY = -cy; + imageOffset = Point() - clipped; } else { if (imageOffsetFromMouse == 0) - { - imageX = dragImage->getWidth() / -2; - imageY = dragImage->getHeight() / -2; - } + imageOffset = Point (dragImage->getWidth() / -2, + dragImage->getHeight() / -2); else - { - imageX = imageOffsetFromMouse->getX(); - imageY = imageOffsetFromMouse->getY(); - } + imageOffset = *imageOffsetFromMouse; } dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent, - this, imageX, imageY); + this, imageOffset); currentDragDesc = sourceDescription; @@ -436,7 +418,7 @@ void DragAndDropContainer::startDragging (const String& sourceDescription, else thisComp->addChildComponent (dragImageComponent); - ((DragImageComponent*) dragImageComponent)->updateLocation (false, mx, my); + ((DragImageComponent*) dragImageComponent)->updateLocation (false, lastMouseDown); dragImageComponent->setVisible (true); } else diff --git a/src/gui/components/mouse/juce_MouseEvent.cpp b/src/gui/components/mouse/juce_MouseEvent.cpp index 964a9ab092..9f7461d5e4 100644 --- a/src/gui/components/mouse/juce_MouseEvent.cpp +++ b/src/gui/components/mouse/juce_MouseEvent.cpp @@ -32,24 +32,21 @@ BEGIN_JUCE_NAMESPACE //============================================================================== -MouseEvent::MouseEvent (const int x_, - const int y_, +MouseEvent::MouseEvent (const Point& position, const ModifierKeys& mods_, Component* const originator, const Time& eventTime_, - const int mouseDownX_, - const int mouseDownY_, + const Point mouseDownPos_, const Time& mouseDownTime_, const int numberOfClicks_, const bool mouseWasDragged) throw() - : x (x_), - y (y_), + : x (position.getX()), + y (position.getY()), mods (mods_), eventComponent (originator), originalComponent (originator), eventTime (eventTime_), - mouseDownX (mouseDownX_), - mouseDownY (mouseDownY_), + mouseDownPos (mouseDownPos_), mouseDownTime (mouseDownTime_), numberOfClicks (numberOfClicks_), wasMovedSinceMouseDown (mouseWasDragged) @@ -68,22 +65,27 @@ bool MouseEvent::mouseWasClicked() const throw() int MouseEvent::getMouseDownX() const throw() { - return mouseDownX; + return mouseDownPos.getX(); } int MouseEvent::getMouseDownY() const throw() { - return mouseDownY; + return mouseDownPos.getY(); +} + +const Point MouseEvent::getMouseDownPosition() const throw() +{ + return mouseDownPos; } int MouseEvent::getDistanceFromDragStartX() const throw() { - return x - mouseDownX; + return x - mouseDownPos.getX(); } int MouseEvent::getDistanceFromDragStartY() const throw() { - return y - mouseDownY; + return y - mouseDownPos.getY(); } int MouseEvent::getDistanceFromDragStart() const throw() @@ -101,32 +103,39 @@ int MouseEvent::getLengthOfMousePress() const throw() } //============================================================================== -int MouseEvent::getScreenX() const throw() +const Point MouseEvent::getPosition() const throw() +{ + return Point (x, y); +} + +int MouseEvent::getScreenX() const +{ + return getScreenPosition().getX(); +} + +int MouseEvent::getScreenY() const { - int sx = x, sy = y; - eventComponent->relativePositionToGlobal (sx, sy); - return sx; + return getScreenPosition().getY(); } -int MouseEvent::getScreenY() const throw() +const Point MouseEvent::getScreenPosition() const { - int sx = x, sy = y; - eventComponent->relativePositionToGlobal (sx, sy); - return sy; + return eventComponent->relativePositionToGlobal (Point (x, y)); } -int MouseEvent::getMouseDownScreenX() const throw() +int MouseEvent::getMouseDownScreenX() const { - int sx = mouseDownX, sy = mouseDownY; - eventComponent->relativePositionToGlobal (sx, sy); - return sx; + return getMouseDownScreenPosition().getX(); } -int MouseEvent::getMouseDownScreenY() const throw() +int MouseEvent::getMouseDownScreenY() const { - int sx = mouseDownX, sy = mouseDownY; - eventComponent->relativePositionToGlobal (sx, sy); - return sy; + return getMouseDownScreenPosition().getY(); +} + +const Point MouseEvent::getMouseDownScreenPosition() const +{ + return eventComponent->relativePositionToGlobal (mouseDownPos); } //============================================================================== @@ -138,13 +147,14 @@ const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent return *this; } - MouseEvent me (*this); - - eventComponent->relativePositionToOtherComponent (otherComponent, me.x, me.y); - eventComponent->relativePositionToOtherComponent (otherComponent, me.mouseDownX, me.mouseDownY); - me.eventComponent = otherComponent; - - return me; + return MouseEvent (eventComponent->relativePositionToOtherComponent (otherComponent, Point (x, y)), + mods, + originalComponent, + eventTime, + eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos), + mouseDownTime, + numberOfClicks, + wasMovedSinceMouseDown); } //============================================================================== diff --git a/src/gui/components/mouse/juce_MouseEvent.h b/src/gui/components/mouse/juce_MouseEvent.h index ff4d50b96e..acc6153119 100644 --- a/src/gui/components/mouse/juce_MouseEvent.h +++ b/src/gui/components/mouse/juce_MouseEvent.h @@ -29,6 +29,7 @@ class Component; #include "../keyboard/juce_ModifierKeys.h" #include "../../../core/juce_Time.h" +#include "../../graphics/geometry/juce_Point.h" //============================================================================== @@ -46,29 +47,24 @@ public: Normally an application will never need to use this. - @param x the x position of the mouse, relative to the component that is passed-in - @param y the y position of the mouse, relative to the component that is passed-in + @param position the position of the mouse, relative to the component that is passed-in @param modifiers the key modifiers at the time of the event @param originator the component that the mouse event applies to @param eventTime the time the event happened - @param mouseDownX the x position of the corresponding mouse-down event (relative to the component that is passed-in). + @param mouseDownPos the position of the corresponding mouse-down event (relative to the component that is passed-in). If there isn't a corresponding mouse-down (e.g. for a mouse-move), this will just be the same as the current mouse-x position. - @param mouseDownY the y position of the corresponding mouse-down event (relative to the component that is passed-in) - If there isn't a corresponding mouse-down (e.g. for a mouse-move), this will just be - the same as the current mouse-y position. @param mouseDownTime the time at which the corresponding mouse-down event happened If there isn't a corresponding mouse-down (e.g. for a mouse-move), this will just be the same as the current mouse-event time. @param numberOfClicks how many clicks, e.g. a double-click event will be 2, a triple-click will be 3, etc @param mouseWasDragged whether the mouse has been dragged significantly since the previous mouse-down */ - MouseEvent (const int x, const int y, + MouseEvent (const Point& position, const ModifierKeys& modifiers, Component* const originator, const Time& eventTime, - const int mouseDownX, - const int mouseDownY, + const Point mouseDownPos, const Time& mouseDownTime, const int numberOfClicks, const bool mouseWasDragged) throw(); @@ -146,6 +142,14 @@ public: */ int getMouseDownY() const throw(); + /** Returns the co-ordinates of the last place that a mouse was pressed. + + The co-ordinates are relative to the component specified in MouseEvent::component. + + @see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked + */ + const Point getMouseDownPosition() const throw(); + /** Returns the straight-line distance between where the mouse is now and where it was the last time the button was pressed. @@ -203,13 +207,20 @@ public: int getLengthOfMousePress() const throw(); //============================================================================== + /** The position of the mouse when the event occurred. + + This position is relative to the top-left of the component to which the + event applies (as indicated by the MouseEvent::eventComponent field). + */ + const Point getPosition() const throw(); + /** Returns the mouse x position of this event, in global screen co-ordinates. The co-ordinates are relative to the top-left of the main monitor. @see getMouseDownScreenX, Desktop::getMousePosition */ - int getScreenX() const throw(); + int getScreenX() const; /** Returns the mouse y position of this event, in global screen co-ordinates. @@ -217,7 +228,15 @@ public: @see getMouseDownScreenY, Desktop::getMousePosition */ - int getScreenY() const throw(); + int getScreenY() const; + + /** Returns the mouse position of this event, in global screen co-ordinates. + + The co-ordinates are relative to the top-left of the main monitor. + + @see getMouseDownScreenY, Desktop::getMousePosition + */ + const Point getScreenPosition() const; /** Returns the x co-ordinate at which the mouse button was last pressed. @@ -225,7 +244,7 @@ public: @see getScreenX, Desktop::getMousePosition */ - int getMouseDownScreenX() const throw(); + int getMouseDownScreenX() const; /** Returns the y co-ordinate at which the mouse button was last pressed. @@ -233,7 +252,15 @@ public: @see getScreenY, Desktop::getMousePosition */ - int getMouseDownScreenY() const throw(); + int getMouseDownScreenY() const; + + /** Returns the co-ordinates at which the mouse button was last pressed. + + The co-ordinates are relative to the top-left of the main monitor. + + @see getScreenY, Desktop::getMousePosition + */ + const Point getMouseDownScreenPosition() const; //============================================================================== /** Creates a version of this event that is relative to a different component. @@ -267,7 +294,7 @@ public: juce_UseDebuggingNewOperator private: - int mouseDownX, mouseDownY; + Point mouseDownPos; Time mouseDownTime; int numberOfClicks; bool wasMovedSinceMouseDown; diff --git a/src/gui/components/mouse/juce_MouseHoverDetector.cpp b/src/gui/components/mouse/juce_MouseHoverDetector.cpp index f3d3be5138..c9ed5c8345 100644 --- a/src/gui/components/mouse/juce_MouseHoverDetector.cpp +++ b/src/gui/components/mouse/juce_MouseHoverDetector.cpp @@ -78,13 +78,12 @@ void MouseHoverDetector::hoverTimerCallback() if (source != 0) { - int mx, my; - source->getMouseXYRelative (mx, my); + const Point pos (source->getMouseXYRelative()); - if (source->reallyContains (mx, my, false)) + if (source->reallyContains (pos.getX(), pos.getY(), false)) { hasJustHovered = true; - mouseHovered (mx, my); + mouseHovered (pos.getX(), pos.getY()); } } } diff --git a/src/gui/components/special/juce_BubbleComponent.cpp b/src/gui/components/special/juce_BubbleComponent.cpp index 90b7b6ccc7..6cc81577a0 100644 --- a/src/gui/components/special/juce_BubbleComponent.cpp +++ b/src/gui/components/special/juce_BubbleComponent.cpp @@ -98,15 +98,14 @@ void BubbleComponent::setPosition (Component* componentToPointTo) { jassert (componentToPointTo->isValidComponent()); - int tx = 0; - int ty = 0; + Point pos; if (getParentComponent() != 0) - componentToPointTo->relativePositionToOtherComponent (getParentComponent(), tx, ty); + pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos); else - componentToPointTo->relativePositionToGlobal (tx, ty); + pos = componentToPointTo->relativePositionToGlobal (pos); - setPosition (Rectangle (tx, ty, componentToPointTo->getWidth(), componentToPointTo->getHeight())); + setPosition (Rectangle (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight())); } void BubbleComponent::setPosition (const int arrowTipX_, diff --git a/src/gui/components/special/juce_MagnifierComponent.cpp b/src/gui/components/special/juce_MagnifierComponent.cpp index cc5b504579..8af123d227 100644 --- a/src/gui/components/special/juce_MagnifierComponent.cpp +++ b/src/gui/components/special/juce_MagnifierComponent.cpp @@ -76,11 +76,11 @@ public: peer->grabFocus(); } - void textInputRequired (int x, int y) + void textInputRequired (const Point& position) { ComponentPeer* peer = magnifierComp->getPeer(); if (peer != 0) - peer->textInputRequired (x, y); + peer->textInputRequired (position); } void getBounds (int& x, int& y, int& w, int& h) const @@ -91,25 +91,25 @@ public: h = component->getHeight(); } - int getScreenX() const { return magnifierComp->getScreenX(); } - int getScreenY() const { return magnifierComp->getScreenY(); } + const Point getScreenPosition() const + { + return magnifierComp->getScreenPosition(); + } - void relativePositionToGlobal (int& x, int& y) + const Point relativePositionToGlobal (const Point& relativePosition) { const double zoom = magnifierComp->getScaleFactor(); - x = roundToInt (x * zoom); - y = roundToInt (y * zoom); - - magnifierComp->relativePositionToGlobal (x, y); + return magnifierComp->relativePositionToGlobal (Point (roundToInt (relativePosition.getX() * zoom), + roundToInt (relativePosition.getY() * zoom))); } - void globalPositionToRelative (int& x, int& y) + const Point globalPositionToRelative (const Point& screenPosition) { - magnifierComp->globalPositionToRelative (x, y); - + const Point p (magnifierComp->globalPositionToRelative (screenPosition)); const double zoom = magnifierComp->getScaleFactor(); - x = roundToInt (x / zoom); - y = roundToInt (y / zoom); + + return Point (roundToInt (p.getX() / zoom), + roundToInt (p.getY() / zoom)); } bool contains (int x, int y, bool) const diff --git a/src/gui/components/special/juce_MidiKeyboardComponent.cpp b/src/gui/components/special/juce_MidiKeyboardComponent.cpp index a81baa0f81..e466f94a81 100644 --- a/src/gui/components/special/juce_MidiKeyboardComponent.cpp +++ b/src/gui/components/special/juce_MidiKeyboardComponent.cpp @@ -251,27 +251,29 @@ int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 }; static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 }; -int MidiKeyboardComponent::xyToNote (int x, int y, float& mousePositionVelocity) +int MidiKeyboardComponent::xyToNote (const Point& pos, float& mousePositionVelocity) { - if (! reallyContains (x, y, false)) + if (! reallyContains (pos.getX(), pos.getY(), false)) return -1; + Point p (pos); + if (orientation != horizontalKeyboard) { - swapVariables (x, y); + p = Point (p.getY(), p.getX()); if (orientation == verticalKeyboardFacingLeft) - y = getWidth() - y; + p = Point (p.getX(), getWidth() - p.getY()); else - x = getHeight() - x; + p = Point (getHeight() - p.getX(), p.getY()); } - return remappedXYToNote (x + xOffset, y, mousePositionVelocity); + return remappedXYToNote (p + Point (xOffset, 0), mousePositionVelocity); } -int MidiKeyboardComponent::remappedXYToNote (int x, int y, float& mousePositionVelocity) const +int MidiKeyboardComponent::remappedXYToNote (const Point& pos, float& mousePositionVelocity) const { - if (y < blackNoteLength) + if (pos.getY() < blackNoteLength) { for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12) { @@ -285,9 +287,9 @@ int MidiKeyboardComponent::remappedXYToNote (int x, int y, float& mousePositionV getKeyPos (note, kx, kw); kx += xOffset; - if (x >= kx && x < kx + kw) + if (pos.getX() >= kx && pos.getX() < kx + kw) { - mousePositionVelocity = y / (float) blackNoteLength; + mousePositionVelocity = pos.getY() / (float) blackNoteLength; return note; } } @@ -307,10 +309,10 @@ int MidiKeyboardComponent::remappedXYToNote (int x, int y, float& mousePositionV getKeyPos (note, kx, kw); kx += xOffset; - if (x >= kx && x < kx + kw) + if (pos.getX() >= kx && pos.getX() < kx + kw) { const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth(); - mousePositionVelocity = y / (float) whiteNoteLength; + mousePositionVelocity = pos.getY() / (float) whiteNoteLength; return note; } } @@ -643,7 +645,7 @@ void MidiKeyboardComponent::resized() float mousePositionVelocity; const int spaceAvailable = w - scrollButtonW * 2; - const int lastStartKey = remappedXYToNote (endOfLastKey - spaceAvailable, 0, mousePositionVelocity) + 1; + const int lastStartKey = remappedXYToNote (Point (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1; if (lastStartKey >= 0 && firstKey > lastStartKey) { @@ -699,11 +701,11 @@ void MidiKeyboardComponent::resetAnyKeysInUse() } } -void MidiKeyboardComponent::updateNoteUnderMouse (int x, int y) +void MidiKeyboardComponent::updateNoteUnderMouse (const Point& pos) { float mousePositionVelocity = 0.0f; const int newNote = (mouseDragging || isMouseOver()) - ? xyToNote (x, y, mousePositionVelocity) : -1; + ? xyToNote (pos, mousePositionVelocity) : -1; if (noteUnderMouse != newNote) { @@ -735,19 +737,19 @@ void MidiKeyboardComponent::updateNoteUnderMouse (int x, int y) void MidiKeyboardComponent::mouseMove (const MouseEvent& e) { - updateNoteUnderMouse (e.x, e.y); + updateNoteUnderMouse (e.getPosition()); stopTimer(); } void MidiKeyboardComponent::mouseDrag (const MouseEvent& e) { float mousePositionVelocity; - const int newNote = xyToNote (e.x, e.y, mousePositionVelocity); + const int newNote = xyToNote (e.getPosition(), mousePositionVelocity); if (newNote >= 0) mouseDraggedToKey (newNote, e); - updateNoteUnderMouse (e.x, e.y); + updateNoteUnderMouse (e.getPosition()); } bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&) @@ -762,7 +764,7 @@ void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const Mou void MidiKeyboardComponent::mouseDown (const MouseEvent& e) { float mousePositionVelocity; - const int newNote = xyToNote (e.x, e.y, mousePositionVelocity); + const int newNote = xyToNote (e.getPosition(), mousePositionVelocity); mouseDragging = false; if (newNote >= 0 && mouseDownOnKey (newNote, e)) @@ -771,7 +773,7 @@ void MidiKeyboardComponent::mouseDown (const MouseEvent& e) noteUnderMouse = -1; mouseDragging = true; - updateNoteUnderMouse (e.x, e.y); + updateNoteUnderMouse (e.getPosition()); startTimer (500); } } @@ -779,19 +781,19 @@ void MidiKeyboardComponent::mouseDown (const MouseEvent& e) void MidiKeyboardComponent::mouseUp (const MouseEvent& e) { mouseDragging = false; - updateNoteUnderMouse (e.x, e.y); + updateNoteUnderMouse (e.getPosition()); stopTimer(); } void MidiKeyboardComponent::mouseEnter (const MouseEvent& e) { - updateNoteUnderMouse (e.x, e.y); + updateNoteUnderMouse (e.getPosition()); } void MidiKeyboardComponent::mouseExit (const MouseEvent& e) { - updateNoteUnderMouse (e.x, e.y); + updateNoteUnderMouse (e.getPosition()); } void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy) @@ -801,10 +803,7 @@ void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float i void MidiKeyboardComponent::timerCallback() { - int mx, my; - getMouseXYRelative (mx, my); - - updateNoteUnderMouse (mx, my); + updateNoteUnderMouse (getMouseXYRelative()); } //============================================================================== diff --git a/src/gui/components/special/juce_MidiKeyboardComponent.h b/src/gui/components/special/juce_MidiKeyboardComponent.h index 26823677a8..6b9b1b2fb4 100644 --- a/src/gui/components/special/juce_MidiKeyboardComponent.h +++ b/src/gui/components/special/juce_MidiKeyboardComponent.h @@ -405,10 +405,10 @@ private: int octaveNumForMiddleC; void getKeyPos (int midiNoteNumber, int& x, int& w) const; - int xyToNote (int x, int y, float& mousePositionVelocity); - int remappedXYToNote (int x, int y, float& mousePositionVelocity) const; + int xyToNote (const Point& pos, float& mousePositionVelocity); + int remappedXYToNote (const Point& pos, float& mousePositionVelocity) const; void resetAnyKeysInUse(); - void updateNoteUnderMouse (int x, int y); + void updateNoteUnderMouse (const Point& pos); void repaintNote (const int midiNoteNumber); MidiKeyboardComponent (const MidiKeyboardComponent&); diff --git a/src/gui/components/special/juce_OpenGLComponent.cpp b/src/gui/components/special/juce_OpenGLComponent.cpp index 1d2f96e020..cdb12056f4 100644 --- a/src/gui/components/special/juce_OpenGLComponent.cpp +++ b/src/gui/components/special/juce_OpenGLComponent.cpp @@ -259,9 +259,8 @@ void OpenGLComponent::paint (Graphics&) if (peer != 0) { - peer->addMaskedRegion (getScreenX() - peer->getScreenX(), - getScreenY() - peer->getScreenY(), - getWidth(), getHeight()); + const Point topLeft (getScreenPosition() - peer->getScreenPosition()); + peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight()); } } } diff --git a/src/gui/components/windows/juce_ComponentPeer.cpp b/src/gui/components/windows/juce_ComponentPeer.cpp index b7ab509f4c..e68880d506 100644 --- a/src/gui/components/windows/juce_ComponentPeer.cpp +++ b/src/gui/components/windows/juce_ComponentPeer.cpp @@ -114,24 +114,22 @@ void ComponentPeer::handleMouseEnter (int x, int y, const int64 time) { jassert (Component::componentUnderMouse->isValidComponent()); - const int oldX = x; - const int oldY = y; - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseExit (x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time); Component::componentUnderMouse = 0; if (deletionChecker.hasBeenDeleted()) return; - c = component->getComponentAt (oldX, oldY); + c = component->getComponentAt (x, y); } Component::componentUnderMouse = c; if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseEnter (x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseEnter (relPos.getX(), relPos.getY(), time); } } @@ -147,16 +145,10 @@ void ComponentPeer::handleMouseMove (int x, int y, const int64 time) if (c != Component::componentUnderMouse) { - const int oldX = x; - const int oldY = y; - if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseExit (x, y, time); - x = oldX; - y = oldY; - + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time); Component::componentUnderMouse = 0; if (deletionChecker.hasBeenDeleted()) @@ -169,10 +161,8 @@ void ComponentPeer::handleMouseMove (int x, int y, const int64 time) if (c != 0) { - component->relativePositionToOtherComponent (c, x, y); - c->internalMouseEnter (x, y, time); - x = oldX; - y = oldY; + const Point relPos (component->relativePositionToOtherComponent (c, Point (x, y))); + c->internalMouseEnter (relPos.getX(), relPos.getY(), time); if (deletionChecker.hasBeenDeleted()) return; // if this window has just been deleted.. @@ -181,8 +171,8 @@ void ComponentPeer::handleMouseMove (int x, int y, const int64 time) if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseMove (x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseMove (relPos.getX(), relPos.getY(), time); } } @@ -197,8 +187,8 @@ void ComponentPeer::handleMouseDown (int x, int y, const int64 time) if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseDown (x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseDown (relPos.getX(), relPos.getY(), time); } } } @@ -209,8 +199,8 @@ void ComponentPeer::handleMouseDrag (int x, int y, const int64 time) if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseDrag (x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseDrag (relPos.getX(), relPos.getY(), time); } } @@ -225,39 +215,34 @@ void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const i if (c != Component::componentUnderMouse) { - const int oldX = x; - const int oldY = y; - if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time); - x = oldX; - y = oldY; + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseUp (oldModifiers, relPos.getX(), relPos.getY(), time); if (Component::componentUnderMouse != 0) - Component::componentUnderMouse->internalMouseExit (x, y, time); + Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time); if (deletionChecker.hasBeenDeleted()) return; - c = component->getComponentAt (oldX, oldY); + c = component->getComponentAt (x, y); } Component::componentUnderMouse = c; if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseEnter (x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseEnter (relPos.getX(), relPos.getY(), time); } } else { if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseUp (oldModifiers, relPos.getX(), relPos.getY(), time); } } } @@ -270,9 +255,8 @@ void ComponentPeer::handleMouseExit (int x, int y, const int64 time) if (Component::componentUnderMouse != 0) { - component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y); - - Component::componentUnderMouse->internalMouseExit (x, y, time); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time); Component::componentUnderMouse = 0; } } @@ -299,14 +283,13 @@ void ComponentPeer::sendFakeMouseMove() throw() component->bounds_.setBounds (realX, realY, realW, realH); } - int x, y; - component->getMouseXYRelative (x, y); + const Point pos (component->getMouseXYRelative()); - if (((unsigned int) x) < (unsigned int) component->getWidth() - && ((unsigned int) y) < (unsigned int) component->getHeight() - && contains (x, y, false)) + if (((unsigned int) pos.getX()) < (unsigned int) component->getWidth() + && ((unsigned int) pos.getY()) < (unsigned int) component->getHeight() + && contains (pos.getX(), pos.getY(), false)) { - postMessage (new Message (fakeMouseMoveMessage, x, y, 0)); + postMessage (new Message (fakeMouseMoveMessage, pos.getX(), pos.getY(), 0)); } fakeMouseMessageSent = true; @@ -638,11 +621,10 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y) if (newTarget != 0) { Component* const targetComp = dynamic_cast (newTarget); - int mx = x, my = y; - component->relativePositionToOtherComponent (targetComp, mx, my); + const Point pos (component->relativePositionToOtherComponent (targetComp, Point (x, y))); dragAndDropTargetComponent = new ComponentDeletionWatcher (dynamic_cast (newTarget)); - newTarget->fileDragEnter (files, mx, my); + newTarget->fileDragEnter (files, pos.getX(), pos.getY()); } } } @@ -654,9 +636,9 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y) if (newTarget != 0) { Component* const targetComp = dynamic_cast (newTarget); - component->relativePositionToOtherComponent (targetComp, x, y); + const Point pos (component->relativePositionToOtherComponent (targetComp, Point (x, y))); - newTarget->fileDragMove (files, x, y); + newTarget->fileDragMove (files, pos.getX(), pos.getY()); } } @@ -691,8 +673,8 @@ void ComponentPeer::handleFileDragDrop (const StringArray& files, int x, int y) return; } - component->relativePositionToOtherComponent (targetComp, x, y); - target->filesDropped (files, x, y); + const Point pos (component->relativePositionToOtherComponent (targetComp, Point (x, y))); + target->filesDropped (files, pos.getX(), pos.getY()); } } } diff --git a/src/gui/components/windows/juce_ComponentPeer.h b/src/gui/components/windows/juce_ComponentPeer.h index 0cfbfec4d5..a71cb744d9 100644 --- a/src/gui/components/windows/juce_ComponentPeer.h +++ b/src/gui/components/windows/juce_ComponentPeer.h @@ -150,16 +150,13 @@ public: virtual void getBounds (int& x, int& y, int& w, int& h) const = 0; /** Returns the x-position of this window, relative to the screen's origin. */ - virtual int getScreenX() const = 0; - - /** Returns the y-position of this window, relative to the screen's origin. */ - virtual int getScreenY() const = 0; + virtual const Point getScreenPosition() const = 0; /** Converts a position relative to the top-left of this component to screen co-ordinates. */ - virtual void relativePositionToGlobal (int& x, int& y) = 0; + virtual const Point relativePositionToGlobal (const Point& relativePosition) = 0; /** Converts a screen co-ordinate to a position relative to the top-left of this component. */ - virtual void globalPositionToRelative (int& x, int& y) = 0; + virtual const Point globalPositionToRelative (const Point& screenPosition) = 0; /** Minimises the window. */ virtual void setMinimised (bool shouldBeMinimised) = 0; @@ -255,7 +252,7 @@ public: This may cause things like a virtual on-screen keyboard to appear, depending on the OS. */ - virtual void textInputRequired (int x, int y) = 0; + virtual void textInputRequired (const Point& position) = 0; /** Called when the window gains keyboard focus. */ void handleFocusGain(); diff --git a/src/gui/components/windows/juce_ResizableWindow.cpp b/src/gui/components/windows/juce_ResizableWindow.cpp index f8f88cadb7..6ba351c6fc 100644 --- a/src/gui/components/windows/juce_ResizableWindow.cpp +++ b/src/gui/components/windows/juce_ResizableWindow.cpp @@ -475,8 +475,7 @@ bool ResizableWindow::restoreWindowStateFromString (const String& s) if (newPos.isEmpty()) return false; - const Rectangle screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentreX(), - newPos.getCentreY())); + const Rectangle screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre())); ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0; if (peer != 0) diff --git a/src/gui/components/windows/juce_TooltipWindow.cpp b/src/gui/components/windows/juce_TooltipWindow.cpp index 2d3ecc3cc4..1c39f0264d 100644 --- a/src/gui/components/windows/juce_TooltipWindow.cpp +++ b/src/gui/components/windows/juce_TooltipWindow.cpp @@ -40,8 +40,6 @@ TooltipWindow::TooltipWindow (Component* const parentComponent, const int millisecondsBeforeTipAppears_) : Component ("tooltip"), millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_), - mouseX (0), - mouseY (0), lastHideTime (0), lastComponentUnderMouse (0), changedCompsSinceShown (true) @@ -80,24 +78,23 @@ void TooltipWindow::showFor (const String& tip) jassert (tip.isNotEmpty()); tipShowing = tip; - int mx, my; - Desktop::getMousePosition (mx, my); + Point mousePos (Desktop::getMousePosition()); if (getParentComponent() != 0) - getParentComponent()->globalPositionToRelative (mx, my); + mousePos = getParentComponent()->globalPositionToRelative (mousePos); int x, y, w, h; getLookAndFeel().getTooltipSize (tip, w, h); - if (mx > getParentWidth() / 2) - x = mx - (w + 12); + if (mousePos.getX() > getParentWidth() / 2) + x = mousePos.getX() - (w + 12); else - x = mx + 24; + x = mousePos.getX() + 24; - if (my > getParentHeight() / 2) - y = my - (h + 6); + if (mousePos.getY() > getParentHeight() / 2) + y = mousePos.getY() - (h + 6); else - y = my + 6; + y = mousePos.getY() + 6; setBounds (x, y, w, h); setVisible (true); @@ -148,11 +145,9 @@ void TooltipWindow::timerCallback() const bool mouseWasClicked = clickCount > mouseClicks; mouseClicks = clickCount; - int mx, my; - Desktop::getMousePosition (mx, my); - const bool mouseMovedQuickly = (abs (mx - mouseX) + abs (my - mouseY) > 12); - mouseX = mx; - mouseY = my; + const Point mousePos (Desktop::getMousePosition()); + const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12; + lastMousePos = mousePos; if (tipChanged || mouseWasClicked || mouseMovedQuickly) lastCompChangeTime = now; diff --git a/src/gui/components/windows/juce_TooltipWindow.h b/src/gui/components/windows/juce_TooltipWindow.h index 64ff63c89b..26b1a91ed0 100644 --- a/src/gui/components/windows/juce_TooltipWindow.h +++ b/src/gui/components/windows/juce_TooltipWindow.h @@ -100,7 +100,8 @@ public: private: //============================================================================== int millisecondsBeforeTipAppears; - int mouseX, mouseY, mouseClicks; + Point lastMousePos; + int mouseClicks; unsigned int lastCompChangeTime, lastHideTime; Component* lastComponentUnderMouse; bool changedCompsSinceShown; diff --git a/src/gui/components/windows/juce_TopLevelWindow.cpp b/src/gui/components/windows/juce_TopLevelWindow.cpp index cd22adab64..3d928694d4 100644 --- a/src/gui/components/windows/juce_TopLevelWindow.cpp +++ b/src/gui/components/windows/juce_TopLevelWindow.cpp @@ -291,22 +291,21 @@ void TopLevelWindow::centreAroundComponent (Component* c, const int width, const } else { - int x = (c->getWidth() - width) / 2; - int y = (c->getHeight() - height) / 2; - c->relativePositionToGlobal (x, y); + Point p (c->relativePositionToGlobal (Point ((c->getWidth() - width) / 2, + (c->getHeight() - height) / 2))); Rectangle parentArea (c->getParentMonitorArea()); if (getParentComponent() != 0) { - getParentComponent()->globalPositionToRelative (x, y); + p = getParentComponent()->globalPositionToRelative (p); parentArea.setBounds (0, 0, getParentWidth(), getParentHeight()); } parentArea.reduce (12, 12); - setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), x), - jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), y), + setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()), + jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()), width, height); } } diff --git a/src/gui/graphics/geometry/juce_Point.h b/src/gui/graphics/geometry/juce_Point.h index 17077bfc02..317408365e 100644 --- a/src/gui/graphics/geometry/juce_Point.h +++ b/src/gui/graphics/geometry/juce_Point.h @@ -65,6 +65,12 @@ public: /** Returns the point's y co-ordinate. */ inline ValueType getY() const throw() { return y; } + inline bool operator== (const Point& other) const throw() { return x == other.x && y == other.y; } + inline bool operator!= (const Point& other) const throw() { return x != other.x || y != other.y; } + + /** Returns true if the point is (0, 0). */ + bool isOrigin() const throw() { return x == ValueType() && y == ValueType(); } + /** Changes the point's x and y co-ordinates. */ void setXY (const ValueType newX, const ValueType newY) throw() { x = newX; y = newY; } @@ -83,13 +89,15 @@ public: /** Subtracts another point's co-ordinates to this one. */ Point& operator-= (const Point& other) throw() { x -= other.x; y -= other.y; return *this; } + /** Returns the straight-line distance between this point and another one. */ + ValueType getDistanceFrom (const Point& other) const throw() { return (ValueType) juce_hypot (x - other.x, y - other.y); } + /** Uses a transform to change the point's co-ordinates. This will only compile if ValueType = float! @see AffineTransform::transformPoint */ void applyTransform (const AffineTransform& transform) throw() { transform.transformPoint (x, y); } - //============================================================================== juce_UseDebuggingNewOperator diff --git a/src/gui/graphics/geometry/juce_Rectangle.h b/src/gui/graphics/geometry/juce_Rectangle.h index 0e9fba48e7..f970ecb6ad 100644 --- a/src/gui/graphics/geometry/juce_Rectangle.h +++ b/src/gui/graphics/geometry/juce_Rectangle.h @@ -107,6 +107,8 @@ public: /** Returns the y co-ordinate of the rectangle's centre. */ inline ValueType getCentreY() const throw() { return y + h / (ValueType) 2; } + inline const Point getCentre() const throw() { return Point (x + w / (ValueType) 2, y + h / (ValueType) 2); } + /** Returns true if the rectangle's width and height are both zero or less */ bool isEmpty() const throw() { return w <= 0 || h <= 0; } @@ -114,6 +116,9 @@ public: /** Returns the rectangle's top-left position as a Point. */ const Point getPosition() const throw() { return Point (x, y); } + /** Changes the position of the rectangle's top-left corner (leaving its size unchanged). */ + void setPosition (const Point& newPos) throw() { x = newPos.getX(); y = newPos.getY(); } + /** Changes the position of the rectangle's top-left corner (leaving its size unchanged). */ void setPosition (const ValueType newX, const ValueType newY) throw() { x = newX; y = newY; } @@ -256,6 +261,12 @@ public: return xCoord >= x && yCoord >= y && xCoord < x + w && yCoord < y + h; } + /** Returns true if this co-ordinate is inside the rectangle. */ + bool contains (const Point point) const throw() + { + return point.getX() >= x && point.getY() >= y && point.getX() < x + w && point.getY() < y + h; + } + /** Returns true if this other rectangle is completely inside this one. */ bool contains (const Rectangle& other) const throw() { @@ -263,6 +274,13 @@ public: && x + w >= other.x + other.w && y + h >= other.y + other.h; } + /** Returns the nearest point to the specified point that lies within this rectangle. */ + const Point getConstrainedPoint (const Point& point) const throw() + { + return Point (jlimit (x, x + w, point.getX()), + jlimit (y, y + h, point.getY())); + } + /** Returns true if any part of another rectangle overlaps this one. */ bool intersects (const Rectangle& other) const throw() { diff --git a/src/native/linux/juce_linux_Windowing.cpp b/src/native/linux/juce_linux_Windowing.cpp index 02e12a0e80..9725c8c549 100644 --- a/src/native/linux/juce_linux_Windowing.cpp +++ b/src/native/linux/juce_linux_Windowing.cpp @@ -111,7 +111,7 @@ static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | Butto //============================================================================== static int pointerMap[5]; -static int lastMousePosX = 0, lastMousePosY = 0; +static Point lastMousePos; enum MouseButtons { @@ -789,26 +789,19 @@ public: h = wh; } - int getScreenX() const + const Point getScreenPosition() const { - return wx; + return Point (wx, wy); } - int getScreenY() const + const Point relativePositionToGlobal (const Point& relativePosition) { - return wy; + return relativePosition + getScreenPosition(); } - void relativePositionToGlobal (int& x, int& y) + const Point globalPositionToRelative (const Point& screenPosition) { - x += wx; - y += wy; - } - - void globalPositionToRelative (int& x, int& y) - { - x -= wx; - y -= wy; + return screenPosition - getScreenPosition(); } void setMinimised (bool shouldBeMinimised) @@ -1091,7 +1084,7 @@ public: } } - void textInputRequired (int /*x*/, int /*y*/) + void textInputRequired (const Point&) { } @@ -1352,7 +1345,7 @@ public: getEventTime (buttonPressEvent->time)); } - lastMousePosX = lastMousePosY = 0x100000; + lastMousePos = Point (0x100000, 0x100000); break; } @@ -1376,7 +1369,7 @@ public: buttonRelEvent->x, buttonRelEvent->y, getEventTime (buttonRelEvent->time)); - lastMousePosX = lastMousePosY = 0x100000; + lastMousePos = Point (0x100000, 0x100000); break; } @@ -1386,13 +1379,11 @@ public: updateKeyModifiers (movedEvent->state); - int x, y, mouseMods; - getMousePos (x, y, mouseMods); + Point mousePos (Desktop::getMousePosition()); - if (lastMousePosX != x || lastMousePosY != y) + if (lastMousePos != mousePos) { - lastMousePosX = x; - lastMousePosY = y; + lastMousePos = mousePos; if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0) { @@ -1411,26 +1402,23 @@ public: { parentWindow = wParent; updateBounds(); - x -= getScreenX(); - y -= getScreenY(); + mousePos -= getScreenPosition(); } else { parentWindow = 0; - x -= getScreenX(); - y -= getScreenY(); + mousePos -= getScreenPosition(); } } else { - x -= getScreenX(); - y -= getScreenY(); + mousePos -= getScreenPosition(); } if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0) - handleMouseMove (x, y, getEventTime (movedEvent->time)); + handleMouseMove (mousePos.getX(), mousePos.getY(), getEventTime (movedEvent->time)); else - handleMouseDrag (x, y, getEventTime (movedEvent->time)); + handleMouseDrag (mousePos.getX(), mousePos.getY(), getEventTime (movedEvent->time)); } break; @@ -1438,7 +1426,7 @@ public: case EnterNotify: { - lastMousePosX = lastMousePosY = 0x100000; + lastMousePos = Point (0x100000, 0x100000); const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing; if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0 @@ -2336,7 +2324,7 @@ private: void resetDragAndDrop() { dragAndDropFiles.clear(); - lastDropX = lastDropY = -1; + lastDropPos = Point (-1, -1); dragAndDropCurrentMimeType = 0; dragAndDropSourceWindow = 0; srcMimeTypeAtomList.clear(); @@ -2401,14 +2389,13 @@ private: dragAndDropSourceWindow = clientMsg->data.l[0]; - const int dropX = ((int) clientMsg->data.l[2] >> 16) - getScreenX(); - const int dropY = ((int) clientMsg->data.l[2] & 0xffff) - getScreenY(); + Point dropPos ((int) clientMsg->data.l[2] >> 16, + (int) clientMsg->data.l[2] & 0xffff); + dropPos -= getScreenPosition(); - if (lastDropX != dropX || lastDropY != dropY) + if (lastDropPos != dropPos) { - lastDropX = dropX; - lastDropY = dropY; - + lastDropPos = dropPos; dragAndDropTimestamp = clientMsg->data.l[3]; Atom targetAction = XA_XdndActionCopy; @@ -2428,7 +2415,7 @@ private: updateDraggedFileList (clientMsg); if (dragAndDropFiles.size() > 0) - handleFileDragMove (dragAndDropFiles, dropX, dropY); + handleFileDragMove (dragAndDropFiles, dropPos.getX(), dropPos.getY()); } } @@ -2438,13 +2425,13 @@ private: updateDraggedFileList (clientMsg); const StringArray files (dragAndDropFiles); - const int lastX = lastDropX, lastY = lastDropY; + const Point lastPos (lastDropPos); sendDragAndDropFinish(); resetDragAndDrop(); if (files.size() > 0) - handleFileDragDrop (files, lastX, lastY); + handleFileDragDrop (files, lastPos.getX(), lastPos.getY()); } void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg) @@ -2578,7 +2565,8 @@ private: } StringArray dragAndDropFiles; - int dragAndDropTimestamp, lastDropX, lastDropY; + int dragAndDropTimestamp; + Point lastDropPos; Atom XA_OtherMime, dragAndDropCurrentMimeType; Window dragAndDropSourceWindow; @@ -2737,17 +2725,18 @@ bool Desktop::canUseSemiTransparentWindows() throw() return false; } -void Desktop::getMousePosition (int& x, int& y) throw() +const Point Desktop::getMousePosition() { - int mouseMods; + int x, y, mouseMods; getMousePos (x, y, mouseMods); + return Point (x, y); } -void Desktop::setMousePosition (int x, int y) throw() +void Desktop::setMousePosition (const Point& newPosition) { ScopedXLock xlock; Window root = RootWindow (display, DefaultScreen (display)); - XWarpPointer (display, None, root, 0, 0, 0, 0, x, y); + XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY()); } diff --git a/src/native/mac/juce_iphone_UIViewComponentPeer.mm b/src/native/mac/juce_iphone_UIViewComponentPeer.mm index af48cde17d..464d8784ba 100644 --- a/src/native/mac/juce_iphone_UIViewComponentPeer.mm +++ b/src/native/mac/juce_iphone_UIViewComponentPeer.mm @@ -93,10 +93,9 @@ public: void setBounds (int x, int y, int w, int h, const bool isNowFullScreen); void getBounds (int& x, int& y, int& w, int& h, const bool global) const; void getBounds (int& x, int& y, int& w, int& h) const; - int getScreenX() const; - int getScreenY() const; - void relativePositionToGlobal (int& x, int& y); - void globalPositionToRelative (int& x, int& y); + const Point getScreenPosition() const; + const Point relativePositionToGlobal (const Point& relativePosition); + const Point globalPositionToRelative (const Point& screenPosition); void setMinimised (bool shouldBeMinimised); bool isMinimised() const; void setFullScreen (bool shouldBeFullScreen); @@ -121,7 +120,7 @@ public: virtual void viewFocusLoss(); bool isFocused() const; void grabFocus(); - void textInputRequired (int x, int y); + void textInputRequired (const Point& position); //============================================================================== void repaint (int x, int y, int w, int h); @@ -717,7 +716,7 @@ void UIViewComponentPeer::grabFocus() } } -void UIViewComponentPeer::textInputRequired (int /*x*/, int /*y*/) +void UIViewComponentPeer::textInputRequired (const Point&) { } @@ -817,13 +816,12 @@ bool Desktop::canUseSemiTransparentWindows() throw() return true; } -void Desktop::getMousePosition (int& x, int& y) throw() +const Point Desktop::getMousePosition() { - x = juce_lastMouseX; - y = juce_lastMouseY; + return Point (juce_lastMouseX, juce_lastMouseY); } -void Desktop::setMousePosition (int x, int y) throw() +void Desktop::setMousePosition (const Point&) { } diff --git a/src/native/mac/juce_mac_MiscUtilities.mm b/src/native/mac/juce_mac_MiscUtilities.mm index 5fa396d0cf..86f490868c 100644 --- a/src/native/mac/juce_mac_MiscUtilities.mm +++ b/src/native/mac/juce_mac_MiscUtilities.mm @@ -145,20 +145,19 @@ bool Desktop::canUseSemiTransparentWindows() throw() return true; } -void Desktop::getMousePosition (int& x, int& y) throw() +const Point Desktop::getMousePosition() { const ScopedAutoReleasePool pool; const NSPoint p ([NSEvent mouseLocation]); - x = roundToInt (p.x); - y = roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y); + return Point (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y)); } -void Desktop::setMousePosition (int x, int y) throw() +void Desktop::setMousePosition (const Point& newPosition) { // this rubbish needs to be done around the warp call, to avoid causing a // bizarre glitch.. CGAssociateMouseAndMouseCursorPosition (false); - CGWarpMouseCursorPosition (CGPointMake (x, y)); + CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY())); CGAssociateMouseAndMouseCursorPosition (true); } diff --git a/src/native/mac/juce_mac_NSViewComponent.mm b/src/native/mac/juce_mac_NSViewComponent.mm index 85b047db59..8a0a4a2931 100644 --- a/src/native/mac/juce_mac_NSViewComponent.mm +++ b/src/native/mac/juce_mac_NSViewComponent.mm @@ -76,12 +76,11 @@ public: if (topComp->getPeer() != 0) { - int x = 0, y = 0; - owner->relativePositionToOtherComponent (topComp, x, y); + const Point pos (owner->relativePositionToOtherComponent (topComp, Point())); NSRect r; - r.origin.x = (float) x; - r.origin.y = (float) y; + r.origin.x = (float) pos.getX(); + r.origin.y = (float) pos.getY(); r.size.width = (float) owner->getWidth(); r.size.height = (float) owner->getHeight(); r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height); diff --git a/src/native/mac/juce_mac_NSViewComponentPeer.mm b/src/native/mac/juce_mac_NSViewComponentPeer.mm index 6d264aca9c..b717e0cf0d 100644 --- a/src/native/mac/juce_mac_NSViewComponentPeer.mm +++ b/src/native/mac/juce_mac_NSViewComponentPeer.mm @@ -135,10 +135,9 @@ public: void setBounds (int x, int y, int w, int h, const bool isNowFullScreen); void getBounds (int& x, int& y, int& w, int& h, const bool global) const; void getBounds (int& x, int& y, int& w, int& h) const; - int getScreenX() const; - int getScreenY() const; - void relativePositionToGlobal (int& x, int& y); - void globalPositionToRelative (int& x, int& y); + const Point getScreenPosition() const; + const Point relativePositionToGlobal (const Point& relativePosition); + const Point globalPositionToRelative (const Point& screenPosition); void setMinimised (bool shouldBeMinimised); bool isMinimised() const; void setFullScreen (bool shouldBeFullScreen); @@ -199,7 +198,7 @@ public: virtual void viewFocusLoss(); bool isFocused() const; void grabFocus(); - void textInputRequired (int x, int y); + void textInputRequired (const Point& position); //============================================================================== void repaint (int x, int y, int w, int h); @@ -858,34 +857,21 @@ void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const getBounds (x, y, w, h, ! isSharedWindow); } -int NSViewComponentPeer::getScreenX() const +const Point NSViewComponentPeer::getScreenPosition() const { int x, y, w, h; getBounds (x, y, w, h, true); - return x; + return Point (x, y); } -int NSViewComponentPeer::getScreenY() const +const Point NSViewComponentPeer::relativePositionToGlobal (const Point& relativePosition) { - int x, y, w, h; - getBounds (x, y, w, h, true); - return y; -} - -void NSViewComponentPeer::relativePositionToGlobal (int& x, int& y) -{ - int wx, wy, ww, wh; - getBounds (wx, wy, ww, wh, true); - x += wx; - y += wy; + return relativePosition + getScreenPosition(); } -void NSViewComponentPeer::globalPositionToRelative (int& x, int& y) +const Point NSViewComponentPeer::globalPositionToRelative (const Point& screenPosition) { - int wx, wy, ww, wh; - getBounds (wx, wy, ww, wh, true); - x -= wx; - y -= wy; + return screenPosition - getScreenPosition(); } NSRect NSViewComponentPeer::constrainRect (NSRect r) @@ -1125,7 +1111,7 @@ void NSViewComponentPeer::grabFocus() } } -void NSViewComponentPeer::textInputRequired (int /*x*/, int /*y*/) +void NSViewComponentPeer::textInputRequired (const Point&) { } @@ -1288,13 +1274,10 @@ void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev) void NSViewComponentPeer::showArrowCursorIfNeeded() { - if (Component::getComponentUnderMouse() == 0) + if (Component::getComponentUnderMouse() == 0 + && Desktop::getInstance().findComponentAt (Desktop::getInstance().getMousePosition()) == 0) { - int mx, my; - Desktop::getInstance().getMousePosition (mx, my); - - if (Desktop::getInstance().findComponentAt (mx, my) == 0) - [[NSCursor arrowCursor] set]; + [[NSCursor arrowCursor] set]; } } diff --git a/src/native/windows/juce_win32_ActiveXComponent.cpp b/src/native/windows/juce_win32_ActiveXComponent.cpp index f83185b01b..d16e19076f 100644 --- a/src/native/windows/juce_win32_ActiveXComponent.cpp +++ b/src/native/windows/juce_win32_ActiveXComponent.cpp @@ -286,10 +286,9 @@ public: if (topComp->getPeer() != 0) { - int x = 0, y = 0; - owner->relativePositionToOtherComponent (topComp, x, y); + const Point pos (owner->relativePositionToOtherComponent (topComp, Point())); - owner->setControlBounds (Rectangle (x, y, owner->getWidth(), owner->getHeight())); + owner->setControlBounds (Rectangle (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight())); } } @@ -452,9 +451,7 @@ bool ActiveXControlComponent::createControl (const void* controlIID) if (dynamic_cast (peer) != 0) { - int x = 0, y = 0; - relativePositionToOtherComponent (getTopLevelComponent(), x, y); - + const Point pos (relativePositionToOtherComponent (getTopLevelComponent(), Point())); HWND hwnd = (HWND) peer->getNativeHandle(); ScopedPointer info (new ActiveXControlData (hwnd, this)); @@ -469,15 +466,15 @@ bool ActiveXControlComponent::createControl (const void* controlIID) if (OleSetContainedObject (info->control, TRUE) == S_OK) { RECT rect; - rect.left = x; - rect.top = y; - rect.right = x + getWidth(); - rect.bottom = y + getHeight(); + rect.left = pos.getX(); + rect.top = pos.getY(); + rect.right = pos.getX() + getWidth(); + rect.bottom = pos.getY() + getHeight(); if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK) { control = info.release(); - setControlBounds (Rectangle (x, y, getWidth(), getHeight())); + setControlBounds (Rectangle (pos.getX(), pos.getY(), getWidth(), getHeight())); ((ActiveXControlData*) control)->controlHWND = getHWND (this); diff --git a/src/native/windows/juce_win32_Windowing.cpp b/src/native/windows/juce_win32_Windowing.cpp index cc125f5730..ce98b5e705 100644 --- a/src/native/windows/juce_win32_Windowing.cpp +++ b/src/native/windows/juce_win32_Windowing.cpp @@ -590,36 +590,22 @@ public: h -= windowBorder.getTopAndBottom(); } - int getScreenX() const + const Point getScreenPosition() const { RECT r; GetWindowRect (hwnd, &r); - return r.left + windowBorder.getLeft(); + return Point (r.left + windowBorder.getLeft(), + r.top + windowBorder.getTop()); } - int getScreenY() const + const Point relativePositionToGlobal (const Point& relativePosition) { - RECT r; - GetWindowRect (hwnd, &r); - return r.top + windowBorder.getTop(); + return relativePosition + getScreenPosition(); } - void relativePositionToGlobal (int& x, int& y) + const Point globalPositionToRelative (const Point& screenPosition) { - RECT r; - GetWindowRect (hwnd, &r); - - x += r.left + windowBorder.getLeft(); - y += r.top + windowBorder.getTop(); - } - - void globalPositionToRelative (int& x, int& y) - { - RECT r; - GetWindowRect (hwnd, &r); - - x -= r.left + windowBorder.getLeft(); - y -= r.top + windowBorder.getTop(); + return screenPosition - getScreenPosition(); } void setMinimised (bool shouldBeMinimised) @@ -779,7 +765,7 @@ public: shouldDeactivateTitleBar = oldDeactivate; } - void textInputRequired (int /*x*/, int /*y*/) + void textInputRequired (const Point&) { if (! hasCreatedCaret) { @@ -1691,9 +1677,8 @@ private: HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect) { updateFileList (pDataObject); - int x = mousePos.x, y = mousePos.y; - owner->globalPositionToRelative (x, y); - owner->handleFileDragMove (files, x, y); + const Point pos (owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); + owner->handleFileDragMove (files, pos.getX(), pos.getY()); *pdwEffect = DROPEFFECT_COPY; return S_OK; } @@ -1706,9 +1691,8 @@ private: HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect) { - int x = mousePos.x, y = mousePos.y; - owner->globalPositionToRelative (x, y); - owner->handleFileDragMove (files, x, y); + const Point pos (owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); + owner->handleFileDragMove (files, pos.getX(), pos.getY()); *pdwEffect = DROPEFFECT_COPY; return S_OK; } @@ -1716,9 +1700,8 @@ private: HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect) { updateFileList (pDataObject); - int x = mousePos.x, y = mousePos.y; - owner->globalPositionToRelative (x, y); - owner->handleFileDragDrop (files, x, y); + const Point pos (owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); + owner->handleFileDragDrop (files, pos.getX(), pos.getY()); *pdwEffect = DROPEFFECT_COPY; return S_OK; } @@ -2001,9 +1984,8 @@ private: if (LOWORD (wParam) == WA_CLICKACTIVE && component->isCurrentlyBlockedByAnotherModalComponent()) { - int mx, my; - component->getMouseXYRelative (mx, my); - Component* const underMouse = component->getComponentAt (mx, my); + const Point mousePos (component->getMouseXYRelative()); + Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY()); if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent()) Component::getCurrentlyModalComponent()->inputAttemptWhenModal(); @@ -2072,8 +2054,8 @@ private: { const int oldModifiers = currentModifiers; - MouseEvent e (0, 0, ModifierKeys::getCurrentModifiersRealtime(), component, - getMouseEventTime(), 0, 0, getMouseEventTime(), 1, false); + MouseEvent e (Point(), ModifierKeys::getCurrentModifiersRealtime(), component, + getMouseEventTime(), Point(), getMouseEventTime(), 1, false); if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK) e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::leftButtonModifier); @@ -2321,17 +2303,16 @@ bool AlertWindow::showNativeDialogBox (const String& title, //============================================================================== -void Desktop::getMousePosition (int& x, int& y) throw() +const Point Desktop::getMousePosition() { POINT mousePos; GetCursorPos (&mousePos); - x = mousePos.x; - y = mousePos.y; + return Point (mousePos.x, mousePos.y); } -void Desktop::setMousePosition (int x, int y) throw() +void Desktop::setMousePosition (const Point& newPosition) { - SetCursorPos (x, y); + SetCursorPos (newPosition.getX(), newPosition.getY()); } //==============================================================================