GraceFt v2.3
开源图形引擎 EGE(Easy Graphics Engine) 的高层封装库
 
载入中...
搜索中...
未找到
GFt::Graphics类 参考

绘图接口类 更多...

#include <Graphics.h>

Public 成员函数

 Graphics ()
 默认构造函数
 
 Graphics (Graphics &&other)
 
 ~Graphics ()
 
void bindBrushSet (BrushSet *brushSet)
 绑定画刷设置
 
void bindPenSet (PenSet *penSet)
 绑定画笔设置
 
void bindTextSet (TextSet *textSet)
 绑定文本设置
 
void clear ()
 使用背景色重绘绘图目标
 
void drawAlphaImage (const PixelMap &pixelMap, const fPoint &dest, const fRect &src)
 以带有透明通道的形式绘制位图
 
void drawAlphaImage (const PixelMap &pixelMap, const fRect &dest, const fRect &src, bool smooth=false)
 以带有透明通道的形式绘制位图
 
void drawArc (const fRect &rect, float startAngle, float sweepAngle)
 绘制椭圆弧
 
void drawBezier (const fBezier &curve)
 绘制贝塞尔曲线
 
void drawCircle (const fCircle &circle)
 绘制圆
 
void drawEllipse (const fEllipse &ellipse)
 绘制椭圆
 
void drawFillCircle (const fCircle &circle)
 填充圆
 
void drawFillEllipse (const fEllipse &rect)
 填充椭圆
 
void drawFillFitCurve (const fFitCurve &curve)
 填充闭合拟合曲线
 
void drawFillPath (const Path &path, const fPoint &pos=fPoint())
 填充闭合路径
 
void drawFillPie (const fRect &rect, float startAngle, float sweepAngle)
 填充扇形
 
void drawFillPolygon (const fPolygon &polygon)
 填充多边形
 
void drawFillRect (const fRect &rect)
 填充矩形
 
void drawFillRoundRect (const fRoundRect &rect)
 填充圆角矩形
 
void drawFitCurve (const fFitCurve &curve)
 绘制拟合曲线
 
void drawImage (const fPoint &pos, const PixelMap &pixelMap)
 绘制位图
 
void drawImage (const fRect &dest, const fRect &src, const PixelMap &pixelMap)
 绘制位图
 
void drawLine (const fLine &line)
 绘制线段
 
void drawPath (const Path &path, const fPoint &pos=fPoint())
 绘制路径
 
void drawPie (const fRect &rect, float startAngle, float sweepAngle)
 绘制扇形线框
 
void drawPolygon (const fPolygon &polygon)
 绘制多边形
 
void drawRect (const fRect &rect)
 绘制矩形
 
void drawRoundRect (const fRoundRect &rect)
 绘制圆角矩形
 
int drawText (const std::wstring &text, const fPoint &pos, const std::vector< std::wstring > &fonts={}, bool show=true)
 在指定位置绘制文本
 
int drawText (const std::wstring &text, const fRect &rect, int flags=TextAlign::Left|TextAlign::Top, const std::vector< std::wstring > &fonts={})
 在指定矩形区域内绘制文本
 
PixelMapgetTarget () const
 获取绘图目标
 
fMat3x3 getTransform () const
 获取当前应用的变换矩阵
 
Graphicsoperator= (Graphics &&other)
 
void reset ()
 重置所有设置
 
void resetTransform ()
 重置变换矩阵
 
void setAntiAliasing (bool enable)
 设置抗锯齿
 
void setBackgroundColor (const Color &color)
 设置默认背景色
 
void setTarget (PixelMap *target)
 设置绘图目标
 
void setTransform (const fMat3x3 &matrix)
 应用变换矩阵
 
int textHeight (const std::wstring &text, const std::vector< std::wstring > &fonts={})
 获取指定文本在指定回滚字体集合中的高度
 
int textHeight (wchar_t c, const std::vector< std::wstring > &fonts={})
 获取指定字符在指定回滚字体集合中的高度
 
int textWidth (const std::wstring &text, const std::vector< std::wstring > &fonts={})
 获取指定文本在指定回滚字体集合中的宽度
 
int textWidth (wchar_t c, const std::vector< std::wstring > &fonts={})
 获取指定字符在指定回滚字体集合中的宽度
 

详细描述

绘图接口类

该类提供了绘图相关的接口,包括绘制线段、矩形、圆形、椭圆、圆弧、多边形、贝塞尔曲线、拟合曲线、路径、图像、文本等

构造及析构函数说明

◆ Graphics() [1/2]

GFt::Graphics::Graphics ( )

默认构造函数

◆ Graphics() [2/2]

GFt::Graphics::Graphics ( Graphics && other)

◆ ~Graphics()

GFt::Graphics::~Graphics ( )

成员函数说明

◆ bindBrushSet()

void GFt::Graphics::bindBrushSet ( BrushSet * brushSet)

绑定画刷设置

参数
brushSet画刷设置

◆ bindPenSet()

void GFt::Graphics::bindPenSet ( PenSet * penSet)

绑定画笔设置

参数
penSet画笔设置

◆ bindTextSet()

void GFt::Graphics::bindTextSet ( TextSet * textSet)

绑定文本设置

参数
textSet文本设置

◆ clear()

void GFt::Graphics::clear ( )

使用背景色重绘绘图目标

◆ drawAlphaImage() [1/2]

void GFt::Graphics::drawAlphaImage ( const PixelMap & pixelMap,
const fPoint & dest,
const fRect & src )

以带有透明通道的形式绘制位图

参数
pixelMap要绘制的位图
dest要绘制的目标位置
src要绘制的源区域

◆ drawAlphaImage() [2/2]

void GFt::Graphics::drawAlphaImage ( const PixelMap & pixelMap,
const fRect & dest,
const fRect & src,
bool smooth = false )

以带有透明通道的形式绘制位图

若源区域与目标区域的大小不一致,则会执行拉伸操作

参数
pixelMap要绘制的位图
dest要绘制的目标区域
src要绘制的源区域
smooth是否启用平滑处理

◆ drawArc()

void GFt::Graphics::drawArc ( const fRect & rect,
float startAngle,
float sweepAngle )

绘制椭圆弧

参数
rect椭圆弧所在椭圆的外接矩形
startAngle起始角度
sweepAngle扫过角度

◆ drawBezier()

void GFt::Graphics::drawBezier ( const fBezier & curve)

绘制贝塞尔曲线

参数
curve贝塞尔曲线

◆ drawCircle()

void GFt::Graphics::drawCircle ( const fCircle & circle)

绘制圆

参数
circle

◆ drawEllipse()

void GFt::Graphics::drawEllipse ( const fEllipse & ellipse)

绘制椭圆

参数
ellipse椭圆

◆ drawFillCircle()

void GFt::Graphics::drawFillCircle ( const fCircle & circle)

填充圆

参数
circle

◆ drawFillEllipse()

void GFt::Graphics::drawFillEllipse ( const fEllipse & rect)

填充椭圆

参数
rect椭圆

◆ drawFillFitCurve()

void GFt::Graphics::drawFillFitCurve ( const fFitCurve & curve)

填充闭合拟合曲线

参数
curve拟合曲线

如果传入的曲线不是闭合的, 则此函数无效果

◆ drawFillPath()

void GFt::Graphics::drawFillPath ( const Path & path,
const fPoint & pos = fPoint() )

填充闭合路径

参数
path路径

◆ drawFillPie()

void GFt::Graphics::drawFillPie ( const fRect & rect,
float startAngle,
float sweepAngle )

填充扇形

参数
rect扇形所在椭圆的外接矩形
startAngle起始角度
sweepAngle扫过角度

◆ drawFillPolygon()

void GFt::Graphics::drawFillPolygon ( const fPolygon & polygon)

填充多边形

参数
points多边形顶点坐标列表

如果传入的多边形不是闭合的, 则此函数无效果

◆ drawFillRect()

void GFt::Graphics::drawFillRect ( const fRect & rect)

填充矩形

参数
rect矩形

◆ drawFillRoundRect()

void GFt::Graphics::drawFillRoundRect ( const fRoundRect & rect)

填充圆角矩形

参数
rect圆角矩形

◆ drawFitCurve()

void GFt::Graphics::drawFitCurve ( const fFitCurve & curve)

绘制拟合曲线

参数
curve拟合曲线

◆ drawImage() [1/2]

void GFt::Graphics::drawImage ( const fPoint & pos,
const PixelMap & pixelMap )

绘制位图

参数
pos要绘制的位置
pixelMap要绘制的位图

◆ drawImage() [2/2]

void GFt::Graphics::drawImage ( const fRect & dest,
const fRect & src,
const PixelMap & pixelMap )

绘制位图

若源区域与目标区域的大小不一致,则会执行拉伸操作

参数
dest要绘制的目标区域
src要绘制的区域
pixelMap要绘制的位图

◆ drawLine()

void GFt::Graphics::drawLine ( const fLine & line)

绘制线段

参数
line线段

◆ drawPath()

void GFt::Graphics::drawPath ( const Path & path,
const fPoint & pos = fPoint() )

绘制路径

参数
path路径
pos路径起点坐标

◆ drawPie()

void GFt::Graphics::drawPie ( const fRect & rect,
float startAngle,
float sweepAngle )

绘制扇形线框

参数
rect扇形所在椭圆的外接矩形
startAngle起始角度
sweepAngle扫过角度

◆ drawPolygon()

void GFt::Graphics::drawPolygon ( const fPolygon & polygon)

绘制多边形

参数
polygon多边形

◆ drawRect()

void GFt::Graphics::drawRect ( const fRect & rect)

绘制矩形

参数
rect矩形

◆ drawRoundRect()

void GFt::Graphics::drawRoundRect ( const fRoundRect & rect)

绘制圆角矩形

参数
rect圆角矩形

◆ drawText() [1/2]

int GFt::Graphics::drawText ( const std::wstring & text,
const fPoint & pos,
const std::vector< std::wstring > & fonts = {},
bool show = true )

在指定位置绘制文本

参数
text要绘制的文本
pos要绘制的位置
fonts指定的回滚字体集合
show是否显示文本, 若为false则只计算文本的宽度
返回
实际绘制出的字符的像素宽度
注解
若未指定字体集合则使用环境当前绑定的字体 若指定了字体集合,则会按照字体列表的顺序依次查找, 直到找到一个能显示的字体(即字体回滚机制),此操作将忽略环境当前绑定的字体

◆ drawText() [2/2]

int GFt::Graphics::drawText ( const std::wstring & text,
const fRect & rect,
int flags = TextAlign::Left | TextAlign::Top,
const std::vector< std::wstring > & fonts = {} )

在指定矩形区域内绘制文本

参数
text要绘制的文本
rect要绘制的矩形区域
flags文本对齐方式
font指定的字体集合
返回
实际绘制出的字符的像素宽度
注解
若未指定字体集合则使用环境当前绑定的字体

若传入了无效的 flags, 则此函数将会忽略它们, 并使用默认的对齐方式(左上对齐)

◆ getTarget()

PixelMap * GFt::Graphics::getTarget ( ) const

获取绘图目标

返回
绘图目标

◆ getTransform()

fMat3x3 GFt::Graphics::getTransform ( ) const

获取当前应用的变换矩阵

返回
变换矩阵

◆ operator=()

Graphics & GFt::Graphics::operator= ( Graphics && other)

◆ reset()

void GFt::Graphics::reset ( )

重置所有设置

◆ resetTransform()

void GFt::Graphics::resetTransform ( )

重置变换矩阵

◆ setAntiAliasing()

void GFt::Graphics::setAntiAliasing ( bool enable)

设置抗锯齿

参数
enable是否启用抗锯齿

◆ setBackgroundColor()

void GFt::Graphics::setBackgroundColor ( const Color & color)

设置默认背景色

参数
color背景色

◆ setTarget()

void GFt::Graphics::setTarget ( PixelMap * target)

设置绘图目标

参数
target绘图目标,如果为nullptr,则绘图目标为屏幕
注解
若设置目标不为 nullptr, 则应保证后续调用此类的其它成员函数时, 目标对象未被析构
否则会引发段错误(指针越界访问)

◆ setTransform()

void GFt::Graphics::setTransform ( const fMat3x3 & matrix)

应用变换矩阵

参数
matrix变换矩阵

对于传入的矩阵, 默认其已经过齐次变换, 即矩阵的最后一列为 (0, 0, 1)

// 例如:将当前坐标系绕点 (100, 100) 逆时针旋转 45 度
// 然后将变换后的坐标原点平移至 (100, 100)
// 最后再以变换后的 (200, 200) 为中心进行缩放到原先的 2 倍
g.setTransform(
rotate(makeVec2(100, 100), radians(45)) *
translate(makeVec2(100, 100)) *
scale(makeVec2(200, 200), makeVec2(2, 2));
constexpr Matrix< M+1, M+1, T > translate(const Vec< M, T > &v)
创建平移坐标变换矩阵
定义 LMath.hpp:172
constexpr Matrix< M+1, M+1, T > scale(const Vec< M, T > &pos, const Vec< M, T > &s)
创建缩放坐标变换矩阵
定义 LMath.hpp:187
constexpr double radians(T deg)
将角度制转为弧度制
定义 LMath.hpp:244
constexpr Matrix< 3, 3, T > rotate(const Vec< 2, T > &axis, float rad)
创建二维坐标系下的旋转坐标变换矩阵
定义 LMath.hpp:200

◆ textHeight() [1/2]

int GFt::Graphics::textHeight ( const std::wstring & text,
const std::vector< std::wstring > & fonts = {} )

获取指定文本在指定回滚字体集合中的高度

参数
text要获取高度的文本
fonts回滚字体集合, 若未指定则使用当前的环境设置
返回
文本的像素高度

◆ textHeight() [2/2]

int GFt::Graphics::textHeight ( wchar_t c,
const std::vector< std::wstring > & fonts = {} )

获取指定字符在指定回滚字体集合中的高度

参数
c要获取高度的字符
fonts回滚字体集合, 若未指定则使用当前的环境设置
返回
字符的像素高度

◆ textWidth() [1/2]

int GFt::Graphics::textWidth ( const std::wstring & text,
const std::vector< std::wstring > & fonts = {} )

获取指定文本在指定回滚字体集合中的宽度

参数
text要获取宽度的文本
fonts回滚字体集合, 若未指定则使用当前的环境设置
返回
文本的像素宽度

◆ textWidth() [2/2]

int GFt::Graphics::textWidth ( wchar_t c,
const std::vector< std::wstring > & fonts = {} )

获取指定字符在指定回滚字体集合中的宽度

参数
c要获取宽度的字符
fonts回滚字体集合, 若未指定则使用当前的环境设置
返回
字符的像素宽度