2018-10-03 22:02:46 +08:00
|
|
|
|
// 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.
|
|
|
|
|
|
|
2018-11-08 21:39:26 +08:00
|
|
|
|
#pragma once
|
2018-11-23 14:55:03 +08:00
|
|
|
|
#include "include-forwards.h"
|
2018-11-15 14:35:19 +08:00
|
|
|
|
#include "Font.hpp"
|
2018-11-12 02:10:35 +08:00
|
|
|
|
#include "Resource.h"
|
2018-11-18 20:26:41 +08:00
|
|
|
|
#include "TextStyle.hpp"
|
2018-11-23 14:55:03 +08:00
|
|
|
|
#include "Singleton.hpp"
|
2019-03-10 13:44:02 +08:00
|
|
|
|
#include "../DX/helper.hpp"
|
|
|
|
|
|
#include "../DX/DeviceResources.h"
|
|
|
|
|
|
#include "../DX/TextRenderer.h"
|
|
|
|
|
|
#include "time.h"
|
|
|
|
|
|
#include <d2d1.h>
|
|
|
|
|
|
#include <d2d1_1.h>
|
2018-05-22 13:49:10 +08:00
|
|
|
|
|
2018-11-08 00:21:59 +08:00
|
|
|
|
namespace easy2d
|
2018-05-22 13:49:10 +08:00
|
|
|
|
{
|
2019-03-10 13:44:02 +08:00
|
|
|
|
struct RenderStatus
|
2018-11-08 00:21:59 +08:00
|
|
|
|
{
|
2019-03-10 13:44:02 +08:00
|
|
|
|
TimePoint start;
|
|
|
|
|
|
Duration duration;
|
|
|
|
|
|
int primitives;
|
|
|
|
|
|
};
|
2018-11-23 14:55:03 +08:00
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
class E2D_API Renderer
|
|
|
|
|
|
: public Singleton<Renderer>
|
|
|
|
|
|
{
|
|
|
|
|
|
E2D_DECLARE_SINGLETON(Renderer);
|
2018-11-25 20:25:46 +08:00
|
|
|
|
|
2018-11-22 19:31:44 +08:00
|
|
|
|
public:
|
2019-03-10 13:44:02 +08:00
|
|
|
|
HRESULT Init(HWND hwnd);
|
2018-11-22 19:31:44 +08:00
|
|
|
|
|
2019-02-09 00:03:24 +08:00
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
inline RenderStatus const& GetStatus() const { return status_; }
|
|
|
|
|
|
|
|
|
|
|
|
inline DeviceResources* GetDeviceResources() const { return device_resources_.Get(); }
|
|
|
|
|
|
|
|
|
|
|
|
inline ITextRenderer* GetTextRenderer() const { return text_renderer_.Get(); }
|
|
|
|
|
|
|
|
|
|
|
|
inline ID2D1SolidColorBrush* GetSolidColorBrush() const { return solid_color_brush_.Get(); }
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT BeginDraw();
|
2018-11-22 19:31:44 +08:00
|
|
|
|
|
|
|
|
|
|
HRESULT EndDraw();
|
|
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
HRESULT CreateLayer(
|
|
|
|
|
|
ComPtr<ID2D1Layer>& layer
|
2018-11-22 19:31:44 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
HRESULT DrawGeometry(
|
|
|
|
|
|
ComPtr<ID2D1Geometry> const& geometry,
|
|
|
|
|
|
const Color& stroke_color,
|
|
|
|
|
|
float stroke_width,
|
|
|
|
|
|
StrokeStyle stroke = StrokeStyle::Miter
|
2018-11-22 19:31:44 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
HRESULT FillGeometry(
|
|
|
|
|
|
ComPtr<ID2D1Geometry> const& geometry,
|
|
|
|
|
|
Color const& fill_color
|
2018-11-22 19:31:44 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
HRESULT DrawImage(
|
|
|
|
|
|
ImagePtr const& image,
|
|
|
|
|
|
Rect const& dest_rect
|
2018-11-22 19:31:44 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
HRESULT DrawBitmap(
|
|
|
|
|
|
ComPtr<ID2D1Bitmap> const& bitmap
|
|
|
|
|
|
);
|
2018-11-22 19:31:44 +08:00
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
HRESULT DrawTextLayout(
|
|
|
|
|
|
ComPtr<IDWriteTextLayout> const& text_layout
|
2018-11-22 19:31:44 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
void SetClearColor(
|
|
|
|
|
|
Color const& clear_color
|
|
|
|
|
|
);
|
2018-11-22 19:31:44 +08:00
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
// <20><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
|
|
|
|
|
HRESULT SetAntialiasMode(
|
|
|
|
|
|
bool enabled
|
2018-11-22 19:31:44 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD><D6BF><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
|
|
|
|
|
HRESULT SetTextAntialiasMode(
|
|
|
|
|
|
TextAntialias mode
|
2018-11-22 19:31:44 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
// <20><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><CDB8><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetOpacity(
|
|
|
|
|
|
float opacity
|
2018-11-22 19:31:44 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT SetTransform(
|
2018-11-25 15:00:15 +08:00
|
|
|
|
const Matrix& matrix
|
2018-11-22 19:31:44 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT SetTextStyle(
|
|
|
|
|
|
const Color& color,
|
|
|
|
|
|
bool has_outline,
|
|
|
|
|
|
const Color& outline_color,
|
|
|
|
|
|
float outline_width,
|
|
|
|
|
|
StrokeStyle outline_stroke
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT PushClip(
|
2018-11-25 15:00:15 +08:00
|
|
|
|
const Matrix& clip_matrix,
|
2018-11-22 19:31:44 +08:00
|
|
|
|
const Size& clip_size
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT PopClip();
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT PushLayer(
|
2019-03-10 13:44:02 +08:00
|
|
|
|
ComPtr<ID2D1Layer> const& layer,
|
2018-11-22 19:31:44 +08:00
|
|
|
|
LayerProperties const& properties
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT PopLayer();
|
|
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
private:
|
|
|
|
|
|
Renderer();
|
2018-11-22 19:31:44 +08:00
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
~Renderer();
|
2018-11-22 19:31:44 +08:00
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
HRESULT CreateDeviceResources();
|
2018-11-23 14:55:03 +08:00
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
HRESULT HandleDeviceLost();
|
2018-11-23 14:55:03 +08:00
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
private:
|
|
|
|
|
|
float opacity_;
|
|
|
|
|
|
bool antialias_;
|
|
|
|
|
|
unsigned long ref_count_;
|
2018-11-22 19:31:44 +08:00
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
TextAntialias text_antialias_;
|
|
|
|
|
|
D2D1_COLOR_F clear_color_;
|
|
|
|
|
|
RenderStatus status_;
|
2018-11-22 19:31:44 +08:00
|
|
|
|
|
2019-03-10 13:44:02 +08:00
|
|
|
|
ComPtr<DeviceResources> device_resources_;
|
|
|
|
|
|
ComPtr<ID2D1Factory1> factory_;
|
|
|
|
|
|
ComPtr<ID2D1DeviceContext> device_context_;
|
|
|
|
|
|
ComPtr<ID2D1DrawingStateBlock> drawing_state_block_;
|
|
|
|
|
|
ComPtr<ITextRenderer> text_renderer_;
|
|
|
|
|
|
ComPtr<ID2D1SolidColorBrush> solid_color_brush_;
|
2018-11-22 19:31:44 +08:00
|
|
|
|
};
|
2018-11-08 21:39:26 +08:00
|
|
|
|
}
|