mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Gfx: Implement GDI+ fallback
This commit is contained in:
		@@ -17,6 +17,9 @@
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
#include "Canvas.h"
 | 
			
		||||
#include "CanvasD2D.h"
 | 
			
		||||
#include "CanvasGDIP.h"
 | 
			
		||||
#include "../Platform.h"
 | 
			
		||||
 | 
			
		||||
namespace Gfx {
 | 
			
		||||
 | 
			
		||||
@@ -31,6 +34,34 @@ Canvas::~Canvas()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Canvas* Canvas::Create(Renderer renderer)
 | 
			
		||||
{
 | 
			
		||||
	if (renderer == Renderer::GDIP)
 | 
			
		||||
	{
 | 
			
		||||
		return new CanvasGDIP();
 | 
			
		||||
	}
 | 
			
		||||
	else if (renderer == Renderer::D2D && Platform::IsAtLeastWin7())
 | 
			
		||||
	{
 | 
			
		||||
		if (CanvasD2D::Initialize())
 | 
			
		||||
		{
 | 
			
		||||
			return new CanvasD2D();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		CanvasD2D::Finalize();
 | 
			
		||||
	}
 | 
			
		||||
	else if (renderer == Renderer::PreferD2D)
 | 
			
		||||
	{
 | 
			
		||||
		if (Canvas* canvas = Create(Renderer::D2D))
 | 
			
		||||
		{
 | 
			
		||||
			return canvas;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return Create(Renderer::GDIP);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nullptr;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void Canvas::Resize(int w, int h)
 | 
			
		||||
{
 | 
			
		||||
	m_W = w;
 | 
			
		||||
 
 | 
			
		||||
@@ -26,12 +26,24 @@
 | 
			
		||||
 | 
			
		||||
namespace Gfx {
 | 
			
		||||
 | 
			
		||||
enum class Renderer
 | 
			
		||||
{
 | 
			
		||||
	GDIP,
 | 
			
		||||
	D2D,
 | 
			
		||||
 | 
			
		||||
	// Attempts to use D2D. If D2D is not available, fallbacks to use GDI+.
 | 
			
		||||
	PreferD2D
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Provides methods for drawing text, bitmaps, etc.
 | 
			
		||||
class __declspec(novtable) Canvas
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	virtual ~Canvas();
 | 
			
		||||
 | 
			
		||||
	// Creates the canvas using the specified rendering engine. May return nullptr.
 | 
			
		||||
	static Canvas* Create(Renderer renderer);
 | 
			
		||||
 | 
			
		||||
	int GetW() const { return m_W; }
 | 
			
		||||
	int GetH() const { return m_H; }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -53,7 +53,6 @@ CanvasD2D::CanvasD2D() : Canvas(),
 | 
			
		||||
	m_Bitmap(),
 | 
			
		||||
	m_TextAntiAliasing(false)
 | 
			
		||||
{
 | 
			
		||||
	Initialize();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CanvasD2D::~CanvasD2D()
 | 
			
		||||
 
 | 
			
		||||
@@ -38,9 +38,6 @@ namespace Gfx {
 | 
			
		||||
class CanvasD2D : public Canvas
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	CanvasD2D();
 | 
			
		||||
	~CanvasD2D();
 | 
			
		||||
 | 
			
		||||
	virtual void Resize(int w, int h);
 | 
			
		||||
 | 
			
		||||
	virtual bool BeginDraw();
 | 
			
		||||
@@ -75,9 +72,12 @@ public:
 | 
			
		||||
	virtual void FillRectangle(Gdiplus::Rect& rect, const Gdiplus::SolidBrush& brush) override;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	friend class Canvas;
 | 
			
		||||
	friend class FontCollectionD2D;
 | 
			
		||||
	friend class TextFormatD2D;
 | 
			
		||||
 | 
			
		||||
	CanvasD2D();
 | 
			
		||||
	~CanvasD2D();
 | 
			
		||||
	CanvasD2D(const CanvasD2D& other) {}
 | 
			
		||||
 | 
			
		||||
	static bool Initialize();
 | 
			
		||||
 
 | 
			
		||||
@@ -32,9 +32,6 @@ namespace Gfx {
 | 
			
		||||
class CanvasGDIP : public Canvas
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	CanvasGDIP();
 | 
			
		||||
	~CanvasGDIP();
 | 
			
		||||
 | 
			
		||||
	virtual void Resize(int w, int h);
 | 
			
		||||
 | 
			
		||||
	virtual bool BeginDraw();
 | 
			
		||||
@@ -69,6 +66,10 @@ public:
 | 
			
		||||
	virtual void FillRectangle(Gdiplus::Rect& rect, const Gdiplus::SolidBrush& brush) override;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	friend class Canvas;
 | 
			
		||||
 | 
			
		||||
	CanvasGDIP();
 | 
			
		||||
	~CanvasGDIP();
 | 
			
		||||
	CanvasGDIP(const CanvasGDIP& other) {}
 | 
			
		||||
 | 
			
		||||
	void Dispose();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user