//--------------------------------------------------------------------- #include #include #pragma hdrstop #include "Grid_F.h" //--------------------------------------------------------------------- #include "Calc_F.h" // °è»ê±â ÄÄÆ÷³ÍÆ® Á¦°Å - by monkman (2008.06.17) //--------------------------------------------------------------------- #pragma package(smart_init) #pragma link "RzEdit" #pragma link "RzSpnEdt" #pragma link "RzBtnEdt" #pragma link "RzButton" #pragma link "RzPanel" #pragma link "RzRadGrp" #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] #define IDS_SECTIONLINE StringTable[6] #define IDS_SECTIONCOLOR StringTable[7] //--------------------------------------------------------------------- __fastcall TGridForm::TGridForm(TComponent* AOwner) : TForm(AOwner) { //============================================ 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; Label5->Caption = IDS_SECTIONLINE; Label6->Caption = IDS_SECTIONCOLOR; OKBtn->Caption = IDS_COMMON_BUTTONOK; CancelBtn->Caption = IDS_COMMON_BUTTONCANCEL; btnDefault->Caption = IDS_DEFAULT; //============================================ } //--------------------------------------------------------------------------- void __fastcall TGridForm::FormCreate(TObject *Sender) { TIniFile *IniFile = new TIniFile(AppDataItem+"\\status.ini"); if (IniFile) { int Count = IniFile->ReadInteger("Grid", "Catalog-Count", 0); for (int i=0; iItems->Add(IniFile->ReadString("Grid", "Catalog-"+String(i), "")); } delete IniFile; } FUnit = uDot; FBitmap = NULL; View(NULL); } //--------------------------------------------------------------------------- void __fastcall TGridForm::FormDestroy(TObject *Sender) { if (FBitmap) delete FBitmap; TIniFile *IniFile = new TIniFile(AppDataItem+"\\status.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-"+String(i), lbGrid->Items->Strings[i]); } else if (iDeleteKey("Grid", "Catalog-"+String(i)); } else break; i++; } delete IniFile; } } //--------------------------------------------------------------------- void __fastcall TGridForm::rgUnitClick(TObject *Sender) { double dGapX, dGapY; if (!(TryStrToFloat(rceGapX->Text, dGapX) && TryStrToFloat(rceGapY->Text, dGapY))) return; switch (FUnit) { case 1: // rceGapX->Text = FloatToStr(dGapX*FDotsPerInch); // rceGapY->Text = FloatToStr(dGapY*FDotsPerInch); dGapX = dGapX * FDotsPerInch; dGapY = dGapY * FDotsPerInch; break; case 2: // rceGapX->Text = FloatToStr(dGapX*(FDotsPerInch/2.54)); // rceGapY->Text = FloatToStr(dGapY*(FDotsPerInch/2.54)); dGapX = dGapX * FDotsPerInch / 2.54; dGapY = dGapY * FDotsPerInch / 2.54; break; } FUnit = TUnit(rgUnit->ItemIndex); //Assinging int to Tputils switch (FUnit) { case 0: rceGapX->Text = FloatToStr(dGapX); rceGapY->Text = FloatToStr(dGapY); break; case 1: rceGapX->Text = FloatToStr(dGapX/FDotsPerInch); rceGapY->Text = FloatToStr(dGapY/FDotsPerInch); break; case 2: rceGapX->Text = FloatToStr(dGapX/(FDotsPerInch/2.54)); rceGapY->Text = FloatToStr(dGapY/(FDotsPerInch/2.54)); break; } } //--------------------------------------------------------------------------- void __fastcall TGridForm::sbCatalogAddClick(TObject *Sender) { double dGapX, dGapY; if (TryStrToFloat(rceGapX->Text, dGapX) && TryStrToFloat(rceGapY->Text, dGapY)) { lbGrid->Items->Add(GridToStr(FUnit, dGapX, dGapY)); } } //--------------------------------------------------------------------------- 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->Text = Grid.X; rceGapY->Text = 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) { String a; shGridColor->Brush->Color = clBlack; seSectionNumber->Value = 0; shSectionColor->Brush->Color = clBlack; TIniFile *IniFile = new TIniFile(AppDataItem+"\\status.ini"); if (IniFile) { rgUnit->ItemIndex = IniFile->ReadInteger("Grid", "Unit", 0); rceGapX->Text = IniFile->ReadFloat("Grid", "GapX", 1.0); rceGapY->Text = IniFile->ReadFloat("Grid", "GapY", 1.0); lbGrid->Items->Add(GridToStr(uDot, 1, 1)); //±âÁ¸¿¡´Â ¾Æ·¡¿Í °°ÀÌ ÀÔ·ÂÇß´ø ¸ðµç °ªÀÌ Ãß°¡ µÇ¾úÁö¸¸ 1Dot¸¸ Ãß°¡. // int Count = IniFile->ReadInteger("Grid", "Catalog-Count", 0); // for (int i=0; iItems->Add(IniFile->ReadString("Grid", "Catalog-"+String(i), "")); // } shGridColor->Brush->Color = (TColor) IniFile->ReadInteger("Grid", "Color", clBlack); seSectionNumber->Value = IniFile->ReadInteger("Grid", "LinesPerSection", 0); shSectionColor->Brush->Color = (TColor) IniFile->ReadInteger("Grid", "SectionColor", clBlack); rgUnit->ItemIndex = 0; rceGapX->Text = 1.0; rceGapY->Text = 1.0; 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; double dGapX, dGapY; g.Unit = (TUnit) rgUnit->ItemIndex; if (TryStrToFloat(rceGapX->Text, dGapX) && TryStrToFloat(rceGapY->Text, dGapY)) { g.X = dGapX; g.Y = dGapY; } 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->Text = Value.X; rceGapY->Text = 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; } } } //--------------------------------------------------------------------------- void __fastcall TGridForm::CalcButtonClick(TObject *Sender) { // °è»ê±â ÄÄÆ÷³ÍÆ® Á¦°Å - by monkman (2008.06.17) TRzButtonEdit *rzbtneditCalc = NULL; rzbtneditCalc = dynamic_cast(Sender); if (rzbtneditCalc) { TCalcForm *CalcForm = new TCalcForm(this); CalcForm->InitForm(rzbtneditCalc); CalcForm->ShowModal(); delete CalcForm; CalcForm = NULL; } } //--------------------------------------------------------------------------- void __fastcall TGridForm::EditorSelectAll(TObject *Sender) { SetFocusAndSelectAll(Sender); } //--------------------------------------------------------------------------- void __fastcall TGridForm::shGridColorMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (GridColorDialog->Execute()) { shGridColor->Brush->Color = GridColorDialog->Color; View(NULL); } } //--------------------------------------------------------------------------- void __fastcall TGridForm::shSectionColorMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (GridColorDialog->Execute()) { shSectionColor->Brush->Color = GridColorDialog->Color; View(NULL); } } //---------------------------------------------------------------------------