2019-04-11 14:40:54 +08:00
|
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
2020-01-21 10:09:55 +08:00
|
|
|
|
//
|
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:
|
2020-01-21 10:09:55 +08:00
|
|
|
|
//
|
2019-03-31 01:37:06 +08:00
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
// all copies or substantial portions of the Software.
|
2020-01-21 10:09:55 +08:00
|
|
|
|
//
|
2019-03-31 01:37:06 +08:00
|
|
|
|
// 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
|
2019-10-11 21:55:29 +08:00
|
|
|
|
#include <kiwano/2d/Actor.h>
|
2020-04-26 21:20:58 +08:00
|
|
|
|
#include <kiwano/render/Frame.h>
|
2020-02-16 20:14:01 +08:00
|
|
|
|
#include <kiwano/render/ShapeMaker.h>
|
2020-02-20 18:22:52 +08:00
|
|
|
|
#include <kiwano/render/RenderContext.h>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-04-11 14:40:54 +08:00
|
|
|
|
namespace kiwano
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
2020-02-06 16:54:47 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
KGE_DECLARE_SMART_PTR(Canvas);
|
2020-10-06 00:14:27 +08:00
|
|
|
|
KGE_DECLARE_SMART_PTR(CanvasRenderContext);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \addtogroup Actors
|
|
|
|
|
|
* @{
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
* @details <EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD>Ρ<EFBFBD>ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵȸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ͼԪ<EFBFBD><EFBFBD>ͬʱ<EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD>
|
2020-01-21 10:09:55 +08:00
|
|
|
|
*/
|
|
|
|
|
|
class KGE_API Canvas : public Actor
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
2020-10-06 00:14:27 +08:00
|
|
|
|
Canvas();
|
|
|
|
|
|
|
2020-02-06 16:54:47 +08:00
|
|
|
|
/// \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param size <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
2020-07-22 21:08:48 +08:00
|
|
|
|
Canvas(const Size& size);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-04-26 21:20:58 +08:00
|
|
|
|
/// @brief <20><>ȡ2D<32><44>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2020-10-06 00:14:27 +08:00
|
|
|
|
CanvasRenderContextPtr GetContext2D() const;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
2020-02-08 00:17:31 +08:00
|
|
|
|
/// \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>軭<EFBFBD><E8BBAD><EFBFBD><EFBFBD>С
|
2020-04-26 21:20:58 +08:00
|
|
|
|
/// @warning <20>ú<EFBFBD><C3BA><EFBFBD><EFBFBD>ᵼ<EFBFBD><E1B5BC>ԭ<EFBFBD><D4AD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧЧ
|
2020-02-08 00:17:31 +08:00
|
|
|
|
void ResizeAndClear(Size size);
|
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
/// \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2020-01-21 10:09:55 +08:00
|
|
|
|
TexturePtr ExportToTexture() const;
|
|
|
|
|
|
|
|
|
|
|
|
void OnRender(RenderContext& ctx) override;
|
|
|
|
|
|
|
2020-10-06 00:14:27 +08:00
|
|
|
|
private:
|
|
|
|
|
|
void RecreateContext(Size* size);
|
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
private:
|
2020-02-20 18:22:52 +08:00
|
|
|
|
TexturePtr texture_cached_;
|
|
|
|
|
|
RenderContextPtr render_ctx_;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2020-10-06 00:14:27 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
class KGE_API CanvasRenderContext : public ObjectBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ʼ<EFBFBD><CABC>Ⱦ
|
|
|
|
|
|
void BeginDraw();
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ
|
|
|
|
|
|
void EndDraw();
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>״<EFBFBD><D7B4><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param shape <20><>״
|
|
|
|
|
|
void DrawShape(ShapePtr shape);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>߶<EFBFBD>
|
|
|
|
|
|
/// @param begin <20>߶<EFBFBD><DFB6><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param end <20>߶<EFBFBD><DFB6>յ<EFBFBD>
|
|
|
|
|
|
void DrawLine(const Point& begin, const Point& end);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>Բ<EFBFBD>α߿<CEB1>
|
|
|
|
|
|
/// @param center Բ<><D4B2>ԭ<EFBFBD><D4AD>
|
|
|
|
|
|
/// @param radius Բ<>ΰ뾶
|
|
|
|
|
|
void DrawCircle(const Point& center, float radius);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>Բ<EFBFBD>α߿<CEB1>
|
|
|
|
|
|
/// @param center <20><>Բԭ<D4B2><D4AD>
|
|
|
|
|
|
/// @param radius <20><>Բ<EFBFBD>뾶
|
|
|
|
|
|
void DrawEllipse(const Point& center, const Vec2& radius);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>α߿<CEB1>
|
|
|
|
|
|
/// @param rect <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
void DrawRect(const Rect& rect);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>Բ<EFBFBD>Ǿ<EFBFBD><C7BE>α߿<CEB1>
|
|
|
|
|
|
/// @param rect <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param radius <20><><EFBFBD><EFBFBD>Բ<EFBFBD>ǰ뾶
|
|
|
|
|
|
void DrawRoundedRect(const Rect& rect, const Vec2& radius);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״
|
|
|
|
|
|
/// @param shape <20><>״
|
|
|
|
|
|
void FillShape(ShapePtr shape);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>
|
|
|
|
|
|
/// @param center Բ<><D4B2>ԭ<EFBFBD><D4AD>
|
|
|
|
|
|
/// @param radius Բ<>ΰ뾶
|
|
|
|
|
|
void FillCircle(const Point& center, float radius);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>
|
|
|
|
|
|
/// @param center <20><>Բԭ<D4B2><D4AD>
|
|
|
|
|
|
/// @param radius <20><>Բ<EFBFBD>뾶
|
|
|
|
|
|
void FillEllipse(const Point& center, const Vec2& radius);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param rect <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
void FillRect(const Rect& rect);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>Բ<EFBFBD>Ǿ<EFBFBD><C7BE><EFBFBD>
|
|
|
|
|
|
/// @param rect <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param radius <20><><EFBFBD><EFBFBD>Բ<EFBFBD>ǰ뾶
|
|
|
|
|
|
void FillRoundedRect(const Rect& rect, const Vec2& radius);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>֡
|
|
|
|
|
|
/// @param frame ͼ<><CDBC>֡
|
|
|
|
|
|
/// @param pos <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
void DrawFrame(FramePtr frame, const Point& pos);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>֡
|
|
|
|
|
|
/// @param frame ͼ<><CDBC>֡
|
|
|
|
|
|
/// @param pos <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
/// @param size <20><>Ⱦ<EFBFBD><C8BE>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>С
|
|
|
|
|
|
void DrawFrame(FramePtr frame, const Point& pos, const Size& size);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD>
|
|
|
|
|
|
/// @param text <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param style <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
|
/// @param point <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
void DrawTextLayout(const String& text, const TextStyle& style, const Point& point);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD>
|
|
|
|
|
|
/// @param layout <20><><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD>
|
|
|
|
|
|
/// @param point <20><><EFBFBD>Ʋ<EFBFBD><C6B2>ֵ<EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
void DrawTextLayout(TextLayoutPtr layout, const Point& point);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
|
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
|
|
|
|
|
/// @param clear_color <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
void Clear(const Color& clear_color);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
/// @param color <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
void SetFillColor(const Color& color);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>仭ˢ
|
|
|
|
|
|
/// @param[in] brush <20><><EFBFBD>仭ˢ
|
|
|
|
|
|
void SetFillBrush(BrushPtr brush);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD>仭ˢ
|
|
|
|
|
|
BrushPtr GetFillBrush() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
/// @param color <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
void SetStrokeColor(const Color& color);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ
|
|
|
|
|
|
/// @param[in] brush <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ
|
|
|
|
|
|
void SetStrokeBrush(BrushPtr brush);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ
|
|
|
|
|
|
BrushPtr GetStrokeBrush() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
|
/// @param stroke_style <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
|
void SetStrokeStyle(StrokeStylePtr stroke_style);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
|
StrokeStylePtr GetStrokeStyle() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param clip_rect <20>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void PushClipRect(const Rect& clip_rect);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵIJü<C4B2><C3BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void PopClipRect();
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ͼ<EFBFBD><CDBC>
|
|
|
|
|
|
/// @param layer ͼ<><CDBC>
|
|
|
|
|
|
void PushLayer(LayerPtr layer);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ͼ<EFBFBD><CDBC>
|
|
|
|
|
|
void PopLayer();
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
|
|
|
|
|
Size GetSize() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD><EFBFBD>ĵĶ<C4B5>ά<EFBFBD>任<EFBFBD><E4BBBB><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetTransform(const Matrix3x2& matrix);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
|
|
|
|
|
void SetAntialiasMode(bool enabled);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD><D6BF><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
|
|
|
|
|
void SetTextAntialiasMode(TextAntialiasMode mode);
|
|
|
|
|
|
|
|
|
|
|
|
virtual ~CanvasRenderContext();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
friend class Canvas;
|
|
|
|
|
|
|
|
|
|
|
|
CanvasRenderContext(RenderContextPtr ctx);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
RenderContextPtr ctx_;
|
|
|
|
|
|
BrushPtr fill_brush_;
|
|
|
|
|
|
BrushPtr stroke_brush_;
|
|
|
|
|
|
StrokeStylePtr stroke_style_;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
/** @} */
|
|
|
|
|
|
|
2020-10-06 00:14:27 +08:00
|
|
|
|
inline void CanvasRenderContext::BeginDraw()
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
ctx_->BeginDraw();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::EndDraw()
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
ctx_->EndDraw();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::DrawShape(ShapePtr shape)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
if (shape)
|
|
|
|
|
|
{
|
|
|
|
|
|
ctx_->SetCurrentBrush(stroke_brush_);
|
|
|
|
|
|
ctx_->SetCurrentStrokeStyle(stroke_style_);
|
|
|
|
|
|
ctx_->DrawShape(*shape);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::DrawLine(const Point& begin, const Point& end)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
|
|
|
|
|
|
ctx_->SetCurrentBrush(stroke_brush_);
|
|
|
|
|
|
ctx_->SetCurrentStrokeStyle(stroke_style_);
|
|
|
|
|
|
ctx_->DrawLine(begin, end);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::DrawCircle(const Point& center, float radius)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
|
|
|
|
|
|
ctx_->SetCurrentBrush(stroke_brush_);
|
|
|
|
|
|
ctx_->SetCurrentStrokeStyle(stroke_style_);
|
|
|
|
|
|
ctx_->DrawCircle(center, radius);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::DrawEllipse(const Point& center, const Vec2& radius)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
|
|
|
|
|
|
ctx_->SetCurrentBrush(stroke_brush_);
|
|
|
|
|
|
ctx_->SetCurrentStrokeStyle(stroke_style_);
|
|
|
|
|
|
ctx_->DrawEllipse(center, radius);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::DrawRect(const Rect& rect)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
|
|
|
|
|
|
ctx_->SetCurrentBrush(stroke_brush_);
|
|
|
|
|
|
ctx_->SetCurrentStrokeStyle(stroke_style_);
|
|
|
|
|
|
ctx_->DrawRectangle(rect);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::DrawRoundedRect(const Rect& rect, const Vec2& radius)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
|
|
|
|
|
|
ctx_->SetCurrentBrush(stroke_brush_);
|
|
|
|
|
|
ctx_->SetCurrentStrokeStyle(stroke_style_);
|
|
|
|
|
|
ctx_->DrawRoundedRectangle(rect, radius);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::FillShape(ShapePtr shape)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
if (shape)
|
|
|
|
|
|
{
|
|
|
|
|
|
ctx_->SetCurrentBrush(fill_brush_);
|
|
|
|
|
|
ctx_->FillShape(*shape);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::FillCircle(const Point& center, float radius)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
|
|
|
|
|
|
ctx_->SetCurrentBrush(fill_brush_);
|
|
|
|
|
|
ctx_->FillCircle(center, radius);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::FillEllipse(const Point& center, const Vec2& radius)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
|
|
|
|
|
|
ctx_->SetCurrentBrush(fill_brush_);
|
|
|
|
|
|
ctx_->FillEllipse(center, radius);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::FillRect(const Rect& rect)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
|
|
|
|
|
|
ctx_->SetCurrentBrush(fill_brush_);
|
|
|
|
|
|
ctx_->FillRectangle(rect);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::FillRoundedRect(const Rect& rect, const Vec2& radius)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
|
|
|
|
|
|
ctx_->SetCurrentBrush(fill_brush_);
|
|
|
|
|
|
ctx_->FillRoundedRectangle(rect, radius);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::DrawFrame(FramePtr frame, const Point& pos)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (frame)
|
|
|
|
|
|
{
|
|
|
|
|
|
Size frame_size = frame->GetSize();
|
|
|
|
|
|
this->DrawFrame(frame, pos, frame_size);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::DrawFrame(FramePtr frame, const Point& pos, const Size& size)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
|
|
|
|
|
|
if (frame)
|
|
|
|
|
|
{
|
|
|
|
|
|
ctx_->DrawFrame(frame, Rect(pos, size));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::DrawTextLayout(const String& text, const TextStyle& style, const Point& point)
|
|
|
|
|
|
{
|
|
|
|
|
|
TextLayoutPtr layout = MakePtr<TextLayout>(text, style);
|
|
|
|
|
|
this->DrawTextLayout(layout, point);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::DrawTextLayout(TextLayoutPtr layout, const Point& point)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
if (layout)
|
|
|
|
|
|
{
|
|
|
|
|
|
ctx_->DrawTextLayout(*layout, point);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::Clear()
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
ctx_->Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::Clear(const Color& clear_color)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
ctx_->Clear(clear_color);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::SetFillColor(const Color& color)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!fill_brush_)
|
|
|
|
|
|
{
|
|
|
|
|
|
fill_brush_ = MakePtr<Brush>();
|
|
|
|
|
|
}
|
|
|
|
|
|
fill_brush_->SetColor(color);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::SetFillBrush(BrushPtr brush)
|
|
|
|
|
|
{
|
|
|
|
|
|
fill_brush_ = brush;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline BrushPtr CanvasRenderContext::GetFillBrush() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return fill_brush_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::SetStrokeBrush(BrushPtr brush)
|
|
|
|
|
|
{
|
|
|
|
|
|
stroke_brush_ = brush;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::SetStrokeColor(const Color& color)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!stroke_brush_)
|
|
|
|
|
|
{
|
|
|
|
|
|
stroke_brush_ = MakePtr<Brush>();
|
|
|
|
|
|
}
|
|
|
|
|
|
stroke_brush_->SetColor(color);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline BrushPtr CanvasRenderContext::GetStrokeBrush() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return stroke_brush_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::SetStrokeStyle(StrokeStylePtr stroke_style)
|
|
|
|
|
|
{
|
|
|
|
|
|
stroke_style_ = stroke_style;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline StrokeStylePtr CanvasRenderContext::GetStrokeStyle() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return stroke_style_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::PushClipRect(const Rect& clip_rect)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
ctx_->PushClipRect(clip_rect);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::PopClipRect()
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
ctx_->PopClipRect();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::PushLayer(LayerPtr layer)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
if (layer)
|
|
|
|
|
|
{
|
|
|
|
|
|
ctx_->PushLayer(*layer);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::PopLayer()
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
ctx_->PopLayer();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Size CanvasRenderContext::GetSize() const
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
return ctx_->GetSize();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::SetTransform(const Matrix3x2& matrix)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
ctx_->SetTransform(matrix);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::SetAntialiasMode(bool enabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
ctx_->SetAntialiasMode(enabled);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void CanvasRenderContext::SetTextAntialiasMode(TextAntialiasMode mode)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(ctx_);
|
|
|
|
|
|
ctx_->SetTextAntialiasMode(mode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
} // namespace kiwano
|