//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "Stitch_F.h" #include "MainImage.h" #include "Palette.h" #include "PenManager.h" #include "Undo.h" #include "LogData.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "RzEdit" #pragma link "RzSpnEdt" #pragma link "RzCmboBx" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_SPACE StringTable[0] #define IDS_DRAWTYPE StringTable[1] #define IDS_CONTINUOUS StringTable[2] #define IDS_SEPARATE StringTable[3] #define IDS_DOT StringTable[4] #define IDS_NONE StringTable[5] #define IDS_LINE StringTable[6] //--------------------------------------------------------------------------- TStitchForm *StitchForm; //--------------------------------------------------------------------------- __fastcall TStitchForm::TStitchForm(TComponent* Owner) : TForm(Owner) { //===================================== 2001.3.27 lhskys FormCreate(TObject *Sender)³»¿ë ¿Å±è StringTable.Create(DirectoryItem, Language, "Stitch"); /* SetSmallFont(Font); SetSmallFont(lDot1->Font); SetSmallFont(lDot2->Font); SetSmallFont(lDot3->Font); SetSmallFont(lGap1->Font); SetSmallFont(lGap2->Font); SetSmallFont(lGap3->Font); SetSmallFont(Label1->Font); SetSmallFont(Label2->Font); SetSmallFont(DrawtypeText1->Font); SetSmallFont(DrawtypeText2->Font); */ gbLine1->Caption = String(IDS_LINE) + "1"; //Label1->Caption = String(IDS_SPACE) + " 1 (0 - 99)"; gbLine2->Caption = String(IDS_LINE) + "2"; //Label2->Caption = String(IDS_SPACE) + " 2 (0 - 99)"; gbLine3->Caption = String(IDS_LINE) + "3"; GroupBox1->Caption = IDS_DRAWTYPE; ImageDot1->Hint = IDS_DOT; ImageDot2->Hint = IDS_DOT; ImageDot3->Hint = IDS_DOT; ImageGap1->Hint = IDS_COMMON_GAP; ImageGap2->Hint = IDS_COMMON_GAP; ImageGap3->Hint = IDS_COMMON_GAP; Image7->Hint = String(IDS_SPACE) + " 1 (0 - 99)"; Image8->Hint = String(IDS_SPACE) + " 2 (0 - 99)"; //lDot1->Caption = IDS_DOT; //lDot2->Caption = IDS_DOT; //lDot3->Caption = IDS_DOT; //lGap1->Caption = IDS_COMMON_GAP; //lGap2->Caption = IDS_COMMON_GAP; //lGap3->Caption = IDS_COMMON_GAP; rzcbDrawtype1->Items->Clear(); rzcbDrawtype1->Items->Add(IDS_CONTINUOUS); rzcbDrawtype1->Items->Add(IDS_SEPARATE); rzcbDrawtype2->Items->Clear(); rzcbDrawtype2->Items->Add(IDS_COMMON_LINE); rzcbDrawtype2->Items->Add(IDS_COMMON_CURVE); //======================================================================== } //--------------------------------------------------------------------------- void __fastcall TStitchForm::FormCreate(TObject *Sender) { // } //--------------------------------------------------------------------------- void __fastcall TStitchForm::iLineClick(TObject *Sender) { /* ±×¸²¿¡¼­ Combo·Î ±³Ã¼ ÇÏ¿´±â ¶§¹®¿¡ ¸·¾ÒÀ½. ¸¸¾àÀÇ °æ¿ì¿¡ ´ëºñÇØ ³²°ÜµÒ. 20050307 by lhskys TImage *s; iMainImageChange(); s = (TImage *) Sender; s_Index[s->Tag]++; if (s_Index[s->Tag]>5) s_Index[s->Tag] = 0; switch (s_Index[s->Tag]) { case 0 : Tstitch.l[s->Tag].kind = TST_DOT; break; case 1 : Tstitch.l[s->Tag].kind = TST_ZZ; break; case 2 : Tstitch.l[s->Tag].kind = TST_BTN; break; case 3 : Tstitch.l[s->Tag].kind = TST_XXX; break; case 4 : Tstitch.l[s->Tag].kind = TST_NL; break; case 5 : Tstitch.l[s->Tag].kind = TST_None; } stitch_picture(s->Tag); */ } //--------------------------------------------------------------------------- void __fastcall TStitchForm::rxSpinEditClick(TObject *Sender) { TRzSpinEdit *rx = (TRzSpinEdit *) Sender; rx->SetFocus(); rx->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TStitchForm::seSpaceChange(TObject *Sender) { TRzSpinEdit *s = (TRzSpinEdit *)Sender; if (s->Text.Length()>0) { if (s->Value<0) { s->Value = 0; } else if (s->Value>99) { s->Value = 99; } else { iMainImageChange(); Tstitch.space[s->Tag] = s->Value; } } } //--------------------------------------------------------------------------- void __fastcall TStitchForm::seDotGapChange(TObject *Sender) { TRzSpinEdit *s = (TRzSpinEdit *)Sender; if (s->Text.Length()>0) { if (s->Value<1) { s->Value = 1; } else if (s->Value>99) { s->Value = 99; } else { iMainImageChange(); Tstitch.l[s->Tag].value[Tstitch.l[s->Tag].kind][s->TabOrder] = s->Value; } } } //--------------------------------------------------------------------------- void __fastcall TStitchForm::Line(COLORREF fc) { BEGIN_LOG(""); MainImageForm->line_pen(Lsx, Lsy, Lex, Ley, fc); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::dot_line(int ln, COLORREF fc) { BEGIN_LOG(""); int i, sx, sy, ex, ey, lx, ly, cnt, pw; double lng, gap, th, ct, st; pw = PenManagerForm->Pen->Thick; sx = Tstitch.l[ln].sx; sy = Tstitch.l[ln].sy; ex = Tstitch.l[ln].ex; ey = Tstitch.l[ln].ey; lx = ex - sx; ly = ey - sy; if ((ly == 0) && (lx == 0)) th = 0; else th = atan2(ly, lx); ct = cos(th); st = sin(th); lng = sqrt(lx * lx + ly * ly); gap = (Tstitch.l[ln].value[TST_DOT][0] + Tstitch.l[ln].value[TST_DOT][1]) * pw; cnt = lng / gap + 1; for (i = 0; i < cnt; i++) { if (gap * i <= lng) { Lsx = (gap * i) * ct + sx + 0.5; Lsy = (gap * i) * st + sy + 0.5; if ((gap * i + ((Tstitch.l[ln].value[TST_DOT][0] - 1) * pw)) <= lng) { Lex = (gap * i + ((Tstitch.l[ln].value[TST_DOT][0] - 1) * pw)) * ct + sx + 0.5; Ley = (gap * i + ((Tstitch.l[ln].value[TST_DOT][0] - 1) * pw)) * st + sy + 0.5; } else { Lex = lng * ct + sx; Ley = lng * st + sy; } Line(fc); } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::zigzag_line(int ln, COLORREF fc) { BEGIN_LOG(""); int sx, sy, ex, ey, lx, ly, i, j, k, cnt, pw; double vx, vy, px, py, theta, lng, wid, hei; pw = PenManagerForm->Pen->Thick; sx = Tstitch.l[ln].sx; ex = Tstitch.l[ln].ex; lx = ex - sx; sy = Tstitch.l[ln].sy; ey = Tstitch.l[ln].ey; ly = ey - sy; lng = sqrt((lx + 1) * (lx + 1) + (ly + 1) * (ly + 1)); wid = Tstitch.l[ln].value[TST_ZZ][0] * pw / 2.0; hei = (Tstitch.l[ln].value[TST_ZZ][1] - 1) * pw / 2.0; if ((ly == 0) && (lx == 0)) theta = 0; else theta = M_PI / 2.0 - atan2(ly, lx); vx = -cos(theta) * hei; vy = sin(theta) * hei; cnt = lng / wid; cnt = (cnt + 1) / 2.0 * 2; Lsx = sx; Lsy = sy; for (i = 0; i < cnt; i++) { j = i * 2 + 1; k = cnt * 2 - j; px = double(sx * k + ex * j) / (cnt * 2); py = double(sy * k + ey * j) / (cnt * 2); if (i & 1) { Lex = px - vx + 0.5; Ley = py - vy + 0.5; } else { Lex = px + vx + 0.5; Ley = py + vy + 0.5; } Line(fc); Lsx = Lex; Lsy = Ley; } Lex = ex; Ley = ey; Line(fc); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::button_line(int ln, COLORREF fc) { BEGIN_LOG(""); int i, j, k, sx, sy, ex, ey, lx, ly, lng, cnt, pw; double theta, gap, size, px, py, vx, vy; pw = PenManagerForm->Pen->Thick; sx = Tstitch.l[ln].sx; ex = Tstitch.l[ln].ex; lx = ex - sx; sy = Tstitch.l[ln].sy; ey = Tstitch.l[ln].ey; ly = ey - sy; lng = sqrt((lx + 1) * (lx + 1) + (ly + 1) * (ly + 1)); gap = (Tstitch.l[ln].value[TST_BTN][1] + 1) * pw; Lsx = sx; Lsy = sy; Lex = ex; Ley = ey; Line(fc); if ((ly == 0) && (lx == 0)) theta = 0; else theta = M_PI / 2.0 - atan2(ly, lx); size = (Tstitch.l[ln].value[TST_BTN][0] * pw - pw) / 2.0; vx = -cos(theta) * size; vy = sin(theta) * size; cnt = lng / gap + 1; for (i = 0; i < cnt; i++) { j = i * 2 + 1; k = cnt * 2 - j; px = double(sx * k + ex * j) / (cnt * 2); py = double(sy * k + ey * j) / (cnt * 2); Lsx = px + vx + 0.5; Lsy = py + vy + 0.5; Lex = px - vx + 0.5; Ley = py - vy + 0.5; Line(fc); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::xxx_line(int ln, COLORREF fc) { BEGIN_LOG(""); int i, j, k, sx, sy, ex, ey, lx, ly, lng, cnt, pw; double theta, gap, size, px, py, vx, vy; pw = PenManagerForm->Pen->Thick; sx = Tstitch.l[ln].sx; ex = Tstitch.l[ln].ex; lx = ex - sx; sy = Tstitch.l[ln].sy; ey = Tstitch.l[ln].ey; ly = ey - sy; lng = sqrt((lx + 1) * (lx + 1) + (ly + 1) * (ly + 1)); size = (Tstitch.l[ln].value[TST_XXX][0] - 1) * pw / sqrt(2.0); gap = (Tstitch.l[ln].value[TST_XXX][0] + Tstitch.l[ln].value[TST_XXX][1]) * pw; if ((ly == 0) && (lx == 0)) theta = M_PI_4; else theta = M_PI_4 - atan2(ly, lx); vx = -cos(theta) * size; vy = sin(theta) * size; cnt = lng / gap + 1; for (i = 0; i < cnt; i++) { j = i * 2 + 1; k = cnt * 2 - j; px = double(sx * k + ex * j) / (cnt * 2); py = double(sy * k + ey * j) / (cnt * 2); Lsx = px + vx + 0.5; Lsy = py + vy + 0.5; Lex = px - vx + 0.5; Ley = py - vy + 0.5; Line(fc); Lsx = px - vy + 0.5; Lsy = py + vx + 0.5; Lex = px + vy + 0.5; Ley = py - vx + 0.5; Line(fc); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::calc_stitch_position(int ix, int iy) { BEGIN_LOG(""); int lx, ly, pw, i, j; double st, ct, theta; pw = PenManagerForm->Pen->Thick; Tstitch.l[1].ex = ix; Tstitch.l[1].ey = iy; lx = Tstitch.l[1].ex - Tstitch.l[1].sx; ly = Tstitch.l[1].ey - Tstitch.l[1].sy; if (!reverse) { i = 1; j = 1; } else { i = -1; j = -1; } if ((lx == 0) && (ly == 0)) theta = 0; else theta = M_PI / 2.0 - atan2(ly, lx); ct = cos(theta) * Tstitch.space[0] * pw * i; st = sin(theta) * Tstitch.space[0] * pw * j; Tstitch.l[0].sx = Tstitch.l[1].sx + ct; Tstitch.l[0].sy = Tstitch.l[1].sy - st; Tstitch.l[0].ex = Tstitch.l[1].ex + ct; Tstitch.l[0].ey = Tstitch.l[1].ey - st; ct = cos(theta) * Tstitch.space[1] * pw * i; st = sin(theta) * Tstitch.space[1] * pw * j; Tstitch.l[2].sx = Tstitch.l[1].sx - ct; Tstitch.l[2].sy = Tstitch.l[1].sy + st; Tstitch.l[2].ex = Tstitch.l[1].ex - ct; Tstitch.l[2].ey = Tstitch.l[1].ey + st; END_LOG; } /* void __fastcall TStitchForm::calc_stitch_position(int ix, int iy) { int lx, ly, pw, i, j; double st, ct, theta; pw = MainForm->PenManagerForm->Pen->Thick; Tstitch.l[1].ex = ix; Tstitch.l[1].ey = iy; lx = Tstitch.l[1].ex - Tstitch.l[1].sx; ly = Tstitch.l[1].ey - Tstitch.l[1].sy; if (!reverse) { i = 1; j = 1; } else { i = -1; j = -1; } if ((lx == 0) && (ly == 0)) theta = 0; else theta = M_PI / 2.0 - atan2(ly, lx); if (start) { ct = cos(theta) * Tstitch.space[0] * pw * i; st = sin(theta) * Tstitch.space[0] * pw * j; Tstitch.l[0].sx = Tstitch.l[1].sx + ct; Tstitch.l[0].sy = Tstitch.l[1].sy - st; Tstitch.l[0].ex = Tstitch.l[1].ex + ct; Tstitch.l[0].ey = Tstitch.l[1].ey - st; ct = cos(theta) * Tstitch.space[1] * pw * i; st = sin(theta) * Tstitch.space[1] * pw * j; Tstitch.l[2].sx = Tstitch.l[1].sx - ct; Tstitch.l[2].sy = Tstitch.l[1].sy + st; Tstitch.l[2].ex = Tstitch.l[1].ex - ct; Tstitch.l[2].ey = Tstitch.l[1].ey + st; mmx[0] = Tstitch.l[0].sx ; mmy[0] = Tstitch.l[0].sy ; mmx[1] = Tstitch.l[2].sx ; mmy[1] = Tstitch.l[2].sy ; } else { ct = cos(theta) * Tstitch.space[0] * pw * i; st = sin(theta) * Tstitch.space[0] * pw * j; Tstitch.l[0].sx = Tstitch.l[0].ex; Tstitch.l[0].sy = Tstitch.l[0].ey; Tstitch.l[0].ex = Tstitch.l[1].ex + ct; Tstitch.l[0].ey = Tstitch.l[1].ey - st; ct = cos(theta) * Tstitch.space[1] * pw * i; st = sin(theta) * Tstitch.space[1] * pw * j; Tstitch.l[2].sx = Tstitch.l[2].ex; Tstitch.l[2].sy = Tstitch.l[2].ey; Tstitch.l[2].ex = Tstitch.l[1].ex - ct; Tstitch.l[2].ey = Tstitch.l[1].ey + st; if (center) { Tstitch.l[0].sx = mmx[0]; Tstitch.l[0].sy = mmy[0]; Tstitch.l[2].sx = mmx[1]; Tstitch.l[2].sy = mmy[1]; center = false; } } } */ //--------------------------------------------------------------------------- void __fastcall TStitchForm::tst_l(COLORREF fc) { BEGIN_LOG(""); TPItemImage *Image = MainImageForm->iMainImage; int i; for (i = 0; i <= 2; i++) { if (Tstitch.l[i].kind == TST_DOT) { dot_line(i, fc); } else if (Tstitch.l[i].kind == TST_ZZ) { zigzag_line(i, fc); } else if (Tstitch.l[i].kind == TST_BTN) { button_line(i, fc); } else if (Tstitch.l[i].kind == TST_XXX) { xxx_line(i, fc); } else if (Tstitch.l[i].kind == TST_NL) { Lsx = Tstitch.l[i].sx; Lsy = Tstitch.l[i].sy; Lex = Tstitch.l[i].ex; Ley = Tstitch.l[i].ey; Line(fc); } } if (DrawTypeIndex[1] == 0) { Image->Repaint(); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::LineLocate(HDC dc, int x, int y) { BEGIN_LOG(""); TPLayerImage *image=MainImageForm->iMainImage; RECT rt; int ls, rs; ls = PenManagerForm->Pen->Thick >> 1; rs = PenManagerForm->Pen->Thick - ls; //MoveToEx(dc, Lsx - x, Lsy - y, NULL); //LineTo(dc, Lex - x, Ley - y); if (image->ZoomIn <= image->ZoomOut) { MoveToEx(dc, image->BitmapToCanvasX(Lsx) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Lsy) - image->BitmapToCanvasY(y), NULL); LineTo(dc, image->BitmapToCanvasX(Lex) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Ley) - image->BitmapToCanvasY(y)); } else { MoveToEx(dc, Lsx - x, Lsy - y, NULL); LineTo(dc, Lex - x, Ley - y); } rt.left = min(Lsx, Lex) - 1; rt.top = min(Lsy, Ley) - 1; rt.right = max(Lsx, Lex) + 1; rt.bottom = max(Lsy, Ley) + 1; UnionRect(&DrawLocate.Src, &DrawLocate.Src, &rt); DrawLocate.Src.left -= ls; DrawLocate.Src.top -= ls; DrawLocate.Src.right += rs; DrawLocate.Src.bottom += rs; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::DotLineLocate(HDC dc, int x, int y, int ln) { BEGIN_LOG(""); TPLayerImage *image=MainImageForm->iMainImage; int i, sx, sy, ex, ey, lx, ly, cnt, pw; double lng, gap, th, ct, st; RECT rt; int ls, rs; ls = PenManagerForm->Pen->Thick >> 1; rs = PenManagerForm->Pen->Thick - ls; pw = PenManagerForm->Pen->Thick; sx = Tstitch.l[ln].sx; sy = Tstitch.l[ln].sy; ex = Tstitch.l[ln].ex; ey = Tstitch.l[ln].ey; lx = ex - sx; ly = ey - sy; if ((ly == 0) && (lx == 0)) th = 0; else th = atan2(ly, lx); ct = cos(th); st = sin(th); lng = sqrt(lx * lx + ly * ly); gap = (Tstitch.l[ln].value[TST_DOT][0] + Tstitch.l[ln].value[TST_DOT][1]) * pw; cnt = lng / gap + 1; for (i = 0; i < cnt; i++) { if (gap * i <= lng) { Lsx = (gap * i) * ct + sx + 0.5; Lsy = (gap * i) * st + sy + 0.5; if ((gap * i + ((Tstitch.l[ln].value[TST_DOT][0] - 1) * pw)) <= lng) { Lex = (gap * i + ((Tstitch.l[ln].value[TST_DOT][0] - 1) * pw)) * ct + sx + 0.5; Ley = (gap * i + ((Tstitch.l[ln].value[TST_DOT][0] - 1) * pw)) * st + sy + 0.5; } else { Lex = lng * ct + sx; Ley = lng * st + sy; } if(Lsx < Lex)Lex += 1; else if(Lsx > Lex)Lex -= 1; if(Lsy < Ley)Ley += 1; else if(Lsy > Ley)Ley -= 1; //MoveToEx(dc, Lsx - x, Lsy - y, NULL); //LineTo(dc, Lex - x, Ley - y); if (image->ZoomIn <= image->ZoomOut) { MoveToEx(dc, image->BitmapToCanvasX(Lsx) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Lsy) - image->BitmapToCanvasY(y), NULL); LineTo(dc, image->BitmapToCanvasX(Lex) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Ley) - image->BitmapToCanvasY(y)); } else { MoveToEx(dc, Lsx - x, Lsy - y, NULL); LineTo(dc, Lex - x, Ley - y); } rt.left = min(Lsx, Lex) - 1; rt.top = min(Lsy, Ley) - 1; rt.right = max(Lsx, Lex) + 1; rt.bottom = max(Lsy, Ley) + 1; UnionRect(&DrawLocate.Src, &DrawLocate.Src, &rt); } } DrawLocate.Src.left -= ls; DrawLocate.Src.top -= ls; DrawLocate.Src.right += rs; DrawLocate.Src.bottom += rs; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::ZigzagLineLocate(HDC dc, int x, int y, int ln) { BEGIN_LOG(""); TPLayerImage *image=MainImageForm->iMainImage; int sx, sy, ex, ey, lx, ly, i, j, k, cnt, pw; double vx, vy, px, py, theta, lng, wid, hei; RECT rt; int ls, rs; ls = PenManagerForm->Pen->Thick >> 1; rs = PenManagerForm->Pen->Thick - ls; pw = PenManagerForm->Pen->Thick; sx = Tstitch.l[ln].sx; ex = Tstitch.l[ln].ex; lx = ex - sx; sy = Tstitch.l[ln].sy; ey = Tstitch.l[ln].ey; ly = ey - sy; lng = sqrt((lx + 1) * (lx + 1) + (ly + 1) * (ly + 1)); wid = Tstitch.l[ln].value[TST_ZZ][0] * pw / 2.0; hei = (Tstitch.l[ln].value[TST_ZZ][1] - 1) * pw / 2.0; if ((ly == 0) && (lx == 0)) theta = 0; else theta = M_PI / 2.0 - atan2(ly, lx); vx = -cos(theta) * hei; vy = sin(theta) * hei; cnt = lng / wid; cnt = (cnt + 1) / 2.0 * 2; Lsx = sx; Lsy = sy; for (i = 0; i < cnt; i++) { j = i * 2 + 1; k = cnt * 2 - j; px = double(sx * k + ex * j) / (cnt * 2); py = double(sy * k + ey * j) / (cnt * 2); if (i & 1) { Lex = px - vx + 0.5; Ley = py - vy + 0.5; } else { Lex = px + vx + 0.5; Ley = py + vy + 0.5; } //MoveToEx(dc, Lsx - x, Lsy - y, NULL); //LineTo(dc, Lex - x, Ley - y); if (image->ZoomIn <= image->ZoomOut) { MoveToEx(dc, image->BitmapToCanvasX(Lsx) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Lsy) - image->BitmapToCanvasY(y), NULL); LineTo(dc, image->BitmapToCanvasX(Lex) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Ley) - image->BitmapToCanvasY(y)); } else { MoveToEx(dc, Lsx - x, Lsy - y, NULL); LineTo(dc, Lex - x, Ley - y); } rt.left = min(Lsx, Lex) - 1; rt.top = min(Lsy, Ley) - 1; rt.right = max(Lsx, Lex) + 1; rt.bottom = max(Lsy, Ley) + 1; UnionRect(&DrawLocate.Src, &DrawLocate.Src, &rt); Lsx = Lex; Lsy = Ley; } Lex = ex; Ley = ey; //MoveToEx(dc, Lsx - x, Lsy - y, NULL); //LineTo(dc, Lex - x, Ley - y); if (image->ZoomIn <= image->ZoomOut) { MoveToEx(dc, image->BitmapToCanvasX(Lsx) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Lsy) - image->BitmapToCanvasY(y), NULL); LineTo(dc, image->BitmapToCanvasX(Lex) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Ley) - image->BitmapToCanvasY(y)); } else { MoveToEx(dc, Lsx - x, Lsy - y, NULL); LineTo(dc, Lex - x, Ley - y); } rt.left = min(Lsx, Lex) - 1; rt.top = min(Lsy, Ley) - 1; rt.right = max(Lsx, Lex) + 1; rt.bottom = max(Lsy, Ley) + 1; UnionRect(&DrawLocate.Src, &DrawLocate.Src, &rt); DrawLocate.Src.left -= ls; DrawLocate.Src.top -= ls; DrawLocate.Src.right += rs; DrawLocate.Src.bottom += rs; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::ButtonLineLocate(HDC dc, int x, int y, int ln) { BEGIN_LOG(""); TPLayerImage *image=MainImageForm->iMainImage; int i, j, k, sx, sy, ex, ey, lx, ly, lng, cnt, pw; double theta, gap, size, px, py, vx, vy; RECT rt; int ls, rs; ls = PenManagerForm->Pen->Thick >> 1; rs = PenManagerForm->Pen->Thick - ls; pw = PenManagerForm->Pen->Thick; sx = Tstitch.l[ln].sx; ex = Tstitch.l[ln].ex; lx = ex - sx; sy = Tstitch.l[ln].sy; ey = Tstitch.l[ln].ey; ly = ey - sy; lng = sqrt((lx + 1) * (lx + 1) + (ly + 1) * (ly + 1)); gap = (Tstitch.l[ln].value[TST_BTN][1] + 1) * pw; Lsx = sx; Lsy = sy; Lex = ex; Ley = ey; //MoveToEx(dc, Lsx - x, Lsy - y, NULL); //LineTo(dc, Lex - x, Ley - y); if (image->ZoomIn <= image->ZoomOut) { MoveToEx(dc, image->BitmapToCanvasX(Lsx) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Lsy) - image->BitmapToCanvasY(y), NULL); LineTo(dc, image->BitmapToCanvasX(Lex) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Ley) - image->BitmapToCanvasY(y)); } else { MoveToEx(dc, Lsx - x, Lsy - y, NULL); LineTo(dc, Lex - x, Ley - y); } rt.left = min(Lsx, Lex) - 1; rt.top = min(Lsy, Ley) - 1; rt.right = max(Lsx, Lex) + 1; rt.bottom = max(Lsy, Ley) + 1; UnionRect(&DrawLocate.Src, &DrawLocate.Src, &rt); if ((ly == 0) && (lx == 0)) theta = 0; else theta = M_PI / 2.0 - atan2(ly, lx); size = (Tstitch.l[ln].value[TST_BTN][0] * pw - pw) / 2.0; vx = -cos(theta) * size; vy = sin(theta) * size; cnt = lng / gap + 1; for (i = 0; i < cnt; i++) { j = i * 2 + 1; k = cnt * 2 - j; px = double(sx * k + ex * j) / (cnt * 2); py = double(sy * k + ey * j) / (cnt * 2); Lsx = px + vx + 0.5; Lsy = py + vy + 0.5; Lex = px - vx + 0.5; Ley = py - vy + 0.5; //MoveToEx(dc, Lsx - x, Lsy - y, NULL); //LineTo(dc, Lex - x, Ley - y); if (image->ZoomIn <= image->ZoomOut) { MoveToEx(dc, image->BitmapToCanvasX(Lsx) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Lsy) - image->BitmapToCanvasY(y), NULL); LineTo(dc, image->BitmapToCanvasX(Lex) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Ley) - image->BitmapToCanvasY(y)); } else { MoveToEx(dc, Lsx - x, Lsy - y, NULL); LineTo(dc, Lex - x, Ley - y); } rt.left = min(Lsx, Lex) - 1; rt.top = min(Lsy, Ley) - 1; rt.right = max(Lsx, Lex) + 1; rt.bottom = max(Lsy, Ley) + 1; UnionRect(&DrawLocate.Src, &DrawLocate.Src, &rt); } DrawLocate.Src.left -= ls; DrawLocate.Src.top -= ls; DrawLocate.Src.right += rs; DrawLocate.Src.bottom += rs; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::XxxLineLocate(HDC dc, int x, int y, int ln) { BEGIN_LOG(""); TPLayerImage *image=MainImageForm->iMainImage; int i, j, k, sx, sy, ex, ey, lx, ly, lng, cnt, pw; double theta, gap, size, px, py, vx, vy; RECT rt; int ls, rs; ls = PenManagerForm->Pen->Thick >> 1; rs = PenManagerForm->Pen->Thick - ls; pw = PenManagerForm->Pen->Thick; sx = Tstitch.l[ln].sx; ex = Tstitch.l[ln].ex; lx = ex - sx; sy = Tstitch.l[ln].sy; ey = Tstitch.l[ln].ey; ly = ey - sy; lng = sqrt((lx + 1) * (lx + 1) + (ly + 1) * (ly + 1)); size = (Tstitch.l[ln].value[TST_XXX][0] - 1) * pw / sqrt(1.8); gap = (Tstitch.l[ln].value[TST_XXX][0] + Tstitch.l[ln].value[TST_XXX][1]) * pw; if ((ly == 0) && (lx == 0)) theta = M_PI_4; else theta = M_PI_4 - atan2(ly, lx); vx = -cos(theta) * size; vy = sin(theta) * size; cnt = lng / gap + 1; for (i = 0; i < cnt; i++) { j = i * 2 + 1; k = cnt * 2 - j; px = double(sx * k + ex * j) / (cnt * 2); py = double(sy * k + ey * j) / (cnt * 2); Lsx = px + vx + 0.5; Lsy = py + vy + 0.5; Lex = px - vx + 0.5; Ley = py - vy + 0.5; //MoveToEx(dc, Lsx - x, Lsy - y, NULL); //LineTo(dc, Lex - x, Ley - y); if (image->ZoomIn <= image->ZoomOut) { MoveToEx(dc, image->BitmapToCanvasX(Lsx) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Lsy) - image->BitmapToCanvasY(y), NULL); LineTo(dc, image->BitmapToCanvasX(Lex) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Ley) - image->BitmapToCanvasY(y)); } else { MoveToEx(dc, Lsx - x, Lsy - y, NULL); LineTo(dc, Lex - x, Ley - y); } rt.left = min(Lsx, Lex) - 1; rt.top = min(Lsy, Ley) - 1; rt.right = max(Lsx, Lex) + 1; rt.bottom = max(Lsy, Ley) + 1; UnionRect(&DrawLocate.Src, &DrawLocate.Src, &rt); Lsx = px - vy + 0.5; Lsy = py + vx + 0.5; Lex = px + vy + 0.5; Ley = py - vx + 0.5; //MoveToEx(dc, Lsx - x, Lsy - y, NULL); //LineTo(dc, Lex - x, Ley - y); if (image->ZoomIn <= image->ZoomOut) { MoveToEx(dc, image->BitmapToCanvasX(Lsx) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Lsy) - image->BitmapToCanvasY(y), NULL); LineTo(dc, image->BitmapToCanvasX(Lex) - image->BitmapToCanvasX(x), image->BitmapToCanvasY(Ley) - image->BitmapToCanvasY(y)); } else { MoveToEx(dc, Lsx - x, Lsy - y, NULL); LineTo(dc, Lex - x, Ley - y); } rt.left = min(Lsx, Lex) - 1; rt.top = min(Lsy, Ley) - 1; rt.right = max(Lsx, Lex) + 1; rt.bottom = max(Lsy, Ley) + 1; UnionRect(&DrawLocate.Src, &DrawLocate.Src, &rt); } DrawLocate.Src.left -= ls; DrawLocate.Src.top -= ls; DrawLocate.Src.right += rs; DrawLocate.Src.bottom += rs; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::TstLineLocate(HDC dc, int x, int y, void *pData) { BEGIN_LOG(""); TPLayerImage *image=MainImageForm->iMainImage; int i; HPEN hPen, hOldPen; if (image->ZoomIn <= image->ZoomOut) { hPen = CreatePen(PS_SOLID, DrawLocate.szPen*image->ZoomIn/image->ZoomOut+0.5, DrawLocate.clPen); } else { hPen = CreatePen(PS_SOLID, DrawLocate.szPen, DrawLocate.clPen); } // by celberus zoomIn ÇßÀ»¶§ ²ÞƲ°Å¸®´Â ¹®Á¦ ¶§¹®¿¡.. if (hPen == NULL) { END_LOG; return; } hOldPen = (HPEN)SelectObject(dc, hPen); for (i = 0; i <= 2; i++) { if (Tstitch.l[i].kind == TST_DOT) { DotLineLocate(dc, x, y, i); } else if (Tstitch.l[i].kind == TST_ZZ) { ZigzagLineLocate(dc, x, y, i); } else if (Tstitch.l[i].kind == TST_BTN) { ButtonLineLocate(dc, x, y, i); } else if (Tstitch.l[i].kind == TST_XXX) { XxxLineLocate(dc, x, y, i); } else if (Tstitch.l[i].kind == TST_NL) { Lsx = Tstitch.l[i].sx; Lsy = Tstitch.l[i].sy; Lex = Tstitch.l[i].ex; Ley = Tstitch.l[i].ey; LineLocate(dc, x, y); } } SelectObject(dc, hOldPen); DeleteObject(hPen); END_LOG; } //---------------------------------------------------------------------------- void __fastcall TStitchForm::DrawTstLineLocate(POINT First, POINT Second) { BEGIN_LOG(""); RECT rt; int ls, rs; TPItemImage *Image = MainImageForm->iMainImage; ls = PenManagerForm->Pen->Thick >> 1; rs = PenManagerForm->Pen->Thick - ls; rt.left = min(First.x, Second.x) - 1; rt.top = min(First.y, Second.y) - 1; rt.right = max(First.x, Second.x) + 1; rt.bottom = max(First.y, Second.y) + 1; DrawLocate.Src.left = rt.left - ls; DrawLocate.Src.top = rt.top - ls; DrawLocate.Src.right = rt.right + rs; DrawLocate.Src.bottom = rt.bottom + rs; UnionRect(&DrawLocate.Dst, &DrawLocate.Src, &DrawLocate.rtInvalidate); DrawLocate.szPen = PenManagerForm->Pen->Thick; DrawLocate.clPen = MainImageForm->Palette->Color[PaletteForm->DIB256Palette->ChoiceIndex]; DrawLocate.ptFirst.x = rt.left; DrawLocate.ptFirst.y = rt.top; DrawLocate.ptSecond.x = rt.right; DrawLocate.ptSecond.y = rt.bottom; Image->RectEditPaint(DrawLocate.Dst, TstLineLocate, NULL); UnionRect(&DrawLocate.rtInvalidate, &DrawLocate.Src, &DrawLocate.rtInvalidate); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::stitch_picture(int n) { BEGIN_LOG(""); // ±×¸²¿¡¼­ Combo·Î ±³Ã¼ ÇÏ¿´±â ¶§¹®¿¡ ¸·¾ÒÀ½. ¸¸¾àÀÇ °æ¿ì¿¡ ´ëºñÇØ ³²°ÜµÒ. 20050307 by lhskys // ÀÌ ÇÔ¼ö¸¦ È£ÃâÇÏÁö ¾ÊÁö¸¸ ³²°ÜµÒ. int i; TImage *s; int w, h; TLabel *l; TRzSpinEdit *se; s = (TImage *)(FindComponent("iLine" + String(n + 1))); w = s->Width; h = s->Height; s->Canvas->Pen->Width = 2; s->Canvas->Pen->Color = clYellow; s->Canvas->Brush->Style = bsSolid; s->Canvas->Brush->Color = clBtnFace; s->Canvas->FillRect(Rect(0, 0, w, h)); if (Tstitch.l[n].kind == TST_DOT) { l = (TLabel *)(FindComponent("lDot" + String(n + 1))); l->Caption = IDS_DOT; l->Visible = true; l = (TLabel *)(FindComponent("lGap" + String(n + 1))); l->Caption = IDS_COMMON_GAP; l->Visible = true; se = (TRzSpinEdit *)(FindComponent("seDot" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_DOT][0]; se->Visible = true; se = (TRzSpinEdit *)(FindComponent("seGap" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_DOT][1]; se->Visible = true; for (i = 0; i <= 4; i++) { s->Canvas->MoveTo((w / 4.0) / 3.0 + i * (w / 4.0), h / 2.0); s->Canvas->LineTo(((w / 4.0) / 3.0) * 2.0 + i * (w / 4.0), h / 2.0); } } else if (Tstitch.l[n].kind == TST_ZZ) { l = (TLabel *)(FindComponent("lDot" + String(n + 1))); l->Caption = IDS_COMMON_HEIGHT; l->Visible = true; l = (TLabel *)(FindComponent("lGap" + String(n + 1))); l->Caption = IDS_COMMON_WIDTH; l->Visible = true; se = (TRzSpinEdit *)(FindComponent("seDot" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_ZZ][0]; se->Visible = true; se = (TRzSpinEdit *)(FindComponent("seGap" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_ZZ][1]; se->Visible = true; for (i = 0; i <= 4; i++) { if (i & 1) { s->Canvas->MoveTo(i * (w / 5.0), 4); s->Canvas->LineTo((i + 1) * (w / 5.0), h-4); } else { s->Canvas->MoveTo(i * (w / 5.0), h-4); s->Canvas->LineTo((i + 1) * (w / 5.0), 4); } } } else if (Tstitch.l[n].kind == TST_BTN) { l = (TLabel *)(FindComponent("lDot" + String(n + 1))); l->Caption = IDS_COMMON_SIZE; l->Visible = true; l = (TLabel *)(FindComponent("lGap" + String(n + 1))); l->Caption = IDS_COMMON_GAP; l->Visible = true; se = (TRzSpinEdit *)(FindComponent("seDot" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_BTN][0]; se->Visible = true; se = (TRzSpinEdit *)(FindComponent("seGap" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_BTN][1]; se->Visible = true; s->Canvas->MoveTo(0, h / 2.0); s->Canvas->LineTo(w, h / 2.0); for (i = 1; i <= 5; i++) { s->Canvas->MoveTo(i * (w / 6.0), 4); s->Canvas->LineTo(i * (w / 6.0), h-4); } } else if (Tstitch.l[n].kind == TST_XXX) { l = (TLabel *)(FindComponent("lDot" + String(n + 1))); l->Caption = IDS_COMMON_SIZE; l->Visible = true; l = (TLabel *)(FindComponent("lGap" + String(n + 1))); l->Caption = IDS_COMMON_GAP; l->Visible = true; se = (TRzSpinEdit *)(FindComponent("seDot" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_XXX][0]; se->Visible = true; se = (TRzSpinEdit *)(FindComponent("seGap" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_XXX][1]; se->Visible = true; for (i = 0; i <= 4; i++) { s->Canvas->MoveTo(i * (w / 4.0), 4); s->Canvas->LineTo((i + 1) * (w / 4.0), h-4); s->Canvas->MoveTo(i * (w / 4.0), h-4); s->Canvas->LineTo((i + 1) * (w / 4.0), 4); } } else if (Tstitch.l[n].kind == TST_NL) { l = (TLabel *)(FindComponent("lDot" + String(n + 1))); l->Visible = false; l = (TLabel *)(FindComponent("lGap" + String(n + 1))); l->Visible = false; se = (TRzSpinEdit *)(FindComponent("seDot" + String(n + 1))); se->Visible = false; se = (TRzSpinEdit *)(FindComponent("seGap" + String(n + 1))); se->Visible = false; s->Canvas->MoveTo(0, h / 2.0); s->Canvas->LineTo(w, h / 2.0); } else if (Tstitch.l[n].kind == TST_None) { l = (TLabel *)(FindComponent("lDot" + String(n + 1))); l->Visible = false; l = (TLabel *)(FindComponent("lGap" + String(n + 1))); l->Visible = false; se = (TRzSpinEdit *)(FindComponent("seDot" + String(n + 1))); se->Visible = false; se = (TRzSpinEdit *)(FindComponent("seGap" + String(n + 1))); se->Visible = false; SetSmallFont(s->Canvas->Font); s->Canvas->Font->Style<Canvas->Font->Color = (TColor)0x008000FF; //0x602B44; Colorchange int wid = (80-s->Canvas->TextWidth(IDS_NONE)) / 2; s->Canvas->TextOut(wid, 4, IDS_NONE); } END_LOG; } //--------------------------------------------------------------------------- /* void __fastcall TStitchForm::InitForm() { Image = MainImageForm->iMainImage; if (Image->Image->uBitmap->BitsPerPixel==8) { MainImageForm->OnSetHLine = MainImageForm->SetHLine8ColorNo; } else { MainImageForm->OnSetHLine = MainImageForm->SetHLine24; } ParentHeight = Parent->Height+20; ClientHeight = 255; Parent->Height = ParentHeight+ClientHeight; Tstitch.sctype = 0; Tstitch.step = 0; Tstitch.line = 1; Tstitch.space[0] = 2; Tstitch.space[1] = 2; Tstitch.l[0].kind = TST_None; Tstitch.l[0].value[0][0] = 3; Tstitch.l[0].value[1][0] = 3; Tstitch.l[0].value[2][0] = 3; Tstitch.l[0].value[3][0] = 3; Tstitch.l[0].value[0][1] = 1; Tstitch.l[0].value[1][1] = 3; Tstitch.l[0].value[2][1] = 3; Tstitch.l[0].value[3][1] = 1; Tstitch.l[1].kind = TST_DOT; Tstitch.l[1].value[0][0] = 3; Tstitch.l[1].value[1][0] = 3; Tstitch.l[1].value[2][0] = 3; Tstitch.l[1].value[3][0] = 3; Tstitch.l[1].value[0][1] = 1; Tstitch.l[1].value[1][1] = 3; Tstitch.l[1].value[2][1] = 3; Tstitch.l[1].value[3][1] = 1; Tstitch.l[2].kind = TST_None; Tstitch.l[2].value[0][0] = 3; Tstitch.l[2].value[1][0] = 3; Tstitch.l[2].value[2][0] = 3; Tstitch.l[2].value[3][0] = 3; Tstitch.l[2].value[0][1] = 1; Tstitch.l[2].value[1][1] = 3; Tstitch.l[2].value[2][1] = 3; Tstitch.l[2].value[3][1] = 1; stitch_picture(0); stitch_picture(1); stitch_picture(2); undos = 0; s_Index[0] = 0; s_Index[1] = 1; s_Index[2] = 0; DrawTypeIndex[0] = 0; DrawTypeIndex[1] = 0; seDot1->Value = 3; seDot2->Value = 3; seDot3->Value = 3; seGap1->Value = 1; seGap2->Value = 1; seGap3->Value = 1; seSpace1->Value = 2; seSpace2->Value = 2; DrawtypeText1->Caption = IDS_CONTINUOUS; DrawtypeText2->Caption = IDS_LINE; reverse = false; start = true; center = false; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::ExitForm() { iMainImageChange(); } */ //--------------------------------------------------------------------------- void __fastcall TStitchForm::InitForm() { #if defined(TEXSTYLIST) MainImageForm->DrawORStitch=true; #endif TPItemImage *Image = MainImageForm->iMainImage; if (Image->uBitmap->BitsPerPixel==8) { MainImageForm->OnSetHLine = MainImageForm->SetHLine8ColorNo; } else { MainImageForm->OnSetHLine = MainImageForm->SetHLine24; } //ParentHeight = Parent->Height+20; //ClientHeight = 255; //Parent->Height = ParentHeight+ClientHeight; Tstitch.step = 0; Tstitch.l[0].value[0][0] = 3; Tstitch.l[0].value[1][0] = 3; Tstitch.l[0].value[2][0] = 3; Tstitch.l[0].value[3][0] = 3; Tstitch.l[0].value[0][1] = 1; Tstitch.l[0].value[1][1] = 3; Tstitch.l[0].value[2][1] = 3; Tstitch.l[0].value[3][1] = 1; Tstitch.l[1].value[0][0] = 3; Tstitch.l[1].value[1][0] = 3; Tstitch.l[1].value[2][0] = 3; Tstitch.l[1].value[3][0] = 3; Tstitch.l[1].value[0][1] = 1; Tstitch.l[1].value[1][1] = 3; Tstitch.l[1].value[2][1] = 3; Tstitch.l[1].value[3][1] = 1; Tstitch.l[2].value[0][0] = 3; Tstitch.l[2].value[1][0] = 3; Tstitch.l[2].value[2][0] = 3; Tstitch.l[2].value[3][0] = 3; Tstitch.l[2].value[0][1] = 1; Tstitch.l[2].value[1][1] = 3; Tstitch.l[2].value[2][1] = 3; Tstitch.l[2].value[3][1] = 1; ReadIniFile(); // ±×¸²¿¡¼­ Combo·Î ±³Ã¼ ÇÏ¿´±â ¶§¹®¿¡ ¸·¾ÒÀ½. ¸¸¾àÀÇ °æ¿ì¿¡ ´ëºñÇØ ³²°ÜµÒ. 20050307 by lhskys // stitch_picture(0); // stitch_picture(1); // stitch_picture(2); stitch_picture_select(); s_Index[0] = Tstitch.l[0].kind; s_Index[1] = Tstitch.l[1].kind; s_Index[2] = Tstitch.l[2].kind; undos = 0; seDot1->Value = Tstitch.l[0].value[Tstitch.l[0].kind][0]; seDot2->Value = Tstitch.l[1].value[Tstitch.l[1].kind][0]; seDot3->Value = Tstitch.l[2].value[Tstitch.l[2].kind][0]; seGap1->Value = Tstitch.l[0].value[Tstitch.l[0].kind][1]; seGap2->Value = Tstitch.l[1].value[Tstitch.l[1].kind][1]; seGap3->Value = Tstitch.l[2].value[Tstitch.l[2].kind][1]; seSpace1->Value = Tstitch.space[0]; seSpace2->Value = Tstitch.space[1]; rzcbDrawtype1->ItemIndex = DrawTypeIndex[0]; rzcbDrawtype2->ItemIndex = DrawTypeIndex[1]; reverse = false; start = true; center = false; rightangle = false; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::ReadIniFile() { BEGIN_LOG(""); TIniFile *StitchIni = NULL; StitchIni = new TIniFile(AppDataItem + "\\Stitch.ini"); if (StitchIni) { Tstitch.space[0] = StitchIni->ReadInteger("Space", "First", 2); Tstitch.space[1] = StitchIni->ReadInteger("Space", "Second", 2); Tstitch.l[0].kind = StitchIni->ReadInteger("Kind", "Line1", 5); Tstitch.l[1].kind = StitchIni->ReadInteger("Kind", "Line2", 0); Tstitch.l[2].kind = StitchIni->ReadInteger("Kind", "Line3", 5); if (Tstitch.l[0].kind < 4) { Tstitch.l[0].value[Tstitch.l[0].kind][0] = StitchIni->ReadInteger("Value", "Dot[0]", 3); if (Tstitch.l[0].kind == 1 || Tstitch.l[0].kind == 2) Tstitch.l[0].value[Tstitch.l[0].kind][1] = StitchIni->ReadInteger("Value", "Gap[0]", 3); else Tstitch.l[0].value[Tstitch.l[0].kind][1] = StitchIni->ReadInteger("Value", "Gap[0]", 1); } if (Tstitch.l[1].kind < 4) { Tstitch.l[1].value[Tstitch.l[1].kind][0] = StitchIni->ReadInteger("Value", "Dot[1]", 3); if (Tstitch.l[1].kind == 1 || Tstitch.l[1].kind == 2) Tstitch.l[1].value[Tstitch.l[1].kind][1] = StitchIni->ReadInteger("Value", "Gap[1]", 3); else Tstitch.l[1].value[Tstitch.l[1].kind][1] = StitchIni->ReadInteger("Value", "Gap[1]", 1); } if (Tstitch.l[2].kind < 4) { Tstitch.l[2].value[Tstitch.l[2].kind][0] = StitchIni->ReadInteger("Value", "Dot[2]", 3); if (Tstitch.l[2].kind == 1 || Tstitch.l[2].kind == 2) Tstitch.l[2].value[Tstitch.l[2].kind][1] = StitchIni->ReadInteger("Value", "Gap[2]", 3); else Tstitch.l[2].value[Tstitch.l[2].kind][1] = StitchIni->ReadInteger("Value", "Gap[2]", 1); } DrawTypeIndex[0] = StitchIni->ReadInteger("DrawType", "First", 0); DrawTypeIndex[1] = StitchIni->ReadInteger("DrawType", "Second", 0); delete StitchIni; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::WriteIniFile() { BEGIN_LOG(""); TIniFile *StitchIni = NULL; StitchIni = new TIniFile(AppDataItem + "\\Stitch.ini"); if (StitchIni) { StitchIni->WriteInteger("Space", "First", Tstitch.space[0]); StitchIni->WriteInteger("Space", "Second", Tstitch.space[1]); StitchIni->WriteInteger("Kind", "Line1", Tstitch.l[0].kind); StitchIni->WriteInteger("Kind", "Line2", Tstitch.l[1].kind); StitchIni->WriteInteger("Kind", "Line3", Tstitch.l[2].kind); if (Tstitch.l[0].kind < 4) { StitchIni->WriteInteger("Value", "Dot[0]", Tstitch.l[0].value[Tstitch.l[0].kind][0]); StitchIni->WriteInteger("Value", "Gap[0]", Tstitch.l[0].value[Tstitch.l[0].kind][1]); } if (Tstitch.l[1].kind < 4) { StitchIni->WriteInteger("Value", "Dot[1]", Tstitch.l[1].value[Tstitch.l[1].kind][0]); StitchIni->WriteInteger("Value", "Gap[1]", Tstitch.l[1].value[Tstitch.l[1].kind][1]); } if (Tstitch.l[2].kind < 4) { StitchIni->WriteInteger("Value", "Dot[2]", Tstitch.l[2].value[Tstitch.l[2].kind][0]); StitchIni->WriteInteger("Value", "Gap[2]", Tstitch.l[2].value[Tstitch.l[2].kind][1]); } StitchIni->WriteInteger("DrawType", "First", DrawTypeIndex[0]); StitchIni->WriteInteger("DrawType", "Second", DrawTypeIndex[1]); delete StitchIni; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::ExitForm() { #if defined(TEXSTYLIST) MainImageForm->DrawORStitch=false; #endif WriteIniFile(); iMainImageChange(); } //--------------------------------------------------------------------------- void __fastcall TStitchForm::RightAnglePosition(int &x, int &y) { int dx, dy, lx, ly; double length; TPItemImage *Image = MainImageForm->iMainImage; dx = x - Tstitch.l[1].sx; dy = y - Tstitch.l[1].sy; length = sqrt(dx * dx + dy * dy); if (x > Tstitch.l[1].sx) { if (y > Tstitch.l[1].sy) { //I lx = Tstitch.l[1].sx + length; ly = Tstitch.l[1].sy; if (lx >= Image->uBitmap->Width) lx = Image->uBitmap->Width - 1; } else { //IV lx = Tstitch.l[1].sx; ly = Tstitch.l[1].sy - length; if (ly < 0) ly = 0; } } else { if (y > Tstitch.l[1].sy) { //II lx = Tstitch.l[1].sx; ly = Tstitch.l[1].sy + length; if (ly >= Image->uBitmap->Height) ly = Image->uBitmap->Height - 1; } else { //III lx = Tstitch.l[1].sx - length; ly = Tstitch.l[1].sy; if (ly < 0) ly = 0; } } x = lx; y = ly; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::iMainImageKeyDown(WORD Key, TShiftState Shift) { if (Key == 'X') { iMainImageChange(); if (DrawTypeIndex[0] == 0 || DrawTypeIndex[0] == 1) { Tstitch.step = 0; undos = 0; } } else if (Key == 'Z') { if (DrawTypeIndex[1] == 0 && Tstitch.step == 1) { rightangle = true; } } } //--------------------------------------------------------------------------- void __fastcall TStitchForm::iMainImageKeyUp(int Key) { if (Key == 'Z') { // 88 : x 90 : z if (DrawTypeIndex[1] == 0 && Tstitch.step == 1) { rightangle = false; } } } //--------------------------------------------------------------------------- void __fastcall TStitchForm::iMainImageChange(void) { TPItemImage *Image = MainImageForm->iMainImage; Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TStitchForm::FGChange(int Value) { iMainImageChange(); } //--------------------------------------------------------------------------- void __fastcall TStitchForm::StitchMouseDown(TMouseButton Button, TShiftState Shift, int X, int Y) { BEGIN_LOG(""); COLORREF c; TPItemImage *Image = MainImageForm->iMainImage; if (Button==mbMiddle || (Shift.Contains(ssShift) && Button==mbLeft)) { END_LOG; return; } c = PaletteForm->DIB256Palette->GetFGCOLORREF(Image->uBitmap->BitsPerPixel); if (DrawTypeIndex[1] == 0) { if (Tstitch.step == 0) { rightangle = false; //lhskys Ŭ¸¯À» ÇßÀ»¶§ z°ªÀÌ ³²¾ÆÀִ°ÍÀ» Ãë¼Ò Tstitch.l[1].sx = X; Tstitch.sx = Tstitch.l[1].sx; Tstitch.l[1].sy = Y; Tstitch.sy = Tstitch.l[1].sy; calc_stitch_position(X, Y); Tstitch.step = 1; DrawTstLineLocate(Point(Tstitch.l[1].sx, Tstitch.l[1].sy), Point(Tstitch.l[1].ex, Tstitch.l[1].ey)); if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) //2001.6.19 by lhskys autorepeat MainImageForm->RedrawingRepeat(PenManagerForm->sbMask->Down, true); } else if (Tstitch.step == 1) { if (DrawTypeIndex[0] == 0) { if (undos == 0) { MainImageForm->UndoSave(UK_PATTERN, Rect(0, 0, Image->uBitmap->Width, Image->uBitmap->Height)); undos = 1; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) //2001.6.19 by lhskys autorepeat MainImageForm->RedrawingRepeat(PenManagerForm->sbMask->Down, true); } } else { MainImageForm->UndoSave(UK_PATTERN, Rect(0, 0, Image->uBitmap->Width, Image->uBitmap->Height)); if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) //2001.6.19 by lhskys autorepeat MainImageForm->RedrawingRepeat(PenManagerForm->sbMask->Down, true); } tst_l(c); if ( DrawTypeIndex[0] == 0) { Tstitch.l[1].sx = Tstitch.l[1].ex; Tstitch.l[1].sy = Tstitch.l[1].ey; DrawTstLineLocate(Point(Tstitch.l[1].sx, Tstitch.l[1].sy), Point(Tstitch.l[1].ex, Tstitch.l[1].ey)); if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) //2001.6.19 by lhskys autorepeat MainImageForm->RedrawingRepeat(PenManagerForm->sbMask->Down, true); } else { Tstitch.step = 0; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) //2001.6.19 by lhskys autorepeat MainImageForm->RedrawingRepeat(PenManagerForm->sbMask->Down, true); } } } else { if (Tstitch.step == 0) { Tstitch.l[1].sx = X; Tstitch.l[1].sy = Y; Tstitch.sx = Tstitch.l[1].sx; Tstitch.sy = Tstitch.l[1].sy; Lsx = Tstitch.sx; Lsy = Tstitch.sy; calc_stitch_position(X, Y); DrawTstLineLocate(Point(Tstitch.l[1].sx, Tstitch.l[1].sy), Point(Tstitch.l[1].ex, Tstitch.l[1].ey)); Tstitch.step = 1; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) //2001.6.19 by lhskys autorepeat MainImageForm->RedrawingRepeat(PenManagerForm->sbMask->Down, true); } else if (Tstitch.step == 1) { Lex = X; Ley = Y; Csx = X; Csy = Y; Tstitch.ex = X; Tstitch.ey =Y; Tstitch.cx = Csx; Tstitch.cy = Csy; calc_stitch_position(X, Y); DrawTstLineLocate(Point(Tstitch.l[1].sx, Tstitch.l[1].sy), Point(Tstitch.l[1].ex, Tstitch.l[1].ey)); Tstitch.step = 2; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) //2001.6.19 by lhskys autorepeat MainImageForm->RedrawingRepeat(PenManagerForm->sbMask->Down, true); } else { Lsx = Tstitch.sx; Lsy = Tstitch.sy; Csx = X; Csy = Y; Tstitch.cx = Csx; Tstitch.cy = Csy; DrawTstCurveLocate(Point(Tstitch.l[1].sx, Tstitch.l[1].sy), Point(Tstitch.l[1].ex, Tstitch.l[1].ey), Point(Csx, Csy)); if (DrawTypeIndex[0] == 1) { MainImageForm->UndoSave(UK_PATTERN, Rect(0, 0, Image->uBitmap->Width, Image->uBitmap->Height)); if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) //2001.6.19 by lhskys autorepeat MainImageForm->RedrawingRepeat(PenManagerForm->sbMask->Down, true); } else { if (undos == 0) { MainImageForm->UndoSave(UK_PATTERN, Rect(0, 0, Image->uBitmap->Width, Image->uBitmap->Height)); undos = 1; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) //2001.6.19 by lhskys autorepeat MainImageForm->RedrawingRepeat(PenManagerForm->sbMask->Down, true); } } dot_curve(c); if (DrawTypeIndex[0] == 1) { Tstitch.step = 0; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) //2001.6.19 by lhskys autorepeat MainImageForm->RedrawingRepeat(PenManagerForm->sbMask->Down, true); } else { Tstitch.step = 1; Tstitch.l[1].sx = Tstitch.ex; Tstitch.l[1].sy = Tstitch.ey; Tstitch.l[1].ex = Tstitch.l[1].sx; Tstitch.l[1].ey = Tstitch.l[1].sy; Tstitch.sx = Tstitch.l[1].sx; Tstitch.sy = Tstitch.l[1].sy; Tstitch.ex = Tstitch.l[1].sx; Tstitch.ey = Tstitch.l[1].sy; Lsx = Tstitch.l[1].sx; Lsy = Tstitch.l[1].sy; Csx = Lsx; Csy = Lsy; Tstitch.cx = Csx; Tstitch.cy = Csy; DrawTstCurveLocate(Point(Tstitch.l[1].sx, Tstitch.l[1].sy), Point(Tstitch.l[1].ex, Tstitch.l[1].ey), Point(Csx, Csy)); if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) //2001.6.19 by lhskys autorepeat MainImageForm->RedrawingRepeat(PenManagerForm->sbMask->Down, true); } } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::StitchMouseMove(int X, int Y) { if(DrawTypeIndex[1] == 0) { if (Tstitch.step != 0) { if (rightangle) { // Z Key int delta_x,delta_y; delta_x = (X - Tstitch.l[1].sx); if(delta_x<0) delta_x = -delta_x; delta_y = (Y - Tstitch.l[1].sy); if(delta_y<0) delta_y = -delta_y; if( delta_xPen->Thick; Tstitch.l[1].ex = ix; Tstitch.l[1].ey = iy; lx = Tstitch.l[1].ex - Tstitch.l[1].sx; ly = Tstitch.l[1].ey - Tstitch.l[1].sy; if (!reverse) { i = 1; j = 1; } else { i = -1; j = -1; } if ((lx == 0) && (ly == 0)) theta = 0; else theta = M_PI / 2.0 - atan2(ly, lx); ct = cos(theta) * Tstitch.space[0] * pw * i; st = sin(theta) * Tstitch.space[0] * pw * j; Tstitch.l[0].sx = Tstitch.l[1].sx + ct; Tstitch.l[0].sy = Tstitch.l[1].sy - st; Tstitch.l[0].ex = Tstitch.l[1].ex + ct; Tstitch.l[0].ey = Tstitch.l[1].ey - st; ct = cos(theta) * Tstitch.space[1] * pw * i; st = sin(theta) * Tstitch.space[1] * pw * j; Tstitch.l[2].sx = Tstitch.l[1].sx - ct; Tstitch.l[2].sy = Tstitch.l[1].sy + st; Tstitch.l[2].ex = Tstitch.l[1].ex - ct; Tstitch.l[2].ey = Tstitch.l[1].ey + st; END_LOG; } //--------------------------------------------------------------------------- /* void __fastcall TStitchForm::dot_curve(TPenMode ch, COLORREF fc) { int sx, sy, ex, ey, mx, my, llex, lley; double ct, st, ss, theta, alpha, d1, d2, d3; double tx, ty, a, b, x, y, pw, count, c; pw = MainForm->PenManagerForm->Pen->Thick; sx = Tstitch.sx; sy = Tstitch.sy; ex = Tstitch.ex; ey = Tstitch.ey; mx = Csx; my = Csy; d1 = sqrt((sx - mx) * (sx - mx) + (sy - my) * (sy - my)); d2 = sqrt((ex - mx) * (ex - mx) + (ey - my) * (ey - my)); d3 = sqrt((ex - sx) * (ex - sx) + (ey - sy) * (ey - sy)); if (d1 > d2) { a = d1; b = d2; } else { a = d2; b = d1; } if ((my - sy) * (ex - sx) == (mx - sx) * (ey - sy)) { Tstitch.l[1].sx = sx; Tstitch.l[1].ex = ex; Tstitch.l[1].sy = sy; Tstitch.l[1].ey = ey; calc_stitch_position(ex, ey); tst_l(ch, fc); } else if ((sy == ey) && ((mx - sx) == (mx - ex))) { if (sx > mx) tx = sx - mx; else tx = mx - sx; ty = sy - my; alpha = ty / (tx * tx); count = fabs(tx) / 160.0 * pw + 2; c = 2.5; Lsx = mx; Lsy = my; x = count + c; while (x <= tx) { y = alpha * (x * x); Lex = mx + x; Ley = my + y; llex = Lex; lley = Ley; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(ch, fc); Lsx = llex; Lsy = lley; count = count + c; x = x + count; } if (sx > ex) Lex = sx; else Lex = ex; Ley = sy; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(ch, fc); count = fabs(tx) / 160.0 * pw + 2; Lsx = mx; Lsy = my; x = count + c; while (x <= tx) { y = alpha * (x * x); Lex = mx - x; Ley = my + y; llex = Lex; lley = Ley; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(ch, fc); Lsx = llex; Lsy = lley; count = count + c; x = x + count; } if (sx < ex) Lex = sx; else Lex = ex; Ley = sy; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(ch, fc); } else { if ((a > b * 1.8) && (d3 < a)) { d1 = sqrt(d1); d2 = sqrt(d2); } tx = (Lex * d1 + Lsx * d2) / (d1 + d2); ty = (Ley * d1 + Lsy * d2) / (d1 + d2); if (tx - mx) ss = (ty - my) / (tx - mx); else ss = 0; theta = M_PI / 2.0 - atan(ss); ct = cos(theta); st = sin(theta); tx = ct * (sx - mx) - st * (sy - my); ty = st * (sx - mx) + ct * (sy - my); alpha = ty / (tx * tx); count = fabs(tx) / 160.0 * pw + 2; c = 2.5; reverse = true; Lsx = mx; Lsy = my; if (tx < 0) { x = -(count + c); while (x >= tx) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; llex = Lex; lley = Ley; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(ch, fc); start = false; Lsx = llex; Lsy = lley; count = count + c; x = x - count; } } else { x = (count + c); while (x <= tx) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; llex = Lex; lley = Ley; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(ch, fc); start = false; Lsx = llex; Lsy = lley; count = count + c; x = x + count; } } Lex = sx; Ley = sy; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(ch, fc); tx = ct * (ex - mx) - st * (ey - my); ty = st * (ex - mx) + ct * (ey - my); alpha = ty / (tx * tx); count = fabs(tx) / 160.0 * pw + 2; c = 2.5; reverse = false; center = true; Lsx = mx; Lsy = my; if (tx < 0) { x = -(count + c); while (x >= tx) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; llex = Lex; lley = Ley; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(ch, fc); Lsx = llex; Lsy = lley; count = count + c; x = x - count; } } else { x = count + c; while (x <= tx) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; llex = Lex; lley = Ley; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(ch, fc); Lsx = llex; Lsy = lley; count = count + c; x = x + count; } } Lex = ex; Ley = ey; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(ch, fc); } start = true; if (ch == pmCopy) Image->Repaint(); Lsx = sx; Lex = ex; Lsy = sy; Ley = ey; } */ //--------------------------------------------------------------------------- void __fastcall TStitchForm::dot_curve(COLORREF fc) { BEGIN_LOG(""); int i, j, sx, sy, ex, ey; int ssx, eex, ssy, eey, mx, my; int cnt, grade, total, value[2], kind; double x, y, llsx, llsy, llex, lley; double tx, ty, a, b, pw, count, c; double lng, gap; double ct, st, ss, theta, alpha, d1, d2, d3; TPItemImage *Image = MainImageForm->iMainImage; kind = Tstitch.l[1].kind; if ((kind != 4) && (kind != 5)) { value[0] = Tstitch.l[1].value[kind][0]; value[1] = Tstitch.l[1].value[kind][1]; } else { value[0] = 4; value[1] = 2; } pw = PenManagerForm->Pen->Thick; sx = Tstitch.sx; sy = Tstitch.sy; ex = Tstitch.ex; ey = Tstitch.ey; mx = Csx; my = Csy; d1 = sqrt((sx - mx) * (sx - mx) + (sy - my) * (sy - my)); d2 = sqrt((ex - mx) * (ex - mx) + (ey - my) * (ey - my)); d3 = sqrt((ex - sx) * (ex - sx) + (ey - sy) * (ey - sy)); if (d1 >= d2) { a = d1; b = d2; } else { a = d2; b = d1; } if ((my - sy) * (ex - sx) == (mx - sx) * (ey - sy)) { Tstitch.l[1].sx = sx; Tstitch.l[1].ex = ex; Tstitch.l[1].sy = sy; Tstitch.l[1].ey = ey; calc_stitch_position(ex, ey); tst_l(fc); } else if ((sy == ey) && ((mx - sx) == (mx - ex))) { tx = abs(mx - sx); ty = sy - my; alpha = ty / (tx * tx); count = fabs(tx) / 160.0 * pw + 2; c = 2.5; Lsx = mx; Lsy = my; x = 0; while (x <= tx) { y = alpha * (x * x); Lex = mx + x; Ley = my + y; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(fc); Lsx = Lex; Lsy = Ley; count = count + c; x = x + count; } if (sx > ex) Lex = sx; else Lex = ex; Ley = sy; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(fc); count = abs(tx) / 160.0 * pw + 2; Lsx = mx; Lsy = my; x = 0; while (x <= tx) { y = alpha * (x * x); Lex = mx - x; Ley = my + y; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(fc); Lsx = Lex; Lsy = Ley; count = count + c; x = x + count; } if (sx < ex) Lex = sx; else Lex = ex; Ley = sy; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(fc); } else { int i; double x1,x2; if ((a > b * 1.8) && (d3 < a)) { d1 = sqrt(d1); d2 = sqrt(d2); } tx = (Lex * d1 + Lsx * d2) / (d1 + d2); ty = (Ley * d1 + Lsy * d2) / (d1 + d2); if (tx - mx) ss = (ty - my) / (tx - mx); else ss = 0; theta = M_PI / 2.0 - atan(ss); ct = cos(theta); st = sin(theta); tx = ct * (sx - mx) - st * (sy - my); ty = st * (sx - mx) + ct * (sy - my); alpha = ty / (tx * tx); ssx = 0; ssy = 0; eex = tx; eey = ty; for(i=0;i<=2;i++){ if(Tstitch.l[i].kind==TST_DOT) gap = (Tstitch.l[i].value[Tstitch.l[i].kind][0] + Tstitch.l[i].value[Tstitch.l[i].kind][1]) * pw; else if(Tstitch.l[i].kind==TST_ZZ) gap = (Tstitch.l[i].value[Tstitch.l[i].kind][0]) * pw; else if(Tstitch.l[i].kind==TST_BTN) gap = (Tstitch.l[i].value[Tstitch.l[i].kind][1]) * pw; else if(Tstitch.l[i].kind==TST_XXX) gap = (Tstitch.l[i].value[Tstitch.l[i].kind][0] + Tstitch.l[i].value[Tstitch.l[i].kind][1]) * pw; else if(Tstitch.l[i].kind==TST_NL) gap = pw; else if(Tstitch.l[i].kind==TST_None)continue; if(gap==0)gap=1; reverse = true; x2=0; x1=0; while(abs(x1) b * 1.8) && (d3 < a)) { d1 = sqrt(d1); d2 = sqrt(d2); } tx = (Lex * d1 + Lsx * d2) / (d1 + d2); ty = (Ley * d1 + Lsy * d2) / (d1 + d2); if (tx - mx) ss = (ty - my) / (tx - mx); else ss = 0; theta = M_PI / 2.0 - atan(ss); ct = cos(theta); st = sin(theta); tx = ct * (sx - mx) - st * (sy - my); ty = st * (sx - mx) + ct * (sy - my); alpha = ty / (tx * tx); ssx = 0; ssy = 0; eex = tx; eey = ty; lng = sqrt((eex - ssx + 1) * (eex - ssx + 1) + (eey - ssy + 1) * (eey - ssy + 1)); gap = (Tstitch.l[0].value[TST_DOT][0] + Tstitch.l[0].value[TST_DOT][1]) * pw; // gap = (value[0] + value[1]) * pw; // by playzzang cnt = lng / gap + 1; grade = (value[0] + value[1]) * 2; total = cnt * grade; reverse = true; for (i = 0; i < cnt; i++) { j = i * grade + 1 + value[1]; llsx = double(eex * j) / total; llsy = alpha * llsx * llsx; Lsx = ct * llsx + st * llsy + mx + 0.5; Lsy = ct * llsy - st * llsx + my + 0.5; j = j + grade; llex = double(eex * j) / total; lley = alpha * llex * llex; Lex = ct * llex + st * lley + mx + 0.5; Ley = ct * lley - st * llex + my + 0.5; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(fc); } tx = ct * (ex - mx) - st * (ey - my); ty = st * (ex - mx) + ct * (ey - my); alpha = ty / (tx * tx); ssx = 0; ssy = 0; eex = tx; eey = ty; lng = sqrt((eex - ssx + 1) * (eex - ssx + 1) + (eey - ssy + 1) * (eey - ssy + 1)); gap = (Tstitch.l[0].value[TST_DOT][0] + Tstitch.l[0].value[TST_DOT][1]) * pw; // gap = (value[0] + value[1]) * pw; // by playzzang cnt = lng / gap + 1; grade = (value[0] + value[1]) * 2; total = cnt * grade; reverse = false; for (i = 0; i < cnt; i++) { j = i * grade + 1 + value[1]; llsx = double(eex * j) / total; llsy = alpha * llsx * llsx; Lsx = ct * llsx + st * llsy + mx + 0.5; Lsy = ct * llsy - st * llsx + my + 0.5; j = j + grade; llex = double(eex * j) / total; lley = alpha * llex * llex; Lex = ct * llex + st * lley + mx + 0.5; Ley = ct * lley - st * llex + my + 0.5; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); tst_l(fc); }*/ } Image->Repaint(); Lsx = sx; Lex = ex; Lsy = sy; Ley = ey; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::TstCurveLocate(HDC dc, int x, int y, void *pData) { BEGIN_LOG(""); int i, j, sx, sy, ex, ey; int ssx, eex, ssy, eey, mx, my; int cnt, grade, total, value[2], kind; double xx, yy, llsx, llsy, llex, lley; double tx, ty, a, b, pw, count, c; double lng, gap; double ct, st, ss, theta, alpha, d1, d2, d3; double x1,x2;//°î¼±À» Á¶°¢Á¶°¢ ±×¸®±âÀ§Çؼ­ kind = Tstitch.l[1].kind; if ((kind != 4) && (kind != 5)) { value[0] = Tstitch.l[1].value[kind][0]; value[1] = Tstitch.l[1].value[kind][1]; } else { value[0] = 3; value[1] = 1; } pw = PenManagerForm->Pen->Thick; sx = Tstitch.sx; sy = Tstitch.sy; ex = Tstitch.ex; ey = Tstitch.ey; mx = Csx; my = Csy; d1 = sqrt((sx - mx) * (sx - mx) + (sy - my) * (sy - my)); d2 = sqrt((ex - mx) * (ex - mx) + (ey - my) * (ey - my)); d3 = sqrt((ex - sx) * (ex - sx) + (ey - sy) * (ey - sy)); if (d1 >= d2) { a = d1; b = d2; } else { a = d2; b = d1; } if ((my - sy) * (ex - sx) == (mx - sx) * (ey - sy)) { Tstitch.l[1].sx = sx; Tstitch.l[1].ex = ex; Tstitch.l[1].sy = sy; Tstitch.l[1].ey = ey; calc_stitch_position(ex, ey); TstLineLocate(dc, x, y, NULL); } else if ((sy == ey) && ((mx - sx) == (mx - ex))) { tx = abs(mx - sx); if (tx == 0) tx = 1; ty = sy - my; alpha = ty / (tx * tx); count = fabs(tx) / 160.0 * pw + 2; c = 2.5; Lsx = mx; Lsy = my; xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = mx + xx; Ley = my + yy; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); TstLineLocate(dc, x, y, NULL); Lsx = Lex; Lsy = Ley; count = count + c; xx = xx + count; } if (sx > ex) Lex = sx; else Lex = ex; Ley = sy; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); TstLineLocate(dc, x, y, NULL); count = abs(tx) / 160.0 * pw + 2; Lsx = mx; Lsy = my; xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = mx - xx; Ley = my + yy; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); TstLineLocate(dc, x, y, NULL); Lsx = Lex; Lsy = Ley; count = count + c; xx = xx + count; } if (sx < ex) Lex = sx; else Lex = ex; Ley = sy; Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; calc_stitch_position(Lex, Ley); TstLineLocate(dc, x, y, NULL); } else { TPLayerImage *image=MainImageForm->iMainImage; HPEN hPen, hOldPen; if (image->ZoomIn <= image->ZoomOut) { hPen = CreatePen(PS_SOLID, DrawLocate.szPen*image->ZoomIn/image->ZoomOut+0.5, DrawLocate.clPen); } else { hPen = CreatePen(PS_SOLID, DrawLocate.szPen, DrawLocate.clPen); } // by celberus zoomIn ÇßÀ»¶§ ²ÞƲ°Å¸®´Â ¹®Á¦ ¶§¹®¿¡.. if (hPen == NULL) { END_LOG; return; } hOldPen = (HPEN)SelectObject(dc, hPen); int i; if ((a > b * 1.8) && (d3 < a)) { d1 = sqrt(d1); d2 = sqrt(d2); } tx = (Lex * d1 + Lsx * d2) / (d1 + d2); ty = (Ley * d1 + Lsy * d2) / (d1 + d2); if (tx - mx) ss = (ty - my) / (tx - mx); else ss = 0; theta = M_PI / 2.0 - atan(ss); ct = cos(theta); st = sin(theta); tx = ct * (sx - mx) - st * (sy - my); ty = st * (sx - mx) + ct * (sy - my); alpha = ty / (tx * tx); ssx = 0; ssy = 0; eex = tx; eey = ty; for(i=0;i<=2;i++){ if(Tstitch.l[i].kind==TST_DOT) gap = (Tstitch.l[i].value[Tstitch.l[i].kind][0] + Tstitch.l[i].value[Tstitch.l[i].kind][1]) * pw; else if(Tstitch.l[i].kind==TST_ZZ) gap = (Tstitch.l[i].value[Tstitch.l[i].kind][0]) * pw; else if(Tstitch.l[i].kind==TST_BTN) gap = (Tstitch.l[i].value[Tstitch.l[i].kind][1]) * pw; else if(Tstitch.l[i].kind==TST_XXX) gap = (Tstitch.l[i].value[Tstitch.l[i].kind][0] + Tstitch.l[i].value[Tstitch.l[i].kind][1]) * pw; else if(Tstitch.l[i].kind==TST_NL) gap = pw; else if(Tstitch.l[i].kind==TST_None)continue; if(gap==0)gap=1; reverse = true; x2=0; x1=0; while(abs(x1)iMainImage; ls = PenManagerForm->Pen->Thick >> 1; rs = PenManagerForm->Pen->Thick - ls; rt.left = min(First.x, Second.x) - 1; rt.top = min(First.y, Second.y) - 1; rt.right = max(First.x, Second.x) + 1; rt.bottom = max(First.y, Second.y) + 1; if (Third.x < rt.left) dist.left = rt.left - Third.x; else dist.left = ls; if (Third.x > rt.right) dist.right = Third.x - rt.right; else dist.right = rs; if (Third.y < rt.top) dist.top = rt.top - Third.y; else dist.top = ls; if (Third.y > rt.bottom) dist.bottom = Third.y - rt.bottom; else dist.bottom = rs; rt.left = min(rt.left, Third.x) - 1; rt.top = min(rt.top, Third.y) - 1; rt.right = max(rt.right, Third.x) + 1; rt.bottom = max(rt.bottom, Third.y) + 1; DrawLocate.Src.left = rt.left - dist.left; DrawLocate.Src.top = rt.top - dist.top; DrawLocate.Src.right = rt.right + dist.right; DrawLocate.Src.bottom = rt.bottom + dist.bottom; UnionRect(&DrawLocate.Dst, &DrawLocate.Src, &DrawLocate.rtInvalidate); DrawLocate.szPen = PenManagerForm->Pen->Thick; DrawLocate.clPen = MainImageForm->Palette->Color[PaletteForm->DIB256Palette->ChoiceIndex]; DrawLocate.ptFirst.x = rt.left; DrawLocate.ptFirst.y = rt.top; DrawLocate.ptSecond.x = rt.right; DrawLocate.ptSecond.y = rt.bottom; Image->RectEditPaint(DrawLocate.Dst, TstCurveLocate, NULL); DrawLocate.rtInvalidate = DrawLocate.Src; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::StitchCombo1Change(TObject *Sender) { int StitchCombo = StitchCombo1->ItemIndex; iMainImageChange(); switch (StitchCombo) { case 0 : Tstitch.l[0].kind = TST_DOT; break; case 1 : Tstitch.l[0].kind = TST_ZZ; break; case 2 : Tstitch.l[0].kind = TST_BTN; break; case 3 : Tstitch.l[0].kind = TST_XXX; break; case 4 : Tstitch.l[0].kind = TST_NL; break; case 5 : Tstitch.l[0].kind = TST_None; } picture(0); } //--------------------------------------------------------------------------- void __fastcall TStitchForm::StitchCombo2Change(TObject *Sender) { int StitchCombo = StitchCombo2->ItemIndex; iMainImageChange(); switch (StitchCombo) { case 0 : Tstitch.l[1].kind = TST_DOT; break; case 1 : Tstitch.l[1].kind = TST_ZZ; break; case 2 : Tstitch.l[1].kind = TST_BTN; break; case 3 : Tstitch.l[1].kind = TST_XXX; break; case 4 : Tstitch.l[1].kind = TST_NL; break; case 5 : Tstitch.l[1].kind = TST_None; } picture(1); } //--------------------------------------------------------------------------- void __fastcall TStitchForm::StitchCombo3Change(TObject *Sender) { int StitchCombo = StitchCombo3->ItemIndex; iMainImageChange(); switch (StitchCombo) { case 0 : Tstitch.l[2].kind = TST_DOT; break; case 1 : Tstitch.l[2].kind = TST_ZZ; break; case 2 : Tstitch.l[2].kind = TST_BTN; break; case 3 : Tstitch.l[2].kind = TST_XXX; break; case 4 : Tstitch.l[2].kind = TST_NL; break; case 5 : Tstitch.l[2].kind = TST_None; } picture(2); } //--------------------------------------------------------------------------- void __fastcall TStitchForm::stitch_picture_select() { StitchCombo1->ItemIndex = Tstitch.l[0].kind; StitchCombo2->ItemIndex = Tstitch.l[1].kind; StitchCombo3->ItemIndex = Tstitch.l[2].kind; picture(0); picture(1); picture(2); } //--------------------------------------------------------------------------- void __fastcall TStitchForm::picture(int n) { int i; int w, h; TPanel *pn; TRzSpinEdit *se; TImage *image; if (Tstitch.l[n].kind == TST_DOT) { image = (TImage *)(FindComponent("ImageDot" + String(n + 1))); image->Hint = IDS_DOT; image = (TImage *)(FindComponent("ImageGap" + String(n + 1))); image->Hint = IDS_COMMON_GAP; se = (TRzSpinEdit *)(FindComponent("seDot" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_DOT][0]; se = (TRzSpinEdit *)(FindComponent("seGap" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_DOT][1]; se->Parent->Visible = true; } else if (Tstitch.l[n].kind == TST_ZZ) { image = (TImage *)(FindComponent("ImageDot" + String(n + 1))); image->Hint = IDS_COMMON_HEIGHT; image = (TImage *)(FindComponent("ImageGap" + String(n + 1))); image->Hint = IDS_COMMON_WIDTH; se = (TRzSpinEdit *)(FindComponent("seDot" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_ZZ][0]; se = (TRzSpinEdit *)(FindComponent("seGap" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_ZZ][1]; se->Parent->Visible = true; } else if (Tstitch.l[n].kind == TST_BTN) { image = (TImage *)(FindComponent("ImageDot" + String(n + 1))); image->Hint = IDS_COMMON_SIZE; image = (TImage *)(FindComponent("ImageGap" + String(n + 1))); image->Hint = IDS_COMMON_GAP; se = (TRzSpinEdit *)(FindComponent("seDot" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_BTN][0]; se = (TRzSpinEdit *)(FindComponent("seGap" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_BTN][1]; se->Parent->Visible = true; } else if (Tstitch.l[n].kind == TST_XXX) { image = (TImage *)(FindComponent("ImageDot" + String(n + 1))); image->Hint = IDS_COMMON_SIZE; image = (TImage *)(FindComponent("ImageGap" + String(n + 1))); image->Hint = IDS_COMMON_GAP; se = (TRzSpinEdit *)(FindComponent("seDot" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_XXX][0]; se = (TRzSpinEdit *)(FindComponent("seGap" + String(n + 1))); se->Value = Tstitch.l[n].value[TST_XXX][1]; se->Parent->Visible = true; } else if (Tstitch.l[n].kind == TST_NL) { se = (TRzSpinEdit *)(FindComponent("seDot" + String(n + 1))); se = (TRzSpinEdit *)(FindComponent("seGap" + String(n + 1))); se->Parent->Visible = false; } else if (Tstitch.l[n].kind == TST_None) { se = (TRzSpinEdit *)(FindComponent("seDot" + String(n + 1))); se = (TRzSpinEdit *)(FindComponent("seGap" + String(n + 1))); se->Parent->Visible = false; } } //--------------------------------------------------------------------------- void __fastcall TStitchForm::rzcbDrawtype1CloseUp(TObject *Sender) { // DrawTypeIndex[0] = rzcbDrawtype1->ItemIndex; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::rzcbDrawtype2CloseUp(TObject *Sender) { // DrawTypeIndex[1] = rzcbDrawtype2->ItemIndex; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::FormClose(TObject *Sender, TCloseAction &Action) { BEGIN_LOG(""); HWND hWnd = ((TWinControl *)Owner)->Handle; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::rzcbDrawtype1Change(TObject *Sender) { DrawTypeIndex[0] = rzcbDrawtype1->ItemIndex; } //--------------------------------------------------------------------------- void __fastcall TStitchForm::rzcbDrawtype2Change(TObject *Sender) { DrawTypeIndex[1] = rzcbDrawtype2->ItemIndex; Tstitch.step = 0; // if (DrawTypeIndex[1] == 1) { // if (Tstitch.step == 1) { // Tstitch.sx = Tstitch.l[1].sx; // Tstitch.sy = Tstitch.l[1].sy; // Lsx = Tstitch.sx; Lsy = Tstitch.sy; // } // } } //---------------------------------------------------------------------------