//--------------------------------------------------------------------------- #include #pragma hdrstop #include "VecMotiveList_F.h" #include "Vector_F.h" #include "MainImage.h" #include "Define.h" #include "LogData.h" //--------------------------------------------------------------------------- #define IDS_Caption StringTable[0] #define IDS_sbInsert StringTable[1] #define IDS_sbDelete StringTable[2] #define IDS_sbSave StringTable[3] #define IDS_sbLoad StringTable[4] #define IDS_Deleteall1 StringTable[5] #define IDS_Tocanvas1 StringTable[6] #define IDS_Message1 StringTable[7] //The Directory can not be created. #define IDS_Message2 StringTable[8] //Motive Object´Â µî·ÏÇÒ ¼ö ¾ø½À´Ï´Ù. #define IDS_Message3 StringTable[9]//TEXT´Â µî·ÏÇÒ ¼ö ¾ø½À´Ï´Ù. //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TVecMotiveForm *VecMotiveForm; //--------------------------------------------------------------------------- __fastcall TVecMotiveForm::TVecMotiveForm(TComponent* Owner) : TForm(Owner) { BEGIN_LOG(""); StringTable.Create(DirectoryItem, Language, "VecMotive"); SetSmallFont(Font); ImgWidth = 50; ImgHeight = 50; TVecMotiveList = new TList; //ItemImageList->Width = ImgWidth; //ItemImageList->Height = ImgHeight; DrawGrid->DoubleBuffered = true; Caption = IDS_Caption; sbInsert->Hint = IDS_sbInsert; sbDelete->Hint = IDS_sbDelete; sbSave->Hint = IDS_sbSave; sbLoad->Hint = IDS_sbLoad; delete1->Caption = IDS_sbDelete; Deleteall1->Caption = IDS_Deleteall1; Tocanvas1->Caption = IDS_Tocanvas1; END_LOG; } //--------------------------------------------------------------------------- __fastcall TVecMotiveForm::~TVecMotiveForm() { BEGIN_LOG(""); DeleteVecMotiveList(); if (TVecMotiveList) delete TVecMotiveList; //DeleteTagFromImgList(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::InitForm() { BEGIN_LOG(""); String fn; HANDLE hFile = INVALID_HANDLE_VALUE; /* Motive_Dir = AppData_Common_Dir + "YoungWoo\\TexPro" + TexProVersion + "\\"; if (!IsDirectoryExist(Motive_Dir.c_str())) { if (!CreateDirectory(Motive_Dir.c_str(), NULL)) { Application->MessageBox(IDS_Message1.c_str(), "Warning", MB_OK);; return; } } Motive_Dir = Motive_Dir + "Textile\\"; if (!IsDirectoryExist(Motive_Dir.c_str())) { if (!CreateDirectory(Motive_Dir.c_str(), NULL)) { Application->MessageBox(IDS_Message1.c_str(), "Warning", MB_OK);; return; } } Motive_Dir = Motive_Dir + "VecMotive\\"; if (!IsDirectoryExist(Motive_Dir.c_str())) { if (!CreateDirectory(Motive_Dir.c_str(), NULL)) { Application->MessageBox(IDS_Message1.c_str(), "Warning", MB_OK);; return; } } */ Motive_Dir = InstallPath + "\\Motive\\"; if (!IsDirectoryExist(Motive_Dir.c_str())) { if (!CreateDirectory(Motive_Dir.c_str(), NULL)) { Application->MessageBox(IDS_Message1.c_str(), L"Warning", MB_OK);; END_LOG; return; } } fn = Motive_Dir + "default.vml"; if (!FileExists(fn)) return; if ((hFile = CreateFile(fn.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) goto fail; if (!LoadFromFile(hFile)) { CloseHandle(hFile); DeleteFile(fn); } fail: if (hFile) CloseHandle(hFile); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::ExitForm() { BEGIN_LOG(""); HANDLE hFile = INVALID_HANDLE_VALUE; String fn = Motive_Dir + String("default.vml"); if (FileExists(fn)) DeleteFile(fn); if (!TVecMotiveList->Count) { END_LOG; return; } if ((hFile = CreateFile(fn.c_str(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) goto fail; if (!SaveToFile(hFile)) { CloseHandle(hFile); DeleteFile(fn); } else { CloseHandle(hFile); } END_LOG; return; fail: if (hFile) CloseHandle(hFile); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::DeleteVecMotiveList(int index) { BEGIN_LOG(""); TVecMotive *item; if (index >= 0) { item = (TVecMotive*)TVecMotiveList->Items[index]; TVecMotiveList->Remove(item); delete item; item = NULL; } else { //index = -1 ¸ðµÎ Áö¿î´Ù. while(TVecMotiveList->Count) { item = (TVecMotive*)TVecMotiveList->Last(); TVecMotiveList->Remove(item); delete item; item = NULL; } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::DeleteTagFromImgList(int index) { BEGIN_LOG(""); //Graphics::TBitmap *bitmap = NULL; if (index >= 0) { ItemImageList->Delete(index); } else { //index = -1 ¸ðµÎ Áö¿î´Ù. ItemImageList->Clear(); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::InsertImageToImgList(TVecMotive *item) { BEGIN_LOG(""); Graphics::TBitmap *bitmap = new Graphics::TBitmap; bitmap->PixelFormat = pf24bit; bitmap->Width = ImgWidth; bitmap->Height = ImgHeight; HDC dc = item->Bitmap->CreateDC(); BitBlt(bitmap->Canvas->Handle, 0, 0, ImgWidth, ImgHeight, dc, 0, 0, SRCCOPY); item->Bitmap->DeleteDC(dc); //ItemImageList->Add(bitmap, NULL); delete bitmap; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::sbInsertClick(TObject *Sender) { BEGIN_LOG(""); TList *DataList = VecDraw->NVector->DataList; TVecData *data = NULL; TVecMotive *stitchItem = new TVecMotive; bool bSelected = false; //Child¸¦ tempChildList¿¡ Ãß°¡. for (int i = 0; i < DataList->Count; i++) { data = (TVecData *) DataList->Items[i]; if (data->bSelected) { if (data->bMotive) { Application->MessageBox(IDS_Message2.c_str(), L"Warning", MB_OK); if (stitchItem) delete stitchItem; stitchItem = NULL; END_LOG; return; } else if (data->Kind == V_TEXTBOX || data->ParentTextBox){ // data->ParentTextBox Ãß°¡ - by monkan (2009.04.17) Application->MessageBox(IDS_Message3.c_str(),L"Warning", MB_OK); if (stitchItem) delete stitchItem; stitchItem = NULL; END_LOG; return; } else { stitchItem->AddVecData(data); bSelected = true; data->bSelected = false; } } //VecDraw->CheckSelected(); // <= ¿Ö ÀÖ¾î¾ßÇÏÁö?? - by monkman (2009.03.30) } if (!bSelected) { delete stitchItem; END_LOG; return; } stitchItem->MakeIconImage(); TVecMotiveList->Add(stitchItem); if (TVecMotiveList->Count > DrawGrid->ColCount*DrawGrid->RowCount) { DrawGrid->RowCount++; } //InsertImageToImgList(stitchItem); DrawGrid->Invalidate(); MainImageForm->iMainImage->Invalidate(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::sbDeleteClick(TObject *Sender) { BEGIN_LOG(""); int index = DrawGrid->Row * DrawGrid->ColCount + DrawGrid->Col; if (TVecMotiveList->Count <= index) { END_LOG; return; } DeleteVecMotiveList(index); //DeleteTagFromImgList(index); if (TVecMotiveList->Count < (DrawGrid->ColCount*(DrawGrid->RowCount-1)+1)) { // ¿¡·¯ ¼öÁ¤ - by monkman (2009.03.30) if (DrawGrid->RowCount > 6) { DrawGrid->RowCount--; } } DrawGrid->Invalidate(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::DrawGridDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State) { BEGIN_LOG(""); int index = 0; HDC dcSrc = NULL, dcDst = NULL; TVecMotive *stitchItem = NULL; index = ARow * DrawGrid->ColCount + ACol; // È¿À²ÀûÀÎ ÄÚµå·Î º¯°æ - by monkman (2009.03.31) if (TVecMotiveList->Count > index) { stitchItem = (TVecMotive *)TVecMotiveList->Items[index]; dcSrc = (HDC)stitchItem->Bitmap->CreateDC(); dcDst = (HDC)DrawGrid->Canvas->Handle; if (dcSrc) { if (dcDst) { SetStretchBltMode(dcDst, HALFTONE); StretchBlt(dcDst, Rect.left, Rect.top, Rect.Width(), Rect.Height() , dcSrc, 0, 0, stitchItem->Bitmap->Width, stitchItem->Bitmap->Height, SRCCOPY); } stitchItem->Bitmap->DeleteDC(dcSrc); } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::DrawGridDblClick(TObject *Sender) { BEGIN_LOG(""); int index; HDC dcSrc = NULL, dcDst = NULL; TVecMotive *stitchItem = NULL; ElementSet element; index = DrawGrid->Row * DrawGrid->ColCount + DrawGrid->Col; // ¿¡·¯ ¼öÁ¤ - by monkman (2009.03.30) if (TVecMotiveList->Count > index) { stitchItem = (TVecMotive*)TVecMotiveList->Items[index]; // ¹ÝÀü °Å¿ïÀÏ ¶§ E_PFILL, E_TEXTBOX, E_PTEXTBOX ¾È µÇµµ·Ï ¼öÁ¤ - by monkman (2009.05.06) if (VecDraw->NVector->bVectorReflectionMode == true) { element.Clear(); element = VecDraw->ElementsInList(stitchItem->MotiveList, false); if (element.Contains(E_PFILL) || element.Contains(E_TEXTBOX) || element.Contains(E_PTEXTBOX)) { // ¹ÝÀü °Å¿ï¿¡¼­ º¹»ç°¡ ¾È µÈ´Ù´Â ¸Þ½ÃÁö END_LOG; return; } } // ¾ÈÀüÇÑ ÄÚµå·Î º¯°æ - by monkman (2009.03.31) if (stitchItem) { dcSrc = stitchItem->Bitmap->CreateDC(); if (dcSrc) { VectorForm->MotiveImage->Canvas->Brush->Color = clWhite; VectorForm->MotiveImage->Canvas->FillRect(TRect(0,0,VectorForm->MotiveImage->Width, VectorForm->MotiveImage->Height)); dcDst = (HDC)VectorForm->MotiveImage->Canvas->Handle; if (dcDst) { SetStretchBltMode(dcDst, HALFTONE); StretchBlt(dcDst, 0, 0, VectorForm->MotiveImage->Width, VectorForm->MotiveImage->Height, dcSrc, 0, 0, 50, 50, SRCCOPY); } dcDst = (HDC)VectorForm->MotiveImage2->Canvas->Handle; if (dcDst) { SetStretchBltMode(dcDst, HALFTONE); StretchBlt(dcDst, 0, 0, VectorForm->MotiveImage2->Width, VectorForm->MotiveImage2->Height, dcSrc, 0, 0, 50, 50, SRCCOPY); } stitchItem->Bitmap->DeleteDC(dcSrc); } int count = VecDraw->SelectedObjectCount(); if (count) { VecDraw->ChangeMotiveChild(stitchItem); VecDraw->MotiveToChild(stitchItem); } else { VecDraw->MotiveToChild(stitchItem); } if (VectorForm->sbSpray->Down && VectorForm->sbSprayMotive->Down) { END_LOG; return; } VectorForm->sbSpray->Click(); VectorForm->sbSpray->Down = true; VectorForm->sbSprayMotive->Click(); VectorForm->sbSprayMotive->Down = true; } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::DrawGridClick(TObject *Sender) { BEGIN_LOG(""); TVecMotive *stitchItem = NULL; int index = DrawGrid->Row * DrawGrid->ColCount + DrawGrid->Col; int widthPx, heightPx; if (TVecMotiveList->Count > index) { stitchItem = (TVecMotive*)TVecMotiveList->Items[index]; widthPx = stitchItem->Second.x - stitchItem->First.x; heightPx = stitchItem->Second.y - stitchItem->First.y; StatusBar->Panels->Items[0]->Width = 200; StatusBar->Panels->Items[0]->Text = "Size: " + IntToStr(widthPx) + "px x " + IntToStr(heightPx) +"px"; } else { StatusBar->Panels->Items[0]->Text = ""; } END_LOG; } //--------------------------------------------------------------------------- bool __fastcall TVecMotiveForm::SaveToFile(HANDLE fh) { BEGIN_LOG(""); int version = 100, count; DWORD dwWrite; TVecMotive *item = NULL; bool bReturn = true; if (!WriteFile(fh, &version, sizeof(int), &dwWrite, NULL)) {bReturn=false; goto fail;} count = TVecMotiveList->Count; if (!WriteFile(fh, &count, sizeof(int), &dwWrite, NULL)) {bReturn=false; goto fail;} for (int i = 0; i < count; i++) { item = (TVecMotive*)TVecMotiveList->Items[i]; bReturn = item->SaveToFile(fh, version); if (!bReturn) goto fail; } fail: END_LOG; return bReturn; } //--------------------------------------------------------------------------- bool __fastcall TVecMotiveForm::LoadFromFile(HANDLE fh) { BEGIN_LOG(""); int version = 100, count; DWORD dwRead; TVecMotive *item = NULL; bool bReturn = true; if (!ReadFile(fh, &version, sizeof(int), &dwRead, NULL)) {bReturn=false; goto fail;} if (!ReadFile(fh, &count, sizeof(int), &dwRead, NULL)) {bReturn=false; goto fail;} for (int i = 0; i < count; i++) { item = new TVecMotive; bReturn = item->LoadFromFile(fh, version); if (bReturn) { //InsertImageToImgList(item); TVecMotiveList->Add(item); if (TVecMotiveList->Count > DrawGrid->ColCount*DrawGrid->RowCount) { DrawGrid->RowCount++; } } else { if (item) delete item; } item = NULL; } DrawGrid->Invalidate(); fail: END_LOG; return bReturn; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::sbSaveClick(TObject *Sender) { BEGIN_LOG(""); HANDLE hFile = INVALID_HANDLE_VALUE; String FileName; if (TVecMotiveList->Count > 0 && SaveDialog->Execute()) { FileName = SaveDialog->FileName; if (ExtractFileExt(FileName).LowerCase() != ".vml") FileName += ".vml"; if ((hFile = CreateFile(FileName.c_str(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) goto fail; if (!SaveToFile(hFile)) { CloseHandle(hFile); DeleteFile(FileName); } else { CloseHandle(hFile); } } END_LOG; return; fail: if (hFile) CloseHandle(hFile); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::sbLoadClick(TObject *Sender) { BEGIN_LOG(""); HANDLE hFile = INVALID_HANDLE_VALUE; String FileName; if (OpenDialog->Execute()) { FileName = OpenDialog->FileName; if (ExtractFileExt(FileName).LowerCase() != ".vml") FileName += ".vml"; if ((hFile = CreateFile(FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) goto fail; if (!LoadFromFile(hFile)) { CloseHandle(hFile); DeleteFile(FileName); } else { CloseHandle(hFile); } } END_LOG; return; fail: if (hFile) CloseHandle(hFile); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::DrawGridKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { BEGIN_LOG(""); switch (Key) { case VK_DELETE: //sbDeleteClick(this); break; case VK_RETURN: DrawGridDblClick(this); break; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::DrawGridMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { BEGIN_LOG(""); // Popup ¸Þ´º ¼±ÅÃÀ» À§ÇØ - by monkman (2009.04.29) TVecMotive *stitchItem = NULL; ElementSet element; TGridCoord grdCoord = DrawGrid->MouseCoord(X, Y); DrawGrid->Col = grdCoord.X; DrawGrid->Row = grdCoord.Y; int index = DrawGrid->Row * DrawGrid->ColCount + DrawGrid->Col; // ¹üÀ§ üũ - by monkman (2009.04.29) if (Button == mbRight) { if (index < TVecMotiveList->Count) { delete1->Enabled = true; Tocanvas1->Enabled = true; stitchItem = (TVecMotive*)TVecMotiveList->Items[index]; // ¹ÝÀü °Å¿ïÀÏ ¶§ E_PFILL, E_TEXTBOX, E_PTEXTBOX ¾È µÇµµ·Ï ¼öÁ¤ - by monkman (2009.05.07) if (VecDraw->NVector->bVectorReflectionMode == true) { element.Clear(); element = VecDraw->ElementsInList(stitchItem->MotiveList, false); if (element.Contains(E_PFILL) || element.Contains(E_TEXTBOX) || element.Contains(E_PTEXTBOX)) { Tocanvas1->Enabled = false; } } } else { delete1->Enabled = false; Tocanvas1->Enabled = false; } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::Save1Click(TObject *Sender) { BEGIN_LOG(""); sbSaveClick(this); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::Load1Click(TObject *Sender) { BEGIN_LOG(""); sbLoadClick(this); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::delete1Click(TObject *Sender) { BEGIN_LOG(""); sbDeleteClick(this); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::Deleteall1Click(TObject *Sender) { BEGIN_LOG(""); DeleteVecMotiveList(-1); DeleteTagFromImgList(-1); DrawGrid->Invalidate(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TVecMotiveForm::Tocanvas1Click(TObject *Sender) { BEGIN_LOG(""); TVecMotive *stitchItem = NULL; ElementSet element; int index = DrawGrid->Row * DrawGrid->ColCount + DrawGrid->Col; // ¹üÀ§ üũ - by monkman (2009.04.29) if (index < TVecMotiveList->Count) { stitchItem = (TVecMotive*)TVecMotiveList->Items[index]; // ¹ÝÀü °Å¿ïÀÏ ¶§ E_PFILL, E_TEXTBOX, E_PTEXTBOX ¾È µÇµµ·Ï ¼öÁ¤ - by monkman (2009.05.06) if (VecDraw->NVector->bVectorReflectionMode == true) { element.Clear(); element = VecDraw->ElementsInList(stitchItem->MotiveList, false); if (element.Contains(E_PFILL) || element.Contains(E_TEXTBOX) || element.Contains(E_PTEXTBOX)) { // ¹ÝÀü °Å¿ï¿¡¼­ º¹»ç°¡ ¾È µÈ´Ù´Â ¸Þ½ÃÁö END_LOG; return; } else { VecDraw->MotiveToCanvas(stitchItem); } } else { VecDraw->MotiveToCanvas(stitchItem); } } END_LOG; } //---------------------------------------------------------------------------