//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Motivelib_F.h" #include "MainImage.h" #include "Main.h" #include "MainMenu.h" #include "FullView.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_MOTIVE StringTable[0] #define IDS_NUMBER StringTable[1] #define IDS_READ StringTable[2] #define IDS_EXIT StringTable[3] #define IDS_DELETE StringTable[4] TMotiveLibForm *MotiveLibForm; //--------------------------------------------------------------------------- __fastcall TMotiveLibForm::TMotiveLibForm(TComponent* Owner) : TForm(Owner) { StringTable.Create(DirectoryItem, Language, "MotiveLib"); SetSmallFont(Font); Caption = IDS_MOTIVE; Label1->Caption = IDS_NUMBER; Button1->Caption = IDS_READ; Button2->Caption = IDS_EXIT; MotiveDelete->Caption = IDS_DELETE; } //--------------------------------------------------------------------------- void __fastcall TMotiveLibForm::Button1Click(TObject *Sender) { // image Àбâ int n; AnsiString MotiveFileName; // ºÒ·¯¿Ã ¸ðƼºê ÆÄÀÏ À̸§ TSuper TempSuper; if (!MotiveListView->Selected) return; n = MotiveListView->Selected->Index; MotiveFileName = n + 1; MotiveFileName = DirectoryItem + "\\" + MotiveFileName + ".tex"; if (MainMenuForm->Item == T_COMBO || MainMenuForm->Item == T_JAQ || MainMenuForm->Item == T_STYLE || MainMenuForm->Item == T_AFTER ) MainMenuForm->ExitForm(1); // ÀÚÄ«µå³ª »ö4Àü°³¿¡¼­´Â âÀ» ´Ý¾ÆÁØ´Ù TempSuper = FullViewForm->Super; FullViewForm->Super = sNormal; // Merge¹æ½ÄÀ» ÀϹÝÇüÀ¸·Î Á¶Àý MainImageForm->InitMerge(MotiveFileName, gffTEX); // Merge FullViewForm->Super = TempSuper; } //--------------------------------------------------------------------------- void __fastcall TMotiveLibForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { switch (Key){ case 13: Button1Click(this); break; case 27: MainForm->MotiveLoadClick(this); break; case 46: MotiveDeleteClick(this); break; } if((Key == 65 || Key == 83 )) MainImageForm->iMainImageKeyDown(Key); //È®´ëÃà¼Ò ´ÜÃàŰ·Î } //--------------------------------------------------------------------------- void __fastcall TMotiveLibForm::FadeOut() { for (int i = 1000; i >0 ; i--) { MotiveLibForm->Height *= i/1000; MotiveLibForm->Width *= i/1000; } } //--------------------------------------------------------------------------- void __fastcall TMotiveLibForm::FormActivate(TObject *Sender) { // UpdateItems(); return; } //--------------------------------------------------------------------------- void __fastcall TMotiveLibForm::UpdateItems() { MotiveListView->Items->Clear(); MotiveImageList->Clear(); TFileInfor *FileInfo = NULL; TListItem *pItem=NULL; int imgindex = 0; AnsiString FileName; TTexVersion *ver = NULL; HANDLE hFile = INVALID_HANDLE_VALUE; TPException ec = EC_NONE; int COUNT = 0; AnsiString s = IDS_NUMBER; TPalette *palette = NULL; TEXPIAFILEHEADER tpfh; DWORD dwRead; if ((FileInfo = new TFileInfor)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((FileInfo->Bitmap = new Graphics::TBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } for (int i = 1 ; i <= 10 ; i++) { FileName = i; FileName = DirectoryItem + "\\" + FileName + ".tex"; if ((hFile = CreateFile(FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) goto next; ver = new TTexVersion; if (!LoadFromTexpiaTag(hFile, FileInfo, ver)) goto next; MotiveImageList->Add(FileInfo->Bitmap, NULL); pItem = MotiveListView->Items->Add(); // TListItem *cc=(TListItem *)MotiveListView->Items->Item[0]; Âü°íÇÒ°Í. if (SetFilePointer(hFile, 0, NULL, FILE_BEGIN)== 0xFFFFFFFF) goto fail; if ((palette = new TPalette)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!ReadFile(hFile, &tpfh, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; goto fail; } if (!ReadFile(hFile, &palette->UseColor, sizeof(Word), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; goto fail; } int ColorCnt = palette->UseColor-1; AnsiString wid = tpfh.CanvasInfor.Width; AnsiString hei = tpfh.CanvasInfor.Height; if(MainImageForm){ switch (MainImageForm->CurrentUnit) { case uDot : wid = wid; hei = hei; break; case uInch : wid = Format("%.2f", OPENARRAY(TVarRec, ((double)StrToInt(wid) / MainImageForm->CanvasInfor.DotsPerInch))); hei = Format("%.2f", OPENARRAY(TVarRec, ((double)StrToInt(hei) / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : wid = Format("%.2f", OPENARRAY(TVarRec, ((double)StrToInt(wid) / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); hei = Format("%.2f", OPENARRAY(TVarRec, ((double)StrToInt(hei) / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); break; } } if (tpfh.BitsPerPixel==8){ pItem->Caption = wid + "X" + hei + " (" + ColorCnt + ")"; }else { pItem->Caption = wid + "X" + hei + " (F)"; } pItem->ImageIndex = imgindex; imgindex++; COUNT ++; CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE; if (ver) { delete ver; ver = NULL; } } Label1->Caption = s + IntToStr(COUNT); if (FileInfo) delete FileInfo; return; fail: EXCEPTION_MESSAGE_OK(ec); next: Label1->Caption = s + IntToStr(COUNT); if (ver) { delete ver; ver = NULL; } if (FileInfo) delete FileInfo; return; } //--------------------------------------------------------------------------- void __fastcall TMotiveLibForm::FormClose(TObject *Sender, TCloseAction &Action) { // MainForm->Motive1->Checked = false; Visible = false; if (FOnUpdateMenu) FOnUpdateMenu(Sender); } //--------------------------------------------------------------------------- void __fastcall TMotiveLibForm::Button2Click(TObject *Sender) { MainForm->MotiveLoadClick(this); } //--------------------------------------------------------------------------- void __fastcall TMotiveLibForm::FormKeyPress(TObject *Sender, char &Key) { switch (Key){ case 109: // Ctrl+M ¸ðƼºê Save MainForm->MotiveSaveClick(this); break; case 23: // Ctrl+W ÀÛ¾÷±¸¿ª ¼¼À̺ê if (MainImageForm->WorkArea && MainImageForm->WorkArea->Mask) MainForm->SaveClick(this); break; } } //--------------------------------------------------------------------------- void __fastcall TMotiveLibForm::FormCreate(TObject *Sender) { UpdateItems(); } //--------------------------------------------------------------------------- void __fastcall TMotiveLibForm::MotiveDeleteClick(TObject *Sender) { int n; if (!MotiveListView->Selected) return; n = MotiveListView->Selected->Index; AnsiString MotiveFileName , OldName , NewName; MotiveFileName = n + 1; MotiveFileName = DirectoryItem + "\\" + MotiveFileName + ".tex"; DeleteFile(MotiveFileName.c_str()); for(int i = n+1 ; i < 10 ; i++) { OldName = i+1; NewName = i; OldName += ".tex"; NewName += ".tex"; RenameFile(DirectoryItem + "\\" + OldName , DirectoryItem + "\\" + NewName); } UpdateItems(); } //--------------------------------------------------------------------------- void __fastcall TMotiveLibForm::MotiveSave() { // ¸ðƼºêµéÀ» ÀúÀåÇÏ´Â ÇÔ¼ö if(!MainImageForm->WorkArea->Mask)return; AnsiString DirName = DirectoryItem; AnsiString FileName = "1"; AnsiString OldName , NewName; int ExtIndex = 1 , cm = 2; // Tex ÆÄÀÏ Çü½Ä, ¾ÐÃà »ç¿ë DeleteFile (DirectoryItem + "\\" + "10.tex"); for(int i = 9 ; i > 0 ; i--) { OldName = i; NewName = i + 1; OldName += ".tex"; NewName += ".tex"; DeleteFile(DirectoryItem + "\\" + NewName); RenameFile(DirectoryItem + "\\" + OldName , DirectoryItem + "\\" + NewName); DeleteFile(DirectoryItem + "\\" + OldName); } MainForm->MoSave = true; MainImageForm->SaveToFile (DirName , FileName + ".tex" , ExtIndex , cm); MainForm->MoSave = false; UpdateItems(); } //--------------------------------------------------------------------------- void __fastcall TMotiveLibForm::MDeleteAll(TObject *Sender) { AnsiString MotiveFileName , OldName , NewName; for(int n = 9 ; n > -1 ; n--) { MotiveFileName = n + 1; MotiveFileName = DirectoryItem + "\\" + MotiveFileName + ".tex"; if(FileExists(MotiveFileName)) DeleteFile(MotiveFileName.c_str()); } UpdateItems(); } //---------------------------------------------------------------------------- void __fastcall TMotiveLibForm::FormShow(TObject *Sender) { Width = 200; Height = 731; UpdateItems(); } //---------------------------------------------------------------------------