|
|
发表于 2006-5-22 09:23:00
|
显示全部楼层
Re: DirectDraw画线
- // -------------------------------------------------------
- // Name: DrawLine()
- // Describe: 绘线(基于Buffer)
- // -------------------------------------------------------
- HRESULT CDisplay::DrawLine( LP_BITMAPX pBitmap, int nBeginX, int nBeginY, int nEndX, int nEndY, PIXEL Color )
- {
- #if _DEBUG
- ASSERT(pBitmap);
- ASSERT(pBitmap->GetBuffer());
- #endif
- register int t;
- int distance;
- int x = 0, y = 0, delta_x, delta_y, incx, incy;
- delta_x = nEndX-nBeginX;
- delta_y = nEndY-nBeginY;
- if(delta_x > 0)
- incx = 1;
- else if(delta_x == 0)
- incx = 0;
- else
- {
- delta_x = -delta_x;
- incx = -1;
- }
- if(delta_y > 0)
- incy = 1;
- else if(delta_y == 0)
- incy = 0;
- else
- {
- delta_y = -delta_y;
- incy = -1;
- }
- if(delta_x > delta_y)
- distance = delta_x; /* **** */
- else
- distance = delta_y;
- for(t=0; t<distance+2; t++)
- {
- // pBitmap->m_pBuffer[nBeginX + nBeginY * pBitmap->m_nPitchWidth] = Color;
- DrawPixel(pBitmap, nBeginX, nBeginY, Color);
- x += delta_x;
- y += delta_y;
- if(x > distance)
- {
- x -= distance;
- nBeginX += incx;
- }
- if(y > distance)
- {
- y -= distance;
- nBeginY += incy;
- }
- }
- return S_OK;
- }
复制代码 |
|