//--------------------------------------------------------------------------- //Kangin D.N., 2005 #include #pragma hdrstop #include "ruler1.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(TRuler *) { new TRuler(NULL); } //--------------------------------------------------------------------------- __fastcall TRuler::TRuler(TComponent* Owner) : TGraphicControl(Owner), FMin(0), FMax(10), FInterval(1), FColor(clBtnFace), FMarksClr(clBtnFace), FOrientation(orHorizontal) { FCanvas = new TControlCanvas(); dynamic_cast(FCanvas)->Control = this; FFont = FCanvas->Font; } __fastcall TRuler::~TRuler() { delete FCanvas; FCanvas = NULL; } //--------------------------------------------------------------------------- void __fastcall TRuler::SetMin(float Min0) { FMin = Min0; Paint(); } // //--------------------------------------------------------------------------- void __fastcall TRuler::SetMax(float Max0) { FMax = Max0; Paint(); } //--------------------------------------------------------------------------- void __fastcall TRuler::SetInterval(float Interval0) { FInterval = Interval0; Paint(); } //--------------------------------------------------------------------------- void __fastcall TRuler::SetColor(TColor Clr0) { FColor = Clr0; Paint(); } //--------------------------------------------------------------------------- void __fastcall TRuler::SetFont(TFont* Font0) { Canvas->Font->Charset = Font0->Charset; Canvas->Font->PixelsPerInch = Font0->PixelsPerInch; Canvas->Font->Color = Font0->Color; Canvas->Font->Height = Font0->Height; Canvas->Font->Name = Font0->Name; Canvas->Font->Pitch = Font0->Pitch; Canvas->Font->Size = Font0->Size; Canvas->Font->Style = Font0->Style; Canvas->Font->FontAdapter = Font0->FontAdapter; Paint(); } //--------------------------------------------------------------------------- void __fastcall TRuler::SetMarksClr(TColor Clr0) { FMarksClr = Clr0; Paint(); } //--------------------------------------------------------------------------- void __fastcall TRuler::SetOrientation(TOrientation Orientation0) { FOrientation = Orientation0; Paint(); } //--------------------------------------------------------------------------- void __fastcall TRuler::Paint(void) { Canvas->Pen->Color = Color; Canvas->Brush->Color = Color; if(Orientation == orHorizontal) { this->Canvas->Rectangle(0, 0, Width, Height - 6); Canvas->Pen->Color = MarksClr; Canvas->Brush->Color = MarksClr; this->Canvas->Rectangle(0, Height - 5, Width, Height); if(FMax != FMin) { float inteer = Interval * Width/(FMax - FMin); float b = FMin; if(inteer != 0) for(float a = -3; a < Width; a+= inteer) { Canvas->Pen->Color = Font->Color; Canvas->Brush->Color = Color; Canvas->MoveTo(a+3, Height); Canvas->LineTo(a+3, Height-10); Canvas->TextOut((int)a, 0, FloatToStr(b)); b += Interval; } } } else { this->Canvas->Rectangle(0, 0, Width-6, Height); Canvas->Pen->Color = MarksClr; Canvas->Brush->Color = MarksClr; this->Canvas->Rectangle(Width - 5, 0, Width, Height); if(FMax != FMin) { float inteer = Interval * Height/(FMax - FMin); float b = FMin; if(inteer != 0) for(float a = -7; a < Height; a+= inteer) { Canvas->Pen->Color = Font->Color; Canvas->Brush->Color = Color; Canvas->MoveTo(Width, a+7); Canvas->LineTo(Width - 10, a+7); Canvas->TextOut(0, (int)a, FloatToStr(b)); b += Interval; } } } } //--------------------------------------------------------------------------- namespace Ruler1 { void __fastcall PACKAGE Register() { TComponentClass classes[1] = {__classid(TRuler)}; RegisterComponents("Мои примеры", classes, 0); } } //---------------------------------------------------------------------------