2019-04-11 14:40:54 +08:00
|
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
2019-03-31 01:37:06 +08:00
|
|
|
|
//
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
|
//
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
|
//
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
#include "Node.h"
|
|
|
|
|
|
#include "Font.hpp"
|
|
|
|
|
|
#include "TextStyle.hpp"
|
|
|
|
|
|
#include "../renderer/TextRenderer.h"
|
|
|
|
|
|
|
|
|
|
|
|
#undef DrawText
|
|
|
|
|
|
|
2019-04-11 14:40:54 +08:00
|
|
|
|
namespace kiwano
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>
|
2019-04-11 14:40:54 +08:00
|
|
|
|
class KGE_API Canvas
|
2019-03-31 01:37:06 +08:00
|
|
|
|
: public VisualNode
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
Canvas();
|
|
|
|
|
|
|
|
|
|
|
|
Canvas(
|
|
|
|
|
|
Size const& size
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
Canvas(
|
|
|
|
|
|
float width,
|
|
|
|
|
|
float height
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
virtual ~Canvas();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ʼ<EFBFBD><CABC>ͼ
|
|
|
|
|
|
void BeginDraw();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ
|
|
|
|
|
|
void EndDraw();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ֱ<EFBFBD><D6B1>
|
|
|
|
|
|
void DrawLine(
|
|
|
|
|
|
const Point& begin,
|
|
|
|
|
|
const Point& end
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>Բ<EFBFBD>α߿<CEB1>
|
|
|
|
|
|
void DrawCircle(
|
|
|
|
|
|
const Point& center,
|
|
|
|
|
|
float radius
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>Բ<EFBFBD>α߿<CEB1>
|
|
|
|
|
|
void DrawEllipse(
|
|
|
|
|
|
const Point& center,
|
|
|
|
|
|
float radius_x,
|
|
|
|
|
|
float radius_y
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>α߿<CEB1>
|
|
|
|
|
|
void DrawRect(
|
|
|
|
|
|
const Rect& rect
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>Բ<EFBFBD>Ǿ<EFBFBD><C7BE>α߿<CEB1>
|
|
|
|
|
|
void DrawRoundedRect(
|
|
|
|
|
|
const Rect& rect,
|
|
|
|
|
|
float radius_x,
|
|
|
|
|
|
float radius_y
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ͼƬ
|
|
|
|
|
|
void DrawImage(
|
|
|
|
|
|
ImagePtr const& image,
|
|
|
|
|
|
float opacity = 1.f
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void DrawText(
|
|
|
|
|
|
String const& text, /* <20><><EFBFBD><EFBFBD> */
|
|
|
|
|
|
Point const& point /* <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB> */
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD>α߿<CEB1>
|
|
|
|
|
|
void DrawGeometry(
|
|
|
|
|
|
GeometryPtr const& geo
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>
|
|
|
|
|
|
void FillCircle(
|
|
|
|
|
|
const Point& center,
|
|
|
|
|
|
float radius
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>
|
|
|
|
|
|
void FillEllipse(
|
|
|
|
|
|
const Point& center,
|
|
|
|
|
|
float radius_x,
|
|
|
|
|
|
float radius_y
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void FillRect(
|
|
|
|
|
|
const Rect& rect
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>Բ<EFBFBD>Ǿ<EFBFBD><C7BE><EFBFBD>
|
|
|
|
|
|
void FillRoundedRect(
|
|
|
|
|
|
const Rect& rect,
|
|
|
|
|
|
float radius_x,
|
|
|
|
|
|
float radius_y
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>伸<EFBFBD><E4BCB8>ͼ<EFBFBD><CDBC>
|
|
|
|
|
|
void FillGeometry(
|
|
|
|
|
|
GeometryPtr const& geo
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
|
void BeginPath(
|
|
|
|
|
|
Point const& begin_pos /* ·<><C2B7><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC> */
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
|
void EndPath(
|
|
|
|
|
|
bool closed = true /* ·<><C2B7><EFBFBD>Ƿ<EFBFBD><C7B7>պ<EFBFBD> */
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>߶<EFBFBD>
|
|
|
|
|
|
void AddLine(
|
|
|
|
|
|
Point const& point /* <20>˵<EFBFBD> */
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>߶<EFBFBD>
|
|
|
|
|
|
void AddLines(
|
|
|
|
|
|
Array<Point> const& points
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>η<EFBFBD><CEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void AddBezier(
|
|
|
|
|
|
Point const& point1, /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵĵ<DFB5>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD> */
|
|
|
|
|
|
Point const& point2, /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵĵڶ<C4B5><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD> */
|
|
|
|
|
|
Point const& point3 /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD><DFB5>յ<EFBFBD> */
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD>
|
|
|
|
|
|
void AddArc(
|
|
|
|
|
|
Point const& point, /* <20>յ<EFBFBD> */
|
|
|
|
|
|
Point const& radius, /* <20><>Բ<EFBFBD>뾶 */
|
|
|
|
|
|
float rotation, /* <20><>Բ<EFBFBD><D4B2>ת<EFBFBD>Ƕ<EFBFBD> */
|
|
|
|
|
|
bool clockwise = true, /* ˳ʱ<CBB3><CAB1> or <20><>ʱ<EFBFBD><CAB1> */
|
|
|
|
|
|
bool is_small = true /* <20>Ƿ<EFBFBD>ȡС<C8A1><D0A1> 180<38><30> <20>Ļ<EFBFBD> */
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// ·<><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void StrokePath();
|
|
|
|
|
|
|
|
|
|
|
|
// ·<><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void FillPath();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
|
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
void SetFillColor(
|
|
|
|
|
|
const Color& color
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
void SetStrokeColor(
|
|
|
|
|
|
const Color& color
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetStrokeWidth(
|
|
|
|
|
|
float width
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ཻ<EFBFBD><E0BDBB>ʽ
|
|
|
|
|
|
void SetOutlineJoinStyle(
|
|
|
|
|
|
StrokeStyle outline_join
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD>ˢ<EFBFBD><CBA2>ʽ
|
|
|
|
|
|
void SetTextStyle(
|
|
|
|
|
|
Font const& font,
|
|
|
|
|
|
TextStyle const& text_style
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
Color GetFillColor() const;
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
Color GetStrokeColor() const;
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
float GetStrokeWidth() const;
|
|
|
|
|
|
|
|
|
|
|
|
// <20>任<EFBFBD><E4BBBB><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetBrushTransform(
|
|
|
|
|
|
Matrix const& transform
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ΪͼƬ
|
|
|
|
|
|
ImagePtr ExportToImage() const;
|
|
|
|
|
|
|
|
|
|
|
|
void OnRender() override;
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
ComPtr<ID2D1Bitmap> const& GetBitmap() const;
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
float stroke_width_;
|
|
|
|
|
|
Font text_font_;
|
|
|
|
|
|
TextStyle text_style_;
|
|
|
|
|
|
|
|
|
|
|
|
ComPtr<ID2D1PathGeometry> current_geometry_;
|
|
|
|
|
|
ComPtr<ID2D1GeometrySink> current_sink_;
|
|
|
|
|
|
ComPtr<ID2D1StrokeStyle> outline_join_style_;
|
|
|
|
|
|
ComPtr<ID2D1SolidColorBrush> fill_brush_;
|
|
|
|
|
|
ComPtr<ID2D1SolidColorBrush> stroke_brush_;
|
|
|
|
|
|
ComPtr<IDWriteTextFormat> text_format_;
|
|
|
|
|
|
ComPtr<ITextRenderer> text_renderer_;
|
|
|
|
|
|
ComPtr<ID2D1BitmapRenderTarget> render_target_;
|
|
|
|
|
|
|
|
|
|
|
|
mutable bool cache_expired_;
|
|
|
|
|
|
mutable ComPtr<ID2D1Bitmap> bitmap_cached_;
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|