📄 asl_bitmap.cpp
字号:
void ASLBitmap::DrawAlphaChannel(ASLBitmap &bmDest, int xDest, int yDest,
const RECT &rcSrc) const
{
ASSERT(m_hBitmap != NULL);
ASSERT(m_pAlpha != NULL);
ASSERT(bmDest.GetHandle() != NULL);
// 对绘图位置进行调整
xDest -= m_ptHot.x;
yDest -= m_ptHot.y;
RECT rect = rcSrc;
if (EqualRect(&rect, &DEFAULTRECT))
{
rect = m_rcClip;
}
if (!_AdjustDrawPos(bmDest, xDest, yDest, rect))
{
return;
}
const int nWidth = rect.right - rect.left;
const int nHeight = rect.bottom - rect.top;
if (nWidth <= 0 || nHeight <= 0)
{
return;
}
BYTE *psrc = (BYTE*)m_pData + m_nPitch * rect.top + rect.left * 2;
BYTE *palpha = m_pAlpha + m_nWidth * rect.top + rect.left;
BYTE *pdst = (BYTE*)bmDest.m_pData + bmDest.m_nPitch * yDest + xDest * 2;
for (int i = 0; i < nHeight; ++i)
{
asmAlphaChannel(psrc, pdst, palpha, nWidth);
psrc += m_nPitch;
palpha += m_nWidth;
pdst += bmDest.m_nPitch;
}
}
//-----------------------------------------------------------------------------
// 函数名: ASLBitmap::DrawAdditive()
// 功 能: 将本位图以色饱和方式绘制到目标位图上(按块号确定源绘制区)
// 参 数: [&bmDest] - 目标位图
// [xDest] - 目标x坐标
// [yDest] - 目标y坐标
// [nSeq] - 块号
// 返回值: [void] - 无
//-----------------------------------------------------------------------------
void ASLBitmap::DrawAdditive(ASLBitmap &bmDest, int xDest, int yDest,
int nSeq) const
{
DrawAdditive(bmDest, xDest, yDest, nSeq / m_nBlockX, nSeq % m_nBlockX);
}
//-----------------------------------------------------------------------------
// 函数名: ASLBitmap::DrawAdditive()
// 功 能: 将本位图以色饱和方式绘制到目标位图上(按行列号确定源绘制区)
// 参 数: [&bmDest] - 目标位图
// [xDest] - 目标x坐标
// [yDest] - 目标y坐标
// [row] - 行号
// [col] - 列号
// 返回值: [void] - 无
//-----------------------------------------------------------------------------
void ASLBitmap::DrawAdditive(ASLBitmap &bmDest, int xDest, int yDest,
int row, int col) const
{
ASSERT(row >= 0 && row < m_nBlockY && col >= 0 && col < m_nBlockX);
RECT rect;
rect.left = col * m_nBlockW;
rect.right = rect.left + m_nBlockW;
rect.top = row * m_nBlockH;
rect.bottom = rect.top + m_nBlockH;
DrawAdditive(bmDest, xDest, yDest, rect);
}
//-----------------------------------------------------------------------------
// 函数名: ASLBitmap::DrawAdditive()
// 功 能: 将本位图以色饱和方式绘制到目标位图上(用户指定源绘制区)
// 参 数: [&bmDest] - 目标位图
// [xDest] - 目标x坐标
// [yDest] - 目标y坐标
// [*rcSrc] - 源绘制区矩形, 为空时表示整张位图
// 返回值: [void] - 无
//-----------------------------------------------------------------------------
void ASLBitmap::DrawAdditive(ASLBitmap &bmDest, int xDest, int yDest,
const RECT &rcSrc) const
{
ASSERT(m_hBitmap != NULL);
ASSERT(bmDest.GetHandle() != NULL);
// 对绘图位置进行调整
xDest -= m_ptHot.x;
yDest -= m_ptHot.y;
RECT rect = rcSrc;
if (EqualRect(&rect, &DEFAULTRECT))
{
rect = m_rcClip;
}
if (!_AdjustDrawPos(bmDest, xDest, yDest, rect))
{
return;
}
const int nWidth = rect.right - rect.left;
const int nHeight = rect.bottom - rect.top;
if (nWidth <= 0 || nHeight <= 0)
{
return;
}
BYTE *psrc = (BYTE*)m_pData + m_nPitch * rect.top + rect.left * 2;
BYTE *pdst = (BYTE*)bmDest.m_pData + bmDest.m_nPitch * yDest + xDest * 2;
for (int i = 0; i < nHeight; ++i)
{
asmAdditive(psrc, pdst, nWidth);
psrc += m_nPitch;
pdst += bmDest.m_nPitch;
}
}
//-----------------------------------------------------------------------------
// 函数名: ASLBitmap::DrawStretch()
// 功 能: 将本位图以缩放方式绘制到目标位图上(按块号确定源绘制区)
// 需要Win2000以上操作系统支持
// 参 数: [&bmDest] - 目标位图
// [xDest] - 目标x坐标
// [yDest] - 目标y坐标
// [xScale] - x方向缩放比例
// [yScale] - y方向缩放比例
// [nSeq] - 块号
// 返回值: [void] - 无
//-----------------------------------------------------------------------------
void ASLBitmap::DrawStretch(ASLBitmap &bmDest, int xDest, int yDest,
double xScale, double yScale, int nSeq) const
{
DrawStretch(bmDest, xDest, yDest, xScale, yScale, nSeq / m_nBlockX, nSeq % m_nBlockX);
}
//-----------------------------------------------------------------------------
// 函数名: ASLBitmap::DrawStretch()
// 功 能: 将本位图以缩放方式绘制到目标位图上(按行列号确定源绘制区)
// 需要Win2000以上操作系统支持
// 参 数: [&bmDest] - 目标位图
// [xDest] - 目标x坐标
// [yDest] - 目标y坐标
// [xScale] - x方向缩放比例
// [yScale] - y方向缩放比例
// [row] - 行号
// [col] - 列号
// 返回值: [void] - 无
//-----------------------------------------------------------------------------
void ASLBitmap::DrawStretch(ASLBitmap &bmDest, int xDest, int yDest,
double xScale, double yScale, int row, int col) const
{
ASSERT(row >= 0 && row < m_nBlockY && col >= 0 && col < m_nBlockX);
RECT rect;
rect.left = col * m_nBlockW;
rect.right = rect.left + m_nBlockW;
rect.top = row * m_nBlockH;
rect.bottom = rect.top + m_nBlockH;
DrawStretch(bmDest, xDest, yDest, xScale, yScale, rect);
}
//-----------------------------------------------------------------------------
// 函数名: ASLBitmap::DrawStretch()
// 功 能: 将本位图以缩放方式绘制到目标位图上(用户指定源绘制区)
// 需要Win2000以上操作系统支持
// 参 数: [&bmDest] - 目标位图
// [xDest] - 目标x坐标
// [yDest] - 目标y坐标
// [xScale] - x方向缩放比例
// [yScale] - y方向缩放比例
// [*rcSrc] - 源绘制区矩形, 为空时表示整张位图
// 返回值: [void] - 无
//-----------------------------------------------------------------------------
void ASLBitmap::DrawStretch(ASLBitmap &bmDest, int xDest, int yDest, double xScale,
double yScale, const RECT &rcSrc) const
{
ASSERT(m_hBitmap != NULL);
ASSERT(bmDest.GetHandle() != NULL);
// 对绘图位置进行调整
xDest -= m_ptHot.x;
yDest -= m_ptHot.y;
RECT rect;
if (EqualRect(&rcSrc, &DEFAULTRECT))
{
rect = m_rcClip;
}
else
{
rect = rcSrc;
if (!_Clip(rect))
{
return;
}
}
int nWidth = rect.right - rect.left;
int nHeight = rect.bottom - rect.top;
if (m_nColorKey >= 0)
{
// 有颜色键处理, 直接调用GDI绘图函数
TransparentBlt(bmDest.GetDC(), xDest, yDest,
int(nWidth*xScale), int(nHeight*yScale),
m_hDC, rect.left, rect.top, nWidth, nHeight, m_nColorKey);
}
else
{
// 无颜色键处理, 直接调用GDI绘图函数
StretchBlt(bmDest.GetDC(), xDest, yDest,
int(nWidth*xScale), int(nHeight*yScale),
m_hDC, rect.left, rect.top, nWidth, nHeight, SRCCOPY);
}
}
//-----------------------------------------------------------------------------
// 函数名: ASLBitmap::DrawRotate()
// 功 能: 将本位图以旋转方式绘制到目标位图上(按块号确定源绘制区)
// 需要Win2000以上操作系统支持
// 参 数: [&bmDest] - 目标位图
// [xDest] - 目标x坐标
// [yDest] - 目标y坐标
// [angle] - 旋转角度
// [nSeq] - 块号
// 返回值: [void] - 无
//-----------------------------------------------------------------------------
void ASLBitmap::DrawRotate(ASLBitmap &bmDest, int xDest, int yDest, double angle,
int nSeq) const
{
DrawRotate(bmDest, xDest, yDest, angle, nSeq / m_nBlockX, nSeq % m_nBlockX);
}
//-----------------------------------------------------------------------------
// 函数名: ASLBitmap::DrawRotate()
// 功 能: 将本位图以旋转方式绘制到目标位图上(按行列号确定源绘制区)
// 需要Win2000以上操作系统支持
// 参 数: [&bmDest] - 目标位图
// [xDest] - 目标x坐标
// [yDest] - 目标y坐标
// [angle] - 旋转角度
// [row] - 行号
// [col] - 列号
// 返回值: [void] - 无
//-----------------------------------------------------------------------------
void ASLBitmap::DrawRotate(ASLBitmap &bmDest, int xDest, int yDest, double angle,
int row, int col) const
{
ASSERT(row >= 0 && row < m_nBlockY && col >= 0 && col < m_nBlockX);
RECT rect;
rect.left = col * m_nBlockW;
rect.right = rect.left + m_nBlockW;
rect.top = row * m_nBlockH;
rect.bottom = rect.top + m_nBlockH;
DrawRotate(bmDest, xDest, yDest, angle, rect);
}
//-----------------------------------------------------------------------------
// 函数名: ASLBitmap::DrawRotate()
// 功 能: 将本位图以旋转方式绘制到目标位图上(用户指定源绘制区)
// 需要Win2000以上操作系统支持
// 参 数: [&bmDest] - 目标位图
// [xDest] - 目标x坐标
// [yDest] - 目标y坐标
// [angle] - 旋转角度
// [*rcSrc] - 源绘制区矩形, 为空时表示整张位图
// 返回值: [void] - 无
//-----------------------------------------------------------------------------
void ASLBitmap::DrawRotate(ASLBitmap &bmDest, int xDest, int yDest, double angle,
const RECT &rcSrc) const
{
ASSERT(m_hBitmap != NULL);
ASSERT(bmDest.GetDC() != NULL);
// 对绘图位置进行调整
xDest -= m_ptHot.x;
yDest -= m_ptHot.y;
RECT rect;
if (EqualRect(&rcSrc, &DEFAULTRECT))
{
rect = m_rcClip;
}
else
{
rect = rcSrc;
if (!_Clip(rect))
{
return;
}
}
int nWidth = rect.right - rect.left;
int nHeight = rect.bottom - rect.top;
float cosa = (float)cos(angle*3.14159/180);
float sina = (float)sin(angle*3.14159/180);
// 设置旋转矩阵
XFORM xform;
xform.eM11 = cosa;
xform.eM12 = -sina;
xform.eM21 = sina;
xform.eM22 = cosa;
xform.eDx = float(xDest + nWidth/2);
xform.eDy = float(yDest + nHeight/2);
// 设置单位矩阵
XFORM xiden;
xiden.eM11 = 1.0f;
xiden.eM12 = 0.0f;
xiden.eM21 = 0.0f;
xiden.eM22 = 1.0f;
xiden.eDx = 0.0f;
xiden.eDy = 0.0f;
// 旋转世界坐标系
SetGraphicsMode(bmDest.GetDC(), GM_ADVANCED);
SetWorldTransform(bmDest.GetDC(), &xform);
// 绘图
if (m_nColorKey >= 0)
{
// 有颜色键处理, 直接调用GDI绘图函数
TransparentBlt(bmDest.GetDC(), -nWidth/2, -nHeight/2, nWidth, nHeight,
m_hDC, rect.left, rect.top, nWidth, nHeight, m_nColorKey);
}
else
{
// 无颜色键处理, 直接调用GDI绘图函数
BitBlt(bmDest.GetDC(), -nWidth/2, -nHeight/2, nWidth, nHeight,
m_hDC, rect.left, rect.top, SRCCOPY);
}
// 恢复世界坐标系
SetWorldTransform(bmDest.GetDC(), &xiden);
}
/******************************************************************************
* 单目绘图函数(修改位图本身)
******************************************************************************/
//-----------------------------------------------------------------------------
// 函数名: ASLBitmap::Clear()
// 功 能: 用指定颜色清空本位图
// 参 数: [cl] - 填充的颜色
// 返回值: [void] - 无
//-----------------------------------------------------------------------------
void ASLBitmap::Clear(COLOR cl)
{
FillRect(cl, m_rcClip.left, m_rcClip.top, m_rcClip.right, m_rcClip.bottom);
}
//-----------------------------------------------------------------------------
// 函数名: ASLBitmap::TextOut()
// 功 能: 输出文字(用默认字体)
// 参 数: [cl] - 文字颜色
// [x] - x坐标
// [y] - y坐标
// [format] - 格式化字符串
// 返回值: [void] - 无
//-----------------------------------------------------------------------------
void ASLBitmap::TextOut(COLOR cl, int x, int y, LPCSTR format, ...)
{
va_list va;
char str[256];
// 处理格式化字符串
va_start(va, format);
vsprintf(str, format, va);
va_end(va);
// 调用GDI函数设置文字颜色并输出文字
SetTextColor(m_hDC, GetRGB32(cl));
::TextOut(m_hDC, x, y, str, (int)strlen(str));
}
//-----------------------------------------------------------------------------
// 函数名: ASLBitmap::TextOut()
// 功 能: 输出文字(用户指定字体)
// 参 数: [font] - 文字字体
// [cl] - 文字颜色
// [x] - x坐标
// [y] - y坐标
// [format] - 格式化字符串
// 返回值: [void] - 无
//-----------------------------------------------------------------------------
void ASLBitmap::TextOut(HFONT font, COLOR cl, int x, int y, LPCSTR format, ...)
{
va_list va;
char str[256];
// 处理格式化字符串
va_start(va, format);
vsprintf(str, format, va);
va_end(va);
// 调用GDI函数设置字体、文字颜色并输出文字
HFONT fontold = (HFONT)SelectObject(m_hDC, font);
SetTextColor(m_hDC, GetRGB32(cl));
::TextOut(m_hDC, x, y, str, (int)strlen(str));
SelectObject(m_hDC, fontold);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -