|
|
2D图形优化输出,越界剪切处理
DirectDraw,Win32 的绘图API,都会有越界后,速度变慢的问题,下面代码可以很好的帮你解决这个问题。
原函数有BUG存在,修改如下,并增强了对左、上边界的处理 [em10][em5]
'---------------------------------------------------------------
'2D图形优化输出,越界剪切处理(2006-3-14)
'---------------------------------------------------------------
Public Function OptimizeOut(X As Long, Y As Long, Width As Long, Height As Long, srcX As Long, srcY As Long) As Boolean
'当X向左中Y向上超出显示范围后,跳出,不显示
If -X + m_Window.Left >= Width Or -Y + m_Window.Top >= Height Then
Exit Function
End If
'当X向右中Y向下超出显示范围后,跳出,不显示
If X > m_Window.Right Or Y > m_Window.Bottom Then
Exit Function
End If
'X向左越界,剪切掉不绘出的部分
If X < m_Window.Left Then
srcX = srcX - X + m_Window.Left
Width = Width + X - m_Window.Left
X = m_Window.Left
End If
'X向右越界,剪切掉不绘出的部分
If X + Width > m_Window.Right Then
Width = m_Window.Right - X
End If
'Y向左越界,剪切掉不绘出的部分
If Y < m_Window.Top Then
srcY = srcY - Y + m_Window.Top
Height = Height + Y - m_Window.Top
Y = m_Window.Top
End If
'Y向右越界,剪切掉不绘出的部分
If Y + Height > m_Window.Bottom Then
Height = m_Window.Bottom - Y
End If
OptimizeOut = True
End Function
|
|