mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Avoided some repainting when moving scaled windows (win32). Also removed the fake drop-shadowing in newer versions of
This commit is contained in:
parent
5f00e94f3e
commit
ef1f2e6094
4 changed files with 78 additions and 68 deletions
|
|
@ -173,51 +173,9 @@ private:
|
|||
JUCE_DECLARE_NON_COPYABLE (MouseListenerList)
|
||||
};
|
||||
|
||||
|
||||
//==============================================================================
|
||||
struct Component::ComponentHelpers
|
||||
struct ScalingHelpers
|
||||
{
|
||||
#if JUCE_MODAL_LOOPS_PERMITTED
|
||||
static void* runModalLoopCallback (void* userData)
|
||||
{
|
||||
return (void*) (pointer_sized_int) static_cast <Component*> (userData)->runModalLoop();
|
||||
}
|
||||
#endif
|
||||
|
||||
static Identifier getColourPropertyId (int colourId)
|
||||
{
|
||||
char reversedHex[32];
|
||||
char* t = reversedHex;
|
||||
|
||||
for (unsigned int v = (unsigned int) colourId;;)
|
||||
{
|
||||
*t++ = "0123456789abcdef" [(int) (v & 15)];
|
||||
v >>= 4;
|
||||
|
||||
if (v == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
char destBuffer[32];
|
||||
char* dest = destBuffer;
|
||||
memcpy (dest, "jcclr_", 6);
|
||||
dest += 6;
|
||||
|
||||
while (t > reversedHex)
|
||||
*dest++ = *--t;
|
||||
|
||||
*dest++ = 0;
|
||||
return destBuffer;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
static inline bool hitTest (Component& comp, Point<int> localPoint)
|
||||
{
|
||||
return isPositiveAndBelow (localPoint.x, comp.getWidth())
|
||||
&& isPositiveAndBelow (localPoint.y, comp.getHeight())
|
||||
&& comp.hitTest (localPoint.x, localPoint.y);
|
||||
}
|
||||
|
||||
template <typename PointOrRect>
|
||||
static PointOrRect unscaledScreenPosToScaled (float scale, PointOrRect pos) noexcept
|
||||
{
|
||||
|
|
@ -271,6 +229,51 @@ struct Component::ComponentHelpers
|
|||
{
|
||||
return scaledScreenPosToUnscaled (comp.getDesktopScaleFactor(), pos);
|
||||
}
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
struct Component::ComponentHelpers
|
||||
{
|
||||
#if JUCE_MODAL_LOOPS_PERMITTED
|
||||
static void* runModalLoopCallback (void* userData)
|
||||
{
|
||||
return (void*) (pointer_sized_int) static_cast <Component*> (userData)->runModalLoop();
|
||||
}
|
||||
#endif
|
||||
|
||||
static Identifier getColourPropertyId (int colourId)
|
||||
{
|
||||
char reversedHex[32];
|
||||
char* t = reversedHex;
|
||||
|
||||
for (unsigned int v = (unsigned int) colourId;;)
|
||||
{
|
||||
*t++ = "0123456789abcdef" [(int) (v & 15)];
|
||||
v >>= 4;
|
||||
|
||||
if (v == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
char destBuffer[32];
|
||||
char* dest = destBuffer;
|
||||
memcpy (dest, "jcclr_", 6);
|
||||
dest += 6;
|
||||
|
||||
while (t > reversedHex)
|
||||
*dest++ = *--t;
|
||||
|
||||
*dest++ = 0;
|
||||
return destBuffer;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
static inline bool hitTest (Component& comp, Point<int> localPoint)
|
||||
{
|
||||
return isPositiveAndBelow (localPoint.x, comp.getWidth())
|
||||
&& isPositiveAndBelow (localPoint.y, comp.getHeight())
|
||||
&& comp.hitTest (localPoint.x, localPoint.y);
|
||||
}
|
||||
|
||||
// converts an unscaled position within a peer to the local position within that peer's component
|
||||
template <typename PointOrRect>
|
||||
|
|
@ -279,7 +282,7 @@ struct Component::ComponentHelpers
|
|||
if (comp.isTransformed())
|
||||
pos = pos.transformedBy (comp.getTransform().inverted());
|
||||
|
||||
return unscaledScreenPosToScaled (comp, pos);
|
||||
return ScalingHelpers::unscaledScreenPosToScaled (comp, pos);
|
||||
}
|
||||
|
||||
// converts a position within a peer's component to the unscaled position within the peer
|
||||
|
|
@ -289,7 +292,7 @@ struct Component::ComponentHelpers
|
|||
if (comp.isTransformed())
|
||||
pos = pos.transformedBy (comp.getTransform());
|
||||
|
||||
return scaledScreenPosToUnscaled (comp, pos);
|
||||
return ScalingHelpers::scaledScreenPosToUnscaled (comp, pos);
|
||||
}
|
||||
|
||||
template <typename PointOrRect>
|
||||
|
|
@ -301,7 +304,8 @@ struct Component::ComponentHelpers
|
|||
if (comp.isOnDesktop())
|
||||
{
|
||||
if (ComponentPeer* peer = comp.getPeer())
|
||||
pointInParentSpace = unscaledScreenPosToScaled (comp, peer->globalToLocal (scaledScreenPosToUnscaled (pointInParentSpace)));
|
||||
pointInParentSpace = ScalingHelpers::unscaledScreenPosToScaled
|
||||
(comp, peer->globalToLocal (ScalingHelpers::scaledScreenPosToUnscaled (pointInParentSpace)));
|
||||
else
|
||||
jassertfalse;
|
||||
}
|
||||
|
|
@ -319,7 +323,8 @@ struct Component::ComponentHelpers
|
|||
if (comp.isOnDesktop())
|
||||
{
|
||||
if (ComponentPeer* peer = comp.getPeer())
|
||||
pointInLocalSpace = unscaledScreenPosToScaled (peer->localToGlobal (scaledScreenPosToUnscaled (comp, pointInLocalSpace)));
|
||||
pointInLocalSpace = ScalingHelpers::unscaledScreenPosToScaled
|
||||
(peer->localToGlobal (ScalingHelpers::scaledScreenPosToUnscaled (comp, pointInLocalSpace)));
|
||||
else
|
||||
jassertfalse;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,18 +64,18 @@ public:
|
|||
{
|
||||
pos = peer->globalToLocal (pos);
|
||||
Component& peerComp = peer->getComponent();
|
||||
return comp.getLocalPoint (&peerComp, Component::ComponentHelpers::unscaledScreenPosToScaled (peerComp, pos));
|
||||
return comp.getLocalPoint (&peerComp, ScalingHelpers::unscaledScreenPosToScaled (peerComp, pos));
|
||||
}
|
||||
|
||||
return comp.getLocalPoint (nullptr, Component::ComponentHelpers::unscaledScreenPosToScaled (comp, pos));
|
||||
return comp.getLocalPoint (nullptr, ScalingHelpers::unscaledScreenPosToScaled (comp, pos));
|
||||
}
|
||||
|
||||
Component* findComponentAt (Point<int> screenPos)
|
||||
{
|
||||
if (ComponentPeer* const peer = getPeer())
|
||||
{
|
||||
Point<int> relativePos (Component::ComponentHelpers::unscaledScreenPosToScaled (peer->getComponent(),
|
||||
peer->globalToLocal (screenPos)));
|
||||
Point<int> relativePos (ScalingHelpers::unscaledScreenPosToScaled (peer->getComponent(),
|
||||
peer->globalToLocal (screenPos)));
|
||||
Component& comp = peer->getComponent();
|
||||
|
||||
// (the contains() call is needed to test for overlapping desktop windows)
|
||||
|
|
@ -90,14 +90,14 @@ public:
|
|||
{
|
||||
// This needs to return the live position if possible, but it mustn't update the lastScreenPos
|
||||
// value, because that can cause continuity problems.
|
||||
return Component::ComponentHelpers::unscaledScreenPosToScaled
|
||||
return ScalingHelpers::unscaledScreenPosToScaled
|
||||
(unboundedMouseOffset + (isMouseDevice ? MouseInputSource::getCurrentRawMousePosition()
|
||||
: lastScreenPos));
|
||||
}
|
||||
|
||||
void setScreenPosition (Point<int> p)
|
||||
{
|
||||
MouseInputSource::setRawMousePosition (Component::ComponentHelpers::scaledScreenPosToUnscaled (p));
|
||||
MouseInputSource::setRawMousePosition (ScalingHelpers::scaledScreenPosToUnscaled (p));
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -345,7 +345,7 @@ public:
|
|||
|
||||
//==============================================================================
|
||||
Time getLastMouseDownTime() const noexcept { return mouseDowns[0].time; }
|
||||
Point<int> getLastMouseDownPosition() const noexcept { return Component::ComponentHelpers::unscaledScreenPosToScaled (mouseDowns[0].position); }
|
||||
Point<int> getLastMouseDownPosition() const noexcept { return ScalingHelpers::unscaledScreenPosToScaled (mouseDowns[0].position); }
|
||||
|
||||
int getNumberOfMultipleClicks() const noexcept
|
||||
{
|
||||
|
|
|
|||
|
|
@ -530,7 +530,8 @@ public:
|
|||
setTitle (component.getName());
|
||||
|
||||
if ((windowStyleFlags & windowHasDropShadow) != 0
|
||||
&& Desktop::canUseSemiTransparentWindows())
|
||||
&& Desktop::canUseSemiTransparentWindows()
|
||||
&& ((! hasTitleBar()) || SystemStats::getOperatingSystemType() < SystemStats::WinVista))
|
||||
{
|
||||
shadower = component.getLookAndFeel().createDropShadowerForComponent (&component);
|
||||
|
||||
|
|
@ -2078,22 +2079,27 @@ private:
|
|||
&& (styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable);
|
||||
}
|
||||
|
||||
Rectangle<int> getCurrentScaledBounds (float scale) const
|
||||
{
|
||||
return ScalingHelpers::unscaledScreenPosToScaled (scale, windowBorder.addedTo (ScalingHelpers::scaledScreenPosToUnscaled (scale, component.getBounds())));
|
||||
}
|
||||
|
||||
LRESULT handleSizeConstraining (RECT& r, const WPARAM wParam)
|
||||
{
|
||||
if (isConstrainedNativeWindow())
|
||||
{
|
||||
const float scale = getComponent().getDesktopScaleFactor();
|
||||
Rectangle<int> pos (rectangleFromRECT (r) / scale);
|
||||
const Rectangle<int> current (windowBorder.addedTo (component.getBounds()));
|
||||
Rectangle<int> pos (ScalingHelpers::unscaledScreenPosToScaled (scale, rectangleFromRECT (r)));
|
||||
const Rectangle<int> current (getCurrentScaledBounds (scale));
|
||||
|
||||
constrainer->checkBounds (pos, windowBorder.addedTo (component.getBounds()),
|
||||
constrainer->checkBounds (pos, current,
|
||||
Desktop::getInstance().getDisplays().getTotalBounds (true),
|
||||
wParam == WMSZ_TOP || wParam == WMSZ_TOPLEFT || wParam == WMSZ_TOPRIGHT,
|
||||
wParam == WMSZ_LEFT || wParam == WMSZ_TOPLEFT || wParam == WMSZ_BOTTOMLEFT,
|
||||
wParam == WMSZ_BOTTOM || wParam == WMSZ_BOTTOMLEFT || wParam == WMSZ_BOTTOMRIGHT,
|
||||
wParam == WMSZ_RIGHT || wParam == WMSZ_TOPRIGHT || wParam == WMSZ_BOTTOMRIGHT);
|
||||
|
||||
pos *= scale;
|
||||
pos = ScalingHelpers::scaledScreenPosToUnscaled (scale, pos);
|
||||
r.left = pos.getX();
|
||||
r.top = pos.getY();
|
||||
r.right = pos.getRight();
|
||||
|
|
@ -2111,9 +2117,8 @@ private:
|
|||
&& ! Component::isMouseButtonDownAnywhere())
|
||||
{
|
||||
const float scale = getComponent().getDesktopScaleFactor();
|
||||
Rectangle<int> pos (wp.x, wp.y, wp.cx, wp.cy);
|
||||
pos /= scale;
|
||||
const Rectangle<int> current (windowBorder.addedTo (component.getBounds()));
|
||||
Rectangle<int> pos (ScalingHelpers::unscaledScreenPosToScaled (scale, Rectangle<int> (wp.x, wp.y, wp.cx, wp.cy)));
|
||||
const Rectangle<int> current (getCurrentScaledBounds (scale));
|
||||
|
||||
constrainer->checkBounds (pos, current,
|
||||
Desktop::getInstance().getDisplays().getTotalBounds (true),
|
||||
|
|
@ -2122,7 +2127,7 @@ private:
|
|||
pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
|
||||
pos.getX() == current.getX() && pos.getRight() != current.getRight());
|
||||
|
||||
pos *= scale;
|
||||
pos = ScalingHelpers::scaledScreenPosToUnscaled (scale, pos);
|
||||
wp.x = pos.getX();
|
||||
wp.y = pos.getY();
|
||||
wp.cx = pos.getWidth();
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) noexcept
|
|||
|
||||
void ComponentPeer::updateBounds()
|
||||
{
|
||||
setBounds (Component::ComponentHelpers::scaledScreenPosToUnscaled (component, component.getBoundsInParent()), false);
|
||||
setBounds (ScalingHelpers::scaledScreenPosToUnscaled (component, component.getBoundsInParent()), false);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -295,17 +295,17 @@ void ComponentPeer::handleMovedOrResized()
|
|||
{
|
||||
const WeakReference<Component> deletionChecker (&component);
|
||||
|
||||
Rectangle<int> newBounds (getBounds());
|
||||
Rectangle<int> newBounds (Component::ComponentHelpers::rawPeerPositionToLocal (component, getBounds()));
|
||||
Rectangle<int> oldBounds (component.getBounds());
|
||||
|
||||
oldBounds = Component::ComponentHelpers::localPositionToRawPeerPos (component, oldBounds);
|
||||
// oldBounds = Component::ComponentHelpers::localPositionToRawPeerPos (component, oldBounds);
|
||||
|
||||
const bool wasMoved = (oldBounds.getPosition() != newBounds.getPosition());
|
||||
const bool wasResized = (oldBounds.getWidth() != newBounds.getWidth() || oldBounds.getHeight() != newBounds.getHeight());
|
||||
|
||||
if (wasMoved || wasResized)
|
||||
{
|
||||
newBounds = Component::ComponentHelpers::rawPeerPositionToLocal (component, newBounds);
|
||||
// newBounds = Component::ComponentHelpers::rawPeerPositionToLocal (component, newBounds);
|
||||
|
||||
component.bounds = newBounds;
|
||||
|
||||
|
|
@ -403,7 +403,7 @@ Rectangle<int> ComponentPeer::globalToLocal (const Rectangle<int>& screenPositio
|
|||
|
||||
Rectangle<int> ComponentPeer::getAreaCoveredBy (Component& subComponent) const
|
||||
{
|
||||
return Component::ComponentHelpers::scaledScreenPosToUnscaled
|
||||
return ScalingHelpers::scaledScreenPosToUnscaled
|
||||
(component, component.getLocalArea (&subComponent, subComponent.getLocalBounds()));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue