I want to use TIELineLayer to draw a set of parallel lines.The code is as follows:
void __fastcall TImageForm::AddInteractivelayer(LayerKind lyrKind, TIEShape userShape)
{
ImgEnMain->MouseInteractLayers = TIEMouseInteractLayers() << mlClickCreateLineLayers << mlEditLayerPoints;
ImgEnMain->Cursor = crIESmallArrow;
}
void __fastcall TImageForm::ImgEnMainLayerMoveSize(TObject *Sender, int layer, TIELayerEvent event,
double &PosX, double &PosY, double &Width, double &Height)
{
if (layer == -1 || layer == 0) {
return;
}
TIELineLayer* llyr = NULL;
llyr = dynamic_cast<TIELineLayer*>(ImgEnMain->Layers[layer]);
if (llyr != NULL) {
if (MeasureType == LayerKind::ParallelSpaceLayer &&
llyr->GroupIndex > PARALINEBASE && mbNeedDrawPLine) {
TPoint DrawStart1, DrawStart2, DrawEnd1, DrawEnd2;
int PLineIndex = ImgEnMain->CurrentLayer->GroupIndex;
if (PLineIndex < PARALINEBASE) return false;
TIELineLayer* llyr = NULL;
llyr = dynamic_cast<TIELineLayer*>(ImgEnMain->CurrentLayer);
if (llyr == NULL) return false;
//Get the first line
TIELineLayer* tmpllyr = NULL;
for( int i = 1; i < ImgEnMain->LayersCount; i++){
tmpllyr = dynamic_cast<TIELineLayer*>(ImgEnMain->Layers[i]);
if (tmpllyr != NULL) {
if (tmpllyr->GroupIndex == PLineIndex &&
ImgEnMain->CurrentLayer->LayerIndex != tmpllyr->LayerIndex) {
DrawStart2 = tmpllyr->LinePoint1;
DrawEnd2 = tmpllyr->LinePoint2;
break;
}
}
double slope1;
if (DrawStart2.X == DrawEnd2.X) {
slope1 = -NaN;
}else{
slope1 = 1.0*(DrawStart2.Y - DrawEnd2.Y)/(DrawStart2.X - DrawEnd2.X);
}
double intercept;
DrawStart1 = llyr->LinePoint1;
intercept = DrawStart2.Y - slope1 * DrawStart1.X;
DrawEnd1.X = BitmapX; //Bitmap Coordinate;
DrawEnd1.Y = slope1 * DrawEnd1.X + intercept;
llyr->LinePoint2 = DrawEnd1;
}
}
When I draw the second line, The second line is not parallel to the first line.Why?