//--------------------------------------------------------------------------- #include #include #include #pragma hdrstop #include "Jacquard.h" #include "FileManager_F.h" #include "Grouping_F.h" #include "JacPrt.h" #include "Main.h" #include "MainImage.h" #include "Palette.h" #include "StatusProgress.h" #include "Texture_F.h" #include "Undo.h" #include "UserColor_F.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_JACQUARDMENU StringTable[0] #define IDS_SELECTCOLOR StringTable[1] #define IDS_TEXTURE StringTable[2] #define IDS_INAREA StringTable[3] #define IDS_EFFECT StringTable[4] #define IDS_ROTATE StringTable[5] #define IDS_ALLDELETE StringTable[6] //--------------------------------------------------------------------------- TJacquardForm *JacquardForm; typedef struct tagTJtxtData { Byte g[4]; Byte mode; char name[22]; TTexBitData *bmp; } TJtxtData; typedef struct tagTjaqdFiledata { Byte base; Byte tcnt; } TJaqdFiledata; //--------------------------------------------------------------------------- __fastcall TJacquardForm::TJacquardForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::FormCreate(TObject *Sender) { //====================================================================== StringTable.Create(DirectoryItem, Language, "Jacquard"); SetSmallFont(Font); SetSmallFont(NameText->Font); Caption = IDS_JACQUARDMENU; SelectColButton->Caption = IDS_SELECTCOLOR; TextureButton->Caption = IDS_TEXTURE; AreaButton->Caption = IDS_INAREA; FileButton->Caption = IDS_COMMON_FILE; EffectButton->Caption = IDS_EFFECT; PrintButton->Caption = IDS_COMMON_PRINT; sbRotate->Hint = IDS_ROTATE; // sbAllDelete->Hint = IDS_ALLDELETE; // sbDelete->Hint = IDS_COMMON_DELETE; sbAllDelete->Caption = IDS_ALLDELETE; sbDelete->Caption = IDS_COMMON_DELETE; //====================================================================== store = NULL; Bitmap = NULL; } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::FormDestroy(TObject *Sender) { int count; AnsiString str; TIniFile* JacIni = new TIniFile(DirectoryItem+"\\Jacquard.ini"); count = JacIni->ReadInteger("Count", "cnt", 0); while (count>0) { str = Format("%d", OPENARRAY(TVarRec, (count-1))); JacIni->WriteInteger(str, "Use", 0); count = count-1; } delete JacIni; } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::TextureButtonClick(TObject *Sender) { TextureForm->Visible = true; Effect = false; IsDraw = false; DrawGImage(); } //---------------------------------------------------------------------------- void __fastcall TJacquardForm::SelectColButtonClick(TObject *Sender) { TextureForm->Visible = false; Effect = false; IsDraw = true; DrawGImage(); Select = 0; } //---------------------------------------------------------------------------- void __fastcall TJacquardForm::AreaButtonClick(TObject *Sender) { TextureForm->Visible = false; Effect = false; IsDraw = true; DrawGImage(); Select = 1; } //---------------------------------------------------------------------------- void __fastcall TJacquardForm::EffectButtonClick(TObject *Sender) { int i, ct, uc; Byte r, g, b; double h, l, s; TextureForm->Visible = false; Effect = true; IsDraw = true; Select =2; minL = 0.5; maxL = 0.5; uc = MainImageForm->Palette->UseColor; for (i=2; i<=uc; i++) { r = MainImageForm->Palette->ColorData[i]->RGB.rgbRed; g = MainImageForm->Palette->ColorData[i]->RGB.rgbGreen; b = MainImageForm->Palette->ColorData[i]->RGB.rgbBlue; RGB2HLS(r, g, b, h, l, s); if (maxLl) minL = l; } alpha = maxL-minL; delta = alpha/2; ct = delta*180; length = delta*180; LigLine(Point(ct-length-18, 0), Point(ct+length-18, 19)); diff = -0.1; } //---------------------------------------------------------------------------- void __fastcall TJacquardForm::PrintButtonClick(TObject *Sender) { TJacPrtForm *Form = NULL; TTexpiaBitmap *Pattern = NULL; int DPI; TRect Src, Dst; TSize r; TextureForm->Visible = false; if ((Form = new TJacPrtForm(this)) == NULL) goto fail; if (Form->ShowModal()==mrOk) { if ((Pattern = new TTexpiaBitmap) == NULL) goto fail; DPI = MainImageForm->CanvasInfor.DotsPerInch; switch (Form->MethodComboBox->ItemIndex) { case 0: //No r.cx = Form->RepeatXEdit->Value; r.cy = Form->RepeatYEdit->Value; if (!ComboNoMethod(Pattern, r)) goto fail; DPI = DPI * 100 / StrToInt(Form->EditZoom->Text); break; case 1: //Yes if (!ComboYesMethod(Pattern)) goto fail; break; } SendToPrinter(Pattern, DPI, "Jacquard - "+MainImageForm->FileName, Form->PageEdit->Value, Form->cbMethod->ItemIndex); delete Pattern; } delete Form; SelectColButton->Down = true; IsDraw = true; return; fail: if (Pattern) delete Pattern; if (Form) delete Form; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); SelectColButton->Down = true; IsDraw = true; } //---------------------------------------------------------------------------- void __fastcall TJacquardForm::FileButtonClick(TObject *Sender) { TFileManagerForm *Form = NULL; TextureForm->Visible = false; Effect = false; if ((Form = new TFileManagerForm(this)) == NULL) goto fail; Form->Extension = 1; //Jacquard¸¦ fileManager¿¡°Ô ¾Ë¸². Form->FilterComboBox->Filter = "Texpro Jacquard File (*.jqd)|*.jqd"; Form->OnRead = JQDOnRead; Form->OnFileName = JQDOnFileName; Form->OnSave = JQDOnSave; Form->ShowModal(); delete Form; SelectColButton->Down = true; IsDraw = true; return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //---------------------------------------------------------------------------- void __fastcall TJacquardForm::sbAllDeleteClick(TObject *Sender) { IniTTextureData(); } //---------------------------------------------------------------------------- void __fastcall TJacquardForm::sbDeleteClick(TObject *Sender) { int r; PTextureData jd; if (store->Count) { r = ImgScrollBar->Position; jd = (PTextureData) store->Items[r]; store->Remove(jd); delete jd; if (store->Count==0) IniTTextureData(); else { ImgScrollBar->Max = store->Count-1; ImgScrollBar->Position = store->Count-1; if (r==store->Count) ImgChange(r-1); else ImgChange(r); } } } //---------------------------------------------------------------------------- void __fastcall TJacquardForm::sbRotateClick(TObject *Sender) { PTextureData jd; int i; if (store->Count>0) { i = ImgScrollBar->Position; jd = (PTextureData) store->Items[i]; jd->Rot = jd->Rot+1; if (jd->Rot==4) jd->Rot = 0; ImgChange(ImgScrollBar->Position); } } //---------------------------------------------------------------------------- void __fastcall TJacquardForm::ImgScrollBarScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { ImgChange(ScrollPos); } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::GImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (Effect) { ImgClick = true; DrawGImage(); LigLine(Point(X-length, 0), Point(X+length, 19)); } } //---------------------------------------------------------------------------- void __fastcall TJacquardForm::GImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (ImgClick) MoveRectangle(X); } //---------------------------------------------------------------------------- void __fastcall TJacquardForm::GImageMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (ImgClick) { MoveRectangle(X); ImgClick = false; } } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::InitFunc(int i) { if (i==0) { SelectColButton->Enabled = true; AreaButton->Enabled = true; EffectButton->Enabled = true; } else { SelectColButton->Enabled = false; AreaButton->Enabled = false; EffectButton->Enabled = false; } } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::ReadJacIni() { int i, count, J_use; AnsiString str; PTextureData jd = NULL; TIniFile* JacIni = new TIniFile(DirectoryItem+"\\Jacquard.ini"); count = JacIni->ReadInteger("Count", "cnt", 0); i = count; if (count>0) { InitFunc(0); mm = true; } else { InitFunc(1); mm = false; } while (count>0) { if ((jd = new TTextureData) == NULL) goto fail; str = Format("%d", OPENARRAY(TVarRec, (i-count))); jd->Itm = JacIni->ReadInteger(str, "Itm", 0); jd->pts = JacIni->ReadInteger(str, "pts", 0); jd->name = JacIni->ReadString(str, "Name", ""); jd->disname = JacIni->ReadString(str, "disName", ""); jd->zoom = JacIni->ReadInteger(str, "zoom", 0); jd->num = JacIni->ReadInteger(str, "num", 0); jd->Ind = JacIni->ReadInteger(str, "Ind", 0); jd->Rot = JacIni->ReadInteger(str, "Rot", 0); J_use = JacIni->ReadInteger(str, "Use", 0); if (J_use) jd->use = true; else jd->use = false; store->Add(jd); count = count-1; } delete JacIni; if (store->Count>0) { ImgScrollBar->Enabled = true; ImgScrollBar->Max = store->Count-1; ImgScrollBar->Position = store->Count-1; ImgChange(store->Count-1); } else ImgScrollBar->Enabled = false; return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::WriteJacIni() { int count, i, J_use; AnsiString str; PTextureData jd; TIniFile* JacIni = new TIniFile(DirectoryItem+"\\Jacquard.ini"); count = JacIni->ReadInteger("Count", "cnt", 0); if (store->CountCount; iEraseSection(str); } } JacIni->WriteInteger("Count", "cnt", store->Count); count = store->Count; while (count>0) { jd = (PTextureData) store->Items[count-1]; str = Format("%d", OPENARRAY(TVarRec, (count-1))); JacIni->WriteInteger(str, "Itm", jd->Itm); JacIni->WriteInteger(str, "pts", jd->pts); JacIni->WriteString(str, "Name", jd->name); JacIni->WriteString(str, "disName", jd->disname); JacIni->WriteInteger(str, "zoom", jd->zoom); JacIni->WriteInteger(str, "num", jd->num); JacIni->WriteInteger(str, "Ind", jd->Ind); JacIni->WriteInteger(str, "Rot", jd->Rot); if (jd->use) J_use = 1; else J_use = 0; JacIni->WriteInteger(str, "Use", J_use); count = count-1; } delete JacIni; } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::IniTTextureData() { PTextureData jd; while (store->Count) { jd = (PTextureData) store->Last(); store->Remove(jd); delete jd; } ImgScrollBar->Max = 0; ImgScrollBar->Enabled = false; find = false; Clear(); } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::FindData(PTextureData jd) { Byte i; PTextureData cp; if (store->Count==0) return; for (i=0; iCount; i++) { cp = (PTextureData) store->Items[i]; if (cp->Itm==jd->Itm) { if (cp->pts==jd->pts) { if (cp->name==jd->name) { if (cp->disname==jd->disname) { if (cp->zoom==jd->zoom) { find = true; Sysutils::Beep(); return; } else { cp->zoom = jd->zoom; return; } } } } } } } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::FoundDrawData(PTextureData jd, Byte &i, Byte &n) { TFound *fd; AnsiString str1, str2; int cnt, x; TTexBitData *bip; cnt = TextureForm->Texture->f[jd->pts]->Count; for (x=0; xTexture->f[jd->pts]->Items[x]; str1 = Format("%d x %d", OPENARRAY(TVarRec, (fd->size, fd->size))); if (str1==jd->name) { i = x; break; } } fd = (TFound *) TextureForm->Texture->f[jd->pts]->Items[i]; cnt = fd->data->Count; for (x=0; xdata->Items[x]; str2 = AnsiString(bip->Name); if (str2==jd->disname) n = x; } } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::DerivDrawData(PTextureData jd, Byte &i, Byte &n) { TDeriv *dt; AnsiString str1, str2; int cnt, x; TTexBitData *bip; cnt = TextureForm->Texture->d[jd->pts]->Count; for (x=0; xTexture->d[jd->pts]->Items[x]; str1 = AnsiString (dt->name); if (str1==jd->name) { i = x; break; } } dt = (TDeriv *) TextureForm->Texture->d[jd->pts]->Items[i]; cnt = dt->data->Count; for (x=0; xdata->Items[x]; str2 = AnsiString (bip->Name); if (str2==jd->disname) n = x; } } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::SpecialDrawData(PTextureData jd, Byte &i, Byte &n) { TSpecial *sp; AnsiString str1, str2; int cnt, x; TTexBitData *bip; cnt = TextureForm->Texture->s->Count; for (x=0; xTexture->s->Items[x]; str1 = AnsiString (sp->name); if (str1==jd->name) { i = x; break; } } sp = (TSpecial *) TextureForm->Texture->s->Items[i]; cnt = sp->data->Count; for (x=0; xdata->Items[x]; str2 = AnsiString (bip->Name); if (str2==jd->disname) n = x; } } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::ImgChange(int Pos) { Byte i, n; PTextureData jd = (PTextureData) store->Items[Pos]; switch (jd->Itm) { case 0: FoundDrawData(jd, i, n); FoundDraw(jd->pts, i, n, jd->Rot); break; case 1: DerivDrawData(jd, i, n); DerivDraw(jd->pts, i, n, jd->Rot); break; case 2: SpecialDrawData(jd, i, n); SpecialDraw(i, n, jd->Rot); break; } } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::FoundDraw(Byte p, Byte i, Byte n, Byte Rot) { TFound *fd = (TFound *) TextureForm->Texture->f[p]->Items[i]; NameText->Caption = Format("F: <<%d>> %d x %d", OPENARRAY(TVarRec, (n+1, fd->size, fd->size))); TTexBitData *bip = (TTexBitData *) fd->data->Items[n]; DrawBitmap(bip, Rot); Image->Canvas->Draw(0, 0, Bitmap); LineDraw(bip, Rot); } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::DerivDraw(Byte p, Byte i, Byte n, Byte Rot) { TDeriv *dt = (TDeriv *) TextureForm->Texture->d[p]->Items[i]; NameText->Caption = Format("D: <<%d>> %s", OPENARRAY(TVarRec, (n+1, dt->name))); TTexBitData *bip = (TTexBitData *) dt->data->Items[n]; DrawBitmap(bip, Rot); Image->Canvas->Draw(0, 0, Bitmap); LineDraw(bip, Rot); } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::SpecialDraw(Byte i, Byte n, Byte Rot) { TSpecial *sp = (TSpecial *) TextureForm->Texture->s->Items[i]; NameText->Caption = Format("S: <<%d>> %s", OPENARRAY(TVarRec, (n+1, sp->name))); TTexBitData *bip = (TTexBitData *) sp->data->Items[n]; DrawBitmap(bip, Rot); Image->Canvas->Draw(0, 0, Bitmap); LineDraw(bip, Rot); } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::DrawBitmap(TTexBitData *bip, Byte Rot) { short x, y, j, w, rw, zr, tot, spt, zh, zw; Byte z, r; Byte *sl, *stp, *temp, *pcx, *pcy; stp = (Byte *) bip->pBitmap; pcy = stp; temp = stp; zw = bip->Width*9; zh = bip->Height*9; w = Bitmap->Width/zw; rw = Bitmap->Width%zw; if (w==0) w = 1; for (y=Bitmap->Height-1; y>=0; y--) { if ((Rot==0)||(Rot==1)) sl = (Byte *) Bitmap->ScanLine[y]; else if ((Rot==2)||(Rot==3)) sl = (Byte *) Bitmap->ScanLine[Bitmap->Height-1-y]; spt = Bitmap->Height-1-y; if ((spt%9)<9) stp = temp; if ((spt%9)==0)stp = pcy; if ((spt%zh)==0) stp = (Byte *)bip->pBitmap; for (j=0; jWidth; r++) { zr = r*9; for (z=0; z<9; z++) { tot = x+zr+z; if (tot>=Bitmap->Width) break; if ((Rot==0)||(Rot==3)) *(sl+tot) = *pcx; else if ((Rot==1)||(Rot==2)) *(sl+(Bitmap->Width-1-tot)) = *pcx; } pcx++; pcy = pcx; } } if ((Bitmap->Width>zw)&&(rw)) { pcx = stp; for (r=0; rWidth; r++) { for (z=0; z<9; z++) { tot = (Bitmap->Width-rw)+(r*9)+z; if (tot>=Bitmap->Width) break; if ((Rot==0)||(Rot==3)) *(sl+tot) = *pcx; else if ((Rot==1)||(Rot==2)) *(sl+(Bitmap->Width-1-tot)) = *pcx; } pcx++; } } } } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::LineDraw(TTexBitData *bip, Byte Rot) { int w, h, i, j, vj; w = bip->Width*9; h = bip->Height*9; switch (Rot) { case 0: case 3: for (i=0; iWidth; i++) { if ((i%9)==0) { Image->Canvas->Pen->Color = clBlue; if ((i%w)==0) Image->Canvas->Pen->Color = clRed; Image->Canvas->MoveTo(i, 0); Image->Canvas->LineTo(i, Bitmap->Height); } } break; case 1: case 2: for (i=Bitmap->Width-1; i>=0; i--) { if (((Bitmap->Width-i-1)%9)==0) { Image->Canvas->Pen->Color = clBlue; if (((Bitmap->Width-1-i)%w)==0) Image->Canvas->Pen->Color = clRed; Image->Canvas->MoveTo(i, 0); Image->Canvas->LineTo(i, Bitmap->Height); } } break; } switch (Rot) { case 0: case 1: for (j=Bitmap->Height-1; j>=0; j--) { vj = Bitmap->Height-1-j; if ((vj%9)==0) { Image->Canvas->Pen->Color = clBlue; if ((vj%h)==0) Image->Canvas->Pen->Color = clRed; Image->Canvas->MoveTo(0, j+1); Image->Canvas->LineTo(Bitmap->Width, j+1); } } break; case 2: case 3: for (j=0; jHeight; j++) { if ((j%9)==0) { Image->Canvas->Pen->Color = clBlue; if ((j%h)==0) Image->Canvas->Pen->Color = clRed; Image->Canvas->MoveTo(0, j); Image->Canvas->LineTo(Bitmap->Width, j); } } break; } } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::Clear() { NameText->Caption = ""; Image->Canvas->Brush->Color = clWhite; Image->Canvas->FillRect(Rect(0, 0, Image->Width, Image->Height)); InitFunc(1); DrawGImage(); mm = false; } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::DrawGImage() { PChar sl; int x, y, xx, i; GImage->Picture->Bitmap->PixelFormat = pf24bit; GImage->Picture->Bitmap->Width = 181; GImage->Picture->Bitmap->Height = 20; GImage->Canvas->Pen->Color = clAqua; for (y=0; y<20; y++) { sl = (char*) GImage->Picture->Bitmap->ScanLine[y]; for (x=0; x<=180; x++) { xx = x*3; i = 255*x/180; *(sl+xx) = i; *(sl+xx+1) = i; *(sl+xx+2) = i; } } GImage->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::SetPaletteColor() { Byte i, uc, r, g, b; double h, l, s; uc = U_Col; if ((uc*2)<=251) { for (i=2; i<=uc; i++) { r = MainImageForm->Palette->ColorData[i]->RGB.rgbRed; g = MainImageForm->Palette->ColorData[i]->RGB.rgbGreen; b = MainImageForm->Palette->ColorData[i]->RGB.rgbBlue; RGB2HLS(r, g, b, h, l, s); l = l+diff; if (l<0.0) l = 0.0; if (l>1.0) l = 1.0; MainImageForm->Palette->HLS2RGB(i-1+uc, h, l, s); } } } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::LigLine(TPoint sp, TPoint ep) { GImage->Canvas->MoveTo(sp.x, sp.y); GImage->Canvas->LineTo(sp.x, ep.y); GImage->Canvas->LineTo(ep.x, ep.y); GImage->Canvas->LineTo(ep.x, sp.y); GImage->Canvas->LineTo(sp.x, sp.y); } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::MoveRectangle(int X) { double center; DrawGImage(); if (X>180) X = 180; if (X<0) X =0; LigLine(Point(X-length, 0), Point(X+length, 19)); center = (double) X/180; diff = center-delta; if (draw) SetPaletteColor(); ::RepaintColor(); } //--------------------------------------------------------------------------- bool __fastcall TJacquardForm::FillRead(Byte *p, int x) { return *(p+x)==FillColor; } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::FillSave(Byte *p, int x) { *(p+x) = 0xFF; } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::SelectColorFill() { TRect Rect; TCursor Cursor = Screen->Cursor; Screen->Cursor = crHourGlass; StatusProgress->Maximum = 4; MainImageForm->iMainImage->Bitmap->FloodFill(First, FillRead, FillSave, Rect); StatusProgress->Position = 2; MainFill(Rect, 0); StatusProgress->Position = 3; StatusProgress->Position = 4; ClientHeight = 223; // Because of an unknown error... Screen->Cursor = Cursor; StatusProgress->End(); } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::AreaFill() { RECT r; TCursor Cursor = Screen->Cursor; Screen->Cursor = crHourGlass; if (MainImageForm->WorkArea->Mask) { r = MainImageForm->WorkArea->Range; MainFill(Rect(r.left, r.top, r.right, r.bottom), 1); } else { MainFill(Rect(0, 0, MainImageForm->iMainImage->Bitmap->Width, MainImageForm->iMainImage->Bitmap->Height), 0); } ClientHeight = 223; // Because of an unknown error... Screen->Cursor = Cursor; } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::EffectFill() { int uc; RECT r; TCursor Cursor = Screen->Cursor; Screen->Cursor = crHourGlass; uc = MainImageForm->Palette->UseColor; if ((uc*2) < 252) { SetPaletteColor(); if (MainImageForm->WorkArea->Mask) { r = MainImageForm->WorkArea->Range; MainFill(Rect(r.left, r.top, r.right, r.bottom), 3); } else { MainFill(Rect(0, 0, MainImageForm->iMainImage->Bitmap->Width, MainImageForm->iMainImage->Bitmap->Height), 2); } ClientHeight = 223; // Because of an unknown error...; sep = true; } else { EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); sep = false; } Screen->Cursor = Cursor; } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::MainFill(TRect Rect, Byte code) { TFound *fd; TDeriv *dt; TSpecial *sp; PTextureData jd; TTexBitData *bip; int pos; Byte zo, Rot, i, n; pos = ImgScrollBar->Position; jd = (PTextureData)store->Items[pos]; switch (jd->Itm) { case 0: FoundDrawData(jd, i, n); fd = (TFound *) TextureForm->Texture->f[jd->pts]->Items[i]; bip = (TTexBitData *) fd->data->Items[n]; break; case 1: DerivDrawData(jd, i, n); dt = (TDeriv *)TextureForm->Texture->d[jd->pts]->Items[i]; bip = (TTexBitData *) dt->data->Items[n]; break; case 2: SpecialDrawData(jd, i, n); sp = (TSpecial *) TextureForm->Texture->s->Items[i]; bip = (TTexBitData *) sp->data->Items[n]; break; } zo = jd->zoom; Rot = jd->Rot; switch (code) { case 0: SubFill(bip, Rect, zo, Rot); break; //Use in case of Select_Color & WA_RECT .. case 1: SubIRREFill(bip, Rect, zo, Rot); break; case 2: SubNONEEffect (bip, Rect, zo, Rot); break; case 3: SubIRREEffect (bip, Rect, zo, Rot); break; } } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::SubFill(TTexBitData *bip, TRect Rect, Byte zo, Byte Rot) { int x, y, j, w, rw, zr, tot, spt, zh, zw; Byte z, r, id; Byte *sl, *ul; TUndoData *ud; Byte *stp, *temp, *pcx, *pcy, *lp; int Width, RL, TB, ec, www, hhh; if (Select==0) id = 0xFF; else id = FillColor; stp = (Byte*) bip->pBitmap; pcy = stp; temp = stp; Width = Rect.Right-Rect.Left; Height = Rect.Bottom-Rect.Top; RL = Rect.Right+Rect.Left; TB = Rect.Top+Rect.Bottom; zw = bip->Width*zo; zh = bip->Height*zo; w = Width / zw; rw = Width % zw; if (w==0) w = 1; if ((ud = Undo->Last)==NULL) { ec = EC_UNDO_NONE; goto fail; } www = ud->Bitmap->Width; hhh = ud->Bitmap->Height; if (!MainImageForm->iMainImage->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!ud->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=Rect.Bottom-1; y>=Rect.Top; y--) { switch (Rot) { case 0: case 1: sl = (Byte *)MainImageForm->iMainImage->Bitmap->GetScanLine(y); ul = (Byte *)ud->Bitmap->GetScanLine(y); break; case 2: case 3: sl = (Byte *)MainImageForm->iMainImage->Bitmap->GetScanLine(TB-1-y); ul = (Byte *)ud->Bitmap->GetScanLine(TB-1-y); break; } spt = Rect.Bottom-1-y; if ((spt % zo)pBitmap; for (j=0; jWidth; r++) { zr = r*zo; for (z=0; z=Rect.Right) break; if ((Rot==0) || (Rot==3)) { if (*(sl+tot)==id) { if (*pcx==1) { *(sl+tot) = ColIndex; } else *(sl+tot) = *(ul+tot); } } else { if (*(sl+(RL-1-tot))==id) { if ((*pcx)==1) { *(sl+(RL-1-tot)) = ColIndex; } else *(sl+(RL-1-tot)) = *(ul+(RL-1-tot)); } } } pcx++; pcy = pcx; } } if ((Width>zw) && (rw)) { pcx = stp; for (r=0; rWidth; r++) { for (z=0; z=Rect.Right) break; if ((Rot==0) || (Rot==3)) { if (*(sl+tot)==id) { if (*pcx==1) { *(sl+tot) = ColIndex; } else *(sl+tot) = *(ul+tot); } } else { if (*(sl+(RL-tot))==id) { if (*pcx==1) { *(sl+(RL-tot)) = ColIndex; } else *(sl+(RL-tot)) = *(ul+(RL-tot)); } } } pcx++; } } switch (Rot) { case 0: case 1: MainImageForm->iMainImage->Bitmap->PutScanLine(y); break; case 2: case 3: MainImageForm->iMainImage->Bitmap->PutScanLine(TB-1-y); break; } } ud->Bitmap->StopScanLine(); MainImageForm->iMainImage->Bitmap->StopScanLine(); return; fail: ud->Bitmap->StopScanLine(); MainImageForm->iMainImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::SubIRREFill(TTexBitData *bip, TRect Rect, Byte zo, Byte Rot) { int x, y, j, w, rw, zr, tot, spt, zh, zw; Byte z, r; Byte *sl, *ul, *ml, *lp; TUndoData *ud; Byte *stp, *temp, *pcx, *pcy; int Width, RL, TB, ec; stp = (Byte *) bip->pBitmap; pcy = stp; temp = stp; Width = Rect.Right-Rect.Left; Height = Rect.Bottom-Rect.Top; RL = Rect.Right+Rect.Left; TB = Rect.Top+Rect.Bottom; zw = bip->Width*zo; zh = bip->Height*zo; w = Width / zw; rw = Width % zw; if (w==0) w = 1; if ((ud = Undo->Last)==NULL) { ec = EC_UNDO_NONE; goto fail; } if (!MainImageForm->iMainImage->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!MainImageForm->WorkArea->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!ud->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=Rect.Bottom-1; y>=Rect.Top; y--) { if ((Rot==0) || (Rot==1)) { sl = (Byte *) MainImageForm->iMainImage->Bitmap->GetScanLine(y); ul = (Byte *) ud->Bitmap->GetScanLine(y); ml = (Byte *) MainImageForm->WorkArea->Mask->GetScanLine(y-Rect.Top); } else { sl = (Byte *) MainImageForm->iMainImage->Bitmap->GetScanLine(TB-1-y); ul = (Byte *) ud->Bitmap->GetScanLine(TB-1-y); ml = (Byte *) MainImageForm->WorkArea->Mask->GetScanLine(Rect.Bottom-1-y); } spt = Rect.Bottom-1-y; if ((spt % zo)pBitmap; for (j=0; jWidth; r++) { zr = r*zo; for (z=0; z=Rect.Right) break; if ((Rot==0) ||(Rot==3)) { if (*(ml+tot-Rect.Left)) { if (*(sl+tot)==FillColor) { if (*pcx==1) { *(sl+tot) = ColIndex; } else *(sl+tot) = *(ul+tot); } } } else { if (*(ml+Rect.Right-1-tot)) { if (*(sl+(RL-1-tot))==FillColor) { if (*pcx==1) { *(sl+(RL-1-tot)) = ColIndex; } else *(sl+(RL-1-tot)) = *(ul+(RL-1-tot)); } } } } pcx++; pcy = pcx; } } if ((Width>zw) && (rw)) { pcx = stp; for (r=0; rWidth; r++) { for (z=0; z=Rect.Right) break; if((Rot==0) ||(Rot==3)) { if (*(ml+tot-Rect.Left)) { if (*(sl+tot)==FillColor) { if (*pcx==1) { *(sl+tot) = ColIndex; } else *(sl+tot) = *(ul+tot); } } } else { if (*(ml+Rect.Right-1-tot)) { if (*(sl+(RL-tot))==FillColor) { if (*pcx==1) { *(sl+(RL-tot)) = ColIndex; } else *(sl+(RL-tot)) = *(ul+(RL-tot)); } } } } pcx++; } } switch (Rot) { case 0: case 1: MainImageForm->iMainImage->Bitmap->PutScanLine(y); break; case 2: case 3: MainImageForm->iMainImage->Bitmap->PutScanLine(TB-1-y); break; } } ud->Bitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); MainImageForm->iMainImage->Bitmap->StopScanLine(); return; fail: ud->Bitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); MainImageForm->iMainImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::SubNONEEffect(TTexBitData *bip, TRect Rect, Byte zo, Byte Rot) { int x, y, j, w, rw, zr, tot, spt, zh, zw, uc; Byte z, r; Byte *sl, *ul, *lp; TUndoData *ud; Byte *stp, *temp, *pcx, *pcy; int RL, TB, ec; stp = (Byte *) bip->pBitmap; pcy = stp; temp = stp; RL = Rect.Right+Rect.Left; TB = Rect.Top+Rect.Bottom; zw = bip->Width*zo; zh = bip->Height*zo; w = (Rect.Right-Rect.Left) / zw; rw = (Rect.Right-Rect.Left) % zw; if (w==0) w = 1; if ((ud = Undo->Last)==NULL) { ec = EC_UNDO_NONE; goto fail; } uc = MainImageForm->Palette->UseColor; if (!MainImageForm->iMainImage->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!ud->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y= Rect.Bottom-1; y>=Rect.Top; y--) { if ((Rot==0) ||(Rot==1)) { sl = (Byte *) MainImageForm->iMainImage->Bitmap->GetScanLine(y); ul = (Byte *) ud->Bitmap->GetScanLine(y); } else { sl = (Byte *) MainImageForm->iMainImage->Bitmap->GetScanLine(TB-1-y); ul = (Byte *) ud->Bitmap->GetScanLine(TB-1-y); } spt = Rect.Bottom-1-y; if ((spt % zo)pBitmap; for (j=0; jWidth; r++) { zr = r*zo; for (z=0; z=Rect.Right) break; if ((Rot==0) || (Rot==3)) { if ((*(sl+tot)==0) || (*(sl+tot)==1)) continue; if (*pcx==1) { *(sl+tot) = uc-1+*(sl+tot); } else *(sl+tot) = *(ul+tot); } else { if ((*(sl+(RL-1-tot))==0) || (*(sl+(RL-1-tot))==1)) continue; if (*pcx==1) { *(sl+(RL-1-tot)) = uc-1+*(sl+(RL-1-tot)); } else *(sl+(RL-1-tot)) = *(ul+(RL-1-tot)); } } pcx++; pcy = pcx; } } if ((Width>zw) && (rw)) { pcx = stp; for (r=0; rWidth; r++) { for (z=0; z=Rect.Right) break; if ((Rot==0) || (Rot==3)) { if ((*(sl+tot)==0) || (*(sl+tot)==1)) continue; if (*pcx==1) { *(sl+tot) = uc-1+*(sl+tot); } else *(sl+tot) = *(ul+tot); } else { if ((*(sl+(RL-tot))==0) || (*(sl+(RL-tot))==1)) continue; if (*pcx==1) { *(sl+(RL-tot)) = uc-1+*(sl+(RL-tot)); } else *(sl+(RL-tot)) = *(ul+(RL-tot)); } } pcx++; } } switch (Rot) { case 0: case 1: MainImageForm->iMainImage->Bitmap->PutScanLine(y); break; case 2: case 3: MainImageForm->iMainImage->Bitmap->PutScanLine(TB-1-y); break; } } ud->Bitmap->StopScanLine(); MainImageForm->iMainImage->Bitmap->StopScanLine(); return; fail: ud->Bitmap->StopScanLine(); MainImageForm->iMainImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::SubIRREEffect(TTexBitData *bip, TRect Rect, Byte zo, Byte Rot) { int x, y, j, w, rw, zr, tot, spt, zh, zw, uc; Byte z, r; Byte *sl, *ul, *ml, *lp; TUndoData *ud; Byte *stp, *temp, *pcx, *pcy; int Width, RL, TB, ec; stp = (Byte *) bip->pBitmap; pcy = stp; temp = stp; Width = Rect.Right-Rect.Left; Height = Rect.Bottom-Rect.Top; RL = Rect.Right+Rect.Left; TB = Rect.Top+Rect.Bottom; zw = bip->Width*zo; zh = bip->Height*zo; w = (Rect.Right-Rect.Left) / zw; rw = (Rect.Right-Rect.Left) % zw; if (w==0) w = 1; if ((ud = Undo->Last)==NULL) { ec = EC_UNDO_NONE; goto fail; } uc = MainImageForm->Palette->UseColor; if (!MainImageForm->iMainImage->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!MainImageForm->WorkArea->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!ud->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y= Rect.Bottom-1; y>=Rect.Top; y--) { if ((Rot==0) ||(Rot==1)) { sl = (Byte *) MainImageForm->iMainImage->Bitmap->GetScanLine(y); ul = (Byte *) ud->Bitmap->GetScanLine(y); ml = (Byte *) MainImageForm->WorkArea->Mask->GetScanLine(y-Rect.Top); } else { sl = (Byte *) MainImageForm->iMainImage->Bitmap->GetScanLine(TB-1-y); ul = (Byte *) ud->Bitmap->GetScanLine(TB-1-y); ml = (Byte *) MainImageForm->WorkArea->Mask->GetScanLine(Rect.Bottom-y); } spt = Rect.Bottom-1-y; if ((spt % zo)pBitmap; for (j=0; jWidth; r++) { zr = r*zo; for (z=0; z=Rect.Right) break; if ((Rot==0) || (Rot==3)) { if (*(ml+tot-Rect.Left)) { if ((*(sl+tot)==0) || (*(sl+tot)==1)) continue; if (*pcx==1) { *(sl+tot) = uc-1+*(sl+tot); } else *(sl+tot) = *(ul+tot); } } else { if (*(ml+Rect.Right-1-tot)) { if ((*(sl+(RL-1-tot))==0) || (*(sl+(RL-1-tot))==1)) continue; if (*pcx==1) { *(sl+(RL-1-tot)) = uc-1+*(sl+(RL-1-tot)); } else *(sl+(RL-1-tot)) = *(ul+(RL-1-tot)); } } } pcx++; pcy = pcx; } } if ((Width>zw) && (rw)) { pcx = stp; for (r=0; rWidth; r++) { for (z=0; z=Rect.Right) break; if ((Rot==0) || (Rot==3)) { if (*(ml+tot-Rect.Left)) { if ((*(sl+tot)==0) || (*(sl+tot)==1)) continue; if (*pcx==1) { *(sl+tot) = uc-1+*(sl+tot); } else *(sl+tot) = *(ul+tot); } } else { if (*(ml+Rect.Right-1-tot)) { if ((*(sl+(RL-tot))==0) || (*(sl+(RL-tot))==1)) continue; if (*pcx==1) { *(sl+(RL-tot)) = uc-1+*(sl+(RL-tot)); } else *(sl+(RL-tot)) = *(ul+(RL-tot)); } } } pcx++; } } switch (Rot) { case 0: case 1: MainImageForm->iMainImage->Bitmap->PutScanLine(y); break; case 2: case 3: MainImageForm->iMainImage->Bitmap->PutScanLine(TB-1-y); break; } } ud->Bitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); MainImageForm->iMainImage->Bitmap->StopScanLine(); return; fail: ud->Bitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); MainImageForm->iMainImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- bool __fastcall TJacquardForm::ComboNoMethod(TTexpiaBitmap *Pattern, TSize r) { TSize s; TRect Src, Re; RGBQUAD rgb[256]; if (MainImageForm->WorkArea->Mask) { Src = (TRect) MainImageForm->WorkArea->Range; s.cx = Src.Right - Src.Left; s.cy = Src.Bottom - Src.Top; } else { Src = Rect(0, 0, MainImageForm->iMainImage->Bitmap->Width, MainImageForm->iMainImage->Bitmap->Height); s.cx = MainImageForm->iMainImage->Bitmap->Width; s.cy = MainImageForm->iMainImage->Bitmap->Height; } MainImageForm->Palette->ToRGBQUAD(rgb, 256); if (!Pattern->Create(s.cx*r.cx, s.cy*r.cy, 8, rgb)) return false; Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); return Repeat_Method(r, s, Src, Pattern); } //--------------------------------------------------------------------------- bool __fastcall TJacquardForm::Repeat_Method(TSize r, TSize s, TRect Src, TTexpiaBitmap *Pattern) { TRect Dst; int x, y; HDC hd, dcDst = NULL; if ((dcDst = Pattern->CreateDC()) == NULL) goto fail; if ((hd = MainImageForm->iMainImage->Bitmap->CreateDC())==NULL) goto fail; for (y=0; yWorkArea->Mask) Irregularrect(Dst, Pattern->BitsPerPixel, dcDst); } } MainImageForm->iMainImage->Bitmap->DeleteDC(hd); Pattern->DeleteDC(dcDst); return true; fail: if (dcDst) Pattern->DeleteDC(dcDst); return false; } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::Irregularrect(TRect Dst, int bpp, HDC dcDst) { HDC hDC; RGBQUAD rgb[256]; TTexpiaBitmap *Mask = NULL; if (MainImageForm->iMainImage->Bitmap->BitsPerPixel==8) { if (bpp == 8) { MainImageForm->Palette->ToRGBQUAD(rgb, 256); Mask = MainImageForm->WorkArea->Mask; Mask->PutColors(0, 256, rgb); } else { Mask = new TTexpiaBitmap; if (!MainImageForm->WorkArea->GetMask(Mask, 1)) goto fail; } } hDC = Mask->CreateDC(); if (hDC) { SetStretchBltMode(dcDst, COLORONCOLOR); StretchBlt(dcDst, Dst.Left, Dst.Top, Dst.Right-Dst.Left, Dst.Bottom-Dst.Top, hDC, 0, 0, Mask->Width, Mask->Height, MERGEPAINT); Mask->DeleteDC(hDC); } if (Mask!=MainImageForm->WorkArea->Mask) ::doDestroy(Mask); return; fail: if (Mask!=MainImageForm->WorkArea->Mask) ::doDestroy(Mask); } //--------------------------------------------------------------------------- bool __fastcall TJacquardForm::ComboYesMethod(TTexpiaBitmap *Pattern) { TRect Src, Dst, Re, PDst; TTexpiaBitmap *UsedColBit = NULL; int w, h, temp, ht, width, height; RGBQUAD rgb[256]; HDC hd = NULL; TCanvas *Canvas = NULL, *UsedCanvas = NULL; if ((UsedColBit = new TTexpiaBitmap) == NULL ) goto fail; if (DrawUsedColor(UsedColBit)== false) goto fail; w = UsedColBit->Width*MainImageForm->CanvasInfor.DotsPerInch/160; h = UsedColBit->Height*MainImageForm->CanvasInfor.DotsPerInch/160; // {µÎ°³ÀÇ BitmapÀ» ÇÕÄ£ PatternÀÇ »õ·Î¿î ³ôÀÌ¿Í ³ÐÀÌ} ht = GetDeviceCaps(Printer()->Handle, VERTRES)*160/GetDeviceCaps(Printer()->Handle, LOGPIXELSY); if (MainImageForm->WorkArea->Mask) { Src = (TRect) MainImageForm->WorkArea->Range; width = Src.Right-Src.Left; height = Src.Bottom-Src.Top; } else { width = MainImageForm->iMainImage->Bitmap->Width; height = MainImageForm->iMainImage->Bitmap->Height; } temp = height; if (w>width) width = w; height = temp+h; if (height>ht) height = ht+h; if (!Pattern->Create(width, height, 24)) goto fail; // { White·Î PatternÀüü¸¦ ä¿ì±â } Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); if ((Canvas = Pattern->CreateCanvas()) == NULL) goto fail; if ((hd = MainImageForm->iMainImage->Bitmap->CreateDC()) == NULL) goto fail; if (hd) { if (MainImageForm->WorkArea->Mask) { Dst = Rect(0, 0, Src.Right-Src.Left, temp); BitBlt(Canvas->Handle, Dst.Left, Dst.Top, Dst.Right, Dst.Bottom, hd, Src.Left, Src.Top, SRCCOPY); Irregularrect(Dst, Pattern->BitsPerPixel, Canvas->Handle); } else { BitBlt(Canvas->Handle, 0, 0, MainImageForm->iMainImage->Bitmap->Width, MainImageForm->iMainImage->Bitmap->Height, hd, 0, 0, SRCCOPY); } MainImageForm->iMainImage->Bitmap->DeleteDC(hd); } else goto fail; PDst = Rect(0, temp , w, temp+h); if (Pattern->Height>ht) PDst = Rect(0, ht, w, ht+h); Src = Rect(0, 0, UsedColBit->Width, UsedColBit->Height); if ((UsedCanvas = UsedColBit->CreateCanvas()) == NULL) goto fail; Canvas->CopyMode = cmSrcCopy; Canvas->CopyRect(PDst, UsedCanvas, Src); UsedColBit->DeleteCanvas(UsedCanvas); Pattern->DeleteCanvas(Canvas); delete UsedColBit; return true; fail: if (hd) MainImageForm->iMainImage->Bitmap->DeleteDC(hd); if (Canvas) Pattern->DeleteCanvas(Canvas); if (UsedColBit) delete UsedColBit; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return false; } //--------------------------------------------------------------------------- bool __fastcall TJacquardForm::DrawUsedColor(TTexpiaBitmap *Pattern) { TChoiceColor *ChoiceColor = NULL; int i, j, k, l, row, tab, temph, toth; AnsiString NameStr; RGBQUAD rgb[256]; TRect BitRect, StrRect, Re; TCanvas *Canvas = NULL; if ((ChoiceColor = new TChoiceColor) == NULL) goto fail; if (MainImageForm->WorkArea->Mask) MainImageForm->SearchWorkAreaColor(ChoiceColor); else MainImageForm->SearchWholeColor(ChoiceColor); if (!Pattern->Create( GetDeviceCaps(Printer()->Handle, HORZRES)*160/GetDeviceCaps(Printer()->Handle, LOGPIXELSX), GetDeviceCaps(Printer()->Handle, VERTRES)*160/GetDeviceCaps(Printer()->Handle, LOGPIXELSY), 24)) goto fail; Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); if ((Canvas = Pattern->CreateCanvas()) == NULL) goto fail; l = (Pattern->Width-34) / 100 ; // Pattern Height Á¤Çϱâ row = 1+ChoiceColor->Count / l; temph = row*70+60; j = 0; k = 0; for (i=0; iCount; i++) { if ((i % l)==0) { j = i / l; k = 0; } BitRect = Rect(44+k*100, 30+j*70, 134+k*100, 80+j*70); PrintColorChip24(Pattern, BitRect, ChoiceColor->ColorMap[i]->RGB.rgbRed, ChoiceColor->ColorMap[i]->RGB.rgbGreen, ChoiceColor->ColorMap[i]->RGB.rgbBlue); switch (ChoiceColor->ColorMap[i]->Kind) { case 0: if (ChoiceColor->ColorMap[i]->Page==0) NameStr = Format("%d - %d - %d", OPENARRAY (TVarRec, (255-ChoiceColor->ColorMap[i]->RGB.rgbRed, 255-ChoiceColor->ColorMap[i]->RGB.rgbGreen, 255-ChoiceColor->ColorMap[i]->RGB.rgbBlue))); else NameStr = PrinterColor->PN2Code(ChoiceColor->ColorMap[i]->Page, ChoiceColor->ColorMap[i]->Number); break; case 3: NameStr = StandardColor->PN2Code(ChoiceColor->ColorMap[i]->Page, ChoiceColor->ColorMap[i]->Number); break; case 4: NameStr = TextileColor->PN2Code(ChoiceColor->ColorMap[i]->Page, ChoiceColor->ColorMap[i]->Number); break; case 0x10: case 0x13: case 0x14: NameStr = ChoiceColor->ColorMap[i]->ColorName; break; } StrRect = Rect(44+k*100, 80+j*70, 134+k*100, 100+j*70); tab = (90-Canvas->TextWidth(NameStr)) / 2; // Adjust Center if (tab<0) tab = 0; Canvas->Font->Size = 10; Canvas->Brush->Color = clWhite; Canvas->TextRect(StrRect, 44+tab+100*k, 82+j*70, NameStr); k = k+1; } Pattern->DeleteCanvas(Canvas); Canvas = NULL; toth = DrawPrtTexture(Pattern, temph); if (!Pattern->Resize(Pattern->Width, temph+toth+10, clWhite)) goto fail; delete ChoiceColor; return true; fail: if (Canvas) Pattern->DeleteCanvas(Canvas); if (ChoiceColor) delete ChoiceColor; return false; } //--------------------------------------------------------------------------- int __fastcall TJacquardForm::DrawPrtTexture(TTexpiaBitmap *bmp, int th) { int cw, ch, i, j, w, h, k, l, tab; TRect chip, StrRect, StrRect1; TTexBitData *bip; AnsiString str, str1; PTextureData jd; TCanvas *Canvas; w = (bmp->Width-60) / 7; h = w+30; cw = w-15; ch = cw; k = 0; j = 0; i = 0; for (l=0; lCount; l++) { jd = (PTextureData) store->Items[l]; if (jd->use) { if ((i % 7)==0) { k = 0; j = i / 7; } chip = Rect(37+w*k, th+h*j, 37+cw+w*k, th+ch+h*j); str = GeTTextureData(l, &bip); SubDrawPrtTexture(bmp, chip, bip, jd->zoom); Canvas = bmp->CreateCanvas(); tab = (cw - Canvas->TextWidth(str)) / 2; if (tab<0) tab = 0; StrRect = Rect(37+w*k, th+ch+h*j, 37+cw+w*k, th+ch+25+h*j); Canvas->Font->Color = clBlue; Canvas->TextRect(StrRect, tab+37+w*k, th+ch+5+h*j, str); str1 = Format("< %d: %d x %d >", OPENARRAY (TVarRec, (jd->num+1, bip->Width, bip->Height))); tab = (cw - Canvas->TextWidth(str1)) / 2; if (tab<0) tab = 0; StrRect1 = Rect(37+w*k, th+ch+25+h*j, 37+cw+w*k, th+h*(j+1)); Canvas->Font->Color = clBlack; Canvas->TextRect(StrRect1, tab+37+w*k, th+ch+25+h*j, str1); LineTexptr(Canvas, chip, jd->zoom, bip); bmp->DeleteCanvas(Canvas); k++; i++; } } return h * ((i / 7) + 1); } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::SubDrawPrtTexture(TTexpiaBitmap *bmp, TRect Rect, TTexBitData *bip, Byte zm) { int x, y, j, w, rw, zr, tot, spt, zh, zw, chipw; Byte z, r; Byte *sl; Byte *stp, *temp, *pcx, *pcy; stp = bip->pBitmap; pcy = stp; temp = stp; chipw = Rect.Right-Rect.Left; zw = bip->Width*zm; zh = bip->Height*zm; w = chipw / zw; rw = chipw % zw; if (w==0) w = 1; bmp->StartScanLine(); for (y=Rect.Bottom-1; y>=Rect.Top; y--) { sl = (Byte *) bmp->GetScanLine(y) + Rect.Left*3; spt = Rect.Bottom-1-y; if ((spt % zm)pBitmap; for (j=0; jWidth; r++) { zr = r*zm; for (z=0; z=Rect.Right) break; if (*pcx==1) *sl = *(sl+1) = *(sl+2) = 0; else *sl = *(sl+1) = *(sl+2) = 255; } pcx++; pcy = pcx; } } if ((chipw>zw) && (rw)) { pcx = stp; for (r=0; rWidth; r++) { for (z=0; z=Rect.Right) break; if (*pcx==1) *sl = *(sl+1) = *(sl+2) = 0; else *sl = *(sl+1) = *(sl+2) = 255; } pcx++; } } bmp->PutScanLine(y); } bmp->StopScanLine(); } //--------------------------------------------------------------------------- AnsiString __fastcall TJacquardForm::GeTTextureData(Byte i, TTexBitData **bip) { Byte Ind, num; TFound *fd; TDeriv *dt; TSpecial *sp; PTextureData jd; jd = (PTextureData)store->Items[i]; switch (jd->Itm) { case 0: FoundDrawData(jd, Ind, num); fd = (TFound *)TextureForm->Texture->f[jd->pts]->Items[Ind]; *bip = (TTexBitData *) fd->data->Items[num]; return Format("< %d x %d >", OPENARRAY (TVarRec, (fd->size, fd->size))); case 1: DerivDrawData(jd, Ind, num); dt = (TDeriv *) TextureForm->Texture->d[jd->pts]->Items[Ind]; *bip = (TTexBitData *) dt->data->Items[num]; return Format("< %s >", OPENARRAY(TVarRec, (dt->name))); case 2: SpecialDrawData(jd, Ind, num); sp = (TSpecial *) TextureForm->Texture->s->Items[Ind]; *bip = (TTexBitData *) sp->data->Items[num]; return Format("< %s >", OPENARRAY(TVarRec, (sp->name))); } return ""; } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::LineTexptr(TCanvas *cv, TRect Rect, Byte i, TTexBitData *bip) { int w, h, x, y, vj, wid, hei; wid = Rect.Right - Rect.Left; hei = Rect.Bottom - Rect.Top; w = bip->Width*i; h = bip->Height*i; for (x=0; xPen->Color = clRed; cv->MoveTo(Rect.Left+x, Rect.Top); cv->LineTo(Rect.Left+x, Rect.Bottom); } } for (y=hei-1; y>=0; y--) { vj = hei-1-y; if ((vj % h)==0) { cv->Pen->Color = clRed; cv->MoveTo(Rect.Left, Rect.Bottom-1-vj); cv->LineTo(Rect.Right, Rect.Bottom-1-vj); } } cv->Pen->Color = clBlack; cv->MoveTo(Rect.Left, Rect.Top); cv->LineTo(Rect.Left, Rect.Bottom); cv->LineTo(Rect.Right, Rect.Bottom); cv->LineTo(Rect.Right, Rect.Top); cv->LineTo(Rect.Left, Rect.Top); } //--------------------------------------------------------------------------- bool __fastcall TJacquardForm::Load_File(AnsiString FileName, int Index, TTexpiaBitmap *pBitmap, TPalette *pPalette, TPCanvasInfor &pi) { TEXPIAFILEHEADER tpfh; int i, ec = EC_NONE; bool sw; TJaqdFiledata tjfd; TJtxtData jtxt; PTextureData jd = NULL; short wid, hei; HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwRead; if ((hFile = CreateFile(FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_OPEN; goto fail; } if ((ec = LoadFromTexpiaFile(hFile, pPalette, tpfh, pBitmap))!=EC_NONE) goto fail; UserColorLibForm->ThisFileHasUserColor(pPalette); pi = tpfh.CanvasInfor; if (tpfh.Version.Method == 'T') { if (tpfh.Version.Number < 200) sw = true; else sw = false; } else sw = true; if (sw) { if (!ReadFile(hFile, &(tjfd.base), 1, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &(tjfd.tcnt), 1, &dwRead, NULL)) goto fail; if (tjfd.tcnt) { for (i=0; iItm = jtxt.g[0]; jd->pts = jtxt.g[1]; jd->Ind = jtxt.g[2]; jd->num = jtxt.g[3]; jd->name = AnsiString(jtxt.name); jd->use = true; jd->zoom = 3; jd->Rot = jtxt.mode; jd->disname = Format("%d", OPENARRAY (TVarRec, (jd->num+1))); store->Add(jd); } } } else { if (!ReadFile(hFile, &(tjfd.tcnt), 1, &dwRead, NULL)) goto fail; for (i=0; iItm), 1, &dwRead, NULL)) goto fail; if ( !ReadFile(hFile, &(jd->pts), 1, &dwRead, NULL)) goto fail; if ( !ReadFile(hFile, jtxt.name, 22, &dwRead, NULL)) goto fail; //window¿¡¼­´Â jd^.Ind¸¦ ´ë½ÅÇÑ´Ù. jd->name = AnsiString(jtxt.name); if ( !ReadFile(hFile, jtxt.name, 22, &dwRead, NULL)) goto fail; jd->disname = AnsiString (jtxt.name); //window¿¡¼­´Â jd^.num¸¦ ´ë½ÅÇÑ´Ù. if ( !ReadFile(hFile, &(jd->Rot), 1, &dwRead, NULL)) goto fail; if ( !ReadFile(hFile, &(jd->zoom), 1, &dwRead, NULL)) goto fail; jd->use = true; store->Add(jd); } } CloseHandle(hFile); if (store->Count>0) mm = true; ImgScrollBar->Max = store->Count-1; ImgScrollBar->Position = store->Count-1; ImgChange(store->Count-1); InitFunc(0); return true; fail: if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_READ; EXCEPTION_MESSAGE_OK(ec); return false; } //--------------------------------------------------------------------------- TPException __fastcall TJacquardForm::Save_File(AnsiString FileName, int Index, TCompressMethod cm) { HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwWrite; int lim, i, ec = EC_NONE; TEXPIAFILEHEADER tpfh; TRect src; RGBQUAD rgb[256]; Byte cnt; char jtxt[22]; PTextureData jd; HDC dcSrc = NULL; TTexpiaBitmap *tag = NULL; if ((hFile = CreateFile(FileName.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', 222); tpfh.CanvasInfor = MainImageForm->CanvasInfor; tpfh.BitsPerPixel = 8; tpfh.Compress = cm; if (MainImageForm->WorkArea->Mask) { src = MainImageForm->WorkArea->Range; tpfh.CanvasInfor.DotsPerInch = tpfh.CanvasInfor.DotsPerInch; tpfh.CanvasInfor.SetSize(cstFree, src.Right-src.Left, src.Bottom-src.Top); } else { src.Left = 0; src.Top = 0; src.Right = MainImageForm->iMainImage->Bitmap->Width; src.Bottom = MainImageForm->iMainImage->Bitmap->Height; } MainImageForm->Palette->ToRGBQUAD(rgb, 256); if ((tag = new TTexpiaBitmap) == NULL) { ec = EC_MEMORY_LACK; goto fail; } MakeTexpiaTag(tag, MainImageForm->iMainImage->Bitmap, src, 0); if (MainImageForm->WorkArea && MainImageForm->WorkArea->Mask) { if (!SaveToTexpiaFile(hFile, MainImageForm->Palette, tpfh, tag, MainImageForm->iMainImage->Bitmap, &MainImageForm->WorkArea->Range)) goto fail; } else { if (!SaveToTexpiaFile(hFile, MainImageForm->Palette, tpfh, tag, MainImageForm->iMainImage->Bitmap)) goto fail; } delete tag; tag = NULL; lim = store->Count-1; cnt = 0; for (i=0; i<=lim; i++) { jd = (PTextureData) store->Items[i]; if (jd->use) cnt = cnt+1; } if (!WriteFile(hFile, &cnt, 1, &dwWrite, NULL)) goto fail; for (i=0; i<=lim; i++) { jd = (PTextureData) store->Items[i]; if (jd->use) { if (!WriteFile(hFile, &jd->Itm, 1, &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &jd->pts, 1, &dwWrite, NULL)) goto fail; StrCopy(jtxt, jd->name.c_str()); if (!WriteFile(hFile, jtxt, 22, &dwWrite, NULL)) goto fail; //window¿¡¼­´Â jd^.Ind¸¦ ´ë½ÅÇÑ´Ù. StrCopy(jtxt, jd->disname.c_str()); if (!WriteFile(hFile, jtxt, 22, &dwWrite, NULL)) goto fail; //window¿¡¼­´Â jd^.num¸¦ ´ë½ÅÇÑ´Ù. if (!WriteFile(hFile, &jd->Rot, 1, &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &jd->zoom, 1, &dwWrite, NULL)) goto fail; } } CloseHandle(hFile); return EC_NONE; fail: if (tag) delete tag; if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_WRITE; return ec; } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::OpenImage(TObject *Sender) { TPSelectImage *Image = (TPSelectImage *)Sender; TPoint p; RECT rc; if (Image->Width==MainImageForm->Panel->Width) { p.x = MainImageForm->iMainImage->PositionX-Image->PositionX; } else { p.x = MainImageForm->iMainImage->CanvasToBitmapX(Image->Left); } if (Image->Height==MainImageForm->Panel->Height) { p.y = MainImageForm->iMainImage->PositionY-Image->PositionY; } else { p.y = MainImageForm->iMainImage->CanvasToBitmapY(Image->Top); } rc = Rect(p.x, p.y, p.x+Image->Bitmap->Width, p.y+Image->Bitmap->Height); MainImageForm->iMainImage->Bitmap->CopyToRect(rc.left, rc.top, Image->Bitmap, SRCCOPY); MainImageForm->WorkArea->SetRectangle(rc); MainImageForm->WorkAreaChange(); PaletteForm->DIB256Palette->ChoiceIndex = 2; Image->Bitmap->Destroy(); Image->Visible = false; ::RepaintColor(); Item = 0; } //--------------------------{Public Method}---------------------------------- void __fastcall TJacquardForm::InitForm() { RGBQUAD rgb[2]; ParentHeight = Parent->Height+20; ClientHeight = 223; Parent->Height = ParentHeight+ClientHeight; TextureForm = new TTextureForm(MainForm); if (TextureForm->InitForm() == false) goto fail; TextureForm->Parent = MainForm; TextureForm->Visible = true; TextureForm->OnChange = TextureOnChange; store = new TList; IniTTextureData(); RunRearrange(); ColIndex = MainImageForm->Palette->UseColor+1; U_Col = MainImageForm->Palette->UseColor; MainImageForm->Palette->ColorData[ColIndex]->RGB.rgbRed = 0; MainImageForm->Palette->ColorData[ColIndex]->RGB.rgbBlue = 0; MainImageForm->Palette->ColorData[ColIndex]->RGB.rgbGreen = 0; PaletteForm->DIB256Palette->ChoiceIndex = ColIndex; PaletteForm->DIB256Palette->Repaint(); TextureButton->Down = true; Effect = false; DrawGImage(); sep = true; //Effect fill¿¡¼­ ÆÈ·¹Æ®¼ö¸¦ Ãʰú½Ã false setPalette¸¦ Åë°ú.; Item = 0; Bitmap = new Graphics::TBitmap; Bitmap->PixelFormat = pf8bit; Bitmap->Width = Image->Width; Bitmap->Height = Image->Height; if (Bitmap->Empty) goto fail; 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(Bitmap->Canvas->Handle, 0, 2, rgb); ReadJacIni(); return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::ExitForm() { TextureForm->Visible = false; PTextureData jd; WriteJacIni(); while (store->Count>0) { jd = (PTextureData)store->Last(); store->Remove(jd); delete jd; } if (store) delete store; if (Bitmap) delete Bitmap; if (TextureForm) delete TextureForm; } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::TextureOnChange(TObject *Sender) { PTextureData jd; TFound *fd; TDeriv *dt; TSpecial *sp; TTexBitData *bip; TTextureForm *Form = (TTextureForm*) Sender; jd = new TTextureData; jd->Itm = Form->Item; jd->pts = Form->ptsItem; switch (Form->Item) { case 0: fd = (TFound *) TextureForm->Texture->f[Form->ptsItem]->Items[Form->Index]; jd->name = Format("%d x %d", OPENARRAY (TVarRec, (fd->size, fd->size))); jd->Ind = Form->Index; jd->num = Form->TextureGrid->Row*Form->TextureGrid->ColCount+Form->TextureGrid->Col; bip = (TTexBitData *)fd->data->Items[jd->num]; jd->disname = AnsiString(bip->Name); break; case 1: dt = (TDeriv *) TextureForm->Texture->d[Form->ptsItem]->Items[Form->Index]; jd->name = AnsiString (dt->name); jd->Ind = Form->Index; jd->num = Form->TextureGrid->Row*Form->TextureGrid->ColCount+Form->TextureGrid->Col; bip = (TTexBitData *)dt->data->Items[jd->num]; jd->disname = AnsiString(bip->Name); break; case 2: sp = (TSpecial *) TextureForm->Texture->s->Items[Form->Index]; jd->name = AnsiString (sp->name); jd->Ind = Form->Index; jd->num = Form->TextureGrid->Row*Form->TextureGrid->ColCount+Form->TextureGrid->Col; bip = (TTexBitData *)sp->data->Items[jd->num]; jd->disname = AnsiString(bip->Name); break; } jd->zoom = StrToInt(Form->ZoEdit->Text); jd->use = false; jd->Rot = 0; FindData(jd); if (find==false) { store->Add(jd); ImgScrollBar->Enabled = true; ImgScrollBar->Max = store->Count-1; ImgScrollBar->Position = store->Count-1; ImgChange(store->Count-1); InitFunc(0); mm = true; } find = false; } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::iMainImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { PTextureData jd; if (mm) { if ((Button==mbLeft) && (IsDraw)) { MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->Bitmap->Width, MainImageForm->iMainImage->Bitmap->Height)); FillColor = MainImageForm->iMainImage->Bitmap->GetPixelColor(X, Y); First = Point(X, Y); jd = (PTextureData) store->Items[ImgScrollBar->Position]; jd->use = true; switch (Select) { case 0: SelectColorFill(); break; case 1: AreaFill(); break; case 2: EffectFill(); if (sep) { U_Col = MainImageForm->Palette->UseColor; MainImageForm->Palette->UseColor = MainImageForm->Palette->UseColor*2-1; SetPaletteColor(); } else jd->use = false; draw = true; break; } ::RepaintColor(); } } else { Sysutils::Beep(); MessageDlg(IDS_MESSAGE_NOTEXTURE, mtWarning, TMsgDlgButtons()<iMainImage->Cursor = crCross; MainImageForm->IsMerge(MainImageForm->iSelectImagePosition(Point(X-MainImageForm->Center.x, Y-MainImageForm->Center.y))); } } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::iSelectImageMouseDown(TObject *Sender, int X, int Y) { if (Item==1) { MainImageForm->IsMerge(MainImageForm->iSelectImagePosition( MainImageForm->iSelectImageConvert(X, Y))); OpenImage(Sender); FGChange(PaletteForm->DIB256Palette->ChoiceIndex); } } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::iSelectImageMouseMove(TObject *Sender, int X, int Y) { if (Item==1) { MainImageForm->IsMerge(MainImageForm->iSelectImagePosition( MainImageForm->iSelectImageConvert(X, Y))); } } //--------------------------------------------------------------------------- void __fastcall TJacquardForm::FGChange(int Value) { ColIndex = Value; shEffect->Brush->Color = RGB2TColor(MainImageForm->Palette->ColorData[Value]->RGB.rgbRed, MainImageForm->Palette->ColorData[Value]->RGB.rgbGreen, MainImageForm->Palette->ColorData[Value]->RGB.rgbBlue); } //--------------------------------------------------------------------------- TPException __fastcall TJacquardForm::JQDOnRead(TFMReadParameter rp) { TRect r; TPCanvasInfor pi; MainImageForm->WorkAreaReset(true); r = Rect(0, 0, MainImageForm->iMainImage->Bitmap->Width, MainImageForm->iMainImage->Bitmap->Height); MainImageForm->UndoSave(UK_ALL, r); IniTTextureData(); // Jacquard TextureÀÇ Store ¸¦ ºñ¿î´Ù. if (!Load_File(rp.FileName, rp.ExtIndex, MainImageForm->iSelectImage->Bitmap, MainImageForm->Palette, pi)) return EC_FILE_NOT_READ; MainImageForm->iMainImage->Bitmap->FillRect(r, PALETTEINDEX(BackgroundColor)); if ((MainImageForm->iSelectImage->Bitmap->Width>MainImageForm->iMainImage->Bitmap->Width) ||(MainImageForm->iSelectImage->Bitmap->Height>MainImageForm->iMainImage->Bitmap->Height) ||(MainImageForm->CanvasInfor.DotsPerInch!=pi.DotsPerInch)) { Undo->RemoveAll(); pi.SetSize(cstFree, MainImageForm->iSelectImage->Bitmap->Width, MainImageForm->iSelectImage->Bitmap->Height); MainImageForm->ResizePattern(pi, 8); } MainImageForm->iMainImage->Bitmap->FillRect(r, PaletteForm->DIB256Palette->GetBGCOLORREF(MainImageForm->iMainImage->Bitmap->BitsPerPixel)); MainImageForm->Center.x = MainImageForm->iSelectImage->Bitmap->Width / 2; MainImageForm->Center.y = MainImageForm->iSelectImage->Bitmap->Height / 2; MainImageForm->iSelectImageSize(); MainImageForm->iSelectImage->Visible = true; MainImageForm->iSelectImage->Repaint(); ::RepaintColor(); Item = 1; return EC_NONE; } //--------------------------------------------------------------------------- AnsiString __fastcall TJacquardForm::JQDOnFileName(AnsiString FileName, TGraphicFileFormat ExtIndex) { PChar s = AnsiStrScan(FileName.c_str(), '.'); if (s==NULL) { AnsiString fn = FileName+".jqd"; return fn; } else { return FileName; } } //--------------------------------------------------------------------------- TPException __fastcall TJacquardForm::JQDOnSave(AnsiString DirName, AnsiString FileName, TGraphicFileFormat ExtIndex, TCompressMethod cm) { return Save_File(FileName, ExtIndex, cm); } //---------------------------------------------------------------------------