1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Windows: Use Component::ScaleFactorListener in ActiveXComponent, OpenGL and video native code and remove some unnecessary JUCE_WIN_PER_MONITOR_DPI_AWARE checks

This commit is contained in:
ed 2021-09-08 08:52:23 +01:00
parent 65396f986d
commit 7bc696cd28
3 changed files with 48 additions and 70 deletions

View file

@ -237,10 +237,8 @@ namespace ActiveXHelpers
}
//==============================================================================
class ActiveXControlComponent::Pimpl : public ComponentMovementWatcher
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
, public ComponentPeer::ScaleFactorListener
#endif
class ActiveXControlComponent::Pimpl : public ComponentMovementWatcher,
public ComponentPeer::ScaleFactorListener
{
public:
Pimpl (HWND hwnd, ActiveXControlComponent& activeXComp)
@ -262,25 +260,19 @@ public:
clientSite->Release();
storage->Release();
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
for (int i = 0; i < ComponentPeer::getNumPeers(); ++i)
if (auto* peer = ComponentPeer::getPeer (i))
peer->removeScaleFactorListener (this);
#endif
if (currentPeer != nullptr)
currentPeer->removeScaleFactorListener (this);
}
void setControlBounds (Rectangle<int> newBounds) const
{
if (controlHWND != nullptr)
{
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
if (auto* peer = owner.getTopLevelComponent()->getPeer())
newBounds = (newBounds.toDouble() * peer->getPlatformScaleFactor()).toNearestInt();
#endif
MoveWindow (controlHWND, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
}
}
void setControlVisible (bool shouldBeVisible) const
@ -300,12 +292,15 @@ public:
void componentPeerChanged() override
{
if (currentPeer != nullptr)
currentPeer->removeScaleFactorListener (this);
componentMovedOrResized (true, true);
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
if (auto* peer = owner.getTopLevelComponent()->getPeer())
peer->addScaleFactorListener (this);
#endif
currentPeer = owner.getTopLevelComponent()->getPeer();
if (currentPeer != nullptr)
currentPeer->addScaleFactorListener (this);
}
using ComponentMovementWatcher::componentVisibilityChanged;
@ -316,12 +311,10 @@ public:
componentPeerChanged();
}
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
void nativeScaleFactorChanged (double /*newScaleFactor*/) override
{
componentMovedOrResized (true, true);
}
#endif
// intercepts events going to an activeX control, so we can sneakily use the mouse events
static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
@ -366,6 +359,7 @@ public:
}
ActiveXControlComponent& owner;
ComponentPeer* currentPeer = nullptr;
HWND controlHWND = {};
IStorage* storage = nullptr;
ActiveXHelpers::JuceIOleClientSite* clientSite = nullptr;

View file

@ -29,10 +29,7 @@ namespace juce
extern ComponentPeer* createNonRepaintingEmbeddedWindowsPeer (Component&, void* parent);
//==============================================================================
class OpenGLContext::NativeContext
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
: private Timer
#endif
class OpenGLContext::NativeContext : private ComponentPeer::ScaleFactorListener
{
public:
NativeContext (Component& component,
@ -89,6 +86,10 @@ public:
{
deleteRenderContext();
releaseDC();
if (safeComponent != nullptr)
if (auto* peer = safeComponent->getTopLevelComponent()->getPeer())
peer->removeScaleFactorListener (this);
}
bool initialiseOnRenderThread (OpenGLContext& c)
@ -173,11 +174,8 @@ private:
HDC dc;
OpenGLContext* context = {};
double nativeScaleFactor = 1.0;
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
Component::SafePointer<Component> safeComponent;
#endif
double nativeScaleFactor = 1.0;
#define JUCE_DECLARE_WGL_EXTENSION_FUNCTION(name, returnType, params) \
typedef returnType (__stdcall *type_ ## name) params; type_ ## name name;
@ -187,24 +185,18 @@ private:
JUCE_DECLARE_WGL_EXTENSION_FUNCTION (wglGetSwapIntervalEXT, int, ())
#undef JUCE_DECLARE_WGL_EXTENSION_FUNCTION
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
void timerCallback() override
void nativeScaleFactorChanged (double newScaleFactor) override
{
if (safeComponent != nullptr)
{
if (auto* peer = safeComponent->getTopLevelComponent()->getPeer())
{
auto newScale = peer->getPlatformScaleFactor();
if (approximatelyEqual (newScaleFactor, nativeScaleFactor)
|| safeComponent == nullptr)
return;
if (! approximatelyEqual (newScale, nativeScaleFactor))
{
nativeScaleFactor = newScale;
updateWindowPosition (peer->getAreaCoveredBy (*safeComponent));
}
}
if (auto* peer = safeComponent->getTopLevelComponent()->getPeer())
{
nativeScaleFactor = newScaleFactor;
updateWindowPosition (peer->getAreaCoveredBy (*safeComponent));
}
}
#endif
void initialiseGLExtensions()
{
@ -228,14 +220,11 @@ private:
if (auto* peer = topComp->getPeer())
{
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
safeComponent = Component::SafePointer<Component> (&component);
nativeScaleFactor = peer->getPlatformScaleFactor();
startTimer (50);
#endif
updateWindowPosition (peer->getAreaCoveredBy (component));
peer->addScaleFactorListener (this);
}
nativeWindow->setVisible (true);

View file

@ -158,14 +158,11 @@ namespace VideoRenderers
}
//==============================================================================
struct VideoComponent::Pimpl : public Component
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
, public ComponentPeer::ScaleFactorListener
#endif
struct VideoComponent::Pimpl : public Component,
private ComponentPeer::ScaleFactorListener
{
Pimpl (VideoComponent& ownerToUse, bool)
: owner (ownerToUse),
videoLoaded (false)
: owner (ownerToUse)
{
setOpaque (true);
context.reset (new DirectShowContext (*this));
@ -178,11 +175,8 @@ struct VideoComponent::Pimpl : public Component
context = nullptr;
componentWatcher = nullptr;
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
for (int i = 0; i < ComponentPeer::getNumPeers(); ++i)
if (auto* peer = ComponentPeer::getPeer (i))
peer->removeScaleFactorListener (this);
#endif
if (currentPeer != nullptr)
currentPeer->removeScaleFactorListener (this);
}
Result loadFromString (const String& fileOrURLPath)
@ -309,7 +303,8 @@ struct VideoComponent::Pimpl : public Component
if (getWidth() > 0 && getHeight() > 0)
if (auto* peer = getTopLevelComponent()->getPeer())
context->updateWindowPosition ((peer->getAreaCoveredBy (*this).toDouble() * peer->getPlatformScaleFactor()).toNearestInt());
context->updateWindowPosition ((peer->getAreaCoveredBy (*this).toDouble()
* peer->getPlatformScaleFactor()).toNearestInt());
}
void updateContextVisibility()
@ -341,21 +336,20 @@ struct VideoComponent::Pimpl : public Component
owner.onErrorOccurred (errorMessage);
}
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
void nativeScaleFactorChanged (double /*newScaleFactor*/) override
{
if (videoLoaded)
updateContextPosition();
}
#endif
File currentFile;
URL currentURL;
private:
VideoComponent& owner;
ComponentPeer* currentPeer = nullptr;
bool videoLoaded = false;
bool videoLoaded;
//==============================================================================
void nativeScaleFactorChanged (double /*newScaleFactor*/) override
{
if (videoLoaded)
updateContextPosition();
}
//==============================================================================
struct ComponentWatcher : public ComponentMovementWatcher
@ -372,6 +366,9 @@ private:
void componentPeerChanged() override
{
if (owner.currentPeer != nullptr)
owner.currentPeer->removeScaleFactorListener (&owner);
if (owner.videoLoaded)
owner.recreateNativeWindowAsync();
}
@ -771,10 +768,8 @@ private:
nativeWindow.reset (new NativeWindow ((HWND) topLevelPeer->getNativeHandle(), this));
hwnd = nativeWindow->hwnd;
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
topLevelPeer->addScaleFactorListener (&component);
#endif
component.currentPeer = topLevelPeer;
component.currentPeer->addScaleFactorListener (&component);
if (hwnd != nullptr)
{