2013-03-25 15:36:12 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2013 Birunthan Mohanathas
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RM_GFX_CANVASD2D_H_
|
|
|
|
#define RM_GFX_CANVASD2D_H_
|
|
|
|
|
|
|
|
#include "Canvas.h"
|
2013-04-09 17:35:49 +00:00
|
|
|
#include "FontCollectionD2D.h"
|
2013-03-25 15:36:12 +00:00
|
|
|
#include "TextFormatD2D.h"
|
2013-04-12 14:09:42 +00:00
|
|
|
#include "Util/WICBitmapDIB.h"
|
2013-05-01 11:38:52 +00:00
|
|
|
#include <memory>
|
2013-03-25 15:36:12 +00:00
|
|
|
#include <string>
|
2013-12-24 11:20:19 +00:00
|
|
|
#include <ole2.h> // For Gdiplus.h.
|
2013-03-25 15:36:12 +00:00
|
|
|
#include <GdiPlus.h>
|
2013-07-29 17:50:32 +00:00
|
|
|
#include <d2d1_1.h>
|
2013-03-25 15:36:12 +00:00
|
|
|
#include <d2d1helper.h>
|
2013-07-28 17:20:28 +00:00
|
|
|
#include <dwrite_1.h>
|
2013-03-25 15:36:12 +00:00
|
|
|
#include <wincodec.h>
|
2013-05-01 11:10:31 +00:00
|
|
|
#include <wrl/client.h>
|
2013-03-25 15:36:12 +00:00
|
|
|
|
|
|
|
namespace Gfx {
|
|
|
|
|
|
|
|
// Provides a Direct2D/DirectWrite implementation of Canvas.
|
|
|
|
class CanvasD2D : public Canvas
|
|
|
|
{
|
|
|
|
public:
|
2013-10-06 07:57:24 +00:00
|
|
|
static bool Initialize();
|
|
|
|
static void Finalize();
|
|
|
|
|
2013-03-25 15:36:12 +00:00
|
|
|
virtual void Resize(int w, int h);
|
|
|
|
|
|
|
|
virtual bool BeginDraw();
|
|
|
|
virtual void EndDraw();
|
|
|
|
|
|
|
|
virtual Gdiplus::Graphics& BeginGdiplusContext() override;
|
|
|
|
virtual void EndGdiplusContext() override;
|
|
|
|
|
|
|
|
virtual HDC GetDC() override;
|
|
|
|
virtual void ReleaseDC(HDC dc) override;
|
2013-04-09 17:35:49 +00:00
|
|
|
|
|
|
|
virtual FontCollection* CreateFontCollection() override { return new FontCollectionD2D(); }
|
2013-03-25 15:36:12 +00:00
|
|
|
virtual TextFormat* CreateTextFormat() override { return new TextFormatD2D(); }
|
|
|
|
|
|
|
|
virtual bool IsTransparentPixel(int x, int y) override;
|
|
|
|
|
2013-04-05 08:35:20 +00:00
|
|
|
virtual void SetTransform(const Gdiplus::Matrix& matrix) override;
|
|
|
|
virtual void ResetTransform() override;
|
|
|
|
virtual void RotateTransform(float angle, float x, float y, float dx, float dy) override;
|
|
|
|
|
2013-03-25 15:36:12 +00:00
|
|
|
virtual void SetAntiAliasing(bool enable) override;
|
|
|
|
virtual void SetTextAntiAliasing(bool enable) override;
|
|
|
|
|
|
|
|
virtual void Clear(const Gdiplus::Color& color) override;
|
|
|
|
|
|
|
|
virtual void DrawTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect, const Gdiplus::SolidBrush& brush) override;
|
|
|
|
virtual bool MeasureTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect) override;
|
|
|
|
virtual bool MeasureTextLinesW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect, UINT& lines) override;
|
|
|
|
|
|
|
|
virtual void DrawBitmap(Gdiplus::Bitmap* bitmap, const Gdiplus::Rect& dstRect, const Gdiplus::Rect& srcRect) override;
|
|
|
|
|
|
|
|
virtual void FillRectangle(Gdiplus::Rect& rect, const Gdiplus::SolidBrush& brush) override;
|
|
|
|
|
|
|
|
private:
|
2013-07-29 17:54:20 +00:00
|
|
|
friend class Canvas;
|
2013-04-12 14:05:21 +00:00
|
|
|
friend class FontCollectionD2D;
|
2013-03-25 15:36:12 +00:00
|
|
|
friend class TextFormatD2D;
|
|
|
|
|
2013-07-29 17:54:20 +00:00
|
|
|
CanvasD2D();
|
|
|
|
~CanvasD2D();
|
2013-03-25 15:36:12 +00:00
|
|
|
CanvasD2D(const CanvasD2D& other) {}
|
|
|
|
|
2013-03-26 19:29:05 +00:00
|
|
|
bool BeginTargetDraw();
|
2013-03-25 15:36:12 +00:00
|
|
|
void EndTargetDraw();
|
|
|
|
|
2013-08-12 15:50:24 +00:00
|
|
|
// Sets the |m_Target| transformation to be equal to that of |m_GdipGraphics|.
|
|
|
|
void UpdateTargetTransform();
|
2013-04-05 08:35:20 +00:00
|
|
|
|
2013-05-01 11:10:31 +00:00
|
|
|
Microsoft::WRL::ComPtr<ID2D1RenderTarget> m_Target;
|
2013-09-29 08:28:28 +00:00
|
|
|
|
|
|
|
// Underlying pixel data shared by both m_Target and m_GdipBitmap.
|
2013-04-12 14:09:42 +00:00
|
|
|
Util::WICBitmapDIB m_Bitmap;
|
2013-03-25 15:36:12 +00:00
|
|
|
|
|
|
|
// GDI+ objects that share the pixel data of m_Bitmap.
|
2013-05-01 11:38:52 +00:00
|
|
|
std::unique_ptr<Gdiplus::Graphics> m_GdipGraphics;
|
|
|
|
std::unique_ptr<Gdiplus::Bitmap> m_GdipBitmap;
|
2013-03-25 15:36:12 +00:00
|
|
|
|
2013-03-26 19:29:05 +00:00
|
|
|
bool m_TextAntiAliasing;
|
2013-03-25 15:36:12 +00:00
|
|
|
|
2013-08-12 15:50:24 +00:00
|
|
|
// |true| if PushAxisAlignedClip()/PopAxisAlignedClip() can be used.
|
|
|
|
bool m_CanUseAxisAlignClip;
|
|
|
|
|
2013-03-25 15:36:12 +00:00
|
|
|
static UINT c_Instances;
|
2013-07-29 17:50:32 +00:00
|
|
|
static Microsoft::WRL::ComPtr<ID2D1Factory1> c_D2DFactory;
|
|
|
|
static Microsoft::WRL::ComPtr<IDWriteFactory1> c_DWFactory;
|
2013-05-01 11:10:31 +00:00
|
|
|
static Microsoft::WRL::ComPtr<IDWriteGdiInterop> c_DWGDIInterop;
|
|
|
|
static Microsoft::WRL::ComPtr<IWICImagingFactory> c_WICFactory;
|
2013-03-25 15:36:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Gfx
|
|
|
|
|
|
|
|
#endif
|