Magic_Game/core/base/Canvas.h

137 lines
2.7 KiB
C
Raw Normal View History

// 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
{
// <20><><EFBFBD><EFBFBD>
class Canvas
: public Node
{
2018-11-12 20:46:54 +08:00
E2D_DISABLE_COPY(Canvas);
public:
Canvas(
float width,
float height
);
virtual ~Canvas();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
void SetLineColor(
const Color& color
);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
void SetFillColor(
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 SetStrokeStyle(
StrokeStyle stroke
);
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
Color GetLineColor() const;
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
Color GetFillColor() const;
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
float GetStrokeWidth() const;
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0BDBB>ʽ
StrokeStyle GetStrokeStyle() const;
// <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><><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
);
private:
float stroke_width_;
2018-11-12 20:46:54 +08:00
StrokeStyle stroke_;
ID2D1RenderTarget* render_target_;
ID2D1SolidColorBrush* fill_brush_;
ID2D1SolidColorBrush* line_brush_;
ID2D1StrokeStyle* stroke_style_;
};
}