//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Environment.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "CurrEdit" #pragma link "ToolEdit" #pragma link "TPSpin" #pragma resource "*.dfm" //--------------------------------------------------------------------- #define IDS_GRID StringTable[0] #define IDS_DPI StringTable[1] #define IDS_GRIDCOLOR StringTable[2] #define IDS_SECTIONLINE StringTable[3] #define IDS_SECTIONCOLOR StringTable[4] #define IDS_CATALOG StringTable[5] #define IDS_MAX_UNDO_COUNT StringTable[6] #define IDS_LIMIT StringTable[7] #define IDS_OPTION StringTable[9] TEnvironmentForm *EnvironmentForm; //--------------------------------------------------------------------------- __fastcall TEnvironmentForm::TEnvironmentForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TEnvironmentForm::FormCreate(TObject *Sender) { AnsiString as; TIniFile *IniFile = new TIniFile(AppDataItem+"\\Environment.ini"); if (IniFile) { seDPI->Value = IniFile->ReadInteger("CanvasInfor", "DPI", 160); rgUnit->ItemIndex = IniFile->ReadInteger("Grid", "Unit", 0); rceGapX->Value = IniFile->ReadFloat("Grid", "GapX", 1.0); rceGapY->Value = IniFile->ReadFloat("Grid", "GapY", 1.0); RadioGroup1->ItemIndex = IniFile->ReadInteger("MainImage", "Unit", 0); int i = 0; while (true) { as = IniFile->ReadString("Grid", "Catalog-"+i, ""); if (as.Length()>0) { lbGrid->Items->Add(as); i++; } else break; } 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; } FUnit = uDot; //============================================ StringTable.Create(DirectoryBin, Language, "Environment"); SetSmallFont(Font); rgUnit->Caption = IDS_COMMON_UNIT; TabSheet1->Caption = IDS_GRID; TabSheet2->Caption = IDS_OPTION; Label1->Caption = IDS_COMMON_HORIZONTAL; Label2->Caption = IDS_COMMON_VERTICAL; Label3->Caption = IDS_CATALOG; Label4->Caption = IDS_GRIDCOLOR; Label5->Caption = IDS_SECTIONLINE; Label6->Caption = IDS_SECTIONCOLOR; Label7->Caption = IDS_DPI; btnOK->Caption = IDS_COMMON_BUTTONOK; btnCancel->Caption = IDS_COMMON_BUTTONCANCEL; //============================================ View(NULL); } //--------------------------------------------------------------------------- void __fastcall TEnvironmentForm::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 TEnvironmentForm::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); } } } //--------------------------------------------------------------------------- void __fastcall TEnvironmentForm::sbCatalogAddClick(TObject *Sender) { char *unit[3] = { "Dot", "Inch", "Cm" }; lbGrid->Items->Add(Format("%s) %.6f x %.6f", OPENARRAY(TVarRec, (unit[(int)FUnit], rceGapX->Value, rceGapY->Value)))); } //--------------------------------------------------------------------------- void __fastcall TEnvironmentForm::sbCatalogDeleteClick(TObject *Sender) { lbGrid->Items->Delete(lbGrid->ItemIndex); } //--------------------------------------------------------------------------- void __fastcall TEnvironmentForm::lbGridDblClick(TObject *Sender) { char *Grid, *tok = ") ", *p; Grid = strdup(lbGrid->Items->Strings[lbGrid->ItemIndex].c_str()); p = strtok(Grid, tok); if (strcmp(p, "Cm")==0) rgUnit->ItemIndex = 2; else if (strcmp(p, "Inch")==0) rgUnit->ItemIndex = 1; else rgUnit->ItemIndex = 0; p = strtok(NULL, tok); rceGapX->Value = atof(p); strtok(NULL, tok); p = strtok(NULL, tok); rceGapY->Value = atof(p); free(Grid); } //--------------------------------------------------------------------------- void __fastcall TEnvironmentForm::sbGridColorClick(TObject *Sender) { if (GridColorDialog->Execute()) { shGridColor->Brush->Color = GridColorDialog->Color; View(NULL); } } //--------------------------------------------------------------------------- void __fastcall TEnvironmentForm::sbSectionColorClick(TObject *Sender) { if (GridColorDialog->Execute()) { shSectionColor->Brush->Color = GridColorDialog->Color; View(NULL); } } //--------------------------------------------------------------------------- void __fastcall TEnvironmentForm::btnOKClick(TObject *Sender) { TIniFile *IniFile = new TIniFile(AppDataItem+"\\Environment.ini"); if (IniFile) { IniFile->WriteInteger("CanvasInfor", "DPI", seDPI->Value); IniFile->EraseSection("Grid"); IniFile->WriteInteger("Grid", "Unit", rgUnit->ItemIndex); IniFile->WriteFloat("Grid", "GapX", rceGapX->Value); IniFile->WriteFloat("Grid", "GapY", rceGapY->Value); for (int i=0; iItems->Count; i++) { IniFile->WriteString("Grid", "Catalog-"+i, lbGrid->Items->Strings[i]); } IniFile->WriteInteger("Grid", "Color", shGridColor->Brush->Color); IniFile->WriteInteger("Grid", "LinesPerSection", seSectionNumber->Value); IniFile->WriteInteger("Grid", "SectionColor", shSectionColor->Brush->Color); IniFile->WriteInteger("MainImage", "Unit", RadioGroup1->ItemIndex); delete IniFile; } } //---------------------------------------------------------------------------