//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "ArrowLine.h" #pragma package(smart_init) //--------------------------------------------------------------------------- // ValidCtrCheck is used to assure that the components created do not have // any pure virtual functions. // static inline void ValidCtrCheck(TArrowLine *) { new TArrowLine(NULL); } //--------------------------------------------------------------------------- __fastcall TArrowLine::TArrowLine(TComponent* Owner) : TGraphicControl(Owner) { ControlStyle = TControlStyle().Clear() << csNoStdEvents; Width = 100; Height = 30; Color = clBlack; FGap = 0; FSharp = 0.3; FSize = 15; FLine = alHorizontal; FTick = 1; FLKind = arNone; FRKind = arNone; } //--------------------------------------------------------------------------- namespace Arrowline { void __fastcall PACKAGE Register() { TComponentClass classes[1] = {__classid(TArrowLine)}; RegisterComponents("Kims", classes, 0); } } //--------------------------------------------------------------------------- void __fastcall TArrowLine::SetGap(int Value) { if(FGap != Value) { FGap = Value; Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TArrowLine::SetLKind(TArKind Value) { if(FLKind != Value) { FLKind = Value; Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TArrowLine::SetRKind(TArKind Value) { if(FRKind != Value) { FRKind = Value; Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TArrowLine::SetSharp(float Value) { if(FSharp != Value) { FSharp = Value; Invalidate(); } } void __fastcall TArrowLine::SetSize(int Value) { if(FSize != Value) { FSize = Value; Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TArrowLine::SetTick(int Value) { if(FTick != Value) { FTick = Value; Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TArrowLine::SetLType(TAlType Value) { if(FLine != Value) { FLine = Value; Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TArrowLine::Changed(void) { Canvas->Pen->Width = FTick; Canvas->Brush->Color = Color; Canvas->Pen->Color = Color; int w = FSize * FSharp + FTick , c; float ds, dc, ws, wc; switch(FLine) { case alVertical : c = Width / 2 + FGap; switch(FLKind) { case arNone : Arw[0].x = c; Arw[0].y = 0; pos1 = -1; break; case arSharf : Arw[0].x = c; Arw[0].y = FSize * 0.7; Arw[1].x = c; Arw[1].y = 0; Arw[2].x = c + w; Arw[2].y = FSize; Arw[3].x = c; Arw[3].y = Arw[0].y; Arw[4].x = c - w; Arw[4].y = FSize; pos1 = 3; break; case arThin : case arFull : Arw[0].x = c; Arw[0].y = FSize; Arw[1].x = c; Arw[1].y = 0; Arw[2].x = c + w; Arw[2].y = FSize; Arw[3].x = c - w; Arw[3].y = FSize; pos1 = 2; break; } switch(FRKind) { case arNone : Arw[pos1 + 2].x = c; Arw[pos1 + 2].y = Height; pos2 = -1; break; case arSharf : Arw[pos1 + 2].x = c; Arw[pos1 + 2].y = Height - FSize * 0.7; Arw[pos1 + 3].x = c; Arw[pos1 + 3].y = Height; Arw[pos1 + 4].x = c + w; Arw[pos1 + 4].y = Height - FSize; Arw[pos1 + 5].x = c; Arw[pos1 + 5].y = Arw[pos1 + 2].y; Arw[pos1 + 6].x = c - w; Arw[pos1 + 6].y = Arw[pos1 + 4].y; pos2 = 3; break; case arThin : case arFull : Arw[pos1 + 2].x = c; Arw[pos1 + 2].y = Height - FSize; Arw[pos1 + 3].x = c; Arw[pos1 + 3].y = Height; Arw[pos1 + 4].x = c + w; Arw[pos1 + 4].y = Arw[pos1 + 2].y; Arw[pos1 + 5].x = c - w; Arw[pos1 + 5].y = Arw[pos1 + 2].y; pos2 = 2; break; } break; case alHorizontal : c = Height / 2 + FGap; switch(FLKind) { case arNone : Arw[0].x = 0; Arw[0].y = c; pos1 = -1; break; case arSharf : Arw[0].x = FSize * 0.7; Arw[0].y = c; Arw[1].x = 0; Arw[1].y = c; Arw[2].x = FSize; Arw[2].y = c + w; Arw[3].x = Arw[0].x; Arw[3].y = c; Arw[4].x = FSize; Arw[4].y = c - w; pos1 = 3; break; case arThin : case arFull : Arw[0].x = FSize; Arw[0].y = c; Arw[1].x = 0; Arw[1].y = c; Arw[2].x = FSize; Arw[2].y = c + w; Arw[3].x = FSize; Arw[3].y = c - w; pos1 = 2; break; } switch(FRKind) { case arNone : pos2 = -1; Arw[pos1 + 2].x = Width; Arw[pos1 + 2].y = c; break; case arSharf : Arw[pos1 + 2].x = Width - FSize * 0.7; Arw[pos1 + 2].y = c; Arw[pos1 + 3].x = Width; Arw[pos1 + 3].y = c; Arw[pos1 + 4].x = Width - FSize; Arw[pos1 + 4].y = c + w; Arw[pos1 + 5].x = Arw[pos1 + 2].x; Arw[pos1 + 5].y = c; Arw[pos1 + 6].x = Arw[pos1 + 4].x; Arw[pos1 + 6].y = c - w; pos2 = 3; break; case arThin : case arFull : Arw[pos1 + 2].x = Width - FSize; Arw[pos1 + 2].y = c; Arw[pos1 + 3].x = Width; Arw[pos1 + 3].y = c; Arw[pos1 + 4].x = Arw[pos1 + 2].x; Arw[pos1 + 4].y = c + w; Arw[pos1 + 5].x = Arw[pos1 + 2].x; Arw[pos1 + 5].y = c - w; pos2 = 2; break; } break; /*********************** ȸÀü Çà·Ä |cos -sin | |sin cos | ************************/ case alSlush : switch(FLKind) { case arNone : if(Height < Width) { Arw[0].x = 0; Arw[0].y = Height - FGap; } else { Arw[0].x = FGap; Arw[0].y = Height; } pos1 = -1; break; case arSharf : if(Height < Width) { Math::SinCos(Math::ArcTan2(Height - FGap * 2, Width), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[0].x = dc * 0.7; Arw[0].y = Height - ds * 0.7 - FGap; Arw[1].x = 0; Arw[1].y = Height - FGap; Arw[2].x = dc + ws; Arw[2].y = Height - ds + wc - FGap; Arw[3].x = Arw[0].x; Arw[3].y = Arw[0].y; Arw[4].x = dc - ws; Arw[4].y = Height - ds - wc - FGap; } else { Math::SinCos(Math::ArcTan2(Height, Width - FGap * 2), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[0].x = dc * 0.7 + FGap; Arw[0].y = Height - ds * 0.7; Arw[1].x = FGap; Arw[1].y = Height; Arw[2].x = dc + ws + FGap; Arw[2].y = Height - ds + wc; Arw[3].x = Arw[0].x; Arw[3].y = Arw[0].y; Arw[4].x = dc - ws + FGap; Arw[4].y = Height - ds - wc; } pos1 = 3; break; case arThin : case arFull : if(Height < Width) { Math::SinCos(Math::ArcTan2(Height - FGap * 2, Width), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[0].x = dc; Arw[0].y = Height - ds - FGap; Arw[1].x = 0; Arw[1].y = Height - FGap; Arw[2].x = dc + ws; Arw[2].y = Height - ds + wc - FGap; Arw[3].x = dc - ws; Arw[3].y = Height - ds - wc - FGap; } else { Math::SinCos(Math::ArcTan2(Height, Width - FGap * 2), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[0].x = dc + FGap; Arw[0].y = Height - ds; Arw[1].x = FGap; Arw[1].y = Height; Arw[2].x = dc + ws + FGap; Arw[2].y = Height - ds + wc; Arw[3].x = dc - ws + FGap; Arw[3].y = Height - ds - wc; } pos1 = 2; break; } switch(FRKind) { case arNone : if(Height < Width) { Arw[pos1 + 2].x = Width; Arw[pos1 + 2].y = FGap; } else { Arw[pos1 + 2].x = Width - FGap; Arw[pos1 + 2].y = 0; } pos2 = -1; break; case arSharf : if(Height < Width) { Math::SinCos(Math::ArcTan2(Height - FGap * 2, Width), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[pos1 + 2].x = Width - dc * 0.7; Arw[pos1 + 2].y = ds * 0.7 + FGap; Arw[pos1 + 3].x = Width; Arw[pos1 + 3].y = FGap; Arw[pos1 + 4].x = Width - dc - ws; Arw[pos1 + 4].y = ds - wc + FGap; Arw[pos1 + 5].x = Arw[pos1 + 2].x; Arw[pos1 + 5].y = Arw[pos1 + 2].y; Arw[pos1 + 6].x = Width - dc + ws; Arw[pos1 + 6].y = ds + wc + FGap; } else { Math::SinCos(Math::ArcTan2(Height, Width - FGap * 2), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[pos1 + 2].x = Width - dc * 0.7 - FGap; Arw[pos1 + 2].y = ds * 0.7; Arw[pos1 + 3].x = Width - FGap; Arw[pos1 + 3].y = 0; Arw[pos1 + 4].x = Width - dc - ws - FGap; Arw[pos1 + 4].y = ds - wc; Arw[pos1 + 5].x = Arw[pos1 + 2].x; Arw[pos1 + 5].y = Arw[pos1 + 2].y; Arw[pos1 + 6].x = Width - dc + ws - FGap; Arw[pos1 + 6].y = ds + wc; } pos2 = 3; break; case arThin : case arFull : if(Height < Width) { Math::SinCos(Math::ArcTan2(Height - FGap * 2, Width), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[pos1 + 2].x = Width - dc; Arw[pos1 + 2].y = ds + FGap; Arw[pos1 + 3].x = Width; Arw[pos1 + 3].y = FGap; Arw[pos1 + 4].x = Width - dc - ws; Arw[pos1 + 4].y = ds - wc + FGap; Arw[pos1 + 5].x = Width - dc + ws; Arw[pos1 + 5].y = ds + wc + FGap; } else { Math::SinCos(Math::ArcTan2(Height, Width - FGap * 2), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[pos1 + 2].x = Width - dc - FGap; Arw[pos1 + 2].y = ds; Arw[pos1 + 3].x = Width - FGap; Arw[pos1 + 3].y = 0; Arw[pos1 + 4].x = Width - dc - ws - FGap; Arw[pos1 + 4].y = ds - wc; Arw[pos1 + 5].x = Width - dc + ws - FGap; Arw[pos1 + 5].y = ds + wc; } pos2 = 2; break; } break; case alRslush : c = 0; switch(FLKind) { case arNone : if(Height < Width) { Arw[0].x = 0; Arw[0].y = FGap; } else { Arw[0].x = FGap; Arw[0].y = 0; } pos1 = -1; break; case arSharf : if(Height < Width) { Math::SinCos(Math::ArcTan2(Height - FGap * 2, Width), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[0].x = dc * 0.7; Arw[0].y = ds * 0.7 + FGap; Arw[1].x = 0; Arw[1].y = FGap; Arw[2].x = dc + ws; Arw[2].y = ds - wc + FGap; Arw[3].x = Arw[0].x; Arw[3].y = Arw[0].y; Arw[4].x = dc - ws; Arw[4].y = ds + wc + FGap; } else { Math::SinCos(Math::ArcTan2(Height, Width - FGap * 2), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[0].x = dc * 0.7 + FGap; Arw[0].y = ds * 0.7; Arw[1].x = FGap; Arw[1].y = 0; Arw[2].x = dc + ws + FGap; Arw[2].y = ds - wc; Arw[3].x = Arw[0].x; Arw[3].y = Arw[0].y; Arw[4].x = dc - ws + FGap; Arw[4].y = ds + wc; } pos1 = 3; break; case arThin : case arFull : if(Height < Width) { Math::SinCos(Math::ArcTan2(Height - FGap * 2, Width), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[0].x = dc; Arw[0].y = ds + FGap; Arw[1].x = 0; Arw[1].y = FGap; Arw[2].x = dc + ws; Arw[2].y = ds - wc + FGap; Arw[3].x = dc - ws; Arw[3].y = ds + wc + FGap; } else { Math::SinCos(Math::ArcTan2(Height, Width - FGap * 2), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[0].x = dc + FGap; Arw[0].y = ds; Arw[1].x = FGap; Arw[1].y = 0; Arw[2].x = dc + ws + FGap; Arw[2].y = ds - wc; Arw[3].x = dc - ws + FGap; Arw[3].y = ds + wc; } pos1 = 2; break; } switch(FRKind) { case arNone : if(Height < Width) { Arw[pos1 + 2].x = Width; Arw[pos1 + 2].y = Height - FGap; } else { Arw[pos1 + 2].x = Width - FGap; Arw[pos1 + 2].y = Height; } pos2 = -1; break; case arSharf : if(Height < Width) { Math::SinCos(Math::ArcTan2(Height - FGap * 2, Width), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[pos1 + 2].x = Width - dc * 0.7; Arw[pos1 + 2].y = Height - ds * 0.7 - FGap; Arw[pos1 + 3].x = Width; Arw[pos1 + 3].y = Height - FGap; Arw[pos1 + 4].x = Width - dc - ws; Arw[pos1 + 4].y = Height - ds + wc - FGap; Arw[pos1 + 5].x = Arw[pos1 + 2].x; Arw[pos1 + 5].y = Arw[pos1 + 2].y; Arw[pos1 + 6].x = Width - dc + ws; Arw[pos1 + 6].y = Height - ds - wc - FGap; } else { Math::SinCos(Math::ArcTan2(Height, Width - FGap * 2), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[pos1 + 2].x = Width - dc * 0.7 - FGap; Arw[pos1 + 2].y = Height - ds * 0.7; Arw[pos1 + 3].x = Width - FGap; Arw[pos1 + 3].y = Height; Arw[pos1 + 4].x = Width - dc - ws - FGap; Arw[pos1 + 4].y = Height - ds + wc; Arw[pos1 + 5].x = Arw[pos1 + 2].x; Arw[pos1 + 5].y = Arw[pos1 + 2].y; Arw[pos1 + 6].x = Width - dc + ws - FGap; Arw[pos1 + 6].y = Height - ds - wc; } pos2 = 3; break; case arThin : case arFull : if(Height < Width) { Math::SinCos(Math::ArcTan2(Height - FGap * 2, Width), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[pos1 + 2].x = Width - dc; Arw[pos1 + 2].y = Height - ds - FGap; Arw[pos1 + 3].x = Width; Arw[pos1 + 3].y = Height - FGap; Arw[pos1 + 4].x = Width - dc - ws; Arw[pos1 + 4].y = Height - ds + wc - FGap; Arw[pos1 + 5].x = Width - dc + ws; Arw[pos1 + 5].y = Height - ds - wc - FGap; } else { Math::SinCos(Math::ArcTan2(Height, Width - FGap * 2), sn, cn); dc = cn * FSize; ds = sn * FSize; ws = sn * w; wc = cn * w; Arw[pos1 + 2].x = Width - dc - FGap; Arw[pos1 + 2].y = Height - ds; Arw[pos1 + 3].x = Width - FGap; Arw[pos1 + 3].y = Height; Arw[pos1 + 4].x = Width - dc - ws - FGap; Arw[pos1 + 4].y = Height - ds + wc; Arw[pos1 + 5].x = Width - dc + ws - FGap; Arw[pos1 + 5].y = Height - ds - wc; } pos2 = 2; break; } break; } } //--------------------------------------------------------------------------- void __fastcall TArrowLine::Paint(void) { Changed(); Canvas->MoveTo(Arw[0].x, Arw[0].y); Canvas->LineTo(Arw[pos1 + 2].x, Arw[pos1 + 2].y); Canvas->Pen->Width = 1; if(pos1 > 1) { if(FLKind != arThin) Canvas->Polygon(&Arw[1], pos1); else { Canvas->MoveTo(Arw[1].x, Arw[1].y); Canvas->LineTo(Arw[2].x, Arw[2].y); Canvas->MoveTo(Arw[1].x, Arw[1].y); Canvas->LineTo(Arw[3].x, Arw[3].y); Canvas->MoveTo(Arw[1].x, Arw[1].y); Canvas->LineTo(Arw[0].x, Arw[0].y); } } if(pos2 > 1) { if(FRKind != arThin) Canvas->Polygon(&Arw[pos1 + 3], pos2); else { Canvas->MoveTo(Arw[pos1 + 3].x, Arw[pos1 + 3].y); Canvas->LineTo(Arw[pos1 + 4].x, Arw[pos1 + 4].y); Canvas->MoveTo(Arw[pos1 + 3].x, Arw[pos1 + 3].y); Canvas->LineTo(Arw[pos1 + 5].x, Arw[pos1 + 5].y); Canvas->MoveTo(Arw[pos1 + 3].x, Arw[pos1 + 3].y); Canvas->LineTo(Arw[pos1 + 2].x, Arw[pos1 + 2].y); } } } //---------------------------------------------------------------------------