//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "TextureArrange_F.h" #include "MainImage.h" #include "Texture_F.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "TPImage" #pragma link "TPRuler2D" #pragma link "TPWeaveImage" #pragma link "TPSelectImage" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define PATTERN 8 #define IDS_TEXTUREARRANGE StringTable[0] #define IDS_CHOSENTEXTURE StringTable[1] #define IDS_TABLEVIEW StringTable[2] #define IDS_TEXTUREARRAY StringTable[3] #define IDS_INSERT StringTable[4] #define IDS_TOTALSIZE StringTable[5] #define IDS_CODE StringTable[6] #define IDS_TEXTURESIZE StringTable[7] #define IDS_NEW StringTable[8] #define IDS_MODE StringTable[9] #define IDS_NORMAL StringTable[10] #define IDS_ADVANCED StringTable[11] #define IDS_WARP StringTable[12] #define IDS_WEFT StringTable[13] TTextureArrangeForm *TextureArrangeForm; //--------------------------------------------------------------------------- __fastcall TTextureArrangeForm::TTextureArrangeForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::FormCreate(TObject *Sender) { TIniFile *IniFile; int w, h; //================================================= StringTable.Create(DirectoryItem, Language, "TextureArrange"); SetSmallFont(Font); Caption = IDS_TEXTUREARRANGE; Label3->Caption = IDS_CHOSENTEXTURE; sbChoiceNew->Caption = IDS_NEW; sbChoiceDelete->Caption = IDS_COMMON_DELETE; sbTableView->Caption = IDS_TABLEVIEW; sbArrangeNew->Caption = IDS_NEW; sbArrangeInsert->Caption = IDS_INSERT; sbArrangeDelete->Caption = IDS_COMMON_DELETE; rgDot->Caption = IDS_COMMON_DRAW; rgDot->Items->Strings[0] = IDS_COMMON_BUTTONYES; rgDot->Items->Strings[1] = IDS_COMMON_BUTTONNO; GroupBox2->Caption = IDS_COMMON_SIZE; btnRun->Caption = IDS_COMMON_BUTTONOK; btnCancel->Caption = IDS_COMMON_BUTTONCANCEL; rgMode->Caption = IDS_MODE; rgMode->Items->Strings[0] = IDS_NORMAL; rgMode->Items->Strings[1] = IDS_ADVANCED; Label4->Caption = IDS_WARP; Label5->Caption = IDS_WEFT; //================================================= rgb[0].rgbRed = 255; rgb[0].rgbGreen = 255; rgb[0].rgbBlue = 255; rgb[1].rgbRed = 0; rgb[1].rgbGreen = 0; rgb[1].rgbBlue = 0; rgb[2].rgbRed = 255; rgb[2].rgbGreen = 0; rgb[2].rgbBlue = 0; rgb[3].rgbRed = 0; rgb[3].rgbGreen = 255; rgb[3].rgbBlue = 0; rgb[4].rgbRed = 0; rgb[4].rgbGreen = 0; rgb[4].rgbBlue = 255; rgb[5].rgbRed = 0; rgb[5].rgbGreen = 255; rgb[5].rgbBlue = 255; rgb[6].rgbRed = 255; rgb[6].rgbGreen = 0; rgb[6].rgbBlue = 255; rgb[7].rgbRed = 255; rgb[7].rgbGreen = 255; rgb[7].rgbBlue = 0; TextureForm->OnChange = TextureArrangeOnChange; Bitmap = new Graphics::TBitmap; //StringGrid¿¡ µé¾î°¡´Â Bitmap »ý¼º Bitmap->PixelFormat = pf8bit; Bitmap->Width = ChoiceDataGrid->DefaultColWidth; Bitmap->Height = ChoiceDataGrid->DefaultRowHeight-20; if(Bitmap->Empty) goto fail; SetDIBColorTable(Bitmap->Canvas->Handle, 0, 2, rgb); TextureUndo = new TSimpleUndo; TextureUndo->Set(TextureImage->Bitmap, NULL); windraw = false; Down = false; isFirst = true; MainImageForm->Plan->Texture->bFinish = false; IniFile = new TIniFile(DirectoryItem + "\\TextureArrange.ini"); if (IniFile) { w = IniFile->ReadInteger("PatternSize", "Warp", 50); h = IniFile->ReadInteger("PatternSize", "Weft", 50); delete IniFile; } if(TextureImage->Bitmap->Create(w, h, 8, rgb) == false) goto fail; TextureImage->Bitmap->CoordinateSystem = csBottomLeft; TextureImage->SetZoom(8, 1); CurrentZoom = 4; Ruler->Zoom = 8; ScrollBarEnabled(); if (MainImageForm->Plan->Texture->ChoiceCount > 0) InitChoiceButton(1); if (MainImageForm->Plan->Texture->bNormal) { rgMode->ItemIndex = 0; pnNormal->BringToFront(); if (MainImageForm->Plan->Texture->Array->Count) { InitArrayButton(1); PatternDataToBitmap(); } } else { rgMode->ItemIndex = 1; pnAdvanced->BringToFront(); EditCol->Text = w; EditRow->Text = h; if(MainImageForm->Plan->Texture->Choice[PATTERN].data) { PatternDataToBitmap(); rgMode->Enabled = false; } } ChangeTotalSize(); return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::FormDestroy(TObject *Sender) { if (rgMode->ItemIndex == 0) { if (MainImageForm->Plan->Texture->ChoiceCount > 0) { MainImageForm->Plan->Texture->bFinish = true; if (MainImageForm->Plan->Texture->Array->Count == 0) { MainImageForm->Plan->Texture->AddArray(1, 1); ArrayToBitmap(); BitmapToData(); } else BitmapToData(); } } else { if (IsData()) { BitmapToData(); MainImageForm->Plan->Texture->bFinish = true; } } TIniFile *IniFile = new TIniFile(DirectoryItem + "\\TextureArrange.ini"); if (IniFile) { IniFile->WriteInteger("PatternSize", "Warp", StrToInt(EditCol->Text)); IniFile->WriteInteger("PatternSize", "Weft", StrToInt(EditRow->Text)); delete IniFile; } delete Bitmap; Bitmap = NULL; delete TextureUndo; TextureUndo = NULL; return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- bool __fastcall TTextureArrangeForm::IsData() { BYTE *tp; bool isData = false; TextureImage->Bitmap->StartScanLine(); for (int i = 0; i < TextureImage->Bitmap->Height; i++) { tp = (BYTE *)TextureImage->Bitmap->GetScanLine(i); for (int j = 0; j < TextureImage->Bitmap->Width; j++) { if (*(tp+j) == 1) { isData = true; goto next;} } } next: TextureImage->Bitmap->StopScanLine(); return isData; } //---------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::sbNewClick(TObject *Sender) { if (windraw) return; Byte *TP; int y; TextureUndo->Save(Rect(0, 0, TextureImage->Bitmap->Width, TextureImage->Bitmap->Height)); if (TextureImage->Bitmap->StartScanLine() == false) goto fail; for (y = 0; y < TextureImage->Bitmap->Height; y++) { TP = TextureImage->Bitmap->GetScanLine(y); memset(TP, 0, TextureImage->Bitmap->Width); TextureImage->Bitmap->PutScanLine(y); } TextureImage->Bitmap->StopScanLine(); if (MainImageForm->Plan->Texture->Choice[PATTERN].data) { MainImageForm->Plan->Texture->DeleteChoiceBitData(PATTERN); } rgMode->Enabled = true; ScrollBarEnabled(); TextureImage->Repaint(); return; fail: TextureImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::EditKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if (Key == VK_RETURN) { if (Sender == EditCol) { EditRow->SetFocus(); EditRow->SelectAll(); } else if (Sender == EditRow) { btnRun->SetFocus(); } } } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::btnRunClick(TObject *Sender) { TTexpiaBitmap *TempBitmap; int w, h, sw, sh, dx; HDC dcSrc, dcDst; w = StrToInt(EditCol->Text); h = StrToInt(EditRow->Text); sw = TextureImage->Bitmap->Width; sh = TextureImage->Bitmap->Height; TempBitmap = new TTexpiaBitmap; TempBitmap->Create(sw, sh, 8, rgb); TempBitmap->Copy(TextureImage->Bitmap, SRCCOPY); RecreateBitmap(w, h); if (w < sw) dx = w; else dx = sw; dcSrc = TempBitmap->CreateDC(); dcDst = TextureImage->Bitmap->CreateDC(); if (h < sh) { BitBlt(dcDst, 0, 0, dx, h, dcSrc, 0, sh - h, SRCCOPY); } else { BitBlt(dcDst, 0, h - sh, dx, sh, dcSrc, 0, 0, SRCCOPY); } TextureImage->Bitmap->DeleteDC(dcDst); TempBitmap->DeleteDC(dcSrc); delete TempBitmap; btnRun->Enabled = false; btnCancel->Enabled = false; rgMode->Enabled = true; ScrollBarEnabled(); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::btnCancelClick(TObject *Sender) { EditCol->Text = TextureImage->Bitmap->Width; EditRow->Text = TextureImage->Bitmap->Height; btnRun->Enabled = false; btnCancel->Enabled = false; } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::EditChange(TObject *Sender) { btnRun->Enabled = true; btnCancel->Enabled = true; } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::EditClick(TObject *Sender) { TEdit *sp = (TEdit *) Sender; sp->SetFocus(); sp->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::sbZoomClick(TObject *Sender) { TSpeedButton *sb = (TSpeedButton *) Sender; if (sb->Tag) { CurrentZoom++; if (CurrentZoom > 5) CurrentZoom = 5; } else { CurrentZoom--; if (CurrentZoom < 1) CurrentZoom = 1; } switch (CurrentZoom) { case 1: TextureImage->SetZoom(1, 1); ZoomText->Caption = "1"; Ruler->Zoom = 1; break; case 2: TextureImage->SetZoom(2, 1); ZoomText->Caption = "2"; Ruler->Zoom = 2; break; case 3: TextureImage->SetZoom(4, 1); ZoomText->Caption = "3"; Ruler->Zoom = 4; break; case 4: TextureImage->SetZoom(8, 1); ZoomText->Caption = "4"; Ruler->Zoom = 8; break; case 5: TextureImage->SetZoom(16, 1); ZoomText->Caption = "5"; Ruler->Zoom = 16; break; } ScrollBarEnabled(); ChoiceDataGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::ScrollBarHScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { TextureImage->PositionX = ScrollBarH->Position; Ruler->StartX = ScrollBarH->Position; } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::ScrollBarVScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { TextureImage->PositionY = ScrollBarV->Max - ScrollBarV->Position; Ruler->StartY = ScrollBarV->Max - ScrollBarV->Position; } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::ScrollBarEnabled() { int w, h; w = TextureImage->Bitmap->Width * TextureImage->ZoomIn; if (TextureImage->Width < w) { ScrollBarH->Enabled = true; ScrollBarH->Max = (w - TextureImage->Width) / TextureImage->ZoomIn +1; TextureImage->PositionX = 0; Ruler->StartX = 0; } else { ScrollBarH->Enabled = false; TextureImage->PositionX = 0; } h = TextureImage->Bitmap->Height * TextureImage->ZoomIn; if (TextureImage->Height < h) { ScrollBarV->Enabled = true; ScrollBarV->Max = (h - TextureImage->Height) / TextureImage->ZoomIn +1; ScrollBarV->Position = ScrollBarV->Max; TextureImage->PositionY = 0; Ruler->StartY = 0; } else { ScrollBarV->Enabled = false; TextureImage->PositionY = 0; } } //---------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::sbChoiceNewClick(TObject *Sender) { TTextureArray *texarray; int i; if (MainImageForm->Plan->Texture->ChoiceCount > 0) { for (i = 0; i < MainImageForm->Plan->Texture->ChoiceCount; i++) { MainImageForm->Plan->Texture->Choice[i].group1 = 3; // 0, 1, 2 Áß ¾î´À°Íµµ ¾Æ´ÔÀ» ³ªÅ¸³¿. MainImageForm->Plan->Texture->DeleteChoiceBitData(i); } } MainImageForm->Plan->Texture->ClearArray(); MainImageForm->Plan->Texture->ChoiceCount = 0; if (MainImageForm->Plan->Texture->ChoiceCount > 0) InitChoiceButton(1); ChoiceDataGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::sbTableViewClick(TObject *Sender) { TextureForm->Visible = sbTableView->Down; } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::ChoiceDataGridClick( TObject *Sender) { int w, h, col = ChoiceDataGrid->Col; if (sbChoiceDelete->Down) { if (MainImageForm->Plan->Texture->ChoiceCount > col) { ChangeChoiceData(col); MainImageForm->Plan->Texture->ChoiceCount--; if (rgMode->ItemIndex == 0) { ChangeArrayData(col); if (MainImageForm->Plan->Texture->Array->Count == 0){ TIniFile *IniFile = new TIniFile(DirectoryItem + "\\TextureArrange.ini"); if (IniFile) { w = IniFile->ReadInteger("PatternSize", "Warp", 50); h = IniFile->ReadInteger("PatternSize", "Weft", 50); delete IniFile; } RecreateBitmap(w, h); } else { ArrayToBitmap(); } } ChoiceDataGrid->Repaint(); } sbChoiceDelete->Down = false; } if (MainImageForm->Plan->Texture->ChoiceCount == 0) { InitChoiceButton(0); } } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::sbUndoClick(TObject *Sender) { /* if (sbUndo->Tag) { 2 sbUndo->Hint = IDS_REDO; sbUndo->Tag = 0; } else { sbUndo->Hint = IDS_COMMON_UNDO; sbUndo->Tag = 1; } */ if (windraw) return; TextureUndo->Read(Rect(0, 0, TextureImage->Bitmap->Width, TextureImage->Bitmap->Height)); TextureImage->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::TextureImageMouseDown( TObject *Sender, TMouseButton Button, TShiftState Shift, int X,int Y) { X = (X/TextureImage->ZoomIn + TextureImage->PositionX )%TextureImage->Bitmap->Width+1; Y = ((TextureImage->Height - Y)/TextureImage->ZoomIn + TextureImage->PositionY )%TextureImage->Bitmap->Height+1; if(X > TextureImage->Bitmap->Width || Y > TextureImage->Bitmap->Height) return; if(MainImageForm->Plan->Texture->bNormal == false){ rgMode->Enabled = false; if(rgDot->ItemIndex == 1){ if(MainImageForm->Plan->Texture->Choice[ChoiceDataGrid->Col].data){ if (step == 0) { First = Point(X, Y); Second = Point(X,Y); step = 1; windraw = false; rgDot->Enabled = false; } else { step = 0; if (windraw) { RangeDraw(); windraw = false; rgDot->Enabled = true; } if((First.x != Second.x) && (First.y != Second.y)) InputTexture(); } TextureImage->Repaint(); } }else{ TextureUndo->Save(Rect(0, 0, TextureImage->Bitmap->Width, TextureImage->Bitmap->Height)); if(Button == mbLeft) Color = 1; //black else if(Button == mbRight) Color = 0; //white Down = true; DrawDot(X, Y); } } } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::TextureImageMouseMove( TObject *Sender, TShiftState Shift, int X, int Y) { int cx = 0, cy = 0; X = (X/TextureImage->ZoomIn + TextureImage->PositionX)%TextureImage->Bitmap->Width+1; Y = ((TextureImage->Height - Y)/TextureImage->ZoomIn + TextureImage->PositionY)%TextureImage->Bitmap->Height+1; if(X>TextureImage->Bitmap->Width || Y>TextureImage->Bitmap->Height || X< 1 || Y<1) return; StatusBar->Panels->Items[0]->Text = Format(" %d :%d",OPENARRAY(TVarRec,(X, Y))); if(MainImageForm->Plan->Texture->bNormal == false){ if(rgDot->ItemIndex == 1){ if(step == 1){ if (X == First.x || Y == First.y) return; int gapx = MainImageForm->Plan->Texture->Choice[ChoiceDataGrid->Col].width; int gapy = MainImageForm->Plan->Texture->Choice[ChoiceDataGrid->Col].height; if (windraw) { RangeDraw(); } if (X - First.x > 0) { cx = (X - First.x + 1) / gapx; if (cx == 0) cx = 1; } else if (X - First.x < 0) { cx = (X - First.x - 1) / gapx; if (cx == 0) cx = -1; } if (Y - First.y > 0) { cy = (Y - First.y + 1) / gapy; if (cy == 0) cy = 1; } else if (Y - First.y < 0) { cy = (Y - First.y - 1) / gapy; if (cy == 0) cy = -1; } if (cx > 0) Second.x = First.x + gapx * cx - 1; else if (cx < 0) Second.x = First.x + gapx * cx + 1; if (cy > 0) Second.y = First.y + gapy * cy - 1; else if (cy < 0) Second.y = First.y + gapy * cy + 1; if (Second.x < 1) Second.x = 1; else if (Second.x > TextureImage->Bitmap->Width) Second.x = TextureImage->Bitmap->Width; if (Second.y < 1) Second.y = 1; if (Second.y > TextureImage->Bitmap->Height) Second.y = TextureImage->Bitmap->Height; windraw = true; RangeDraw(); TextureImage->Repaint(); } }else{ if(Down){ DrawDot(X, Y); } } } } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::TextureImageMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { Down = false; } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::ChoiceDataGridDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State) { if (MainImageForm->Plan->Texture->ChoiceCount > 0) { if (ACol < MainImageForm->Plan->Texture->ChoiceCount) { // Bitmap ±×¸®±â... DrawBitmap(MainImageForm->Plan->Texture->Choice[ACol].data, MainImageForm->Plan->Texture->Choice[ACol].width, MainImageForm->Plan->Texture->Choice[ACol].height); ChoiceDataGrid->Canvas->Draw(Rect.left, 0, Bitmap); // Line ±×¸®±â... LineDraw(ACol, ARow, Rect, MainImageForm->Plan->Texture->Choice[ACol].width, MainImageForm->Plan->Texture->Choice[ACol].height); // Á¦¸ñ ¾²±â... TitleText(ACol, ARow, Rect, MainImageForm->Plan->Texture->Choice[ACol].width, MainImageForm->Plan->Texture->Choice[ACol].height); } } } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::RangeDraw() { HDC hDC = NULL; HBRUSH hOldBrush; HPEN hOldPen, hPen = NULL; int nDrawMode; int fx, fy, sx, sy; if((First.x == Second.x) || (First.y == Second.y)) return; if((hDC = TextureImage->Bitmap->CreateDC()) == NULL) goto fail; hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); if ((hPen = CreatePen(PS_SOLID, 1, clYellow)) == NULL) goto fail; hOldPen = SelectObject(hDC, hPen); nDrawMode = GetROP2(hDC); SetROP2(hDC, R2_XORPEN); fx = First.x -1; fy = TextureImage->Bitmap->Height - First.y; sx = Second.x -1; sy = TextureImage->Bitmap->Height - Second.y; Rectangle(hDC, min(fx, sx), min(fy, sy), max(fx, sx) +1, max(fy, sy) +1); SetROP2(hDC, nDrawMode); SelectObject(hDC, hOldPen); DeleteObject(hPen); SelectObject(hDC, hOldBrush); TextureImage->Bitmap->DeleteDC(hDC); return; fail: if (hDC) TextureImage->Bitmap->DeleteDC(hDC); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //---------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::TextureArrangeOnChange(TObject *Sender) { TFound *fd; TDeriv *dt; TSpecial *sp; TTexBitData *bip; TTextureForm *Form = (TTextureForm*) Sender; AnsiString str; MainImageForm->Plan->Texture->ChoiceCount++; int cnt = MainImageForm->Plan->Texture->ChoiceCount - 1; if (MainImageForm->Plan->Texture->ChoiceCount <= 8) { int num = Form->TextureGrid->Row*Form->TextureGrid->ColCount+Form->TextureGrid->Col; switch (Form->ptsItem) { case 0: str = Form->PlainListBox->Items->Strings[Form->Index]; break; case 1: str = Form->TwillListBox->Items->Strings[Form->Index]; break; case 2: str = Form->SatinListBox->Items->Strings[Form->Index]; break; } switch (Form->Item) { case 0: fd = (TFound *) Form->Texture->f[Form->ptsItem]->Items[Form->Index]; bip = (TTexBitData *) fd->data->Items[num]; break; case 1: dt = (TDeriv *) Form->Texture->d[Form->ptsItem]->Items[Form->Index]; bip = (TTexBitData *) dt->data->Items[num]; break; case 2: sp = (TSpecial *) Form->Texture->s->Items[Form->Index]; bip = (TTexBitData *) sp->data->Items[num]; break; } if (!FindSameData(Form->Item, Form->ptsItem, str, AnsiString(bip->Name))) { MainImageForm->Plan->Texture->Choice[cnt].group1 = Form->Item; MainImageForm->Plan->Texture->Choice[cnt].group2 = Form->ptsItem; switch (Form->Item) { case 0: sprintf(MainImageForm->Plan->Texture->Choice[cnt].group3, " %d x %d", fd->size, fd->size); break; case 1: strcpy(MainImageForm->Plan->Texture->Choice[cnt].group3, dt->name); break; case 2: strcpy(MainImageForm->Plan->Texture->Choice[cnt].group3, sp->name); break; } strcpy(MainImageForm->Plan->Texture->Choice[cnt].group4, bip->Name); MainImageForm->Plan->Texture->InitChoiceBitData(cnt, bip->Width, bip->Height, bip->pBitmap); InitChoiceButton(1); ChoiceDataGrid->Repaint(); } else { Sysutils::Beep(); MainImageForm->Plan->Texture->ChoiceCount--; } } else { MainImageForm->Plan->Texture->ChoiceCount = 8; Sysutils::Beep(); ShowMessage(IDS_MESSAGE_DATAFULL); } } //--------------------------------------------------------------------------- bool __fastcall TTextureArrangeForm::FindSameData(int itm, int pts, AnsiString str1, AnsiString str2) { for (int i = 0; i < MainImageForm->Plan->Texture->ChoiceCount; i++) { if (MainImageForm->Plan->Texture->Choice[i].group1 == itm) if (MainImageForm->Plan->Texture->Choice[i].group2 == pts) if (AnsiString(MainImageForm->Plan->Texture->Choice[i].group3) == str1) if (AnsiString(MainImageForm->Plan->Texture->Choice[i].group4) == str2) return true; } return false; } //---------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::DrawBitmap(Byte *bip, int bwidth, int bheight) { short x, y, j, w, rw, zr, tot, spt, zh, zw; Byte z, r; Byte *sl, *stp, *temp, *pcx, *pcy; stp = bip; pcy = stp; temp = stp; zw = bwidth*CurrentZoom; zh = bheight*CurrentZoom; w = Bitmap->Width/zw; rw = Bitmap->Width%zw; if (w==0) w = 1; for (y=Bitmap->Height-1; y>=0; y--) { sl =(Byte*) Bitmap->ScanLine[y]; spt = Bitmap->Height-1-y; if ((spt%CurrentZoom)=Bitmap->Width) break; sl[tot] = Byte(*pcx); } pcx = pcx+1; pcy = pcx; } } if ((Bitmap->Width>zw) && (rw!=0)) { pcx = stp; for (r=0; rWidth-rw)+(r*CurrentZoom)+z; if (tot>=Bitmap->Width) break; sl[tot] = Byte(*pcx); } pcx = pcx+1; } } } } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::LineDraw(int col, int row, TRect dRect, int bwidth, int bheight) { short dx, dy, sx, sy, w, h, i, j, vj; if (CurrentZoom<4) return; dy = ChoiceDataGrid->DefaultRowHeight; dx = ChoiceDataGrid->DefaultColWidth; sx = dRect.left; sy = row*(dy+2)+Bitmap->Height; w = bwidth*CurrentZoom; h = bheight*CurrentZoom; if (CurrentZoom>6) { for (i=0; iWidth; i++) { if ((i%CurrentZoom)==0) { ChoiceDataGrid->Canvas->Pen->Color = clBlue; if ((i%w)==0) ChoiceDataGrid->Canvas->Pen->Color = clRed; ChoiceDataGrid->Canvas->MoveTo(sx+i, sy); ChoiceDataGrid->Canvas->LineTo(sx+i, sy-Bitmap->Height); } } for (j=Bitmap->Height-1; j>=0; j--) { vj = Bitmap->Height-1-j; if ((vj%CurrentZoom)==0) { ChoiceDataGrid->Canvas->Pen->Color = clBlue; if ((vj%h)==0) ChoiceDataGrid->Canvas->Pen->Color = clRed; ChoiceDataGrid->Canvas->MoveTo(sx, sy-vj); ChoiceDataGrid->Canvas->LineTo(sx+Bitmap->Width, sy-vj); } } } else if (CurrentZoom>3) { for (i=0; iWidth; i++) { if ((i%w)==0) { ChoiceDataGrid->Canvas->Pen->Color = clRed; ChoiceDataGrid->Canvas->MoveTo(sx+i, sy); ChoiceDataGrid->Canvas->LineTo(sx+i, sy-Bitmap->Height); } } for (j=Bitmap->Height-1; j>=0; j--) { vj = Bitmap->Height-1-j; if ((vj%h)==0) { ChoiceDataGrid->Canvas->Pen->Color = clRed; ChoiceDataGrid->Canvas->MoveTo(sx, sy-vj); ChoiceDataGrid->Canvas->LineTo(sx+Bitmap->Width, sy-vj); } } } } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::TitleText(int Col, int Row, TRect dRect, int bwidth, int bheight) { int tab; AnsiString Name; TRect StrRect; Name = Format("<< %d >> %d x %d", OPENARRAY(TVarRec, (Col+1+Row*5, bwidth, bheight))); tab = (ChoiceDataGrid->DefaultColWidth-ChoiceDataGrid->Canvas->TextWidth(Name))/2; if (tab<0) tab = 0; StrRect = Rect(dRect.Left, dRect.Bottom-18, dRect.Left+ChoiceDataGrid->DefaultColWidth, dRect.Bottom-2); ChoiceDataGrid->Canvas->TextRect(StrRect, dRect.Left+tab, StrRect.Top+2, Name); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::ChangeChoiceData(int i) { while (i < MainImageForm->Plan->Texture->ChoiceCount-1) { MainImageForm->Plan->Texture->Choice[i].group1 = MainImageForm->Plan->Texture->Choice[i+1].group1; MainImageForm->Plan->Texture->Choice[i].group2 = MainImageForm->Plan->Texture->Choice[i+1].group2; strcpy(MainImageForm->Plan->Texture->Choice[i].group3, MainImageForm->Plan->Texture->Choice[i+1].group3); strcpy(MainImageForm->Plan->Texture->Choice[i].group4, MainImageForm->Plan->Texture->Choice[i+1].group4); MainImageForm->Plan->Texture->DeleteChoiceBitData(i); MainImageForm->Plan->Texture->InitChoiceBitData(i, MainImageForm->Plan->Texture->Choice[i+1].width, MainImageForm->Plan->Texture->Choice[i+1].height, MainImageForm->Plan->Texture->Choice[i+1].data); i++; } int cnt = MainImageForm->Plan->Texture->ChoiceCount-1; MainImageForm->Plan->Texture->Choice[cnt].group1 = 3; // 0, 1, 2 Áß ¾î´À°Íµµ ¾Æ´ÔÀ» ³ªÅ¸³¿. MainImageForm->Plan->Texture->DeleteChoiceBitData(cnt); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::InputTexture() { Byte *sl, *dl; int fx, fy, sx, sy, tx, ty; int sizeX, sizeY; fx = min(First.x, Second.x) -1; fy = min(First.y, Second.y); sx = max(First.x, Second.x); sy = max(First.y, Second.y) +1; TextureUndo->Save(Rect(0, 0, TextureImage->Bitmap->Width, TextureImage->Bitmap->Height)); dl = MainImageForm->Plan->Texture->Choice[ChoiceDataGrid->Col].data; sizeX = MainImageForm->Plan->Texture->Choice[ChoiceDataGrid->Col].width; sizeY = MainImageForm->Plan->Texture->Choice[ChoiceDataGrid->Col].height; TextureImage->Bitmap->StartScanLine(); int H = TextureImage->Bitmap->Height; for(int y = fy, ty = 0; y < sy; y++, ty++){ sl = (Byte*) TextureImage->Bitmap->GetScanLine(H-y); if(ty == sizeY) ty = 0; for(int x = fx, tx = 0; x < sx ; x++,tx++){ if(tx == sizeX) tx = 0; *(sl + x)= *(dl + sizeX*ty + tx); } TextureImage->Bitmap->PutScanLine(H-y); } TextureImage->Bitmap->StopScanLine(); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::ArrayToBitmap() { int h, i, size, code, pw, ph, dx, dy , x, y, StartX; int PatternX = 0, PatternY = 0; Byte *DP, *PP; StartX = 0; for(i = 0; i< MainImageForm->Plan->Texture->Array->Count; i++){ code = ((TTextureArray *)MainImageForm->Plan->Texture->Array->Items[i])->code -1; h = MainImageForm->Plan->Texture->Choice[code].height; PatternX += ((TTextureArray *)MainImageForm->Plan->Texture->Array->Items[i])->size; PatternY = MainImageForm->Plan->Texture->GetLCM(h, PatternY); } RecreateBitmap(PatternX, PatternY); if(!(TextureImage->Bitmap->StartScanLine())) goto fail; for(i = 0; iPlan->Texture->Array->Count; i++){ code = ((TTextureArray *)MainImageForm->Plan->Texture->Array->Items[i])->code -1; size = ((TTextureArray *)MainImageForm->Plan->Texture->Array->Items[i])->size; pw = MainImageForm->Plan->Texture->Choice[code].width; ph = MainImageForm->Plan->Texture->Choice[code].height; DP = MainImageForm->Plan->Texture->Choice[code].data; for (y = TextureImage->Bitmap->Height - 1, dy = 0; y >= 0; y--,dy++){ if(dy >= ph) dy = 0; PP = TextureImage->Bitmap->GetScanLine(y); for(x = 0,dx = 0; x < size;x++,dx++){ if(dx >= pw) dx = 0; *(PP + StartX + x) = *(DP + pw*dy + dx); } TextureImage->Bitmap->PutScanLine(y); } StartX = StartX + size; } TextureImage->Bitmap->StopScanLine(); return; fail: TextureImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::PatternDataToBitmap() { Byte *DP, *TP; int y, pw, ph; pw = MainImageForm->Plan->Texture->Choice[PATTERN].width; ph = MainImageForm->Plan->Texture->Choice[PATTERN].height; DP = MainImageForm->Plan->Texture->Choice[PATTERN].data; RecreateBitmap(pw, ph); if(!(TextureImage->Bitmap->StartScanLine())) goto fail; for(y = TextureImage->Bitmap->Height - 1; y >= 0; y--){ TP = TextureImage->Bitmap->GetScanLine(y); memcpy(TP, DP, pw); TextureImage->Bitmap->PutScanLine(y); DP += pw; } TextureImage->Bitmap->StopScanLine(); TextureImage->Repaint(); return; fail: TextureImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::BitmapToData() { Byte *DP, *PP; MainImageForm->Plan->Texture->bFinish = true; if (MainImageForm->Plan->Texture->Choice[PATTERN].data) MainImageForm->Plan->Texture->DeleteChoiceBitData(PATTERN); MainImageForm->Plan->Texture->Choice[PATTERN].width = TextureImage->Bitmap->Width; MainImageForm->Plan->Texture->Choice[PATTERN].height = TextureImage->Bitmap->Height; MainImageForm->Plan->Texture->Choice[PATTERN].data = (Byte *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, TextureImage->Bitmap->Width*TextureImage->Bitmap->Height); DP = MainImageForm->Plan->Texture->Choice[PATTERN].data; if (!(TextureImage->Bitmap->StartScanLine())) goto fail; for (int y = TextureImage->Bitmap->Height - 1; y >= 0; y--) { PP = (Byte *) TextureImage->Bitmap->GetScanLine(y); memcpy(DP, PP, TextureImage->Bitmap->Width); DP += TextureImage->Bitmap->Width; } TextureImage->Bitmap->StopScanLine(); return; fail: TextureImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //---------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::InitChoiceButton(int i) { sbChoiceDelete->Down = false; sbChoiceNew->Enabled = i; sbChoiceDelete->Enabled = i; } //---------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::DrawDot(int X, int Y) { Byte *TP; if (Down) { if (TextureImage->Bitmap->StartScanLine() == false) goto fail; X = X - 1; Y = TextureImage->Bitmap->Height - Y; TP = (Byte *) TextureImage->Bitmap->GetScanLine(Y); TP[X] = Color; TextureImage->Bitmap->PutScanLine(Y); TextureImage->Bitmap->StopScanLine(); TextureImage->Repaint(); } return; fail: TextureImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //---------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::rgModeClick(TObject *Sender) { int w, h; TIniFile *IniFile; if(rgMode->ItemIndex == 1) { pnAdvanced->BringToFront(); if (isFirst) { IniFile = new TIniFile(DirectoryItem + "\\TextureArrange.ini"); if (IniFile) { w = IniFile->ReadInteger("PatternSize", "Warp", 50); h = IniFile->ReadInteger("PatternSize", "Weft", 50); delete IniFile; } EditCol->Text = w; EditRow->Text = h; isFirst = false; } MainImageForm->Plan->Texture->bNormal = false; } else { pnNormal->BringToFront(); MainImageForm->Plan->Texture->bNormal = true; } ChangeTotalSize(); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::ArrayDataGridClick(TObject *Sender) { TTextureArray *texarray; int i, w, h; if (MainImageForm->Plan->Texture->ChoiceCount == 0) return; if (ArrayDataGrid->Row) { if (sbArrangeInsert->Down || sbArrangeDelete->Down) { if ((ArrayDataGrid->Row-1)Plan->Texture->Array->Count) { if (sbArrangeInsert->Down) { MainImageForm->Plan->Texture->InsertArray(ArrayDataGrid->Row-1); insert = ArrayDataGrid->Row; ///////// for (i=MainImageForm->Plan->Texture->Array->Count; i>ArrayDataGrid->Row; i--) { ArrayDataGrid->Cells[1][i] = ArrayDataGrid->Cells[1][i-1]; ArrayDataGrid->Cells[2][i] = ArrayDataGrid->Cells[2][i-1]; ArrayDataGrid->Cells[3][i] = ArrayDataGrid->Cells[3][i-1]; } ArrayDataGrid->Cells[1][ArrayDataGrid->Row] = ""; ArrayDataGrid->Cells[2][ArrayDataGrid->Row] = ""; ArrayDataGrid->Cells[3][ArrayDataGrid->Row] = ""; } else if (sbArrangeDelete->Down) { MainImageForm->Plan->Texture->RemoveArray(ArrayDataGrid->Row-1); if (insert == ArrayDataGrid->Row) insert = -1; for (i=ArrayDataGrid->Row; i<=MainImageForm->Plan->Texture->Array->Count; i++) { ArrayDataGrid->Cells[1][i] = ArrayDataGrid->Cells[1][i+1]; ArrayDataGrid->Cells[2][i] = ArrayDataGrid->Cells[2][i+1]; ArrayDataGrid->Cells[3][i] = ArrayDataGrid->Cells[3][i+1]; } i = MainImageForm->Plan->Texture->Array->Count+1; ArrayDataGrid->Cells[1][i] = ""; ArrayDataGrid->Cells[2][i] = ""; ArrayDataGrid->Cells[3][i] = ""; if (MainImageForm->Plan->Texture->Array->Count == 0){ TIniFile *IniFile = new TIniFile(DirectoryItem + "\\TextureArrange.ini"); if (IniFile) { w = IniFile->ReadInteger("PatternSize", "Warp", 50); h = IniFile->ReadInteger("PatternSize", "Weft", 50); delete IniFile; } RecreateBitmap(w, h); } else { ArrayToBitmap(); } } ChangeTotalSize(); } ArrayDataGrid->EditorMode = false; sbArrangeInsert->Down = false; sbArrangeDelete->Down = false; if (MainImageForm->Plan->Texture->Array->Count == 0) InitArrayButton(0); } else if (ArrayDataGrid->Col){ switch (ArrayDataGrid->Col) { case 1: if ((ArrayDataGrid->Row-1)<=MainImageForm->Plan->Texture->Array->Count) ArrayDataGrid->EditorMode = true; break; case 2: if ((ArrayDataGrid->Row-1)Plan->Texture->Array->Count) ArrayDataGrid->EditorMode = true; break; default: ArrayDataGrid->EditorMode = false; } } } ArrayDataGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::ArrayDataGridDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State) { AnsiString str; int x, y, wid; TSize size; TTextureArray *texarray; size.cx = Rect.Right-Rect.Left; size.cy = Rect.Bottom-Rect.Top; if (ACol == 0) { if (ARow == 0) str = "No."; else str = ARow; } else { if (ARow == 0) { switch (ACol) { case 1: str = IDS_CODE; break; case 2: str = IDS_COMMON_REPEAT; break; case 3: str = IDS_TEXTURESIZE; break; } } else { if (MainImageForm->Plan->Texture->Array->Count) { if (ARow <= MainImageForm->Plan->Texture->Array->Count) { if (ARow == insert) return; texarray = (TTextureArray *) MainImageForm->Plan->Texture->Array->Items[ARow-1]; switch (ACol) { case 1: str = AnsiString(texarray->code); break; case 2: str = AnsiString(texarray->repeat); break; case 3: wid = MainImageForm->Plan->Texture->Choice[texarray->code - 1].width; str = Format("%d x %d = %d", OPENARRAY(TVarRec, (wid, texarray->repeat, texarray->size))); break; } } } } } x = (size.cx-ArrayDataGrid->Canvas->TextWidth(str)) / 2; if (x<0) x = 0; y = (size.cy-ArrayDataGrid->Canvas->TextHeight(str)) / 2; if (y<0) y = 0; ArrayDataGrid->Canvas->TextRect(Rect, Rect.Left+x, Rect.Top+y, str); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::ArrayDataGridKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { TTextureArray *texarray; if (Key==VK_RETURN) { TStringGrid *grid = (TStringGrid *) Sender; if (grid->EditorMode) { if (ProperInput(ArrayDataGrid->Cells[grid->Col][grid->Row], grid->Col)) { if ((grid->Row-1) == MainImageForm->Plan->Texture->Array->Count) { if (grid->Col == 1) { MainImageForm->Plan->Texture->AddArray(StrToInt(ArrayDataGrid->Cells[grid->Col][grid->Row])); grid->Col = grid->Col+1; InitArrayButton(1); } } else if ((grid->Row-1) < MainImageForm->Plan->Texture->Array->Count){ texarray = (TTextureArray *) MainImageForm->Plan->Texture->Array->Items[grid->Row-1]; if (grid->Col == 1) { texarray->code = StrToInt(ArrayDataGrid->Cells[grid->Col][grid->Row]); texarray->size = CalculateSize(texarray); if (texarray->size > 0) ArrayToBitmap(); if (insert>=0) insert = -1; grid->Col = grid->Col+1; } else if (grid->Col == 2) { texarray->repeat = StrToInt(ArrayDataGrid->Cells[grid->Col][grid->Row]); texarray->size = CalculateSize(texarray); if (texarray->size > 0) ArrayToBitmap(); grid->Row = grid->Row+1; grid->Col = 1; } } grid->EditorMode = false; ArrayDataGrid->Repaint(); ChangeTotalSize(); } else { ArrayDataGrid->Cells[grid->Col][grid->Row] = ""; } } } } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::ArrayDataGridSelectCell( TObject *Sender, int ACol, int ARow, bool &CanSelect) { if (CanSelect) { if (MainImageForm->Plan->Texture->ChoiceCount == 0) return; if (ARow) { switch (ACol) { case 0: case 3: ArrayDataGrid->Options>>goEditing; break; case 1: case 2: ArrayDataGrid->Options<Options>>goEditing; } } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::InitArrayButton(int i) { sbArrangeInsert->Down = false; sbArrangeDelete->Down = false; sbArrangeNew->Enabled = i; sbArrangeInsert->Enabled = i; sbArrangeDelete->Enabled = i; rgMode->Enabled = 1-i; } //--------------------------------------------------------------------------- int __fastcall TTextureArrangeForm::CalculateSize(TTextureArray *ta) { if (ta->code <= MainImageForm->Plan->Texture->ChoiceCount) { return MainImageForm->Plan->Texture->Choice[ta->code-1].width*ta->repeat; } else { return 0; } } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::ChangeTotalSize() { TTextureArray *texarray; int cnt = MainImageForm->Plan->Texture->Array->Count; int totalx = 0, totaly = 0, h; if (MainImageForm->Plan->Texture->bNormal) { if (cnt) { for (int i = 0; i < cnt; i++) { texarray = (TTextureArray *) MainImageForm->Plan->Texture->Array->Items[i]; h = MainImageForm->Plan->Texture->Choice[texarray->code -1].height; totalx += texarray->size; totaly = MainImageForm->Plan->Texture->GetLCM(h, totaly); } } } else { totalx = TextureImage->Bitmap->Width; totaly = TextureImage->Bitmap->Height; } StatusBar->Panels->Items[1]->Text = Format(IDS_TOTALSIZE+": %d x %d",OPENARRAY(TVarRec,(totalx, totaly))); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::ChangeArrayData(int i) { TTextureArray *texarray; int j = 0; int oldcnt = MainImageForm->Plan->Texture->Array->Count; while (j < MainImageForm->Plan->Texture->Array->Count) { texarray = (TTextureArray *) MainImageForm->Plan->Texture->Array->Items[j]; if (i == texarray->code-1) { MainImageForm->Plan->Texture->RemoveArray(j); continue; } else if (i < texarray->code-1) { texarray->code = texarray->code-1; } j++; } int cnt = MainImageForm->Plan->Texture->Array->Count; for (j = 1; j <= oldcnt; j++) { if (j <= cnt) { texarray = (TTextureArray *) MainImageForm->Plan->Texture->Array->Items[j-1]; ArrayDataGrid->Cells[1][j] = AnsiString(texarray->code); ArrayDataGrid->Cells[2][j] = AnsiString(texarray->repeat); ArrayDataGrid->Cells[3][j] = AnsiString(texarray->size); } else { ArrayDataGrid->Cells[1][j] = ""; ArrayDataGrid->Cells[2][j] = ""; ArrayDataGrid->Cells[3][j] = ""; } } ChangeTotalSize(); ArrayDataGrid->Repaint(); } //--------------------------------------------------------------------------- bool __fastcall TTextureArrangeForm::ProperInput(AnsiString str, int Acol) { if ((str == "")||(Acol == 3)) return false; try { if (Acol == 1) { if (StrToInt(str) <= MainImageForm->Plan->Texture->ChoiceCount && StrToInt(str) > 0) return true; else return false; } else return true; } catch (EConvertError *error) { return false; } } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::sbArrangeNewClick(TObject *Sender) { TTextureArray *texarray; TIniFile *IniFile; int w, h; int cnt = MainImageForm->Plan->Texture->Array->Count; while (cnt) { ArrayDataGrid->Cells[1][cnt] = ""; ArrayDataGrid->Cells[2][cnt] = ""; ArrayDataGrid->Cells[3][cnt] = ""; cnt--; } if (MainImageForm->Plan->Texture->Choice[PATTERN].data) { MainImageForm->Plan->Texture->DeleteChoiceBitData(PATTERN); } MainImageForm->Plan->Texture->ClearArray(); IniFile = new TIniFile(DirectoryItem + "\\TextureArrange.ini"); if (IniFile) { w = IniFile->ReadInteger("PatternSize", "Warp", 50); h = IniFile->ReadInteger("PatternSize", "Weft", 50); delete IniFile; } RecreateBitmap(w, h); InitArrayButton(0); ChangeTotalSize(); ArrayDataGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::RecreateBitmap(int w, int h) { TextureImage->Bitmap->Destroy(); TextureImage->Bitmap->Create(w, h, 8, rgb); TextureImage->Bitmap->CoordinateSystem = csBottomLeft; StatusBar->Panels->Items[1]->Text = Format(IDS_TOTALSIZE+": %d x %d",OPENARRAY(TVarRec,(w, h))); } //---------------------------------------------------------------------------- void __fastcall TTextureArrangeForm::sbMinShaftClick(TObject *Sender) { if (windraw) return; BYTE *tp; TTexpiaBitmap *TempBitmap; int mx = 1, my = 1; TextureImage->Bitmap->StartScanLine(); for (int i = 0; i < TextureImage->Bitmap->Height; i++) { tp = (BYTE *)TextureImage->Bitmap->GetScanLine(i); for (int j = 0; j < TextureImage->Bitmap->Width; j++) { if (*(tp+j) == 1) { mx = max(j+1, mx); my = max(my, TextureImage->Bitmap->Height - i); } } } TextureImage->Bitmap->StopScanLine(); EditCol->Text = mx; EditRow->Text = my; TempBitmap = new TTexpiaBitmap; TempBitmap->Create(mx, my, 8, rgb); TempBitmap->Copy(0, 0, mx, my, TextureImage->Bitmap, 0, TextureImage->Bitmap->Height - my, SRCCOPY); RecreateBitmap(mx, my); TextureImage->Bitmap->Copy(TempBitmap, SRCCOPY); delete TempBitmap; } //---------------------------------------------------------------------------