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

Graphics code refactoring

This commit is contained in:
tpoole 2017-06-27 15:31:54 +01:00
parent ccb4ce8829
commit 0874e47a35
6 changed files with 898 additions and 802 deletions

View file

@ -57,7 +57,7 @@
#undef JUCE_USE_DIRECTWRITE
#endif
#if JUCE_USE_DIRECTWRITE
#if JUCE_USE_DIRECTWRITE || JUCE_DIRECT2D
/* If you hit a compile error trying to include these files, you may need to update
your version of the Windows SDK to the latest one. The DirectWrite and Direct2D
headers are in the version 7 SDKs.

View file

@ -142,4 +142,8 @@ class LowLevelGraphicsContext;
#include "native/juce_mac_CoreGraphicsContext.h"
#endif
#if JUCE_DIRECT2D && JUCE_WINDOWS
#include "native/juce_win32_Direct2DGraphicsContext.h"
#endif
}

View file

@ -0,0 +1,103 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2017 - ROLI Ltd.
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
27th April 2017).
End User License Agreement: www.juce.com/juce-5-licence
Privacy Policy: www.juce.com/juce-5-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
#pragma once
#ifndef _WINDEF_
class HWND__; // Forward or never
typedef HWND__* HWND;
#endif
class Direct2DLowLevelGraphicsContext : public LowLevelGraphicsContext
{
public:
Direct2DLowLevelGraphicsContext (HWND);
~Direct2DLowLevelGraphicsContext();
//==============================================================================
bool isVectorDevice() const override { return false; }
void setOrigin (Point<int>) override;
void addTransform (const AffineTransform&) override;
float getPhysicalPixelScaleFactor() override;
bool clipToRectangle (const Rectangle<int>&) override;
bool clipToRectangleList (const RectangleList<int>&) override;
void excludeClipRectangle (const Rectangle<int>&) override;
void clipToPath (const Path&, const AffineTransform&) override;
void clipToImageAlpha (const Image&, const AffineTransform&) override;
bool clipRegionIntersects (const Rectangle<int>&) override;
Rectangle<int> getClipBounds() const override;
bool isClipEmpty() const override;
//==============================================================================
void saveState() override;
void restoreState() override;
void beginTransparencyLayer (float opacity) override;
void endTransparencyLayer() override;
//==============================================================================
void setFill (const FillType&) override;
void setOpacity (float) override;
void setInterpolationQuality (Graphics::ResamplingQuality) override;
//==============================================================================
void fillRect (const Rectangle<int>&, bool replaceExistingContents) override;
void fillRect (const Rectangle<float>&) override;
void fillRectList (const RectangleList<float>&) override;
void fillPath (const Path&, const AffineTransform&) override;
void drawImage (const Image& sourceImage, const AffineTransform&) override;
//==============================================================================
void drawLine (const Line<float>&) override;
void setFont (const Font&) override;
const Font& getFont() override;
void drawGlyph (int glyphNumber, const AffineTransform&) override;
bool drawTextLayout (const AttributedString&, const Rectangle<float>&) override;
void resized();
void clear();
void start();
void end();
//==============================================================================
private:
struct SavedState;
HWND hwnd;
SavedState* currentState;
OwnedArray<SavedState> states;
Rectangle<int> bounds;
struct Pimpl;
friend struct Pimpl;
friend struct ContainerDeletePolicy<Pimpl>;
ScopedPointer<Pimpl> pimpl;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Direct2DLowLevelGraphicsContext)
};

View file

@ -265,6 +265,8 @@ public:
IDWriteFontFace* getIDWriteFontFace() const noexcept { return dwFontFace; }
float getUnitsToHeightScaleFactor() const noexcept { return unitsToHeightScaleFactor; }
private:
SharedResourcePointer<Direct2DFactories> factories;
ComSmartPtr<IDWriteFontFace> dwFontFace;

View file

@ -1837,7 +1837,7 @@ private:
}
else
#endif
{
HRGN rgn = CreateRectRgn (0, 0, 0, 0);
const int regionType = GetUpdateRgn (hwnd, rgn, false);
@ -1865,6 +1865,8 @@ private:
_fpreset(); // because some graphics cards can unmask FP exceptions
#endif
}
lastPaintTime = Time::getMillisecondCounter();
}
@ -1993,8 +1995,8 @@ private:
void updateDirect2DContext()
{
if (currentRenderingEngine != direct2DRenderingEngine)
direct2DContext = 0;
else if (direct2DContext == 0)
direct2DContext = nullptr;
else if (direct2DContext == nullptr)
direct2DContext = new Direct2DLowLevelGraphicsContext (hwnd);
}
#endif