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_CANVAS_H_
|
|
|
|
#define RM_GFX_CANVAS_H_
|
|
|
|
|
2013-04-09 17:35:49 +00:00
|
|
|
#include "FontCollection.h"
|
2013-03-25 15:36:12 +00:00
|
|
|
#include "TextFormat.h"
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <GdiPlus.h>
|
|
|
|
|
|
|
|
namespace Gfx {
|
|
|
|
|
2013-07-29 17:54:20 +00:00
|
|
|
enum class Renderer
|
|
|
|
{
|
|
|
|
GDIP,
|
|
|
|
D2D,
|
|
|
|
|
|
|
|
// Attempts to use D2D. If D2D is not available, fallbacks to use GDI+.
|
|
|
|
PreferD2D
|
|
|
|
};
|
|
|
|
|
2013-04-09 17:54:40 +00:00
|
|
|
// Provides methods for drawing text, bitmaps, etc.
|
2013-03-25 16:05:57 +00:00
|
|
|
class __declspec(novtable) Canvas
|
2013-03-25 15:36:12 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~Canvas();
|
|
|
|
|
2013-07-29 17:54:20 +00:00
|
|
|
// Creates the canvas using the specified rendering engine. May return nullptr.
|
|
|
|
static Canvas* Create(Renderer renderer);
|
|
|
|
|
2013-03-25 15:36:12 +00:00
|
|
|
int GetW() const { return m_W; }
|
|
|
|
int GetH() const { return m_H; }
|
|
|
|
|
2013-07-25 20:53:02 +00:00
|
|
|
void SetAccurateText(bool option) { m_AccurateText = option; }
|
|
|
|
|
2013-04-09 17:54:40 +00:00
|
|
|
// Resize the draw area of the Canvas. This function must not be called if BeginDraw() has been
|
|
|
|
// called and has not yet been matched by a correspoding call to EndDraw.
|
2013-03-25 15:36:12 +00:00
|
|
|
virtual void Resize(int w, int h);
|
|
|
|
|
|
|
|
// BeginDraw() must be matched by a corresponding call to EndDraw(). Drawing functions must be
|
|
|
|
// be called only between BeginDraw() and EndDraw().
|
|
|
|
virtual bool BeginDraw() = 0;
|
|
|
|
virtual void EndDraw() = 0;
|
|
|
|
|
|
|
|
// Allows the use of Gdiplus::Graphics to perform drawing. Must be called between BeginDraw()
|
|
|
|
// and EndDraw(). BeginGdiplusGraphicsContext() must be matched by a corresponding call to
|
|
|
|
// EndGdiplusGraphicsContext(). While in the Gdiplus context, non-const member functions of
|
|
|
|
// this class must not be called.
|
|
|
|
virtual Gdiplus::Graphics& BeginGdiplusContext() = 0;
|
|
|
|
virtual void EndGdiplusContext() = 0;
|
|
|
|
|
|
|
|
// Returns a read-only DC. Must be called between BeginDraw() and EndDraw(). GetDC() must be
|
|
|
|
// matched by a corresponding call to ReleaseDC(). While in the Gdiplus context, non-const
|
|
|
|
// member functions of this class must not be called.
|
|
|
|
virtual HDC GetDC() = 0;
|
|
|
|
virtual void ReleaseDC(HDC dc) = 0;
|
|
|
|
|
2013-04-09 17:54:40 +00:00
|
|
|
// The Create* functions allocate objects specific to this Canvas object.
|
2013-04-09 17:35:49 +00:00
|
|
|
virtual FontCollection* CreateFontCollection() = 0;
|
2013-03-25 15:36:12 +00:00
|
|
|
virtual TextFormat* CreateTextFormat() = 0;
|
|
|
|
|
|
|
|
virtual bool IsTransparentPixel(int x, int y) = 0;
|
|
|
|
|
2013-04-05 08:35:20 +00:00
|
|
|
virtual void SetTransform(const Gdiplus::Matrix& matrix) = 0;
|
|
|
|
virtual void ResetTransform() = 0;
|
|
|
|
virtual void RotateTransform(float angle, float x, float y, float dx, float dy) = 0;
|
2013-03-29 11:33:11 +00:00
|
|
|
|
2013-03-25 15:36:12 +00:00
|
|
|
virtual void SetAntiAliasing(bool enable) = 0;
|
|
|
|
virtual void SetTextAntiAliasing(bool enable) = 0;
|
|
|
|
|
|
|
|
virtual void Clear(const Gdiplus::Color& color = Gdiplus::Color(0, 0, 0, 0)) = 0;
|
|
|
|
|
|
|
|
virtual void DrawTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect, const Gdiplus::SolidBrush& brush) = 0;
|
|
|
|
virtual bool MeasureTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect) = 0;
|
|
|
|
virtual bool MeasureTextLinesW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect, UINT& lines) = 0;
|
|
|
|
|
|
|
|
virtual void DrawBitmap(Gdiplus::Bitmap* bitmap, const Gdiplus::Rect& dstRect, const Gdiplus::Rect& srcRect) = 0;
|
|
|
|
|
|
|
|
virtual void FillRectangle(Gdiplus::Rect& rect, const Gdiplus::SolidBrush& brush) = 0;
|
|
|
|
|
|
|
|
protected:
|
2013-03-25 16:05:57 +00:00
|
|
|
Canvas();
|
|
|
|
|
2013-03-25 15:36:12 +00:00
|
|
|
int m_W;
|
|
|
|
int m_H;
|
|
|
|
|
2013-07-31 09:55:32 +00:00
|
|
|
// GDI+, by default, includes padding around the string and also has a larger character spacing
|
|
|
|
// compared to DirectWrite. In order to minimize diffeences between the text renderers,
|
|
|
|
// an option is provided to enable accurate (typographic) text rendering. If set to |true|,
|
|
|
|
// it is expected that there is no padding around the text and that the output is similar to
|
|
|
|
// the default DirectWrite output. Otherwise, the expected result should be similar to that of
|
|
|
|
// non-typographic GDI+.
|
2013-07-25 20:53:02 +00:00
|
|
|
bool m_AccurateText;
|
|
|
|
|
2013-03-25 15:36:12 +00:00
|
|
|
private:
|
|
|
|
Canvas(const Canvas& other) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Gfx
|
|
|
|
|
|
|
|
#endif
|