//--------------------------------------------------------------------------- #include #include #include #include #pragma hdrstop #include "YarnDesign_F.h" #include "BaseYarnDesign_F.h" #include "Common.h" #include "Exception.h" //gabriel #include "MainDesign_F.h" #include "Palette.h" #include "YarnRepeat_F.h" #include "YarnTable_F.h" #include "YarnUnit_F.h" #include "YarnPrint_F.h" #include "common.h"//gabriel: to use IDS_MESSAGE_FILEEXIST //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Rulers" #pragma link "TPImage" #pragma link "TPSelectImage" #pragma link "TPSpin" #pragma link "PColorGrid" #pragma link "TPLayerImage" //gabriel #pragma link "YarnDesignImage" #pragma link "RzPanel" #pragma link "RzEdit" #pragma link "RzSpnEdt" #pragma link "RzButton" #pragma link "RzRadChk" #pragma link "RzTabs" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define WIDTH 800 #define HEIGHT 100 #define P_HEIGHT 600 #define yDPI 160 //#define MAXWIDTH 4000 #define SetBit(r, s) (((r)[(s)>>3]) |= (BYTE)(0x0080 >> ((s)&7))) #define ResetBit(r, s) (((r)[(s)>>3]) &= (BYTE)(0xFF7F >> ((s)&7))) const int YARN_WIDTH = 800; const int YARN_HEIGHT = 100; #define min(a, b) (((a) < (b)) ? (a) : (b))//gabriel , temp #define max(a, b) (((a) > (b)) ? (a) : (b)) #define IDS_INFORMATION StringTable[0] #define IDS_YARNUNIT StringTable[1] #define IDS_YARNNUMBER StringTable[2] #define IDS_YARN StringTable[3] #define IDS_TOTALCOUNT StringTable[4] #define IDS_TWIST StringTable[5] #define IDS_TPI StringTable[6] #define IDS_HAIR StringTable[7] #define IDS_HAIREFFECT StringTable[8] #define IDS_LENGTH StringTable[9] #define IDS_DENSITY StringTable[10] #define IDS_MAKE StringTable[11] #define IDS_FUNCTION StringTable[12] #define IDS_FANCY StringTable[13] #define IDS_SUPER StringTable[14] #define IDS_MKFOLDER StringTable[15] #define IDS_DYEDYARN StringTable[16] #define IDS_SELECTCOLOR StringTable[17] #define IDS_METHOD StringTable[18] #define IDS_REDO StringTable[19] #define IDS_PENWIDTH StringTable[20] #define IDS_DEL_FOLDER StringTable[21] #define IDS_SWINDOWOFF StringTable[22] #define IDS_DETAIL StringTable[23] #define IDS_DESIGN StringTable[24] #define IDS_MEASURE StringTable[25] #define IDS_FANCYTHICK StringTable[26] #define IDS_FANCYTHICK_MEASURE StringTable[27] #define IDS_PENCOLOR StringTable[28] #define IDS_YARNUNIT StringTable[29] #define IDS_ERASER StringTable[30] #define IDS_DRAWING StringTable[31] #define IDS_DELETEFANCY StringTable[32] #define IDS_ONEREPEAT StringTable[33] #define IDS_YARNPRINT StringTable[34] #define IDS_LEAVEFANCY StringTable[35] //--------------------------------------------------------------------------- TYarnDesignForm *YarnDesignForm; //--------------------------------------------------------------------------- enum MeasureItem { NONE, POINT1, POINT2, POINT_W } MItem; //--------------------------------------------------------------------------- __fastcall TYarnDesignForm::TYarnDesignForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; //======================================================= 20051117 by lhskys tdw ¼öÁ¤ StringTable.Create(BaseDir, Language, "YarnDesign"); SetSmallFont(Font); SetSmallFont(StaticText1->Font); SetSmallFont(Label9->Font); SetSmallFont(lbUnit->Font); SetSmallFont(lbYarn->Font); SetSmallFont(lbYarn1->Font); SetSmallFont(lbYarn2->Font); SetSmallFont(lbYarn3->Font); SetSmallFont(lbYarn4->Font); SetSmallFont(lbYarnUnit1->Font); SetSmallFont(lbYarnUnit2->Font); SetSmallFont(lbYarnUnit3->Font); SetSmallFont(lbYarnUnit4->Font); SetSmallFont(sbCountUnit->Font); SetSmallFont(seCount->Font); SetSmallFont(cbSameUnit->Font); SetSmallFont(Label1->Font); SetSmallFont(Label2->Font); SetSmallFont(Label3->Font); SetSmallFont(lbSameUnit->Font); SetSmallFont(lbLengthUnit->Font); SetSmallFont(sbSameUnit->Font); SetSmallFont(seLength->Font); SetSmallFont(seYarnNumber->Font); SetSmallFont(MakeButton->Font); SetSmallFont(sbDyedYarn->Font); SetSmallFont(Label6->Font); SetSmallFont(Pencolor->Font); SetSmallFont(spPenWidth->Font); SetSmallFont(lbCalH->Font); SetSmallFont(lbCalW->Font); SetSmallFont(lbFancyThick->Font); SetSmallFont(lbFancyWidth->Font); SetSmallFont(stFancyThick->Font); SetSmallFont(stFancyWidth->Font); StaticText1->Caption = IDS_INFORMATION; Label2->Caption = IDS_COMMON_LENGTH; Label3->Caption = IDS_YARNNUMBER; //gbYarn->Caption = IDS_YARN; lbYarn->Caption = IDS_YARN; Label9->Caption = IDS_TOTALCOUNT; gbTwist->Caption = IDS_TWIST; Label4->Caption = IDS_METHOD; stTwist->Caption = "S " + AnsiString(IDS_COMMON_DIRECTION); Label5->Caption = IDS_TPI; Label6->Caption = IDS_PENWIDTH; gbHair->Caption = IDS_HAIR; cbHair->Caption = IDS_HAIREFFECT; Label7->Caption = IDS_LENGTH; Label8->Caption = IDS_DENSITY; MakeButton->Caption = IDS_MAKE; gbFunction->Caption = IDS_FUNCTION; sbFile->Hint = IDS_COMMON_FILE; sbGrid->Hint = IDS_COMMON_GRID; sbUndo->Hint = IDS_COMMON_UNDO; sbRepeat->Hint = IDS_COMMON_REPEAT; sbWindow->Hint = IDS_COMMON_WINDOW; sbMove->Hint = IDS_COMMON_MOVE; sbCopy->Hint = IDS_COMMON_COPY; cbFancy->Caption = IDS_FANCY; cbSuper->Caption = IDS_SUPER; //sbRead->Caption = IDS_COMMON_READ; //sbMkdir->Caption = IDS_MKFOLDER; //sbSave->Caption = IDS_COMMON_SAVE; //sbSaveAs->Caption = IDS_COMMON_SAVEAS; //sbDelete->Caption = IDS_COMMON_DELETE; //sbRename->Caption = IDS_COMMON_RENAME; //sbDeldir->Caption = IDS_DEL_FOLDER; sbDyedYarn->Caption = IDS_DYEDYARN; sbRect->Caption = IDS_COMMON_RECTANGLE; sbOff->Caption = IDS_SWINDOWOFF; tsDetail->Caption = IDS_DETAIL; tsDesign->Caption = IDS_DESIGN; gbMeasure->Caption = IDS_MEASURE; sbFThick->Caption = IDS_MEASURE; sbFWidth->Caption = IDS_MEASURE; lbFancyThick->Caption = IDS_FANCYTHICK; sbFancyThickMeasure->Hint = IDS_FANCYTHICK_MEASURE; Pencolor->Caption = IDS_PENCOLOR; Label1->Caption = IDS_YARNUNIT; sbErase->Hint = IDS_ERASER; gbDraw->Caption = IDS_DRAWING; lbFancyWidth->Caption = IDS_ONEREPEAT; sbYarnPrint->Hint = IDS_YARNPRINT; cbLeaveFancy->Hint = IDS_LEAVEFANCY; //cbLeaveFancy->Caption = IDS_LEAVEFANCY; // Á¼¾Æ¼­ °Á LF·Î ³öµÒ //======================================================= use_ImageRepaint_bitmapcopy = false;//gabriel } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::FormCreate(TObject *Sender) { //=================================================================== 20051121 by lhskys ini ÆÄÀÏ ¼öÁ¤ TIniFile *IniFile = new TIniFile(BaseDir+"\\YarnDesign.ini"); if (IniFile) { Left = IniFile->ReadInteger("Form", "Left", (Screen->Width-Width)>>1); Top = IniFile->ReadInteger("Form", "Top", (Screen->Height-Height)>>1); delete IniFile; } //=================================================================== yarncount = 1; // ½Ç ´ÜÀ§ °áÁ¤ // if (MainDesignForm) { /// FLengthUnit = MainDesignForm->CurrentUnit; // } else { FLengthUnit = uCm; // } OnUnitChange(); // for ( int i = 0; i < 4; i++){ FEditingYarnInfor[i] = new TInfor; } OnYarnCountChange(); SZ = false; // S twist isTPI = true; // TPI Method Review(); if (FullImage->Bitmap->Create(YARN_WIDTH, YARN_HEIGHT, 24) == false) goto fail; FullImage->Bitmap->FillRect(Rect(0, 0, YARN_WIDTH, YARN_HEIGHT), clWhite); PartImage->Color = clWhite; YarnBitmap = PartImage->Bitmap; if (YarnBitmap->Create(WIDTH, HEIGHT, 24) == false) goto fail; YarnBitmap->FillRect(Rect(0, 0, WIDTH, HEIGHT), clWhite); PartImage->AddLayer("Fancy", WIDTH, HEIGHT, 24, clWhite); FancyBitmap = PartImage->Bitmap; FancyMask = PartImage->LayerMask; /* YarnBitmap = YarnImage->YarnBitmap; FancyBitmap = YarnImage->FancyBitmap; FancyMask = YarnImage->FancyMask; */ PartImage->Index = 0; PartImage->Canvas->Brush->Color = clWhite; PartImage->Canvas->FillRect(Rect(0, 0, PartImage->Width, PartImage->Height)); BeforeMask = NULL; BeforeMask = new TTexpiaBitmap; BeforeMask->Create(FancyMask->Width, FancyMask->Height, 1); BeforeMask->FillRect(Rect(0, 0, FancyMask->Width, FancyMask->Height), clWhite); bpp = 24; propt = 1; zvalue = 16; IsDraw = false; WorkArea = NULL; // qe WorkArea = new TPWorkArea(&FancyBitmap); WorkArea->undoMax = 0; YarnUndo = new TSimpleUndo; YarnUndo->Set(FancyBitmap, WorkArea); // qe TempBitmap = NULL; Bitmap = NULL; BitmapMask = NULL; TempMask = NULL; if ((TempBitmap = new TTexpiaBitmap) == NULL) goto fail; if ((Bitmap = new TTexpiaBitmap) == NULL) goto fail; if ((BitmapMask = new TTexpiaBitmap) == NULL) goto fail; if ((TempMask = new TTexpiaBitmap) == NULL) goto fail; IsDraw = false; IsDrawLine = false; IsDrawVLine = false; //05.11.04.shin Down = false; bmake = false; fload = false; allsame = true; sameunit = false; changeunit = false; startx = 0; step = 0; pencolor = clWhite; presy = 0; preey = HEIGHT; for(int i = 0; i < 6; i++) vsble[i] = false; //FilePanel->Visible = false; YarnTableForm->Visible = false; YarnTableForm->OnYarnChange = YarnDataChange; YarnTableForm->OnDirChange = DeleteFolder; YarnTableForm->OnCloseForm = ExitFile; PartImage->Grid = false; sbCountUnit->Visible = false; //sbColorBox->DoubleBuffered = true; IndicateRectangle(0, true); DoubleBuffered = true; FullImage->Repaint(); PartImage->Repaint(); return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); // PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::FormDestroy(TObject *Sender) { for (int i = 0; i < 4; i++) { if (FEditingYarnInfor[i]) { delete FEditingYarnInfor[i]; FEditingYarnInfor[i] = NULL; } } delete YarnUndo; if (Bitmap) delete Bitmap; if (TempBitmap) delete TempBitmap; if (BeforeMask) delete BeforeMask; if (BitmapMask) delete BitmapMask; if (TempMask) delete TempMask; if (SaveFancyBitmap) delete SaveFancyBitmap; if (SaveFancyMask) delete SaveFancyMask; //=================================================================== 20051121 by lhskys ini ÆÄÀÏ ¼öÁ¤ TIniFile *IniFile = new TIniFile(BaseDir+"\\YarnDesign.ini"); if (IniFile) { if (Left<0) Left = 10; if (Top<0) Top = 10; IniFile->WriteInteger("Form", "Left", Left); IniFile->WriteInteger("Form", "Top", Top); delete IniFile; } //=================================================================== } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::seYarnNumberChange(TObject *Sender) { TLabel *lb = NULL, *lbUnit = NULL; TSpeedButton *sb = NULL; int unit, prevunit; if (seYarnNumber->Text.Length()>0) { yarncount = seYarnNumber->Value; OnYarnCountChange(); for (int i = 1; i <= 4; i++) { lb = (TLabel *) FindComponent("lbYarn" + IntToStr(i)); lbUnit = (TLabel *) FindComponent("lbYarnUnit" + IntToStr(i)); sb = (TSpeedButton *) FindComponent("sbYarn" + IntToStr(i)); lb->Enabled = (i <= yarncount); if (lb->Enabled) lb->Font->Color = clMaroon; lbUnit->Enabled = (i <= yarncount); sb->Enabled = (i <= yarncount); } /* if (yarncount == 1){ FYarnUnit.Method = FEditingYarnInfor[0]->YarnUnit.Method; FYarnUnit.System = FEditingYarnInfor[0]->YarnUnit.System; } */ CalculateCount(); Review(); } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbYarnClick(TObject *Sender) { TPoint ptScreen; TLabel *label; TSpeedButton *sb = (TSpeedButton *)Sender; int temp; TBaseYarnDesignForm *Form = new TBaseYarnDesignForm(this); Form->DIB256Palette->Palette = PaletteForm->DIB256Palette->Palette; if (sb==sbYarn1) { Form->yInfor = FEditingYarnInfor[0]; temp = 0; } else if (sb==sbYarn2) { Form->yInfor = FEditingYarnInfor[1]; temp = 1; } else if (sb==sbYarn3) { Form->yInfor = FEditingYarnInfor[2]; temp = 2; } else if (sb==sbYarn4) { Form->yInfor = FEditingYarnInfor[3]; temp = 3; } ptScreen = ClientToScreen(Point(gbYarn->Left+sb->Left+sb->Width+10, gbYarn->Top+sb->Top - 25)); Form->Left = ptScreen.x; Form->Top = ptScreen.y; Form->TakeUnit(Form->yInfor->YarnUnit, (FLengthUnit==uInch)); if (Form->ShowModal() == mrOk) { FEditingYarnInfor[temp]->YarnUnit = Form->yInfor->YarnUnit; if (CheckUnit()) FYarnUnit = FEditingYarnInfor[0]->YarnUnit; //KillFancy(); YarnVerNo = 0; label = (TLabel *) FindComponent("lbYarn" + IntToStr(temp + 1)); label->Font->Color = clNavy; CalculateCount(); if (!sameunit) cbSameUnit->Checked = false; Review(); } delete Form; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::seCountChange(TObject *Sender) { int i; double chcount; if (bchange) return; if (seCount->Text.Length() > 0) { if (seCount->Value > seCount->Max) seCount->Value = seCount->Max; else if (seCount->Value < seCount->Min) seCount->Value = seCount->Min; if (seCount->Value > 3000) { seCount->Value = 3000; return; } if (allsame){ if (FYarnUnit.Method) chcount = seCount->Value * yarncount; else chcount = seCount->Value / yarncount; for (i = 0; i < yarncount; i++) { FEditingYarnInfor[i]->Count = chcount; } } else { if (FYarnUnit.Method) chcount = seCount->Value * yarncount; else chcount = seCount->Value / yarncount; for (i = 0; i < yarncount; i++) { if ((FEditingYarnInfor[i]->YarnUnit.System == FYarnUnit.System) && (FEditingYarnInfor[i]->YarnUnit.Method == FYarnUnit.Method)) { FEditingYarnInfor[i]->Count = chcount; } else { FEditingYarnInfor[i]->Count = ConvertYarnCount(FEditingYarnInfor[i]->YarnUnit, FYarnUnit, chcount); } } } CalculateCount(true); if (FYarnData.Count){ // óÀ½ ¸¸µé ¶§¿Í ¸¸µé¾îÁø ½Ç º¯°æÇÒ ¶§ÀÇ ±¸ºÐÀ§ÇØ;; CalculateWidthHeight(); } CountV = seCount->Value; Review(); } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::stTwistClick(TObject *Sender) { if (SZ) { SZ = false; stTwist->Caption = "S " + AnsiString(IDS_COMMON_DIRECTION); } else { SZ = true; stTwist->Caption = "Z " + AnsiString(IDS_COMMON_DIRECTION); } //KillFancy(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::EditClick(TObject *Sender) { TPSpinEdit *ed = (TPSpinEdit *) Sender; ed->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::seLengthClick(TObject *Sender) { seLength->SetFocus(); seLength->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::MakeButtonClick(TObject *Sender) { if (cbLeaveFancy->Checked && cbFancy->Checked){ LeaveFancyBitmap(); //06.01.04.shin } if (MeasurePanel->Visible) sbMeaClick(this); if (FYarnData.FancyThick){ FYarnData.FancyThick = 0; FYarnData.FPoint1 = 0; FYarnData.FPoint2 = 0; } FYarnData.FancyOneRepeat = 0; //06.01.12.shin //KillFancy(); pencolor = clWhite; Shape->Brush->Color = clWhite; sbErase->Down = false; if(WorkArea->Mask) sbOffClick(this); if(menuitem == TMove || menuitem == TCopy) ResetMoveCopyMode(); InitMakeData(); Simulation(); //05.11.01.shin if (cbLeaveFancy->Checked&& cbFancy->Checked){ ChangeColor(); FancyBitmap->Copy(SaveFancyBitmap, SRCCOPY); FancyMask->Copy(SaveFancyMask, SRCCOPY); ImageRepaint(true); //cbFancy->Checked = true; //cbLeaveFancy->Checked = false; } if (zvalue >= 5) sbGrid->Enabled = true; else sbGrid->Enabled = false; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::Simulation() { int i, j; TTexpiaBitmap **TP = NULL; TTexpiaBitmap *UNIT = NULL; TTexpiaBitmap *TEMP = NULL; TPoint ptScreen; FYarnData.ImageLength = yarnMakeData.ImageWidth; FYarnData.ImageHeight = HEIGHT; YarnUndo->RemoveAll(); if (FYarnData.TYC > 1) { if ( FYarnData.TPI != 0){ // || FYarnData.TPM != 0){ // TPMºÎºÐ Ãß°¡ by Shin TP = new TTexpiaBitmap * [FYarnData.TYC]; for (i = 0; i < FYarnData.TYC; i++) { TP[i] = NULL; TP[i] = new TTexpiaBitmap; TP[i]->Create(yarnMakeData.ImageWidth, yarnMakeData.OneRepeatHeight[i + 1], 24); if (TP[i] == NULL) goto fail; DrawTPUnit(TP[i], i); } UNIT = new TTexpiaBitmap; UNIT->Create(yarnMakeData.ImageWidth, yarnMakeData.OneRepeatHeight[0], 24); if (UNIT == NULL) goto fail; MakeMultiTwistUnit(UNIT, TP); } else { TP = new TTexpiaBitmap * [FYarnData.TYC]; int pileh = 0; double sep[4] = { 0.0, 0.0, 0.0, 0.0 }; for (i = 1; i <= FYarnData.TYC; i++) pileh += yarnMakeData.OneRepeatHeight[i]; for (i = 0; i < FYarnData.TYC; i++) { sep[i] = 0; if (i == 0){ sep[i] = (yarnMakeData.OneRepeatHeight[0]/(double)pileh) * yarnMakeData.OneRepeatHeight[i + 1]; } else { sep[i] = sep[i-1] + (yarnMakeData.OneRepeatHeight[0]/(double)pileh) * yarnMakeData.OneRepeatHeight[i + 1]; } if (i == yarncount - 1){ if (yarnMakeData.OneRepeatHeight[0] - sep[i] <= 1){ sep[i] = yarnMakeData.OneRepeatHeight[0]; } else { double dtemp = 0.0; dtemp = (yarnMakeData.OneRepeatHeight[0] - sep[i])/FYarnData.TYC; for (int j = 0; j < FYarnData.TYC; j++){ sep[j] += dtemp; } } } } int ttemp = 0, isep[4] = {0, 0, 0, 0}, big = 0; double dif = 0.0; for (int i = 0; i < FYarnData.TYC; i++){ if (i == 0) isep[i] = sep[i] + 0.5; else isep[i] = sep[i] - sep[i - 1] + 0.5; if (isep[i] < 1) isep[i] = 1; if ( i == 0){ dif = sep[i] - isep[i]; big = 0; } else { if ((sep[i] - sep[i - 1]) - isep[i] > dif){ dif = (sep[i] - sep[i - 1]) - isep[i]; big = i; } } ttemp += isep[i]; if (i == FYarnData.TYC - 1){ if (ttemp <= yarnMakeData.OneRepeatHeight[0]) isep[big] = isep[big] + yarnMakeData.OneRepeatHeight[0] - ttemp; else isep[i] = isep[i] - (ttemp - yarnMakeData.OneRepeatHeight[0]); } } for (i = 0; i < FYarnData.TYC; i++) { TP[i] = NULL; TP[i] = new TTexpiaBitmap; if (i == 0) TP[i]->Create(yarnMakeData.ImageWidth, isep[i], 24); else TP[i]->Create(yarnMakeData.ImageWidth, isep[i], 24); DrawTPUnit(TP[i], i); MakeSingleTwistUnit(TP[i], i); } UNIT = new TTexpiaBitmap; UNIT->Create(yarnMakeData.ImageWidth, yarnMakeData.OneRepeatHeight[0], 24); if (UNIT == NULL) goto fail; MakeMultiTwistUnit(UNIT, TP); } } else { UNIT = new TTexpiaBitmap; UNIT->Create(yarnMakeData.ImageWidth, yarnMakeData.OneRepeatHeight[0], 24); if (UNIT == NULL) goto fail; DrawTPUnit(UNIT, 0); MakeSingleTwistUnit(UNIT, 0); } if (FYarnData.TYC > 1) { for (i = 0; i < FYarnData.TYC; i++) { delete TP[i]; TP[i] = NULL; } delete[] TP; } TEMP = new TTexpiaBitmap; TEMP->Create(yarnMakeData.ImageWidth, HEIGHT, 24); if (TEMP == NULL) goto fail; TEMP->FillRect(Rect(0, 0, TEMP->Width, TEMP->Height), clWhite); TempImage(TEMP, UNIT); if (UNIT) { delete UNIT; UNIT = NULL; } if (FYarnData.Hair) DrawHair(TEMP); if (FYarnData.Fancy) DrawFancy(TEMP); DrawYarnImage(TEMP); if (TEMP) { delete TEMP; TEMP = NULL; } ImageRepaint(true); presy = (HEIGHT - FYarnData.Thick) / 2; preey = presy + FYarnData.Thick; cbSuper->Enabled = true; bmake = true; return; fail: if (TP) { if (FYarnData.TYC > 1) { for (i = 0; i < FYarnData.TYC; i++) { if (TP[i]) { delete TP[i]; TP[i] = NULL; } } delete[] TP; } } if (UNIT) { delete UNIT; UNIT = NULL; } if (TEMP) { delete TEMP; TEMP = NULL; } EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //------------------------------------------------------------------------ void __fastcall TYarnDesignForm::seLengthChange(TObject *Sender) { if (seLength->Text.Length() > 0) { if (FLengthUnit == uCm) { yarnMakeData.ImageWidth = seLength->Value * yDPI / 2.54 + 0.5; if (yarnMakeData.ImageWidth <= 0) { seLength->Value = 2.54 * 16 / yDPI /10;//gabriel: MinValue=0.1(<--10), so / 10 yarnMakeData.ImageWidth = 16; } } else { yarnMakeData.ImageWidth = seLength->Value * yDPI; if (yarnMakeData.ImageWidth <= 16) { seLength->Value = 16.0 / yDPI/10;//gabriel yarnMakeData.ImageWidth = 16; } } bmake = false; } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbExitWinClick(TObject *Sender) { FYarnData.Hair = cbHair->Checked; seHairLength->Enabled = cbHair->Checked; seHairDensity->Enabled = cbHair->Checked; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::ScrollBarScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { FullImage->PositionX = ScrollBar->Position; Ruler->Start = ScrollBar->Position; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::seTPIChange(TObject *Sender) { if (seTPI->Text.Length() > 0) { if (isTPI) { if (seTPI->Value > 99) seTPI->Value = 99; } //KillFancy(); } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::seHairChange(TObject *Sender) { TPSpinEdit *sp = (TPSpinEdit *) Sender; if (sp->Text.Length() > 0) { if (sp->Value > 100) sp->Value = 100; if (sp->Value < 0) sp->Value = 0; } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbGridClick(TObject *Sender) { PartImage->Grid = sbGrid->Down; PartImage->GridGapX = 1; PartImage->GridGapY = 1; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbUndoClick(TObject *Sender) { if(menuitem == TCopy || menuitem == TMove) ResetMoveCopyMode(); if (sbUndo->Tag) { sbUndo->Hint = IDS_REDO; sbUndo->Tag = 0; } else { sbUndo->Hint = IDS_COMMON_UNDO; sbUndo->Tag = 1; } YarnUndo->Read(Rect(0, 0, FancyBitmap->Width, HEIGHT)); UndoMask(true); if (WorkArea->Mask) sbOffClick(this); // 8 ImageRepaint(false); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbFileClick(TObject *Sender) { InitFile(); if (MeasurePanel->Visible) sbMeaClick(this); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbExitClick(TObject *Sender) { ExitFile(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::FullImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { RectangleMove(X); Down = true; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::FullImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (Down) RectangleMove(X); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::FullImageMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (Down) { RectangleMove(X); Down = false; } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::RepeatImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TTexpiaBitmap *Temp = NULL, *TempM = NULL; Byte *dp, *dmp, *sp; int i, j; if (bmake) { if (step > 0) { // µÎ ¹øÂ° down step = 0; IndicateRectangle(0, true); sbRepeat->Enabled = true; if (WorkArea->Mask) sbOffClick(this); /*// ½ÇÀÚü¸¦ º¯°æÇÒ °æ¿ì if (FYarnData.VerNo >= 400 && !FYarnData.Dyed && !cbFancy->Checked) { HDC dcYarn, dcFancy, dcTemp; dcFancy = FancyBitmap->CreateDC(); dcYarn = YarnBitmap->CreateDC(); BitBlt(dcFancy, 0, 0, yarnMakeData.ImageWidth, HEIGHT, dcYarn, 0, 0, SRCCOPY); YarnBitmap->DeleteDC(dcYarn); FancyBitmap->DeleteDC(dcFancy); Byte *SP, *MP; FancyBitmap->StartScanLine(); FancyMask->StartScanLine(); for (int y = 0; y < HEIGHT; y++) { SP = FancyBitmap->GetScanLine(y); MP = FancyMask->GetScanLine(y); for (int x = 0; x < yarnMakeData.ImageWidth; x++, SP += 3) { if ((*SP != 255) || (*(SP + 1) != 255) || (*(SP + 2) != 255)) MP[x/8] &= ~(0x80 >> (x%8)); } FancyMask->PutScanLine(y); } FancyMask->StopScanLine(); FancyBitmap->StopScanLine(); sbRepeat->Enabled = false; } */ Rsx = propt*(min(isx, X) + fpos); Rex = propt*(max(isx, X) + FullImage->PositionX); if (Rsx == Rex) return; YarnUndo->Save(Rect(0, 0, FancyBitmap->Width, HEIGHT)); UndoMask(false); /* //---------------------> 05.11.15.shin ½ÇºÎºÐµµ ¹Ýº¹ TTexpiaBitmap *yarnTemp = new TTexpiaBitmap; yarnTemp->Create(Rex - Rsx, HEIGHT, 24); if (yarnTemp == NULL) goto fail; yarnTemp->CopyFromRect(YarnBitmap, Rsx, 0, SRCCOPY); HDC dcYarn, dcTemp; dcYarn = YarnBitmap->CreateDC(); dcTemp = yarnTemp->CreateDC(); int width = 0; while(width < YarnBitmap->Width){ BitBlt(dcYarn, width, 0, yarnTemp->Width, HEIGHT, dcTemp, 0, 0, SRCCOPY); width += yarnTemp->Width; } YarnBitmap->DeleteDC(dcYarn); yarnTemp->DeleteDC(dcTemp); delete yarnTemp; //----------< */ // Temp = new TTexpiaBitmap; TempM= new TTexpiaBitmap; Temp->Create(Rex - Rsx, HEIGHT, 24); TempM->Create(Rex - Rsx, HEIGHT, 1); TempM->FillRect(Rect(0, 0, TempM->Width, TempM->Height), clWhite); if (Temp == NULL) goto fail; if (TempM == NULL) goto fail; TempM->CopyFromRect(FancyMask, Rsx, 0, SRCCOPY); Temp->CopyFromRect(FancyBitmap, Rsx, 0, SRCCOPY); RepeatYarnImage(Temp, TempM); if (Temp) { delete Temp; Temp = NULL; } if (TempM) { delete TempM; TempM = NULL; } } else { step = 1; isx = X; fpos = FullImage->PositionX; IndicateRectangle(X, false); } } return; fail: if (Temp) { delete Temp; Temp = NULL; } EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::RepeatImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (step > 0) IndicateRectangle(X, false); } //--------------------------------------------------------------------------- TPoint __fastcall TYarnDesignForm::PointConvert(int X, int Y) //È­¸éÁÂÇ¥¸¦ imageÀÇ ÁÂÇ¥·Î { if (zvalue > 2){ X = X /(int)zvalue + PartImage->PositionX + 1; Y = Y /(int)zvalue + 1; } else { if (ExactDot > 0){ X = (double)X /((double)((int)(16*ExactDot))/10) + PartImage->PositionX + 1; Y = (double)Y /((double)((int)(16*ExactDot))/10) + 1; } } return Point(X, Y); } //--------------------------------------------------------------------------- TPoint __fastcall TYarnDesignForm::PointReConvert(int X, int Y) // imageÀÇ ÁÂÇ¥¸¦ È­¸éÁÂÇ¥·Î { if (zvalue > 2){ X = (X - PartImage->PositionX)*(int)zvalue; Y = (Y - 1)*(int)zvalue; } else { X = (X - PartImage->PositionX)*((double)((int)(16*ExactDot))/10); Y = (Y - 1)*((double)((int)(16*ExactDot))/10); } return Point(X, Y); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::PartImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { int h, ptx, pty; ptx = X/8 + PartImage->PositionX; pty = Y/8 + 1; PT = PointConvert(X, Y - 1); switch (menuitem) { case TOff : int pw; if (Button == mbMiddle || (Shift.Contains(ssShift) && Button==mbLeft)) { if (sbErase->Down){ sbErase->Down = false; sbEraseClick(this); } if (FYarnData.Dyed){ COLORREF c = FancyBitmap->GetPixelColor(ptx, pty-1); RGBQUAD q; TColor2RGB(TColor(c), q.rgbRed, q.rgbGreen, q.rgbBlue); pencolor = RGBToColor24(q); Shape->Brush->Color = TColor(c); for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ if (ptx+i-1 >= 0 && ptx+i-1 <= FancyBitmap->Width-1 && pty-1+j-1 >= 0 && pty-1+j-1 <= FancyBitmap->Height-1) if (FancyBitmap->GetPixelColor(ptx+i-1, pty-1+j-1-1) != clWhite) nearc[i+j*3] = FancyBitmap->GetPixelColor(ptx+i-1, pty-1+j-1-1); else nearc[i+j*3] = c; else nearc[i+j*3] = c; } } } else { COLORREF c = YarnBitmap->GetPixelColor(PT.x, PT.y); RGBQUAD q; TColor2RGB(TColor(c), q.rgbRed, q.rgbGreen, q.rgbBlue); FindPencolor(q); } } else if (Button == mbLeft) { Down = true; pw = spPenWidth->Value; if (pw == 1) { ls = 0; rs = 1; } else { ls = pw / 2.0; rs = pw - ls; } YarnUndo->Save(Rect(0, 0, FancyBitmap->Width, HEIGHT)); UndoMask(false); BeforeX = PT.x; BeforeY = PT.y; DrawLine(PT.x, PT.y); } return; fail: Down = false; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; case TWin: if (Button == mbLeft) WindowMouseDown(PT.x, PT.y); break; case TMove: case TCopy: YarnUndo->Save(Rect(0, 0, FancyBitmap->Width, HEIGHT)); UndoMask(false); MoveCopyMouseDown(PT.x, PT.y); break; case TMeasure: MeasureMouseDown(PT.x, PT.y); break; } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::PartImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { PT = PointConvert(X, Y - 1); switch (menuitem) { case TOff: if (Down) { DrawLine(PT.x, PT.y); ImageRepaint(false); } break; case TWin: WindowMouseMove(X, Y); break; case TMove: case TCopy: MoveCopyMouseMove(PT.x, PT.y); MaintainWorkArea(); break; case TMeasure: MeasureMouseMove(PT.x, PT.y); break; } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::PartImageMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { PT = PointConvert(X, Y); if (Down) { BeforeX = -1; ImageRepaint(false); Down = false; MaintainWorkArea(); } MItem = NONE; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbFileFunctionClick(TObject *Sender) { //TSpeedButton *sb = (TSpeedButton *) Sender; //9_30 //FItem = sb->Tag; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbMkdirClick(TObject *Sender) { /* //9_30 AnsiString dir = ""; if (InputQuery(IDS_COMMON_MAKEFOLDER, IDS_COMMON_INPUTNAME, dir)) { CreateDirectory(dir.c_str(), NULL); YarnTableForm->DirectoryListBox->Update(); } */ } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbSaveAsClick(TObject *Sender) { /* //9_30 AnsiString fn = "Noname.yan"; if (InputQuery(IDS_COMMON_SAVEAS, IDS_COMMON_INPUTNAME, fn)) { fn = FileNameExt(fn); if (!FileExists(fn)) { YarnSave(fn); } else { EXCEPTION_MESSAGE_OK(EC_FILE_EXIST_ALREADY); sbSaveAsClick(Sender); } } */ } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbRepeatClick(TObject *Sender) { TYarnRepeatForm *Form = NULL; TTexpiaBitmap *Temp = NULL, *TempBack = NULL, *TempM = NULL, *TempBM = NULL; Byte *DP, *SP, *SMP, *DMP; int i , j, ec, k = 0; if(WorkArea->Mask) sbOffClick(this); Form = new TYarnRepeatForm(this); for (i = 0; i < yarncount; i++) { for (j = 0; j < FYarnData.yInfor[i].Colors; j++) { Form->yColor[k].rgbRed = FYarnData.yInfor[i].yColor[j].rgbRed; Form->yColor[k].rgbGreen = FYarnData.yInfor[i].yColor[j].rgbGreen; Form->yColor[k].rgbBlue = FYarnData.yInfor[i].yColor[j].rgbBlue; k++; } } Form->yColors = FYarnData.Colors; Temp = new TTexpiaBitmap; Temp->Create(Rex - Rsx, HEIGHT , 24); if (Temp == NULL) { ec = EC_MEMORY_LACK; goto fail; } Temp->FillRect(Rect(0, 0, Temp->Width, Temp->Height), clWhite); TempM = new TTexpiaBitmap; TempM->Create(Rex - Rsx, HEIGHT, 1); if (TempM == NULL) { ec = EC_MEMORY_LACK; goto fail; } TempM->FillRect(Rect(0, 0, TempM->Width, TempM->Height), clWhite); TempBack = new TTexpiaBitmap; TempBack->Create(Rex - Rsx, HEIGHT , 24); if (TempBack == NULL) { ec = EC_MEMORY_LACK; goto fail; } TempBack->FillRect(Rect(0, 0, TempBack->Width, TempBack->Height), clWhite); TempBM = new TTexpiaBitmap; TempBM->Create(Rex - Rsx, HEIGHT, 1); if (TempBM == NULL) { ec = EC_MEMORY_LACK; goto fail; } TempM->FillRect(Rect(0, 0, TempBM->Width, TempBM->Height), clWhite); TempM->CopyFromRect(FancyMask, Rsx, 0, SRCCOPY); Temp->CopyFromRect(FancyBitmap, Rsx, 0, SRCCOPY); TempBack->CopyFromRect(YarnBitmap, Rsx, 0, SRCCOPY); //proptÃß°¡ 05.11.14.shin if (Form->InitForm(Temp, TempM, TempBack, FYarnData.Dyed, propt) == false) {ec = EC_MEMORY_LACK; goto fail;} if (Form->ShowModal() == mrOk) { /* //---------------------> 05.11.15.shin ½ÇºÎºÐµµ ¹Ýº¹ TTexpiaBitmap *yarnTemp = new TTexpiaBitmap; yarnTemp->Create(Rex - Rsx, HEIGHT, 24); if (yarnTemp == NULL) goto fail; yarnTemp->Copy(TempBack, SRCCOPY); HDC dcYarn, dcTemp; dcYarn = YarnBitmap->CreateDC(); dcTemp = yarnTemp->CreateDC(); int width = 0; while(width < YarnBitmap->Width){ BitBlt(dcYarn, width, 0, yarnTemp->Width, HEIGHT, dcTemp, 0, 0, SRCCOPY); width += yarnTemp->Width; } YarnBitmap->DeleteDC(dcYarn); yarnTemp->DeleteDC(dcTemp); delete yarnTemp; //----------< */ RepeatYarnImage(Temp, TempM); } if (Temp) { delete Temp; Temp = NULL; } if (TempM) { delete TempM; TempM = NULL; } if (TempBack) { delete TempBack; TempBack = NULL; } if (TempBM) { delete TempBM; TempBM = NULL; } delete Form; return; fail: if (Temp) delete Temp; if (TempBack) delete TempBack; if (Form) delete Form; EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- // Private Method //--------------------------------------------------------------------------- // Initdata method void __fastcall TYarnDesignForm::Review() { TLabel *label, *Unitlabel; AnsiString str, countStr; int pastcount; lbUnit->Caption = FYarnUnit.Name(); lbSameUnit->Caption = FYarnUnit.Name(); lbLengthUnit->Caption = FLengthUnit==uCm ? "Cm" : "Inch"; for (int i = 0; i < 4; i++) { if (FEditingYarnInfor[i]) { label = (TLabel *) FindComponent("lbYarn" + IntToStr(i+1)); label->Caption = GetlbYarnCaption(FEditingYarnInfor[i], i+1, FYarnUnit); Unitlabel = (TLabel *) FindComponent("lbYarnUnit" + IntToStr(i+1)); Unitlabel->Caption = GetlbYarnUnitCaption(FEditingYarnInfor[i], FYarnUnit); if (!cbSameUnit->Checked) { Unitlabel->Visible = true; } if (i > 0 && allsame) { if ((FEditingYarnInfor[i-1]->YarnUnit.Name() != FEditingYarnInfor[i]->YarnUnit.Name()) || (FEditingYarnInfor[i-1]->Count != FEditingYarnInfor[i]->Count)) allsame = false; } } } //10_1 if (sameunit) { sbCountUnit->Visible = false; if (cbSameUnit->Checked) lbSameUnit->Visible = true; } else { sbCountUnit->Visible = true; } } //--------------------------------------------------------------------------- bool __fastcall TYarnDesignForm::CheckUnit() // ÇöÀç ¼³Á¤µÈ unit°ú °¢°¢ÀÇ unitµéÀÌ ÀÏÄ¡Çϴ°¡ { bool unitdiff = false; for (int i = 0; i < yarncount; i++) { if(FEditingYarnInfor[i]) { if((FEditingYarnInfor[i]->YarnUnit.System != FYarnUnit.System) || (FEditingYarnInfor[i]->YarnUnit.Method != FYarnUnit.Method)) { unitdiff = true; } else unitdiff = false; } } return unitdiff; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::CalculateCount(bool AllCountChange) { double tot = 0; int i, unit, prevunit; sameunit = true; for (i = 0; i < 6; i++) vsble[i] = false; for (i = 0; i < yarncount; i++) { if ((YarnVerNo != 0) && (YarnVerNo < 400)) // old yarn - unitÀÌ ¸ðµÎ °°À½ { if (FEditingYarnInfor[i]) { tempcount[i] = FEditingYarnInfor[i]->Count; if (FYarnUnit.Method) { tot += (double) (1.0 / FEditingYarnInfor[i]->Count); } else tot += FEditingYarnInfor[i]->Count; } } else { if(yarncount == 1) { tempcount[0] = FEditingYarnInfor[0]->Count; } else { if (FEditingYarnInfor[i]) { unit = FindUnitIndex(FEditingYarnInfor[i]->YarnUnit); vsble[unit] = true; if (unit == FindUnitIndex(FYarnUnit)) { tempcount[i] = FEditingYarnInfor[i]->Count; } else { sameunit = false; tempcount[i] = ConvertYarnCount(FYarnUnit, FEditingYarnInfor[i]->YarnUnit, FEditingYarnInfor[i]->Count); } } } if (FYarnUnit.Method) { tot += (double) (1.0 / tempcount[i]); } else tot += tempcount[i]; } } bchange = true; double chv, calv; chv = seCount->Value; if (FYarnUnit.Method){ calv = 1 / tot; } else calv = tot; // Àüü ¹ø¼ö¸¦ ¹ø°æÇÒ ¶§¸¸ üũÇÒ ³»¿ëÀÓ 1103 // ½ÇÀ» »õ·Î ¸¸µé ¶§´Â »ó°ü¾øÁö¸¸ ÀÌ¹Ì ¸¸µé¾îÁ®ÀÖ°í ¹ø¼ö¸¦ º¯°æÇϰíÀÚ ÇÒ ¶§ ÇÊ¿ä. // ¸Å¹ø ÇÕ¿¬ÇÑ ½ÇµéÀÇ ¹ø¼ö¸¦ ´Ù½Ã °è»êÇØ¼­ º¸¿©Áִµ¥ // Á÷Á¢ ÀÔ·ÂÇÑ °ªº¸´Ù °è»êµÈ °ªÀÌ À۰ųª Ŭ ¶§ ÀÔ·ÂÇÑ ´ë·Î ³ªÅ¸³ªÁö ¾Ê´Â ¹®Á¦°¡ Àֱ⠶§¹® if (AllCountChange){ if (CountV + 1 == chv ){ if (chv > calv) seCount->Value = chv; else seCount->Value = calv; } else if (CountV - 1 == chv){ if (chv < calv) seCount->Value = chv; else seCount->Value = calv; } else { if (changeunit) seCount->Value = calv; else seCount->Value = chv; } } else { seCount->Value = calv; } changeunit = false; bchange = false; } //--------------------------------------------------------------------------- AnsiString __fastcall TYarnDesignForm::GetlbYarnCaption(TInfor *yi, int i, TYarnUnit YarnUnit) { AnsiString str, unit; if (yi->Type == 0) str = "Normal"; else if (yi->Type == 1) str = "Melange"; else if (yi->Type == 2) str = "Rainbow"; if (YarnVerNo != 0 && YarnVerNo < 400) unit = YarnUnit.Name(); else unit = yi->YarnUnit.Name(); if (yi->Count) { if (FYarnUnit.Method && (FYarnUnit.System == YU_WORSTED || FYarnUnit.System == YU_Y_S_W)) str = Format("%d) %s , 1/%d", OPENARRAY(TVarRec, (i, str.c_str(), yi->Count))); else str = Format("%d) %s , %d/1", OPENARRAY(TVarRec, (i, str.c_str(), yi->Count))); } else str = Format("%d) None", OPENARRAY(TVarRec, (i))); return str; } //--------------------------------------------------------------------------- AnsiString __fastcall TYarnDesignForm::GetlbYarnUnitCaption(TInfor *yi, TYarnUnit YarnUnit) { AnsiString str, unit; if (YarnVerNo != 0 && YarnVerNo < 400) unit = YarnUnit.Name(); else unit = yi->YarnUnit.Name(); if (yi->Count) { str = Format("(Unit : %s )",OPENARRAY(TVarRec,(unit))); } return str; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::OnYarnCountChange() { for (int i = 0; i < 4; i++){ if (i < yarncount){ if (FEditingYarnInfor[i] == NULL) { FEditingYarnInfor[i] = new TInfor; InitYarnInfor(i); } } else { if (FEditingYarnInfor[i]) { delete FEditingYarnInfor[i]; FEditingYarnInfor[i] = NULL; } } } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::InitYarnInfor(int i) { FEditingYarnInfor[i]->YarnUnit.System = FYarnUnit.System; FEditingYarnInfor[i]->YarnUnit.Method = FYarnUnit.Method; FEditingYarnInfor[i]->Count = 5; FEditingYarnInfor[i]->TPI = 5; FEditingYarnInfor[i]->Colors = 1; for (int j = 0; j < 8; j++){ FEditingYarnInfor[i]->yColor[j].rgbBlue = 0; FEditingYarnInfor[i]->yColor[j].rgbGreen = 0; FEditingYarnInfor[i]->yColor[j].rgbRed = 0; FEditingYarnInfor[i]->yColor[j].rgbReserved = 0; } } //---------------------------------------------------------------------------// simulation method void __fastcall TYarnDesignForm::InitMakeData() { RulerZoom->Zoom = 16; FYarnData.TYC = yarncount; // ½Ç Á¤º¸ ÃʱâÈ­ if (FYarnData.yInfor) { delete[] FYarnData.yInfor; FYarnData.yInfor = NULL; } FYarnData.yInfor = new TInfor[yarncount]; for (int i = 0; i < yarncount; i++) { FYarnData.yInfor[i].Copy(FEditingYarnInfor[i]); } // ÃÑ »ç¿ëµÈ »ö»ó °è»ê FYarnData.Colors = 0; for (int i = 0; i < FYarnData.TYC; i++){ FYarnData.Colors += FYarnData.yInfor[i].Colors; } // ½Ç ¼³°è µ¥ÀÌÅÍ ÀÔ·Â FYarnData.TYC = yarncount; FYarnData.SZ = SZ; if (isTPI) { FYarnData.TPI = seTPI->Value; } else { FYarnData.TPM = seTPI->Value; } FYarnData.Hair = cbHair->Checked; //FYarnData.Fancy = cbFancy->Checked; FYarnData.Fancy = false; FYarnData.Count = seCount->Value; allcount = seCount->Value; // ÃÑ ¹ø¼ö FYarnData.Unit.Copy(FYarnUnit); FYarnData.DPI = yDPI; if (FLengthUnit == uCm) FYarnData.Length = seLength->Value * FYarnData.DPI / 2.54; // ½Ç ±æÀÌ else FYarnData.Length = seLength->Value * FYarnData.DPI; yarnMakeData.ImageWidth = FYarnData.Length; CalculateWidthHeight(); FYarnData.Thick = yarnMakeData.OneRepeatHeight[0]; FYarnData.ExactThick = ExactDot; if (FYarnData.Hair) FYarnData.Width = HEIGHT; else FYarnData.Width = FYarnData.Thick; FYarnData.Dyed = false; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::CalculateWidthHeight() { int i; double odot; yarnMakeData.OneRepeatWidthLCM = 0; for (i = 0; i <= FYarnData.TYC; i++) { if (i) { if (FYarnData.yInfor) { odot = Count2Dot(FYarnData.DPI, FYarnUnit, tempcount[i-1]); yarnMakeData.OneRepeatWidth[i] = propt * FYarnData.DPI / FYarnData.yInfor[i-1].TPI + 0.5; // 0¹ø ½ÇÀ» 1¹ø ¹è¿­¿¡ ³Ö´Â´Ù. // ÇÕ¿¬µÈ ½Ç Áß °¡´Â½ÇÀÇ ºñÀ²ÀÌ ³Ê¹« ÀûÀ» ¶§ 1¹Ì¸¸ÀÌ¸é ³ªÅ¸³ªÁö ¾ÊÀ½. // À̶§´Â ¹«Á¶°Ç 1·Î. if (propt * odot < 1) yarnMakeData.OneRepeatHeight[i] = 1; else yarnMakeData.OneRepeatHeight[i] = propt * odot; yarnMakeData.OneRepeatWidthLCM = LCM(yarnMakeData.OneRepeatWidthLCM, yarnMakeData.OneRepeatWidth[i]); } else break; } else { ExactDot = Count2Dot(FYarnData.DPI, FYarnUnit, FYarnData.Count); FYarnData.RealThick = (25.4 / FYarnData.DPI)* ExactDot; if (ExactDot >= 10) { yarnMakeData.OneRepeatHeight[0] = ExactDot; propt = 1; } else { yarnMakeData.OneRepeatHeight[0] = 10; propt = 10 / ExactDot; } if (FYarnData.TPI == 0) { yarnMakeData.OneRepeatWidth[0] = 0; } else { yarnMakeData.OneRepeatWidth[0] = propt * FYarnData.DPI / FYarnData.TPI + 0.5; } yarnMakeData.OneRepeatWidthLCM = yarnMakeData.OneRepeatWidth[0]; } } // ¿©±â¼­ zoom °ªÀ» °áÁ¤ÇÏ°í ±×¿¡ µû¶ó ±æÀ̸¦ °áÁ¤. // ÇöÀç part image¿¡ º¸¿©Áö´Â ºÎºÐÀº 16¹è È®´ëµÈ Å©±âÀ̰í // ½ÇÀÇ À̹ÌÁö´Â ¸ðµÎ 10dot·Î ¸¸µé¾îÁü. // 10dot·Î ¸¸µé¾îÁø ½ÇÀº ½ÇÁ¦ dot¿¡¼­ propt¸¸Å­ È®´ë°¡ µÈ »óÅÂÀ̰í // °Å±â¿¡¼­ zvalue¸¸Å­ È®´ëµÇ¾î °á±¹ 16¹è È®´ë°¡ µÊ. zvalue = 16 / propt; PartImage->PositionY = 0; PartImage->Left = 0; if (zvalue < 2){ PartImage->Height = YarnBitmap->Height * 16 * ExactDot / 10; PartImage->Top = PanelPart->Height/2 - PartImage->Height/ 2; PartImage->SetZoom(16 * ExactDot, 10); } else { PartImage->Height = YarnBitmap->Height * (int)zvalue; PartImage->Top = PanelPart->Height/2 - PartImage->Height/ 2; PartImage->SetZoom(zvalue, 1); propt = 16.0/(int)zvalue; } yarnMakeData.ImageWidth = yarnMakeData.ImageWidth * propt + 0.5; } //--------------------------------------------------------------------------- void __fastcall ReadyToMelangeColor(Byte *cs, TInfor *yi) { int i, j, k; for (i = 0, j = 0, k = 0; i < 100; i++, k++) { if (k >= yi->Method[j].Number) { j++; k = 0; } if (j >= yi->Methods) j = yi->Methods - 1; cs[i] = j; } } //--------------------------------------------------------------------------- // ÇÕ¿¬µÇ´Â °¢°¢ÀÇ ½ÇÀÇ À̹ÌÁö¸¦ ¸¸µç´Ù void __fastcall TYarnDesignForm::DrawTPUnit(TTexpiaBitmap *Image, int i) { TInfor *yi; Byte *IP, cs[100], type, r, g, b; int sx, sy, ex, ey, mm, j, x, y, k; short uw, *length = NULL; double h, l, s, nh, nl, ns, pnl; int term, fterm, slope, sl, nslope, center, fcenter; yi = &FYarnData.yInfor[i]; type = yi->Type; Image->StartScanLine(); RGBQUAD rgbWhite, rgbWhiteN, rgbBlack, rgbBlackN; rgbWhite.rgbRed = 0xFF; rgbWhite.rgbGreen = 0xFF; rgbWhite.rgbBlue = 0xFF; rgbWhite.rgbRed = 0xFF; rgbWhite.rgbGreen = 0xFF; rgbWhite.rgbBlue = 0xFF; rgbWhiteN.rgbRed = 0xFE; rgbWhiteN.rgbGreen = 0xFE; rgbWhiteN.rgbBlue = 0xFE; rgbBlack.rgbBlue = 0x00; rgbBlack.rgbGreen = 0x00; rgbBlack.rgbRed = 0x00; rgbBlackN.rgbBlue = 0x01; rgbBlackN.rgbGreen = 0x01; rgbBlackN.rgbRed = 0x01; // rgb(255,255,255) -> rgb(254, 254, 254) // rgb(0, 0, 0,) -> rgb(1, 1, 1) for(int j = 0; j < FYarnData.yInfor[i].Colors; j++){ if (FYarnData.yInfor[i].yColor[j].rgbBlue == rgbWhite.rgbBlue && FYarnData.yInfor[i].yColor[j].rgbGreen == rgbWhite.rgbGreen && FYarnData.yInfor[i].yColor[j].rgbRed == rgbWhite.rgbRed) FYarnData.yInfor[i].yColor[j] = rgbWhiteN; else if (FYarnData.yInfor[i].yColor[j].rgbBlue == rgbBlack.rgbBlue && FYarnData.yInfor[i].yColor[j].rgbGreen == rgbBlack.rgbGreen && FYarnData.yInfor[i].yColor[j].rgbRed == rgbBlack.rgbRed) FYarnData.yInfor[i].yColor[j] = rgbBlackN; } if (type == 0) // normal { for (y = 0; y < Image->Height; y++) { if (yi->SZ) { IP = Image->GetScanLine(y) + 3 * (Image->Width - 1); for (x = 0; x < Image->Width; x++, IP -=3) { *IP = FYarnData.yInfor[i].yColor->rgbBlue; *(IP + 1) = FYarnData.yInfor[i].yColor->rgbGreen; *(IP + 2) = FYarnData.yInfor[i].yColor->rgbRed; } Image->PutScanLine(y); } else { IP = Image->GetScanLine(y); for (x = 0; x < Image->Width; x++, IP += 3 ) { *IP = FYarnData.yInfor[i].yColor->rgbBlue; *(IP + 1) = FYarnData.yInfor[i].yColor->rgbGreen; *(IP + 2) = FYarnData.yInfor[i].yColor->rgbRed; } Image->PutScanLine(y); } } } else if (type == 1) { //Melange Draw ReadyToMelangeColor(cs, yi); for (y = 0; y < Image->Height; y++) { if (yi->SZ){ IP = Image->GetScanLine(y) + 3 * (Image->Width - 1); for (x = 0; x < Image->Width; x++, IP -= 3) { // Z k = cs[random(100)]; if (FYarnData.Colors == 1 ) { *IP = FYarnData.yInfor->yColor->rgbBlue; *(IP + 1) = FYarnData.yInfor->yColor->rgbGreen; *(IP + 2) = FYarnData.yInfor->yColor->rgbRed; } else { if ( yarncount > 1 ){ // ¿©·¯°¡´Ú *IP = FYarnData.yInfor[i].yColor[k].rgbBlue; *(IP + 1) = FYarnData.yInfor[i].yColor[k].rgbGreen; *(IP + 2) = FYarnData.yInfor[i].yColor[k].rgbRed; } else { *IP = FYarnData.yInfor->yColor[k].rgbBlue; // ÇѰ¡´Ú *(IP + 1) = FYarnData.yInfor->yColor[k].rgbGreen; *(IP + 2) = FYarnData.yInfor->yColor[k].rgbRed; } } } } else { IP = Image->GetScanLine(y); for (x = 0; x < Image->Width; x++, IP += 3) { // S k = cs[random(100)]; if (FYarnData.Colors == 1 ) { *IP = FYarnData.yInfor->yColor->rgbBlue; *(IP + 1) = FYarnData.yInfor->yColor->rgbGreen; *(IP + 2) = FYarnData.yInfor->yColor->rgbRed; } else { if ( yarncount > 1 ){ // ¿©·¯°¡´Ú *IP = FYarnData.yInfor[i].yColor[k].rgbBlue; *(IP + 1) = FYarnData.yInfor[i].yColor[k].rgbGreen; *(IP + 2) = FYarnData.yInfor[i].yColor[k].rgbRed; } else { *IP = FYarnData.yInfor->yColor[k].rgbBlue; // ÇѰ¡´Ú *(IP + 1) = FYarnData.yInfor->yColor[k].rgbGreen; *(IP + 2) = FYarnData.yInfor->yColor[k].rgbRed; } } } } Image->PutScanLine(y); } } // (type == 2) else { // 2 ->rainbow mm = FYarnData.yInfor[i].Methods; length = new short [mm * 2]; if (length) { for (j = 0, uw = 0; j < mm; j++) { uw += FYarnData.yInfor[i].Method[j].Number * propt; length[j] = uw; } for (y = 0; y < Image->Height; y++) { if (yi->SZ){ // Z direction IP = Image->GetScanLine(y) + 3 * (Image->Width - 1); for (j = 0, x = 0; x < Image->Width; x++, IP -= 3) { if (x % uw == length[j]-1) { j++; if (j == mm) j = 0; } *IP = FYarnData.yInfor[i].yColor[j].rgbBlue; *(IP + 1) = FYarnData.yInfor[i].yColor[j].rgbGreen; *(IP + 2) = FYarnData.yInfor[i].yColor[j].rgbRed; } } else { IP = Image->GetScanLine(y); //S direction for (j = 0, x = 0; x < Image->Width; x++, IP += 3) { if (x % uw == length[j]-1) { j++; if (j == mm) j = 0; } *IP = FYarnData.yInfor[i].yColor[j].rgbBlue; *(IP + 1) = FYarnData.yInfor[i].yColor[j].rgbGreen; *(IP + 2) = FYarnData.yInfor[i].yColor[j].rgbRed; } } Image->PutScanLine(y); } } if (length) delete[] length; } Image->StopScanLine(); } //---------------------------------------------------------------------------- // ²¿ÀÓÀ» ³ªÅ¸³¾ ¼ö ÀÖµµ·Ï À½¿µÀ» ÁÜ. void __fastcall TYarnDesignForm::MakeSingleTwistUnit(TTexpiaBitmap *Image, int i) { Byte *IP; double h[8], l[8], s[8], ah, al, as, nh, nl, ns, cl, ll, yl, slope, pt, plus, yplus; Byte r, g, b, nr, ng, nb; int x, y, k, j, term, type, colors; RGBQUAD *rgbColor = NULL; type = FYarnData.yInfor[i].Type; if (FYarnData.TPI == 0){ if (FYarnData.TYC > 1 || FYarnData.TPM == 0){ // TPMÃß°¡ by Shin term = (yDPI * propt - 1)/ FYarnData.yInfor[i].TPI; } else { term = (yDPI * 100 / 2.54 * propt - 1)/ FYarnData.TPM; } } else term = (yDPI * propt - 1)/( FYarnData.TPI); // 1ÀÎÄ¡´ç ²¿ÀÓÀÇ °£°Ý /* if (FYarnData.TPI == 0) term = (yDPI * propt - 1)/ FYarnData.yInfor[i].TPI; else term = (yDPI * propt - 1)/( FYarnData.TPI); // 1ÀÎÄ¡´ç ²¿ÀÓÀÇ °£°Ý */ if (type == 0) //----------------------normal { r = FYarnData.yInfor[i].yColor[0].rgbRed; g = FYarnData.yInfor[i].yColor[0].rgbGreen; b = FYarnData.yInfor[i].yColor[0].rgbBlue; RGB2HLS( r, g, b, ah, al, as); nh = ah; nl = al; ns = as; yl = al - 0.05; if (term < 10) term = 10; if ((al > 0.1) && (term/20 > 1)) plus = (al - 0.1)/(term/20); else plus = 0.001; Image->StartScanLine(); for (y = 0; y < Image->Height; y++) { slope = y * (term /Image->Height); if (term == 10) slope = 0; if (FYarnData.SZ) pt = 1 + slope; else pt = term - slope; if ( y < Image->Height /2 ) yl += 0.015; else yl -= 0.015; if ( yl >= al ) yl = al; if ( yl < yl/4) yl = yl/4; if ( yl <= 0 ) yl = 0; IP = Image->GetScanLine(y); for (x = 0; x < Image->Width; x++) { HLS2RGB( nh, yl, ns, *(IP + 3 * x + 2), *(IP + 3 * x + 1), *(IP + 3 * x )); //-------------- ¿©±â°¡ À½¿µ (ÇѰ¡Áö »öÀ̹ǷΠ±× »öÀ» °¡Áö°í Çѹø¿¡) if ( x == pt + term/4 ) { nl = yl; for ( k = x - 2*term/4; k < x - 1 ; k++ ) { if ( k > 0 ) { plus = (nl - 4*nl/7)/(term); if ( k < x - term/4) nl -= plus; else nl += plus; if ( nl >= yl ) nl = yl; if ( nl < yl - yl/4) nl = yl - yl/4; if ( nl <= 0 ) nl = 0; HLS2RGB( nh, nl, ns, *(IP + 3 * k + 2), *(IP + 3 * k + 1), *(IP + 3 * k )); } } pt += term; } //---------- ¿©±â±îÁö } Image->PutScanLine(y); } Image->StopScanLine(); } else { //--------------- rainbow, melange colors = FYarnData.yInfor[i].Methods; rgbColor = new RGBQUAD [sizeof(RGBQUAD)*colors]; for (int j = 0; j < colors; j++) { rgbColor[j] = FYarnData.yInfor[i].yColor[j]; RGB2HLS(rgbColor[j].rgbRed, rgbColor[j].rgbGreen, rgbColor[j].rgbBlue, h[j], l[j], s[j]); } Image->StartScanLine(); for( y = 0; y < Image->Height; y++) { slope = y * (term /Image->Height); if (term == 10) slope = 0; if (FYarnData.SZ) pt = 1 + slope; else pt = term - slope; IP = Image->GetScanLine(y); j = 0; for (x = 0; x < Image->Width; x++) { //---------------- À§Ä¡¸¶´ÙÀÇ »öÀ¸·Î À½¿µ if ( x == pt + term/4 ) { int count = 1; for ( k = x - 2*term/4; k < x ; k++ ) { if ( k > 0 ) { nr = *(IP + 3 * k + 2); ng = *(IP + 3 * k + 1); nb = *(IP + 3 * k); for (j = 0; j < colors; j++) { if ((nr == rgbColor[j].rgbRed) && (ng == rgbColor[j].rgbGreen) && (nb == rgbColor[j].rgbBlue)) { break; } } if (j >= colors) j = colors - 1; // Ȥ½Ã¸ð¸£´Ï.... nh = h[j]; nl = l[j]; ns = s[j]; plus = (nl - 4*nl/7)/(term); if ( k < x - term/4){ ll = nl - plus * count; } else { if ( k == x - term/4){ cl = nl - plus * count; count = 1; } ll = cl + plus * count; } count++; if ( ll >= nl ) ll = nl; if ( ll < nl - nl/4) ll = nl - nl/4; if ( ll <= 0 ) nl = 0; HLS2RGB( nh, ll, ns, *(IP + 3 * k + 2), *(IP + 3 * k + 1), *(IP + 3 * k )); /* if ((k % term == 0) && (y == 0 || y == Image->Height - 1)){ *(IP + 3 * k) = 0xFF; *(IP + 3 * k + 1) = 0xFF; *(IP + 3 * k + 2) = 0xFF; } */ } } pt += term; } //--------------- } Image->PutScanLine(y); } Image->StopScanLine(); if (rgbColor) { delete[] rgbColor; rgbColor = NULL; } } } //--------------------------------------------------------------------------- // µÎ °¡´Ú ÀÌ»óÀÇ ½ÇÀÌ ²¿¿´À» °æ¿ì ²¿ÀÓÀÇ À½¿µ ³ªÅ¸³¿. void __fastcall TYarnDesignForm::MakeMultiTwistUnit(TTexpiaBitmap *Image, TTexpiaBitmap **TP) { int i, x, y, k, pileh, index, hei, ux, uy, tot, grp, xx, yy, oldx, term, w, ix, oldi = 0; double theta, dx, dy, st, ct; TPoint rest; int dh[4] = { 0, 0, 0, 0 }; short uh[4] = { 0, 0, 0, 0 }, curve[4] = { 0, 0, 0, 0 }; BYTE *DP, *SP, *SSP; COLORREF now, old, color, cbot, ctop, temp; TInfor *yi; pileh = 0; for (i = 1; i <= yarncount; i++) { pileh += yarnMakeData.OneRepeatHeight[i]; dh[i-1] = pileh; } if (pileh >= yarnMakeData.OneRepeatWidth[0] && FYarnData.TPI != 0) { // ³Ê¹« ²Ê¹ö¸° °æ¿ì ux = 0; for (i = 0; i < yarncount; i++) { uh[i] = yarnMakeData.OneRepeatWidth[0] * ((double) yarnMakeData.OneRepeatHeight[i+1] / pileh) + 0.5; curve[i] = uh[i] / 8; if (curve[i] == 0) curve[i] = uh[i] / 4; TP[i]->StartScanLine(); } // 90µµ ȸÀü Image->StartScanLine(); for (y = 0; y < Image->Height; y++, ux++) { DP = Image->GetScanLine(Image->Height - y - 1); index = 0; uy = 0; if (ux >= yarnMakeData.OneRepeatWidth[index+1]) ux = 0; for (x = 0; x < Image->Width; x++, uy++, DP += 3) { if (uy >= uh[index]) { index++; uy = 0; if (index == yarncount) index = 0; } SP = TP[index]->GetScanLine(uy) + 3 * ux; if (uy <= uh[index]/2) { memcpy(DP, SP , 3); } else { double h, l, s; RGB2HLS(*SP, *(SP + 1), *(SP + 2), h, l, s); HLS2RGB(h, l - 0.1, s, *DP, *(DP + 1), *(DP + 2)); } } Image->PutScanLine(Image->Height - y - 1); } TP[index]->StopScanLine(); // Curve Effect index = 0; tot = 0; for (x = 0; x < Image->Width; x++) { if (x == tot) { xx = 0; if (!(curve[index] == 1 && uh[i] > 3)) { while (xx < curve[index]) { if (x + xx >= 0 && x + xx < Image->Width) { DP = Image->GetScanLine(0) + 3 *(x + xx); *DP = 0xFF; *(DP + 1) = 0xFF; *(DP + 2) = 0xFF; DP = Image->GetScanLine(Image->Height - 1) + 3 *(x + xx); *DP = 0xFF; *(DP + 1) = 0xFF; *(DP + 2) = 0xFF; } xx++; } Image->PutScanLine(0); Image->PutScanLine(Image->Height - 1); } xx = curve[index]; while (xx > 0) { if (x - xx >= 0 && x - xx < Image->Width) { DP = Image->GetScanLine(0) + 3 *(x - xx); *DP = 0xFF; *(DP + 1) = 0xFF; *(DP + 2) = 0xFF; DP = Image->GetScanLine(Image->Height - 1) + 3 *(x - xx); *DP = 0xFF; *(DP + 1) = 0xFF; *(DP + 2) = 0xFF; } xx--; } Image->PutScanLine(0); Image->PutScanLine(Image->Height - 1); tot += uh[index]; index++; if (index == yarncount) index = 0; // } } ytox = 0; Image->StopScanLine(); } else { //------------------ Àû´çÈ÷ ²Á °æ¿ì Image->StartScanLineN(2); if (FYarnData.TPI == 0) { for(i = 0; i < yarncount; i++){ TP[i]->StartScanLine(); } int hgt = 0; for (y = 0, k = 0, uy = 0; y < Image->Height; y++, uy++){ DP = Image->GetScanLineN(y, 1); if (y == 0) hgt = TP[k]->Height; if (y == hgt) { k++; uy = 0; hgt += TP[k]->Height;} for (x = 0; x < Image->Width; x++){ SP = TP[k]->GetScanLine(uy); memcpy( DP + 3 * x, SP + 3 * x , 3); } Image->PutScanLineN(y, 1); } } else { double nh, nl, ns, h[8], l[8], s[8], a, diff, cl; Byte r,g,b, nr, ng, nb; int i, oldx = 0, j, colors; RGBQUAD *rgbMel = NULL; theta = asin((double) pileh / yarnMakeData.OneRepeatWidth[0]); st = sin(theta); ct = cos(theta); grp = (double) Image->Height / (3 * tan(theta)); term = 0; for (i = 0; i < yarncount; i++) TP[i]->StartScanLine(); if (FYarnData.SZ) { //----------------------------------- Z dy = (double) Image->Width * st; hei = dy + (double) Image->Height * ct; for (y = 0; y < Image->Height; y++) { oldx = 0; DP = Image->GetScanLineN(y, 1); for (x = 0; x < Image->Width; x++) { xx = x * ct + y * st; yy = y * ct - x * st + dy; if (xx >= 0 && yy >= 0) { rest.y = (hei - yy - 1) % pileh; if (rest.y < 0) continue; for (i = 0; i < yarncount; i++) { if (rest.y < dh[i]) { uy = dh[i] - rest.y - 1; break; } } yi = &FYarnData.yInfor[oldi]; int type = yi->Type; if (type == 1) { colors = FYarnData.yInfor[oldi].Methods; if (rgbMel){ delete[] rgbMel; rgbMel = NULL; } rgbMel = new RGBQUAD [sizeof(RGBQUAD)*colors]; for (j = 0; j < colors; j++) { rgbMel[j] = FYarnData.yInfor[oldi].yColor[j]; RGB2HLS(rgbMel[j].rgbRed, rgbMel[j].rgbGreen, rgbMel[j].rgbBlue, h[j], l[j], s[j]); } } ux = xx % yarnMakeData.OneRepeatWidth[i+1]; SP = TP[i]->GetScanLine(uy) + 3 * x; memcpy(DP + 3 * x, SP, 3); //---------- À½¿µºÎºÐ grp = (double) Image->Height / (3 * tan(theta)); if (((i != oldi)&& (x < Image->Width))|| x == Image->Width - 1) { if (x != 0) { term = x - oldx; if (0 < term <= x) { if (type != 1){ RGB2HLS(*((DP - 3) + 3 * x), *((DP - 3) + 3 * x + 1), *((DP - 3) + 3 * x + 2), nh, nl, ns); if (nl > 0) diff = (nl*100)/(term*1.5); else diff = 0; if (nl*100/8 > 15) a = nl*100 - (nl*100/8); else a = nl*100 - 15; if (a <= 0) a = 0; } int count = 0; for (k = x; x - k < term; k-- ) { j = 0; if (x - k >= 0) { if (type != 1){ // type : 0, 2 HLS2RGB(nh, a/100, ns, *((DP - 3) + 3 * k), *((DP - 3) + 3 * k + 1), *((DP - 3) + 3 * k + 2)); a += diff; if ( a >= nl*100 ) a = nl*100; if ( a < nl*100 - 15 ) a = nl*100 - 15; if (x - k == term*4/7){ diff = -diff; } } else { // type : 1 - melange nb = *((DP - 3) + 3 * k); ng = *((DP - 3) + 3 * k + 1); nr = *((DP - 3) + 3 * k + 2); for (j = 0; j < colors; j++) { if ((nr == rgbMel[j].rgbRed) && (ng == rgbMel[j].rgbGreen) && (nb == rgbMel[j].rgbBlue)) { break; } } if (j >= colors) j = colors - 1; nh = h[j]; nl = l[j]; ns = s[j]; if (nl > 0) diff = (nl*100)/(term*1.5); else diff = 0; if (x - k >= term/2){ if (x - k == term/2) count = -term*4/7; diff = -diff; } if (nl*100/8 > 15) a = nl*100 - (nl*100/8); else a = nl*100 - 15; a = a + diff * count; if ( a >= nl*100 ) a = nl*100; if ( a < nl*100 - 15) a = nl*100 - 15; HLS2RGB(nh, a/100, ns, *((DP - 3) + 3 * k + 2), *((DP - 3) + 3 * k + 1), *((DP - 3) + 3 * k)); count++; } //-----¿©±â¿¡ Ä¿ºê if ( y == 0 || y == Image->Height - 1 ) { if ((x - k) < (grp / 2)) { *((DP - 3) + 3 * k) = 0xFF; *((DP - 3) + 3 * k + 1) = 0xFF; *((DP - 3) + 3 * k + 2) = 0xFF; } else if ( term - (x - k) <= grp - (grp / 2)) { *((DP - 3) + 3 * k) = 0xFF; *((DP - 3) + 3 * k + 1) = 0xFF; *((DP - 3) + 3 * k + 2) = 0xFF; } } //------ } } oldx = x; } } } oldi = i; //--------------- } } Image->PutScanLineN(y, 1); } } else { //-------------------------- S dx = (double) Image->Height * st + 0.5; for (y = 0; y < Image->Height; y++) { oldx = 0; DP = Image->GetScanLineN(y, 1); for (x = 0; x < Image->Width; x++) { xx = x * ct - y * st + dx; yy = x * st + y * ct; if (xx >= 0 && yy >= 0) { rest.y = yy % pileh; for (i = 0; i < yarncount; i++) { if (rest.y < dh[i]) { if (i == 0) uy = rest.y; else uy = rest.y - dh[i-1]; break; } } yi = &FYarnData.yInfor[oldi]; int type = yi->Type; if (type == 1) { colors = FYarnData.yInfor[oldi].Methods; if (rgbMel){ delete[] rgbMel; rgbMel = NULL; } rgbMel = new RGBQUAD [sizeof(RGBQUAD)*colors]; for (j = 0; j < colors; j++) { rgbMel[j] = FYarnData.yInfor[oldi].yColor[j]; RGB2HLS(rgbMel[j].rgbRed, rgbMel[j].rgbGreen, rgbMel[j].rgbBlue, h[j], l[j], s[j]); } } ux = xx % yarnMakeData.OneRepeatWidth[i+1]; SP = TP[i]->GetScanLine(uy) + 3 * x; memcpy (DP + 3 * x, SP, 3); //------------- grp = (double) Image->Height / (3 * tan(theta)); if ((( i != oldi ) && (x < Image->Width)) || x == Image->Width - 1) { if (x != 0) { term = x - oldx; if (0 < term <= x) { if ( type != 1 ) { RGB2HLS(*((DP - 3) + 3 * x + 2), *((DP - 3) + 3 * x + 1), *((DP - 3) + 3 * x), nh, nl, ns); if (nl > 0) diff = (nl*100)/(term*1.5); else diff = 0; if (nl*100/8 > 15) a = nl*100 - (nl*100/8); else a = nl*100 - 15; if (a <= 0) a = 0; } int count = 1; for (k = x; x - k < term; k-- ) // À½¿µºÎºÐ { if (x - k >= 0) { if ( type != 1 ) // type : 0, 2 { HLS2RGB(nh, a/100, ns, *((DP - 3) + 3 * k + 2), *((DP-3) + 3 * k + 1), *((DP - 3) + 3 * k)); a += diff; if ( a >= nl*100 ) a = nl*100; if ( a < nl*100 - 15) a = nl*100 - 15; if (x - k == term*4/7){ diff = -diff; } } else { // type : 1 - melange nb = *((DP - 3) + 3 * k); ng = *((DP - 3) + 3 * k + 1); nr = *((DP - 3) + 3 * k + 2); for (j = 0; j < colors; j++) { if ((nr == rgbMel[j].rgbRed) && (ng == rgbMel[j].rgbGreen) && (nb == rgbMel[j].rgbBlue)) { break; } } if (j >= colors) j = colors - 1; nh = h[j]; nl = l[j]; ns = s[j]; if (nl > 0) diff = (nl*100)/(term*1.5); else diff = 0; if (x - k >= term/2){ if (x - k == term/2) count = -term*4/7; diff = -diff; } if (nl*100/8 > 15) a = nl*100 - (nl*100/8); else a = nl*100 - 15; a = a + diff * count; if ( a >= nl*100 ) a = nl*100; if ( a < nl*100 - 15) a = nl*100 - 15; HLS2RGB(nh, a/100, ns, *((DP - 3) + 3 * k + 2), *((DP - 3) + 3 * k + 1), *((DP - 3) + 3 * k)); count++; } //-----¿©±â¿¡ Ä¿ºê if ( y == 0 || y == Image->Height - 1 ) { if ((x - k) < (grp / 2)) { *((DP - 3) + 3 * k) = 0xFF; *((DP - 3) + 3 * k + 1) = 0xFF; *((DP - 3) + 3 * k + 2) = 0xFF; } else if ( term - (x - k) <= grp - (grp / 2)) { *((DP - 3) + 3 * k) = 0xFF; *((DP - 3) + 3 * k + 1) = 0xFF; *((DP - 3) + 3 * k + 2) = 0xFF; } } //------ } } oldx = x; } } } oldi = i; //--------------- } } Image->PutScanLineN(y, 1); } } ytox = 1 / tan(theta); if (rgbMel) { delete[] rgbMel; rgbMel = NULL; } } Image->StopScanLine(); for (i = 0; i < yarncount; i++) TP[i]->StopScanLine(); } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::TempImage(TTexpiaBitmap *YarnImage, TTexpiaBitmap *Image) { int x, y, sx, sy, ex, ey, mm, k, pos; bool fb = false, pb = false; Byte *SP, *DP; sx = 0; sy = (HEIGHT - Image->Height) / 2; ex = Image->Width; ey = sy + Image->Height; Image->StartScanLine(); YarnImage->StartScanLine(); for (y = sy; y < ey; y++) { DP = YarnImage->GetScanLine(y); SP = Image->GetScanLine(y - sy); for (x = sx; x < ex; x++, DP += 3, SP += 3) { memcpy(DP, SP, 3); } YarnImage->PutScanLine(y); } Image->StopScanLine(); YarnImage->StopScanLine(); PartImage->ResizeLayer(YarnImage->Width, HEIGHT, clWhite); PartImage->Canvas->Brush->Color = clWhite; PartImage->Canvas->FillRect(Rect(0, 0, PartImage->Width, PartImage->Height)); FancyMask->FillRect(Rect(0, 0, YarnImage->Width, HEIGHT), clWhite); BeforeMask->Create(FancyMask->Width, FancyMask->Height, 1); BeforeMask->FillRect(Rect(0, 0, FancyMask->Width, FancyMask->Height), clWhite); return; fail: if (fb) FullImage->Bitmap->Destroy(); if (pb) PartImage->Bitmap->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::HairAxis(int &col, int &row, Byte &q) { char h_dir; short axis; h_dir = (((q+4)%8) + 2) % 8; while (1) { // axis = rand() % 100; /* if (axis<35) q = rand() % 3 + 2;//2 + 2; else if (axis<70) q = rand() % 3 + 5;//2 + 5; // else if (axis<85) q = 4; else q = rand() % 8; */ q = rand() % 8; if (q==h_dir || q==(h_dir+1)%8 || q==(h_dir+2)%8 || q==(h_dir+3)%8 || q==(h_dir+4)%8) { break; } } if (q==0) { col = 0; row = -1; } else if (q==1) { col = 1; row = -1; } else if (q==2) { col = 1; row = 0; } else if (q==3) { col = 1; row = 1; } else if (q==4) { col = 0; row = 1; } else if (q==5) { col = -1; row = 1; } else if (q==6) { col = -1; row = 0; } else if (q==7) { col = -1; row = -1; } if (FYarnData.SZ) col *= -1; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::DrawHair(TTexpiaBitmap *YarnImage) { Byte q, ch = 1; int i, j, k, tabx, taby, lng, col, row; double h, l, s, nh, nl, ns; int y, dx, dy, density, length, oldy = 0; Byte *DP, r, g, b; density = seHairDensity->Value; length = seHairLength->Value; if (density == 0 || length == 0) return; tabx = 100.0 / density * (rand()%5); taby = 2 * density / yarnMakeData.OneRepeatHeight[0]; YarnImage->StartScanLine(); for (i = 0; i < taby; i++) { do { if ( i < taby/3 ) y = ((HEIGHT - yarnMakeData.OneRepeatHeight[0]) / 2) + (rand()%3); else if (( taby/3 <= i ) && (i <= taby*2/3 )) y = ((HEIGHT - yarnMakeData.OneRepeatHeight[0]) / 2) + (rand()%4 + 3); else y = ((HEIGHT - yarnMakeData.OneRepeatHeight[0]) / 2) + (rand()%3 + 7); } while( oldy == y ); for (j = 0; j < YarnImage->Width; j += tabx) { dx = j; DP = YarnImage->GetScanLine(y) + 3 * j; if (RGB(*DP, *(DP + 1), *(DP + 2)) == clWhite){ if ( y < HEIGHT/2){ dy = y + 1; } else { dy = y - 1; } } else dy = y ; oldy = y; DP = YarnImage->GetScanLine(dy) + 3 * j; r = *DP; g = *(DP + 1); b = *(DP + 2); RGB2HLS(r,g,b, h, l, s); //------ /* double fh, fl, fs; for (int i = 0; i < FYarnData.TYC; i++){ for (int j = 0; j < FYarnData.yInfor[i].Colors; j++){ RGB2HLS(FYarnData.yInfor[i].yColor[j].rgbRed, FYarnData.yInfor[i].yColor[j].rgbGreen, FYarnData.yInfor[i].yColor[j].rgbBlue, fh, fl, fs); if (IsRange(25, fh, h) && IsRange(2, fs*100 , s*100)){ if (l < fl - 0.01) l = fl - 0.01; h = fh; s = fs; } } // ¿ø·¡ »öÀÇ ÀÏÁ¤ÇÑ ¹üÀ§¾È¿¡¼­ hairÀÇ »öÀÌ ³ªÅ¸³ª°Ô ÇÏ·Á°íÇßÁö¸¸ } */ // ¹Ù²ï hls°ª¿¡¼­ÀÇ rgb¿Í ¿ø·¡ rgb»öÀÌ Â÷À̰¡ Ä¿¼­ Á¦´ë·Î ³ªÅ¸³ªÁö¾ÊÀ½ //---- nh = h; nl = l - 0.003; if (nl >= 1) nl = 1; if (nl <= 0.2) nl = 0.2; ns = s; YarnImage->PutScanLine(dy); lng = ((double)((HEIGHT - yarnMakeData.OneRepeatHeight[0]) / 2.0) * length/100) / (rand()%3+1) + 1; q = 4; col = 0; row = 1; for (k = 0; k < lng; k++) { if ( y < HEIGHT / 2){ dx += col; dy -= row; } else { dx -= col; dy += row; } if (nl < 1 ) { // if ( lng >= 10) nl -= (l/10)/(lng - 1); // hair »ö ÀÏÁ¤ÇÏ°Ô ÇØµÒ // else nl -= 0.005; // ÀÏÁ¤ÇÏÁö¾ÊÀ¸¸é hair°¡ ¸¹¾ÆÁú ¼ö·Ï »öÂ÷ÀÌ } if ( nl >= 1 ) nl = 1; if ( nl >= l) nl = l; if ( nl <= l - 0.08) nl = l - 0.08; if ( nl <= 0) nl = 0; HLS2RGB(nh, nl, ns, r, g, b); if (dx >= 0 && dx < YarnImage->Width && dy >= 0 && dy < YarnImage->Height) { DP = YarnImage->GetScanLine(dy) + 3 * dx; *DP = r; *(DP + 1) = g; *(DP + 2) = b; YarnImage->PutScanLine(dy); } if (ch == 0) HairAxis(col, row, q); ch++ ; if (ch > 1) ch = 0; } tabx = 100.0 / density * (rand()%5 + 1) * 2; } } YarnImage->StopScanLine(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::DrawYarnImage(TTexpiaBitmap *YarnImage) { Byte *DP, *SP; bool fb = false, pb = false; int y; if (YarnImage->Width > WIDTH) { fb = FullImage->Bitmap->Create(YarnImage->Width, HEIGHT, 24); if (fb == false) goto fail; ScrollBar->Enabled = true; ScrollBar->Max = max(0, YarnImage->Width / propt - WIDTH); } else { ScrollBar->Position = 0; ScrollBar->Enabled = false; } YarnBitmap->Create(YarnImage->Width, HEIGHT, 24); YarnBitmap->Copy(YarnImage, SRCCOPY); return; fail: if (fb) FullImage->Bitmap->Destroy(); if (pb) PartImage->Bitmap->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- // FullView Rectangle void __fastcall TYarnDesignForm::WADraw() { HDC hDC = NULL; HBRUSH hOldBrush; HPEN hOldPen; int nDrawMode, recwid; if (FYarnData.Dyed) recwid = 100; else recwid = 50; hDC = FullImage->Bitmap->CreateDC(); if (hDC == NULL) goto fail; hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); hOldPen = SelectObject(hDC, GetStockObject(WHITE_PEN)); nDrawMode = GetROP2(hDC); SetROP2(hDC, R2_XORPEN); Rectangle(hDC, startx, 0, startx + recwid, 80); // 80 : FormÀÇ FullImage size SetROP2(hDC, nDrawMode); SelectObject(hDC, hOldBrush); SelectObject(hDC, hOldPen); FullImage->Bitmap->DeleteDC(hDC); return; fail: FullImage->Bitmap->DeleteDC(hDC); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::RectangleMove(int X) { int recwid; if (FYarnData.Dyed) recwid = 100; else recwid = 50; if (IsDraw) WADraw(); startx = X + FullImage->PositionX - recwid/2; if (startx < 0) startx = 0; if (startx > yarnMakeData.ImageWidth / propt + 0.5 - recwid) startx = yarnMakeData.ImageWidth / propt + 0.5 - recwid; WADraw(); IsDraw = true; if (FYarnData.Dyed) PartImage->PositionX = startx; else PartImage->PositionX = (int)(startx * propt); RulerZoom->Start = startx; FullImage->Repaint(); PartImage->Repaint(); MaintainWorkArea(); } //--------------------------------------------------------------------------- // Repeat Image void __fastcall TYarnDesignForm::IndicateRectangle(int X, bool erase) { RepeatImage->Canvas->Brush->Color = clWhite; RepeatImage->Canvas->FillRect(Rect(0, 0, RepeatImage->Width, RepeatImage->Height)); if (!erase) { RepeatImage->Canvas->Brush->Color = clBlue; RepeatImage->Canvas->Pen->Color = clYellow; RepeatImage->Canvas->Rectangle(min(isx, X) - ScrollBar->Position + fpos, 0, max(isx, X), RepeatImage->Height); } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::RepeatYarnImage(TTexpiaBitmap *Temp, TTexpiaBitmap *TempM) { Byte *TP, *DP, *DMP, *UD, *TMP; int x, y, dx; TTexpiaBitmap *Tb = YarnUndo->Last->Bitmap; if (FancyBitmap->StartScanLineN(2) == false) goto fail; if (FancyMask->StartScanLine() == false) goto fail; if (cbSuper->Checked) { int sy = (HEIGHT - FYarnData.Thick) / 2; int ey = sy + FYarnData.Thick - 1; if (Tb->StartScanLine() == false) goto fail; if (Temp->StartScanLine() == false) goto fail; if (TempM->StartScanLine() == false) goto fail; for (y = 0; y < HEIGHT; y++) { DP = FancyBitmap->GetScanLineN(y, 1); DMP = FancyMask->GetScanLine(y); TP = Temp->GetScanLine(y); TMP = TempM->GetScanLine(y); if (y < sy || y > ey) { UD = Tb->GetScanLine(y); for (x = 0, dx = 0; x < yarnMakeData.ImageWidth; x++, dx++, DP += 3, UD += 3) { if (dx >= Temp->Width) dx = 0; *DP = *(TP + 3 * dx); *(DP + 1) = *(TP + 3 * dx + 1); *(DP + 2) = *(TP + 3 * dx + 2); if (TMP[dx/8] & (0x80 >> (dx%8))) { DMP[x/8] |= (0x80 >> (x%8)); } else { DMP[x/8] &= ~(0x80 >> (x%8)); } if ((*UD != 255) && (*(UD + 1)!= 255) && (*(UD + 2) != 255)) { *DP = *UD; *(DP + 1) = *(UD + 1); *(DP + 2) = *(UD + 2); DMP[x/8] &= ~(0x80 >> (x%8)); } } } else { for (x = 0, dx = 0; x < yarnMakeData.ImageWidth; x++, dx++ , DP += 3) { if (dx >= Temp->Width) dx = 0; *DP = *(TP + 3 * dx); *(DP + 1) = *(TP + 3 * dx + 1); *(DP + 2) = *(TP + 3 * dx + 2); if (TMP[dx/8] & (0x80 >> (dx%8))) { DMP[x/8] |= (0x80 >> (x%8)); } else { DMP[x/8] &= ~(0x80 >> (x%8)); } } } FancyBitmap->PutScanLineN(y , 1); FancyMask->PutScanLine(y); } Tb->StopScanLine(); FancyBitmap->StopScanLine(); FancyMask->StopScanLine(); } else { if (Temp->StartScanLine() == false) goto fail; if (TempM->StartScanLine() == false) goto fail; for (y = 0; y < HEIGHT; y++) { DP = FancyBitmap->GetScanLineN(y, 1); DMP = FancyMask->GetScanLine(y); TP = Temp->GetScanLine(y); TMP = TempM->GetScanLine(y); for (x = 0, dx = 0; x < yarnMakeData.ImageWidth; x++, dx++ , DP += 3) { if (dx >= Temp->Width) dx = 0; *DP = *(TP + 3 * dx); *(DP + 1) = *(TP + 3 * dx + 1); *(DP + 2) = *(TP + 3 * dx + 2); if (TMP[dx/8] & (0x80 >> (dx%8))) { DMP[x/8] |= (0x80 >> (x%8)); } else { DMP[x/8] &= ~(0x80 >> (x%8)); } } FancyBitmap->PutScanLineN(y , 1); FancyMask->PutScanLine(y); } } FancyBitmap->StopScanLine(); FancyMask->StopScanLine(); if (FYarnData.VerNo >= 400 && !FYarnData.Dyed && !cbFancy->Checked) // ½ÇÀÚü¸¦ º¯°æÇÒ °æ¿ì { HDC dcYarn, dcFancy, dcTemp; dcFancy = FancyBitmap->CreateDC(); dcYarn = YarnBitmap->CreateDC(); BitBlt(dcYarn, 0, 0, yarnMakeData.ImageWidth, HEIGHT, dcFancy, 0, 0, SRCCOPY); YarnBitmap->DeleteDC(dcYarn); FancyBitmap->DeleteDC(dcFancy); FancyBitmap->FillRect(Rect(0, 0, yarnMakeData.ImageWidth, HEIGHT), clWhite); FancyMask->FillRect(Rect(0, 0, yarnMakeData.ImageWidth, HEIGHT), clWhite); } ImageRepaint(true); return; fail: Tb->StopScanLine(); FancyBitmap->StopScanLine(); FancyMask->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- // Draw Image void __fastcall TYarnDesignForm::DrawDot(int X, int Y) { Byte *DP, *DMP, r, g, b; WORD *WDP; int sx, ex, sy, ey, i, j; double h, l, s, nl; RGBQUAD rgb; if (cbFancy->Checked || FYarnData.Dyed) { sx = X - ls; if (sx < 0) sx = 0; ex = X + rs; if (ex > FancyBitmap->Width) ex = FancyBitmap->Width; sy = Y - ls; if (sy < 0) sy = 0; ey = Y + rs; if (ey > FancyBitmap->Height) ey = FancyBitmap->Height; start.x = sx; start.y = sy; end.x = ex; end.y = ey; b = pencolor & 0xFF; g = (pencolor >> 8) & 0xFF; r = (pencolor >> 16) & 0xFF; FancyBitmap->StartScanLine(); FancyMask->StartScanLine(); for (i = sy; i < ey; i++) { DP = (Byte *)FancyBitmap->GetScanLine(i); DMP = (Byte *)FancyMask->GetScanLine(i); for (j = sx * 3; j < ex * 3; j += 3) { if (FYarnData.Dyed) { if (pencolor == clWhite){ r = 255; g = 255; b = 255; } else { int i = 0 , mapping[9]; mapping[0] = 0; mapping[1] = 1; mapping[2] = 2; mapping[3] = 5; mapping[4] = 8; mapping[5] = 7; mapping[6] = 6; mapping[7] = 3; mapping[8] = 4; TColor2RGB(TColor(nearc[mapping[((i++) + rand()%2)%9 ]]), r, g, b); i++; if (i == 9) i = 0; } *(DP + j + 2) = r; *(DP + j + 1) = g; *(DP + j) = b; } else { *(DP + j + 2) = r; *(DP + j + 1) = g; *(DP + j) = b; } if (r == 255 && g == 255 && b == 255) { DMP[j/24] |= (0x80 >> ((j/3)%8)); } else { DMP[j/24] &= ~(0x80 >> ((j/3)%8)); } } FancyBitmap->PutScanLine(i); FancyMask->PutScanLine(i); } FancyMask->StopScanLine(); FancyBitmap->StopScanLine(); } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::DrawLine(int X, int Y){ // by JangJinMan int start_x, start_y, dx, dy, dx2, dy2, x_inc, y_inc, error, i; if (Down){ if (BeforeX == -1) return; start_x = BeforeX; start_y = BeforeY; dx = X - BeforeX; dy = Y - BeforeY; if(dx >= 0) x_inc = 1; else{ x_inc = -1; dx = -dx; } if(dy>=0) y_inc = 1; else { y_inc = -1; dy = -dy; } dx2 = dx << 1; dy2 = dy << 1; if (dx > dy){ error = dy2 - dx; for (i = 0; i <= dx; i++){ DrawDot(start_x, start_y); if (error >= 0){ error -= dx2; start_y += y_inc; } error += dy2; start_x += x_inc; } } else { error = dx2 - dy; for(i = 0; i <= dy; i++){ DrawDot(start_x, start_y); if(error >= 0){ error -= dy2; start_x += x_inc; } error += dx2; start_y += y_inc; } } BeforeX = X; BeforeY = Y; } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::UndoMask(bool undo) // true -> undo, false -> save { HDC dcMask, dcBeforeMask, dcTemp; dcMask = FancyMask->CreateDC(); dcBeforeMask = BeforeMask->CreateDC(); if (dcMask == NULL) goto fail; if (dcBeforeMask == NULL) goto fail; if (undo) { TMask = new TTexpiaBitmap; TMask->Create(FancyMask->Width, FancyMask->Height, 1); TMask->FillRect(Rect(0, 0, FancyMask->Width, FancyMask->Height), clWhite); dcTemp = TMask->CreateDC(); if (dcTemp == NULL) goto fail; BitBlt(dcTemp, 0, 0, FancyMask->Width, FancyMask->Height, dcMask, 0, 0, SRCCOPY); BitBlt(dcMask, 0, 0, FancyMask->Width, FancyMask->Height, dcBeforeMask, 0, 0, SRCCOPY); BitBlt(dcBeforeMask, 0, 0, FancyMask->Width, FancyMask->Height, dcTemp, 0, 0, SRCCOPY); TMask->DeleteDC(dcTemp); delete TMask; } else BitBlt(dcBeforeMask, 0, 0, FancyMask->Width, FancyMask->Height, dcMask, 0, 0, SRCCOPY); FancyMask->DeleteDC(dcMask); BeforeMask->DeleteDC(dcBeforeMask); return; fail: FancyMask->DeleteDC(dcMask); BeforeMask->DeleteDC(dcBeforeMask); if (TMask) TMask->DeleteDC(dcTemp); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::ImageRepaint(bool zeropos) { HBITMAP bmMemL; HDC dcFull, dcYarn, dcFancy, dcMask, dcMemL; int hFull; dcFull = FullImage->Bitmap->CreateDC(); dcYarn = YarnBitmap->CreateDC(); dcFancy = FancyBitmap->CreateDC(); dcMask = FancyMask->CreateDC(); if (dcFull == NULL) goto fail; if (dcYarn == NULL) goto fail; hFull = (HEIGHT - (HEIGHT / propt)) / 2 - (HEIGHT - 80)/2; // 80 : formÀÇ FullImage size if (yarnMakeData.ImageWidth / propt < WIDTH) FullImage->Bitmap->FillRect(Rect(0, 0, WIDTH, HEIGHT), clWhite); else FullImage->Bitmap->FillRect(Rect(0, 0, yarnMakeData.ImageWidth, HEIGHT), clWhite); if (ExactDot < 2) SetStretchBltMode(dcFull, HALFTONE); else SetStretchBltMode(dcFull, COLORONCOLOR); if ((bmMemL = CreateCompatibleBitmap(dcFull, FullImage->Bitmap->Width, FullImage->Bitmap->Height)) == NULL) goto fail; if ((dcMemL = CreateCompatibleDC(dcFull)) == NULL) goto fail; SelectObject(dcMemL, bmMemL); StretchBlt(dcFull, 0, hFull, yarnMakeData.ImageWidth / propt, HEIGHT / propt, dcYarn, 0, 0, yarnMakeData.ImageWidth, HEIGHT, SRCCOPY); StretchBlt(dcFull, 0, hFull, yarnMakeData.ImageWidth / propt, HEIGHT / propt, dcMask, 0, 0, yarnMakeData.ImageWidth, HEIGHT, SRCAND); StretchBlt(dcMemL, 0, hFull, yarnMakeData.ImageWidth / propt, HEIGHT / propt, dcMask, 0, 0, yarnMakeData.ImageWidth, HEIGHT, NOTSRCCOPY); StretchBlt(dcMemL, 0, hFull, yarnMakeData.ImageWidth / propt, HEIGHT / propt, dcFancy, 0, 0, yarnMakeData.ImageWidth, HEIGHT, SRCAND); BitBlt(dcFull, 0, hFull, yarnMakeData.ImageWidth / propt, HEIGHT / propt, dcMemL, 0, hFull, SRCPAINT); if (zeropos) { FullImage->PositionX = 0; PartImage->PositionX = 0; if (ScrollBar->Enabled) ScrollBar->Position = 0; startx = 0; } RulerZoom->Zoom = 16; //propt * zvalue; FullImage->Bitmap->DeleteDC(dcFull); YarnBitmap->DeleteDC(dcYarn); FancyBitmap->DeleteDC(dcFancy); FancyMask->DeleteDC(dcMask); DeleteDC(dcMemL); DeleteObject(bmMemL); WADraw(); IsDraw = true; FullImage->Repaint(); PartImage->Repaint(); if (use_ImageRepaint_bitmapcopy) ImageRepaint_bitmapcopy();//gabriel return; fail: FullImage->Bitmap->DeleteDC(dcFull); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::ImageRepaint_bitmapcopy() { int temp_propt = propt;//gabriel: temporary var propt = 1;//gabriel: set 1 original_yarn_image if (original_yarn_image) delete original_yarn_image; original_yarn_image = new TTexpiaBitmap; original_yarn_image->Create(yarnMakeData.ImageWidth, HEIGHT, 24); HBITMAP bmMemL; HDC dcFull, dcYarn, dcFancy, dcMask, dcMemL; int hFull; dcFull = original_yarn_image->CreateDC(); dcYarn = YarnBitmap->CreateDC(); dcFancy = FancyBitmap->CreateDC(); dcMask = FancyMask->CreateDC(); if (dcFull == NULL) goto fail; if (dcYarn == NULL) goto fail; hFull = (HEIGHT - (HEIGHT / propt)) / 2 - (HEIGHT - 80)/2; // 80 : formÀÇ FullImage size if (yarnMakeData.ImageWidth / propt < WIDTH) original_yarn_image->FillRect(Rect(0, 0, WIDTH, HEIGHT), clWhite); else original_yarn_image->FillRect(Rect(0, 0, yarnMakeData.ImageWidth, HEIGHT), clWhite); if (ExactDot < 2) SetStretchBltMode(dcFull, HALFTONE); else SetStretchBltMode(dcFull, COLORONCOLOR); if ((bmMemL = CreateCompatibleBitmap(dcFull, original_yarn_image->Width, original_yarn_image->Height)) == NULL) goto fail; if ((dcMemL = CreateCompatibleDC(dcFull)) == NULL) goto fail; SelectObject(dcMemL, bmMemL); StretchBlt(dcFull, 0, hFull, yarnMakeData.ImageWidth / propt, HEIGHT / propt, dcYarn, 0, 0, yarnMakeData.ImageWidth, HEIGHT, SRCCOPY); StretchBlt(dcFull, 0, hFull, yarnMakeData.ImageWidth / propt, HEIGHT / propt, dcMask, 0, 0, yarnMakeData.ImageWidth, HEIGHT, SRCAND); StretchBlt(dcMemL, 0, hFull, yarnMakeData.ImageWidth / propt, HEIGHT / propt, dcMask, 0, 0, yarnMakeData.ImageWidth, HEIGHT, NOTSRCCOPY); StretchBlt(dcMemL, 0, hFull, yarnMakeData.ImageWidth / propt, HEIGHT / propt, dcFancy, 0, 0, yarnMakeData.ImageWidth, HEIGHT, SRCAND); BitBlt(dcFull, 0, hFull, yarnMakeData.ImageWidth / propt, HEIGHT / propt, dcMemL, 0, hFull, SRCPAINT); original_yarn_image->DeleteDC(dcFull); YarnBitmap->DeleteDC(dcYarn); FancyBitmap->DeleteDC(dcFancy); FancyMask->DeleteDC(dcMask); DeleteDC(dcMemL); DeleteObject(bmMemL); WADraw(); IsDraw = true; propt = temp_propt;//gabriel: restore return; fail: propt = temp_propt;//gabriel: restore original_yarn_image->DeleteDC(dcFull); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- // File Method void __fastcall TYarnDesignForm::InitFile() { //FilePanel->Visible = true; YarnTableForm->Panel1->Height = 70; YarnTableForm->sbRead->Down = true; YarnTableForm->sbSave->Enabled = bmake; YarnTableForm->sbSaveAs->Enabled = bmake; YarnTableForm->Visible = true; YarnTableForm->BringToFront(); FItem = 0; // sbRead->Down = true; // sbSave->Enabled = bmake; // sbSaveAs->Enabled = bmake; if(WorkArea->Mask) WorkArea->ResetRegion(PartImage); ImageRepaint(); StatusItem(0); sbWinClick(this); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::ExitFile() { //FilePanel->Visible = false; YarnTableForm->Visible = false; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::YarnDataChange(AnsiString fn) { /* switch (FItem) { case 0: FileRead(fn); ExitFile(); break; case 1: FileSave(fn); break; case 2: FileDelete(fn); break; case 3: FileRename(fn); break; } */ if (YarnTableForm->sbRead->Down) FItem = 0; else if (YarnTableForm->sbSave->Down) FItem = 1; else if (YarnTableForm->sbSaveAs->Down) FItem = 2; else if (YarnTableForm->sbRename->Down) FItem = 3; else if (YarnTableForm->sbDelete->Down) FItem = 4; switch (FItem) { case 0: FileRead(fn); ExitFile(); break; case 1: FileSave(fn); break; case 2: FileSaveAs(fn); break; case 3: FileRename(fn); break; case 4: FileDelete(fn); break; } FItem = 0; YarnTableForm->sbRead->Down = true; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::DeleteFolder(AnsiString FolderName) { SHFILEOPSTRUCT shfile; char *ucFrom = NULL; if (YarnTableForm->sbDelFolder->Down) FItem = 5; if (FItem == 5) { memset(&shfile, 0, sizeof(SHFILEOPSTRUCT)); shfile.hwnd = Handle; shfile.wFunc = FO_DELETE; ucFrom = new char [FolderName.Length()+2]; if (ucFrom) { strcpy(ucFrom, FolderName.c_str()); shfile.pFrom = ucFrom; shfile.pTo = NULL; shfile.fFlags = FOF_ALLOWUNDO ; SHFileOperation(&shfile); delete[] ucFrom; } YarnTableForm->DirectoryListBox->Update(); } FItem = 0; YarnTableForm->sbRead->Down = true; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::FileRead(AnsiString fn) { TPException ec = EC_NONE; if (!FileExists(fn)) { ec = EC_FILE_NOT_EXIST; goto fail; } fload = true; if (FYarnData.yInfor) { delete[] FYarnData.yInfor; FYarnData.yInfor = NULL; } if (FYarnData.FancyMap) { delete[] FYarnData.FancyMap; FYarnData.FancyMap = NULL; } //ClearColorGrid(); if ((ec = FYarnData.LoadFromFile(fn)) != EC_NONE) goto fail; FYarnUnit = FYarnData.Unit; YarnVerNo = FYarnData.VerNo; if (FLengthUnit == uCm) seLength->Value = 2.54 * FYarnData.Length / yDPI; else seLength->Value = (float)FYarnData.Length / yDPI; // ÆÒ½Ã, ½ºÄµ»ç ºÒ·¯¿Ã¶§ ¼Ò¼öÁ¡¾È³ª¿À´Â°Í floatÀ¸·Î if (FYarnData.Hden) seHairDensity->Value = FYarnData.Hden; else FYarnData.Hden = 20; if (FYarnData.Hlen) seHairLength->Value = FYarnData.Hlen; else FYarnData.Hlen = 50; yarnMakeData.ImageWidth = FYarnData.Length; yarncount = FYarnData.TYC; seYarnNumber->Value = yarncount; if (!FYarnData.Dyed){ if (yarncount > 1) { for (int i = 0; i < yarncount; i++) { FEditingYarnInfor[i]->Copy(&FYarnData.yInfor[i]); } } else FEditingYarnInfor[0]->Copy(&FYarnData.yInfor[0]); } bchange = true; seCount->Value = FYarnData.Count; bchange = false; SZ = FYarnData.SZ; stTwist->Caption = (SZ) ? "Z Direction" : "S Direction"; if (FYarnData.IsTPIMethod()) { isTPI = true; lbTPI->Caption = "TPI"; seTPI->Value = FYarnData.TPI; } else { isTPI = false; lbTPI->Caption = "TPM"; seTPI->Value = FYarnData.TPM; } cbHair->Checked = FYarnData.Hair; sbRepeat->Enabled = false; bpp = 24; if (FYarnData.Dyed) { MakeButton->Visible = false; sbDyedYarn->Enabled = true; sbDyedYarn->Down = true; RulerZoom->Zoom = 8; InitImage(true); DrawScanData(); bmake = true; InitFile(); } else { MakeButton->Visible = true; sbDyedYarn->Enabled = false; sbDyedYarn->Down = false; RulerZoom->Zoom = 16; InitImage(false); CalculateCount(); if (sameunit) cbSameUnit->Checked = true; else cbSameUnit->Checked = false; CalculateWidthHeight(); Simulation(); if (zvalue >= 5) sbGrid->Enabled = true; } cbFancy->Checked = FYarnData.Fancy; sbErase->Down = false; delete[] FYarnData.Map; FYarnData.Map = NULL; FYarnData.Width = HEIGHT; Review(); fload = false; return; fail: if (ec == EC_NONE) ec = EC_FILE_NOT_READ; EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::FileSaveAs(AnsiString fn) { fn = "Noname.yan"; if (InputQuery(IDS_COMMON_SAVEAS, IDS_COMMON_INPUTNAME+" ", fn)) {//ÇÑ±Û À߸®´Â ¹®Á¦¶§¹®¿¡ °ø¶õ Ãß°¡ fn = FileNameExt(fn); if (!FileExists(fn)) { YarnSave(fn); } else { //EXCEPTION_MESSAGE_OK(EC_FILE_EXIST_ALREADY); MessageDlg(IDS_MESSAGE_FILEEXIST, mtWarning, TMsgDlgButtons()<SetZoom(8 , 1); PartImage->Height = YarnBitmap->Height * 8; PartImage->PositionY = 0; PartImage->Top = PanelPart->Height / 2 - PartImage->Height / 2; PartImage->Left = 0; if (FYarnData.Width > HEIGHT) { dsy = 0; dey = HEIGHT; ssy = (FYarnData.Width - HEIGHT) / 2; } else { dsy = (HEIGHT - FYarnData.Width) / 2; dey = dsy + FYarnData.Width; ssy = 0; } if (FYarnData.Length > WIDTH) { fb = FullImage->Bitmap->Create(FYarnData.Length, HEIGHT, 24); if (fb == false) goto fail; } pb = PartImage->Bitmap->Create(zvalue*FYarnData.Length, P_HEIGHT, 24); PartImage->Bitmap->FillRect(Rect(0, 0, zvalue*FYarnData.Length, P_HEIGHT), clWhite); if (pb == false) goto fail; YarnBitmap->Create(FYarnData.ImageLength, HEIGHT, 24); YarnBitmap->FillRect(Rect(0, 0, YarnBitmap->Width, HEIGHT), clWhite); FancyBitmap->Create(YarnBitmap->Width, HEIGHT, 24); FancyBitmap->FillRect(Rect(0, 0, YarnBitmap->Width, HEIGHT), clWhite); FancyMask->Create(YarnBitmap->Width, HEIGHT, 1); FancyMask->FillRect(Rect(0, 0, YarnBitmap->Width, HEIGHT), clWhite); PartImage->Canvas->Brush->Color = clWhite; PartImage->Canvas->FillRect(Rect(0, 0, PartImage->Width, PartImage->Height)); FancyMask->FillRect(Rect(0, 0, YarnBitmap->Width, HEIGHT), clWhite); if (FancyBitmap->StartScanLine() == false) goto fail; if (FancyMask->StartScanLine() == false) goto fail; for ( dy = dsy, sy = ssy; dy < dey; dy++, sy++) { DP = FancyBitmap->GetScanLine(dy); DMP = FancyMask->GetScanLine(dy); SP = (Byte *) FYarnData.Map + (FYarnData.Length * sy * 3); for (dx = 0; dx < FYarnData.Length; dx++, DP += 3, SP += 3){ memcpy(DP, SP, 3); if (*DP != 255 || *(DP + 1) != 255 || *(DP + 2) != 255) DMP[dx/8] &= ~(0x80 >> (dx%8)); } FancyBitmap->PutScanLine(dy); FancyMask->PutScanLine(dy); } FancyBitmap->StopScanLine(); FancyMask->StopScanLine(); ImageRepaint(); return; fail: if (fb) FullImage->Bitmap->Destroy(); if (pb) PartImage->Bitmap->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::YarnSave(AnsiString fn) { Byte *wdp, *fdp, *wsp, *mp, *dp; int x, y, imageH, cutH, sy, ey, size, fsize; HBITMAP bmMemL; HDC dcImage, dcYarn, dcFancy, dcMask, dcMemL; Image = new TTexpiaBitmap; Image->Create(yarnMakeData.ImageWidth, HEIGHT, 24); Image->FillRect(Rect(0, 0, yarnMakeData.ImageWidth, HEIGHT), clWhite); dcImage = Image->CreateDC(); dcYarn = YarnBitmap->CreateDC(); dcFancy = FancyBitmap->CreateDC(); dcMask = FancyMask->CreateDC(); if (HEIGHT < HEIGHT/propt * 5){ imageH = 0; cutH = ((HEIGHT/propt * 5 - HEIGHT)/2)/(HEIGHT/propt * 5 / HEIGHT); } else { imageH = (HEIGHT - HEIGHT/propt * 5)/2; cutH = 0; } if ((bmMemL = CreateCompatibleBitmap(dcImage, Image->Width, Image->Height)) == NULL) goto fail; if ((dcMemL = CreateCompatibleDC(dcImage)) == NULL) goto fail; SelectObject(dcMemL, bmMemL); if (!FYarnData.Dyed){ SetStretchBltMode(dcImage, COLORONCOLOR); StretchBlt(dcImage, 0, imageH, yarnMakeData.ImageWidth/propt * 5, HEIGHT/propt * 5 , dcYarn, 0, cutH, yarnMakeData.ImageWidth, HEIGHT, SRCCOPY); StretchBlt(dcImage, 0, imageH, yarnMakeData.ImageWidth/propt * 5 , HEIGHT/propt * 5 , dcMask, 0, cutH, yarnMakeData.ImageWidth, HEIGHT, SRCAND); StretchBlt(dcMemL, 0, imageH, yarnMakeData.ImageWidth/propt * 5 , HEIGHT/propt * 5 , dcMask, 0, cutH, yarnMakeData.ImageWidth, HEIGHT, NOTSRCCOPY); StretchBlt(dcMemL, 0, imageH, yarnMakeData.ImageWidth/propt * 5, HEIGHT/propt * 5 , dcFancy, 0, cutH, yarnMakeData.ImageWidth, HEIGHT, SRCAND); BitBlt(dcImage, 0, 0, yarnMakeData.ImageWidth, HEIGHT, dcMemL, 0, 0, SRCPAINT); } else { BitBlt(dcImage, 0, 0, yarnMakeData.ImageWidth, HEIGHT , dcYarn, 0, 0, SRCCOPY); BitBlt(dcImage, 0, 0, yarnMakeData.ImageWidth , HEIGHT , dcMask, 0, 0, SRCAND); BitBlt(dcMemL, 0, 0, yarnMakeData.ImageWidth , HEIGHT , dcMask, 0, 0, NOTSRCCOPY); BitBlt(dcMemL, 0, 0, yarnMakeData.ImageWidth, HEIGHT , dcFancy, 0, 0, SRCAND); BitBlt(dcImage, 0, 0, yarnMakeData.ImageWidth , HEIGHT , dcMemL, 0, 0, SRCPAINT); } if (cbHair->Checked || cbFancy->Checked) { FYarnData.Width = HEIGHT; fsize = HEIGHT * yarnMakeData.ImageWidth * 3; size = 100 * HEIGHT * 3; if (cbHair->Checked){ FYarnData.Hair = 1; FYarnData.Hden = seHairDensity->Value; FYarnData.Hlen = seHairLength->Value; } if (cbFancy->Checked){ FYarnData.Fancy = 1; } } else if (FYarnData.Dyed){ size = FYarnData.Length * HEIGHT * 3; } else { fsize = 0; size = 100 * HEIGHT * 3; FYarnData.Fancy = 0; FYarnData.Hair = 0; } FYarnData.mapsize = size; FYarnData.Map = new Byte[size]; if (FYarnData.Map == NULL) goto fail; wdp = (Byte *) FYarnData.Map; memset( wdp, 1, size); if (!FYarnData.Dyed){ if (Image->StartScanLine() == false) goto fail; for (y = 0; y < HEIGHT; y++) { wsp = Image->GetScanLine(y); for ( x = 0; x < 100; x++, wsp += 3, wdp += 3) { // if ( x < yarnMakeData.ImageWidth){ if (*wsp == 0x7FFFFF) *wdp = 0x800000; // } else { // *wdp = 0x800000; // } memcpy(wdp, wsp, 3); } } Image->StopScanLine(); } else { if (Image->StartScanLine() == false) goto fail; for (y = 0; y < HEIGHT; y++) { wsp = Image->GetScanLine(y); for ( x = 0; x < yarnMakeData.ImageWidth; x++, wsp += 3, wdp += 3) { if (*wsp == 0x7FFFFF) *wdp = 0x800000; memcpy(wdp, wsp, 3); } } Image->StopScanLine(); } FYarnData.fancymapsize = fsize; if ((FYarnData.Fancy == 1) && (!FYarnData.Dyed)) { if (FYarnData.FancyMap){ delete[] FYarnData.FancyMap; FYarnData.FancyMap = NULL; } FYarnData.FancyMap = new Byte [fsize]; if (FYarnData.FancyMap == NULL) goto fail; fdp = (Byte *) FYarnData.FancyMap; memset( fdp, 0, fsize); // memset( fdp, 0xFF, fsize); if (FancyBitmap->StartScanLine() == false) goto fail; for ( y = 0; y < HEIGHT; y++) { wsp = FancyBitmap->GetScanLine(y); for ( x = 0; x < yarnMakeData.ImageWidth; x++, wsp += 3, fdp += 3) { if ((*wsp != 255) || (*(wsp + 1) != 255) || (*(wsp + 2) != 255)){ memcpy(fdp, wsp, 3); } else *fdp = 0x800000; /* if ((*wsp != 255) || (*(wsp + 1) != 255) || (*(wsp + 2) != 255)) { if (*wsp == 0x7FFFFF) *fdp = 0x800000; memcpy(fdp, wsp, 3); } */ } } FancyBitmap->StopScanLine(); } if (FYarnData.SaveToFile(fn) != EC_NONE) goto fail; delete[] FYarnData.Map; FYarnData.Map = NULL; if (FYarnData.FancyMap){ delete[] FYarnData.FancyMap; FYarnData.FancyMap = NULL; } YarnTableForm->FileListBox->Update(); Image->DeleteDC(dcImage); YarnBitmap->DeleteDC(dcYarn); FancyBitmap->DeleteDC(dcFancy); FancyMask->DeleteDC(dcMask); DeleteDC(dcMemL); DeleteObject(bmMemL); delete Image; return; fail: Image->StopScanLine(); FancyBitmap->StopScanLine(); if (FYarnData.Map) {HeapFree(GetProcessHeap(), 0, FYarnData.Map); FYarnData.Map = NULL;} EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::FileSave(AnsiString fn) { if (FileExists(fn)) YarnSave(fn); } //--------------------------------------------------------------------------- AnsiString __fastcall TYarnDesignForm::FileNameExt(AnsiString fn) { PChar s; int FileNameLength, last1, last2, last3, last4; char FileIndex1, FileIndex2, FileIndex3, FileIndex4; //=============================================================== FileNameLength = fn.Length(); if(FileNameLength > 4){ last1 = FileNameLength-3; last2 = FileNameLength-2; last3 = FileNameLength-1; last4 = FileNameLength; FileIndex1 = '.'; FileIndex2 = 'j'; FileIndex3 = 'q'; FileIndex4 = 'd'; if((FileIndex1 == fn[last1])&&(FileIndex2 == fn[last2]) && (FileIndex3 == fn[last3])&&(FileIndex4 == fn[last4])){ s = "PASS"; }else s=NULL; }else s=NULL; //=============================================================== // char *s = AnsiStrScan(fn.c_str(), '.'); if (s==NULL) return fn + ".yan"; else return fn; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::FileDelete(AnsiString fn) { if (FileExists(fn)) { if (MessageDlg(IDS_MESSAGE_DELETEFILE+ fn, mtWarning, TMsgDlgButtons()<FileListBox->Update(); } } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::FileRename(AnsiString fn) { AnsiString s; if (FileExists(fn)) { s = fn; if (InputQuery(IDS_COMMON_RENAME, IDS_COMMON_INPUTNAME, s)) { s = FileNameExt(s); for (int i = 0; i < YarnTableForm->FileListBox->Items->Count; i++) { if (s == YarnTableForm->FileListBox->Items->Strings[i]) { //EXCEPTION_MESSAGE_OK(EC_FILE_EXIST_ALREADY); MessageDlg(IDS_MESSAGE_FILEEXIST, mtWarning, TMsgDlgButtons()<FileListBox->Update(); } } } //--------------------------------------------------------------------------- /////// Public Method ///////////////////////////////////////////////////// //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::OnUnitChange() {/* if (MainDesignForm) { FLengthUnit = MainDesignForm->CurrentUnit; if (FLengthUnit==uCm) { seLength->Value = seLength->Value * 2.54; } else { seLength->Value = seLength->Value / 2.54; } RulerZoom->AUnit = FLengthUnit; Ruler->AUnit = FLengthUnit; stUnit->Caption = FLengthUnit==uCm ? "Cm" : "Inch"; Review(); } */ } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::DrawFancy(TTexpiaBitmap *YarnImage) { int i, j, sy, ey, y, x, yy, msy, mey, Length; Byte *DP, *DMP, *SP, tmp; RGBQUAD nRGB; sy = (HEIGHT - FYarnData.Thick) / 2; ey = sy + FYarnData.Thick; if (FYarnData.FancyMap) { FancyBitmap->StartScanLine(); FancyMask->StartScanLine(); for (y = 0; y < HEIGHT; y++) { SP = (Byte *)FYarnData.FancyMap + y * yarnMakeData.ImageWidth * 3; DP = (Byte *)FancyBitmap->GetScanLine(y); DMP = (Byte *)FancyMask->GetScanLine(y); for (x = 0; x < yarnMakeData.ImageWidth; x++, DP += 3, SP += 3) { if (*SP || *(SP + 1) || *(SP + 2)) { if (((int)*SP != 255) || ((int)*(SP + 1) != 255) || ((int)*(SP + 2) != 255)) { int yi = -1, yc = -1; for (i = 0; i < yarncount; i++) { for (j = 0; j < FYarnData.yInfor[i].Colors; j++) { int r, g, b; r = (short)FYarnData.yInfor[i].yColor[j].rgbRed; g = (short)FYarnData.yInfor[i].yColor[j].rgbGreen; b = (short)FYarnData.yInfor[i].yColor[j].rgbBlue; if ((((int)*(SP + 2) <= r + 1) && ((int)*(SP + 2) >= r - 1)) && (((int)*(SP + 1) <= g + 1) && ((int)*(SP + 1) >= g - 1)) && (((int)*SP <= b + 1) && ((int)*SP >= b - 1))) { yi = i; yc = j; } if (yi > -1 && yc > -1){ j = FYarnData.yInfor[i].Colors - 1; i = yarncount - 1; } } } if (yi > -1 && yc > -1){ nRGB = FYarnData.yInfor[yi].yColor[yc]; } else { for (i = 0; i < yarncount; i++) //À½¿µ»ö Ãß°¡ 05.11.09.shin { for (j = 0; j < FYarnData.yInfor[i].Colors; j++) { int r, g, b; double dh, dl, ds; RGBQUAD rgbDark; RGBQUAD2HLS(FYarnData.yInfor[i].yColor[j], dh, dl, ds); dl -= 0.1; rgbDark = HLS2RGBQUAD(dh, dl, ds); r = (short)rgbDark.rgbRed; g = (short)rgbDark.rgbGreen; b = (short)rgbDark.rgbBlue; if ((((int)*(SP + 2) <= r + 1) && ((int)*(SP + 2) >= r - 1)) && (((int)*(SP + 1) <= g + 1) && ((int)*(SP + 1) >= g - 1)) && (((int)*SP <= b + 1) && ((int)*SP >= b - 1))) { yi = i; yc = j; nRGB.rgbRed = rgbDark.rgbRed; nRGB.rgbGreen = rgbDark.rgbGreen; nRGB.rgbBlue = rgbDark.rgbBlue; } if (yi > -1 && yc > -1){ j = FYarnData.yInfor[i].Colors - 1; i = yarncount - 1; } } } } if (yi < 0 && yc < 0) nRGB = FYarnData.yInfor[0].yColor[0]; *(DP + 2) = (short)nRGB.rgbRed; *(DP + 1) = (short)nRGB.rgbGreen; *DP = (short)nRGB.rgbBlue; DMP[x/8] &= ~(0x80 >>(x%8)); } } } FancyBitmap->PutScanLine(y); FancyMask->PutScanLine(y); } FancyBitmap->StopScanLine(); FancyMask->StopScanLine(); } return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::KillFancy() { if (!fload && !cbLeaveFancy->Checked) cbFancy->Checked = false; //06.01.04.shin } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbDyedYarnClick(TObject *Sender) { if(WorkArea->Mask) sbOffClick(this); //qe if(menuitem == TMove || menuitem == TCopy) ResetMoveCopyMode(); if (sbDyedYarn->Down) { InitImage(true); } else { InitImage(false); yarncount = 1; seYarnNumber->Value = 1; FEditingYarnInfor[0]->YarnUnit = FYarnUnit; FEditingYarnInfor[0]->Count = 1; lbYarnUnit1->Enabled = true; MakeButton->Visible = true; cbSameUnit->Checked = false; Review(); } bmake = false; cbSuper->Enabled = false; if (MeasurePanel->Visible) sbMeaClick(this); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::InitImage(bool dyed) { int enable; bool fb = false, yb = false, fcb = false; if (bpp == 24) { if (dyed){ enable = 0; lbYarn1->Enabled = enable; lbYarn2->Enabled = enable; lbYarn3->Enabled = enable; lbYarn4->Enabled = enable; sbYarn1->Enabled = enable; sbYarn2->Enabled = enable; sbYarn3->Enabled = enable; sbYarn4->Enabled = enable; lbYarnUnit1->Enabled = enable; lbYarnUnit2->Enabled = enable; lbYarnUnit3->Enabled = enable; lbYarnUnit4->Enabled = enable; } else { enable = 1; for (int i = 1; i <= yarncount; i++) { ((TLabel *) FindComponent("lbYarn" + IntToStr(i)))->Enabled = true; ((TSpeedButton *) FindComponent("sbYarn" + IntToStr(i)))->Enabled = true; } } fb = FullImage->Bitmap->Create(WIDTH, HEIGHT, 24); if (fb == false) goto fail; FullImage->Bitmap->FillRect(Rect(0, 0, WIDTH, HEIGHT), clWhite); yb = YarnBitmap->Create(WIDTH, HEIGHT, 24); if (yb == false) goto fail; YarnBitmap->FillRect(Rect(0, 0, WIDTH, HEIGHT), clWhite); fcb = FancyBitmap->Create(WIDTH, HEIGHT, 24); if (fcb == false) goto fail; FancyBitmap->FillRect(Rect(0, 0, WIDTH, HEIGHT), clWhite); } pencolor = clWhite; Shape->Brush->Color = clWhite; Label1->Enabled = enable; cbSameUnit->Enabled = enable; lbSameUnit->Enabled = enable; sbSameUnit->Enabled = enable; Label2->Enabled = enable; seLength->Enabled = enable; lbLengthUnit->Enabled = enable; Label3->Enabled = enable; seYarnNumber->Enabled = enable; Label9->Enabled = enable; //lbCount->Enabled = enable; lbUnit->Enabled = enable; seCount->Enabled = enable; Label4->Enabled = enable; stTwist->Enabled = enable; Label5->Enabled = enable; seTPI->Enabled = enable; cbHair->Enabled = enable; Label7->Enabled = enable; Label8->Enabled = enable; seHairLength->Enabled = enable; seHairDensity->Enabled = enable; MakeButton->Enabled = enable; cbFancy->Enabled = enable; sbCountUnit->Enabled = enable; YarnUndo->RemoveAll(); return; fail: if (fb) FullImage->Bitmap->Destroy(); if (yb) YarnBitmap->Destroy(); if (fcb) FancyBitmap->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbWindowClick(TObject *Sender) { if (MeasurePanel->Visible) sbMeaClick(this); if(menuitem == TMove || menuitem == TCopy) ResetMoveCopyMode(); if(sbWindow->Down){ menuitem = TWin; InitWin(); }else{ sbWinClick(this); } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbOffClick(TObject *Sender) { WorkArea->ResetRegion(PartImage); StatusItem(0); sbWinClick(this); ImageRepaint(false); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::WindowMouseDown(int X, int Y) //added by qe { position = PartImage->PositionX; if (WinStep == 0) { WorkArea->ResetRegion(PartImage); First = Point(X, Y); // imageÀÇ ÁÂÇ¥·Î º¯È¯µÈ »óÅÂÀÓ P_First = PointReConvert(X, Y + 1); // ´Ù½Ã È­¸éÁÂÇ¥·Î º¯È¯. È­¸é¿¡¼­ ÀÛ¾÷±¸¿ª ±×·ÁÁÜ IsDraw = false; WinStep = 1; } else { Second = Point(X, Y); P_Second = PointReConvert(X, Y + 1); First.y = First.y - 1; Second.y = Second.y - 1; if (IsDraw) { ImageRepaint(false); WorkAreaDraw(); IsDraw = false; } WorkArea->SetShapeRegion(FancyBitmap, First, Second); StatusItem(1); WinStep = 0; } } //---------------------------------------------------------------------------- void __fastcall TYarnDesignForm::WindowMouseMove(int X, int Y) { if (WinStep > 0) { ImageRepaint(false); P_Second = Point(X, Y + 1); WorkAreaDraw(); IsDraw = true; } } //---------------------------------------------------------------------------- void __fastcall TYarnDesignForm::MoveCopyMouseDown(int X, int Y) { int dx, dy, x, y; RECT rc = WorkArea->Range; Byte *DP, *DMP; HDC dcFancyBitmap, dcTempBitmap; FancyBitmap->Copy(Bitmap, SRCCOPY); FancyMask->Copy(BitmapMask, SRCCOPY); YarnUndo->Save(Rect(0, 0, FancyBitmap->Width, HEIGHT)); UndoMask(false); if (menuitem == TMove) { FancyBitmap->FillRect(rc, clWhite); FancyMask->FillRect(rc, clWhite); } dx = X - TempBitmap->Width / 2; dy = Y - TempBitmap->Height / 2; if (dx < 0) dx = 0; if (dx + TempBitmap->Width >= FancyBitmap->Width) dx = FancyBitmap->Width - TempBitmap->Width - 1; if (dy < 0) dy = 0; if (dy + TempBitmap->Height >= FancyBitmap->Height) dy = FancyBitmap->Height - TempBitmap->Height - 1; //05.11.03.shin //FancyMask->CopyToRect(dx, dy, TempMask, SRCCOPY); // º¹»çÇÑ ºÎºÐÀÇ Èò»öÀÌ ³²À½. 05.11.03.shin //FancyBitmap->CopyToRect(dx, dy, TempBitmap, SRCCOPY); PasteCopyData(dx, dy); //05.11.03.shin if (menuitem == TMove) { sbMove->Down = false; menuitem = TOff; WorkArea->ResetRegion(PartImage); WorkArea->SetShapeRegion(FancyBitmap, Point(dx, dy), Point(dx+TempBitmap->Width - 1, dy+TempBitmap->Height - 1)); position = PartImage->PositionX; First = Point(dx, dy); Second = Point(dx+TempBitmap->Width, dy+TempBitmap->Height); P_First = PointReConvert(dx, dy + 2); P_Second = PointReConvert(dx+TempBitmap->Width - 1, dy+TempBitmap->Height + 1); ImageRepaint(false); WorkAreaDraw(); } else { Bitmap->Copy(FancyBitmap, SRCCOPY); BitmapMask->Copy(FancyMask, SRCCOPY); ImageRepaint(false); MaintainWorkArea(); } return; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::PasteCopyData(int dx, int dy) //05.11.03.shin { int dstY = dy, dstX = dx; Byte *Dst, *Src; FancyBitmap->StartScanLine(); TempBitmap->StartScanLine(); for (int y = 0; y < TempBitmap->Height; y++){ Dst = FancyBitmap->GetScanLine(dstY); Src = TempBitmap->GetScanLine(y); for (int x = 0; x < TempBitmap->Width; x++, Src+=3, Dst += 3){ if ((*Src != 255) && (*(Src + 1)!= 255) && (*(Src + 2) != 255)){ *(Dst + 3*dx) = *Src; *(Dst + 3*dx + 1) = *(Src + 1); *(Dst + 3*dx + 2) = *(Src + 2); } } FancyBitmap->PutScanLine(dstY); dstY++; } FancyBitmap->StopScanLine(); TempBitmap->StopScanLine(); FancyMask->CopyToRect(dx, dy, TempMask, SRCAND); // ¸¶½ºÅ©´Â AND } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::MoveCopyMouseMove(int X, int Y) { int dx, dy; FancyBitmap->Copy(Bitmap, SRCCOPY); FancyMask->Copy(BitmapMask, SRCCOPY); dx = X - TempBitmap->Width / 2; dy = Y - TempBitmap->Height / 2; if (dx < 0) dx = 0; if (dx + TempBitmap->Width > FancyBitmap->Width) dx = FancyBitmap->Width - TempBitmap->Width; if (dy < 0) dy = 0; if (dy + TempBitmap->Height > FancyBitmap->Height) dy = FancyBitmap->Height - TempBitmap->Height; //FancyBitmap->CopyToRect(dx, dy, TempBitmap,SRCCOPY); // tempbitmapÀ» fancybitmapÀÇ dx, dy·Î copy //FancyMask->CopyToRect(dx, dy, TempMask,SRCCOPY); PasteCopyData(dx, dy); //05.11.03.shin ImageRepaint(false); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::WorkAreaDraw() { HDC hDC = NULL; HBRUSH hOldBrush; HPEN hOldPen, hPen = NULL; int nDrawMode, fx, fy, sx, sy; POINT fir, sec; COLORREF clOldBk; hDC=PartImage->Canvas->Handle; clOldBk = SetBkColor(hDC, clWhite); hPen = CreatePen(PS_DOT, 1, clBlack); hOldPen = SelectObject(hDC, hPen); hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); fx = P_First.x; fy = P_First.y; sx = P_Second.x; sy = P_Second.y; Rectangle(hDC,min(fx, sx), min(fy, sy)-(int)zvalue, max(fx,sx)+(int)zvalue,max(fy, sy)); SetBkColor(hDC, clOldBk); SelectObject(hDC, hOldPen); DeleteObject(hPen); SelectObject(hDC, hOldBrush); return; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::MaintainWorkArea() //7 { if (WorkArea->Mask) { int width; if (FYarnData.Dyed) width = 100; else width = 50; if ((startx*propt <= First.x) && (First.x <= (startx + width)*propt)){ if (position != PartImage->PositionX){ P_First = PointReConvert(First.x, First.y); P_Second = PointReConvert(Second.x, Second.y); } WorkAreaDraw(); } } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::StatusItem(int i) { sbMove->Enabled = i; sbCopy->Enabled = i; sbOff->Enabled = i; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::Timer1Timer(TObject *Sender) { PartImage->OutlineBitmapRgn(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbWinClick(TObject *Sender) { sbWindow->Down = false; menuitem = TOff; WinStep = 0; WinPanel->Visible = false; pcDetail->Enabled = true; PartImage->Repaint(); MaintainWorkArea(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::InitWin() { WinPanel->Visible = true; sbRect->Down = true; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbMoveCopyClick(TObject *Sender) { bool tp = false, bt = false, tm = false, bm = false; TSpeedButton *sp = (TSpeedButton *) Sender; if(menuitem == TMove || menuitem == TCopy){ FancyBitmap->Copy(Bitmap, SRCCOPY); FancyMask->Copy(BitmapMask, SRCCOPY); ImageRepaint(false); } //if(menuitem == TMove || menuitem == TCopy) ResetMoveCopyMode(); if(sp->Down){ sbWinClick(this); if(sp == sbMove){ menuitem = TMove; } else if (sp == sbCopy) { menuitem = TCopy; } RECT rc = WorkArea->Range; tp = TempBitmap->Create(rc.right - rc.left, rc.bottom - rc.top, 24); if (tp == false) goto fail; tm = TempMask->Create(rc.right - rc.left, rc.bottom - rc.top, 1); if (tm == false) goto fail; TempBitmap->CopyFromRect(FancyBitmap, rc.left, rc.top, SRCCOPY); TempMask->CopyFromRect(FancyMask, rc.left, rc.top, SRCCOPY); bt = Bitmap->Create(FancyBitmap->Width, FancyBitmap->Height, 24); if (bt == false) goto fail; bm = BitmapMask->Create(FancyMask->Width, FancyMask->Height, 1); if (bm == false) goto fail; Bitmap->Copy(FancyBitmap, SRCCOPY); BitmapMask->Copy(FancyMask, SRCCOPY); }else { menuitem = TOff; } MaintainWorkArea(); return; fail: if (bt) Bitmap->Destroy(); if (tp) TempBitmap->Destroy(); if (tm) TempMask->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::ResetMoveCopyMode() { FancyBitmap->Copy(Bitmap, SRCCOPY); FancyMask->Copy(BitmapMask, SRCCOPY); ImageRepaint(false); sbCopy->Down = false; sbMove->Down = false; menuitem = TOff; } //--------------------------------------------------------------------------- // Measure void __fastcall TYarnDesignForm::sbFancyThickMeasureClick(TObject *Sender) { if(WorkArea->Mask) sbOffClick(this); if (sbFancyThickMeasure->Down){ InitMeasure(); MeasurePanel->Visible = true; MakeButton->Enabled = false; } else sbMeaClick(this); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::InitMeasure() { double len, wlen; DeleteLine(0); IsDrawLine = false; oldpoint = 0; IsDrawVLine = false; voldpoint = 0;//05.11.04.shin menuitem = TMeasure; if (FYarnData.FancyThick > 0){ len = FYarnData.FancyThick / propt; if (FLengthUnit == uInch) len = len / 160.0; else if (FLengthUnit == uCm) len = len * 2.54 / 160; //stFancyThick->Caption = Format("%.2f", OPENARRAY(TVarRec,(len))); stFancyThick->Text = Format("%.2f", OPENARRAY(TVarRec,(len))); } else { //stFancyThick->Caption = 0; stFancyThick->Text = 0; } if (FYarnData.FancyOneRepeat > 0){ //05.11.11.shin wlen = FYarnData.FancyOneRepeat / propt; if (FLengthUnit == uInch) wlen = wlen /160; else if (FLengthUnit == uCm) wlen = wlen * 2.54 / 160; //stFancyWidth->Caption = Format("%.2f", OPENARRAY(TVarRec,(wlen))); stFancyWidth->Text = Format("%.2f", OPENARRAY(TVarRec,(wlen))); } else { //stFancyWidth->Caption = 0; stFancyWidth->Text = 0; } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbMeaClick(TObject *Sender) { sbFancyThickMeasure->Down = false; MakeButton->Enabled = true; MeasurePanel->Visible = false; menuitem = TOff; MItem = NONE; if (IsDrawLine) DrawLine(); //if (IsDrawVLine) DrawVLine(); //05.11.07.shin DelPointLine(Point1); DelPointLine(Point2); sbPoint1->Down = false; sbPoint2->Down = false; sbPointW->Down = false; //05.11.07.shin PartImage->Repaint(); MaintainWorkArea(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbMeasureExitClick(TObject *Sender) { sbMeaClick(Sender); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::MeasureMouseDown(int X, int Y) //Point1, Point2 : ÃøÁ¤ÇÑ °ª { double length; if (MItem == POINT1){ Point1.y = Y; } else if (MItem == POINT2){ Point2.y = Y; } else if (MItem == POINT_W){ //05.11.07.shin Point_W.x = X; } oldpoint = Y; voldpoint = X; IsDrawLine = false; IsDrawVLine = false; if (MItem == POINT1 || MItem == POINT2){ if (sbPoint1->Down && sbPoint2->Down) sbFThick->Enabled = true; } else if (MItem == POINT_W){ sbFWidth->Enabled = true; //05.11.07.shin } MItem = NONE; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::MeasureMouseMove(int X, int Y) //M_First, M_Second : ±×·ÁÁö´Â Á¡ { if (IsDrawVLine){ if (M_VFirst.x != voldpoint) DrawVLine(); //05.11.07.shin M_VFirst.x = X; M_VFirst.y = 0; M_VSecond.x = X; M_VSecond.y = PartImage->Bitmap->Height - 1; DrawVLine(); IsDrawVLine = true; } else { //--------------------------- if (Point1.y != 0 && Point2.y != 0){ IsDrawLine = false; } else { if (IsDrawLine){ if (M_First.y != oldpoint) DrawLine(); M_First.x = 0; M_First.y = Y; M_Second.x = PartImage->Bitmap->Width - 1; M_Second.y = Y; DrawLine(); IsDrawLine = true; } } //---------------------------- } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::DrawLine() { HDC hDC = NULL; HPEN hOldPen; int nDrawMode; hDC = PartImage->Bitmap->CreateDC(); if (hDC == NULL) {EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return;} hOldPen = SelectObject(hDC, GetStockObject(WHITE_PEN)); nDrawMode = GetROP2(hDC); SetROP2(hDC, R2_XORPEN); MoveToEx(hDC, M_First.x, M_First.y - 1, NULL); // ¸¶¿ì½º Æ÷ÀÎÆ®º¸´Ù ÇÑ dot ¾Æ·¡·Î ±×·ÁÁ®¼­; LineTo(hDC, M_Second.x, M_Second.y - 1); SetROP2(hDC,nDrawMode); SelectObject(hDC, hOldPen); PartImage->Bitmap->DeleteDC(hDC); PartImage->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::DrawVLine() //05.11.04.shin { HDC hDC = NULL; HPEN hOldPen; int nDrawMode; hDC = PartImage->Bitmap->CreateDC(); if (hDC == NULL) {EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return;} hOldPen = SelectObject(hDC, GetStockObject(WHITE_PEN)); nDrawMode = GetROP2(hDC); SetROP2(hDC, R2_XORPEN); MoveToEx(hDC, M_VFirst.x, M_VFirst.y, NULL); LineTo(hDC, M_VSecond.x, M_VSecond.y); SetROP2(hDC,nDrawMode); SelectObject(hDC, hOldPen); PartImage->Bitmap->DeleteDC(hDC); PartImage->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbPoint1Click(TObject *Sender) { if (sbPoint1->Down){ IsDrawLine = true; if (MItem == POINT1) { MItem = NONE; DrawLine(); DeleteLine(0); IsDrawLine = false; } else { if(MItem == POINT2) { DrawLine(); DeleteLine(0); } DelPointLine(Point1); MItem = POINT1; IsDrawLine = true; } sbPointW->Enabled = false; } else { DelPointLine(Point1); IsDrawLine = false; if (!sbPoint2->Down) sbPointW->Enabled = true; } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbPoint2Click(TObject *Sender) { if (sbPoint2->Down){ IsDrawLine = true; if (MItem == POINT2) { MItem = NONE; DrawLine(); DeleteLine(0); IsDrawLine = false; } else { if (MItem == POINT1) { DrawLine(); DeleteLine(0); } MItem = POINT2; DelPointLine(Point2); IsDrawLine = true; } sbPointW->Enabled = false; } else { DelPointLine(Point2); IsDrawLine = false; if (!sbPoint1->Down) sbPointW->Enabled = true; } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbFThickClick(TObject *Sender) { int point1, point2; POINT pt1, pt2; double len; point1 = Point1.y; point2 = Point2.y; pt1.y = point1; pt2.y = point2; FYarnData.FPoint1 = pt1.y < pt2.y ? pt1.y : pt2.y; FYarnData.FPoint2 = pt1.y < pt2.y ? pt2.y : pt1.y; len = abs(FYarnData.FPoint1 - FYarnData.FPoint2); FYarnData.FancyThick = len; len = len / propt; if (FLengthUnit == uInch) len = len / 160.0; else if (FLengthUnit == uCm) len = len * 2.54 / 160; //stFancyThick->Caption = Format("%.2f", OPENARRAY(TVarRec,(len))); stFancyThick->Text = Format("%.2f", OPENARRAY(TVarRec,(len))); MItem = NONE; DelPointLine(Point1); DelPointLine(Point2); IsDrawLine = false; sbPoint1->Down = false; sbPoint2->Down = false; sbPointW->Enabled = true; sbFThick->Enabled = false; PartImage->Repaint(); MaintainWorkArea(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbFWidthClick(TObject *Sender) //05.11.11.shin { double len; len = Point_W.x; FYarnData.FancyOneRepeat = len; len = len/propt; if (FLengthUnit == uInch) len = len / 160.0; else if (FLengthUnit == uCm) len = len * 2.54 / 160; //stFancyWidth->Caption = Format("%.2f", OPENARRAY(TVarRec,(len))); stFancyWidth->Text = Format("%.2f", OPENARRAY(TVarRec,(len))); MItem = NONE; DrawVLine(); IsDrawVLine = false; sbPointW->Down = false; sbPoint1->Enabled = true; sbPoint2->Enabled = true; sbFWidth->Enabled = false; M_VFirst.x = 0; M_VFirst.y = 0; M_VSecond.x = 0; M_VSecond.y = 0; PartImage->Repaint(); MaintainWorkArea(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::DeleteLine(int Y) { M_First.x = 0; M_First.y = Y ; M_Second.x = PartImage->Bitmap->Width - 1; M_Second.y = Y; DrawLine(); IsDrawLine = false; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::DelPointLine(POINT point) { if (point.y != 0) { DeleteLine(point.y); DeleteLine(0); oldpoint = 0; } if (point.y == Point1.y) Point1.y = 0; else Point2.y = 0; } //--------------------------------------------------------------------------- /* void __fastcall TYarnDesignForm::MakeColorGrid() { int count = 1, ttab = 0; GColors = new TList; GColors->Capacity = FYarnData.Colors; cgrid = new TShape(this); cgrid->Parent = sbColorBox; cgrid->Left = FYarnData.Colors < 10 ? 5 : 7; cgrid->Top = 5; cgrid->Width = 23; cgrid->Height = 17; cgrid->Pen->Color = clBlack; cgrid->Pen->Width = 1; cgrid->Brush->Color = clWhite; cgrid->Visible = true; cgrid->OnMouseDown = colorgrid->OnMouseDown; GColors->Add(cgrid); // Áö¿ì±â¿ëÀ¸·Î Èò»ö. rgb(255,255,255) for (int i = 0; i < FYarnData.TYC; i++) { for (int j = 0; j < FYarnData.yInfor[i].Colors; j++) { cgrid = new TShape(this); cgrid->Parent = sbColorBox; if (FYarnData.Colors < 10) { if (count != 0) ttab = count / 5; cgrid->Left = 5 + (5 + 23) * (count % 5); } else { if(count != 0) ttab = count / 4; cgrid->Left = 7 + (7 + 23) * (count % 4); } cgrid->Top = 5 + (5 + 17) * ttab; cgrid->Width = 23; cgrid->Height = 17; cgrid->Pen->Color = clBlack; cgrid->Pen->Width = 1; cgrid->Brush->Color = RGB2TColor(FYarnData.yInfor[i].yColor[j].rgbRed, FYarnData.yInfor[i].yColor[j].rgbGreen, FYarnData.yInfor[i].yColor[j].rgbBlue); if (cgrid->Brush->Color == clWhite) cgrid->Brush->Color = 0x00FEFEFE; cgrid->Visible = true; cgrid->OnMouseDown = colorgrid->OnMouseDown; GColors->Add(cgrid); count++; } } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::ClearColorGrid() { if (!FYarnData.Dyed) { if (GColors){ for (int i = GColors->Count; i > 0; i--){ cgrid = (TShape *)GColors->Items[i-1]; GColors->Remove(cgrid); delete cgrid; cgrid = NULL; } delete GColors; } } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::colorgridMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { RGBQUAD q; int index; for (int i = 0; i < GColors->Count; i++) { cgrid = (TShape *)GColors->Items[i]; cgrid->Pen->Width = 1; } index = GColors->IndexOf(Sender); cgrid = (TShape *)GColors->Items[index]; cgrid->Pen->Width = 2; pencolor = cgrid->Brush->Color; TColor2RGB(TColor(pencolor), q.rgbRed, q.rgbGreen, q.rgbBlue); pencolor = RGBToColor24(q); } */ //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbCountUnitClick(TObject *Sender) { TPoint ptScreen; int i; TYarnUnitForm *Form = new TYarnUnitForm(this); for (i = 0; i < 6; i++) Form->vsble[i] = vsble[i]; ptScreen = ClientToScreen(Point(sbCountUnit->Left+sbCountUnit->Width+20, sbCountUnit->Top)); Form->Left = ptScreen.x; Form->Top = ptScreen.y; Form->YarnUnit.System = FYarnUnit.System; Form->YarnUnit.Method = FYarnUnit.Method; if (Form->ShowModal()== mrOk) { FYarnUnit = Form->YarnUnit; for (i = 0; i < 6; i++) vsble[i] = false; changeunit = true; //KillFancy(); } delete Form; CalculateCount(); Review(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::cbFancyClick(TObject *Sender) { if (!cbFancy->Checked){ YarnUndo->Save(Rect(0, 0, FancyBitmap->Width, FancyBitmap->Height)); UndoMask(false); FancyBitmap->FillRect(Rect(0, 0, FancyBitmap->Width, FancyBitmap->Height), clWhite); FancyMask->FillRect(Rect(0, 0, FancyBitmap->Width, FancyBitmap->Height), clWhite); sbRepeat->Enabled = false; WorkArea->ResetRegion(PartImage); StatusItem(0); ImageRepaint(); } return; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::cbSameUnitClick(TObject *Sender) { TLabel *Unitlabel; if (cbSameUnit->Checked){ sbSameUnit->Visible = true; for (int i = 0; i < yarncount; i++){ Unitlabel = (TLabel *) FindComponent("lbYarnUnit" + IntToStr(i+1)); Unitlabel->Visible = false; } } else { sbSameUnit->Visible = false; lbSameUnit->Visible = false; for (int i = 0; i < yarncount; i++){ Unitlabel = (TLabel *) FindComponent("lbYarnUnit" + IntToStr(i+1)); Unitlabel->Visible = true; } } Review(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbSameUnitClick(TObject *Sender) { TPoint ptScreen; int i; TYarnUnitForm *Form = new TYarnUnitForm(this); for (i = 0; i < 6; i++) Form->vsble[i] = true; ptScreen = ClientToScreen(Point(sbSameUnit->Left+sbSameUnit->Width+25, sbSameUnit->Top)); Form->Left = ptScreen.x; Form->Top = ptScreen.y; Form->YarnUnit.System = FYarnUnit.System; Form->YarnUnit.Method = FYarnUnit.Method; if (Form->ShowModal()== mrOk) { FYarnUnit = Form->YarnUnit; sameunit = true; lbSameUnit->Visible = true; for (int i = 0; i < yarncount; i++) FEditingYarnInfor[i]->YarnUnit = FYarnUnit; //KillFancy(); } delete Form; CalculateCount(); Review(); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::FindPencolor(RGBQUAD src) { Byte sr, sg, sb, fr, fg, fb; double sh, sl, ss, fh, fl, fs; TColor color; sr = src.rgbRed; sg = src.rgbGreen; sb = src.rgbBlue; if (sr == 0 && sg == 0 && sb == 0){ src.rgbBlue = 0x01; src.rgbGreen = 0x01; src.rgbRed = 0x01; src.rgbReserved = 0x00; } RGB2HLS(sr, sg, sb, sh, sl, ss); for (int i = 0; i < FYarnData.TYC; i++){ for (int j = 0; j < FYarnData.yInfor[i].Colors; j++){ RGB2HLS(FYarnData.yInfor[i].yColor[j].rgbRed,FYarnData.yInfor[i].yColor[j].rgbGreen, FYarnData.yInfor[i].yColor[j].rgbBlue, fh, fl, fs); if (IsRange(1, fh, sh) && IsRange(2, fs*100 , ss*100) && IsRange(50, fl*100, sl*100)){ Shape->Brush->Color = RGB2TColor(FYarnData.yInfor[i].yColor[j].rgbRed, FYarnData.yInfor[i].yColor[j].rgbGreen, FYarnData.yInfor[i].yColor[j].rgbBlue); pencolor = RGBToColor24(FYarnData.yInfor[i].yColor[j]); } } } if (sbErase->Down) sbErase->Down = false; } //--------------------------------------------------------------------------- bool __fastcall IsRange(int range, int src, int comp) { if ( src >= comp ) { if ( src - comp > range) return false; } else { if (comp - src > range) return false; } return true; } //--------------------------------------------------------------------------- int __fastcall LCM(int u, int v) // ÃÖ¼Ò°ø¹è¼ö±¸ÇÏ´Â ÇÔ¼ö { return u * v / GCD(u, v); } //--------------------------------------------------------------------------- int __fastcall GCD(int u, int v) // ÃÖ´ë°ø¾à¼ö±¸ÇÏ´Â ÇÔ¼ö { while(u) // u°¡ 0ÀÌ¸é ·çÇÁ¸¦ ³¡³¿ { if(u < v) // u°¡ vº¸´Ù ÀÛÀ¸¸é u¿Í v¸¦ ±³È¯ÇÑ´Ù. { // XORÀ» ÀÌ¿ëÇØ¼­ µÎ º¯¼öÀÇ °ªÀ» ¹Ù²Þ. u = u^v; v = u^v; u = u^v; } u -= v; // u = u-v } return v; // u°¡ 0À϶§ v°¡ ÃÖ´ë°ø¾à¼ö } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbEraseClick(TObject *Sender) { if (sbErase->Down){ oldpencolor = pencolor; pencolor = clWhite; } else { if (pencolor == clWhite) pencolor = oldpencolor; } } //--------------------------------------------------------------------------- __fastcall TYarnMakeData::TYarnMakeData() { for (int i = 0; i < 5; i++ ) { OneRepeatWidth[i] = 0; OneRepeatHeight[i] = 0; } ImageWidth = WIDTH; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::lbTPIClick(TObject *Sender) { if (isTPI) { lbTPI->Caption = "TPM"; isTPI = false; } else { lbTPI->Caption = "TPI"; isTPI = true; } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::cbLeaveFancyClick(TObject *Sender) { if (cbLeaveFancy->Checked && cbFancy->Checked){ //06.01.04.shin LeaveFancyBitmap(); } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::LeaveFancyBitmap() //06.01.04.shin { if (SaveFancyBitmap){ delete SaveFancyBitmap; SaveFancyBitmap = NULL; } if (SaveFancyMask){ delete SaveFancyMask; SaveFancyMask = NULL; } SaveFancyBitmap = new TTexpiaBitmap; SaveFancyMask = new TTexpiaBitmap; SaveFancyBitmap->Copy(FancyBitmap, SRCCOPY); SaveFancyMask->Copy(FancyMask, SRCCOPY); for (int i = 0; i < 32; i++){ FancyColors[i].rgbRed = 0xFF; FancyColors[i].rgbGreen = 0xFF; FancyColors[i].rgbBlue = 0xFF; FancyColors[i].rgbReserved = 0xFF; } int cnt = 0; for (int i = 0; i < FYarnData.TYC; i++){ for (int j = 0; j < FYarnData.yInfor[i].Colors; j++){ FancyColors[cnt] = FYarnData.yInfor[i].yColor[j]; cnt++; } } FancyColorNum = cnt; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::ChangeColor() //05.11.01.shin { Byte *SP, *DP, chRed, chGreen, chBlue; RGBQUAD nRGB; bool isDark = false; SaveFancyBitmap->StartScanLine(); for (int y = 0; y < SaveFancyBitmap->Height; y++) { SP = (Byte *)SaveFancyBitmap->GetScanLine(y); for (int x = 0; x < SaveFancyBitmap->Width; x++, SP += 3) { if (*SP || *(SP + 1) || *(SP + 2)) { if (((int)*SP != 255) || ((int)*(SP + 1) != 255) || ((int)*(SP + 2) != 255)) { //----------- int yi = 0, yc = 0, nowColor = -1; isDark = false; for (int i = 0; i < FancyColorNum; i++) { int r, g, b; r = (short)FancyColors[i].rgbRed; g = (short)FancyColors[i].rgbGreen; b = (short)FancyColors[i].rgbBlue; if ((((int)*(SP + 2) <= r + 1) && ((int)*(SP + 2) >= r - 1)) // ¿ø·¡ rgb¿Í ¿ÀÂ÷ +- 1 && (((int)*(SP + 1) <= g + 1) && ((int)*(SP + 1) >= g - 1)) && (((int)*SP <= b + 1) && ((int)*SP >= b - 1))) { nowColor = i; i = FancyColorNum - 1; } } if (nowColor == -1){ //À½¿µ»ö Ãß°¡ 05.11.09.shin for (int i = 0; i < yarncount; i++) { for (int j = 0; j < FancyColorNum; j++) { int r, g, b; double dh, dl, ds; RGBQUAD rgbDark; RGBQUAD2HLS(FancyColors[i], dh, dl, ds); dl -= 0.1; rgbDark = HLS2RGBQUAD(dh, dl, ds); r = (short)rgbDark.rgbRed; g = (short)rgbDark.rgbGreen; b = (short)rgbDark.rgbBlue; if ((((int)*(SP + 2) <= r + 1) && ((int)*(SP + 2) >= r - 1)) && (((int)*(SP + 1) <= g + 1) && ((int)*(SP + 1) >= g - 1)) && (((int)*SP <= b + 1) && ((int)*SP >= b - 1))) { nowColor = i; isDark = true; j = FancyColorNum - 1; i = yarncount - 1; } } } if (nowColor == -1) nowColor = 0; } int cnt = 0; for (int i = 0; i < FYarnData.TYC; i++){ for (int j = 0; j < FYarnData.yInfor[i].Colors; j++){ if (cnt == nowColor){ yi = i; yc = j; j = FYarnData.yInfor[i].Colors - 1; i = FYarnData.TYC - 1; } cnt++; } } //---------- nRGB = FYarnData.yInfor[yi].yColor[yc]; if (isDark){ // À½¿µ»öÀÌ´Ù 05.11.09.shin double dh, dl, ds; RGBQUAD nDark; RGBQUAD2HLS(nRGB, dh, dl, ds); dl -= 0.1; nDark = HLS2RGBQUAD(dh, dl, ds); chRed = nDark.rgbRed; chGreen = nDark.rgbGreen; chBlue = nDark.rgbBlue; } else { chRed = nRGB.rgbRed; chGreen = nRGB.rgbGreen; chBlue = nRGB.rgbBlue; } *(SP + 2) = (short)chRed; *(SP + 1) = (short)chGreen; *SP = (short)chBlue; } } } SaveFancyBitmap->PutScanLine(y); } SaveFancyBitmap->StopScanLine(); for (int i = 0; i < 32; i++){ FancyColors[i].rgbRed = 0xFF; FancyColors[i].rgbGreen = 0xFF; FancyColors[i].rgbBlue = 0xFF; FancyColors[i].rgbReserved = 0xFF; } int cnt = 0; for (int i = 0; i < FYarnData.TYC; i++){ for (int j = 0; j < FYarnData.yInfor[i].Colors; j++){ FancyColors[cnt] = FYarnData.yInfor[i].yColor[j]; cnt++; } } FancyColorNum = cnt; } //------------------------------------------------------------------------------ void __fastcall TYarnDesignForm::sbPointWClick(TObject *Sender) //05.11.04.shin { if (sbPointW->Down && !sbPoint1->Down && !sbPoint2->Down){ IsDrawVLine = true; DrawVLine(); MItem = POINT_W; sbPoint1->Enabled = false; sbPoint2->Enabled = false; } else { IsDrawVLine = false; sbPoint1->Enabled = true; sbPoint2->Enabled = true; } } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::sbYarnPrintClick(TObject *Sender) //05.12.12.shin { TPrinter *printer = Printer(); if (printer->Printers->Count == 0) return; TYarnPrintForm *PrintForm = NULL; if ((PrintForm = new TYarnPrintForm(this)) == NULL) return; if (PrintForm->ShowModal() == mrOk){ HDC dcFull, dcYarn, dcFancy, dcMask, dcPrintBitmap = NULL, hPrintDC = NULL, bmMemL, dcMemL; int WidthRes, HeightRes; // int hFull = (HEIGHT - (HEIGHT / propt)) / 2 - (HEIGHT - 80)/2; // 80 : formÀÇ FullImage size dcFull = FullImage->Bitmap->CreateDC(); dcYarn = YarnBitmap->CreateDC(); dcFancy = FancyBitmap->CreateDC(); dcMask = FancyMask->CreateDC(); Printer()->Title = FYarnData.FileName; Printer()->BeginDoc(); hPrintDC = Printer()->Handle; WidthRes = GetDeviceCaps(hPrintDC, LOGPIXELSX); HeightRes = GetDeviceCaps(hPrintDC, LOGPIXELSY); TTexpiaBitmap *printBitmap = new TTexpiaBitmap; printBitmap->Create(yarnMakeData.ImageWidth/propt*WidthRes/160, HEIGHT/propt*HeightRes/160, 24); printBitmap->FillRect(Rect(0, 0, printBitmap->Width, printBitmap->Height), clWhite); dcPrintBitmap = printBitmap->CreateDC(); int pageWidth = GetDeviceCaps(hPrintDC, HORZRES); int pageHeight = GetDeviceCaps(hPrintDC, VERTRES); SetStretchBltMode(dcPrintBitmap, COLORONCOLOR); //SetStretchBltMode(Printer()->Canvas->Handle, COLORONCOLOR); // if ((bmMemL = CreateCompatibleBitmap(dcFull, FullImage->Bitmap->Width, FullImage->Bitmap->Height)) == NULL) ; // if ((dcMemL = CreateCompatibleDC(dcFull)) == NULL) ; if ((bmMemL = CreateCompatibleBitmap(dcPrintBitmap, printBitmap->Width, printBitmap->Height)) == NULL) ; if ((dcMemL = CreateCompatibleDC(dcPrintBitmap)) == NULL) ; SelectObject(dcMemL, bmMemL); StretchBlt(dcPrintBitmap, 0, 0, yarnMakeData.ImageWidth/propt*WidthRes/160, HEIGHT/propt*HeightRes/160, dcYarn, 0, 0, yarnMakeData.ImageWidth, HEIGHT, SRCCOPY); StretchBlt(dcPrintBitmap, 0, 0, yarnMakeData.ImageWidth/propt*WidthRes/160, HEIGHT/propt*HeightRes/160, dcMask, 0, 0, yarnMakeData.ImageWidth, HEIGHT, SRCAND); StretchBlt(dcMemL, 0, 0, yarnMakeData.ImageWidth/propt*WidthRes/160, HEIGHT/propt*HeightRes/160, dcMask, 0, 0, yarnMakeData.ImageWidth, HEIGHT, NOTSRCCOPY); StretchBlt(dcMemL, 0, 0, yarnMakeData.ImageWidth/propt*WidthRes/160, HEIGHT/propt*HeightRes/160, dcFancy, 0, 0, yarnMakeData.ImageWidth, HEIGHT, SRCAND); BitBlt(dcPrintBitmap, 0, 0, yarnMakeData.ImageWidth/propt*WidthRes/160, HEIGHT/propt*HeightRes/160, dcMemL, 0, 0, SRCPAINT); //StretchBlt(Printer()->Canvas->Handle, 0, 0, yarnMakeData.ImageWidth/propt*WidthRes/160, HEIGHT/propt*HeightRes/160, dcYarn, 0, 0, yarnMakeData.ImageWidth, HEIGHT, SRCCOPY); //StretchBlt(Printer()->Canvas->Handle, 0, 0, yarnMakeData.ImageWidth/propt*WidthRes/160, HEIGHT/propt*HeightRes/160, dcMask, 0, 0, yarnMakeData.ImageWidth, HEIGHT, SRCAND); //StretchBlt(dcMemL, 0, 0, yarnMakeData.ImageWidth/propt*WidthRes/160, HEIGHT/propt*HeightRes/160, dcMask, 0, 0, yarnMakeData.ImageWidth, HEIGHT, NOTSRCCOPY); //StretchBlt(dcMemL, 0, 0, yarnMakeData.ImageWidth/propt*WidthRes/160, HEIGHT/propt*HeightRes/160, dcFancy, 0, 0, yarnMakeData.ImageWidth, HEIGHT, SRCAND); //BitBlt(Printer()->Canvas->Handle, 0, 0, yarnMakeData.ImageWidth/propt*WidthRes/160, HEIGHT/propt*HeightRes/160, dcMemL, 0, 0, SRCPAINT); int pWidth = printBitmap->Width; int pHeight = printBitmap->Height; if (pageWidth < printBitmap->Width) pWidth = pageWidth; if (pageHeight < printBitmap->Height) pHeight = pageHeight; BitBlt(Printer()->Canvas->Handle, 0, 0, pWidth, pHeight, dcPrintBitmap, 0, 0, SRCCOPY); Printer()->EndDoc(); if (dcPrintBitmap) printBitmap->DeleteDC(dcPrintBitmap); if (dcFull) FullImage->Bitmap->DeleteDC(dcFull); if (dcYarn) YarnBitmap->DeleteDC(dcYarn); if (dcFancy) FancyBitmap->DeleteDC(dcFancy); if (dcMask) FancyMask->DeleteDC(dcMask); if (dcMemL){ DeleteDC(dcMemL); DeleteObject(bmMemL); } if (printBitmap){ delete printBitmap; printBitmap = NULL; } ImageRepaint(false); } delete PrintForm; } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::FileRead_public(AnsiString fn) { FileRead(fn); } //--------------------------------------------------------------------------- void __fastcall TYarnDesignForm::cbFancyMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (cbFancy->Checked){ //¸Þ¼¼Áö: ÆÒ½Ãµ¥ÀÌÅͰ¡ »ç¶óÁý´Ï´Ù. °è¼ÓÇϽðڽÀ´Ï±î? AnsiString msg = IDS_DELETEFANCY; if (Application->MessageBox(msg.c_str(), "Warning", MB_OKCANCEL) == IDOK){ cbFancy->Checked = false; /* YarnUndo->Save(Rect(0, 0, FancyBitmap->Width, FancyBitmap->Height)); UndoMask(false); FancyBitmap->FillRect(Rect(0, 0, FancyBitmap->Width, FancyBitmap->Height), clWhite); FancyMask->FillRect(Rect(0, 0, FancyBitmap->Width, FancyBitmap->Height), clWhite); sbRepeat->Enabled = false; WorkArea->ResetRegion(PartImage); StatusItem(0); ImageRepaint(); */ } else { cbFancy->Checked = true; fload = true; } } } //---------------------------------------------------------------------------