目录
- 前言
- D2DEngine全代码示例
- D2DEngine全函数解析
- D2DEngine
-
- 表层设备类
-
- D2DEngine::Initialize
- D2DEngine::ChangeRenderTarget
- D2DEngine::ChangeRenderSize
- D2DEngine::ChangeBrushColor
- D2DEngine::ChangeLinearBrushColor
- D2DEngine::ChangeRadialBrushColor
- D2DEngine::ChangeStrokeStyle
- D2DEngine::ChangeTextFormat
- D2DEngine::CreateLayer
- D2DEngine::CreateRectangle
- D2DEngine::CreateRoundedRectangle
- D2DEngine::CreateEllipse
- D2DEngine::OpenGeometryDevice
- D2DEngine::AddLineGeometry
- D2DEngine::AddArcGeometry
- D2DEngine::AddBezierGeometry
- D2DEngine::AddBezierGeometries
- D2DEngine::AddQuadraticBezierGeometry
- D2DEngine::AddQuadraticBezierGeometries
- D2DEngine::AddCombineGeometry
- D2DEngine::CloseGeometryDevice
- D2DEngine::SetTransform
- 渲染类
-
- D2DEngine::BeginDraw
- D2DEngine::EndDraw
- D2DEngine::Clear
- D2DEngine::PushLayer
- D2DEngine::PopLayer
- D2DEngine::DrawBitmap
- D2DEngine::Drawtext
- D2DEngine::DrawLine
- D2DEngine::DrawRectangle
- D2DEngine::FillRectangle
- D2DEngine::DrawRoundedRectangle
- D2DEngine::FillRoundedRectangle
- D2DEngine::DrawEllipse
- D2DEngine::FillEllipse
- D2DEngine::DrawCustomGeometry
- D2DEngine::FillCustomGeometry
- WIC类
- D2DBitmap
- D2D图形类
-
- 基类成员函数
-
- D2DBasicGeometry::GetReadOnlyTransformedMatrixes
- D2DBasicGeometry::GetReferencedTransformedMatrixes
- D2DBasicGeometry::Clear
- D2DBasicGeometry::ClearTransform
- D2DBasicGeometry::GetSize
- D2DBasicGeometry::Empty
- D2DBasicGeometry::Identity
- D2DBasicGeometry::Scale
- D2DBasicGeometry::Translation
- D2DBasicGeometry::Rotation
- D2DBasicGeometry::Skew
- D2DBasicGeometry::AddScale
- D2DBasicGeometry::AddTranslation
- D2DBasicGeometry::AddRotation
- D2DBasicGeometry::AddSkew
- D2DBasicGeometry::append
- D2DBasicGeometry::remove
- D2DBasicGeometry::insert
- D2DEngineSpace
—————————————————————————————————————————————————————
前言
D2DEngine V1.0.1 链接:https://blog.csdn.net/DGAF2198588973/article/details/125909836
D2DEngine内部架构简析
将"符合模式"一项改"否"(/permissive)
—————————————————————————————————————————————————————
模板.cpp
模板对所有D2DEngine程序都通用
#include<windows.h>
#include"D2DEngine1_0.h" //直接引用头文件
LRESULT CALLBACK CallBackFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hin, HINSTANCE, LPSTR, int CmdShow)
{
MSG msg = {};
WNDCLASSEX wcex = {};
memset(&wcex, 0, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = CallBackFunc;
wcex.lpszClassName = L"D2D";
wcex.hInstance = hin;
wcex.style = CS_GLOBALCLASS; // 去掉ReDraw重画
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
// 设置为NULL_BRUSH,不需要来自GDI的任何绘制
RegisterClassEx(&wcex);
HWND hwnd = CreateWindowW(wcex.lpszClassName, L"D2D",
WS_OVERLAPPED | WS_SYSMENU,
// WS_OVERLAPPEDWINDOW 会触发OnSize消息,暂时先不处理这个消息
0, 0, 640, 480,
nullptr,
nullptr,
hin,
nullptr
);
ShowWindow(hwnd, CmdShow);
// 因为 CS_GLOBALCLASS,必须要用ShowWindow显示窗口
//————————————————————————————————————————————————————————————————————
//TODO:在这里进行 Direct2D渲染
//————————————————————————————————————————————————————————————————————
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
—————————————————————————————————————————————————————
D2DEngine全代码示例
1.绘制背景色窗口
// D2DHelloWorld.cpp
#include<windows.h>
#include"D2DEngine1_0.h"
using namespace D2D1;
LRESULT CALLBACK CallBackFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hin, HINSTANCE, LPSTR, int CmdShow)
{
MSG msg = {};
WNDCLASSEX wcex = {};
memset(&wcex, 0, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = CallBackFunc;
wcex.lpszClassName = L"D2D";
wcex.hInstance = hin;
wcex.style = CS_GLOBALCLASS;
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
RegisterClassEx(&wcex);
HWND hwnd = CreateWindowW(wcex.lpszClassName, L"D2D",
WS_OVERLAPPED | WS_SYSMENU,
0, 0, 640, 480,
nullptr,
nullptr,
hin,
nullptr
);
ShowWindow(hwnd, CmdShow);
//————————————————————————————————————————————————————————————————————
D2DEngine* Engine = new D2DEngine; //创建 D2DEngine对象
Engine->Initialize(hwnd); //用句柄初始化D2DEngine
Engine->BeginDraw();
Engine->Clear(ColorF::Blue); //将窗口清空并渲染成蓝色
Engine->EndDraw();
//————————————————————————————————————————————————————————————————————
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
—————————————————————————————————————————————————————
2.绘制静态图片
// D2DDrawStaticBitmap.cpp
#include<windows.h>
#include"D2DEngine1_0.h"
using namespace std;
using namespace D2D1;
LRESULT CALLBACK CallBackFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hin, HINSTANCE, LPSTR, int CmdShow)
{
MSG msg = {};
WNDCLASSEX wcex = {};
memset(&wcex, 0, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = CallBackFunc;
wcex.lpszClassName = L"D2D";
wcex.hInstance = hin;
wcex.style = CS_GLOBALCLASS;
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
RegisterClassEx(&wcex);
HWND hwnd = CreateWindowW(wcex.lpszClassName, L"D2D",
WS_OVERLAPPED | WS_SYSMENU,
0, 0, 517.5, 709.5,
nullptr,
nullptr,
hin,
nullptr
);
ShowWindow(hwnd, CmdShow);
D2DEngine* Engine = new D2DEngine; // 创建 D2DEngine对象
Engine->Initialize(hwnd); // 初始化 D2DEngine设备
D2DBitmap Photo(L"鬼吕.jpeg");
// 创建 Picture类对象,并用图片路径初始化
Engine->TransformPictureIntoBitmap(Photo);
// 图片转换,经过这一步才能正确加载 D2D位图
Engine->BeginDraw(); // 开始绘制
Engine->DrawBitmap(Photo, 0, 0, 517.5, 709.5); // 绘制图片
Engine->EndDraw(); // 结束绘制
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
—————————————————————————————————————————————————————
3.绘制动态图片
// D2DDrawDynamicBitmap.cpp
#include<windows.h>
#include<thread>
#include"D2DEngine1_0.h"
using namespace std;
using namespace D2D1;
D2DEngine* Engine = new D2DEngine; // 创建 D2DEngine对象
D2DBitmapGroup BitmapGroup; // 创建图组,用于动图
D2DBitmap GIF(L"引流之主.gif"); // 创建 Picture类对象,并用图片路径初始化,这里填 GIF(动图路径)
void Draw()
{
Engine->TransformPictureIntoBitmap(GIF, BitmapGroup);
// 图片转换,经过这一步才能正确加载 D2D位图
// 使用了 TransformPictureIntoBitmap 的重载函数
size_t framecount = BitmapGroup.BitmapGroup.size(); //获取动图总帧数
size_t tloop = 0; // 循环次数
size_t i = 0; // 循环形参,表示第 i帧图片
// 循环3次
while (tloop < 3)
{
Engine->BeginDraw(); // 开始绘制
Engine->DrawBitmap(BitmapGroup.BitmapGroup[i], 0, 0, 448, 680); // 绘制第 i帧图片
Engine->EndDraw(); // 结束绘制
Sleep(80); //使程序停止80毫秒,这样能产生视觉效应
if (i == framecount - 1) //如果播放到最后一帧
{
tloop++; //循环次数加一
i = 0; //重置形参, 从第一帧开始绘制
}
i++; //帧数加一
}
}
LRESULT CALLBACK CallBackFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hin, HINSTANCE, LPSTR, int CmdShow)
{
MSG msg = {};
WNDCLASSEX wcex = {};
memset(&wcex, 0, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = CallBackFunc;
wcex.lpszClassName = L"D2D";
wcex.hInstance = hin;
wcex.style = CS_GLOBALCLASS;
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
RegisterClassEx(&wcex);
HWND hwnd = CreateWindowW(wcex.lpszClassName, L"D2D",
WS_OVERLAPPED | WS_SYSMENU,
300, 0, 448, 680,
nullptr,
nullptr,
hin,
nullptr
);
ShowWindow(hwnd, CmdShow);
Engine->Initialize(hwnd); // 初始化 D2DEngine设备
thread thread_1(Draw); // 开启线程
thread_1.detach(); //释放线程,令线程不阻断消息循环
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
—————————————————————————————————————————————————————
4.导出窗口图像为静态图片
// D2DPackImage.cpp
#include<windows.h>
#include"D2DEngine1_0.h"
using namespace std;
using namespace D2D1;
LRESULT CALLBACK CallBackFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hin, HINSTANCE, LPSTR, int CmdShow)
{
MSG msg = {};
WNDCLASSEX wcex = {};
memset(&wcex, 0, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = CallBackFunc;
wcex.lpszClassName = L"D2D";
wcex.hInstance = hin;
wcex.style = CS_GLOBALCLASS;
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
RegisterClassEx(&wcex);
HWND hwnd = CreateWindowW(wcex.lpszClassName, L"D2D",
WS_OVERLAPPED | WS_SYSMENU,
300, 0, 640, 480,
nullptr,
nullptr,
hin,
nullptr
);
ShowWindow(hwnd, CmdShow);
D2DEngine* Engine = new D2DEngine; // 创建 D2DEngine对象
D2DBitmap Photo(L"曹操.jpeg"); //存储本文件夹下 曹操.jpeg 的图片路径
Engine->Initialize(hwnd); // 初始化 D2DEngine设备,渲染目标默认指定整个窗口客户区
Engine->TransformPictureIntoBitmap(Photo); //图片格式转换
Engine->BeginDraw(); //开始绘制
Engine->DrawBitmap(Photo, 0, 0, 640, 480); //将图片绘制在窗口客户区上
Engine->EndDraw(); //停止绘制
//至此, D2DEngine已绘制完成
Engine->PackRenderTargetAsImageFile
(L"", L"曹操", Picture_Format::BMP);
//截取整个窗口 (由于没有指定渲染目标) ,并将窗口的图像转换为图像文件
//由于没有指定路径名,程序会创建一个叫 曹操.bmp 的图像文件导出到其所在本地磁盘里
//你可以去看看本地磁盘是不是多了什么
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
—————————————————————————————————————————————————————
5.绘制文本
// D2DDrawText.cpp
#include<windows.h>
#include"D2DEngine1_0.h"
using namespace D2D1;
LRESULT CALLBACK CallBackFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hin, HINSTANCE, LPSTR, int CmdShow)
{
MSG msg = {};
WNDCLASSEX wcex = {};
memset(&wcex, 0, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = CallBackFunc;
wcex.lpszClassName = L"D2D";
wcex.hInstance = hin;
wcex.style = CS_GLOBALCLASS;
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
RegisterClassEx(&wcex);
HWND hwnd = CreateWindowW(wcex.lpszClassName, L"D2D",
WS_OVERLAPPED | WS_SYSMENU,
0, 0, 900, 554,
nullptr,
nullptr,
hin,
nullptr
);
ShowWindow(hwnd, CmdShow);
D2DEngine* Engine = new D2DEngine; //创建D2DEngine对象
D2DBitmap Pic(L"率土之滨.jpeg"); //创建图片对象
Engine->Initialize(hwnd); //用句柄初始化D2DEngine
Engine->TransformPictureIntoBitmap(Pic); //转换图片
Engine->BeginDraw(); //开始渲染
Engine->DrawBitmap(Pic, 0, 0, 900, 554); //先绘制图片
Engine->ChangeTextFormat(40, ColorF::White,L"叶根友毛笔行书2.0版");
//改变文本样式,字体大小为40,颜色为白色,字体簇(家族)为"叶根友毛笔行书2.0版"
Engine->Drawtext(L"率土之滨,莫非王臣", 400, 100, 400, 100);
//在 (400,100,800,200) 的区域绘制文字,使文字不被图片覆盖
Engine->EndDraw(); //停止渲染
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
—————————————————————————————————————————————————————
6.绘制文本并导出为动图
// D2DDrawText2.cpp
#include<windows.h>
#include<string>
#include<thread> //线程库
#include"D2DEngine1_0.h"
using namespace std;
using namespace D2D1;
D2DEngine* Engine; //全局D2DEngine,以便子线程能使用
D2DBitmap Pic(L"太师乱汉.jpeg"); //创建图片对象
void D2DThread(); //提供子线程运行的函数
LRESULT CALLBACK CallBackFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hin, HINSTANCE, LPSTR, int CmdShow)
{
MSG msg = {};
WNDCLASSEX wcex = {};
memset(&wcex, 0, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = CallBackFunc;
wcex.lpszClassName = L"D2D";
wcex.hInstance = hin;
wcex.style = CS_GLOBALCLASS;
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
RegisterClassEx(&wcex);
HWND hwnd = CreateWindowW(wcex.lpszClassName, L"D2D",
WS_OVERLAPPED | WS_SYSMENU,
0, 0, 1280, 642,
nullptr,
nullptr,
hin,
nullptr
);
ShowWindow(hwnd, CmdShow);
Engine = new D2DEngine; //创建D2DEngine对象
Engine->Initialize(hwnd); //用句柄初始化D2DEngine
Engine->TransformPictureIntoBitmap(Pic); //转换图片
thread thread1(D2DThread); //创建子线程
thread1.detach(); //不阻塞主线程,让子线程单独运行
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
void D2DThread()
{
D2DBitmapGroup Group; //创建图组
wstring text(L"董卓无道,帝室羸落,天下大乱,民不聊生,时待命世之英杰以济之");
D2D1::ColorF color(1.0f, 0.0f, 0.0f); //字体颜色
for (size_t i = 0; i < text.size(); i++)
{
color.r -= 0.03f;
color.g += 0.03f;
color.b += 0.03f;
Engine->BeginDraw(); //开始渲染
Engine->DrawBitmap(Pic, 0, 0, 1280, 642); //先绘制图片
Engine->ChangeTextFormat(40, color, L"叶根友毛笔行书2.0版");
//改变文本样式,字体大小为40,颜色为白色,字体簇(家族)为"叶根友毛笔行书2.0版"
Engine->Drawtext(&text.substr(0, i + 1)[0],
75, 400, 1200, 100);
//在 (75,400,1200,100) 的区域绘制文字,使文字不被图片覆盖
Engine->EndDraw(); //停止渲染
Group.BitmapGroup.push_back(Engine->RenderTargetShot()); //截一帧图片
Sleep(200); //停止200毫秒
}
Engine->PackD2DBitmapAsImageFile(L"", L"TSLH", Picture_Format::GIF, Group); //导出动图
}
—————————————————————————————————————————————————————
7.绘制图形1
// D2DDrawGeometry.cpp
#include<windows.h>
#include"D2DEngine1_0.h"
using namespace D2D1;
LRESULT CALLBACK CallBackFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hin, HINSTANCE, LPSTR, int CmdShow)
{
MSG msg = {};
WNDCLASSEX wcex = {};
memset(&wcex, 0, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = CallBackFunc;
wcex.lpszClassName = L"D2D";
wcex.hInstance = hin;
wcex.style = CS_GLOBALCLASS;
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
RegisterClassEx(&wcex);
HWND hwnd = CreateWindowW(wcex.lpszClassName, L"D2D",
WS_OVERLAPPED | WS_SYSMENU,
0, 0, 1000, 680,
nullptr,
nullptr,
hin,
nullptr
);
ShowWindow(hwnd, CmdShow);
D2DEngine* Engine = new D2DEngine;
Engine->Initialize(hwnd);
D2DRectangle rectangle(100, 100, 100, 150); //矩形
D2DRoundedRectangle rrectangle(400, 200, 300, 200, 10, 10); //圆角矩形
D2DEllipse ellipse(270, 450, 100, 100); //圆形
//创建图形
Engine->CreateRectangle(rectangle);
Engine->CreateRoundedRectangle(rrectangle);
Engine->CreateEllipse(ellipse);
//绘制图形
using D2D1::ColorF;
Engine->BeginDraw();
Engine->Clear(); //改变背景色为白色
//绘制直线,直线不需要Create函数就可以直接填参绘制
Engine->ChangeBrushColor(ColorF::MediumPurple);
Engine->DrawLine(50, 400, 500, 60, 2.0f, D2D_Brush_Type::NORMAL);
//填充矩形,使用普通画刷
Engine->ChangeBrushColor(ColorF::CadetBlue);
Engine->FillRectangle(rectangle,D2D_Brush_Type::NORMAL);
//圆角矩形描边,线条宽度3.0f,使用普通画刷
Engine->ChangeBrushColor(ColorF::Gold);
Engine->DrawRoundedRectangle(rrectangle, 3.0f, D2D_Brush_Type::NORMAL);
//绘制圆形
Engine->ChangeBrushColor(ColorF::LightSteelBlue);
Engine->FillEllipse(ellipse, D2D_Brush_Type::NORMAL);
Engine->EndDraw();
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
—————————————————————————————————————————————————————
8.绘制图形2
// D2DGradientExample.cpp
#include<windows.h>
#include"D2DEngine1_0.h"
using namespace D2D1;
LRESULT CALLBACK CallBackFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hin, HINSTANCE, LPSTR, int CmdShow)
{
MSG msg = {};
WNDCLASSEX wcex = {};
memset(&wcex, 0, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = CallBackFunc;
wcex.lpszClassName = L"D2D";
wcex.hInstance = hin;
wcex.style = CS_GLOBALCLASS;
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
RegisterClassEx(&wcex);
HWND hwnd = CreateWindowW(wcex.lpszClassName, L"D2D",
WS_OVERLAPPED | WS_SYSMENU,
0, 0, 1000, 680,
nullptr,
nullptr,
hin,
nullptr
);
ShowWindow(hwnd, CmdShow);
D2DEngine* Engine = new D2DEngine;
Engine->Initialize(hwnd);
D2DRectangle rectangle(100, 100, 100, 150); //矩形
D2DRoundedRectangle rrectangle(400, 200, 300, 200, 10, 10); //圆角矩形
D2DEllipse ellipse(270, 450, 100, 100); //圆形
//创建图形
Engine->CreateRectangle(rectangle);
Engine->CreateRoundedRectangle(rrectangle);
Engine->CreateEllipse(ellipse);
using D2D1::ColorF;
//绘制图形
Engine->BeginDraw();
Engine->Clear(ColorF::Azure);
//创建线性渐变画刷(第一次改变即为创建)
Engine->ChangeLinearGradientBrushColor({ ColorF::Blue,ColorF::Red }, { 1,0 },
D2D1::Point2F(50, 400), D2D1::Point2F(500, 60));
Engine->DrawLine(50, 400, 500, 60, 2.0f, D2D_Brush_Type::LINEAR); //使用线性渐变画刷
//使用上文创建的线性渐变画刷
Engine->FillRectangle(rectangle, D2D_Brush_Type::LINEAR); //绘制矩形
//创建放射渐变画刷
Engine->ChangeRadialGradientBrushColor(
{ ColorF::DarkBlue, ColorF::LightSteelBlue, ColorF::Blue },
{ 1,2,1 }, Point2F(550,300), Point2F(), 250, 250);
Engine->FillRoundedRectangle(rrectangle, D2D_Brush_Type::RADIAL); //绘制圆角矩形
//改变放射渐变画刷颜色
Engine->ChangeRadialGradientBrushColor(
{ ColorF::Black, ColorF::White },
{ 1,0 }, Point2F(270, 450), Point2F(), 100, 100);
Engine->FillEllipse(ellipse, D2D_Brush_Type::RADIAL); //绘制椭圆
Engine->EndDraw();
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
—————————————————————————————————————————————————————
9.绘制图形3
// D2DDrawGeometryX.cpp
#include "D2DEngine1_0.h" //直接引用头文件
#include <thread>
using namespace std;
D2DEngine* Engine = new D2DEngine; //D2D设备
void Render(HWND hwnd); //渲染函数
LRESULT CALLBACK CallBackFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hin, HINSTANCE, LPSTR, int CmdShow)
{
MSG msg = {};
WNDCLASSEX wcex = {};
memset(&wcex, 0, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = CallBackFunc;
wcex.lpszClassName = L"D2D";
wcex.hInstance = hin;
wcex.style = CS_GLOBALCLASS;
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
RegisterClassEx(&wcex);
HWND hwnd = CreateWindowW(wcex.lpszClassName, L"D2D",
WS_OVERLAPPED | WS_SYSMENU,
0, 0, 640, 480,
nullptr,
nullptr,
hin,
nullptr
);
ShowWindow(hwnd, CmdShow);
Engine->Initialize(hwnd); //初始化
thread draw(Render,hwnd); //创建线程
draw.detach(); //释放线程,使其单独运行
while (::GetMessage(&msg, NULL, 0, 0))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
return msg.wParam;
}
void Render(HWND hwnd)
{
D2DBitmapGroup Group; //用于存储动图
D2DRoundedRectangle RRectangle(50, 175, 510, 60, 1, 1); //进度条框
D2DRectangle rectangle(55, 180, 50, 50); //进度条
Engine->CreateRoundedRectangle(RRectangle);
Engine->ChangeBrushColor(D2D1::ColorF::Black);
Engine->BeginDraw();
Engine->Clear(); //背景设为白色
Engine->DrawRoundedRectangle(RRectangle, 1.0f, D2D_Brush_Type::NORMAL); //绘制进度条框
Engine->EndDraw();
std::vector<D2D1::ColorF> Color; //颜色组
Color.push_back(D2D1::ColorF::Red);
Color.push_back(D2D1::ColorF::Blue);
//渐变画刷
Engine->ChangeLinearGradientBrushColor(Color, { 0,1 },
D2D1::Point2F(55, 180), D2D1::Point2F(560, 235));
for (size_t i = 1; i < 11; i++)
{
Engine->CreateRectangle(rectangle); //创建进度条
Engine->BeginDraw();
Engine->FillRectangle(rectangle, D2D_Brush_Type::LINEAR); //绘制进度条
Engine->EndDraw();
rectangle.ChangeX(55 + i * 50); //改变进度条X坐标
Group.BitmapGroup.push_back(Engine->RenderTargetShot()); //截取快照
Sleep(200); //暂停0.2秒
}
Engine->PackD2DBitmapAsImageFile(L"", L"D2DEffect", Picture_Format::GIF, Group);
//导出动图到磁盘
}
—————————————————————————————————————————————————————
10.图层
// D2DLayerExample.cpp
#include<windows.h>
#include<thread>
#include"D2DEngine1_0.h"
using namespace std;
using namespace D2D1;
D2DEngine* Engine = new D2DEngine; // 创建 D2DEngine对象
D2DBitmapGroup BitmapGroup; // 创建图组,用于动图
D2DBitmapGroup Group; // 图组2
D2DBitmap GIF(L"鸡你太美.gif"); // 创建 Picture类对象,并用图片路径初始化,这里填 GIF(动图路径)
void Draw()
{
D2DLayer Layer; //创建图层
Engine->TransformPictureIntoBitmap(GIF, BitmapGroup);
// 图片转换,经过这一步才能正确加载 D2D位图
// 使用了 TransformPictureIntoBitmap 的重载函数
size_t framecount = BitmapGroup.BitmapGroup.size(); //获取动图总帧数
size_t tloop = 0; // 循环次数
size_t i = 0; // 循环形参,表示第i帧图片
// 循环1次
while (tloop < 1)
{
Engine->BeginDraw(); // 开始绘制
Engine->PushLayer(Layer, D2DEngineSpace::D2D_Clip(80, 70, 120, 120));
// 添加图层,裁取绘制区域,绘制区域外的图像将被覆盖
Engine->DrawBitmap(BitmapGroup.BitmapGroup[i], 0, 0, 320, 320); // 绘制第 i帧图片
Engine->PopLayer();
Engine->EndDraw(); // 结束绘制
Sleep(80); //使程序停止80毫秒,这样能产生视觉效应
Group.BitmapGroup.push_back(Engine->RenderTargetShot()); //截图
if (i == framecount - 1) //如果播放到最后一帧
{
tloop++; //循环次数加一
i = 0; //重置形参, 从第一帧开始绘制
}
i++; //帧数加一
}
Engine->PackD2DBitmapAsImageFile(L"", L"", Picture_Format::GIF, Group); //打包动图
}
LRESULT CALLBACK CallBackFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hin, HINSTANCE, LPSTR, int CmdShow)
{
MSG msg = {};
WNDCLASSEX wcex = {};
memset(&wcex, 0, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = CallBackFunc;
wcex.lpszClassName = L"D2D";
wcex.hInstance = hin;
wcex.style = CS_GLOBALCLASS;
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
RegisterClassEx(&wcex);
HWND hwnd = CreateWindowW(wcex.lpszClassName, L"D2D",
WS_OVERLAPPED | WS_SYSMENU,
300, 0, 320, 320,
nullptr,
nullptr,
hin,
nullptr
);
ShowWindow(hwnd, CmdShow);
Engine->Initialize(hwnd); // 初始化 D2DEngine设备
thread thread_1(Draw); // 开启线程
thread_1.detach(); //释放线程,令线程不阻断消息循环
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
—————————————————————————————————————————————————————
D2DEngine全函数解析
—————————————————————————————————————————————————————
D2DEngine
表层设备类
D2DEngine::Initialize
初始化D2DEngine设备 (同时创建普通画刷)
bool Initialize(
const HWND hwnd,
const D2D1::ColorF BrushColor = D2D1::ColorF::White,
RECT Draw_Region = {}
);
hwnd 窗口句柄
BrushColor 要初始化的普通画刷颜色,默认白色
Draw_Region 绘制区域(相对于第一参数),默认整个窗口
任何有关D2DEngine的操作都必须放在此函数后面,否则设备初始化失败!
D2DEngine::ChangeRenderTarget
改变渲染目标(慎用)
bool ChangeRenderTarget(
HWND hwnd,
RECT DrawRegion,
D2D1_RENDER_TARGET_PROPERTIES Properties = D2D1::RenderTargetProperties()
);
hwnd 窗口句柄
DrawRegion 绘制区域(相对于第一参数)
Properties 高级选项,默认D2D1_RENDER_RAEGET_TYPE_DEFAULT
慎用此函数,此函数可能使部分WIC类函数失效并报错!
D2DEngine::ChangeRenderSize
改变渲染区域
bool ChangeRenderSize(LPARAM lParam);
lParam 附加消息
常常用于窗口改变大小时的处理:WM_SIZE
bool ChangeRenderSize(T width, T height);
width 要改变的宽度
height 要改变的长度
D2DEngine::ChangeBrushColor
改变普通画刷颜色
void ChangeBrushColor(const D2D1::ColorF Color);
color 颜色
Initialize函数会自动创建普通画刷!
D2DEngine::ChangeLinearBrushColor
改变线性渐变画刷颜色
bool ChangeLinearGradientBrushColor(
std::vector<D2D1::ColorF> ColorGroup,
std::vector<float> GradientRatio,
D2D1_POINT_2F Begin,
D2D1_POINT_2F End
);
ColorGroup 颜色组
GradientRatio 渐变比例
Begin 渐变轴起点
End 渐变轴终点
注意:
1.各画刷设备互不共用,互不影响
2.第一参数和第二参数的个数必须相同,否则会返回false
3.渐变轴起点和终点可以确定渐变方向
4.第一次调用该函数将视为创建!
D2DEngine::ChangeRadialBrushColor
改变径向渐变画刷颜色
bool ChangeRadialGradientBrushColor(
std::vector<D2D1::ColorF> ColorGroup,
std::vector<float> GradientRatio,
D2D1_POINT_2F Center,
D2D1_POINT_2F OriginOffect,
float RadiusX,
float RadiusY
);
ColorGroup 颜色组
GradientRatio 渐变比例
Center 渐变中心(起点)
OriginOffset 渐变中心偏移量
RadiusX 渐变X半长轴
RadiusY 渐变Y半长轴
注意:
1.各画刷设备互不共用,互不影响
2.第一参数和第二参数的个数必须相同,否则会返回false
3.渐变起点和终点可以确定渐变方向
4.第一次调用该函数将视为创建!
D2DEngine::ChangeStrokeStyle
改变线条风格
bool ChangeStrokeStyle(
const D2D1_STROKE_STYLE_PROPERTIES Strokestyle,
std::initializer_list<float> dashes
);
Strokestyle 线条风格
dashes 线条间隔组
注意:
1.第一次调用该函数将视为创建!
2.当且仅当绘制线段或图形边廓时才生效
D2DEngine::ChangeTextFormat
改变文本样式
bool ChangeTextFormat(
float FontSize,
D2D1::ColorF TextColor,
WCHAR* FontFamilyName = L"新宋体"
);
FontSize 字体大小
TextColor 字体颜色
FontFamilyName 字体簇,默认"新宋体"
注意:
1.如果字体簇找不到会使用系统默认字体 (不会发生COM错误)
2.使用ChangeBrushColor函数也可以改变字体颜色
D2DEngine::CreateLayer
创建图层
bool CreateLayer(D2DLayer& Layer);
Layer 要创建的图层对象
D2DEngine::CreateRectangle
创建矩形
bool CreateRectangle(D2DRectangle& Rectangle);
Rectangle 要创建的矩形类
D2DEngine::CreateRoundedRectangle
创建圆角矩形
bool CreateRoundedRectangle(D2DRoundedRectangle& RoundedRectangle);
RoundedRectangle 要创建的圆角矩形类
D2DEngine::CreateEllipse
创建椭圆
bool CreateEllipse(D2DEllipse& Ellipse);
Ellipse 要创建的椭圆类
D2DEngine::OpenGeometryDevice
启动自定义图形绘制设备
bool OpenGeometryDevice(
D2DCustomGeometry& Geometry,
bool IsAlternate = false
);
Geometry 要创建的自定义图形
IsAlternate 是否交替填充,默认为否
注意:
启动设备会把传入的Geometry重置
D2DEngine::AddLineGeometry
添加由直线组成的多边形
void AddLineGeometry(
std::vector<D2D1_POINT_2F> Points,
bool Fillmode = false,
bool Openmode = false
);
Points 顶点数组
Fillmode 填充模式,默认无填充
Openmode 设置为封闭图形,默认为是
D2DEngine::AddArcGeometry
添加圆弧
void AddArcGeometry(
D2D1_POINT_2F BeginPoint,
D2D1_POINT_2F EndPoint,
D2D1_SIZE_F XYRadius,
float RotationAngle,
bool Fillmode = false,
bool Openmode = false,
D2D1_SWEEP_DIRECTION SweepDirection = D2D1_SWEEP_DIRECTION_CLOCKWISE,
D2D1_ARC_SIZE ArcSize = D2D1_ARC_SIZE_SMALL
);
BeginPoint 起点
EndPoint 终点
XYRadius XY半长轴
RotationAngle 旋转角度
Fillmode 填充模式,默认无填充
Openmode 设置为封闭图形,默认为是
SweepDirection 扫描方向,默认顺时针
ArcSize 绘制超过180°的圆弧,默认为否
D2DEngine::AddBezierGeometry
添加贝塞尔曲线
void AddBezierGeometry(
D2D1_POINT_2F Points[4],
bool Fillmode = false,
bool Openmode = false
);
Points 顶点数组
Fillmode 填充模式,默认无填充
Openmode 设置为封闭图形,默认为是
顶点数组需要4个顶点: 起点,两个控制点,终点
D2DEngine::AddBezierGeometries
批量添加贝塞尔曲线
void AddBezierGeometries(
D2D1_POINT_2F BeginPoint,
std::initializer_list<D2D1_BEZIER_SEGMENT> Points,
bool Fillmode = false,
bool Openmode = false
);
BeginPoint 起始点
Points 顶点数组
Fillmode 填充模式,默认无填充
Openmode 设置为封闭图形,默认为是
每个顶点数组由3点组成:两个控制点,终点
D2DEngine::AddQuadraticBezierGeometry
添加二次贝塞尔曲线
void AddQuadraticBezierGeometry(
D2D1_POINT_2F Points[3],
bool Fillmode = false,
bool Openmode = false
);
顶点数组需要3个顶点:起点,控制点,终点
D2DEngine::AddQuadraticBezierGeometries
批量添加二次贝塞尔曲线
void AddQuadraticBezierGeometries(
D2D1_POINT_2F BeginPoint,
std::initializer_list<D2D1_QUADRATIC_BEZIER_SEGMENT> Points,
bool Fillmode = false,
bool Openmode = false
);
BeginPoint 起始点
Points 顶点数组
Fillmode 填充模式,默认无填充
Openmode 设置为封闭图形,默认为是
每个顶点数组由2点组成: 控制点,终点
D2DEngine::AddCombineGeometry
添加合并图形
bool AddCombineGeometry(
ID2D1Geometry* OperatingGeometry,
ID2D1Geometry* InputGeometry,
D2D1_COMBINE_MODE Combinemode,
D2D1_MATRIX_3X2_F TransformedMatrix = D2D1::Matrix3x2F::Identity()
);
OperatingGeometry 要操作的图形A
InputGeometry 输入图形B
Combinemode 合并模式
TransformedMatrix 变换矩阵,默认单位矩阵
注意:
1.合并的图形将传入至D2DCustomGeometry(OpenGeometryDevice)中,发生COM错误时返回false
2.图形A和图形B必须先调用相应的Create函数创建好,否则会发生错误!
D2DEngine::CloseGeometryDevice
关闭自定义图形绘制设备,并同时创建自定义图形
bool CloseGeometryDevice(D2DCustomGeometry& Geometry);
Geometry 在OpenGeometryDevice中传入的D2DCustomGeometry
OpenGeometryDevice(Geometry);
Add_ ... // 在这里添加图形
CloseGeometryDevice(Geometry);
D2DEngine::SetTransform
将渲染目标进行转换
void SetTransform(D2D1_MATRIX_3X2_F Matrix);
Matrix 转换矩阵
注意转换后渲染目标上的图形边廓会变粗
—————————————————————————————————————————————————————
渲染类
D2DEngine::BeginDraw
开始渲染,将后缓冲区切换至渲染状态
void BeginDraw();
D2DEngine::EndDraw
结束渲染,后缓冲区切换至呈现状态,前后缓冲区进行交换
bool EndDraw();
D2DEngine::Clear
清理渲染目标并填充背景色
void Clear(const D2D1::ColorF ClearColor = D2D1::ColorF::White);
ClearColor 要填充的背景色,默认白色
D2DEngine::PushLayer
添加一层图层
void PushLayer(
D2DLayer Layer,
D2D1_LAYER_PARAMETERS LayerParameters = D2D1::LayerParameters());
Layer 已创建的图层
LayerParameters 指定图层属性,默认系统赋值
注意:
1.图层可嵌套
2.此函数必须放在BeginDraw函数之后才能执行
D2DEngine::PopLayer
弹出一层图层
void PopLayer();
Engine->BeginDraw();
Engine->PushLayer(Layer);
todo... //在这里进行代码渲染
Engine->PopLayer();
Engine->EndDraw();
D2DEngine::DrawBitmap
绘制单帧位图
void DrawBitmap(
D2DBitmap Bitmap,
float x,
float y,
float width,
float height
);
Bitmap 位图
x X坐标
y Y坐标
width 宽
height 高
void DrawBitmap(
D2DBitmap Bitmap,
D2D_RECT_F ClipRegion,
D2D_RECT_F DrawRegion,
float Alpha = 1.0f
);
Bitmap 原位图
ClipRegion 原位图裁剪范围
DrawRegion 原位图绘制到目标的范围
Alpha 透明度,默认不透明
D2DEngine::Drawtext
绘制单色文本
void Drawtext(
WCHAR* text,
float x,
float y,
float width,
float height
);
text 绘制文本
x X坐标
y Y坐标
width 绘制区域的宽
height 绘制区域的高
D2DEngine::DrawLine
绘制直线
void DrawLine(
float BeginX,
float BeginY,
float EndX,
float EndY,
float StrokeWidth,
D2D_Brush_Type BrushType
);
BeginX 起点的X坐标
BeginY 起点的Y坐标
EndX 终点的X坐标
EndY 终点的Y坐标
StrokeWidth 线条宽度
BrushType 画刷类型
D2DEngine::DrawRectangle
绘制矩形轮廓
void DrawRectangle(
D2DRectangle Rectangle,
float StrokeWidth,
D2D_Brush_Type BrushType
);
Rectangle 已创建的矩形类
StrokeWidth 轮廓宽度
BrushType 画刷类型
D2DEngine::FillRectangle
填充矩形
void FillRectangle(
D2DRectangle Rectangle,
D2D_Brush_Type BrushType
);
Rectangle 已创建的矩形类
BrushType 画刷类型
D2DEngine::DrawRoundedRectangle
绘制圆角矩形轮廓
void DrawRoundedRectangle(
D2DRoundedRectangle RoundedRectangle,
float StrokeWidth,
D2D_Brush_Type BrushType
);
RoundedRectangle 已创建的圆角矩形类
StrokeWidth 轮廓宽度
BrushType 画刷类型
D2DEngine::FillRoundedRectangle
填充圆角矩形
void FillRoundedRectangle(
D2DRoundedRectangle RoundedRectangle,
D2D_Brush_Type BrushType
);
RoundedRectangle 已创建的圆角矩形类
BrushType 画刷类型
D2DEngine::DrawEllipse
绘制椭圆轮廓
void DrawEllipse(
D2DEllipse Ellipse,
float StrokeWidth,
D2D_Brush_Type BrushType
);
Ellipse 已创建的椭圆类
StrokeWidth 轮廓宽度
BrushType 画刷类型
D2DEngine::FillEllipse
填充椭圆
void FillEllipse(
D2DEllipse Ellipse,
D2D_Brush_Type BrushType
);
Ellipse 已创建的椭圆类
BrushType 画刷类型
D2DEngine::DrawCustomGeometry
绘制自定义图形轮廓
void DrawCustomGeometry(
D2DCustomGeometry CustomGeometry,
float StrokeWidth,
D2D_Brush_Type BrushType
);
CustomGeometry 已创建的自定义图形类
StrokeWidth 轮廓宽度
BrushType 画刷类型
D2DEngine::FillCustomGeometry
填充自定义图形
void FillCustomGeometry(
D2DCustomGeometry CustomGeometry,
D2D_Brush_Type BrushType
);
CustomGeometry 已创建的自定义图形类
BrushType 画刷类型
—————————————————————————————————————————————————————
WIC类
windows 图片组件 (windows image component,WIC),功能极其强大,提供了图片转换所需的解码器和编码器接口,是D2DEngine位图操作的核心
D2DEngine::RenderTargetShot
截取渲染目标的图像并输出为D2D位图
D2DBitmap RenderTargetShot();
D2DEngine::GetPictureFrame
获取图片帧数
UINT GetPictureFrame(D2DBitmap& Bitmap);
D2DBitmap 要解析的图片
D2DEngine::TransformPictureIntoBitmap
转换图片
bool TransformPictureIntoBitmap(D2DBitmap& Bitmap);
Bitmap 要解析的位图
bool TransformPictureIntoBitmap(
D2DBitmap& Bitmap,
D2DBitmapGroup& BitmapGroup
);
Bitmap 要解析的位图
BitmapGroup 要输出的图组
D2DEngine::PackRenderTargetAsImageFile
打包渲染目标上的图像,变成位图文件
bool PackRenderTargetAsImageFile(
WCHAR* Pathname,
WCHAR* Filename,
Picture_Format TransformFormat
);
Pathname 路径名
Filename 文件名
TransformFormat 将转换的格式(拓展名)
注意:
1.路径名为空会默认在可执行文件所在磁盘创建文件
2.路径名不存在不会创建文件,并返回false
3.文件名可为空
D2DEngine::PackD2DBitmapAsImageFile
打包静态(动态)D2D位图成图像文件
bool PackD2DBitmapAsImageFile(
WCHAR* Pathname,
WCHAR* Filename,
Picture_Format TransformFormat,
D2DBitmap Bitmap
);
Pathname 路径名
Filename 文件名
TransformFormat 将转换的格式(拓展名)
Bitmap 要传入的D2D位图
bool PackD2DBitmapAsImageFile(
WCHAR* Pathname,
WCHAR* Filename,
Picture_Format TransformFormat,
D2DBitmapGroup BitmapGroup
);
Pathname 路径名
Filename 文件名
TransformFormat 将转换的格式(拓展名)
BitmapGroup 要传入的位图组
—————————————————————————————————————————————————————
D2DBitmap
D2DBitmap::GetBitmapFileName
获取D2DBitmap类内部存储的图片路径
WCHAR* GetBitmapFileName();
D2DBitmap::ChangeFileName
改变D2DBitmap类存储的图片文件路径
bool ChangeFileName(WCHAR* Filename);
Filename 文件路径名
D2DBitmap::CheckFileIfExist
检测某路径是否存在
bool CheckFileIfExist(WCHAR* Filename);
Filename 文件路径名
D2DBitmap::CheckFileSelfIfExist
检测位图自身路径是否存在
bool CheckFileSelfIfExist();
—————————————————————————————————————————————————————
D2D图形类
基类成员函数
注意:
1.基类成员函数在派生类除Clear方法被重写外,其余一致相同
2.图形类分为原图形和变换图形,若类内存储的变换矩阵容器存在元素,将默认创建并使用变换图形!
D2DBasicGeometry::GetReadOnlyTransformedMatrixes
以只读方式返回对象里的变换矩阵容器
std::vector<D2D1_MATRIX_3X2_F> GetReadOnlyTransformedMatrixes();
D2DBasicGeometry::GetReferencedTransformedMatrixes
以引用方式返回对象里的变换矩阵容器
std::vector<D2D1_MATRIX_3X2_F>& GetReferencedTransformedMatrixes();
D2DBasicGeometry::Clear
重置图形
virtual void Clear();
Clear方法均被其派生类重写
D2DBasicGeometry::ClearTransform
清除变换,清除变换后将不会使用转换后的图形
void ClearTransform();
D2DBasicGeometry::GetSize
返回变换矩阵容器的大小
size_t GetSize();
D2DBasicGeometry::Empty
检测矩阵是否为空,若容器为空,返回true
bool Empty();
D2DBasicGeometry::Identity
返回单位矩阵(任意3x2矩阵乘它都等于其本身)
D2D1_MATRIX_3X2_F Identity();
D2DBasicGeometry::Scale
返回缩放转换
D2D1_MATRIX_3X2_F Scale(
float ScaleX,
float ScaleY,
float width,
float height
);
ScaleX 缩放点X轴坐标
ScaleY 缩放点Y轴坐标
width X轴缩放长度
height Y轴缩放长度
D2DBasicGeometry::Translation
返回平移转换
D2D1_MATRIX_3X2_F Translation(
float MoveX,
float MoveY
);
MoveX X轴平移距离
MoveY Y轴平移距离
D2DBasicGeometry::Rotation
返回旋转转换
D2D1_MATRIX_3X2_F Rotation(
float x,
float y,
float angle
);
x 旋转点X轴坐标
y 旋转点Y轴坐标
angle 旋转角度
D2DBasicGeometry::Skew
返回倾斜转换
D2D1_MATRIX_3X2_F Skew(
float x,
float y,
float angleX,
float angleY
);
x 倾斜点X轴坐标
y 倾斜点Y轴坐标
angleX X轴倾斜角度
angleY Y轴倾斜角度
D2DBasicGeometry::AddScale
在变换矩阵容器尾部添加缩放转换
void AddScale(
float ScaleX,
float ScaleY,
float width,
float height
);
ScaleX 缩放点X轴坐标
ScaleY 缩放点Y轴坐标
width X轴缩放长度
height Y轴缩放长度
D2DBasicGeometry::AddTranslation
在变换矩阵容器尾部添加平移转换
void AddTranslation(
float MoveX,
float MoveY
);
MoveX X轴平移距离
MoveY Y轴平移距离
D2DBasicGeometry::AddRotation
在变换矩阵容器尾部添加旋转转换
void AddRotation(
float x,
float y,
float angle
);
x 旋转点X轴坐标
y 旋转点Y轴坐标
angle 旋转角度
D2DBasicGeometry::AddSkew
在变换矩阵容器尾部添加倾斜转换
void AddSkew(
float x,
float y,
float angleX,
float angleY
);
x 倾斜点X轴坐标
y 倾斜点Y轴坐标
angleX X轴倾斜角度
angleY Y轴倾斜角度
D2DBasicGeometry::append
在变换矩阵容器尾部批量添加变换矩阵
void append(std::initializer_list<D2D1_MATRIX_3X2_F> Matrixies);
Matrixies 矩阵组
D2DBasicGeometry::remove
清除指定索引(区间)的转换矩阵
bool remove(UINT Index);
Index 索引
bool remove(
UINT BeginIndex,
UINT EndIndex
);
BeginIndex 起始索引
EndIndex 终止索引
注意:如果索引不存在,或者 EndIndex-BeginIndex < 0,都会返回false
D2DBasicGeometry::insert
在指定索引(批量)插入变换矩阵
bool insert(
UINT Index,
D2D1_MATRIX_3X2_F Matrix
);
Index 索引
Matrix 变换矩阵
bool insert(
UINT Index,
std::initializer_list<D2D1_MATRIX_3X2_F> Matrixies
);
Index 索引
Matrixies 变换矩阵组
—————————————————————————————————————————————————————
D2DEngineSpace
D2DEngineSpace::D2D_Clip
用于图层,限定绘制区域,此区域外的绘制操作将会被覆盖
D2D1_LAYER_PARAMETERS D2D_Clip(
float x,
float y,
float width,
float height
);
x 相对渲染目标的X坐标
y 相对渲染目标的Y坐标
width 宽
height 高