//--------------------------------------------------------------------------- #include #pragma hdrstop #include "TPGraduator.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(TGraduator *) { new TGraduator(NULL); } //--------------------------------------------------------------------------- __fastcall TGraduator::TGraduator(TComponent* Owner) : TGraphicControl(Owner) { cursorState = CUR_NONE; gdStep = STEP_NONE; } //--------------------------------------------------------------------------- void __fastcall TGraduator::Paint() { HDC dcCanvas = TGraphicControl::Canvas->Handle; HBRUSH hOldBrush=NULL; HPEN hOldPen=NULL, hBlackPen=NULL, hRedPen = NULL; int nDrawMode; hOldBrush = SelectObject(dcCanvas, GetStockObject(NULL_BRUSH)); hBlackPen = CreatePen(PS_SOLID, 1, clBlack); hRedPen = CreatePen(PS_SOLID, 1, clRed); hOldPen = SelectObject(dcCanvas, hBlackPen); // nDrawMode = GetROP2(dcCanvas); // SetROP2(dcCanvas, R2_NOT); Ellipse(dcCanvas, Width / 4, Height / 4, Width * 3 / 4 , Height * 3 / 4); SelectObject(dcCanvas, hRedPen); MoveToEx(dcCanvas, 0, Height / 2, NULL); LineTo(dcCanvas, Width, Height / 2); MoveToEx(dcCanvas, Width / 2, 0, NULL); LineTo(dcCanvas, Width / 2, Height); Ellipse(dcCanvas, Width / 2 - 4, Height / 2 - 4, Width / 2 + 5, Height / 2 + 5); // TGraphicControl::Canvas->Brush->Color = clWhite; // TGraphicControl::Canvas->FillRect(ClientRect); // TGraphicControl::Canvas->Brush->Style = bsClear; // TGraphicControl::Canvas->Brush->Color = clTeal; // TGraphicControl::Canvas->Pen->Color = clBlack; // TGraphicControl::Canvas->Pen->Width = 1; // TGraphicControl::Canvas->Ellipse(0, 0, Width, Height); // TGraphicControl::Canvas->MoveTo(0, 0); // TGraphicControl::Canvas->LineTo(Height, Width); } //--------------------------------------------------------------------------- void __fastcall TGraduator::MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y) { if ((Y >= Height / 2 - 1 && Y <= Height / 2 + 1) || (X >= Width / 2 - 1 && X <= Width / 2 + 1)); if (Y == Height / 2 || X == Width / 2) { // TControl::MouseDown(Button, Shift, X, Y); } else { // Parent->OnMouseDown(this, Button, Shift, Left + X, Top + Y); } } //--------------------------------------------------------------------------- void __fastcall TGraduator::MouseMove(TShiftState Shift, int X, int Y) { if ((Y >= Height / 2 - 4 && Y <= Height / 2 + 5) || (X >= Width / 2 - 4 && X <= Width / 2 + 5)) { if (cursorState == CUR_NONE) { parentCursor = Parent->Cursor; TControl::Cursor = crHandPoint; cursorState = CUR_CROSSPOS; } } else if ((Y >= Height / 2 - 1 && Y <= Height / 2 + 1) || (X >= Width / 2 - 1 && X <= Width / 2 + 1)) { // CROSSPOS if (cursorState == CUR_NONE) { parentCursor = Parent->Cursor; TControl::Cursor = crHandPoint; cursorState = CUR_CROSSPOS; } } else if ((double) ((X - (Width / 2)) * (X - (Width / 2))) / ((Width / 4) * (Width / 4)) + (double) ((Y - (Height / 2)) * (Y - (Height / 2))) / ((Height / 4) * (Height / 4)) < 1.1 && (double) ((X - (Width / 2)) * (X - (Width / 2))) / ((Width / 4) * (Width / 4)) + (double) ((Y - (Height / 2)) * (Y - (Height / 2))) / ((Height / 4) * (Height / 4)) > 0.9) { if (cursorState == CUR_NONE) { parentCursor = Parent->Cursor; TControl::Cursor = crSize; } else if (cursorState == CUR_CROSSPOS) { TControl::Cursor = crSize; } } else { TControl::Cursor = parentCursor; cursorState = CUR_NONE; } // } //--------------------------------------------------------------------------- namespace Tpgraduator { void __fastcall PACKAGE Register() { TComponentClass classes[1] = {__classid(TGraduator)}; RegisterComponents("Texpia", classes, 0); } } //---------------------------------------------------------------------------