Magic_Game/core/base/Canvas.h

138 lines
2.7 KiB
C++

// Copyright (c) 2016-2018 Easy2D - Nomango
//
// 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 <d2d1.h>
namespace easy2d
{
// »­²¼
class Canvas
: public Node
{
public:
Canvas(
float width,
float height
);
virtual ~Canvas();
// ÉèÖÃÏßÌõÑÕÉ«
void SetLineColor(
const Color& color
);
// ÉèÖÃÌî³äÑÕÉ«
void SetFillColor(
const Color& color
);
// ÉèÖÃÏßÌõ¿í¶È
void SetStrokeWidth(
float width
);
// ÉèÖÃÏßÌõÏཻÑùʽ
void SetStrokeStyle(
Stroke strokeStyle
);
// »ñÈ¡ÏßÌõÑÕÉ«
Color GetLineColor() const;
// »ñÈ¡Ìî³äÑÕÉ«
Color GetFillColor() const;
// »ñÈ¡ÏßÌõ¿í¶È
float GetStrokeWidth() const;
// »ñÈ¡ÏßÌõÏཻÑùʽ
Stroke GetStrokeStyle() const;
// »­Ö±Ïß
void DrawLine(
const Point& begin,
const Point& end
);
// »­Ô²Ðα߿ò
void DrawCircle(
const Point& center,
float radius
);
// »­ÍÖÔ²Ðα߿ò
void DrawEllipse(
const Point& center,
float radius_x,
float radius_y
);
// »­¾ØÐα߿ò
void DrawRect(
const Rect& rect
);
// »­Ô²½Ç¾ØÐα߿ò
void DrawRoundedRect(
const Rect& rect,
float radius_x,
float radius_y
);
// Ìî³äÔ²ÐÎ
void FillCircle(
const Point& center,
float radius
);
// Ìî³äÍÖÔ²ÐÎ
void FillEllipse(
const Point& center,
float radius_x,
float radius_y
);
// Ìî³ä¾ØÐÎ
void FillRect(
const Rect& rect
);
// Ìî³äÔ²½Ç¾ØÐÎ
void FillRoundedRect(
const Rect& rect,
float radius_x,
float radius_y
);
private:
E2D_DISABLE_COPY(Canvas);
private:
float stroke_width_;
Stroke stroke_;
ID2D1RenderTarget* render_target_;
ID2D1SolidColorBrush* fill_brush_;
ID2D1SolidColorBrush* line_brush_;
ID2D1StrokeStyle* stroke_style_;
};
}