//--------------------------------------------------------------------------- #include #pragma hdrstop #include #include "TPShape.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(TPShape *) { new TPShape(NULL); } //--------------------------------------------------------------------------- __fastcall TPShape::TPShape(TComponent* Owner) : TGraphicControl(Owner) { ControlStyle = ControlStyle << csReplicatable ; Width = 65; Height = 65; FSciSize = 3; FPen = new TPen; FPen->OnChange = StyleChanged; FBrush = new TBrush; FBrush->OnChange = StyleChanged; } //--------------------------------------------------------------------------- __fastcall TPShape::~TPShape() { delete FPen; delete FBrush; } //--------------------------------------------------------------------------- void __fastcall TPShape::Paint() { int X, Y, W, H, S; Canvas->Pen = FPen; Canvas->Brush = FBrush; X = Canvas->Pen->Width / 2; Y = X; W = Width - Canvas->Pen->Width + 1; H = Height - Canvas->Pen->Width + 1; if(Canvas->Pen->Width == 0 ){ W--; H--; } S = (WRectangle(X,Y,X+W,Y+H); break; case tpstRoundRect: case tpstRoundSquare: Canvas->RoundRect(X,Y,X+W,Y+H,S/4,S/4); break; case tpstCircle: case tpstEllipse: Canvas->Ellipse(X,Y,X+W,Y+H); break; case tpstScissors: ScissorsEffect(X,Y,X+W,Y+H,FSciSize); break; } } //--------------------------------------------------------------------------- void __fastcall TPShape::StyleChanged (TObject* Sender) { Invalidate(); } //--------------------------------------------------------------------------- void __fastcall TPShape::SetBrush(TBrush* Value) { FBrush->Assign(Value); } //--------------------------------------------------------------------------- void __fastcall TPShape::SetPen(TPen* Value) { FPen->Assign(Value); } //--------------------------------------------------------------------------- void __fastcall TPShape::SetShape(TPShapeType Value) { if( FShape != Value) { FShape = Value; Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TPShape::SetSciSize(int Value) { if( Value > 3 && Value < 15) { FSciSize = Value; Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TPShape::ScissorsEffect(int x,int y,int w, int h,int size) { int UNIT; UNIT = size; if (UNIT <3 ) UNIT = 3; POINT Start, End; Start.x = x ; Start.y = y ; End.x = w -1; End.y = h-1; int i; long temp; // ½ÃÀÛÁ¡À» ¼³Á¤ if (Start.x > End.x){ temp = Start.x; Start.x = End.x; End.x = temp; } if (Start.y > End.y) { temp = Start.y; Start.y = End.y; End.y = temp; } long Garo, Sero; int VertexCount[4]; Garo = abs(End.x - Start.x -UNIT); // °¡·Î ±æÀÌ Sero = abs(End.y - Start.y -UNIT); // ¼¼·Î ±æÀÌ // ¼¼·Î º¯ÀÇ VerTex ¼ö ±¸Çϱâ VertexCount[0] = VertexCount[2] = Sero / UNIT ; // °¡·Î º¯ÀÇ VerTex ¼ö ±¸Çϱâ VertexCount[1] = VertexCount[3] = Garo / UNIT; int Total = VertexCount[0] + VertexCount[1] + VertexCount[2] + VertexCount[3]; POINT *pt = new POINT[Total]; //MoveToEx(hDC,Start.x + UNIT,Start.y + UNIT,NULL); Canvas->MoveTo(Start.x +UNIT,Start.y +UNIT); int ValueX ,ValueY; // Áº¯ÀÇ ÁÂÇ¥ ±¸Çϱâ ValueY = Start.y; for( i = 0; i < VertexCount[0] ; i++) { if( i %2 == 1) { pt[i].x = Start.x ; } if (i %2 == 0){ pt[i].x = Start.x + UNIT; } pt[i].y = ValueY = ValueY + UNIT; if(pt[i].y > End.y - UNIT) { if(abs(pt[i].y - pt[i-1].y) < 4) pt[i].x = Start.x +UNIT; pt[i].y = End.y - UNIT; } } // ¹Øº¯ÀÇ ÁÂÇ¥ ±¸Çϱâ ValueX = Start.x; int RoopStart; RoopStart = VertexCount[0]; for(i = RoopStart ; i < RoopStart + VertexCount[1]; i++) { if(i % 2 == 1) pt[i].y = End.y; if(i % 2 == 0) pt[i].y = End.y - UNIT; pt[i].x = ValueX = ValueX + UNIT; if(pt[i].x > End.x - UNIT){ if(abs(pt[i].x - pt[i-1].x) < 4) pt[i].y = Start.y +UNIT; pt[i].x = End.x - UNIT; } } // ¿ìº¯ÀÇ ÁÂÇ¥ ±¸Çϱâ RoopStart = RoopStart + VertexCount[1]; ValueY = End.y; for( i = RoopStart; i < RoopStart + VertexCount[2]; i++) { if( i %2 == 1) { pt[i].x = End.x ; } if (i %2 == 0) { pt[i].x = End.x -UNIT; } pt[i].y = ValueY = ValueY - UNIT; if(pt[i].y < Start.y + UNIT) { if(abs(pt[i].y - pt[i-1].y) < 4) pt[i].x = End.x -UNIT; pt[i].y = Start.y + UNIT; } } // À­º¯ÀÇ ÁÂÇ¥ ±¸Çϱâ ValueX = End.x; RoopStart = RoopStart + VertexCount[2]; for( i = RoopStart ; i < RoopStart + VertexCount[3];i++) { if(i % 2 == 1) pt[i].y = Start.y; if(i % 2 == 0) pt[i].y = Start.y + UNIT; pt[i].x = ValueX = ValueX - UNIT; if(pt[i].x < Start.x + UNIT) { if(abs(pt[i].x - pt[i-1].x) < 3) pt[i].y = Start.y +UNIT; pt[i].x = Start.x - UNIT; } } Canvas->MoveTo(Start.x +UNIT,Start.y + UNIT); Canvas->Polygon((TPoint *)pt, Total -1); delete pt; } //--------------------------------------------------------------------------- namespace Tpshape { void __fastcall PACKAGE Register() { TComponentClass classes[1] = {__classid(TPShape)}; RegisterComponents("Texpia", classes, 0); } } //---------------------------------------------------------------------------