C4Object: Line data now properties

For objects with Line set, color is now stored
as an array [LineColor, VertexColor] in the property
LineColor.
If Line==C4D_Line_Vertex, the vertices of the target objects
that the line attaches to is also stored as an array [Target0Vtx,
Target1Vtx] in the property LineAttach.
stable-5.2
Nicolas Hake 2009-07-22 18:24:07 +02:00
parent ab5da9cc3f
commit 496e795577
5 changed files with 37 additions and 25 deletions

View File

@ -52,6 +52,7 @@ class C4TargetFacet: public C4Facet
void DrawBolt(int iX1, int iY1, int iX2, int iY2, BYTE bCol, BYTE bCol2);
void DrawLine(int iX1, int iY1, int iX2, int iY2, BYTE bCol1, BYTE bCol2);
void DrawLineDw(int iX1, int iY1, int iX2, int iY2, uint32_t col1, uint32_t col2);
public:
C4TargetFacet &operator = (const C4Facet& rhs)
{

View File

@ -169,6 +169,8 @@ P_ActMap,
P_Attach,
P_Visibility,
P_Parallaxity,
P_LineColors,
P_LineAttach,
P_Procedure,
P_Directions,
P_FlipDir,

View File

@ -45,15 +45,20 @@ void C4TargetFacet::SetRect(C4TargetRect &rSrc)
X=rSrc.x; Y=rSrc.y; Wdt=rSrc.Wdt; Hgt=rSrc.Hgt; TargetX=rSrc.tx; TargetY=rSrc.ty;
}
void C4TargetFacet::DrawLine(int iX1, int iY1, int iX2, int iY2, BYTE bCol1, BYTE bCol2)
void C4TargetFacet::DrawLineDw(int iX1, int iY1, int iX2, int iY2, uint32_t col1, uint32_t col2)
{
if (!lpDDraw || !Surface || !Wdt || !Hgt) return;
// Scroll position
iX1-=TargetX; iY1-=TargetY; iX2-=TargetX; iY2-=TargetY;
// No clipping is done here, because clipping will be done by gfx wrapper anyway
// Draw line
lpDDraw->DrawLine(Surface,X+iX1,Y+iY1,X+iX2,Y+iY2,bCol1);
lpDDraw->DrawPix(Surface,(float)(X+iX1),(float)(Y+iY1),lpDDraw->Pal.GetClr(bCol2));
lpDDraw->DrawLineDw(Surface,X+iX1,Y+iY1,X+iX2,Y+iY2,col1);
lpDDraw->DrawPix(Surface,(float)(X+iX1),(float)(Y+iY1),col2);
}
void C4TargetFacet::DrawLine(int iX1, int iY1, int iX2, int iY2, BYTE bCol1, BYTE bCol2)
{
DrawLineDw(iX1, iY1, iX2, iY2, lpDDraw->Pal.GetClr(bCol1), lpDDraw->Pal.GetClr(bCol2));
}
// bolt random size

View File

@ -2600,34 +2600,25 @@ void C4Object::DrawLine(C4TargetFacet &cgo)
// additive mode?
PrepareDrawing();
// Draw line segments
C4Value colorsV; GetProperty(Strings.P[P_LineColors], colorsV);
C4ValueArray *colors = colorsV.getArray();
int32_t color0 = 0x00FF00FF, color1 = 0x00FF00FF; // use bright colors so author notices
if (colors)
{
color0 = colors->GetItem(0).getInt(); color1 = colors->GetItem(1).getInt();
}
for (int32_t vtx=0; vtx+1<Shape.VtxNum; vtx++)
switch (Def->Line)
{
case C4D_Line_Power:
cgo.DrawLine(Shape.VtxX[vtx],Shape.VtxY[vtx],
Shape.VtxX[vtx+1],Shape.VtxY[vtx+1],
68,26);
break;
case C4D_Line_Source: case C4D_Line_Drain:
cgo.DrawLine(Shape.VtxX[vtx],Shape.VtxY[vtx],
Shape.VtxX[vtx+1],Shape.VtxY[vtx+1],
23,26);
break;
case C4D_Line_Lightning:
cgo.DrawBolt(Shape.VtxX[vtx],Shape.VtxY[vtx],
Shape.VtxX[vtx+1],Shape.VtxY[vtx+1],
CWhite,CWhite);
break;
case C4D_Line_Rope:
cgo.DrawLine(Shape.VtxX[vtx],Shape.VtxY[vtx],
Shape.VtxX[vtx+1],Shape.VtxY[vtx+1],
65,65);
break;
case C4D_Line_Vertex:
case C4D_Line_Colored:
cgo.DrawLine(Shape.VtxX[vtx],Shape.VtxY[vtx],
cgo.DrawLineDw(Shape.VtxX[vtx],Shape.VtxY[vtx],
Shape.VtxX[vtx+1],Shape.VtxY[vtx+1],
BYTE(Local[0].getInt()),BYTE(Local[1].getInt()));
color0, color1);
break;
}
// reset blit mode
@ -5213,6 +5204,17 @@ void C4Object::ExecAction()
BOOL fBroke;
fBroke=FALSE;
int32_t iConnectX,iConnectY;
int32_t attachVertex0,attachVertex1;
attachVertex0=attachVertex1=0;
{
C4Value lineAttachV; GetProperty(Strings.P[P_LineAttach], lineAttachV);
C4ValueArray *lineAttach = lineAttachV.getArray();
if (lineAttach)
{
attachVertex0 = lineAttach->GetItem(0).getInt();
attachVertex1 = lineAttach->GetItem(1).getInt();
}
}
// Line destruction check: Target missing or incomplete
if (!Action.Target || (Action.Target->Con<FullCon)) fBroke=TRUE;
@ -5229,8 +5231,8 @@ void C4Object::ExecAction()
{
// Connect to vertex
if (Def->Line == C4D_Line_Vertex)
{ iConnectX=Action.Target->GetX()+Action.Target->Shape.GetVertexX(Local[2].getInt());
iConnectY=Action.Target->GetY()+Action.Target->Shape.GetVertexY(Local[2].getInt()); }
{ iConnectX=Action.Target->GetX()+Action.Target->Shape.GetVertexX(attachVertex0);
iConnectY=Action.Target->GetY()+Action.Target->Shape.GetVertexY(attachVertex0); }
// Connect to bottom center
else
{ iConnectX=Action.Target->GetX();
@ -5251,8 +5253,8 @@ void C4Object::ExecAction()
{
// Connect to vertex
if (Def->Line == C4D_Line_Vertex)
{ iConnectX=Action.Target2->GetX()+Action.Target2->Shape.GetVertexX(Local[3].getInt());
iConnectY=Action.Target2->GetY()+Action.Target2->Shape.GetVertexY(Local[3].getInt()); }
{ iConnectX=Action.Target2->GetX()+Action.Target2->Shape.GetVertexX(attachVertex1);
iConnectY=Action.Target2->GetY()+Action.Target2->Shape.GetVertexY(attachVertex1); }
// Connect to bottom center
else
{ iConnectX=Action.Target2->GetX();

View File

@ -116,6 +116,8 @@ C4StringTable::C4StringTable()
P[P_Step] = RegString("Step");
P[P_Visibility] = RegString("Visibility");
P[P_Parallaxity] = RegString("Parallaxity");
P[P_LineColors] = RegString("LineColors");
P[P_LineAttach] = RegString("LineAttach");
for (unsigned int i = 0; i < P_LAST; ++i) P[i]->IncRef();
}