//--------------------------------------------------------------------- #include #include #pragma hdrstop #include "Grid_F.h" //--------------------------------------------------------------------- #pragma package(smart_init) #pragma link "CurrEdit" #pragma link "ToolEdit" #pragma link "TPSpin" #pragma resource "*.dfm" //--------------------------------------------------------------------- #define IDS_GRIDFORM StringTable[0] #define IDS_GRIDSTYLE StringTable[1] #define IDS_CURGRIDCOLOR StringTable[2] #define IDS_CATALOG StringTable[3] #define IDS_SELGRIDCOLOR StringTable[4] #define IDS_DEFAULT StringTable[5] //--------------------------------------------------------------------- __fastcall TGridForm::TGridForm(TComponent* AOwner) : TForm(AOwner) { } //--------------------------------------------------------------------------- void __fastcall TGridForm::FormCreate(TObject *Sender) { TIniFile *IniFile = new TIniFile(DirectoryItem+"\\Environment.ini"); if (IniFile) { int Count = IniFile->ReadInteger("Grid", "Catalog-Count", 0); for (int i=0; iItems->Add(IniFile->ReadString("Grid", "Catalog-"+AnsiString(i), "")); } delete IniFile; } FUnit = uDot; FBitmap = NULL; //============================================ StringTable.Create(DirectoryBin, Language, "Grid"); SetSmallFont(Font); Caption = IDS_GRIDFORM; rgUnit->Caption = IDS_COMMON_UNIT; Label1->Caption = IDS_COMMON_HORIZONTAL; Label2->Caption = IDS_COMMON_VERTICAL; Label3->Caption = IDS_CATALOG; Label4->Caption = IDS_CURGRIDCOLOR; OKBtn->Caption = IDS_COMMON_BUTTONOK; CancelBtn->Caption = IDS_COMMON_BUTTONCANCEL; btnDefault->Caption = IDS_DEFAULT; //============================================ View(NULL); } //--------------------------------------------------------------------------- void __fastcall TGridForm::FormDestroy(TObject *Sender) { if (FBitmap) delete FBitmap; TIniFile *IniFile = new TIniFile(DirectoryItem+"\\Environment.ini"); if (IniFile) { int Count = IniFile->ReadInteger("Grid", "Catalog-Count", 0); IniFile->WriteInteger("Grid", "Catalog-Count", lbGrid->Items->Count); int i = 0; while (true) { if (iItems->Count) { IniFile->WriteString("Grid", "Catalog-"+AnsiString(i), lbGrid->Items->Strings[i]); } else if (iDeleteKey("Grid", "Catalog-"+AnsiString(i)); } else break; i++; } delete IniFile; } } //--------------------------------------------------------------------- void __fastcall TGridForm::rgUnitClick(TObject *Sender) { switch (FUnit) { case 1: rceGapX->Value *= FDotsPerInch; rceGapY->Value *= FDotsPerInch; break; case 2: rceGapX->Value *= FDotsPerInch/2.54; rceGapY->Value *= FDotsPerInch/2.54; break; } FUnit = TUnit(rgUnit->ItemIndex); //Assinging int to Tputils switch (FUnit) { case 1: rceGapX->Value /= FDotsPerInch; rceGapY->Value /= FDotsPerInch; break; case 2: rceGapX->Value /= FDotsPerInch/2.54; rceGapY->Value /= FDotsPerInch/2.54; break; } } //--------------------------------------------------------------------------- void __fastcall TGridForm::sbCatalogAddClick(TObject *Sender) { lbGrid->Items->Add(GridToStr(FUnit, rceGapX->Value, rceGapY->Value)); } //--------------------------------------------------------------------------- void __fastcall TGridForm::sbCatalogDeleteClick(TObject *Sender) { lbGrid->Items->Delete(lbGrid->ItemIndex); } //--------------------------------------------------------------------------- void __fastcall TGridForm::lbGridDblClick(TObject *Sender) { TGrid Grid = StrToGrid(lbGrid->Items->Strings[lbGrid->ItemIndex]); rgUnit->ItemIndex = Grid.Unit; rceGapX->Value = Grid.X; rceGapY->Value = Grid.Y; } //--------------------------------------------------------------------------- void __fastcall TGridForm::sbGridColorClick(TObject *Sender) { if (GridColorDialog->Execute()) { shGridColor->Brush->Color = GridColorDialog->Color; View(NULL); } } //--------------------------------------------------------------------------- void __fastcall TGridForm::seSectionNumberChange(TObject *Sender) { if (seSectionNumber->Text.Length()>0) { View(NULL); } } //--------------------------------------------------------------------------- void __fastcall TGridForm::sbSectionColorClick(TObject *Sender) { if (GridColorDialog->Execute()) { shSectionColor->Brush->Color = GridColorDialog->Color; View(NULL); } } //--------------------------------------------------------------------------- void __fastcall TGridForm::btnDefaultClick(TObject *Sender) { rgUnit->ItemIndex = 0; rceGapX->Value = 1.0; rceGapY->Value = 1.0; shGridColor->Brush->Color = clBlack; seSectionNumber->Value = 0; shSectionColor->Brush->Color = clBlack; TIniFile *IniFile = new TIniFile(DirectoryItem+"\\Environment.ini"); if (IniFile) { rgUnit->ItemIndex = IniFile->ReadInteger("Grid", "Unit", 0); rceGapX->Value = IniFile->ReadFloat("Grid", "GapX", 1.0); rceGapY->Value = IniFile->ReadFloat("Grid", "GapY", 1.0); int Count = IniFile->ReadInteger("Grid", "Catalog-Count", 0); for (int i=0; iItems->Add(IniFile->ReadString("Grid", "Catalog-"+AnsiString(i), "")); } shGridColor->Brush->Color = IniFile->ReadInteger("Grid", "Color", clBlack); seSectionNumber->Value = IniFile->ReadInteger("Grid", "LinesPerSection", 0); shSectionColor->Brush->Color = IniFile->ReadInteger("Grid", "SectionColor", clBlack); delete IniFile; } View(NULL); } //--------------------------------------------------------------------------- void __fastcall TGridForm::View(TObject *Sender) { int p; Image->Canvas->Pen->Color = shGridColor->Brush->Color; for (p=0; pWidth; p+=5) { Image->Canvas->MoveTo(p, 0); Image->Canvas->LineTo(p, Image->Height); } for (p=0; pHeight; p+=5) { Image->Canvas->MoveTo(0, p); Image->Canvas->LineTo(Image->Width, p); } if (seSectionNumber->Value>0) { Image->Canvas->Pen->Color = shSectionColor->Brush->Color; for (p=0; pWidth; p+=5*seSectionNumber->Value) { Image->Canvas->MoveTo(p, 0); Image->Canvas->LineTo(p, Image->Height); } for (p=0; pHeight; p+=5*seSectionNumber->Value) { Image->Canvas->MoveTo(0, p); Image->Canvas->LineTo(Image->Width, p); } } } //--------------------------------------------------------------------------- // Private Function //--------------------------------------------------------------------- TGrid __fastcall TGridForm::GetGap() { TGrid g; g.Unit = rgUnit->ItemIndex; g.X = rceGapX->Value; g.Y = rceGapY->Value; return g; } //--------------------------------------------------------------------- TColor __fastcall TGridForm::GetGridColor() { return shGridColor->Brush->Color; } //--------------------------------------------------------------------- int __fastcall TGridForm::GetLinesPerSection() { return seSectionNumber->Value; } //--------------------------------------------------------------------- TColor __fastcall TGridForm::GetSectionColor() { return shSectionColor->Brush->Color; } //--------------------------------------------------------------------- void __fastcall TGridForm::SetGap(TGrid Value) { rgUnit->ItemIndex = Value.Unit; rceGapX->Value = Value.X; rceGapY->Value = Value.Y; } //--------------------------------------------------------------------------- void __fastcall TGridForm::SetGridColor(TColor Value) { if (Value!=shGridColor->Brush->Color) { shGridColor->Brush->Color = Value; } } //--------------------------------------------------------------------------- void __fastcall TGridForm::SetLinesPerSection(int Value) { if (Value!=seSectionNumber->Value) { seSectionNumber->Value = Value; } } //--------------------------------------------------------------------------- void __fastcall TGridForm::SetSectionColor(TColor Value) { if (Value!=shSectionColor->Brush->Color) { shSectionColor->Brush->Color = Value; } } //--------------------------------------------------------------------------- void __fastcall TGridForm::SetUnit(TUnit Value) { if (Value!=FUnit) { switch (Value) { case uDot: rgUnit->ItemIndex = 0; break; case uInch: rgUnit->ItemIndex = 1; break; case uCm: rgUnit->ItemIndex = 2; break; } } } //---------------------------------------------------------------------------