//--------------------------------------------------------------------------- #include #include #include #pragma hdrstop #include "TextureDesign_F.h" #include "Common.h" #include "Exception.h" #include "Texture_F.h" #include "chart.h" #include "TexturePrint.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "TPImage" #pragma link "TPWeaveImage" #pragma link "TPSelectImage" #pragma link "Rulers" #pragma link "TPRuler2D" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_TEXTUREDESIGNER StringTable[0] #define IDS_TEXTUREDESIGN StringTable[1] #define IDS_MODE StringTable[2] #define IDS_DETAIL StringTable[3] #define IDS_WARP StringTable[4] #define IDS_WEFT StringTable[5] #define IDS_SHAFT StringTable[6] #define IDS_TEXTUREMENU StringTable[7] #define IDS_SKETCH StringTable[8] #define IDS_DRAWDOT StringTable[9] #define IDS_TEXFILEMANAGER StringTable[10] #define IDS_WINDOWOFF StringTable[11] #define IDS_WINDOWON StringTable[12] #define IDS_REDO StringTable[13] #define IDS_PREVIEW StringTable[14] #define IDS_COLORREVERSE StringTable[15] #define IDS_DESIGNVIEW StringTable[16] #define IDS_SPREADVIEW StringTable[17] #define IDS_SHAFTMIN StringTable[18] #define IDS_ROTATEMOVE StringTable[19] #define IDS_LEFTROTATE StringTable[20] #define IDS_RIGHTROTATE StringTable[21] #define IDS_SHIFTMOVE StringTable[32] #define IDS_SHIFTUP StringTable[23] #define IDS_SHIFTLEFT StringTable[24] #define IDS_SHIFTRIGHT StringTable[25] #define IDS_SHIFTDOWN StringTable[26] #define IDS_COLOR StringTable[27] #define IDS_NEWCREATE StringTable[28] #define IDS_OVERWRITE StringTable[29] #define IDS_INSERT StringTable[30] #define IDS_TEXTURE StringTable[31] #define IDS_GROUP StringTable[32] #define IDS_NORMAL StringTable[33] //--------------------------------------------------------------------------- #define WHITE 0 #define BLACK 1 //--------------------------------------------------------------------------- TTextureDesignForm *TextureDesignForm; //--------------------------------------------------------------------------- __fastcall TTextureDesignForm::TTextureDesignForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; //================================================================== StringTable.Create(DirectoryItem, Language, "TextureDesign"); SetSmallFont(Font); SetSmallFont(StaticText3->Font); SetSmallFont(StaticText2->Font); SetSmallFont(sbWinOff->Font); SetSmallFont(sbWinOn->Font); SetSmallFont(StaticText7->Font); SetSmallFont(StaticText6->Font); SetSmallFont(StaticText5->Font); SetSmallFont(StaticText4->Font); SetSmallFont(Label13->Font); Caption = IDS_TEXTUREDESIGNER; StaticText3->Caption = IDS_TEXTUREDESIGN; rgMode->Caption = IDS_MODE; rgMode->Items->Strings[0] = IDS_NORMAL; rgMode->Items->Strings[1] = IDS_DETAIL; Label4->Caption = IDS_WARP; Label5->Caption = IDS_WEFT; Label->Caption = IDS_SHAFT; Label15->Caption = IDS_COMMON_ZOOM; sbRun->Caption = IDS_COMMON_RUN; sbCancel->Caption = IDS_COMMON_BUTTONCANCEL; //IDS_CANCEL StaticText2->Caption = IDS_TEXTUREMENU; SketchGroup->Caption = IDS_SKETCH; sbDrawDot->Hint = IDS_DRAWDOT; sbDrawCLine->Hint = IDS_COMMON_CONTINUOUSLINE; //IDS_COUNTINUOUSLINE; sbDrawSLine->Hint = IDS_COMMON_SEPARATELINE; //IDS_SEPARATELINE; sbReadSave->Hint = IDS_TEXFILEMANAGER; WindowGroup->Caption = IDS_COMMON_WINDOW; sbWinOff->Caption = IDS_WINDOWOFF; sbWinOn->Caption = IDS_WINDOWON; sbClear->Hint = IDS_COMMON_DELETE; //IDS_CLEAR; sbMove->Hint = IDS_COMMON_MOVE; //IDS_MOVE; sbCopy->Hint = IDS_COMMON_COPY; //IDS_COPY; sbRepeat->Hint = IDS_COMMON_REPEAT; //IDS_REPEAT; sbFill->Hint = IDS_COMMON_FILL; //IDS_FILL; sbUndo->Hint = IDS_COMMON_UNDO; PreviewGroup->Caption = IDS_PREVIEW; sbReverse->Hint = IDS_COLORREVERSE; sbDesign->Hint = IDS_DESIGNVIEW; sbSpread->Hint = IDS_SPREADVIEW; sbMinShaft->Hint = IDS_SHAFTMIN; RotateGroup->Caption = IDS_ROTATEMOVE; sbUpdown->Hint = IDS_COMMON_UPDOWN; //IDS_UPDOWN; sbMirror->Hint = IDS_COMMON_MIRROR; //IDS_MIRROR; sbRotateL->Hint = IDS_LEFTROTATE; sbRotateR->Hint = IDS_RIGHTROTATE; ShiftGroup->Caption = IDS_SHIFTMOVE; sbShiftU->Hint = IDS_SHIFTUP; sbShiftL->Hint = IDS_SHIFTLEFT; sbShiftR->Hint = IDS_SHIFTRIGHT;; sbShiftD->Hint = IDS_SHIFTDOWN; ColorGroup->Caption = IDS_COLOR; PositionGroup->Caption = IDS_COMMON_POSITION; sbNew->Caption = IDS_NEWCREATE; StaticText7->Caption = IDS_COMMON_READ; StaticText6->Caption = IDS_COMMON_SAVEAS; //IDS_SAVE; StaticText5->Caption = IDS_COMMON_DELETE; StaticText4->Caption = IDS_COMMON_RENAME; sbNormal->Caption = IDS_COMMON_NORMAL; sbReadWindow->Caption = IDS_COMMON_WINDOW; sbOverWrite->Caption = IDS_OVERWRITE; sbInsert->Caption = IDS_INSERT; sbDelTexture->Caption = IDS_TEXTURE; sbDelGroup->Caption = IDS_GROUP; sbNameTexture->Caption = IDS_TEXTURE; sbNameGroup->Caption = IDS_GROUP; //================================================================== } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::FormClose(TObject *Sender, TCloseAction &Action) { PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::FormCreate(TObject *Sender) { TIniFile *IniFile = new TIniFile(DirectoryItem + "\\Main.ini"); if (IniFile) { Left = IniFile->ReadInteger("TextureDesign", "FormLeft", (Screen->Width-Width)>>1); Top = IniFile->ReadInteger("TextureDesign", "FormTop", (Screen->Height-Height)>>1); delete IniFile; } 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; Image->Bitmap->CoordinateSystem = csBottomLeft; if (Image->Bitmap->Create(20, 20, 8, rgb) == false) goto fail; //Normal Image Image->SetZoom(16, 1); // Detail Image CenterImage->Bitmap->CoordinateSystem = csBottomLeft; if (CenterImage->Bitmap->Create(20, 20, 8, rgb) == false) goto fail; CenterImage->SetZoom(10, 1); LiftImage->Bitmap->CoordinateSystem = csBottomLeft; if (LiftImage->Bitmap->Create(20, 20, 8, rgb) == false) goto fail; LiftImage->SetZoom(10, 1); DrawImage->Bitmap->CoordinateSystem = csBottomLeft; if (DrawImage->Bitmap->Create(20, 20, 8, rgb) == false) goto fail; DrawImage->SetZoom(10, 1); TempBit = NULL; Bitmap = NULL; if ((TempBit = new TTexpiaBitmap) == NULL) goto fail; if ((Bitmap = new TTexpiaBitmap) == NULL) goto fail; WorkArea = NULL; TextureUndo = NULL; if ((WorkArea = new TPWorkArea(&(Image->Bitmap))) == NULL) { WorkArea->undoMax = 0; #ifdef TPDEBUG SHOWDEBUG; #endif } if ((TextureUndo = new TSimpleUndo) == NULL) { #ifdef TPDEBUG SHOWDEBUG; #endif } TextureUndo->Set(Image->Bitmap, WorkArea); Ruler->Zoom = 16; CurrentZoom = 5; DKind = dmDot; menuitem = TOFF; Color = 0; move = false; IsDraw = false; windraw = false; Mode = 0; PanelFile->SendToBack(); PanelFile->Visible = false; TextureForm->OnChange = FileFunctionChange; TextureForm->OnListChange = FileFunctionListChange; TextureForm->OnButtonChange = FileFunctionButtonChange; TextureForm->OnCloseForm = ExitFileForm; EditShaft->Enabled = false; //qe return; fail: PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::FormDestroy(TObject *Sender) { TIniFile *IniFile = new TIniFile(DirectoryItem + "\\Main.ini"); if (IniFile) { if (Left<0) Left = 10; if (Top<0) Top = 10; IniFile->WriteInteger("TextureDesign", "FormLeft", Left); IniFile->WriteInteger("TextureDesign", "FormTop", Top); delete IniFile; } ExitFileForm(); ::doDestroy(WorkArea); ::doDestroy(TextureUndo); ::doDestroy(Bitmap); ::doDestroy(TempBit); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::EditChange(TObject *Sender) { TEdit *sp = (TEdit *) Sender; if (sp->Text.Length() > 0) { if (sp->Tag == 0) { if (Mode == 1) { int i = StrToInt(EditCol->Text); ShaftLabel->Caption = Format("(2 - %d)", OPENARRAY(TVarRec, (i))); } } sbRun->Enabled = true; sbCancel->Enabled = true; } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::EditClick(TObject *Sender) { TEdit *sp = (TEdit *) Sender; sp->SetFocus(); sp->SelectAll(); OnMouseMoving(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::rgModeClick(TObject *Sender) { OnMouseMoving(); if (rgMode->ItemIndex) EditShaft->Enabled = true; else EditShaft->Enabled = false; sbRun->Enabled = true; sbCancel->Enabled = true; RemoveAfterImage(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbRunClick(TObject *Sender) { OnMouseMoving(); InitPanel(); Mode = rgMode->ItemIndex; sbRun->Enabled = false; sbCancel->Enabled = false; FileFunctionListChange(TextureForm); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbCancelClick(TObject *Sender) { OnMouseMoving(); EditCol->Text = Image->Bitmap->Width; EditRow->Text = Image->Bitmap->Height; if (sbWinOff->Enabled) { if (Mode==1) { Mode = 0; rgMode->ItemIndex = 0; } } else { if (Mode==0) { Mode = 1; rgMode->ItemIndex = 1; } } sbRun->Enabled = false; sbCancel->Enabled = false; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbZoomClick(TObject *Sender) { TSpeedButton *sb = (TSpeedButton *) Sender; OnMouseMoving(); if (sb->Tag) { CurrentZoom++; if (CurrentZoom > 5) CurrentZoom = 5; } else { CurrentZoom--; if (CurrentZoom < 1) CurrentZoom = 1; } switch (CurrentZoom) { case 1: Image->SetZoom(1, 1); ZoomText->Caption = "1"; Ruler->Zoom = 1; break; case 2: Image->SetZoom(2, 1); ZoomText->Caption = "2"; Ruler->Zoom = 2; break; case 3: Image->SetZoom(4, 1); ZoomText->Caption = "3"; Ruler->Zoom = 4; break; case 4: Image->SetZoom(8, 1); ZoomText->Caption = "4"; Ruler->Zoom = 8; break; case 5: Image->SetZoom(16, 1); ZoomText->Caption = "5"; Ruler->Zoom = 16; break; } ScrollBarEnabled(); RemoveAfterImage(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbDrawFunctionClick(TObject *Sender) { TSpeedButton *sb = (TSpeedButton *) Sender; OnMouseMoving(); switch (sb->Tag) { case 0: ShapeDot->Brush->Color = clRed; ShapeCLine->Brush->Color = clBlack; ShapeSLine->Brush->Color = clBlack; ShapeDot->Pen->Color = clRed; ShapeCLine->Pen->Color = clBlack; ShapeSLine->Pen->Color = clBlack; DKind = dmDot; break; case 1: ShapeDot->Brush->Color = clBlack; ShapeCLine->Brush->Color = clRed; ShapeSLine->Brush->Color = clBlack; ShapeDot->Pen->Color = clBlack; ShapeCLine->Pen->Color = clRed; ShapeSLine->Pen->Color = clBlack; DKind = dmCLine; break; case 2: ShapeDot->Brush->Color = clBlack; ShapeCLine->Brush->Color = clBlack; ShapeSLine->Brush->Color = clRed; ShapeDot->Pen->Color = clBlack; ShapeCLine->Pen->Color = clBlack; ShapeSLine->Pen->Color = clRed; DKind = dmSLine; break; } // RemoveAfterImage(); if (IsDraw) { Image->Bitmap->Copy(TempBit, SRCCOPY); step = 0; IsDraw = false; } if (Mode) DetailImageRepaint(); else Image->Repaint(); menuitem = TOFF; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbWindowClick(TObject *Sender) { TSpeedButton *sb = (TSpeedButton *) Sender; OnMouseMoving(); if (sb->Tag) { if (sbWinOn->Down) { menuitem = TWIN; sbWinOn->Font->Color = clRed; } else { menuitem = TOFF; sbWinOn->Font->Color = clGreen; step = 0; } sbWinOff->Font->Color = clBlack; } else { menuitem = TOFF; step = 0; sbWinOff->Font->Color = clGreen; sbWinOn->Font->Color = clBlack; WorkArea->ResetRegion(Image); StatusItem(0); SetRotateButton(Image->Bitmap->Width == Image->Bitmap->Height); } RemoveAfterImage(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbClearClick(TObject *Sender) { Byte *SP, *DP; int x, y; if (Mode) { TextureUndo->Save(Rect(0, 0, CenterImage->Bitmap->Width, CenterImage->Bitmap->Height)); ClearImage(CenterImage->Bitmap); ClearImage(LiftImage->Bitmap); if (DrawImage->Bitmap->StartScanLine() == false) goto fail; for (y = 0; y < DrawImage->Bitmap->Height; y++) { DP = DrawImage->Bitmap->GetScanLine(y); if (y == DrawImage->Bitmap->Height-1) memset(DP, 1, DrawImage->Bitmap->Width); else memset(DP, 0, DrawImage->Bitmap->Width); DrawImage->Bitmap->PutScanLine(y); } DrawImage->Bitmap->StopScanLine(); DetailImageRepaint(); } else { OnMouseMoving(); TextureUndo->Save(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); ClearImage(Image->Bitmap); menuitem = TOFF; step = 0; sbWinOff->Font->Color = clGreen; sbWinOn->Font->Color = clBlack; WorkArea->ResetRegion(Image); StatusItem(0); SetRotateButton(Image->Bitmap->Width == Image->Bitmap->Height); sbWinOff->Down = true; } RemoveAfterImage(); return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbUndoClick(TObject *Sender) { if (sbUndo->Tag) { sbUndo->Hint = IDS_COMMON_UNDO; sbUndo->Tag = 0; } else { sbUndo->Hint = IDS_REDO; sbUndo->Tag = 1; } IsDraw = false; if (move) { OnMouseMoving(); } else { if (Mode) { TextureUndo->Read(Rect(0, 0, CenterImage->Bitmap->Width, CenterImage->Bitmap->Height)); ClearImage(LiftImage->Bitmap); ClearImage(DrawImage->Bitmap); SetDetailImage(); DetailImageRepaint(); } else { if (DKind == dmCLine && step > 0) { Image->Bitmap->Copy(TempBit, SRCCOPY); step = 0; } TextureUndo->Read(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); Image->Repaint(); } } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::FunctionClick(TObject *Sender) { bool tp = false, bt = false; TSpeedButton *sp = (TSpeedButton *) Sender; OnSimpleMouseMoving(); RemoveAfterImage(); if (sp->Down) { if (sp->Tag == 11) { menuitem = TMOVE; } else if (sp->Tag == 12) { menuitem = TCOPY; } else if (sp->Tag == 13) { menuitem = TREPEAT; } else if (sp->Tag == 14) { menuitem = TFILL; } //qe TextureUndo->Save(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); RECT rc = WorkArea->Range; tp = TempBit->Create(rc.right - rc.left, rc.bottom - rc.top, 8, rgb); if (tp == false) goto fail; TempBit->CopyFromRect(Image->Bitmap, rc.left, rc.top, SRCCOPY); bt = Bitmap->Create(Image->Bitmap->Width, Image->Bitmap->Height, 8, rgb); if (bt == false) goto fail; Bitmap->Copy(Image->Bitmap, SRCCOPY); } else { menuitem = TOFF; } ChangeShapeColor(sp->Tag, sp->Down); return; fail: if (bt) Bitmap->Destroy(); if (tp) TempBit->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbReverseClick(TObject *Sender) { RECT rect; if (Mode) { rect = Rect(0, 0, CenterImage->Bitmap->Width, CenterImage->Bitmap->Height); TextureUndo->Save(rect); ReverseBitmap(CenterImage->Bitmap, rect); rect = Rect(0, 0, LiftImage->Bitmap->Width, LiftImage->Bitmap->Height); ReverseBitmap(LiftImage->Bitmap, rect); DetailImageRepaint(); } else { OnMouseMoving(); if (WorkArea->Mask) rect = WorkArea->Range; else rect = Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height); TextureUndo->Save(rect); ReverseBitmap(Image->Bitmap, rect); Image->Repaint(); } RemoveAfterImage(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbDesignClick(TObject *Sender) { if (Mode) { sbZoomIn->Enabled = false; sbZoomOut->Enabled = false; DetailPanel->BringToFront(); } else { OnMouseMoving(); Image->SetZoom(16, 1); ZoomText->Caption = "5"; CurrentZoom = 5; Ruler->Zoom = 16; ScrollBarEnabled(); } ShapeDesign->Brush->Color = clBlue; ShapeSpread->Brush->Color = clBlack; ShapeDesign->Pen->Color = clBlue; ShapeSpread->Pen->Color = clBlack; RemoveAfterImage(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbSpreadClick(TObject *Sender) { if (Mode) { sbZoomIn->Enabled = true; sbZoomOut->Enabled = true; NormalPanel->BringToFront(); SetNormalImage(); } else { OnMouseMoving(); } Image->SetZoom(1, 1); ZoomText->Caption = "1"; Ruler->Zoom = 1; CurrentZoom = 1; ScrollBarEnabled(); ShapeDesign->Brush->Color = clBlack; ShapeSpread->Brush->Color = clBlue; ShapeDesign->Pen->Color = clBlack; ShapeSpread->Pen->Color = clBlue; RemoveAfterImage(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbMinShaftClick(TObject *Sender) { HDC srcdc, dstdc; bool bt = false, db = false, lb = false, dline = false; int shaft, hh, ww; shaft = SetDetailImage(); if (shaft > 1) { TextureUndo->RemoveAll(); bt = Bitmap->Create(CenterImage->Bitmap->Width, shaft, 8, rgb); if (bt == false) goto fail; Bitmap->CopyFromRect(DrawImage->Bitmap, 0, DrawImage->Bitmap->Height - shaft , SRCCOPY); hh = shaft * 10; if (DrawImage->Top + hh < DetailPanel->Height - 20) { DrawImage->Height = shaft * 10; DrawImage->BringToFront(); DrawImage->Visible = true; DRulerV->Height = DrawImage->Height; DScrollBarV->Height = DrawImage->Height; dline = true; } db = DrawImage->Bitmap->Create(CenterImage->Bitmap->Width, shaft, 8, rgb); if (db == false) goto fail; DrawImage->Bitmap->Copy(Bitmap, SRCCOPY); bt = Bitmap->Create(shaft, CenterImage->Bitmap->Height, 8, rgb); if (bt == false) goto fail; Bitmap->CopyFromRect(LiftImage->Bitmap, 0, 0, SRCCOPY); ww = shaft * 10; if (LiftImage->Left + ww < DetailPanel->Width - 20) { LiftImage->Width = shaft * 10; LRulerH->Width = LiftImage->Width; LScrollBarH->Width = LiftImage->Width; dline = true; } lb = LiftImage->Bitmap->Create(shaft, CenterImage->Bitmap->Height, 8, rgb); if (lb == false) goto fail; LiftImage->Bitmap->Copy(Bitmap, SRCCOPY); if (dline) LineDraw(); EditShaft->Text = shaft; ww = LiftImage->Width / 10; hh = DrawImage->Height / 10; LScrollBarH->Enabled = (ww < LiftImage->Bitmap->Width); DScrollBarV->Enabled = (hh < DrawImage->Bitmap->Height); } return; fail: if (lb) LiftImage->Bitmap->Destroy(); if (db) DrawImage->Bitmap->Destroy(); if (bt) Bitmap->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbUpdownClick(TObject *Sender) { Byte *SP, *DP; RECT rc = ReadyToTempBitmap(); int x, y; if (Image->Bitmap->StartScanLine() == false) goto fail; if (TempBit->StartScanLine() == false) goto fail; for (y = rc.top; y < rc.bottom; y++) { DP = Image->Bitmap->GetScanLine(y); SP = TempBit->GetScanLine(rc.bottom - 1 - y); for (x = rc.left; x < rc.right; x++) { DP[x] = SP[x - rc.left]; } Image->Bitmap->PutScanLine(y); } TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); Image->Repaint(); return; fail: TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbMirrorClick(TObject *Sender) { Byte *SP, *DP; RECT rc = ReadyToTempBitmap(); int x, y; if (Image->Bitmap->StartScanLine() == false) goto fail; if (TempBit->StartScanLine() == false) goto fail; for (y = rc.top; y < rc.bottom; y++) { DP = Image->Bitmap->GetScanLine(y); SP = TempBit->GetScanLine(y - rc.top); for (x = rc.left; x < rc.right; x++) { DP[x] = SP[rc.right - 1- x]; } Image->Bitmap->PutScanLine(y); } TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); Image->Repaint(); return; fail: TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbRotateLClick(TObject *Sender) { Byte *SP, *DP; RECT rc = ReadyToTempBitmap(); int x, y; int h = rc.bottom + rc.left - 1; if (Image->Bitmap->StartScanLine() == false) goto fail; if (TempBit->StartScanLine() == false) goto fail; for (y = rc.top; y < rc.bottom; y++) { SP = TempBit->GetScanLine(y - rc.top); for (x = rc.left; x < rc.right; x++) { DP = Image->Bitmap->GetScanLine(h - x); DP[y - rc.top + rc.left] = SP[x - rc.left]; Image->Bitmap->PutScanLine(h - x); } } TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); Image->Repaint(); return; fail: TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbRotateRClick(TObject *Sender) { Byte *SP, *DP; RECT rc = ReadyToTempBitmap(); int x, y; if (Image->Bitmap->StartScanLine() == false) goto fail; if (TempBit->StartScanLine() == false) goto fail; for (y = rc.top; y < rc.bottom; y++) { SP = TempBit->GetScanLine(y - rc.top); for (x = rc.left; x < rc.right; x++) { DP = Image->Bitmap->GetScanLine(rc.top + x - rc.left); DP[rc.right - 1- y + rc.top] = SP[x - rc.left]; Image->Bitmap->PutScanLine(rc.top + x - rc.left); } } TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); Image->Repaint(); return; fail: TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbShiftUClick(TObject *Sender) { Byte *SP, *DP; RECT rc = ReadyToTempBitmap(); int x, y; if (Image->Bitmap->StartScanLine() == false) goto fail; if (TempBit->StartScanLine() == false) goto fail; SP = TempBit->GetScanLine(0); DP = Image->Bitmap->GetScanLine(rc.bottom-1); memcpy(DP+rc.left, SP, TempBit->Width); Image->Bitmap->PutScanLine(rc.bottom-1); for (y = rc.top+1; y < rc.bottom; y++) { SP = TempBit->GetScanLine(y - rc.top); DP = Image->Bitmap->GetScanLine(y-1); for (x = rc.left; x < rc.right; x++) { DP[x] = SP[x - rc.left]; } Image->Bitmap->PutScanLine(y-1); } TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); Image->Repaint(); return; fail: TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbShiftRClick(TObject *Sender) { Byte *SP, *DP; RECT rc = ReadyToTempBitmap(); int x, y; if (Image->Bitmap->StartScanLine() == false) goto fail; if (TempBit->StartScanLine() == false) goto fail; for (y = rc.top; y < rc.bottom; y++) { SP = TempBit->GetScanLine(y - rc.top); DP = Image->Bitmap->GetScanLine(y); for (x = rc.left; x < rc.right-1; x++) { DP[x+1] = SP[x - rc.left]; } DP[rc.left] = SP[rc.right - rc.left - 1]; Image->Bitmap->PutScanLine(y); } TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); Image->Repaint(); return; fail: TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbShiftDClick(TObject *Sender) { Byte *SP, *DP; RECT rc = ReadyToTempBitmap(); int x, y; if (Image->Bitmap->StartScanLine() == false) goto fail; if (TempBit->StartScanLine() == false) goto fail; for (y = rc.top; y < rc.bottom - 1; y++) { SP = TempBit->GetScanLine(y - rc.top); DP = Image->Bitmap->GetScanLine(y+1); for (x = rc.left; x < rc.right; x++) { DP[x] = SP[x - rc.left]; } Image->Bitmap->PutScanLine(y+1); } SP = TempBit->GetScanLine(rc.bottom - rc.top - 1); DP = Image->Bitmap->GetScanLine(rc.top); memcpy(DP+rc.left, SP, TempBit->Width); Image->Bitmap->PutScanLine(rc.top); TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); Image->Repaint(); return; fail: TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbShiftLClick(TObject *Sender) { Byte *SP, *DP; RECT rc = ReadyToTempBitmap(); int x, y; if (Image->Bitmap->StartScanLine() == false) goto fail; if (TempBit->StartScanLine() == false) goto fail; for (y = rc.top; y < rc.bottom; y++) { SP = TempBit->GetScanLine(y - rc.top); DP = Image->Bitmap->GetScanLine(y); for (x = rc.left+1; x < rc.right; x++) { DP[x-1] = SP[x - rc.left]; } DP[rc.right - 1] = SP[0]; Image->Bitmap->PutScanLine(y); } TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); Image->Repaint(); return; fail: TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { switch (menuitem) { case TOFF: if (Button == mbLeft) { BlackShape->BringToFront(); Color = BLACK; } else if (Button == mbRight) { WhiteShape->BringToFront(); Color = WHITE; } if (DKind == dmDot) { if (X>=0 && XBitmap->Width && Y>=0 && YBitmap->Height) { TextureUndo->Save(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); down = true; DrawDot(Image->Bitmap, X, Y); } } else if (DKind == dmCLine) { if (step == 0) { TextureUndo->Save(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); First = Point(X, Y); Second = Point(X, Y); CopyToTempBitmap(Image->Bitmap); DrawLine(Image->Bitmap, Color); step = 1; // move = true; } else { if (IsDraw) Image->Bitmap->Copy(TempBit, SRCCOPY); TextureUndo->Save(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); Second = Point(X, Y); DrawLine(Image->Bitmap, Color); First = Point(X, Y); CopyToTempBitmap(Image->Bitmap); } } else { if (step == 0) { TextureUndo->Save(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); First = Point(X, Y); Second = Point(X, Y); CopyToTempBitmap(Image->Bitmap); DrawLine(Image->Bitmap, Color); step = 1; // move = true; } else { if (IsDraw) Image->Bitmap->Copy(TempBit, SRCCOPY); Second = Point(X, Y); DrawLine(Image->Bitmap, Color); IsDraw = false; step = 0; // move = false; } } break; case TWIN: if (Button == mbLeft) WindowMouseDown(X, Y); break; case TMOVE: if (Button == mbLeft) MoveCopyMouseDown(X, Y); break; case TCOPY: if (Button == mbLeft) { //qe TextureUndo->Save(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); MoveCopyMouseDown(X, Y); } break; case TREPEAT: if (Button == mbLeft) RepeatMouseDown(X, Y); break; case TFILL: if (Button == mbLeft) FillMouseDown(X, Y); break; case TFILE: if (fileitem == READ_W) if (Button == mbLeft) { TextureUndo->Save(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); ReadWindowMouseDown(X, Y); } if (Button == mbRight) { OnMouseMoving(); InitFileForm(); } break; } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::CopyToTempBitmap(TTexpiaBitmap *bmp) { if (TempBit->Create(bmp->Width, bmp->Height, 8, rgb) == false) { TempBit->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } TempBit->Copy(bmp, SRCCOPY); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { switch (menuitem) { case TOFF: if (DKind == dmDot) { DrawDot(Image->Bitmap, X, Y); } else if (DKind == dmCLine) { if (step > 0) { if (IsDraw) Image->Bitmap->Copy(TempBit, SRCCOPY); Second = Point(X, Y); DrawLine(Image->Bitmap, Color); } } else { if (step > 0) { if (IsDraw) Image->Bitmap->Copy(TempBit, SRCCOPY); Second = Point(X, Y); DrawLine(Image->Bitmap, Color); } } break; case TWIN: WindowMouseMove(X, Y); break; case TMOVE: case TCOPY: case TFILL: MoveCopyFillMouseMove(X, Y); break; case TREPEAT: RepeatMouseMove(X, Y); break; case TFILE: if (fileitem == READ_W) ReadWindowMouseMove(X, Y); break; } TextX->Caption = X+1; TextY->Caption = Image->Bitmap->Height - Y; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ImageMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (DKind == dmDot) { DrawDot(Image->Bitmap, X, Y); Image->Repaint(); down = false; } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ScrollBarVScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { Image->PositionY = ScrollBarV->Max - ScrollBarV->Position; Ruler->StartY = ScrollBarV->Max - ScrollBarV->Position; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ScrollBarHScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { Image->PositionX = ScrollBarH->Position; Ruler->StartX = ScrollBarH->Position; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::TimerTimer(TObject *Sender) { Image->OutlineBitmapRgn(); } //--------------------------------------------------------------------------- // file event /// void __fastcall TTextureDesignForm::sbReadSaveClick(TObject *Sender) { OnMouseMoving(); if (menuitem == TFILE) ExitFileForm(); else InitFileForm(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbNewClick(TObject *Sender) { TextureForm->NewDirectory(Image->Bitmap->Width); InitFileButton(1); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbExitClick(TObject *Sender) { ExitFileForm(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbNormalClick(TObject *Sender) { if (sbNormal->Down) fileitem = READ_N; else fileitem = NONE; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbReadWindowClick(TObject *Sender) { if (sbReadWindow->Down) fileitem = READ_W; else fileitem = NONE; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbOverWriteClick(TObject *Sender) { if (sbOverWrite->Down) fileitem = SAVE_O; else fileitem = NONE; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbInsertClick(TObject *Sender) { TTexBitData *bip = NULL, *cmp; TFound *fd; TDeriv *dt; TSpecial *sp; int i; if (sbInsert->Down) fileitem = SAVE_I; else fileitem = NONE; AnsiString name = ""; if (InputQuery(IDS_COMMON_INSERTTEXTURE, IDS_COMMON_INPUTNAME, name)) { if (TextureForm->Item == 0) { fd = (TFound *)TextureForm->Texture->f[TextureForm->ptsItem]->Items[TextureForm->Index]; for (i=0; idata->Count; i++) { cmp = (TTexBitData *)fd->data->Items[i]; if (strcmp(cmp->Name, name.c_str()) == 0) { MessageDlg(IDS_MESSAGE_FILEEXIST, mtWarning, TMsgDlgButtons()<Item == 1) { dt = (TDeriv *) TextureForm->Texture->d[TextureForm->ptsItem]->Items[TextureForm->Index]; for (i=0; idata->Count; i++) { cmp = (TTexBitData *)dt->data->Items[i]; if (strcmp(cmp->Name, name.c_str()) == 0) { MessageDlg(IDS_MESSAGE_FILEEXIST, mtWarning, TMsgDlgButtons()<Item == 2) { sp = (TSpecial *) TextureForm->Texture->s->Items[TextureForm->Index]; for (i=0; idata->Count; i++) { cmp = (TTexBitData *)sp->data->Items[i]; if (strcmp(cmp->Name, name.c_str()) == 0) { MessageDlg(IDS_MESSAGE_FILEEXIST, mtWarning, TMsgDlgButtons()<Create(name, CenterImage->Bitmap->Width, CenterImage->Bitmap->Height, DrawImage->Bitmap->Height)) goto fail; CenterImage->Bitmap->SaveToMemory(bip->pBitmap, bip->Width, true); LiftImage->Bitmap->SaveToMemory(bip->pLiftBitmap, bip->Shaft, true); DrawImage->Bitmap->SaveToMemory(bip->pDrawBitmap, bip->Width, true); } else { if (!bip->Create(name, Image->Bitmap->Width, Image->Bitmap->Height)) goto fail; Image->Bitmap->SaveToMemory(bip->pBitmap, bip->Width, true); } TextureForm->InsertTexture(bip); } fileitem = READ_N; InitFileButton(1); return; fail: if (bip) delete bip; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbDelTextureClick(TObject *Sender) { if (sbDelTexture->Down) fileitem = DELETE_T; else fileitem = NONE; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbDelGroupClick(TObject *Sender) { TextureForm->DeleteTextureGroup(); fileitem = READ_N; InitFileButton(1); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbNameTextureClick(TObject *Sender) { if (sbNameTexture->Down) fileitem = RENAME_T; else fileitem = NONE; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbNameGroupClick(TObject *Sender) { TextureForm->RenameTextureGroup(); InitFileButton(1); fileitem = READ_N; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::CScrollBarHScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { CRulerH->Start = ScrollPos; CenterImage->PositionX = ScrollPos; DrawImage->PositionX = ScrollPos; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::CScrollBarVScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { int x = CScrollBarV->Max - ScrollPos; CRulerV->Start = x; CenterImage->PositionY = x; LiftImage->PositionY = x; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::LScrollBarHScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { LiftImage->PositionX = ScrollPos; LRulerH->Start = ScrollPos; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::DScrollBarVScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { int x = DScrollBarV->Max - ScrollPos; DrawImage->PositionY = x; DRulerV->Start = x; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::DrawImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { Byte *SP; if (Button == mbLeft) { if (DrawImage->Bitmap->StartScanLine() == false) goto fail; for (int y = 0; y < DrawImage->Bitmap->Height; y++) { SP = DrawImage->Bitmap->GetScanLine(y); if (y == Y) SP[X] = 1; else if (SP[X]) SP[X] = 0; DrawImage->Bitmap->PutScanLine(y); } DrawImage->Bitmap->StopScanLine(); CenterImageChange(); DrawImage->Repaint(); } else if (Button == mbRight && menuitem == TFILE) InitFileForm(); return; fail: DrawImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::DrawImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { TextX->Caption = X+1; TextY->Caption = DrawImage->Bitmap->Height - Y; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::LiftImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (Button == mbLeft) { BlackShape->BringToFront(); Color = BLACK; } else if (Button == mbRight) { WhiteShape->BringToFront(); Color = WHITE; } if (DKind == dmDot) { if (X>=0 && XBitmap->Width && Y>=0 && YBitmap->Height) { TextureUndo->Save(Rect(0, 0, LiftImage->Bitmap->Width, LiftImage->Bitmap->Height)); down = true; DrawDot(LiftImage->Bitmap, X, Y); CenterImageChange(); } } else if (DKind == dmCLine) { if (step == 0) { First = Point(X, Y); Second = Point(X, Y); CopyToTempBitmap(LiftImage->Bitmap); DrawLine(LiftImage->Bitmap, Color); step = 1; } else { if (IsDraw) LiftImage->Bitmap->Copy(TempBit, SRCCOPY); TextureUndo->Save(Rect(0, 0, LiftImage->Bitmap->Width, LiftImage->Bitmap->Height)); Second = Point(X, Y); DrawLine(LiftImage->Bitmap, Color); First = Point(X, Y); CopyToTempBitmap(LiftImage->Bitmap); CenterImageChange(); } } else { if (step == 0) { First = Point(X, Y); Second = Point(X, Y); CopyToTempBitmap(LiftImage->Bitmap); DrawLine(LiftImage->Bitmap, Color); step = 1; } else { if (IsDraw) LiftImage->Bitmap->Copy(TempBit, SRCCOPY); TextureUndo->Save(Rect(0, 0, LiftImage->Bitmap->Width, LiftImage->Bitmap->Height)); Second = Point(X, Y); DrawLine(LiftImage->Bitmap, Color); IsDraw = false; step = 0; CenterImageChange(); } } if (Button == mbRight && menuitem == TFILE) InitFileForm(); LiftImage->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::LiftImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (DKind == dmDot) { if (X>=0 && XBitmap->Width && Y>=0 && YBitmap->Height) { DrawDot(LiftImage->Bitmap, X, Y); if (down) CenterImageChange(); } } else if (DKind == dmCLine) { if (step > 0) { if (IsDraw) LiftImage->Bitmap->Copy(TempBit, SRCCOPY); Second = Point(X, Y); DrawLine(LiftImage->Bitmap, Color); } } else { if (step > 0) { if (IsDraw) LiftImage->Bitmap->Copy(TempBit, SRCCOPY); Second = Point(X, Y); DrawLine(LiftImage->Bitmap, Color); } } LiftImage->Repaint(); TextX->Caption = X+1; TextY->Caption = LiftImage->Bitmap->Height - Y; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::LiftImageMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (DKind == dmDot) { DrawDot(LiftImage->Bitmap, X, Y); CenterImageChange(); LiftImage->Repaint(); down = false; } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::CenterImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (menuitem == TFILE) { if (fileitem == READ_W) if (Button == mbLeft) { TextureUndo->Save(Rect(0, 0, CenterImage->Bitmap->Width, CenterImage->Bitmap->Height)); ReadWindowMouseDown(X, Y); } if (Button == mbRight) InitFileForm(); } DetailImageRepaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::CenterImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (menuitem == TFILE) { if (fileitem == READ_W) { ReadWindowMouseMove(X, Y); DetailImageRepaint(); } } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::LineImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (menuitem == TFILE && Button == mbRight) InitFileForm(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::DetailPanelMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (menuitem == TFILE && Button == mbRight) InitFileForm(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::LiftImageMouseLeave(TObject *Sender) { if (down) down = false; if (IsDraw) { LiftImage->Bitmap->Copy(TempBit, SRCCOPY); IsDraw = false; } } //--------------------------------------------------------------------------- ////// Private Method /////////////////////////////////////////////////////// //--------------------------------------------------------------------------- // private -- Normal menu Method //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::DrawDot(TTexpiaBitmap *bmp, int X, int Y) { Byte *SP; if (down) { if (bmp->StartScanLine() == false) goto fail; SP = (Byte *) bmp->GetScanLine(Y); SP[X] = Color; bmp->PutScanLine(Y); bmp->StopScanLine(); Image->Repaint(); } return; fail: bmp->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::DrawLine(TTexpiaBitmap *bmp, int col) { HDC hDC = NULL; HBRUSH hOldBrush; HPEN hOldPen; HRGN hRgn; int nDrawMode; int ex, ey; if (WorkArea->Mask) { RECT rc = Rect(WorkArea->Range.left, WorkArea->Range.top, WorkArea->Range.right-1 , WorkArea->Range.bottom-1); WorkArea->ResetRegion(Image); hDC = bmp->CreateDC(); if (hDC == NULL) goto fail; if (col) hOldPen = SelectObject(hDC, GetStockObject(BLACK_PEN)); else hOldPen = SelectObject(hDC, GetStockObject(WHITE_PEN)); nDrawMode = GetROP2(hDC); SetROP2(hDC, R2_COPYPEN); Interporation(ex, ey); MoveToEx(hDC, First.x, First.y, NULL); LineTo(hDC, ex, ey); SetROP2(hDC, nDrawMode); SelectObject(hDC, hOldPen); bmp->DeleteDC(hDC); WorkArea->SetShapeRegion(Image, Point(rc.left, rc.top), Point(rc.right, rc.bottom), false); } else { hDC = bmp->CreateDC(); if (hDC == NULL) goto fail; if (col) hOldPen = SelectObject(hDC, GetStockObject(BLACK_PEN)); else hOldPen = SelectObject(hDC, GetStockObject(WHITE_PEN)); nDrawMode = GetROP2(hDC); SetROP2(hDC, R2_COPYPEN); Interporation(ex, ey); MoveToEx(hDC, First.x, First.y, NULL); LineTo(hDC, ex, ey); SetROP2(hDC, nDrawMode); SelectObject(hDC, hOldPen); bmp->DeleteDC(hDC); } IsDraw = true; if (bmp == Image->Bitmap) Image->Repaint(); return; fail: if (hDC) bmp->DeleteDC(hDC); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::WorkAreaDraw() { HDC hDC = NULL; HBRUSH hOldBrush; HPEN hOldPen, hPen = NULL; int nDrawMode; if ((hDC = Image->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); Rectangle(hDC, min(First.x, Second.x), min(First.y, Second.y), max(First.x+1, Second.x+1), max(First.y+1, Second.y+1)); SetROP2(hDC, nDrawMode); SelectObject(hDC, hOldPen); DeleteObject(hPen); SelectObject(hDC, hOldBrush); Image->Bitmap->DeleteDC(hDC); return; fail: if (hDC) Image->Bitmap->DeleteDC(hDC); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::Interporation(int &x, int &y) { int dx, dy; double rad, des; dx = First.x - Second.x; dy = First.y - Second.y; if (dx == 0) rad = 0; else rad = atan2(dy, dx); des = M_PI_4 / 2; if (rad == 0) { if (dx == 0) { x = Second.x; if (dy < 0) y = Second.y + 1; else y = Second.y - 1; } else if (dy == 0) { y = Second.y; if (dx < 0) x = Second.x + 1; else x = Second.x - 1; } return; } if (rad >= -des && rad <= des) { x = Second.x - 1; y = Second.y; } else if (rad >= des && rad <= 3*des) { x = Second.x - 1; y = Second.y - 1; } else if (rad >= 3*des && rad <= 5*des) { x = Second.x; y = Second.y - 1; } else if (rad >= 5*des && rad <= 7*des) { x = Second.x + 1; y = Second.y - 1; } else if (rad >= -7*des && rad <= -5*des) { x = Second.x + 1; y = Second.y + 1; } else if (rad >= -5*des && rad <= -3*des) { x = Second.x; y = Second.y + 1; } else if (rad >= -3*des && rad <= -des) { x = Second.x - 1; y = Second.y + 1; } else { x = Second.x + 1; y = Second.y; } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ReverseBitmap(TTexpiaBitmap *bmp, RECT rc) { Byte *SP; int x, y; if (bmp->StartScanLine() == false) goto fail; for (y = rc.top; y < rc.bottom; y++) { SP = bmp->GetScanLine(y); for (x = rc.left; x < rc.right; x++) { SP[x] = ~(SP[x]) & 1; } bmp->PutScanLine(y); } bmp->StopScanLine(); return; fail: bmp->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- RECT __fastcall TTextureDesignForm::ReadyToTempBitmap() { RECT rc; OnMouseMoving(); if (WorkArea->Mask) { rc = WorkArea->Range; } else { rc = Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height); } if (TempBit->Create(rc.right - rc.left, rc.bottom - rc.top, 8, rgb) == false) goto fail; TempBit->CopyFromRect(Image->Bitmap, rc.left, rc.top, SRCCOPY); TextureUndo->Save(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); return rc; fail: TempBit->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return rc; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::WindowMouseDown(int X, int Y) { if (step == 0) { WorkArea->ResetRegion(Image); First = Point(X, Y); windraw = false; step = 1; } else { if (windraw) { WorkAreaDraw(); windraw = false; } Second = Point(X, Y); WorkArea->SetShapeRegion(Image, First, Second, false); StatusItem(1); menuitem = TOFF; step = 0; } Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::WindowMouseMove(int X, int Y) { if (step > 0) { if (windraw) { WorkAreaDraw(); windraw = false; } Second = Point(X, Y); WorkAreaDraw(); windraw = true; Image->Repaint(); } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::MoveCopyMouseDown(int X, int Y) { int dx, dy, x, y; RECT rc = WorkArea->Range; Byte *DP; Image->Bitmap->Copy(Bitmap, SRCCOPY); TextureUndo->Save(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); if (menuitem == TMOVE) { if (Image->Bitmap->StartScanLine() == false) goto fail; for (y = rc.top; y < rc.bottom; y++) { DP = Image->Bitmap->GetScanLine(y); memset(DP+rc.left, 0, rc.right - rc.left); Image->Bitmap->PutScanLine(y); } Image->Bitmap->StopScanLine(); } dx = X - TempBit->Width / 2; dy = Y - TempBit->Height / 2; if (dx < 0) dx = 0; if (dx + TempBit->Width > Image->Bitmap->Width) dx = Image->Bitmap->Width - TempBit->Width; if (dy < 0) dy = 0; if (dy + TempBit->Height > Image->Bitmap->Height) dy = Image->Bitmap->Height - TempBit->Height; Image->Bitmap->CopyToRect(dx, dy, TempBit, SRCCOPY); if (menuitem == TMOVE) { sbMove->Down = false; Shape11->Pen->Color = clBlack; Shape11->Brush->Color = clBlack; menuitem = TOFF; WorkArea->ResetRegion(Image); WorkArea->SetShapeRegion(Image, Point(dx, dy), Point(dx+TempBit->Width - 1, dy+TempBit->Height - 1), false); } else { Bitmap->Copy(Image->Bitmap, SRCCOPY); } Image->Repaint(); move = false; return; fail: Image->Bitmap->StopScanLine(); move = false; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::MoveCopyFillMouseMove(int X, int Y) { int dx, dy; Image->Bitmap->Copy(Bitmap, SRCCOPY); dx = X - TempBit->Width / 2; dy = Y - TempBit->Height / 2; if (dx < 0) dx = 0; if (dx + TempBit->Width > Image->Bitmap->Width) dx = Image->Bitmap->Width - TempBit->Width; if (dy < 0) dy = 0; if (dy + TempBit->Height > Image->Bitmap->Height) dy = Image->Bitmap->Height - TempBit->Height; Image->Bitmap->CopyToRect(dx, dy, TempBit, SRCCOPY); Image->Repaint(); move = true; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::FillMouseDown(int X, int Y) { int dx, dy, x, y, w, h, sx, sy; Byte *DP, *SP, *BP; w = TempBit->Width; h = TempBit->Height; Image->Bitmap->Copy(Bitmap, SRCCOPY); TextureUndo->Save(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); if (X <= w/2) dx = 0; else dx = X - Floor(w / 2); if (Y <= h/2) dy = 0; else dy = Y - Floor(h / 2); if (dx + TempBit->Width > Image->Bitmap->Width) dx = Image->Bitmap->Width - TempBit->Width; if (dy + TempBit->Height > Image->Bitmap->Height) dy = Image->Bitmap->Height - TempBit->Height; sy = (h - dy % h); if (Image->Bitmap->StartScanLine() == false) goto fail; if (TempBit->StartScanLine() == false) goto fail; for (y = 0; y < Image->Bitmap->Height; y++, sy++) { DP = Image->Bitmap->GetScanLine(y); if (sy >= h) sy = 0; SP = TempBit->GetScanLine(sy); sx = (w - dx % w); for (x = 0; x < Image->Bitmap->Width; x++, sx++) { if (sx >= w) sx = 0; DP[x] = SP[sx]; } Image->Bitmap->PutScanLine(y); } TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); Image->Repaint(); sbFill->Down = false; Shape14->Pen->Color = clBlack; Shape14->Brush->Color = clBlack; menuitem = TOFF; move = false; return; fail: TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::RepeatMouseDown(int X, int Y) { Image->Bitmap->Copy(Bitmap, SRCCOPY); TextureUndo->Save(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); RepeatMouseMove(X, Y); sbRepeat->Down = false; Shape13->Pen->Color = clBlack; Shape13->Brush->Color = clBlack; menuitem = TOFF; move = false; Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::RepeatMouseMove(int X, int Y) { int x, y, sx, sy, ex, ey, dx, dy, w, h, tx; Byte *DP, *SP; RECT rc = WorkArea->Range; Image->Bitmap->Copy(Bitmap, SRCCOPY); w = TempBit->Width; h = TempBit->Height; if (X >= rc.left) { sx = rc.left; if (X <= rc.right) ex = rc.right; else ex = X+1; dx = 0; } else { sx = X; ex = rc.right; dx = w - ((rc.left - sx) % w); if (dx == w) dx = 0; } if (Y >= rc.top) { sy = rc.top; if (Y <= rc.bottom) ey = rc.bottom; else ey = Y+1; dy = 0; } else { sy = Y; ey = rc.bottom; dy = h - ((rc.top - sy) % h); if (dy == h) dy = 0; } if (Image->Bitmap->StartScanLine() == false) goto fail; if (TempBit->StartScanLine() == false) goto fail; for (y = sy; y < ey; y++, dy++) { DP = Image->Bitmap->GetScanLine(y); if (dy >= h) dy = 0; SP = TempBit->GetScanLine(dy); tx = dx; for (x = sx; x < ex; x++, tx++) { if (tx >= w) tx = 0; DP[x] = SP[tx]; } Image->Bitmap->PutScanLine(y); } TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); Image->Repaint(); move = true; return; fail: TempBit->StopScanLine(); Image->Bitmap->StopScanLine(); move = true; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::RemoveAfterImage() { if (IsDraw) { if (DKind == dmCLine && step > 0) Image->Bitmap->Copy(TempBit, SRCCOPY); else TextureUndo->Read(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); step = 0; IsDraw = false; } if (Mode) DetailImageRepaint(); else Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::OnSimpleMouseMoving() { if (move) { Image->Bitmap->Copy(Bitmap, SRCCOPY); Image->Repaint(); ChangeShapeColor(0, false); move = false; } else if (windraw) { WorkAreaDraw(); windraw = false; menuitem = TOFF; step = 0; sbWinOff->Font->Color = clGreen; sbWinOn->Font->Color = clBlack; sbWinOff->Down = true; } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::OnMouseMoving() { if (move) { if (Mode) { TextureUndo->Read(Rect(0, 0, CenterImage->Bitmap->Width, CenterImage->Bitmap->Height)); ClearImage(LiftImage->Bitmap); ClearImage(DrawImage->Bitmap); SetDetailImage(); DetailImageRepaint(); } else { if (menuitem == TCOPY || menuitem == TREPEAT) { Image->Bitmap->Copy(Bitmap, SRCCOPY); //qeTextureUndo->Read(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); } else { TextureUndo->Read(Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height)); } Image->Repaint(); } if (menuitem == TFILE) { ExitFileForm(); } else { sbMove->Down = false; sbCopy->Down = false; sbFill->Down = false; sbRepeat->Down = false; } menuitem = TOFF; ChangeShapeColor(0, false); move = false; } else if (windraw) { WorkAreaDraw(); windraw = false; menuitem = TOFF; step = 0; sbWinOff->Font->Color = clGreen; sbWinOn->Font->Color = clBlack; sbWinOff->Down = true; } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ChangeShapeColor(int k, bool ok) { TShape *shape; for (int i = 11; i < 15; i++) { shape = (TShape *) FindComponent("Shape" + AnsiString(i)); if (ok && k == shape->Tag) { shape->Brush->Color = clRed; shape->Pen->Color = clRed; } else { shape->Brush->Color = clBlack; shape->Pen->Color = clBlack; } } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::StatusItem(int i) { sbMove->Enabled = i; sbCopy->Enabled = i; sbRepeat->Enabled = i; sbFill->Enabled = i; if (i) { sbWinOn->Font->Color = clGreen; RECT r = WorkArea->Range; SetRotateButton((r.right - r.left) == (r.bottom - r.top)); } else { sbWinOn->Font->Color = clBlack; } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ScrollBarEnabled() { int w, h; w = Image->Bitmap->Width * Image->ZoomIn; if (Image->Width < w) { ScrollBarH->Enabled = true; ScrollBarH->Max = (w - Image->Width) / Image->ZoomIn; } else { ScrollBarH->Enabled = false; } h = Image->Bitmap->Height * Image->ZoomIn; if (Image->Height < h) { ScrollBarV->Enabled = true; ScrollBarV->Max = (h - Image->Height) / Image->ZoomIn+1; ScrollBarV->Position = ScrollBarV->Max; } else { ScrollBarV->Enabled = false; } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::SetRotateButton(bool sw) { sbRotateL->Enabled = sw; sbRotateR->Enabled = sw; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ClearImage(TTexpiaBitmap *bmp) { Byte *DP; int y; if (bmp->StartScanLine() == false) goto fail; for (y = 0; y < bmp->Height; y++) { DP = bmp->GetScanLine(y); memset(DP, 0, bmp->Width); bmp->PutScanLine(y); } bmp->StopScanLine(); return; fail: bmp->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- // Private --- Detail Method //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::InitPanel() { if (rgMode->ItemIndex) { DetailPanel->BringToFront(); TextureUndo->RemoveAll(); TextureUndo->Set(CenterImage->Bitmap, WorkArea); if (StrToInt(EditShaft->Text) > StrToInt(EditCol->Text)) EditShaft->Text = EditCol->Text; SetLocateImage(); //-------| 1. À§Ä¡Àâ°í SetCenterImage(Image->Bitmap); // | ÇÑ ¹­À½.... 2. center ±×¸®°í SetDetailImage(); //-------| 3. ³ª¸ÓÁö ±×¸®°í.... DetailImageRepaint(); InitModeButton(0); } else { NormalPanel->BringToFront(); TextureUndo->RemoveAll(); TextureUndo->Set(Image->Bitmap, WorkArea); SetNormalImage(); Image->Repaint(); SetRotateButton(EditCol->Text == EditRow->Text); ScrollBarEnabled(); InitModeButton(1); } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::SetNormalImage() { HDC srcdc = NULL, dstdc = NULL; int w, h, sw, sh, dx, dy, y; bool ib = false, bt = false; if (Mode) { // ÇöÀç¸ðµå... Detail w = StrToInt(EditCol->Text); h = StrToInt(EditRow->Text); sw = CenterImage->Bitmap->Width; sh = CenterImage->Bitmap->Height; ib = Image->Bitmap->Create(w, h, 8, rgb); if (ib == false) goto fail; ClearImage(Image->Bitmap); if (w < sw) dx = w; else dx = sw; srcdc = CenterImage->Bitmap->CreateDC(); if (srcdc == NULL) goto fail; dstdc = Image->Bitmap->CreateDC(); if (dstdc == NULL) goto fail; if (h < sh) { BitBlt(dstdc, 0, 0, dx, h, srcdc, 0, sh - h, SRCCOPY); } else { BitBlt(dstdc, 0, h - sh, dx, sh, srcdc, 0, 0, SRCCOPY); } Image->Bitmap->DeleteDC(dstdc); CenterImage->Bitmap->DeleteDC(srcdc); } else { // ÇöÀç¸ðµå... Normal bt = Bitmap->Create(Image->Bitmap->Width, Image->Bitmap->Height, 8, rgb); if (bt == false) goto fail; Bitmap->Copy(Image->Bitmap, SRCCOPY); w = StrToInt(EditCol->Text); h = StrToInt(EditRow->Text); sw = Bitmap->Width; sh = Bitmap->Height; ib = Image->Bitmap->Create(w, h, 8, rgb); if (ib == false) goto fail; ClearImage(Image->Bitmap); if (w < sw) dx = w; else dx = sw; srcdc = Bitmap->CreateDC(); if (srcdc == NULL) goto fail; dstdc = Image->Bitmap->CreateDC(); if (dstdc == NULL) goto fail; if (h < sh) { BitBlt(dstdc, 0, 0, dx, h, srcdc, 0, sh - h, SRCCOPY); } else { BitBlt(dstdc, 0, h - sh, dx, sh, srcdc, 0, 0, SRCCOPY); } Image->Bitmap->DeleteDC(dstdc); Bitmap->DeleteDC(srcdc); } Image->SetZoom(16, 1); ZoomText->Caption = "5"; Ruler->Zoom = 16; return; fail: if (dstdc) Image->Bitmap->DeleteDC(dstdc); if (srcdc) Bitmap->DeleteDC(srcdc); if (ib) Image->Bitmap->Destroy(); if (bt) Bitmap->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::SetLocateImage() { POINT Center; int wid, hei, s, limitw, limith, totw, toth, temp; double ratio; bool cb = false, lb = false, db = false; s = StrToInt(EditShaft->Text) * 10; wid = StrToInt(EditCol->Text) * 10; hei = StrToInt(EditRow->Text) * 10; totw = DetailPanel->Width; toth = DetailPanel->Height; Center.x = totw / 2; Center.y = toth / 2; limitw = Center.x - 61; limith = Center.y - 61; if (totw > 81+wid+s) { if (limitw < wid) { Center.x = wid + 61; } CenterImage->Left = Center.x - 10 - 16 - wid; CenterImage->Width = wid; CRulerH->Left = CenterImage->Left; CRulerH->Width = wid; CRulerV->Left = CenterImage->Left - 24; CScrollBarH->Left = CenterImage->Left; CScrollBarH->Width = wid; CScrollBarH->Enabled = false; CScrollBarV->Left = Center.x - 26; LiftImage->Left = Center.x + 10; LiftImage->Width = s; LRulerH->Left = LiftImage->Left; LRulerH->Width = s; LScrollBarH->Left = LiftImage->Left; LScrollBarH->Width = s; LScrollBarH->Enabled = false; DrawImage->Left = Center.x - 10 - 16 - wid; DrawImage->Width = wid; DRulerV->Left = DrawImage->Left - 24; DScrollBarV->Left = Center.x - 26; } else { ratio = (double) (61+wid) / (81+wid+s); Center.x = totw *ratio; if (Center.x > 610) Center.x = 610; CenterImage->Left = 35; temp = Center.x - 61; CenterImage->Width = temp - (temp % 10); CRulerH->Left = CenterImage->Left; CRulerH->Width = CenterImage->Width; CRulerV->Left = CenterImage->Left - 24; CScrollBarH->Left = CenterImage->Left; CScrollBarH->Width = CenterImage->Width; CScrollBarH->Max = (wid - CenterImage->Width) / 10; CScrollBarH->Enabled = true; CScrollBarV->Left = 35 + CenterImage->Width; LiftImage->Left = Center.x + 10; temp = totw - Center.x - 20; LiftImage->Width = temp - (temp % 10) ; LRulerH->Left = LiftImage->Left; LRulerH->Width = LiftImage->Width; LScrollBarH->Left = LiftImage->Left; LScrollBarH->Width = LiftImage->Width; if (s > LiftImage->Width) { LScrollBarH->Max = (s - LiftImage->Width) / 10; LScrollBarH->Enabled = true; } else LScrollBarH->Enabled = false; DrawImage->Left = 35; temp = Center.x - 61; DrawImage->Width = temp - (temp % 10); DRulerV->Left = DrawImage->Left - 24; DScrollBarV->Left = 35 + DrawImage->Width; } if (toth > 81+hei+s) { if (hei > s) { if (limith < hei) Center.y = hei + 61; } else { if (limith < s) Center.y = toth - s - 20; } CenterImage->Top = Center.y - 10 - 16 - hei; CenterImage->Height = hei; CRulerH->Top = CenterImage->Top - 26; CRulerV->Top = CenterImage->Top - 1; CRulerV->Height = hei; CScrollBarH->Top = Center.y - 26; CScrollBarV->Top = CenterImage->Top; CScrollBarV->Height = hei; CScrollBarV->Enabled = false; LiftImage->Top = Center.y - 10 - 16 - hei; LiftImage->Height = hei; LRulerH->Top = LiftImage->Top - 26; LScrollBarH->Top = Center.y - 26; DrawImage->Top = Center.y + 10; DrawImage->Height = s; DRulerV->Top = DrawImage->Top - 1; DRulerV->Height = s; DScrollBarV->Top = DrawImage->Top; DScrollBarV->Height = s; DScrollBarV->Enabled = false; } else { ratio = (double) (61+hei) / (81+hei+s); Center.y = toth *ratio; if (Center.y > 680) Center.y = 680; CenterImage->Top = 35; temp = Center.y - 61; CenterImage->Height = temp - (temp % 10); CRulerH->Top = CenterImage->Top - 26; CRulerV->Top = CenterImage->Top - 1; CRulerV->Height = CenterImage->Height; CScrollBarH->Top = 35 + CenterImage->Height; CScrollBarV->Top = CenterImage->Top; CScrollBarV->Height = CenterImage->Height; CScrollBarV->Max = (hei - CenterImage->Height) / 10; CScrollBarV->Position = CScrollBarV->Max; CScrollBarV->Enabled = true; LiftImage->Top = 35; LiftImage->Height = CenterImage->Height; LRulerH->Top = LiftImage->Top - 26; LScrollBarH->Top = 35 + LiftImage->Height; DrawImage->Top = Center.y + 10; temp = toth - Center.y - 20; DrawImage->Height = temp - (temp % 10); DRulerV->Top = DrawImage->Top - 1; DRulerV->Height = DrawImage->Height; DScrollBarV->Top = DrawImage->Top; DScrollBarV->Height = DrawImage->Height; if (s > DrawImage->Height) { DScrollBarV->Max = (s - DrawImage->Height) / 10; DScrollBarV->Position = DScrollBarV->Max; DScrollBarV->Enabled = true; } else DScrollBarV->Enabled = false; } cb = CenterImage->Bitmap->Create(wid/10, hei/10, 8, rgb); if (cb == false) goto fail; ClearImage(CenterImage->Bitmap); lb = LiftImage->Bitmap->Create(s/10, hei/10, 8, rgb); if (lb == false) goto fail; ClearImage(LiftImage->Bitmap); db = DrawImage->Bitmap->Create(wid/10, s/10, 8, rgb); if (db == false) goto fail; ClearImage(DrawImage->Bitmap); LineImage->Left = Center.x; LineImage->Top = Center.y; LineImage->Width = totw - Center.x - 5; LineImage->Height = toth - Center.y - 5; LineDraw(); return; fail: if (cb) CenterImage->Bitmap->Destroy(); if (lb) LiftImage->Bitmap->Destroy(); if (db) DrawImage->Bitmap->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::SetCenterImage(TTexpiaBitmap *bmp) { int dw, dh, sw, sh, h, w; HDC srcdc = NULL, dstdc = NULL; dw = CenterImage->Bitmap->Width; dh = CenterImage->Bitmap->Height; sw = bmp->Width; sh = bmp->Height; if (dw > sw) w = sw; else w = dw; srcdc = bmp->CreateDC(); if (srcdc == NULL) goto fail; dstdc = CenterImage->Bitmap->CreateDC(); if (dstdc == NULL) goto fail; if (dh > sh) { BitBlt(dstdc, 0, dh - sh, w, sh, srcdc, 0, 0, SRCCOPY); } else { BitBlt(dstdc, 0, 0, w, dh, srcdc, 0, sh - dh, SRCCOPY); } CenterImage->Bitmap->DeleteDC(dstdc); bmp->DeleteDC(srcdc); return; fail: if (dstdc) CenterImage->Bitmap->DeleteDC(dstdc); if (srcdc) bmp->DeleteDC(srcdc); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- int __fastcall TTextureDesignForm::SetDetailImage() { Byte *DP, *SP, *CP, *LP = NULL; int x, y, cx, cy, dh, width, height; TPBitmap *TP = NULL; if ((TP = new TPBitmap) == NULL) goto fail; if (!TP->Create(CenterImage->Bitmap->Width, CenterImage->Bitmap->Height, 8)) goto fail; if (TP->Lock() == NULL) goto fail; CenterImage->Bitmap->SaveToMemory(TP->ScanLine(0), TP->BytesPerLine); width = CenterImage->Bitmap->Width; height = CenterImage->Bitmap->Height; dh = DrawImage->Bitmap->Height - 1; LP = (Byte *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, width); if (LP == NULL) goto fail; if (DrawImage->Bitmap->StartScanLine() == false) goto fail; if (LiftImage->Bitmap->StartScanLine() == false) goto fail; for (x = 0; x < width; x++) { if (LP[x] == 0) { DrawImagePutPixel(x, dh); LP[x] = 1; } else continue; for (cx = 0; cx < width; cx++) { for (y = 0; y < height; y++) { if (x != cx) { DP = TP->ScanLine(y)+x; SP = TP->ScanLine(y)+cx; if(*DP == *SP) { if (y == height-1) { DrawImagePutPixel(cx, dh); LP[cx] = 1; break; } continue; } else break; } else break; } //|-- CenterImage x, |-------LiftImage x; } //| | LiftImagePutPixel(TP, x, DrawImage->Bitmap->Height - 1 - dh); dh--; } LiftImage->Bitmap->StopScanLine(); DrawImage->Bitmap->StopScanLine(); HeapFree(GetProcessHeap(), 0, LP); delete TP; return DrawImage->Bitmap->Height - 1 - dh; // Minimize Shaft length.... fail: LiftImage->Bitmap->StopScanLine(); DrawImage->Bitmap->StopScanLine(); if (LP) HeapFree(GetProcessHeap(), 0, LP); if (TP) delete TP; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return 0; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::DrawImagePutPixel(int X, int Y) { Byte *DP = DrawImage->Bitmap->GetScanLine(Y); DP[X] = 1; DrawImage->Bitmap->PutScanLine(Y); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::LiftImagePutPixel(TPBitmap *TP, int CX, int LX) { Byte *CP, *LP; for (int y = 0; y < LiftImage->Bitmap->Height; y++) { LP = LiftImage->Bitmap->GetScanLine(y); CP = TP->ScanLine(y)+CX; LP[LX] = *CP; LiftImage->Bitmap->PutScanLine(y); } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::LineDraw() { LineImage->Canvas->Brush->Color = clSilver; LineImage->Canvas->FillRect(Rect(0, 0, LineImage->Width, LineImage->Height)); LineImage->Canvas->Pen->Color = clRed; LineImage->Canvas->Pen->Width = 3; LineImage->Canvas->MoveTo(0, 15); LineImage->Canvas->LineTo(LiftImage->Width + 5, 15); LineImage->Canvas->LineTo(LiftImage->Width + 5, 0); LineImage->Canvas->MoveTo(0, DrawImage->Height + 5); LineImage->Canvas->LineTo(15, DrawImage->Height + 5); LineImage->Canvas->LineTo(15, 0); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::CenterImageChange() { Byte *CP, *DP, *LP; short *TP = NULL; int x, y, w; w = DrawImage->Bitmap->Width; TP = (short *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, w*sizeof(short)); if (TP == NULL) goto fail; if (DrawImage->Bitmap->StartScanLine() == false) goto fail; for (y = 0; y < DrawImage->Bitmap->Height; y++) { DP = DrawImage->Bitmap->GetScanLine(y); for (x = 0; x < DrawImage->Bitmap->Width; x++) { if (DP[x]) TP[x] = DrawImage->Bitmap->Height - 1 - y; } } DrawImage->Bitmap->StopScanLine(); if (CenterImage->Bitmap->StartScanLine() == false) goto fail; if (LiftImage->Bitmap->StartScanLine() == false) goto fail; for (y = 0; y < CenterImage->Bitmap->Height; y++) { CP = CenterImage->Bitmap->GetScanLine(y); LP = LiftImage->Bitmap->GetScanLine(y); for (x = 0; x < CenterImage->Bitmap->Width; x++) { CP[x] = LP[TP[x]]; } CenterImage->Bitmap->PutScanLine(y); } LiftImage->Bitmap->StopScanLine(); CenterImage->Bitmap->StopScanLine(); HeapFree(GetProcessHeap(), 0, TP); CenterImage->Repaint(); return; fail: LiftImage->Bitmap->StopScanLine(); CenterImage->Bitmap->StopScanLine(); DrawImage->Bitmap->StopScanLine(); if (TP) HeapFree(GetProcessHeap(), 0, TP); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::DetailImageRepaint() { CenterImage->Repaint(); LiftImage->Repaint(); DrawImage->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::InitModeButton(int i) { sbShiftU->Enabled = i; sbShiftD->Enabled = i; sbShiftL->Enabled = i; sbShiftR->Enabled = i; sbWinOn->Enabled = i; sbWinOff->Enabled = i; sbCopy->Enabled = i; sbMove->Enabled = i; sbFill->Enabled = i; sbRepeat->Enabled = i; sbUpdown->Enabled = i; sbMirror->Enabled = i; sbRotateR->Enabled = i; sbRotateL->Enabled = i; sbZoomOut->Enabled = i; sbZoomIn->Enabled = i; sbMinShaft->Enabled = ~i & 1; EditShaft->Enabled = ~i & 1; } //--------------------------------------------------------------------------- // private -- file menu method //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::InitFileForm() { TextureForm->Visible = true; PanelFile->Visible = true; TextureForm->BringToFront(); PanelFile->BringToFront(); sbExit->Enabled = true; startmove = false; menuitem = TFILE; fileitem = READ_N; sbNormal->Down = true; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ExitFileForm() { TextureForm->Visible = false; PanelFile->SendToBack(); PanelFile->Visible = false; sbExit->Enabled = false; InitFileButton(0); menuitem = TOFF; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ReadNormal(TTexBitData *bip) { TextureUndo->RemoveAll(); EditCol->Text = bip->Width; EditRow->Text = bip->Height; if (Mode) { if (bip->Information) { EditShaft->Text = bip->Shaft; SetLocateImage(); CenterImage->Bitmap->LoadFromMemory(bip->pBitmap, bip->Width, true); LiftImage->Bitmap->LoadFromMemory(bip->pLiftBitmap, bip->Shaft, true); DrawImage->Bitmap->LoadFromMemory(bip->pDrawBitmap, bip->Width, true); } else { EditShaft->Text = bip->Width; SetLocateImage(); CenterImage->Bitmap->LoadFromMemory(bip->pBitmap, bip->Width, true); sbMinShaftClick(sbMinShaft); } DetailImageRepaint(); } else { sbWindowClick(sbWinOff); sbWinOff->Down = true; if (Image->Bitmap->Create(bip->Width, bip->Height, 8, rgb) == false) goto fail; Image->Bitmap->LoadFromMemory(bip->pBitmap, bip->Width, true); ScrollBarEnabled(); Image->Repaint(); } sbRun->Enabled = false; sbCancel->Enabled = false; SetRotateButton(EditCol->Text == EditRow->Text); ChangeShapeColor(0, false); sbMove->Down = false; sbCopy->Down = false; sbRepeat->Down = false; sbFill->Down = false; ExitFileForm(); step = 0; return; fail: Image->Bitmap->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ReadWindow(TTexBitData *bip) { bool tb = false, bc = false; if (bip->Width > Image->Bitmap->Width || bip->Height > Image->Bitmap->Height) { EXCEPTION_MESSAGE_OK(EC_FILE_NOT_READ); fileitem = READ_N; InitFileButton(1); } else { TextureUndo->RemoveAll(); tb = TempBit->Create(bip->Width, bip->Height, 8, rgb); if (tb == false) goto fail; TempBit->LoadFromMemory(bip->pBitmap, bip->Width, true); if (Mode) { bc = Bitmap->Create(CenterImage->Bitmap->Width, CenterImage->Bitmap->Height, 8, rgb); if (bc == false) goto fail; Bitmap->Copy(CenterImage->Bitmap, SRCCOPY); } else { bc = Bitmap->Create(Image->Bitmap->Width, Image->Bitmap->Height, 8, rgb); if (bc == false) goto fail; Bitmap->Copy(Image->Bitmap, SRCCOPY); } TextureForm->Visible = false; PanelFile->SendToBack(); PanelFile->Visible = false; sbExit->Enabled = false; startmove = true; } return; fail: if (bc) Bitmap->Destroy(); if (tb) TempBit->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ReadWindowMouseDown(int X, int Y) { int dx, dy, x, y; dx = X - TempBit->Width / 2; dy = Y - TempBit->Height / 2; if (Mode) { CenterImage->Bitmap->Copy(Bitmap, SRCCOPY); if (dx < 0) dx = 0; if (dx + TempBit->Width > CenterImage->Bitmap->Width) dx = CenterImage->Bitmap->Width - TempBit->Width; if (dy < 0) dy = 0; if (dy + TempBit->Height > CenterImage->Bitmap->Height) dx = CenterImage->Bitmap->Height - TempBit->Height; CenterImage->Bitmap->CopyToRect(dx, dy, TempBit, SRCCOPY); Bitmap->Copy(CenterImage->Bitmap, SRCCOPY); ClearImage(LiftImage->Bitmap); ClearImage(DrawImage->Bitmap); SetDetailImage(); } else { Image->Bitmap->Copy(Bitmap, SRCCOPY); if (dx < 0) dx = 0; if (dx + TempBit->Width > Image->Bitmap->Width) dx = Image->Bitmap->Width - TempBit->Width; if (dy < 0) dy = 0; if (dy + TempBit->Height > Image->Bitmap->Height) dx = Image->Bitmap->Height - TempBit->Height; Image->Bitmap->CopyToRect(dx, dy, TempBit, SRCCOPY); Bitmap->Copy(Image->Bitmap, SRCCOPY); } move = false; Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ReadWindowMouseMove(int X, int Y) { if (startmove) { int dx, dy; dx = X - TempBit->Width / 2; dy = Y - TempBit->Height / 2; if (Mode) { CenterImage->Bitmap->Copy(Bitmap, SRCCOPY); if (dx < 0) dx = 0; if (dx + TempBit->Width > CenterImage->Bitmap->Width) dx = CenterImage->Bitmap->Width - TempBit->Width; if (dy < 0) dy = 0; if (dy + TempBit->Height > CenterImage->Bitmap->Height) dx = CenterImage->Bitmap->Height - TempBit->Height; CenterImage->Bitmap->CopyToRect(dx, dy, TempBit, SRCCOPY); } else { Image->Bitmap->Copy(Bitmap, SRCCOPY); if (dx < 0) dx = 0; if (dx + TempBit->Width > Image->Bitmap->Width) dx = Image->Bitmap->Width - TempBit->Width; if (dy < 0) dy = 0; if (dy + TempBit->Height > Image->Bitmap->Height) dx = Image->Bitmap->Height - TempBit->Height; Image->Bitmap->CopyToRect(dx, dy, TempBit, SRCCOPY); } move = true; Image->Repaint(); } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::OverWrite(TTexBitData *bip) { if (Mode) { bip->Resize(CenterImage->Bitmap->Width, CenterImage->Bitmap->Height, DrawImage->Bitmap->Height); CenterImage->Bitmap->SaveToMemory(bip->pBitmap, bip->Width, true); LiftImage->Bitmap->SaveToMemory(bip->pLiftBitmap, bip->Shaft, true); DrawImage->Bitmap->SaveToMemory(bip->pDrawBitmap, bip->Width, true); } else { bip->Resize(Image->Bitmap->Width, Image->Bitmap->Height); Image->Bitmap->SaveToMemory(bip->pBitmap, bip->Width, true); } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::FileFunctionChange(TObject *Sender) { TTexBitData *bip = NULL; switch (fileitem) { case READ_N: TextureForm->ExtractData(&bip); ReadNormal(bip); break; case READ_W: TextureForm->ExtractData(&bip); ReadWindow(bip); InitFileButton(0); break; case SAVE_O: TextureForm->ExtractData(&bip); OverWrite(bip); TextureForm->OverWriteTexture(); fileitem = READ_N; InitFileButton(1); break; case DELETE_T: TextureForm->DeleteTexture(); fileitem = READ_N; InitFileButton(1); break; case RENAME_T: TextureForm->RenameTexture(); fileitem = READ_N; InitFileButton(1); break; } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::FileFunctionListChange(TObject *Sender) { TTextureForm *Form = (TTextureForm *) Sender; TFound *fd; if (Form->Item == 0) { fd = (TFound *) Form->Texture->f[Form->ptsItem]->Items[Form->Index]; if (fd->size == Image->Bitmap->Width && fd->size == Image->Bitmap->Height) { sbOverWrite->Enabled = true; sbInsert->Enabled = true; } else { sbOverWrite->Enabled = false; sbInsert->Enabled = false; } } else { sbOverWrite->Enabled = true; sbInsert->Enabled = true; } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::FileFunctionButtonChange(TObject *Sender) { TTextureForm *Form = (TTextureForm *) Sender; if (Form->sbFound->Down) { sbNameGroup->Enabled = false; } else { sbNameGroup->Enabled = true; } FileFunctionListChange(Sender); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::InitFileButton(int i) { sbNormal->Down = i; sbReadWindow->Down = false; sbDelTexture->Down = false; sbNameTexture->Down = false; sbOverWrite->Down = false; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::LoadFromMemory(TTexpiaBitmap *bmp, Byte *mem) { Byte *DP, *SP; int x, y; if (!(bmp->StartScanLine())) goto fail; SP = mem; for (y = bmp->Height - 1; y >= 0; y--) { DP = (Byte *) bmp->GetScanLine(y); memcpy(DP, SP, bmp->Width); bmp->PutScanLine(y); SP += bmp->Width; } bmp->StopScanLine(); return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::SaveToMemory(TTexpiaBitmap *bmp, Byte *mem) { Byte *DP, *SP; int x, y; if (!(bmp->StartScanLine())) goto fail; DP = mem; for (y = bmp->Height - 1; y >= 0; y--) { SP = (Byte *) bmp->GetScanLine(y); memcpy(DP, SP, bmp->Width); DP += bmp->Width; } bmp->StopScanLine(); return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::sbPrintClick(TObject *Sender) { TTexturePrintForm *Form = NULL; TTexpiaBitmap *Pattern = NULL; int rx, ry, size; if ((Form = new TTexturePrintForm(this)) == NULL) goto fail; Form->OnSave = TextureSaveToFile; if (Form->ShowModal() == mrOk) { if ((Pattern = new TTexpiaBitmap)==NULL) goto fail; rx = Form->spEditX->Value; ry = Form->spEditY->Value; size = Form->rgSize->ItemIndex; size = size ? (size == 1 ? 16 : 32) : 8; if (!DrawTexturePrint(Pattern, rx, ry, size, true)) goto fail; SendToPrinter(Pattern, 160, "Texture", Form->spPage->Value, Form->cbMethod->ItemIndex); delete Pattern; } else delete Form; return; fail: if (Pattern) delete Pattern; if (Form) delete Form; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::TextureSaveToFile(int x, int y, int size) { TTexpiaBitmap *Pattern = NULL, *Pattern24 = NULL; AnsiString str, fn, ext; // Char *s = NULL; PChar s; int FileNameLength, last1, last2, last3, last4; char FileIndex1, FileIndex2, FileIndex3, FileIndex4; TIniFile *IniFile = new TIniFile(DirectoryItem + "\\Directory.ini"); if (IniFile) { str = IniFile->ReadString("Texture", "Directory", "C:\\"); delete IniFile; } SaveDialog1->InitialDir = str; SaveDialog1->FileName = ""; if (SaveDialog1->Execute()){ if ((Pattern = new TTexpiaBitmap)==NULL) goto fail; if (!DrawTexturePrint(Pattern, x, y, size, false)) goto fail; if (SaveDialog1->FilterIndex == 1) ext = ".jpg"; else if (SaveDialog1->FilterIndex == 2) ext = ".bmp"; str = ExtractFileName(SaveDialog1->FileName); //=============================================================== FileNameLength = str.Length(); if(FileNameLength > 4){ last1 = FileNameLength-3; last2 = FileNameLength-2; last3 = FileNameLength-1; last4 = FileNameLength; FileIndex1 = '.'; FileIndex2 = 'j'; FileIndex3 = 'q'; FileIndex4 = 'd'; if((FileIndex1 == str[last1])&&(FileIndex2 == str[last2]) && (FileIndex3 == str[last3])&&(FileIndex4 == str[last4])){ s = "PASS"; }else s=NULL; }else s=NULL; //=============================================================== // s = AnsiStrScan(str.c_str(), '.'); //"ÆÄÀϳ×ÀÓ¿¡ '.'ÀÌ µé¾î°¡¸é ¾ÈµÇ°ÚÁÒ? ¤Ñ.¤Ñ" if (s==NULL) fn = SaveDialog1->FileName+ext; else fn = SaveDialog1->FileName; if (SaveDialog1->FilterIndex == 1) { if ((Pattern24 = new TTexpiaBitmap)==NULL) goto fail; Pattern24->Create(Pattern->Width, Pattern->Height, 24); Pattern24->Copy(Pattern, SRCCOPY); if (Pattern24->SaveToFile(fn, FILE_LEAD2JFIF, 30) == false) goto fail; delete Pattern24; } else if (SaveDialog1->FilterIndex == 2) { if (Pattern->SaveToFile(fn, FILE_BMP) == false) goto fail; } IniFile = new TIniFile(DirectoryItem + "\\Directory.ini"); if (IniFile) { IniFile->WriteString("Texture", "Directory", ExtractFileDir(SaveDialog1->FileName)); delete IniFile; } delete Pattern; } return; fail: if (Pattern) delete Pattern; } //--------------------------------------------------------------------------- bool __fastcall TTextureDesignForm::DrawTexturePrint(TTexpiaBitmap *Pattern, int rx, int ry, int size, bool IsPrint) { int wid, hei, lx, lw, tmCnt, sx[2], sy[2], ex[2], ey[2]; AnsiString str, company, date, time; TRegIniFile *Reg = NULL; TCanvas *Canvas = NULL; wid = Image->Bitmap->Width; hei = Image->Bitmap->Height; if (IsPrint) { Reg = new TRegIniFile(""); if (Reg) { Reg->RootKey = HKEY_LOCAL_MACHINE; if (Reg->OpenKey("\\SOFTWARE\\MicroSoft\\Windows", false)) company = Reg->ReadString("CurrentVersion", "RegisteredOrganization", ""); delete Reg; } date = DateToStr(Date()); time = TimeToStr(Time()); date = Format("%s %s", OPENARRAY(TVarRec, (date.c_str(), time.c_str()))); InitTexture(); tmCnt = tmap.cnt; lx = ChartSx*2 + wid * size * rx + tmCnt * size + 50; str = Format("[ TEXTURE SIZE : %d x %d ]", OPENARRAY(TVarRec, (wid, hei))); str = str + " " + date + ", " + company; lw = str.Length() * 15 + ChartSx * 2 + 50; if (!Pattern->Create(lx < lw ? lw : lx, ChartSy*2+ hei * size * ry + tmCnt * size + 200, 16)) goto fail; } else { InitTexture(); tmCnt = tmap.cnt; lx = ChartSx*2 + wid * size * rx + tmCnt * size + 50; str = Format("[ TEXTURE SIZE : %d x %d ]", OPENARRAY(TVarRec, (wid, hei))); lw = str.Length() * 8 + ChartSx * 2; if (!Pattern->Create(lx < lw ? lw : lx, ChartSy*2+ hei * size * ry + tmCnt * size + 100, 16)) goto fail; } Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); if ((Canvas = Pattern->CreateCanvas()) == NULL) goto fail; Canvas->Font->Size = 12; Canvas->Font->Color = clPurple; Canvas->Brush->Color = clWhite; Canvas->TextOut(15, 10, str); Canvas->Font->Size = 8; Canvas->Font->Color = clBlack; //Center-Chart Draw point(Canvas, 11, 50, wid, hei, tdata, (double)size, rx, ry, 0); // Lift-Chart Draw sx[0] = 11 + ChartSx + wid * size * rx + 10; sy[0] = 50; point(Canvas, sx[0], sy[0], tmCnt, hei, tmap.map[0], (double)size, rx, ry, 1); // Draw-Chart Draw sx[1] = 11; sy[1] = sy[0] + ChartSy + hei * size * ry + 31; point(Canvas, sx[1], sy[1], wid, tmCnt, tmap.map[1], (double)size, rx, ry, 2); sx[0] += ChartSx; ex[0] = sx[0] + tmCnt * size ; ey[0] = sy[0] + hei * size * ry; sx[1] += ChartSx; ex[1] = sx[1] + wid * size * rx; ey[1] = sy[1] + tmCnt * size; Canvas->MoveTo(ex[1]+10, sy[1]); Canvas->LineTo(ex[0], sy[1]); Canvas->MoveTo(ex[0], ey[0]+ChartSy); Canvas->LineTo(ex[0], sy[1]); Canvas->MoveTo(ex[1]+10, ey[1]); Canvas->LineTo(sx[0], ey[1]); Canvas->MoveTo(sx[0], ey[0]+ChartSy); Canvas->LineTo(sx[0], ey[1]); ExitTexture(); Pattern->DeleteCanvas(Canvas); Canvas = NULL; return true; fail: if (Canvas) Pattern->DeleteCanvas(Canvas); return false; } //--------------------------------------------------------------------------- bool __fastcall TTextureDesignForm::InitTexture() { Byte *sp, *dp; int c, x, y, width, height; Byte *td; width = Image->Bitmap->Width; height = Image->Bitmap->Height; CreateTextureData(width, height); if ((tmap.map[0] = (Byte *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, width * height)) == NULL) goto fail; if ((tmap.map[1] = (Byte *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, width * height)) == NULL) goto fail; td = tdata; tmap.cnt = 0; for (x = 0; x < width; x++) { for (c = 0; c < tmap.cnt; c++) { sp = td + x; dp = tmap.map[0] + c; for (y = 0; y < height; y++) { if (*sp != *dp) break; sp += width; dp += width; } if (y >= height) break; } if (c >= tmap.cnt) { sp = td + x; dp = tmap.map[0] + c; for (y = 0; y < height; y++) { *dp = *sp; sp += width; dp += width; } tmap.cnt++; } *(tmap.map[1]+c * width + x) = 1; } return true; fail: ExitTexture(); return false; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::ExitTexture() { if (tmap.map[0]) { HeapFree(GetProcessHeap(), 0, tmap.map[0]); tmap.map[0] = NULL; } if (tmap.map[1]) { HeapFree(GetProcessHeap(), 0, tmap.map[1]); tmap.map[1] = NULL; } DestroyTextureData(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::CreateTextureData(int w, int h) { tdata = (Byte *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, w * h); Image->Bitmap->SaveToMemory(tdata, w, true); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::DestroyTextureData() { if (tdata) { HeapFree(GetProcessHeap(), 0, tdata); tdata = NULL; } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::point(TCanvas *area, int sx, int sy, int lx, int ly, Byte *p, double g, int rx, int ry, int kind) { TPChart *chart = NULL; Byte *tpx, *tpy; int rex, rey, sizex, sizey; chart = new TPChart(area, sx, sy, lx, ly, g, g, rx, ry, kind); chart->outline_repeat(7); switch (kind) { case 0: rex = rx; rey = ry; break; case 1: rex = 1; rey = ry; break; case 2: rex = rx; rey = 1; break; } sizex = Image->Bitmap->Width; sizey = Image->Bitmap->Height; tpy = p; for (int y = 0; y < sizey * rey; y++) { if (y % sizey == 0) p = tpy; tpx = p; for (int x = 0; x < sizex * rex; x++) { if (x % sizex == 0) p = tpx; if (*p++) chart->point(x, y, clNavy); } } delete chart; } //---------------------------------------------------------------------------- void __fastcall TTextureDesignForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if(Key == 13 && sbRun->Enabled)sbRunClick(this); //lhskys ¿£ÅÍ·Î ½ÇÇàÇϱâ } //---------------------------------------------------------------------------