//--------------------------------------------------------------------------- #include #include #include #pragma hdrstop #include "MainMenu.h" #include "Style_F.h" #include "MainImage.h" #include "Palette.h" #include "Undo.h" #include "Vecdraw.h" #include "Dialog_F.h" #ifndef ACADEMY #include "UserColor_F.h" #endif //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_STYLEPATTERNCHART StringTable[0] #define IDS_COLUMNMENU StringTable[2] #define IDS_CELLMENU StringTable[3] #define IDS_INSERT StringTable[4] #define IDS_OVERWRITE StringTable[5] #define IDS_FIX StringTable[6] #define IDS_IMAGEDEL StringTable[7] #define IDS_ONLYCOLORSAVE StringTable[8] #define IDS_BITMAPSTYLE StringTable[1] #define IDS_VECTORSTYLE StringTable[9] #define IDS_SEARCH StringTable[10] #define IDS_ALLSEARCH StringTable[11] //--------------------------------------------------------------------------- TStyleForm *StyleForm; typedef struct tagImgdata { TUnionBitmap *sBitmap; RECT rect; // MainImage ¿¡¼­ÀÇ À§Ä¡... bool draw; } TImgdata; //--------------------------------------------------------------------------- __fastcall TStyleForm::TStyleForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; Data = NULL; Imgstore = NULL; //============================================================== StringTable.Create(DirectoryItem, Language, "Style"); SetSmallFont(Font); SetSmallFont(stTitle->Font); SetSmallFont(sbMainIns->Font); SetSmallFont(sbMainDel->Font); SetSmallFont(stPara->Font); SetSmallFont(sbHorIns->Font); SetSmallFont(sbHorDel->Font); SetSmallFont(stCell->Font); SetSmallFont(sbVerIns->Font); SetSmallFont(sbVerDel->Font); SetSmallFont(sbVerExchange->Font); SetSmallFont(sbExit->Font); SetSmallFont(StringGrid->Font); Caption = IDS_STYLEPATTERNCHART; sbMainIns->Caption = IDS_INSERT; sbMainDel->Caption = IDS_COMMON_DELETE; stPara->Caption = IDS_COLUMNMENU; sbHorIns->Caption = IDS_INSERT; sbHorDel->Caption = IDS_COMMON_DELETE; stCell->Caption = IDS_CELLMENU; sbVerIns->Caption = IDS_INSERT; sbVerDel->Caption = IDS_COMMON_DELETE; sbVerExchange->Caption = IDS_OVERWRITE; sbFix->Caption = IDS_FIX; sbDelete->Caption = IDS_IMAGEDEL; sbExit->Caption = IDS_COMMON_EXIT; Search->Caption = IDS_SEARCH; //============================================================== STR_VECTORSTYLE = IDS_VECTORSTYLE; STR_BITMAPSTYLE = IDS_BITMAPSTYLE; AllSearch->Caption = IDS_ALLSEARCH; isVector = VecDraw->bVectorStyle; // Styleform exitÇØµµ »ç¿ëÇÏ´ø ȯ°æ ³²°Ô.. if (isVector) stTitle->Caption = STR_VECTORSTYLE; else stTitle->Caption = STR_BITMAPSTYLE; } //--------------------------------------------------------------------------- void __fastcall TStyleForm::FormCreate(TObject *Sender) { // } //--------------------------------------------------------------------------- void __fastcall TStyleForm::FormClose(TObject *Sender, TCloseAction &Action) { VecDraw->ExitMerge(); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TStyleForm::FormShow(TObject *Sender) { if (MainImageForm->WorkArea->Mask && MainImageForm->iMainImage->uBitmap->BitsPerPixel==8) { sbVerIns->Enabled = true; sbVerExchange->Enabled = true; } else { sbVerIns->Enabled = false; sbVerExchange->Enabled = false; } } //--------------------------------------------------------------------------- void __fastcall TStyleForm::sbPreviousClick(TObject *Sender) { if (sbMainIns->Down) sbMainIns->Down = false; if(currentIndex == 0) return; DeleteOldData(currentIndex); currentIndex--; ChangeStyleData(); StringGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TStyleForm::sbNextClick(TObject *Sender) { if (sbMainIns->Down) sbMainIns->Down = false; if(currentIndex == Data->Count-1) return; DeleteOldData(currentIndex); currentIndex++; ChangeStyleData(); StringGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TStyleForm::sbInsClick(TObject *Sender) { TSpeedButton *sb = (TSpeedButton *)Sender; AnsiString fn, dn; TDirectoryInfor *di; ChangeButtonState(Sender); if (InputQuery("Input Box", "Name", fn)) { if (sb->Name == "sbMainIns") { dn = SearchFile->InitDirectory + "\\" + fn; //change dir.... CreateDirectory(dn.c_str(), NULL); DeleteOldData(currentIndex); UpdateData(); currentIndex = GetCurrentIndex(fn); ChangeStyleData(); sbMainIns->Down = false; }else if (sb->Name == "sbHorIns") { di = (TDirectoryInfor *) Data->Items[currentIndex]; //updatedata... dn = SearchFile->InitDirectory + "\\" + di->Name + "\\" + fn; CreateDirectory(dn.c_str(), NULL); DeleteOldData(currentIndex); UpdateData(); ChangeStyleData(); sbHorIns->Down = false; } } StringGrid->SetFocus(); StringGrid->Repaint(); // ChangeButtonState(Sender); } //--------------------------------------------------------------------------- void __fastcall TStyleForm::sbMainDelClick(TObject *Sender) { TDirectoryInfor *di; ChangeButtonState(Sender); // if (sbMainIns->Down) sbMainIns->Down = false; if (Data->Count > 0) { di = (TDirectoryInfor *) Data->Items[currentIndex]; if (MessageDlg(IDS_MESSAGE_DELETEFILE, mtWarning, TMsgDlgButtons()<InitDirectory + "\\" + di->Name); else return; ComboBox->Items->Delete(currentIndex); DeleteOldData(currentIndex); UpdateData(); if(currentIndex == Data->Count) currentIndex = currentIndex-1; ChangeStyleData(); StringGrid->Repaint(); } } //--------------------------------------------------------------------------- void __fastcall TStyleForm::ComboBoxChange(TObject *Sender) { if (sbMainIns->Down) sbMainIns->Down = false; DeleteOldData(currentIndex); currentIndex = ComboBox->ItemIndex; ChangeStyleData(); StringGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TStyleForm::StringGridClick(TObject *Sender) { TDirectoryInfor *firdi, *secdi; TFileInfor *fi; int FileNameLength, last1, last2, last3, last4; char FileIndex1, FileIndex2, FileIndex3, FileIndex4; int column = StringGrid->Col; int row = StringGrid->Row; AnsiString dn, fn, cmfn, cmfn2; char *s; if (Data->Count<=0) return; if (column) { if(sbHorDel->Down) { firdi = (TDirectoryInfor *) Data->Items[currentIndex]; if (firdi->pDirectoryList) { if (column <= firdi->pDirectoryList->Count) { secdi = (TDirectoryInfor *) firdi->pDirectoryList->Items[column-1]; dn = SearchFile->InitDirectory + "\\" + firdi->Name + "\\" + secdi->Name; DeleteFolder(dn); DeleteOldData(currentIndex); UpdateData(); ChangeStyleData(); StringGrid->Repaint(); } } sbHorDel->Down = false; } else if (sbVerIns->Down) { if(row) { BlackAndWhite(); if(BWBreak)return; firdi = (TDirectoryInfor *) Data->Items[currentIndex]; if (firdi->pDirectoryList) { if (column <= firdi->pDirectoryList->Count) { secdi = (TDirectoryInfor *) firdi->pDirectoryList->Items[column-1]; dn = SearchFile->InitDirectory + "\\" + firdi->Name + "\\" + secdi->Name; if (InputQuery("Input Box", "Name", fn)) { //=============================================================== FileNameLength = fn.Length(); if(FileNameLength > 4){ last1 = FileNameLength-3; last2 = FileNameLength-2; last3 = FileNameLength-1; last4 = FileNameLength; FileIndex1 = '.'; FileIndex2 = 't'; FileIndex3 = 'e'; FileIndex4 = 'x'; if((FileIndex1 == fn[last1])&&(FileIndex2 == fn[last2]) && (FileIndex3 == fn[last3])&&(FileIndex4 == fn[last4])){ s = "PASS"; }else s=NULL; }else s=NULL; //=============================================================== // s = AnsiStrScan(fn.c_str(), '.'); if (s==NULL) fn = fn + ".tex"; if(secdi->pFileList != NULL){ for (int i=0; ipFileList->Count; i++) { fi = (TFileInfor *) secdi->pFileList->Items[i]; cmfn = fi->Name; cmfn2 = fn; if (cmfn == cmfn2) { int btn = EXCEPTION_MESSAGE2_OKCANCEL(EC_FILE_EXIST_ALREADY, (IDS_MESSAGE_REALLYFILESAVE).c_str()); if (btn == mrOk) { fn = dn + "\\" + fn; SaveToFile(fn); goto next; } else { goto next; } } } } fn = dn + "\\" + fn; SaveToFile(fn); next: DeleteOldData(currentIndex); UpdateData(); ChangeStyleData(); StringGrid->Repaint(); } } } } sbVerIns->Down = false; } else if (sbVerDel->Down) { if(row) { firdi = (TDirectoryInfor *) Data->Items[currentIndex]; if (firdi->pDirectoryList) { if (column <= firdi->pDirectoryList->Count) { secdi = (TDirectoryInfor *) firdi->pDirectoryList->Items[column-1]; if (secdi->pFileList) { if (row <= secdi->pFileList->Count){ fi = (TFileInfor *) secdi->pFileList->Items[row-1]; dn = SearchFile->InitDirectory + "\\" + fi->Path + "\\" + fi->Name; DeleteFolder(dn); DeleteOldData(currentIndex); UpdateData(); ChangeStyleData(); StringGrid->Repaint(); } } } } } sbVerDel->Down = false; } else if (sbVerExchange->Down) { if(row) { BlackAndWhite(); if(BWBreak)return; firdi = (TDirectoryInfor *) Data->Items[currentIndex]; if (firdi->pDirectoryList) { if (column <= firdi->pDirectoryList->Count) { secdi = (TDirectoryInfor *) firdi->pDirectoryList->Items[column-1]; if (secdi->pFileList) { if (row <= secdi->pFileList->Count){ fi = (TFileInfor *) secdi->pFileList->Items[row-1]; dn = SearchFile->InitDirectory + "\\" + fi->Path + "\\" + fi->Name; dn = dn.LowerCase(); // ´ë¹®ÀÚÀΰæ¿ì ¾ÈµÇ¾ú´ø°æ¿ì¸¦ À§ÇØ SaveToFile(dn); DeleteOldData(currentIndex); UpdateData(); ChangeStyleData(); StringGrid->Repaint(); } } } } } sbVerExchange->Down = false; } } } //--------------------------------------------------------------------------- void __fastcall TStyleForm::StringGridDrawCell(TObject *Sender, int Col, int Row, TRect &Rect, TGridDrawState State) { int x, y; AnsiString str; TFileInfor *fi; TDirectoryInfor *firdi, *secdi; TRect r; HDC hDC = NULL; if (Data->Count>0) firdi = (TDirectoryInfor *) Data->Items[currentIndex]; else return; if (Col){ if (Row) { if (firdi->pDirectoryList) { if (Col <= firdi->pDirectoryList->Count) { secdi = (TDirectoryInfor *) firdi->pDirectoryList->Items[Col-1]; if (secdi->pFileList) { if (Row <= secdi->pFileList->Count) { fi = (TFileInfor *) secdi->pFileList->Items[Row-1]; // StringGrid->Canvas->Draw(Rect.Left+5, Rect.Top+5, fi->Bitmap); //================================================== TBitmap->TexpiaBitmap in TFileInfor for not system downing... if ((hDC = fi->tBitmap->CreateDC()) == NULL) goto fail; BitBlt(StringGrid->Canvas->Handle, Rect.Left+5, Rect.Top+5, fi->tBitmap->Width, fi->tBitmap->Height, hDC, 0, 0, NOTSRCCOPY); fi->tBitmap->DeleteDC(hDC); //================================================= r.Left = Rect.Left+5; r.Top = Rect.Top+110; r.Right = Rect.Left+85; r.Bottom = Rect.Top+130; StringGrid->Canvas->TextRect(r, Rect.Left+5, Rect.Top+115, fi->Name); } } } } } else { if (firdi->pDirectoryList) { if (Col <= firdi->pDirectoryList->Count) { secdi = (TDirectoryInfor *) firdi->pDirectoryList->Items[Col-1]; str = secdi->Name; x = ((Rect.Right - Rect.Left) - StringGrid->Canvas->TextWidth(str)) / 2; y = ((Rect.Bottom - Rect.Top) - StringGrid->Canvas->TextHeight(str)) / 2; // StringGrid->Canvas->Font->Color = clBlue; StringGrid->Canvas->TextRect(Rect, Rect.Left + x, Rect.Top + y, str); } } } } else { if (Row) { str = AnsiString(Row); x = ((Rect.Right - Rect.Left) - StringGrid->Canvas->TextWidth(str)) / 2; y = ((Rect.Bottom - Rect.Top) - StringGrid->Canvas->TextHeight(str)) / 2; StringGrid->Canvas->TextRect(Rect, Rect.Left + x, Rect.Top + y, str); } } return; fail: fi->tBitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TStyleForm::StringGridMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TDirectoryInfor *firdi, *secdi; TFileInfor *fi; TGridCoord grid = StringGrid->MouseCoord(X, Y); if (Button == mbRight) { if (Data->Count > 0) { firdi = (TDirectoryInfor *) Data->Items[currentIndex]; if (firdi->pDirectoryList) { if (grid.X && grid.X <= firdi->pDirectoryList->Count) { secdi = (TDirectoryInfor *) firdi->pDirectoryList->Items[grid.X-1]; if (secdi->pFileList) { if (grid.Y && grid.Y <= secdi->pFileList->Count) { fi = (TFileInfor*) secdi->pFileList->Items[grid.Y-1]; path = SearchFile->InitDirectory + "\\" + fi->Path + "\\" + fi->Name; loadOk = true; return; } } } } } } loadOk = false; } //--------------------------------------------------------------------------- void __fastcall TStyleForm::StringGridDblClick(TObject *Sender) { TDirectoryInfor *firdi, *secdi; TFileInfor *fi; if (Data->Count > 0) { firdi = (TDirectoryInfor *) Data->Items[currentIndex]; if (firdi->pDirectoryList) { if (StringGrid->Col && StringGrid->Col <= firdi->pDirectoryList->Count) { secdi = (TDirectoryInfor *) firdi->pDirectoryList->Items[StringGrid->Col-1]; if (secdi->pFileList) { if (StringGrid->Row && StringGrid->Row <= secdi->pFileList->Count) { fi = (TFileInfor*) secdi->pFileList->Items[StringGrid->Row-1]; path = SearchFile->InitDirectory + "\\" + fi->Path + "\\" + fi->Name; mirror = false; LoadToMainImage(); } } } } } } //--------------------------------------------------------------------------- void __fastcall TStyleForm::MirrorLeftClick(TObject *Sender) { if (loadOk) { mirror = false; LoadToMainImage(); } } //--------------------------------------------------------------------------- void __fastcall TStyleForm::MirrorRightClick(TObject *Sender) { if (loadOk) { mirror = true; LoadToMainImage(); } } //--------------------------------------------------------------------------- void __fastcall TStyleForm::sbFixClick(TObject *Sender) { TImgdata *id; while (Imgstore->Count>0) { id = (TImgdata *) Imgstore->Last(); Imgstore->Remove(id); delete id->sBitmap; delete id; } // MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, // MainImageForm->iMainImage->uBitmap->Height)); if(!isVector)MainImageForm->UndoSave(UK_ALL, Rect(0,0,0,0)); //by linuxjun method = 0; fix = true; sbDelete->Enabled = false; ::RepaintColor(); } //--------------------------------------------------------------------------- void __fastcall TStyleForm::sbExitClick(TObject *Sender) { ChangeButtonState(Sender); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- ///// Private Method ////////////////////////////////////////////////// //--------------------------------------------------------------------------- void __fastcall TStyleForm::DeleteOldData(int Index) { TDirectoryInfor *firdi, *secdi; TFileInfor *fi; int i, j; if (Index == -1) return; if (Data->Count > 0) { firdi = (TDirectoryInfor *) Data->Items[Index]; if (firdi->pDirectoryList) { for (i=0; ipDirectoryList->Count; i++) { secdi = (TDirectoryInfor *) firdi->pDirectoryList->Items[i]; if (secdi->pFileList) { for (j=0; jpFileList->Count; j++) { fi = (TFileInfor *) secdi->pFileList->Items[j]; // if(fi->Bitmap) { // delete fi->Bitmap; // fi->Bitmap = NULL; if (fi->tBitmap) { delete fi->tBitmap; fi->tBitmap = NULL; } } } } } } } //--------------------------------------------------------------------------- void __fastcall TStyleForm::UpdateData() { TDirectoryInfor *di, *tdi; int i, cnt; while(Data->Count>0) { di = (TDirectoryInfor *) Data->Last(); Data->Remove(di); } SearchFile->Create(this); di = (TDirectoryInfor *) SearchFile->RootDirectory(); if (di->pDirectoryList) { cnt = di->pDirectoryList->Count; ComboBox->Items->Clear(); // CB5¾Ö¼­´Â °°Àº À̸§ÀÇ AddObject¿¡ ´ëÇÏ¿© ¶Ç´Ù¸¥°Ô »ý±â¹Ç·Î ¸®¼ÂÀ» ¿äÇÑ´Ù// by jeegeo for (i=0; ipDirectoryList->Items[i]; ComboBox->Items->AddObject(tdi->Name, (TObject *)vsList); //Strings[i] = tdi->Name; Data->Add(tdi); } } } //--------------------------------------------------------------------------- void __fastcall TStyleForm::ChangeStyleData() { TDirectoryInfor *firdi, *secdi; TFileInfor *fi = NULL; HANDLE hFile = INVALID_HANDLE_VALUE; // int FH, i, j, x, y; int i, j, x, y; TTexVersion ver; RGBQUAD rgb[2]; Byte *sl; HDC hDC = NULL; Byte *tb; int ec = EC_NONE; TCanvas *Canvas = NULL; if (currentIndex == -1) return; if (Data->Count > 0) { firdi = (TDirectoryInfor *) Data->Items[currentIndex]; ComboBox->Text = firdi->Name; if (firdi->pDirectoryList) { for (i=0; ipDirectoryList->Count; i++) { secdi = (TDirectoryInfor *) firdi->pDirectoryList->Items[i]; if (secdi->pFileList) { for (j=0; jpFileList->Count; j++) { fi = (TFileInfor *) secdi->pFileList->Items[j]; // fi->Bitmap = new Graphics::TBitmap; // if (!fi->Bitmap) goto fail; if ((fi->tBitmap = new TTexpiaBitmap) == NULL) {ec = EC_MEMORY_LACK; goto fail;} // if ((FH = FileOpen(SearchFile->InitDirectory + "\\" + fi->Path + "\\" + fi->Name, // fmOpenRead))==-1) goto fail; if ((hFile = CreateFile((SearchFile->InitDirectory + "\\" + fi->Path + "\\" + fi->Name).c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { goto fail; } // if (!LoadFromTexpiaTag(hFile, fi, &ver)) goto fail; if (!LoadFromTexpiaStyleTag(hFile, fi, &ver)) goto fail; if (ver.Texpia =='P' && ver.Method =='T' && ver.Number >= 210) { rgb[0].rgbRed = 255; rgb[0].rgbGreen = 255; rgb[0].rgbBlue = 255; rgb[1].rgbRed = 0; rgb[1].rgbGreen = 0; rgb[1].rgbBlue = 0; // SetDIBColorTable(fi->Bitmap->Canvas->Handle, 0, 2, rgb); // for (y = 0; y < 100; y++) { // sl = (Byte *)fi->Bitmap->ScanLine[y]; // for (x = 0; x< 80; x++) sl[x] = sl[x] - 1; // } if ((hDC = fi->tBitmap->CreateDC()) == NULL) {ec = EC_MEMORY_LACK; goto fail;} SetDIBColorTable(hDC, 0, 2, rgb); fi->tBitmap->DeleteDC(hDC); if ((fi->tBitmap->StartScanLine()) == false) {ec = EC_MEMORY_LACK; goto fail;} for (y = 0; y < fi->tBitmap->Height; y++) { tb = fi->tBitmap->GetScanLine(y); for (x = 0; x< fi->tBitmap->Width; x++) { tb[x] = tb[x]-1; } fi->tBitmap->PutScanLine(y); } fi->tBitmap->StopScanLine(); } // FileClose(FH); CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE; } } } } } return; fail : if(fi->tBitmap)fi->tBitmap = NULL; if (hFile!=INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) EXCEPTION_MESSAGE_OK(EC_FILE_NOT_OPEN); else EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- int __fastcall TStyleForm::GetCurrentIndex(AnsiString str) { TDirectoryInfor *tdi; int cnt = Data->Count; if (cnt>0) { for (int i = 0; i < cnt; i++) { tdi = (TDirectoryInfor *) Data->Items[i]; if (tdi->Name == str) { return i; } } } return -1; } //--------------------------------------------------------------------------- void __fastcall TStyleForm::DeleteFolder(AnsiString FolderName) { SHFILEOPSTRUCT shfile; char *ucFrom = NULL; memset(&shfile, 0, sizeof(SHFILEOPSTRUCT)); shfile.hwnd = Handle; shfile.wFunc = FO_DELETE; if ((ucFrom = (char *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, FolderName.Length()+2)) == NULL) goto fail; strcpy(ucFrom, FolderName.c_str()); shfile.pFrom = ucFrom; shfile.fFlags = FOF_ALLOWUNDO ; SHFileOperation(&shfile); HeapFree(GetProcessHeap(), 0, ucFrom); return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TStyleForm::SaveToFile(AnsiString fn) { TEXPIAFILEHEADER tpfh; TRect src; RGBQUAD rgb[256]; TTexpiaBitmap *tag = NULL; int ec = EC_NONE; HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwWrite; HDC dcTemp=NULL; TColorData *ColorMap; ColorMap = PaletteForm->DIB256Palette->Palette->ColorData[1]; BackupR = ColorMap->RGB.rgbRed; BackupG = ColorMap->RGB.rgbGreen; BackupB = ColorMap->RGB.rgbBlue; if ((hFile = CreateFile(fn.c_str(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_CREATE; goto fail; } tpfh.Version = TexVersion('P', 'T', 300); // 8.0ºÎÅÍ 300À¸·Î // tpfh.Version = TexVersion('P', 'T', 222); tpfh.CanvasInfor = MainImageForm->CanvasInfor; tpfh.BitsPerPixel = 8; tpfh.Compress = cmZLib; src = MainImageForm->WorkArea->Range; tpfh.CanvasInfor.DotsPerInch = tpfh.CanvasInfor.DotsPerInch; tpfh.CanvasInfor.SetSize(cstFree, src.Right-src.Left, src.Bottom-src.Top); PaletteForm->DIB256Palette->SetNormal(1,255, 255, 255); MainImageForm->Palette->ToRGBQUAD(rgb, 256); MainImageForm->iMainImage->ChangeRGBColors(rgb); if ((tag = new TTexpiaBitmap) == NULL) {ec = EC_MEMORY_LACK; goto fail;} MakeTexpiaTag(tag, MainImageForm->iMainImage->uBitmap, src, 1); ////////////// if (isVector) { if ((dcTemp = tag->CreateDC())==NULL) goto fail; VecDraw->TagDraw(dcTemp, src, 3); tag->DeleteDC(dcTemp); dcTemp = NULL; } //////// Vector Tag By GreenFIsh if (MainImageForm->WorkArea && MainImageForm->WorkArea->Mask) { if (!SaveToTexpiaFile(hFile, MainImageForm->Palette, tpfh, tag, MainImageForm->iMainImage->uBitmap, &MainImageForm->WorkArea->Range)) { ec = EC_FILE_NOT_WRITE; goto fail; } } else { if (!SaveToTexpiaFile(hFile, MainImageForm->Palette, tpfh, tag, MainImageForm->iMainImage->uBitmap)) { ec = EC_FILE_NOT_WRITE; goto fail; } } delete tag; /* À̰÷¿¡ Vector Save°¡ µé¾î°£´Ù */ if (isVector) VecDraw->SaveToFile(hFile, 3); //========================= CloseHandle(hFile); PaletteForm->DIB256Palette->SetNormal(1,BackupR, BackupG, BackupB); ::RepaintColor(); return; fail: MainImageForm->iMainImage->uBitmap->StopScanLine(); if (tag) { tag->StopScanLine(); delete tag; } if (hFile == INVALID_HANDLE_VALUE) CloseHandle(hFile); ::RepaintColor(); EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TStyleForm::LoadToMainImage() { TEXPIAFILEHEADER tpfh; int x, y; TImgdata *id = NULL; RGBQUAD rgb[256]; Byte *sl; TPalette *spalette = NULL; TPItemImage *Image = MainImageForm->iMainImage; int ec = EC_NONE; HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwRead; bool vector; if ((id = new TImgdata)==NULL) { ec = EC_MEMORY_LACK; goto fail; } id->sBitmap = NULL; if ((id->sBitmap = new TUnionBitmap) == NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((spalette = new TPalette)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((hFile = CreateFile(path.c_str(),GENERIC_READ, 0, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_MEMORY_LACK; goto fail; } if ((ec = LoadFromTexpiaFile(hFile, spalette, tpfh, id->sBitmap))!=EC_NONE) goto fail; #ifndef ACADEMY UserColorLibForm->ThisFileHasUserColor(spalette); #endif //==============Vector Merge if (tpfh.Version.Number >= 240) { if (!ReadFile(hFile, &vector, sizeof(bool), &dwRead, NULL)) goto fail; if (vector) VecDraw->InitMerge(hFile, id->sBitmap->Width, mirror); // By GreenFish Vector File Merge } //============== CloseHandle(hFile); MainImageForm->Palette->ToRGBQUAD(rgb, 256); id->sBitmap->PutColors(0, 256, rgb); if (mirror) { // if (L_ReverseBitmap(id->sBitmap->Handle) != SUCCESS) goto fail; // if (id->sBitmap->L_ReverseBitmap()) != SUCCESS) goto fail; id->sBitmap->ReverseBitmap_8Bit(); } if (!(Image->SubBitmap->Create(id->sBitmap->Width, id->sBitmap->Height, 8, rgb))) { ec = EC_MEMORY_LACK; goto fail; } if (!(Image->SubMask->Create(id->sBitmap->Width, id->sBitmap->Height, 8, rgb))) { ec = EC_MEMORY_LACK; goto fail; } if (!(id->sBitmap->StartScanLine())) {ec = EC_MEMORY_LACK; goto fail;} for (y = 0; y < id->sBitmap->Height; y++) { sl = id->sBitmap->GetScanLine(y); for (x = 0; x < id->sBitmap->Width; x++) { if(sl[x] < 2) { sl[x] = 255; } else { sl[x] = 0; } } id->sBitmap->PutScanLine(y); } id->sBitmap->StopScanLine(); Image->SubMask->Copy(id->sBitmap, SRCCOPY); MainImageForm->iMainImage->SubVisible = false; MainImageForm->Center.x = MainImageForm->iMainImage->SubBitmap->Width / 2; MainImageForm->Center.y = MainImageForm->iMainImage->SubBitmap->Height / 2; id->draw = false; Imgstore->Add(id); delete spalette; ImgIndex = Imgstore->Count-1; if(method == 1)SeparateImage(); else method = 1; return; fail: if (hFile == INVALID_HANDLE_VALUE) CloseHandle(hFile); if (spalette) delete spalette; if (id) { if (id->sBitmap) delete id->sBitmap; delete id; } EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TStyleForm::MergeBitmap() { TImgdata *id; POINT p; TPItemImage *Image = MainImageForm->iMainImage; RECT r; if (Imgstore->Count>0) { p.x = Image->SubRange.left; p.y = Image->SubRange.top; id = (TImgdata *) Imgstore->Items[ImgIndex]; Image->SubBitmap->CopyFromRect(Image->uBitmap, p.x, p.y, SRCCOPY); Image->SubBitmap->Copy(id->sBitmap, SRCAND); Image->SubVisible = true; r.left = paintrect.left < Image->SubRange.left ? paintrect.left : Image->SubRange.left; r.top = paintrect.top < Image->SubRange.top ? paintrect.top : Image->SubRange.top; r.right = paintrect.right > Image->SubRange.right ? paintrect.right : Image->SubRange.right; r.bottom = paintrect.bottom > Image->SubRange.bottom ? paintrect.bottom : Image->SubRange.bottom; paintrect = Image->SubRange; Image->RectPaint(r); } } //--------------------------------------------------------------------------- void __fastcall TStyleForm::SeparateImage() { ///* //BeConverted by linuxjun Don't Forget!! Undo_Method THistoryData *ud; TImgdata *id; TCursor cur = Screen->Cursor; Byte *sl, *dl, *ll; RGBQUAD rgb[256]; int ec, i, x, y; TPItemImage *Image = MainImageForm->iMainImage; Screen->Cursor = crHourGlass; if ((ud = MainImageForm->Undo->GetLast())==NULL) { ec = EC_UNDO_NONE; goto fail; } // Image->uBitmap->Copy(ud->uBitmap, SRCCOPY); // convert by celberus Image->uBitmap->PartialUndo->LoadUndoWithOutIndexChange(); //converted by linuxjun // if (Image->LayerMask) Image->LayerMask->Copy(ud->LayerMask, SRCCOPY); //blocked by linuxjun For New Undo if (Image->LayerMask) Image->LayerMask->PartialUndo->LoadUndoWithOutIndexChange(); // ud->Complete(); for (i = 0; i < Imgstore->Count; i++) { if (ImgIndex != i) { id = (TImgdata *) Imgstore->Items[i]; if (id->draw) { if (!(Image->uBitmap->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } if (Image->LayerMask) { if (!(Image->LayerMask->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } if (!(id->sBitmap->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } for (y = 0; y < id->sBitmap->Height; y++) { dl = Image->uBitmap->GetScanLine(y + id->rect.top); ll = Image->LayerMask->GetScanLine(y + id->rect.top); sl = id->sBitmap->GetScanLine(y); if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { for (x = 0; x < id->sBitmap->Width; x++) { if (sl[x] == 0) { int j; if(PaletteForm->StyleUseColor) j = PaletteForm->DIB256Palette->UseColor-1; else j = PaletteForm->DIB256Palette->UseColor; dl[x + id->rect.left] = j + 1; ll[x + id->rect.left] = 0; // Layer Mask } } }else { // Full Color // TColor TempC = MainImageForm->Palette->ColorData[2]->Color; dl += id->rect.left*3; for (x = 0; x < id->sBitmap->Width; x++, dl+=3) { if (sl[x] == 0) { *dl = clBlack;//TempC & 0xFF ; *(dl+1) = clBlack;//(TempC>>8) & 0xFF; *(dl+2) = clBlack;//(TempC>>16) & 0xFF; ll[(id->rect.left+x) >> 3] &= ~(0x80 >> ((id->rect.left+x) & 7)); // Layer Mask // ll[x + id->rect.left] = 0; } } } Image->LayerMask->PutScanLine(y + id->rect.top); Image->uBitmap->PutScanLine(y + id->rect.top); } id->sBitmap->StopScanLine(); Image->LayerMask->StopScanLine(); } else { if (!(id->sBitmap->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } for (y = 0; y < id->sBitmap->Height; y++) { dl = Image->uBitmap->GetScanLine(y + id->rect.top); sl = id->sBitmap->GetScanLine(y); if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { for (x = 0; x < id->sBitmap->Width; x++) { if (sl[x] == 0) { int j; if(PaletteForm->StyleUseColor) j = PaletteForm->DIB256Palette->UseColor-1; else j = PaletteForm->DIB256Palette->UseColor; dl[x + id->rect.left] = j + 1; } } }else { // Full Color // TColor TempC = MainImageForm->Palette->ColorData[2]->Color; dl += id->rect.left*3; for (x = 0; x < id->sBitmap->Width; x++, dl+=3) { if (sl[x] == 0) { *dl = clBlack;//TempC & 0xFF ; *(dl+1) = clBlack;//(TempC>>8) & 0xFF; *(dl+2) = clBlack;//(TempC>>16) & 0xFF; } } } Image->uBitmap->PutScanLine(y + id->rect.top); } id->sBitmap->StopScanLine(); } Image->uBitmap->StopScanLine(); } } } id = (TImgdata *) Imgstore->Items[ImgIndex]; MainImageForm->Palette->ToRGBQUAD(rgb, 256); if (!(Image->SubBitmap->Create(id->sBitmap->Width, id->sBitmap->Height, 8, rgb))) { ec = EC_MEMORY_LACK; goto fail; } if (!(Image->SubMask->Create(id->sBitmap->Width, id->sBitmap->Height, 8, rgb))) { ec = EC_MEMORY_LACK; goto fail; } Image->SubMask->Copy(id->sBitmap, SRCCOPY); MainImageForm->Center.x = Image->SubBitmap->Width / 2; MainImageForm->Center.y = Image->SubBitmap->Height / 2; ::RepaintColor(); method = 1; Screen->Cursor = cur; return; fail: id->sBitmap->StopScanLine(); MainImageForm->iMainImage->uBitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(ec); Screen->Cursor = cur; /* //BeConverted by linuxjun Don't Forget!! Undo_Method TUndoData *ud; TImgdata *id; TCursor cur = Screen->Cursor; Byte *sl, *dl, *ll; RGBQUAD rgb[256]; int ec, i, x, y; TPItemImage *Image = MainImageForm->iMainImage; Screen->Cursor = crHourGlass; if ((ud = Undo->Last)==NULL) { ec = EC_UNDO_NONE; goto fail; } Image->uBitmap->Copy(ud->Bitmap, SRCCOPY); // convert by celberus if (Image->LayerMask) Image->LayerMask->Copy(ud->LayerMask, SRCCOPY); ud->Complete(); for (i = 0; i < Imgstore->Count; i++) { if (ImgIndex != i) { id = (TImgdata *) Imgstore->Items[i]; if (id->draw) { if (!(Image->uBitmap->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } if (Image->LayerMask) { if (!(Image->LayerMask->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } if (!(id->sBitmap->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } for (y = 0; y < id->sBitmap->Height; y++) { dl = Image->uBitmap->GetScanLine(y + id->rect.top); ll = Image->LayerMask->GetScanLine(y + id->rect.top); sl = id->sBitmap->GetScanLine(y); if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { for (x = 0; x < id->sBitmap->Width; x++) { if (sl[x] == 0) { int j; if(PaletteForm->StyleUseColor) j = PaletteForm->DIB256Palette->UseColor-1; else j = PaletteForm->DIB256Palette->UseColor; dl[x + id->rect.left] = j + 1; ll[x + id->rect.left] = 0; // Layer Mask } } }else { // Full Color // TColor TempC = MainImageForm->Palette->ColorData[2]->Color; dl += id->rect.left*3; for (x = 0; x < id->sBitmap->Width; x++, dl+=3) { if (sl[x] == 0) { *dl = clBlack;//TempC & 0xFF ; *(dl+1) = clBlack;//(TempC>>8) & 0xFF; *(dl+2) = clBlack;//(TempC>>16) & 0xFF; ll[(id->rect.left+x) >> 3] &= ~(0x80 >> ((id->rect.left+x) & 7)); // Layer Mask // ll[x + id->rect.left] = 0; } } } Image->LayerMask->PutScanLine(y + id->rect.top); Image->uBitmap->PutScanLine(y + id->rect.top); } id->sBitmap->StopScanLine(); Image->LayerMask->StopScanLine(); } else { if (!(id->sBitmap->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } for (y = 0; y < id->sBitmap->Height; y++) { dl = Image->uBitmap->GetScanLine(y + id->rect.top); sl = id->sBitmap->GetScanLine(y); if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { for (x = 0; x < id->sBitmap->Width; x++) { if (sl[x] == 0) { int j; if(PaletteForm->StyleUseColor) j = PaletteForm->DIB256Palette->UseColor-1; else j = PaletteForm->DIB256Palette->UseColor; dl[x + id->rect.left] = j + 1; } } }else { // Full Color // TColor TempC = MainImageForm->Palette->ColorData[2]->Color; dl += id->rect.left*3; for (x = 0; x < id->sBitmap->Width; x++, dl+=3) { if (sl[x] == 0) { *dl = clBlack;//TempC & 0xFF ; *(dl+1) = clBlack;//(TempC>>8) & 0xFF; *(dl+2) = clBlack;//(TempC>>16) & 0xFF; } } } Image->uBitmap->PutScanLine(y + id->rect.top); } id->sBitmap->StopScanLine(); } Image->uBitmap->StopScanLine(); } } } id = (TImgdata *) Imgstore->Items[ImgIndex]; MainImageForm->Palette->ToRGBQUAD(rgb, 256); if (!(Image->SubBitmap->Create(id->sBitmap->Width, id->sBitmap->Height, 8, rgb))) { ec = EC_MEMORY_LACK; goto fail; } if (!(Image->SubMask->Create(id->sBitmap->Width, id->sBitmap->Height, 8, rgb))) { ec = EC_MEMORY_LACK; goto fail; } Image->SubMask->Copy(id->sBitmap, SRCCOPY); MainImageForm->Center.x = Image->SubBitmap->Width / 2; MainImageForm->Center.y = Image->SubBitmap->Height / 2; ::RepaintColor(); method = 1; Screen->Cursor = cur; return; fail: id->sBitmap->StopScanLine(); MainImageForm->iMainImage->uBitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(ec); Screen->Cursor = cur; */ } //--------------------------------------------------------------------------- void __fastcall TStyleForm::DeleteImage() { ///* //BeConverted by linuxjun Don't Forget!! Undo_Method THistoryData *ud; TImgdata *id; Byte *sl, *dl, *ll; TCursor cur = Screen->Cursor; int i, x, y, ec = EC_NONE; Screen->Cursor = crHourGlass; id = (TImgdata *) Imgstore->Items[ImgIndex]; Imgstore->Remove(id); delete id->sBitmap; delete id; if (ImgIndex == Imgstore->Count) ImgIndex = ImgIndex - 1; if (Imgstore->Count == 0) { sbDelete->Enabled = false; fix = true; } if ((ud = MainImageForm->Undo->GetLast())==NULL) { ec = EC_UNDO_NONE; goto fail; } // MainImageForm->iMainImage->uBitmap->Copy(ud->uBitmap, SRCCOPY); MainImageForm->iMainImage->uBitmap->PartialUndo->LoadUndoWithOutIndexChange(); //converted by linuxjun if (MainImageForm->iMainImage->LayerMask) // MainImageForm->iMainImage->LayerMask->Copy(ud->LayerMask, SRCCOPY); MainImageForm->iMainImage->LayerMask->PartialUndo->LoadUndoWithOutIndexChange(); //by linuxjun // ud->Complete(); for (i = 0; i < Imgstore->Count; i++) { id = (TImgdata *) Imgstore->Items[i]; if (id->draw) { if (!(MainImageForm->iMainImage->uBitmap->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } if (MainImageForm->iMainImage->LayerMask) { if (!(MainImageForm->iMainImage->LayerMask->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } if (!(id->sBitmap->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } for (y = 0; y < id->sBitmap->Height; y++) { dl = MainImageForm->iMainImage->uBitmap->GetScanLine(y + id->rect.top); ll = MainImageForm->iMainImage->LayerMask->GetScanLine(y + id->rect.top); sl = id->sBitmap->GetScanLine(y); if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { for (x = 0; x < id->sBitmap->Width; x++) { if (sl[x] == 0) { dl[x + id->rect.left] = stycolor+1; // dl[x + id->rect.left] = 2; ll[x + id->rect.left] = 0; } } }else { // Full Color // TColor TempC = MainImageForm->Palette->ColorData[2]->Color; dl += id->rect.left*3; for (x = 0; x < id->sBitmap->Width; x++, dl+=3) { if (sl[x] == 0) { *dl = clBlack;//TempC & 0xFF ; *(dl+1) = clBlack;//(TempC>>8) & 0xFF; *(dl+2) = clBlack;//(TempC>>16) & 0xFF; ll[(id->rect.left+x) >> 3] &= ~(0x80 >> ((id->rect.left+x) & 7)); // Layer Mask // ll[x + id->rect.left] = 0; // Layer Mask } } } MainImageForm->iMainImage->LayerMask->PutScanLine(y + id->rect.top); MainImageForm->iMainImage->uBitmap->PutScanLine(y + id->rect.top); } id->sBitmap->StopScanLine(); MainImageForm->iMainImage->LayerMask->StopScanLine(); } else { if (!(id->sBitmap->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } for (y = 0; y < id->sBitmap->Height; y++) { dl = MainImageForm->iMainImage->uBitmap->GetScanLine(y + id->rect.top); sl = id->sBitmap->GetScanLine(y); if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { for (x = 0; x < id->sBitmap->Width; x++) { if (sl[x] == 0) { dl[x + id->rect.left] = stycolor+1; // dl[x + id->rect.left] = 2; } } }else { // Full Color // TColor TempC = MainImageForm->Palette->ColorData[2]->Color; dl += id->rect.left*3; for (x = 0; x < id->sBitmap->Width; x++, dl+=3) { if (sl[x] == 0) { *dl = clBlack;//TempC & 0xFF ; *(dl+1) = clBlack;//(TempC>>8) & 0xFF; *(dl+2) = clBlack;//(TempC>>16) & 0xFF; } } } MainImageForm->iMainImage->uBitmap->PutScanLine(y + id->rect.top); } id->sBitmap->StopScanLine(); } MainImageForm->iMainImage->uBitmap->StopScanLine(); } } ::RepaintColor(); sbDelete->Down = false; method = 2; Screen->Cursor = cur; return; fail: Screen->Cursor = cur; if (id->sBitmap) id->sBitmap->StopScanLine(); if (MainImageForm->iMainImage->LayerMask) MainImageForm->iMainImage->LayerMask->StopScanLine(); MainImageForm->iMainImage->uBitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(ec); /* //BeConverted by linuxjun Don't Forget!! Undo_Method TUndoData *ud; TImgdata *id; Byte *sl, *dl, *ll; TCursor cur = Screen->Cursor; int i, x, y, ec = EC_NONE; Screen->Cursor = crHourGlass; id = (TImgdata *) Imgstore->Items[ImgIndex]; Imgstore->Remove(id); delete id->sBitmap; delete id; if (ImgIndex == Imgstore->Count) ImgIndex = ImgIndex - 1; if (Imgstore->Count == 0) { sbDelete->Enabled = false; fix = true; } if ((ud = Undo->Last)==NULL) { ec = EC_UNDO_NONE; goto fail; } MainImageForm->iMainImage->uBitmap->Copy(ud->Bitmap, SRCCOPY); if (MainImageForm->iMainImage->LayerMask) MainImageForm->iMainImage->LayerMask->Copy(ud->LayerMask, SRCCOPY); ud->Complete(); for (i = 0; i < Imgstore->Count; i++) { id = (TImgdata *) Imgstore->Items[i]; if (id->draw) { if (!(MainImageForm->iMainImage->uBitmap->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } if (MainImageForm->iMainImage->LayerMask) { if (!(MainImageForm->iMainImage->LayerMask->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } if (!(id->sBitmap->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } for (y = 0; y < id->sBitmap->Height; y++) { dl = MainImageForm->iMainImage->uBitmap->GetScanLine(y + id->rect.top); ll = MainImageForm->iMainImage->LayerMask->GetScanLine(y + id->rect.top); sl = id->sBitmap->GetScanLine(y); if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { for (x = 0; x < id->sBitmap->Width; x++) { if (sl[x] == 0) { dl[x + id->rect.left] = stycolor+1; // dl[x + id->rect.left] = 2; ll[x + id->rect.left] = 0; } } }else { // Full Color // TColor TempC = MainImageForm->Palette->ColorData[2]->Color; dl += id->rect.left*3; for (x = 0; x < id->sBitmap->Width; x++, dl+=3) { if (sl[x] == 0) { *dl = clBlack;//TempC & 0xFF ; *(dl+1) = clBlack;//(TempC>>8) & 0xFF; *(dl+2) = clBlack;//(TempC>>16) & 0xFF; ll[(id->rect.left+x) >> 3] &= ~(0x80 >> ((id->rect.left+x) & 7)); // Layer Mask // ll[x + id->rect.left] = 0; // Layer Mask } } } MainImageForm->iMainImage->LayerMask->PutScanLine(y + id->rect.top); MainImageForm->iMainImage->uBitmap->PutScanLine(y + id->rect.top); } id->sBitmap->StopScanLine(); MainImageForm->iMainImage->LayerMask->StopScanLine(); } else { if (!(id->sBitmap->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } for (y = 0; y < id->sBitmap->Height; y++) { dl = MainImageForm->iMainImage->uBitmap->GetScanLine(y + id->rect.top); sl = id->sBitmap->GetScanLine(y); if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { for (x = 0; x < id->sBitmap->Width; x++) { if (sl[x] == 0) { dl[x + id->rect.left] = stycolor+1; // dl[x + id->rect.left] = 2; } } }else { // Full Color // TColor TempC = MainImageForm->Palette->ColorData[2]->Color; dl += id->rect.left*3; for (x = 0; x < id->sBitmap->Width; x++, dl+=3) { if (sl[x] == 0) { *dl = clBlack;//TempC & 0xFF ; *(dl+1) = clBlack;//(TempC>>8) & 0xFF; *(dl+2) = clBlack;//(TempC>>16) & 0xFF; } } } MainImageForm->iMainImage->uBitmap->PutScanLine(y + id->rect.top); } id->sBitmap->StopScanLine(); } MainImageForm->iMainImage->uBitmap->StopScanLine(); } } ::RepaintColor(); sbDelete->Down = false; method = 2; Screen->Cursor = cur; return; fail: Screen->Cursor = cur; if (id->sBitmap) id->sBitmap->StopScanLine(); if (MainImageForm->iMainImage->LayerMask) MainImageForm->iMainImage->LayerMask->StopScanLine(); MainImageForm->iMainImage->uBitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(ec); */ } //--------------------------------------------------------------------------- void __fastcall TStyleForm::ChangeButtonState(TObject *Sender) { TSpeedButton *s = (TSpeedButton *) Sender; if (s != sbMainIns) if(sbMainIns->Down) sbMainIns->Down = false; if (s != sbHorIns) if(sbHorIns->Down) sbHorIns->Down = false; if (s != sbHorDel) if(sbHorDel->Down) sbHorDel->Down = false; if (s != sbVerIns) if(sbVerIns->Down) sbVerIns->Down = false; if (s != sbVerDel) if(sbVerDel->Down) sbVerDel->Down = false; if (s != sbVerExchange) if(sbVerExchange->Down) sbVerExchange->Down = false; if (s != sbDelete) if(sbDelete->Down) sbDelete->Down = false; } //--------------------------------------------------------------------------- void __fastcall TStyleForm::ReadIniFile() { TIniFile *StyleIni = NULL; int l, t; StyleIni = new TIniFile(DirectoryItem + "\\Style.ini"); if (StyleIni) { l = StyleIni->ReadInteger("Form", "Left", (Screen->Width-Width)>>1); t = StyleIni->ReadInteger("Form", "Top", (Screen->Height-Height)>>1); currentIndex = StyleIni->ReadInteger("Image", "Order", 0); if (currentIndex < 0) currentIndex = 0; if (currentIndex>0) { if (currentIndex >= Data->Count) currentIndex = Data->Count - 1; } delete StyleIni; } if (l < 0) Left = 0; else Left = l; if (t < 0) Top = 0; else Top = t; } //--------------------------------------------------------------------------- void __fastcall TStyleForm::WriteIniFile() { TIniFile *StyleIni = NULL; StyleIni = new TIniFile(DirectoryItem + "\\Style.ini"); if (StyleIni) { StyleIni->WriteInteger("Form", "Left", Left); StyleIni->WriteInteger("Form", "Top", Top); if (currentIndex < 0) currentIndex = 0; StyleIni->WriteInteger("Image", "Order", currentIndex); delete StyleIni; } } //--------------------------------------------------------------------------- ////// Public Method ////////////////////////////////////////////////// //--------------------------------------------------------------------------- void __fastcall TStyleForm::InitForm() { int i, j; SearchFile = new TSearchFile; SearchFile->FileName = "*.tex"; if (isVector) { SearchFile->InitDirectory = DirectoryVStyle; // Vector StyleÀÎ °æ¿ì °æ·Î º¯°æ }else { SearchFile->InitDirectory = DirectoryStyle; } SearchFile->Make = true; SearchFile->SubDirectory = true; Data = new TList; UpdateData(); ReadIniFile(); // currentIndex = 0; ChangeStyleData(); // Left = Screen->Width - (Width + 20); Top = 30; StringGrid->Align = alClient; StringGrid->ColCount = 20; StringGrid->RowCount = 30; StringGrid->ColWidths[0] = 30; StringGrid->RowHeights[0] = 24; for (i = 1; i < 20; i++) StringGrid->ColWidths[i] = 90; for (j = 1; j < 30; j++) StringGrid->RowHeights[j] = 135; // MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, // MainImageForm->iMainImage->uBitmap->Height)); // µµ½ÄÈ­¿¡¼­ÀÇ ¾ðµÎ Ä«¿îÆ®¹®Á¦·Î »èÁ¦ if(PaletteForm->StyleUseColor) if(PaletteForm->DIB256Palette->UseColor == 2)stycolor = PaletteForm->DIB256Palette->UseColor-1; else stycolor = PaletteForm->DIB256Palette->UseColor; else stycolor = PaletteForm->DIB256Palette->UseColor; PaletteForm->DIB256Palette->SetNormal(stycolor+1,0, 0, 0); ::RepaintColor(); MainImageForm->iMainImage->SubEnabled = true; Imgstore = new TList; method = 0; CSearchCount = 0; RSearchCount = 0; del = false; fix = true; styleOUT = false; // MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, // MainImageForm->iMainImage->uBitmap->Height)); //blocked by linuxjun For New Undo if(!isVector)MainImageForm->UndoSave(UK_ALL, Rect(0,0,0,0)); //by linuxjun For New Undo Visible = true; BringToFront(); if(stycolor>250){ EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); styleOUT = true; } } //--------------------------------------------------------------------------- void __fastcall TStyleForm::ExitForm() { int i, j; TFileInfor *fi; TDirectoryInfor *firdi, *secdi; TImgdata *id; // if (fix) MainImageForm->Undo->RemoveLast(); //caution!! blocked for new Undo WriteIniFile(); if (Data->Count>0) { firdi = (TDirectoryInfor *) Data->Items[currentIndex]; if (firdi->pDirectoryList) { for (i=0; ipDirectoryList->Count; i++) { secdi = (TDirectoryInfor *) firdi->pDirectoryList->Items[i]; if (secdi->pFileList) { for (j=0; jpFileList->Count; j++) { fi = (TFileInfor *) secdi->pFileList->Items[j]; // if(fi->Bitmap) { // delete fi->Bitmap; // fi->Bitmap = NULL; if(fi->tBitmap) { delete fi->tBitmap; fi->tBitmap = NULL; } } } } } } while(Data->Count>0) { firdi = (TDirectoryInfor *) Data->Last(); Data->Remove(firdi); } delete Data; delete SearchFile; while (Imgstore->Count>0) { id = (TImgdata *) Imgstore->Last(); Imgstore->Remove(id); delete id->sBitmap; delete id; } delete Imgstore; MainImageForm->iMainImage->SubVisible = false; MainImageForm->iMainImage->SubEnabled = false; Visible = false; if(stycnt)MainImageForm->Palette->UseColor = stycolor+1; } //--------------------------------------------------------------------------- bool __fastcall TStyleForm::PopupInsert() { if ((method == 2) && (Imgstore->Count>0)) return true; else return false; } //--------------------------------------------------------------------------- void __fastcall TStyleForm::PopupClick(TObject *Sender) { if (del) DeleteImage(); } //--------------------------------------------------------------------------- void __fastcall TStyleForm::iMainImageMouseMove(int X, int Y) { if (method == 1) { // MainImageForm->SubBitmapPosition(X, Y, false); MainImageForm->SubBitmapPosition(X, Y, true); MergeBitmap(); } } //--------------------------------------------------------------------------- void __fastcall TStyleForm::iMainImageMouseDown(TMouseButton Button, int X, int Y) { TImgdata *id; int min[2] = {999, 999999999}; int tempsquare; // min[0] ImgIndex; min[1] RectSquare; del = false; if (Imgstore->Count>0) { if (method == 1) { DrawToImage(X , Y); } else if (method == 2) { for (int i = 0; i < Imgstore->Count; i++) { id = (TImgdata *) Imgstore->Items[i]; if (PtInRect(&id->rect, Point(X, Y))) { tempsquare = ((id->rect.right - id->rect.left) * (id->rect.bottom - id->rect.top)); if (min[1]>tempsquare) { min[1] = tempsquare; min[0] = i; } } } if (min[0] != 999) { del = true; ImgIndex = min[0]; if (Button == mbLeft) { if (sbDelete->Down) DeleteImage(); else SeparateImage(); } } } } } //--------------------------------------------------------------------------- void __fastcall TStyleForm::DrawToImage(int X, int Y) { ////////////////////new variable//////////// bool isFirstX; int StartX,EndX; //////////////////////////////////////////// ///* //BeConverted by linuxjun Don't Forget!! Undo_Method int w, h, x, y; THistoryData *ud; TImgdata *id; POINT p; Byte *sl, *dl, *ll; TPItemImage *Image = MainImageForm->iMainImage; stycnt = false; MainImageForm->SubBitmapPosition(X, Y, false); p.x = Image->SubRange.left; p.y = Image->SubRange.top; id = (TImgdata *) Imgstore->Items[ImgIndex]; w = Image->SubBitmap->Width; h = Image->SubBitmap->Height; if (!(Image->uBitmap->StartScanLine())) goto fail; if (!(Image->SubBitmap->StartScanLine())) goto fail; if (!(id->sBitmap->StartScanLine())) goto fail; if (Image->uBitmap->BitsPerPixel == 8) { for (y = 0; y < h; y++) { dl = Image->uBitmap->GetScanLine(y + p.y); sl = Image->SubBitmap->GetScanLine(y); isFirstX=true; //for new Undo_Method by linuxjun StartX=EndX=0; //by linuxjun for (x = 0; x < w; x++) { ////////////////////////////// EndX=x+p.x; // if (isFirstX) // { // StartX=x+p.x; // isFirstX=false; // } // if (sl[x] == 0) { if(stycolor>250){ EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); Image->SubBitmap->StopScanLine(); Image->uBitmap->StopScanLine(); id->sBitmap->StopScanLine(); return; } stycnt = true; dl[x+p.x] = stycolor+1; } else { dl[x+p.x] = sl[x]; // ////////////////////////////// } } if(!isFirstX)Image->uBitmap->PutScanLine(y + p.y,StartX,EndX-StartX+1); //by linuxjun } }else { // Full Color ¿¡¼­µµ ½ÇÇà °¡´ÉÇÏ°Ô By GreenFish // TColor TempC = MainImageForm->Palette->ColorData[2]->Color; for (y = 0; y < h; y++) { dl = Image->uBitmap->GetScanLine(y + p.y); //sl = Image->SubBitmap->GetScanLine(y); sl = id->sBitmap->GetScanLine(y); dl += p.x * 3; isFirstX=true; //for new Undo_Method by linuxjun StartX=EndX=0; //by linuxjun for (x = 0; x < w; x++, dl+=3 ) { if (sl[x] == 0) { *dl = clBlack; *(dl+1) = clBlack; *(dl+2) = clBlack; // */ /* *dl = TempC & 0xFF ; *(dl+1) = (TempC>>8) & 0xFF; *(dl+2) = (TempC>>16) & 0xFF;*/ // /* //BeConverted by linuxjun Don't Forget!! Undo_Method // ////////////////////////////// // EndX=3*x+p.x*3; // // if (isFirstX) // // { // // StartX=3*x+p.x*3; // // isFirstX=false; // // } // // ////////////////////////////// ////////////////////////////// EndX=x+p.x; // if (isFirstX) // { // StartX=x+p.x; // isFirstX=false; // } // ////////////////////////////// } } if(!isFirstX)Image->uBitmap->PutScanLine(y + p.y,StartX,EndX-StartX+1); //by linuxjun //Image->uBitmap->PutScanLine(y + p.y); } } id->sBitmap->StopScanLine(); Image->SubBitmap->StopScanLine(); Image->uBitmap->StopScanLine(); if (Image->LayerMask) Image->LayerMask->CopyToRect(p.x, p.y, Image->SubMask, SRCAND); Image->SubBitmap->Destroy(); Image->SubMask->Destroy(); Image->SubVisible = false; ::RepaintColor(); id->rect = Rect(p.x, p.y, p.x + w, p.y + h); id->draw = true; sbDelete->Enabled = true; method = 2; fix = false; return; fail: Image->SubBitmap->StopScanLine(); Image->uBitmap->StopScanLine(); Image->SubBitmap->Destroy(); Image->SubMask->Destroy(); id->sBitmap->StopScanLine(); Image->LayerMask->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); /* //BeConverted by linuxjun Don't Forget!! Undo_Method int w, h, x, y; TUndoData *ud; TImgdata *id; POINT p; Byte *sl, *dl, *ll; TPItemImage *Image = MainImageForm->iMainImage; stycnt = false; MainImageForm->SubBitmapPosition(X, Y, false); p.x = Image->SubRange.left; p.y = Image->SubRange.top; id = (TImgdata *) Imgstore->Items[ImgIndex]; w = Image->SubBitmap->Width; h = Image->SubBitmap->Height; if (!(Image->uBitmap->StartScanLine())) goto fail; if (!(Image->SubBitmap->StartScanLine())) goto fail; if (Image->uBitmap->BitsPerPixel == 8) { for (y = 0; y < h; y++) { dl = Image->uBitmap->GetScanLine(y + p.y); sl = Image->SubBitmap->GetScanLine(y); for (x = 0; x < w; x++) { if (sl[x] == 0) { if(stycolor>250){ EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); return; } stycnt = true; dl[x+p.x] = stycolor+1; } else { dl[x+p.x] = sl[x]; } } Image->uBitmap->PutScanLine(y + p.y); } }else { // Full Color ¿¡¼­µµ ½ÇÇà °¡´ÉÇÏ°Ô By GreenFish // TColor TempC = MainImageForm->Palette->ColorData[2]->Color; for (y = 0; y < h; y++) { dl = Image->uBitmap->GetScanLine(y + p.y); sl = Image->SubBitmap->GetScanLine(y); dl += p.x * 3; for (x = 0; x < w; x++, dl+=3 ) { if (sl[x] == 0) { *dl = clBlack; *(dl+1) = clBlack; *(dl+2) = clBlack; */ /* *dl = TempC & 0xFF ; *(dl+1) = (TempC>>8) & 0xFF; *(dl+2) = (TempC>>16) & 0xFF;*/ /* //BeConverted by linuxjun Don't Forget!! Undo_Method } } Image->uBitmap->PutScanLine(y + p.y); } } Image->SubBitmap->StopScanLine(); Image->uBitmap->StopScanLine(); if (Image->LayerMask) Image->LayerMask->CopyToRect(p.x, p.y, Image->SubMask, SRCAND); Image->SubBitmap->Destroy(); Image->SubMask->Destroy(); Image->SubVisible = false; ::RepaintColor(); id->rect = Rect(p.x, p.y, p.x + w, p.y + h); id->draw = true; sbDelete->Enabled = true; method = 2; fix = false; return; fail: Image->SubBitmap->StopScanLine(); Image->uBitmap->StopScanLine(); Image->SubBitmap->Destroy(); Image->SubMask->Destroy(); id->sBitmap->StopScanLine(); Image->LayerMask->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); */ } //--------------------------------------------------------------------------- void __fastcall TStyleForm::sbButtonStateClick(TObject *Sender) { ChangeButtonState(Sender); } //--------------------------------------------------------------------------- void __fastcall TStyleForm::BlackAndWhite() { Byte *mp, mm, *bp, *lp; int x, y; BWBreak = false; if (!MainImageForm->WorkArea->Mask->StartScanLine()) goto fail; if (!MainImageForm->iMainImage->uBitmap->StartScanLine()) goto fail; if (MainImageForm->iMainImage->LayerMask) { if (!MainImageForm->iMainImage->LayerMask->StartScanLine()) goto fail; if (MainImageForm->iMainImage->uBitmap->BitsPerPixel==8) { for (y=MainImageForm->WorkArea->Range.top; yWorkArea->Range.bottom; y++) { bp = MainImageForm->iMainImage->uBitmap->GetScanLine(y); lp = MainImageForm->iMainImage->LayerMask->GetScanLine(y); mp = MainImageForm->WorkArea->Mask->GetScanLine(y-MainImageForm->WorkArea->Range.top); for (x=MainImageForm->WorkArea->Range.left; xWorkArea->Range.right; x++, mp++) { if (*mp && (lp[x] == 0)) { if(!(*(bp+x) == 0x01 || *(bp+x) == 0x02)){ ShowMessage(IDS_ONLYCOLORSAVE); BWBreak = true; MainImageForm->iMainImage->LayerMask->StopScanLine(); MainImageForm->iMainImage->uBitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); return; } } } } } MainImageForm->iMainImage->LayerMask->StopScanLine(); } else { if (MainImageForm->iMainImage->uBitmap->BitsPerPixel==8) { for (y=MainImageForm->WorkArea->Range.top; yWorkArea->Range.bottom; y++) { bp = MainImageForm->iMainImage->uBitmap->GetScanLine(y); mp = MainImageForm->WorkArea->Mask->GetScanLine(y-MainImageForm->WorkArea->Range.top); for (x=MainImageForm->WorkArea->Range.left; xWorkArea->Range.right; x++, mp++) { if (*mp) { if(!(*(bp+x) == 0x01 || *(bp+x) == 0x02)){ ShowMessage(IDS_ONLYCOLORSAVE); BWBreak = true; MainImageForm->iMainImage->uBitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); return; } } } } } } MainImageForm->iMainImage->uBitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); return; fail: if (MainImageForm->iMainImage->LayerMask) MainImageForm->iMainImage->LayerMask->StopScanLine(); MainImageForm->iMainImage->uBitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); return; } //--------------------------------------------------------------------------- void __fastcall TStyleForm::stTitleClick(TObject *Sender) { //====================== Vector Style·Î ÀüȯÇÑ´Ù if (isVector) { isVector = false; VecDraw->bVectorStyle = false; stTitle->Caption = STR_BITMAPSTYLE; }else { isVector = true; VecDraw->bVectorStyle = true; stTitle->Caption = STR_VECTORSTYLE; } ExitForm(); InitForm(); UpdateData(); DeleteOldData(currentIndex); // currentIndex = ComboBox->ItemIndex; ChangeStyleData(); StringGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TStyleForm::SearchClick(TObject *Sender) { int FNLength, s; AnsiString fn, Sn, Sfn; AnsiString LowName; TDialogForm *Form = NULL; TDirectoryInfor *firdi, *secdi; TFileInfor *fi; AnsiString temp; Form = new TDialogForm(this); Form->Caption = IDS_SEARCH; Form->PanelCopy->BringToFront(); Form->InitForm(1, "", 1); if (Form->ShowModal() == mrOk) { CSearchCount = 0; firdi = (TDirectoryInfor *) Data->Items[currentIndex]; name = Form->EditCopy->Text; FNLength = name.Length(); LowName = name.LowerCase(); if(LowName.Pos(".tex") == FNLength - 3)Sfn = name; else Sfn = name+".tex"; NumOfSearchFiles=0; CurrentFileNum=0; //////////////////////////// for(int i = 0; i < firdi->pDirectoryList->Count; i++){ secdi = (TDirectoryInfor *) firdi->pDirectoryList->Items[CSearchCount]; for (int j = 0; j < secdi->pFileList->Count; j++) { fi = (TFileInfor*) secdi->pFileList->Items[j]; fn = fi->Name.LowerCase(); Sn = Sfn.LowerCase(); if(AllSearch->Checked){ s = fn.Pos(name.LowerCase()); if(s){ NumOfSearchFiles++; CurrentFileNum = 1; } }else if(fn == Sn){ NumOfSearchFiles++; CurrentFileNum = 1; } } CSearchCount++; } temp = CurrentFileNum; temp +="/"; temp +=NumOfSearchFiles; StatusBar1->SimpleText=temp; // StatusBar1->SimpleText=CurrentFileNum+"/"+NumOfSearchFiles; //////////////////////////// CSearchCount = 0; for(int i = 0; i < firdi->pDirectoryList->Count; i++){ secdi = (TDirectoryInfor *) firdi->pDirectoryList->Items[CSearchCount]; for (int j = 0; j < secdi->pFileList->Count; j++) { fi = (TFileInfor*) secdi->pFileList->Items[j]; fn = fi->Name.LowerCase(); Sn = Sfn.LowerCase(); if(AllSearch->Checked){ s = fn.Pos(name.LowerCase()); if(s){ StringGrid->Row = j+1; StringGrid->Col = CSearchCount+1; StringGrid->SetFocus(); RSearchCount = j; goto next; } }else if(fn == Sn){ StringGrid->Row = j+1; StringGrid->Col = CSearchCount+1; StringGrid->SetFocus(); goto next; } } CSearchCount++; } ShowMessage(IDS_MESSAGE_FILENOTFOUND); next: if(AllSearch->Checked){ RSearchCount++; }else CSearchCount++; } } //--------------------------------------------------------------------------- void __fastcall TStyleForm::StringGridKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { int FNLength, s, len; AnsiString fn, Sn, Sfn; AnsiString LowName, names; AnsiString temp; TDirectoryInfor *firdi, *secdi; TFileInfor *fi; if(Key == 114){ firdi = (TDirectoryInfor *) Data->Items[currentIndex]; FNLength = name.Length(); LowName = name.LowerCase(); if(LowName.Pos(".tex") == FNLength - 3)Sfn = name; else Sfn = name+".tex"; for(int i = CSearchCount; i < firdi->pDirectoryList->Count; i++){ secdi = (TDirectoryInfor *) firdi->pDirectoryList->Items[CSearchCount]; for (int j = RSearchCount; j < secdi->pFileList->Count; j++) { fi = (TFileInfor*) secdi->pFileList->Items[j]; fn = fi->Name.LowerCase(); Sn = Sfn.LowerCase(); if(AllSearch->Checked){ len = fn.Length(); //len = (fn.Length() - 4); for (int i = 1; i <= len; i++) { names += fn[i]; } s = names.Pos(name.LowerCase()); fn = ""; if(s){ StringGrid->Row = j+1; StringGrid->Col = CSearchCount+1; StringGrid->SetFocus(); RSearchCount = j; CurrentFileNum++; goto next; } }else if(fn == Sn){ StringGrid->Row = j+1; StringGrid->Col = CSearchCount+1; StringGrid->SetFocus(); CurrentFileNum++; goto next; } } CSearchCount++; RSearchCount = 0; } ShowMessage(IDS_MESSAGE_OVERFILENOTFOUND); next: if(AllSearch->Checked){ RSearchCount++; temp = CurrentFileNum; temp +="/"; temp +=NumOfSearchFiles; StatusBar1->SimpleText=temp; // StatusBar1->SimpleText=CurrentFileNum+"/"+NumOfSearchFiles; }else{ CSearchCount++; temp = CurrentFileNum; temp +="/"; temp +=NumOfSearchFiles; StatusBar1->SimpleText=temp; // StatusBar1->SimpleText=CurrentFileNum+"/"+NumOfSearchFiles; } } } //---------------------------------------------------------------------------