162 lines
4.0 KiB
C++
162 lines
4.0 KiB
C++
#include <ddraw/drawsfc.hpp>
|
|
#include <common/point.hpp>
|
|
#include <common/rgbcolor.hpp>
|
|
#include <common/math.hpp>
|
|
|
|
void DrawingSurface::setRowInfo(void)
|
|
{
|
|
if(!isLocked())return;
|
|
mRowInfo.rowCount(mSurfaceDescription.height());
|
|
for(int row=0;row<mRowInfo.rowCount();row++)
|
|
mRowInfo[row]=int((BYTE*)mSurfaceDescription.ptrSurface()+(row*(mSurfaceDescription.width()+(mSurfaceDescription.lPitch()-mSurfaceDescription.width()))));
|
|
}
|
|
|
|
void DrawingSurface::clear(void)
|
|
{
|
|
if(!isLocked())return;
|
|
if(pitch()==width())::memset(mSurfaceDescription.ptrSurface(),0,extent());
|
|
else
|
|
{
|
|
int sfcHeight(height());
|
|
int sfcWidth(width());
|
|
for(int index=0;index<sfcHeight;index++)::memset((void*)mRowInfo[index],0,sfcWidth);
|
|
}
|
|
}
|
|
|
|
void DrawingSurface::setBits(BYTE byteValue)
|
|
{
|
|
if(!isLocked())return;
|
|
int sfcHeight(height());
|
|
int sfcWidth(width());
|
|
for(int index=0;index<sfcHeight;index++)::memset((void*)mRowInfo[index],byteValue,sfcWidth);
|
|
}
|
|
|
|
void DrawingSurface::line(const Point &firstPoint,const Point &secondPoint,BYTE byteValue)
|
|
{
|
|
int xRunning((LONG)firstPoint.x()<<0x10);
|
|
int yRunning((LONG)firstPoint.y()<<0x10);
|
|
int xDelta;
|
|
int yDelta;
|
|
short xDir(1);
|
|
short yDir(1);
|
|
short steps;
|
|
|
|
if(secondPoint.x()<firstPoint.x())xDir=-1;
|
|
if(secondPoint.y()<firstPoint.y())yDir=-1;
|
|
xDelta=(int)secondPoint.x()-(int)firstPoint.x();
|
|
yDelta=(int)secondPoint.y()-(int)firstPoint.y();
|
|
if(xDelta<0)xDelta=-xDelta;
|
|
if(yDelta<0)yDelta=-yDelta;
|
|
if(xDelta<yDelta)
|
|
{
|
|
xDelta<<=0x10;
|
|
if(yDelta)xDelta/=yDelta;
|
|
else xDelta=1L;
|
|
steps=yDelta;
|
|
yDelta=0x10000;
|
|
}
|
|
else
|
|
{
|
|
yDelta<<=0x10;
|
|
if(xDelta)yDelta/=xDelta;
|
|
else yDelta=1L;
|
|
steps=xDelta;
|
|
xDelta=0x10000;
|
|
}
|
|
if(-1==xDir&&-1==yDir)
|
|
{
|
|
for(short stepIndex=0;stepIndex<steps;stepIndex++)
|
|
{
|
|
setByte(yRunning>>0x10,xRunning>>0x10,byteValue);
|
|
xRunning-=xDelta;
|
|
yRunning-=yDelta;
|
|
}
|
|
}
|
|
else if(-1==xDir&&1==yDir)
|
|
{
|
|
for(short stepIndex=0;stepIndex<steps;stepIndex++)
|
|
{
|
|
setByte(yRunning>>0x10,xRunning>>0x10,byteValue);
|
|
xRunning-=xDelta;
|
|
yRunning+=yDelta;
|
|
}
|
|
}
|
|
else if(1==xDir&&-1==yDir)
|
|
{
|
|
for(short itemIndex=0;itemIndex<steps;itemIndex++)
|
|
{
|
|
setByte(yRunning>>0x10,xRunning>>0x10,byteValue);
|
|
xRunning+=xDelta;
|
|
yRunning-=yDelta;
|
|
}
|
|
}
|
|
else if(1==xDir&&1==yDir)
|
|
{
|
|
for(short itemIndex=0;itemIndex<steps;itemIndex++)
|
|
{
|
|
setByte(yRunning>>0x10,xRunning>>0x10,byteValue);
|
|
xRunning+=xDelta;
|
|
yRunning+=yDelta;
|
|
}
|
|
}
|
|
}
|
|
|
|
WORD DrawingSurface::square(const Point ¢erPoint,WORD lineLength,BYTE palIndex)
|
|
{
|
|
WORD halfLength(lineLength>>0x01);
|
|
Point topLeft;
|
|
Point topRight;
|
|
Point bottomLeft;
|
|
Point bottomRight;
|
|
|
|
if(!isOkay())return FALSE;
|
|
topLeft.x(centerPoint.x()-halfLength);
|
|
topLeft.y(centerPoint.y()-halfLength);
|
|
topRight.x(centerPoint.x()+halfLength);
|
|
topRight.y(centerPoint.y()-halfLength);
|
|
bottomRight.x(centerPoint.x()+halfLength);
|
|
bottomRight.y(centerPoint.y()+halfLength);
|
|
bottomLeft.x(centerPoint.x()-halfLength);
|
|
bottomLeft.y(centerPoint.y()+halfLength);
|
|
line(topLeft,topRight,palIndex);
|
|
line(topRight,bottomRight,palIndex);
|
|
line(bottomRight,bottomLeft,palIndex);
|
|
line(bottomLeft,topLeft,palIndex);
|
|
return TRUE;
|
|
}
|
|
|
|
WORD DrawingSurface::circle(const Point &xyPoint,WORD radius,WORD palIndex,WORD aspectValue)
|
|
{
|
|
int a(radius);
|
|
int af;
|
|
int bf;
|
|
int b(0);
|
|
int target(1);
|
|
int radiusSquared(radius*radius);
|
|
|
|
if(!isOkay())return FALSE;
|
|
while(a>=b)
|
|
{
|
|
b=(int)(Math::sqrt(radiusSquared-(a*a))+.50);
|
|
int temp(target);
|
|
target=b;
|
|
b=temp;
|
|
while(b<target)
|
|
{
|
|
if(100.00!=aspectValue)af=(aspectValue*a)/100.00,bf=(aspectValue*b)/100.00;
|
|
else af=a,bf=b;
|
|
setByte(xyPoint.x()+af,xyPoint.y()+b,palIndex);
|
|
setByte(xyPoint.x()+bf,xyPoint.y()+a,palIndex);
|
|
setByte(xyPoint.x()-af,xyPoint.y()+b,palIndex);
|
|
setByte(xyPoint.x()-bf,xyPoint.y()+a,palIndex);
|
|
setByte(xyPoint.x()-af,xyPoint.y()-b,palIndex);
|
|
setByte(xyPoint.x()-bf,xyPoint.y()-a,palIndex);
|
|
setByte(xyPoint.x()+af,xyPoint.y()-b,palIndex);
|
|
setByte(xyPoint.x()+bf,xyPoint.y()-a,palIndex);
|
|
++b;
|
|
}
|
|
--a;
|
|
}
|
|
return TRUE;
|
|
}
|