//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "Draw_F.h" #include "MainImage.h" #include "Palette.h" #include "PenManager.h" #include "Undo.h" #include "MainMenu.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_SOLID StringTable[0] #define IDS_DOT StringTable[1] #define IDS_LASTCENTER StringTable[2] #define IDS_RADIUS StringTable[3] #define IDS_AXIS StringTable[4] //--------------------------------------------------------------------------- TDrawForm *DrawForm; //--------------------------------------------------------------------------- __fastcall TDrawForm::TDrawForm(TComponent* Owner) : TForm(Owner) { //============================================================= StringTable.Create(DirectoryBin, Language, "Draw"); SetSmallFont(Font); SetSmallFont(lLineType->Font); SetSmallFont(lFillType->Font); SetSmallFont(lLength->Font); SetSmallFont(lAngle->Font); SetSmallFont(lDotType->Font); SetSmallFont(lDotLength->Font); SetSmallFont(lDotSpace->Font); sbLine->Caption = IDS_COMMON_LINE; sbCurve->Caption = IDS_COMMON_CURVE; sbSquare->Caption = IDS_COMMON_SQUARE; sbRect->Caption = IDS_COMMON_RECTANGLE; sbCircle->Caption = IDS_COMMON_CIRCLE; sbEllip->Caption = IDS_COMMON_ELLIPSE; sbOut->Caption = IDS_COMMON_OUTLINE; lLineType->Caption = IDS_COMMON_CONTINUOUSLINE; lFillType->Caption = AnsiString(IDS_COMMON_FILL) + " : " + AnsiString(IDS_COMMON_BUTTONNO); lLength->Caption = IDS_COMMON_LENGTH; lAngle->Caption = IDS_COMMON_ANGLE; lDotType->Caption = IDS_SOLID; lDotLength->Caption = IDS_COMMON_LENGTH; lDotSpace->Caption = IDS_COMMON_GAP; btnFirst->Caption = IDS_COMMON_FIRSTPOINT; //============================================================= } //--------------------------------------------------------------------------- void __fastcall TDrawForm::FormCreate(TObject *Sender) { // } //--------------------------------------------------------------------------- void __fastcall TDrawForm::lLineTypeClick(TObject *Sender) { iMainImageChange(); if (Item == TD_LINE) { if (Line_type == 0) { Line_type = 1; undos = 0; lLineType->Caption = IDS_COMMON_CONTINUOUSLINE; } else if (Line_type == 1) { step = 0; Line_type = 0; lLineType->Caption = IDS_COMMON_SEPARATELINE; } } else if (Item == TD_CURVE) { if (Curve_type == 0) { Curve_type = 1; undos = 0; lLineType->Caption = IDS_COMMON_CONTINUOUSLINE; } else if (Curve_type == 1) { step = 0; Curve_type = 0; lLineType->Caption = IDS_COMMON_SEPARATELINE; } } view(); } //--------------------------------------------------------------------------- void __fastcall TDrawForm::lFillTypeClick(TObject *Sender) { iMainImageChange(); if (fill_not == 0) { fill_not = 1; lFillType->Caption = AnsiString(IDS_COMMON_FILL) + " : " + AnsiString(IDS_COMMON_BUTTONYES); Ltype[Item].sw = 0; lDotType->Caption = IDS_SOLID; } else if (fill_not == 1) { fill_not = 0; lFillType->Caption = AnsiString(IDS_COMMON_FILL) + " : " + AnsiString(IDS_COMMON_BUTTONNO); } view(); } //--------------------------------------------------------------------------- void __fastcall TDrawForm::FunctionClick(TObject *Sender) { TSpeedButton *s; bool change = false; int prestep, sx, sy; iMainImageChange(); s = (TSpeedButton *)Sender; if (s == sbLine) { if (Item == TD_CURVE && Line_type == 1 && step < 2) { change = true; prestep = step; if (Ltype[TD_CURVE].sw != Ltype[TD_LINE].sw) { if (Ltype[TD_CURVE].sw == 0) { Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; } else if (Ltype[TD_CURVE].sw == 1) { Lsx = Tstitch.l[1].sx; Lsy = Tstitch.l[1].sy; } } } Item = TD_LINE; btnFirst->Caption = IDS_COMMON_FIRSTPOINT; } else if (s == sbCurve) { if (Item == TD_LINE && Line_type == 1) { change = true; prestep = step; if (Ltype[TD_CURVE].sw != Ltype[TD_LINE].sw) { if (Ltype[TD_LINE].sw == 0) { Tstitch.l[1].sx = Lsx; Tstitch.l[1].sy = Lsy; } else if (Ltype[TD_LINE].sw == 1) { Lsx = Tstitch.l[1].sx; Lsy = Tstitch.l[1].sy; } } } Item = TD_CURVE; } else if (s == sbSquare) { Item = TD_SQUR; } else if (s == sbRect) { Item = TD_RECT; } else if (s == sbCircle) { Item = TD_CIRCLE; btnFirst->Caption = IDS_LASTCENTER; } else if (s == sbEllip) { Item = TD_ELLIP; btnFirst->Caption = IDS_LASTCENTER; } else if (s == sbOut) { Item = TD_OUT; } isw = 0; Asw = 0; Lsw = 0; Dsw = 0; Line_type = 1; Curve_type = 1; view(); if (change) step = prestep; } //--------------------------------------------------------------------------- void __fastcall TDrawForm::lDotTypeClick(TObject *Sender) { iMainImageChange(); if (Ltype[Item].sw == 0) { Ltype[Item].sw = 1; lDotType->Caption = IDS_DOT; lFillType->Caption = AnsiString(IDS_COMMON_FILL) + " : " + IDS_COMMON_BUTTONNO; fill_not = 0; } else if (Ltype[Item].sw == 1) { Ltype[Item].sw = 0; lDotType->Caption = IDS_SOLID; } view(); } //--------------------------------------------------------------------------- void __fastcall TDrawForm::EditMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TEdit *s; s = (TEdit *)Sender; if (s == eDotLength) { s->SetFocus(); s->SelectAll(); } else if (s == eDotSpace) { s->SetFocus(); s->SelectAll(); } else { if (Ltype[Item].sw == 0) { if (Item == TD_LINE) { if (step != 0) { s->SetFocus(); s->SelectAll(); } } else if (Item == TD_CURVE) { if (step != 0) { s->SetFocus(); s->SelectAll(); } } else if (Item == TD_SQUR) { if (step == 0) { s->SetFocus(); s->SelectAll(); } } else if (Item == TD_RECT) { if (step == 0) { s->SetFocus(); s->SelectAll(); } } else if (Item == TD_CIRCLE) { if (step == 0) { s->SetFocus(); s->SelectAll(); } } else if (Item == TD_ELLIP) { if (step == 0) { s->SetFocus(); s->SelectAll(); } } } } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::EditKeyPress(TObject *Sender, char &Key) { TEdit *s; if (Key == 13) { iMainImageChange(); s = (TEdit *)Sender; if (s == eLength1) { if (Item != TD_LINE) { Lsx = -1; Lex = -1; Lsy = -1; Ley = -1; Csx = -1; Csy = -1; } isw = 1; Lsw = 1; InputNumber(); } else if (s == eLength2) { if (Item != TD_LINE) { Lsx = -1; Lex = -1; Lsy = -1; Ley = -1; Csx = -1; Csy = -1; } isw = 1; Lsw = 1; InputNumber(); } else if (s == eAngle) { isw = 1; Asw = 1; InputNumber(); } else if (s == eDotLength) { Dsw = 1; InputDotNumber(); } else if (s == eDotSpace) { Dsw = 2; InputDotNumber(); } SetFocus(); Key = 0; } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::btnFirstClick(TObject *Sender) { COLORREF c; c = PaletteForm->DIB256Palette->GetFGCOLORREF(MainImageForm->iMainImage->Bitmap->BitsPerPixel); iMainImageChange(); if (Item == TD_LINE) { if (Ltype[TD_LINE].sw == 0) { Lex = firstln.x; Ley = firstln.y; Line(c); step = 0; } else if (Ltype[TD_LINE].sw == 1) { Tstitch.l[1].ex = firstln.x; Tstitch.l[1].ey = firstln.y; Tstitch.ex = Tstitch.l[1].ex; Tstitch.ey = Tstitch.l[1].ey; dot_line(pmCopy, 1, Ltype[TD_LINE].value, c); step = 0; } } else if (Item == TD_CIRCLE) { Csx = cirlast.x; Csy = cirlast.y; Lsx = Csx; Lsy = Csy; Lex = Lsx; Ley = Lsy; isw = 0; step = 1; } else if (Item == TD_ELLIP) { Csx = elliplast.x; Csy = elliplast.y; Lsx = Csx; Lsy = Csy; Lex = Lsx; Ley = Lsy; isw = 0; step = 1; } } //--------------------------------------------------------------------------- // Private Function //--------------------------------------------------------------------------- void __fastcall TDrawForm::InputDotNumber(void) { if (Dsw == 1) { Ltype[Item].value[0] = StrToInt(eDotLength->Text); Dsw = 0; } else if (Dsw == 2) { Ltype[Item].value[1] = StrToInt(eDotSpace->Text); Dsw = 0; } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::InputNumber(void) { AnsiString s; int pw, x, y, ang; double len; TPItemImage *Image = MainImageForm->iMainImage; pw = PenManagerForm->Pen->Thick; if (Item == TD_CIRCLE) { s = eLength1->Text; if (isw == 1) { switch (MainImageForm->CurrentUnit) { case uInch : if (StrToFloat(s) * MainImageForm->CanvasInfor.DotsPerInch + 0.5 > pw) { Radius = StrToFloat(s) * MainImageForm->CanvasInfor.DotsPerInch + 0.5; } break; case uCm : if (StrToFloat(s) / 2.54 * MainImageForm->CanvasInfor.DotsPerInch + 0.5 > pw) { Radius = StrToFloat(s) / 2.54 * MainImageForm->CanvasInfor.DotsPerInch + 0.5; } break; default : if (StrToInt(s) > (pw)) { Radius = StrToInt(s); } break; } isw = 2; if (Radius > sqrt(Image->Bitmap->Width * Image->Bitmap->Width + Image->Bitmap->Height * Image->Bitmap->Height) / 2.0) { Radius = sqrt(Image->Bitmap->Width * Image->Bitmap->Width + Image->Bitmap->Height * Image->Bitmap->Height) / 2.0; } } } else if (Item == TD_ELLIP) { if (isw == 1) { switch (MainImageForm->CurrentUnit) { case uDot : if (StrToInt(eLength1->Text) > pw / 2.0) Ell_rx = StrToInt(eLength1->Text); if (StrToInt(eLength2->Text) > pw / 2.0) Ell_ry = StrToInt(eLength2->Text); break; case uInch : if (StrToFloat(eLength1->Text) * MainImageForm->CanvasInfor.DotsPerInch + 0.5 > pw / 2.0) { Ell_rx = StrToFloat(eLength1->Text) * MainImageForm->CanvasInfor.DotsPerInch + 0.5; } if (StrToFloat(eLength2->Text) * MainImageForm->CanvasInfor.DotsPerInch + 0.5 > pw / 2.0) { Ell_ry = StrToFloat(eLength2->Text) * MainImageForm->CanvasInfor.DotsPerInch + 0.5; } break; case uCm : if (StrToFloat(eLength1->Text) * MainImageForm->CanvasInfor.DotsPerInch / 2.54 + 0.5 > pw / 2.0) { Ell_rx = StrToFloat(eLength1->Text) * MainImageForm->CanvasInfor.DotsPerInch / 2.54 + 0.5; } if (StrToFloat(eLength2->Text) * MainImageForm->CanvasInfor.DotsPerInch / 2.54 + 0.5 > pw / 2.0) { Ell_ry = StrToFloat(eLength2->Text) * MainImageForm->CanvasInfor.DotsPerInch / 2.54 + 0.5; } } isw = 2; x = Image->Bitmap->Width * Image->Bitmap->Width; y = Image->Bitmap->Height * Image->Bitmap->Height; if (Ell_rx > sqrt(x + y)) { Ell_rx = sqrt(x + y); } if (Ell_ry > sqrt(x + y)) { Ell_ry = sqrt(x + y); } } } else if (Item == TD_SQUR) { if (isw == 1) { switch (MainImageForm->CurrentUnit) { case uDot : if (StrToInt(eLength1->Text) > pw) Sqr_l = StrToInt(eLength1->Text); break; case uInch : if (StrToFloat(eLength1->Text) * MainImageForm->CanvasInfor.DotsPerInch + 0.5 > pw) { Sqr_l = StrToFloat(eLength1->Text) * MainImageForm->CanvasInfor.DotsPerInch + 0.5; } break; case uCm : if (StrToFloat(eLength1->Text) / 2.54 * MainImageForm->CanvasInfor.DotsPerInch + 0.5 > pw) { Sqr_l = StrToFloat(eLength1->Text) / 2.54 * MainImageForm->CanvasInfor.DotsPerInch + 0.5; } } isw = 2; if (Sqr_l > Image->Bitmap->Width) Sqr_l = Image->Bitmap->Width; if (Sqr_l > Image->Bitmap->Height) Sqr_l = Image->Bitmap->Height; } } else if (Item == TD_RECT) { if (isw == 1) { switch (MainImageForm->CurrentUnit) { case uDot : if (StrToInt(eLength1->Text) > pw) Rec_lx = StrToInt(eLength1->Text); if (StrToInt(eLength2->Text) > pw) Rec_ly = StrToInt(eLength2->Text); break; case uInch : if (StrToFloat(eLength1->Text) * MainImageForm->CanvasInfor.DotsPerInch + 0.5 > pw) { Rec_lx = StrToFloat(eLength1->Text) * MainImageForm->CanvasInfor.DotsPerInch + 0.5; } if (StrToFloat(eLength2->Text) * MainImageForm->CanvasInfor.DotsPerInch + 0.5 > pw) { Rec_ly = StrToFloat(eLength2->Text) * MainImageForm->CanvasInfor.DotsPerInch + 0.5; } break; case uCm : if (StrToFloat(eLength1->Text) / 2.54 * MainImageForm->CanvasInfor.DotsPerInch + 0.5 > pw) { Rec_lx = StrToFloat(eLength1->Text) / 2.54 * MainImageForm->CanvasInfor.DotsPerInch + 0.5; } if (StrToFloat(eLength2->Text) / 2.54 * MainImageForm->CanvasInfor.DotsPerInch + 0.5 > pw) { Rec_ly = StrToFloat(eLength2->Text) / 2.54 * MainImageForm->CanvasInfor.DotsPerInch + 0.5; } } isw = 2; if (Rec_lx > Image->Bitmap->Width) Rec_lx = Image->Bitmap->Width; if (Rec_ly > Image->Bitmap->Height) Rec_ly = Image->Bitmap->Height; } } else if (Item == TD_LINE) { if (Asw == 1) { ang = StrToInt(eAngle->Text); ang %= 90; Line_angle = ang; Asw = 2; } if (Lsw == 1) { len = StrToFloat(eLength1->Text); switch (MainImageForm->CurrentUnit) { case uDot : Line_len = len - pw; break; case uInch : Line_len = len * MainImageForm->CanvasInfor.DotsPerInch - pw; break; case uCm : Line_len = len * MainImageForm->CanvasInfor.DotsPerInch / 2.54 - pw ; } if (Line_len >= 0) { if (Line_len > sqrt(Image->Bitmap->Width * Image->Bitmap->Width + Image->Bitmap->Height * Image->Bitmap->Height)) { Line_len = sqrt(Image->Bitmap->Width * Image->Bitmap->Width + Image->Bitmap->Height * Image->Bitmap->Height); } Lsw = 2; } else Lsw = 0; } } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::Line(COLORREF fc) { double p; int lx, ly, dx, dy; TPItemImage *Image = MainImageForm->iMainImage; MainImageForm->line_pen(Lsx, Lsy, Lex, Ley, fc); if ((Item == TD_LINE) && (Ltype[Item].sw == 0)) { Image->Repaint(); dx = Lex - Lsx; dy = Ley - Lsy; if (dy < 0) { p = (atan2((double)dy, (double)dx) + 2 * M_PI) * 180.0 / M_PI; } else { if ((dx == 0) && (dy == 0)) p = 0; else p = atan2((double)dy, (double)dx) * 180.0 / M_PI; } eAngle->Text = Format("%3.0f", OPENARRAY(TVarRec, (p))); // lx = abs(dx) + 1; ly = abs(dy) + 1; lx = abs(dx); ly = abs(dy); p = sqrt(lx * lx + ly * ly) + PenManagerForm->Pen->Thick; switch (MainImageForm->CurrentUnit) { case uDot : eLength1->Text = p; break; case uInch: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, (p / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, (p / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); } } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::outline_pen(TPBitmap *op, int sx, int sy) { int i, j, x, y, r, pw; Byte c; Byte *OP, *BP; TPItemImage *Image = MainImageForm->iMainImage; c = PaletteForm->DIB256Palette->ChoiceIndex; pw = PenManagerForm->Pen->Thick; x = sx - 40; y = sy - 40; r = pw - 1; for (i = 40 - r; i <= 40 + r; i++) { if ((y + i >= 0) && (y + i < Image->Bitmap->Height)) { BP = Image->Bitmap->GetScanLineN(y + i, 1); OP = op->ScanLine(i); for (j = 40 - r; j <= 40 + r; j++) { if ((x + j >= 0) && (x + j < Image->Bitmap->Width)) { if ((OP[j] == 0xFF) && ((BP[x + j] == 0xFF) || (BP[x + j] == 0xFE))) { BP[x + j] = c; } } } Image->Bitmap->PutScanLineN(y + i, 1); } } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::outlinemask_pen(TPBitmap *op, int sx, int sy) { int i, j, x, y, r, pw; Byte *OP, *BP, *MP; TPItemImage *Image = MainImageForm->iMainImage; pw = PenManagerForm->Pen->Thick; x = sx - 40; y = sy - 40; r = pw - 1; for (i = 40 - r; i <= 40 + r; i++) { if ((y + i >= 0) && (y + i < Image->Bitmap->Height)) { BP = Image->Bitmap->GetScanLineN(y + i, 1); MP = Image->Mask->GetScanLineN(y + i, 1); OP = op->ScanLine(i); for (j = 40 - r; j <= 40 + r; j++) { if ((x + j >= 0) && (x + j < Image->Bitmap->Width)) { if ((OP[j] == 0xFF) && ((BP[x + j] == 0xFF) || (BP[x + j] == 0xFE))) { MP[x + j] = MainImageForm->MaskPixel; } } } Image->Mask->PutScanLineN(y + i, 1); } } } //--------------------------------------------------------------------------- bool __fastcall TDrawForm::OutRead(Byte *p, int x) { return *(p + x) == (Byte)OutColor; } //---------------------------------------------------------------------------- void __fastcall TDrawForm::OutSave(Byte *p, int x) { *(p + x) = 0xFF; } //--------------------------------------------------------------------------- bool __fastcall TDrawForm::OutRead24(Byte *p, int x) { COLORREF c; p += 3*x; GetPixel24(p, c); return c == OutColor; } //--------------------------------------------------------------------------- void __fastcall TDrawForm::outline_pen_24(TPBitmap *op, TPBitmap *mask, int sx, int sy, COLORREF dc) { int i, j, x, y, r, pw; Byte *OP, *MP, *BBP; TPItemImage *Image = MainImageForm->iMainImage; pw = PenManagerForm->Pen->Thick; x = sx - 40; y = sy - 40; r = pw - 1; for (i = 40 - r; i <= 40 + r; i++) { if ((y + i >= 0) && (y + i < Image->Bitmap->Height)) { BBP = Image->Bitmap->GetScanLineN(y + i, 1) + 3*(x+(40-r)); MP = mask->ScanLine(y + i); OP = op->ScanLine(i); for (j = 40 - r; j <= 40 + r; j++, BBP += 3) { if ((x + j >= 0) && (x + j < Image->Bitmap->Width)) { if ((OP[j] == 0xFF) && (*(MP + ((x+j) >> 3)) & (0x80 >> ((x+j) & 7)))) { SetPixel24(BBP, dc); } } } Image->Bitmap->PutScanLineN(y + i, 1); } } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::outlinemask_pen_24(TPBitmap *op, TPBitmap *mask, int sx, int sy) { int i, j, x, y, r, pw; Byte *OP, *MP, *BBP; TPItemImage *Image = MainImageForm->iMainImage; pw = PenManagerForm->Pen->Thick; x = sx - 40; y = sy - 40; r = pw - 1; for (i = 40 - r; i <= 40 + r; i++) { if ((y + i >= 0) && (y + i < Image->Bitmap->Height)) { BBP = Image->Mask->GetScanLineN(y + i, 1); MP = mask->ScanLine(y + i); OP = op->ScanLine(i); for (j = 40 - r; j <= 40 + r; j++) { if ((x + j >= 0) && (x + j < Image->Bitmap->Width)) { if ((OP[j] == 0xFF) && (*(MP + ((x+j) >> 3)) & (0x80 >> ((x+j) & 7)))) { BBP[(x + j) >> 3] |= MainImageForm->MaskPixel >> ((x + j) & 7); } } } Image->Mask->PutScanLineN(y + i, 1); } } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::outlinemaskdelete_pen_24(TPBitmap *op, TPBitmap *mask, int sx, int sy) { int i, j, x, y, r, pw; Byte *OP, *MP, *BBP; TPItemImage *Image = MainImageForm->iMainImage; pw = PenManagerForm->Pen->Thick; x = sx - 40; y = sy - 40; r = pw - 1; for (i = 40 - r; i <= 40 + r; i++) { if ((y + i >= 0) && (y + i < Image->Bitmap->Height)) { BBP = Image->Mask->GetScanLineN(y + i, 1); MP = mask->ScanLine(y + i); OP = op->ScanLine(i); for (j = 40 - r; j <= 40 + r; j++) { if ((x + j >= 0) && (x + j < Image->Bitmap->Width)) { if ((OP[j] == 0xFF) && (*(MP + ((x+j) >> 3)) & (0x80 >> ((x+j) & 7)))) { BBP[(x + j) >> 3] &= ~(0x80 >> ((x + j) & 7)); } } } Image->Mask->PutScanLineN(y + i, 1); } } } //---------------------------------------------------------------------------- bool __fastcall TDrawForm::outline_24(int XD, int YD) { int x, y, sx, sy, ex, ey, a, pw, r1, tx, ty, wid, hei, code, i, ec; Extended sqr_x, sqr_y, r; TPoint max, min, size; TPoint *sp = 0, *now = 0; TList *stack = NULL; TCursor OldCursor; COLORREF crrf; Byte *OP = 0, *BP = 0, *NBP = 0, *PBP = 0, *MP = 0, mm; TRect rect; TPBitmap *outpen = NULL, *MaskFF = NULL, *MaskFE = NULL, *MaskFD = NULL; TPItemImage *Image = MainImageForm->iMainImage; // -1- fill¿µ¿ª ±¸Çϱâ if ((MaskFF = new TPBitmap) == NULL) { ec = EC_MEMORY_LACK; goto fail; } OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; fillstart = Point(XD, YD); OutColor = Image->Bitmap->GetPixelColor(XD, YD); size = Point(Image->Bitmap->Width, Image->Bitmap->Height); if (!(Image->Bitmap->FloodFillMask(fillstart, OutRead24, NULL, rect, MaskFF))) { ec = EC_MEMORY_LACK; goto fail; } min.x = rect.Left; max.x = rect.Right; min.y = rect.Top; max.y = rect.Bottom; if (min.x > 0) sx = min.x; else sx = 1; if (max.x < size.x - 1) ex = max.x; else ex = size.x - 2; if (min.y > 0) sy = min.y; else sy = 1; if (max.y < size.y - 1) ey = max.y; else ey = size.y - 2; // -2- MaskFF¿¡¼­ color °æ°è¼± MaskFE ¸¸µé±â. wid = ex - sx + 3; hei = ey - sy + 3; if ((MaskFE = new TPBitmap) == NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!(MaskFE->Create(wid, hei, 1))) { ec = EC_MEMORY_LACK; goto fail; } if ((MaskFD = new TPBitmap) == NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!(MaskFD->Create(wid, hei, 1))) { ec = EC_MEMORY_LACK; goto fail; } if (MaskFF->Lock() == NULL) { ec = EC_MEMORY_LACK; goto fail; } if (MaskFE->Lock() == NULL) { ec = EC_MEMORY_LACK; goto fail; } for (y = sy; y <= ey; y++) { BP = MaskFF->ScanLine(y); NBP = MaskFF->ScanLine(y - 1); PBP = MaskFF->ScanLine(y + 1); MP = MaskFE->ScanLine(y - sy); mm = 0x80; *MP = 0; for (x = sx; x <= ex; x++) { if (*(BP + (x >> 3)) & (0x80 >> (x & 7))) { if (!(*(BP + ((x-1) >> 3)) & (0x80 >> ((x-1) & 7))) || !(*(BP + ((x+1) >> 3)) & (0x80 >> ((x+1) & 7))) || !(*(NBP + (x >> 3)) & (0x80 >> (x & 7))) || !(*(PBP + (x >> 3)) & (0x80 >> (x & 7)))) { *MP |= mm; } } if (mm == 1) { MP++; mm = 0x80; *MP = 0; } else mm >>= 1; } } MaskFF->Unlock(); // -3- Search the nearest point from StartPoint. tx = fillstart.x - sx; ty = fillstart.y - sy; code = 1; r = 0.0; while (code == 1) { for (i = 0; i <= 0.75 * r; i++) { x = tx + i; sqr_x = (r * r) - ((tx - x) * (tx - x)); y = ty + sqrt(sqr_x); if ((x >= 0) && (x < wid) && (y >= 0) && (y < hei)) { BP = MaskFE->ScanLine(y); if (*(BP + (x >> 3)) & (0x80 >> (x & 7))) { code = 0; break; } } x = tx - i; if ((x >= 0) && (x < wid) && (y >= 0) && (y < hei)) { BP = MaskFE->ScanLine(y); if (*(BP + (x >> 3)) & (0x80 >> (x & 7))) { code = 0; break; } } x = tx + i; y = ty - sqrt(sqr_x); if ((x >= 0) && (x < wid) && (y >= 0) && (y < hei)) { BP = MaskFE->ScanLine(y); if (*(BP + (x >> 3)) & (0x80 >> (x & 7))) { code = 0; break; } } x = tx - i; if ((x >= 0) && (x < wid) && (y >= 0) && (y < hei)) { BP = MaskFE->ScanLine(y); if (*(BP + (x >> 3)) & (0x80 >> (x & 7))) { code = 0; break; } } y = ty + i; sqr_y = (r * r) - ((ty - y) * (ty - y)); x = tx + sqrt(sqr_y); if ((x >= 0) && (x < wid) && (y >= 0) && (y < hei)) { BP = MaskFE->ScanLine(y); if (*(BP + (x >> 3)) & (0x80 >> (x & 7))) { code = 0; break; } } y = ty - i; if ((x >= 0) && (x < wid) && (y >= 0) && (y < hei)) { BP = MaskFE->ScanLine(y); if (*(BP + (x >> 3)) & (0x80 >> (x & 7))) { code = 0; break; } } y = ty + i; x = tx - sqrt(sqr_y); if ((x >= 0) && (x < wid) && (y >= 0) && (y < hei)) { BP = MaskFE->ScanLine(y); if (*(BP + (x >> 3)) & (0x80 >> (x & 7))) { code = 0; break; } } y = ty - i; if ((x>=0) && (x < wid) && (y >= 0) && (y < hei)) { BP = MaskFE->ScanLine(y); if (*(BP + (x >> 3)) & (0x80 >> (x & 7))) { code = 0; break; } } if ((r > wid) && (r > hei)) { ec = EC_NO_TARGET; goto fail; } r = r + 1; } } // -4- MaskFE¿¡¼­ Ãֿܰû¼± ÃßÃâµÈ MaskFD ¸¸µé±â. if (MaskFD->Lock() == NULL) { ec = EC_MEMORY_LACK; goto fail; } MaskFD->Fill(0); now = new TPoint; now->x = x; now->y = y; MP = MaskFD->ScanLine(now->y); *(MP + (now->x >> 3)) |= (0x80 >> (now->x & 7)); if ((stack = new TList) == NULL) { ec = EC_MEMORY_LACK; goto fail; } stack->Add(now); while (stack->Count) { sp = (TPoint *)(stack->Last()); stack->Remove(sp); sx = sp->x; sy = sp->y; if (sp) delete sp; sp = 0; for (y = sy-1; y <= sy+1; y++) { if (y >=0 && y < hei) { BP = MaskFE->ScanLine(y); MP = MaskFD->ScanLine(y); for (x = sx-1; x <= sx+1; x++) { if (x >=0 && x < wid) { now = new TPoint; if (*(BP + (x >> 3)) & (0x80 >> (x & 7))) { *(BP + (x >> 3)) &= ~(0x80 >> (x & 7)); *(MP + (x >> 3)) |= (0x80 >> (x & 7)); now->x = x; now->y = y; stack->Add(now); } else { if (now) delete now; now = 0; } } } } } } if (now) delete now; now =0; while (stack->Count) { sp = (TPoint *)(stack->Last()); stack->Remove(sp); if (sp) delete sp; sp = 0; } if (stack) delete stack; stack = NULL; MaskFD->Unlock(); if (MaskFE) delete MaskFE; MaskFE = NULL; // -5- PenMask ¸¸µé±â. if ((outpen = new TPBitmap) == NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!(outpen->Create(81, 81, 8))) { ec = EC_MEMORY_LACK; goto fail; } if (outpen->Lock() == NULL) { ec = EC_MEMORY_LACK; goto fail; } pw = (PenManagerForm->Pen->Thick - 1) * 2 + 1; for (y = 0; y <= 80; y++) { OP = outpen->ScanLine(y); for (x = 0; x <= 80; x++) { OP[x] = 0x00; } } if (pw == 1) { OP = outpen->ScanLine(40); OP[40] = 0xFF; } else { if (PenManagerForm->Pen->Shape == 0) { r = pw / 2.0; r1 = r; for (y = 0; y <= r1; y++) { PBP = outpen->ScanLine(40 + y); NBP = outpen->ScanLine(40 - y); x = sqrt(r * r - y * y); for (a = 40 - x; a <= 40 + x; a++) { PBP[a] = 0xFF; NBP[a] = 0xFF; } } } else { r1 = 40 - pw / 2.0; for (y = r1; y <= r1 + pw - 1; y++) { OP = outpen->ScanLine(y); for (x = r1; x <= r1 + pw - 1; x++) { OP[x] = 0xFF; } } } } // -6- Image¿¡ OutLine ±¸ÇöÇϱâ. if (MaskFD->Lock() == NULL) { ec = EC_MEMORY_LACK; goto fail; } if (MaskFF->Lock() == NULL) { ec = EC_MEMORY_LACK; goto fail; } if (PenManagerForm->sbMask->Down) { if (!(Image->Mask->StartScanLineN(2))) { ec = EC_MEMORY_LACK; goto fail; } if (PenManagerForm->chDelete->Checked) { for (y = min.y; y < max.y; y++) { PBP = Image->Mask->GetScanLine(y); MP = MaskFD->ScanLine(y - min.y); mm = 0x80; for (x = min.x; x < max.x; x++) { if (*MP & mm) { PBP[x >> 3] &= ~(0x80 >> (x & 7)); outlinemaskdelete_pen_24(outpen, MaskFF, x, y); } if (mm == 1) { MP++; mm = 0x80; } else mm >>=1; } Image->Mask->PutScanLine(y); } } else { for (y = min.y; y < max.y; y++) { PBP = Image->Mask->GetScanLine(y); MP = MaskFD->ScanLine(y - min.y); mm = 0x80; for (x = min.x; x < max.x; x++) { if (*MP & mm) { PBP[x >> 3] |= MainImageForm->MaskPixel >> (x & 7); outlinemask_pen_24(outpen, MaskFF, x, y); } if (mm == 1) { MP++; mm = 0x80; } else mm >>=1; } Image->Mask->PutScanLine(y); } } Image->Mask->StopScanLine(); } else { if (!(Image->Bitmap->StartScanLineN(2))) { ec = EC_MEMORY_LACK; goto fail; } crrf = PaletteForm->DIB256Palette->GetFGCOLORREF(24); for (y = min.y; y < max.y; y++) { PBP = Image->Bitmap->GetScanLine(y) + 3*min.x; MP = MaskFD->ScanLine(y - min.y); mm = 0x80; for (x = min.x; x < max.x; x++, PBP += 3) { if (*MP & mm) { SetPixel24(PBP, crrf); outline_pen_24(outpen, MaskFF, x, y, crrf); } if (mm == 1) { MP++; mm = 0x80; } else mm >>=1; } Image->Bitmap->PutScanLine(y); } Image->Bitmap->StopScanLine(); } if (outpen) delete outpen; if (MaskFD) delete MaskFD; if (MaskFF) delete MaskFF; ::RepaintImage(); Screen->Cursor = OldCursor; return true; fail: if (outpen) delete outpen; if (MaskFE) delete MaskFE; if (MaskFD) delete MaskFD; if (MaskFF) delete MaskFF; Undo->Read(); Screen->Cursor = OldCursor; EXCEPTION_MESSAGE_OK(ec); return false; } //--------------------------------------------------------------------------- void __fastcall TDrawForm::outline(int XD, int YD) { RGBQUAD rgb[256]; int x, y, sx, sy, ex, ey, i, code, a, pw, r1, ec; Extended sqr_x, sqr_y, r; TPoint max, min, size; TPoint *sp = 0, *now = 0; TList *stack = NULL; TUndoData *undo = NULL; TCursor OldCursor; TPBitmap *outpen = NULL; Byte c; Byte *OP = 0, *BP = 0, *NBP = 0, *PBP = 0; TRect rect; TPItemImage *Image = MainImageForm->iMainImage; OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; fillstart = Point(XD, YD); OutColor = Image->Bitmap->GetPixelColor(XD, YD); size = Point(Image->Bitmap->Width, Image->Bitmap->Height); Image->Bitmap->FloodFill(fillstart, OutRead, OutSave, rect); min.x = rect.Left; max.x = rect.Right; min.y = rect.Top; max.y = rect.Bottom; if (min.x > 0) sx = min.x; else sx = 1; if (max.x < size.x - 1) ex = max.x; else ex = size.x - 2; if (min.y > 0) sy = min.y; else sy = 1; if (max.y < size.y - 1) ey = max.y; else ey = size.y - 2; MainImageForm->Palette->ToRGBQUAD(rgb, 256); Image->Bitmap->PutColors(0, 256, rgb); if (!(Image->Bitmap->StartScanLineN(3))) { ec = EC_MEMORY_LACK; goto fail; } for (y = sy; y <= ey; y++) { BP = Image->Bitmap->GetScanLine(y); NBP = Image->Bitmap->GetScanLineN(y - 1, 1); PBP = Image->Bitmap->GetScanLineN(y + 1, 2); for (x = sx; x <= ex; x++) { if (BP[x] == 0xFF) { if (((BP[x - 1] & 0xFE) != 0xFE) || ((BP[x + 1] & 0xFE) != 0xFE) || ((NBP[x] & 0xFE) != 0xFE) || ((PBP[x] & 0xFE) != 0xFE)) { BP[x] = 0xFE; } } } Image->Bitmap->PutScanLine(y); } x = fillstart.x; y = fillstart.y; code = 1; r = 0.0; while (code == 1) { for (i = 0; i <= 0.75 * r; i++) { x = fillstart.x + i; sqr_x = (r * r) - ((fillstart.x - x) * (fillstart.x - x)); y = fillstart.y + sqrt(sqr_x); if ((x >= 0) && (x < size.x) && (y >= 0) && (y < size.y)) { BP = Image->Bitmap->GetScanLine(y); if (BP[x] == 0xFE) { code = 0; break; } } x = fillstart.x - i; if ((x >= 0) && (x < size.x) && (y >= 0) && (y < size.y)) { BP = Image->Bitmap->GetScanLine(y); if (BP[x] == 0xFE) { code = 0; break; } } x = fillstart.x + i; y = fillstart.y - sqrt(sqr_x); if ((x >= 0) && (x < size.x) && (y >= 0) && (y < size.y)) { BP = Image->Bitmap->GetScanLine(y); if (BP[x] == 0xFE) { code = 0; break; } } x = fillstart.x - i; if ((x >= 0) && (x < size.x) && (y >= 0) && (y < size.y)) { BP = Image->Bitmap->GetScanLine(y); if (BP[x] == 0xFE) { code = 0; break; } } y = fillstart.y + i; sqr_y = (r * r) - ((fillstart.y - y) * (fillstart.y - y)); x = fillstart.x + sqrt(sqr_y); if ((x >= 0) && (x < size.x) && (y >= 0) && (y < size.y)) { BP = Image->Bitmap->GetScanLine(y); if (BP[x] == 0xFE) { code = 0; break; } } y = fillstart.y - i; if ((x >= 0) && (x < size.x) && (y >= 0) && (y < size.y)) { BP = Image->Bitmap->GetScanLine(y); if (BP[x] == 0xFE) { code = 0; break; } } y = fillstart.y + i; x = fillstart.x - sqrt(sqr_y); if ((x >= 0) && (x < size.x) && (y >= 0) && (y < size.y)) { BP = Image->Bitmap->GetScanLine(y); if (BP[x] == 0xFE) { code = 0; break; } } y = fillstart.y - i; if ((x>=0) && (x < size.x) && (y >= 0) && (y < size.y)) { BP = Image->Bitmap->GetScanLine(y); if (BP[x] == 0xFE) { code = 0; break; } } if ((r > size.x) && (r > size.y)) { ec = EC_NO_TARGET; goto fail; } r = r + 1; } } now = new TPoint; now->x = x; now->y = y; BP = Image->Bitmap->GetScanLine(now->y); BP[now->x] = 0xFD; Image->Bitmap->PutScanLine(now->y); if ((stack = new TList) == NULL){ec = EC_MEMORY_LACK; goto fail; } stack->Add(now); while (stack->Count) { sp = (TPoint *)(stack->Last()); stack->Remove(sp); sx = sp->x; sy = sp->y; if (sp) delete sp; sp = 0; now = new TPoint; now->x = sx + 1; now->y = sy; BP = Image->Bitmap->GetScanLine(now->y); if (BP[now->x] == 0xFE) { BP[now->x] = 0xFD; Image->Bitmap->PutScanLine(now->y); stack->Add(now); } else { if (now) delete now; now = 0; } now = new TPoint; now->x = sx + 1; now->y = sy + 1; BP = Image->Bitmap->GetScanLine(now->y); if (BP[now->x] == 0xFE) { BP[now->x] = 0xFD; Image->Bitmap->PutScanLine(now->y); stack->Add(now); } else { if (now) delete now; now = 0; } now = new TPoint; now->x = sx; now->y = sy + 1; BP = Image->Bitmap->GetScanLine(now->y); if (BP[now->x] == 0xFE) { BP[now->x] = 0xFD; Image->Bitmap->PutScanLine(now->y); stack->Add(now); } else { if (now) delete now; now = 0; } now = new TPoint; now->x = sx - 1; now->y = sy + 1; BP = Image->Bitmap->GetScanLine(now->y); if (BP[now->x] == 0xFE) { BP[now->x] = 0xFD; Image->Bitmap->PutScanLine(now->y); stack->Add(now); } else { if (now) delete now; now = 0; } now = new TPoint; now->x = sx - 1; now->y = sy; BP = Image->Bitmap->GetScanLine(now->y); if (BP[now->x] == 0xFE) { BP[now->x] = 0xFD; Image->Bitmap->PutScanLine(now->y); stack->Add(now); } else { if (now) delete now; now = 0; } now = new TPoint; now->x = sx - 1; now->y = sy - 1; BP = Image->Bitmap->GetScanLine(now->y); if (BP[now->x] == 0xFE) { BP[now->x] = 0xFD; Image->Bitmap->PutScanLine(now->y); stack->Add(now); } else { if (now) delete now; now = 0; } now = new TPoint; now->x = sx; now->y = sy - 1; BP = Image->Bitmap->GetScanLine(now->y); if (BP[now->x] == 0xFE) { BP[now->x] = 0xFD; Image->Bitmap->PutScanLine(now->y); stack->Add(now); } else { if (now) delete now; now = 0; } now = new TPoint; now->x = sx + 1; now->y = sy - 1; BP = Image->Bitmap->GetScanLine(now->y); if (BP[now->x] == 0xFE) { BP[now->x] = 0xFD; Image->Bitmap->PutScanLine(now->y); stack->Add(now); } else { if (now) delete now; now = 0; } } if (now) delete now; now = 0; while (stack->Count) { sp = (TPoint *)(stack->Last()); stack->Remove(sp); if (sp) delete sp; sp = 0; } if (stack) delete stack; stack = NULL; if ((outpen = new TPBitmap) == NULL) {ec = EC_MEMORY_LACK; goto fail; } if (!(outpen->Create(81, 81, 8))) {ec = EC_MEMORY_LACK; goto fail; } if (outpen->Lock() == NULL) {ec = EC_MEMORY_LACK; goto fail; } pw = (PenManagerForm->Pen->Thick - 1) * 2 + 1; for (y = 0; y <= 80; y++) { OP = outpen->ScanLine(y); for (x = 0; x <= 80; x++) { OP[x] = 0x00; } } if (pw == 1) { OP = outpen->ScanLine(40); OP[40] = 0xFF; } else { if (PenManagerForm->Pen->Shape == 0) { r = pw / 2.0; r1 = r; for (y = 0; y <= r1; y++) { PBP = outpen->ScanLine(40 + y); NBP = outpen->ScanLine(40 - y); x = sqrt(r * r - y * y); for (a = 40 - x; a <= 40 + x; a++) { PBP[a] = 0xFF; NBP[a] = 0xFF; } } } else { r1 = 40 - pw / 2.0; for (y = r1; y <= r1 + pw - 1; y++) { OP = outpen->ScanLine(y); for (x = r1; x <= r1 + pw - 1; x++) { OP[x] = 0xFF; } } } } if (PenManagerForm->sbMask->Down) { Byte *MP = 0; if (!(Image->Mask->StartScanLineN(2))) { ec = EC_MEMORY_LACK; goto fail; } for (y = min.y; y < max.y; y++) { BP = Image->Bitmap->GetScanLine(y); MP = Image->Mask->GetScanLine(y); for (x = min.x; x < max.x; x++) { if (BP[x] == 0xFD) { MP[x] = MainImageForm->MaskPixel; outlinemask_pen(outpen, x, y); } } Image->Mask->PutScanLine(y); } if (outpen) delete outpen; outpen = NULL; if ((undo = Undo->Last) == NULL) { ec = EC_UNDO_NONE; goto fail; } if (!(undo->Bitmap->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } for (y = min.y; y < max.y; y++) { BP = Image->Bitmap->GetScanLine(y); OP = undo->Bitmap->GetScanLine(y); for (x = min.x; x < max.x; x++) { if ((BP[x] == 0xFF) || (BP[x] == 0xFE) || (BP[x] == 0xFD)) { BP[x] = OP[x]; } } Image->Bitmap->PutScanLine(y); } undo->Bitmap->StopScanLine(); Image->Mask->StopScanLine(); } else { c = PaletteForm->DIB256Palette->ChoiceIndex; for (y = min.y; y < max.y; y++) { BP = Image->Bitmap->GetScanLine(y); for (x = min.x; x < max.x; x++) { if (BP[x] == 0xFD) { BP[x] = c; outline_pen(outpen, x, y); } } Image->Bitmap->PutScanLine(y); } if (outpen) delete outpen; outpen = NULL; if ((undo = Undo->Last) == NULL) { ec = EC_UNDO_NONE; goto fail; } if (!(undo->Bitmap->StartScanLine())) { ec = EC_MEMORY_LACK; goto fail; } for (y = min.y; y < max.y; y++) { BP = Image->Bitmap->GetScanLine(y); OP = undo->Bitmap->GetScanLine(y); for (x = min.x; x < max.x; x++) { if ((BP[x] == 0xFF) || (BP[x] == 0xFE)) { BP[x] = OP[x]; } } Image->Bitmap->PutScanLine(y); } undo->Bitmap->StopScanLine(); } ::RepaintImage(); Image->Bitmap->StopScanLine(); Screen->Cursor = OldCursor; return; fail: if (outpen) delete outpen; if (Image->Mask) Image->Mask->StopScanLine(); if (undo) undo->Bitmap->StopScanLine(); Image->Bitmap->StopScanLine(); Undo->Read(); Screen->Cursor = OldCursor; EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TDrawForm::fit_dot_line(TPenMode ch, int ln, int *value, COLORREF fc) { int i, j, k, sx, sy, ex, ey; int cnt, dot, grade, total; double lng, gap; sx = Tstitch.l[ln].sx; sy = Tstitch.l[ln].sy; ex = Tstitch.l[ln].ex; ey = Tstitch.l[ln].ey; lng = (int)(sqrt((double)(ex - sx + 1) * (ex - sx + 1) + (ey - sy + 1) * (ey - sy + 1))); gap = (double)(value[0] + value[1]) * PenManagerForm->Pen->Thick; cnt = lng / gap + 1; grade = (value[0] + value[1]) * 2; dot = (value[0] - 1) * 2; total = cnt * grade; for (i = 0; i < cnt; i++) { j = i * grade + 1 + value[1]; k = total - j; Lsx = (double)(sx * k + ex * j) / total + 0.5; Lsy = (double)(sy * k + ey * j) / total + 0.5; j = j + dot; k = k - dot; Lex = (double)(sx * k + ex * j) / total + 0.5; Ley = (double)(sy * k + ey * j) / total + 0.5; Line(fc); } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::fit_dot_line(HDC dc, int x, int y) { int i, j, k, sx, sy, ex, ey; int cnt, dot, grade, total; double lng, gap; sx = Tstitch.l[1].sx; sy = Tstitch.l[1].sy; ex = Tstitch.l[1].ex; ey = Tstitch.l[1].ey; lng = int(sqrt(double(ex - sx + 1) * (ex - sx + 1) + (ey - sy + 1) * (ey - sy + 1))); gap = double(Ltype[Item].value[0] + Ltype[Item].value[1]) * PenManagerForm->Pen->Thick; cnt = lng / gap + 1; grade = (Ltype[Item].value[0] + Ltype[Item].value[1]) * 2; dot = (Ltype[Item].value[0] - 1) * 2; total = cnt * grade; for (i = 0; i < cnt; i++) { j = i * grade + 1 + Ltype[Item].value[1]; k = total - j; Lsx = double(sx * k + ex * j) / total + 0.5; Lsy = double(sy * k + ey * j) / total + 0.5; j = j + dot; k = k - dot; Lex = double(sx * k + ex * j) / total + 0.5; Ley = double(sy * k + ey * j) / total + 0.5; MoveToEx(dc, Lsx - x, Lsy - y, NULL); LineTo(dc, Lex - x, Ley - y); } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::square(TPenMode ch, COLORREF fc) { int sx, sy, ex, ey, lx, ly, pt, sr, lr; int SignX, SignY; Byte *IP; TPItemImage *Image = MainImageForm->iMainImage; pt = PenManagerForm->Pen->Thick; sr = pt >> 1; lr = pt - sr; if (isw==0) { sx = Lsx; sy = Lsy; lx = abs(Lex - sx); ly = abs(Ley - sy); if (lx > ly) lx = ly; ex = sx > Lex ? sx - lx : sx + lx; ey = sy > Ley ? sy - lx : sy + lx; if (sx > ex) swap(sx, ex); if (sy > ey) swap(sy, ey); } else { lx = Sqr_l - PenManagerForm->Pen->Thick; sx = Csx - lx / 2; sy = Csy - lx / 2; ex = sx + lx; ey = sy + lx; } if (ch == pmXor) { DrawRectangleLocate(Rect(sx, sy, ex + 1, ey + 1)); if (IsDraw) IsDraw = false; else IsDraw = true; } else if (ch == pmCopy) { if (fill_not == 1) { if (ex - sx - pt > 0 && ey - sy - pt > 0) { if (PenManagerForm->sbMask->Down) { if (!(Image->Mask->StartScanLine())) goto fail; } else { if (!(Image->Bitmap->StartScanLine())) goto fail; if (MainImageForm->MaskArea) { if (!(Image->Mask->StartScanLine())) goto fail; } } for (int i = sy + lr; i < ey - sr; i++) { MainImageForm->set_hline(sx + lr, i, ex - sx - pt, fc); } if (PenManagerForm->sbMask->Down) { Image->Mask->StopScanLine(); } else { if (MainImageForm->MaskArea) Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); } } } MainImageForm->line_pen(sx, sy, ex, sy, fc); MainImageForm->line_pen(ex, sy, ex, ey, fc); MainImageForm->line_pen(sx, ey, ex, ey, fc); MainImageForm->line_pen(sx, sy, sx, ey, fc); Image->Repaint(); } lx += PenManagerForm->Pen->Thick; switch (MainImageForm->CurrentUnit) { case uDot: eLength1->Text = lx; break; case uInch: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)lx / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, (2.54 * lx / MainImageForm->CanvasInfor.DotsPerInch))); break; } return; fail: Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TDrawForm::dotted_square(TPenMode ch, int *value, COLORREF fc) { int sx, sy, ex, ey, lx, ly, lng, l; TPItemImage *Image = MainImageForm->iMainImage; sx = Tstitch.sx; sy = Tstitch.sy; ex = Tstitch.ex; ey = Tstitch.ey; lx = ex - sx; ly = ey - sy; if (abs(lx) > abs(ly)) lng = ly; else lng = lx; l = abs(lng); if (lx * ly > 0) { Tstitch.l[1].sx = sx; Tstitch.l[1].sy = sy; Tstitch.l[1].ex = sx; Tstitch.l[1].ey = sy + lng; fit_dot_line(ch, 1, value, fc); Tstitch.l[1].ex = sx + lng; Tstitch.l[1].ey = sy; fit_dot_line(ch, 1, value, fc); Tstitch.l[1].sx = sx + lng; Tstitch.l[1].sy = sy + lng; Tstitch.l[1].ex = sx; Tstitch.l[1].ey = sy + lng; fit_dot_line(ch, 1, value, fc); Tstitch.l[1].ex = sx + lng; Tstitch.l[1].ey = sy; fit_dot_line(ch, 1, value, fc); } else { if (lx < 0) l = l * (-1); Tstitch.l[1].sx = sx; Tstitch.l[1].sy = sy; Tstitch.l[1].ex = sx; Tstitch.l[1].ey = sy - l; fit_dot_line(ch, 1, value, fc); Tstitch.l[1].ex = sx + l; Tstitch.l[1].ey = sy; fit_dot_line(ch, 1, value, fc); Tstitch.l[1].sx = sx + l; Tstitch.l[1].sy = sy - l; Tstitch.l[1].ex = sx; Tstitch.l[1].ey = sy - l; fit_dot_line(ch, 1, value, fc); Tstitch.l[1].ex = sx + l; Tstitch.l[1].ey = sy; fit_dot_line(ch, 1, value, fc); } if (ch == pmCopy) Image->Repaint(); l = abs(l) + PenManagerForm->Pen->Thick; switch (MainImageForm->CurrentUnit) { case uDot : eLength1->Text = l; break; case uInch: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)l / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)l / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::rectangle(TPenMode ch, COLORREF fc) { int sx, sy, ex, ey, lx, ly, pt, sr, lr; Byte *IP; TPItemImage *Image = MainImageForm->iMainImage; pt = PenManagerForm->Pen->Thick; sr = pt >> 1; lr = pt - sr; if (isw==0) { sx = Lsx; sy = Lsy; ex = Lex; ey = Ley; if (sx > ex) swap(sx, ex); if (sy > ey) swap(sy, ey); lx = ex - sx; ly = ey - sy; } else { lx = Rec_lx - PenManagerForm->Pen->Thick; ly = Rec_ly - PenManagerForm->Pen->Thick; sx = Csx - lx / 2; sy = Csy - ly / 2; } ex = sx + lx; ey = sy + ly; if (ch == pmXor) { DrawRectangleLocate(Rect(sx, sy, ex + 1, ey + 1)); if (IsDraw) IsDraw = false; else IsDraw = true; } else if (ch == pmCopy) { if (fill_not == 1) { if (ex - sx - pt > 0 && ey - sy - pt > 0) { if (PenManagerForm->sbMask->Down) { if (!(Image->Mask->StartScanLine())) goto fail; } else { if (!(Image->Bitmap->StartScanLine())) goto fail; if (MainImageForm->MaskArea) { if (!(Image->Mask->StartScanLine())) goto fail; } } for (int i = sy + lr; i < ey - sr; i++) { MainImageForm->set_hline(sx + lr, i, ex - sx - pt, fc); } if (PenManagerForm->sbMask->Down) { Image->Mask->StopScanLine(); } else { if (MainImageForm->MaskArea) Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); } } } MainImageForm->line_pen(sx, sy, ex, sy, fc); MainImageForm->line_pen(ex, sy, ex, ey, fc); MainImageForm->line_pen(sx, ey, ex, ey, fc); MainImageForm->line_pen(sx, sy, sx, ey, fc); Image->Repaint(); } lx += PenManagerForm->Pen->Thick; ly += PenManagerForm->Pen->Thick; switch (MainImageForm->CurrentUnit) { case uDot: eLength1->Text = lx; eLength2->Text = ly; break; case uInch: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)lx / MainImageForm->CanvasInfor.DotsPerInch))); eLength2->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)ly / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, (2.54 * lx / MainImageForm->CanvasInfor.DotsPerInch))); eLength2->Text = Format("%.2f", OPENARRAY(TVarRec, (2.54 * ly / MainImageForm->CanvasInfor.DotsPerInch))); break; } return; fail: Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TDrawForm::dotted_rectangle(TPenMode ch, int *value, COLORREF fc) { int sx, sy, ex, ey, lx, ly; TPItemImage *Image = MainImageForm->iMainImage; sx = Tstitch.sx; sy = Tstitch.sy; ex = Tstitch.ex; ey = Tstitch.ey; Tstitch.l[1].sx = sx; Tstitch.l[1].sy = sy; Tstitch.l[1].ex = ex; Tstitch.l[1].ey = sy; fit_dot_line(ch, 1, value, fc); Tstitch.l[1].ex = sx; Tstitch.l[1].ey = ey; fit_dot_line(ch, 1, value, fc); Tstitch.l[1].sx = ex; Tstitch.l[1].sy = ey; Tstitch.l[1].ex = sx; Tstitch.l[1].ey = ey; fit_dot_line(ch, 1, value, fc); Tstitch.l[1].ex = ex; Tstitch.l[1].ey = sy; fit_dot_line(ch, 1, value, fc); if (ch == pmCopy) Image->Repaint(); lx = abs(ex - sx) + PenManagerForm->Pen->Thick; ly = abs(ey - sy) + PenManagerForm->Pen->Thick; switch (MainImageForm->CurrentUnit) { case uDot : eLength1->Text = lx; eLength2->Text = ly; break; case uInch: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)lx / MainImageForm->CanvasInfor.DotsPerInch))); eLength2->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)ly / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)lx / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); eLength2->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)ly / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::curve(TPenMode ch, COLORREF fc) { int sx, sy, ex, ey, mx, my; double ct, st, ss, theta, alpha, d1, d2, d3; double tx, ty, a, b, x, y, pw, count; TPItemImage *Image = MainImageForm->iMainImage; pw = PenManagerForm->Pen->Thick; sx = Lsx; sy = Lsy; ex = Lex; ey = Ley; mx = Csx; my = Csy; d1 = sqrt((double)(sx - mx) * (sx - mx) + (sy - my) * (sy - my)); d2 = sqrt((double)(ex - mx) * (ex - mx) + (ey - my) * (ey - my)); d3 = sqrt((double)(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)) { Line(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 = pw / 10 + 1; Lsx = mx; Lsy = my; x = 0; while (x <= tx) { y = alpha * (x * x); Lex = mx + x; Ley = my + y; Line(fc); Lsx = Lex; Lsy = Ley; x = x + count; } if (sx > ex) Lex = sx; else Lex = ex; Ley = sy; Line(fc); count = pw / 10 + 1; Lsx = mx; Lsy = my; x = 0; while (x <= tx) { y = alpha * (x * x); Lex = mx - x; Ley = my + y; Line(fc); Lsx = Lex; Lsy = Ley; x = x + count; } if (sx < ex) Lex = sx; else Lex = ex; Ley = sy; Line(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; else ss = (double)(ty - my) / (tx - mx); 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 = pw / 10 + 1; Lsx = mx; Lsy = my; if (tx < 0) { x = 0; while (x >= tx) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; Line(fc); Lsx = Lex; Lsy = Ley; x = x - count; } } else { x = 0; while (x <= tx) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; Line(fc); Lsx = Lex; Lsy = Ley; x = x + count; } } Lex = sx; Ley = sy; Line(fc); tx = ct * (ex - mx) - st * (ey - my); ty = st * (ex - mx) + ct * (ey - my); alpha = ty / (tx * tx); count = pw / 10 + 1; Lsx = mx; Lsy = my; if (tx < 0) { x = 0; while (x >= tx) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; Line(fc); Lsx = Lex; Lsy = Ley; x = x - count; } } else { x = 0; while (x <= tx) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; Line(fc); Lsx = Lex; Lsy = Ley; x = x + count; } } Lex = ex; Ley = ey; Line(fc); } if (ch == pmCopy) Image->Repaint(); Lsx = sx; Lex = ex; Lsy = sy; Ley = ey; } //--------------------------------------------------------------------------- void __fastcall TDrawForm::dot_curve(TPenMode ch, int *value, COLORREF fc) { int i, j, k, sx, sy, ex, ey; int ssx, eex, ssy, eey, mx, my; int cnt, dot, grade, total; double x, y, llsx, llsy, llex, lley; double tx, ty, a, b, pw, count; double lng, gap; double ct, st, ss, theta, alpha, d1, d2, d3; TPItemImage *Image = MainImageForm->iMainImage; pw = PenManagerForm->Pen->Thick; sx = Lsx; sy = Lsy; ex = Lex; ey = Ley; 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; dot_line(ch, 1, value, fc); } else if ((sy == ey) && ((mx - sx) == (mx - ex))) { tx = abs(mx - sx); ty = sy - my; alpha = ty / (tx * tx); count = pw / 10.0 + 1; Lsx = mx; Lsy = my; x = 0; while (x <= tx) { y = alpha * (x * x); Lex = mx + x; Ley = my + y; Line(fc); Lsx = Lex; Lsy = Ley; x = x + count; } if (sx > ex) Lex = sx; else Lex = ex; Ley = sy; Line(fc); count = pw / 10.0 + 1; Lsx = mx; Lsy = my; x = 0; while (x <= tx) { y = alpha * (x * x); Lex = mx - x; Ley = my + y; Line(fc); Lsx = Lex; Lsy = Ley; x = x + count; } if (sx < ex) Lex = sx; else Lex = ex; Ley = sy; Line(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; else ss = (ty - my) / (tx - mx); theta = M_PI_2 - 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 = (value[0] + value[1]) * PenManagerForm->Pen->Thick; cnt = lng / gap + 1; grade = (value[0] + value[1]) * 2; dot = (value[0] - 1) * 2; total = cnt * grade; for (i = 0; i < cnt; i++) { j = i * grade + 1 + value[1]; k = total - j; llsx = double(ssx * k + 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 + dot; k = k - dot; llex = double(ssx * k + eex * j) / total; lley = alpha * llex * llex; Lex = ct * llex + st * lley + mx + 0.5; Ley = ct * lley - st * llex + my + 0.5; Line(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 = (value[0] + value[1]) * PenManagerForm->Pen->Thick; cnt = lng / gap + 1; grade = (value[0] + value[1]) * 2; dot = (value[0] - 1) * 2; total = cnt * grade; for (i = 0; i < cnt; i++) { j = i * grade + 1 + value[1]; k = total - j; llsx = double(ssx * k + 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 + dot; k = k - dot; llex = double(ssx * k + eex * j) / total; lley = alpha * llex * llex; Lex = ct * llex + st * lley + mx + 0.5; Ley = ct * lley - st * llex + my + 0.5; Line(fc); } } Image->Repaint(); Lsx = sx; Lex = ex; Lsy = sy; Ley = ey; } //--------------------------------------------------------------------------- void __fastcall TDrawForm::circle(TPenMode ch, COLORREF fc) { int lx, ly, dia, h; TTexpiaBitmap *tb = NULL; HDC dc = NULL; HPEN hPen = NULL, hOldPen = NULL; int x, y, xx, ls, rs, ec = EC_NONE; BYTE *bp; TPItemImage *Image = MainImageForm->iMainImage; if (isw==0) { lx = Lsx - Csx; ly = Lsy - Csy; dia = 2 * sqrt(lx * lx + ly * ly) + 1; } else { dia = Radius; } h = dia / 2; if (ch == pmXor) { DrawEllipseLocate(Rect(Csx - h, Csy - h, Csx - h + dia + 1, Csy - h + dia + 1)); if (IsDraw) IsDraw = false; else IsDraw = true; } else if (ch == pmCopy) { if (PenManagerForm->sbMask->Down) { if (!(Image->Mask->StartScanLine())) {ec = EC_MEMORY_LACK; goto fail;} } else { if (!(Image->Bitmap->StartScanLine())) {ec = EC_MEMORY_LACK; goto fail;} if (MainImageForm->MaskArea) { if (!(Image->Mask->StartScanLine())) {ec = EC_MEMORY_LACK; goto fail;} } } ls = PenManagerForm->Pen->Thick >> 1; rs = PenManagerForm->Pen->Thick - ls; if ((tb = new TTexpiaBitmap)==NULL) {ec = EC_MEMORY_LACK; goto fail;} if (!tb->Create(dia, dia, 8)) {ec = EC_MEMORY_LACK; goto fail;} if ((dc = tb->CreateDC())==NULL) {ec = EC_RESOURCE_LACK; goto fail;} if (fill_not == 0) { SelectObject(dc, GetStockObject(NULL_BRUSH)); } else { SelectObject(dc, GetStockObject(WHITE_BRUSH)); } if ((hPen = CreatePen(PS_SOLID, PenManagerForm->Pen->Thick, clWhite))==NULL) {ec = EC_RESOURCE_LACK; goto fail;} SelectObject(dc, hPen); Ellipse(dc, ls, ls, dia - rs + 1, dia - rs + 1); DeleteObject(hPen); hPen = NULL; tb->DeleteDC(dc); dc = NULL; if (!tb->StartScanLine()) {ec = EC_MEMORY_LACK; goto fail;} for (y = 0; y < dia; y++) { bp = tb->GetScanLine(y); for (x = 0; x < dia;) { if (bp[x]) { for (xx = x; xx < dia; xx++) { if (bp[xx]==0) break; } MainImageForm->set_hline(Csx - h + x, Csy - h + y, xx - x, fc); x = xx; } else { x++; } } } tb->StopScanLine(); delete tb; if (PenManagerForm->sbMask->Down) { Image->Mask->StopScanLine(); } else { if (MainImageForm->MaskArea) Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); } Image->Repaint(); } switch (MainImageForm->CurrentUnit) { case uDot: eLength1->Text = dia; break; case uInch: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)dia / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, (2.54 * dia / MainImageForm->CanvasInfor.DotsPerInch))); break; } return; fail: if (tb) { if (dc) tb->DeleteDC(dc); delete tb; } /* if (PenManagerForm->sbMask->Down) { Image->Mask->StopScanLine(); } else { if (MainImageForm->MaskArea) Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); } */ Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TDrawForm::dot_line(TPenMode ch, int ln, int *value, COLORREF fc) { int i, sx, sy, ex, ey, lx, ly; int cnt, dx, dy; double lng, gap, th, ct, st, p; int ccsx, ccsy, ccex, ccey; TPItemImage *Image = MainImageForm->iMainImage; 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 = (value[0] + value[1]) * PenManagerForm->Pen->Thick; cnt = lng / gap + 1; if ((Item == TD_LINE) || (Item == TD_CURVE)) { ccsx = Lsx; ccsy = Lsy; ccex = Lex; ccey = Ley; 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 + ((value[0] - 1) * PenManagerForm->Pen->Thick)) <= lng) { Lex = (gap * i + ((value[0] - 1) * PenManagerForm->Pen->Thick)) * ct + sx + 0.5; Ley = (gap * i + ((value[0] - 1) * PenManagerForm->Pen->Thick)) * st + sy + 0.5; } else { Lex = lng * ct + sx; Ley = lng * st + sy; } Line(fc); } } Lsx = ccsx; Lsy = ccsy; Lex = ccex; Ley = ccey; } else { ccsx = Lsx; ccsy = Lsy; ccex = Lex; ccey = Ley; 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 + ((value[0] - 1) * PenManagerForm->Pen->Thick)) <= lng) { Lex = (gap * i + ((value[0] - 1) * PenManagerForm->Pen->Thick)) * ct + sx + 0.5; Ley = (gap * i + ((value[0] - 1) * PenManagerForm->Pen->Thick)) * st + sy + 0.5; } else { Lex = lng * ct + sx; Ley = lng * st + sy; } Line(fc); } } Lsx = ccsx; Lsy = ccsy; Lex = ccex; Ley = ccey; } Image->Repaint(); dx = Lex - Lsx; dy = Ley - Lsy; if (dy < 0) { p = (atan2(dy, dx) + 2 * M_PI) * 180.0 / M_PI; } else { if ((dx == 0) && (dy == 0)) p = 0; else p = (atan2(dy, dx)) * 180.0 / M_PI; } eAngle->Text = Format("%3.0f", OPENARRAY(TVarRec, (p))); lx = abs(dx) + 1; ly = abs(dy) + 1; p = sqrt(lx * lx + ly * ly) + PenManagerForm->Pen->Thick; switch (MainImageForm->CurrentUnit) { case uDot : eLength1->Text = p; break; case uInch: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, (p / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, (p / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::dot_line_mark(int len, char *bb, int *value) { int i, j, k, l, sx, ex; int cnt, dot, grade, total, ls, le; double lng, gap; lng = len; sx = 0; ex = lng; lng = lng+1; gap = (double)(value[0]+value[1])*PenManagerForm->Pen->Thick; cnt = lng / gap + 1; grade = (value[0]+value[1])*2; dot = (value[0]-1)*2; total = cnt * grade; for (i=0; iiMainImage; c = PaletteForm->DIB256Palette->GetFGCOLORREF(Image->Bitmap->BitsPerPixel); pw = PenManagerForm->Pen->Thick; lr = abs(Csx - Lsx) - pw / 2.0; sr = abs(Csy - Lsy) - pw / 2.0; r = sqrt(lr * lr + sr * sr); l = 2 * M_PI * r + 0.5; dc = new char[l+10]; memset(dc, 0, l+10); dot_line_mark(l, dc, value); Image->Bitmap->StartScanLine(); if (Image->Mask) Image->Mask->StartScanLine(); i = 0; while (i < r * 0.75) { j = sqrt(r * r - i * i) + 0.5; x = i; y = j; len = dot_pos(x, y, r); if (dc[len]) { Lsx = Csx + i; Lsy = Csy + j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } len = dot_pos(x, -y, r); if (dc[len]) { Lsx = Csx + i; Lsy = Csy - j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } len = dot_pos(-x, y, r); if (dc[len]) { Lsx = Csx - i; Lsy = Csy + j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } len = dot_pos(-x, -y, r); if (dc[len]) { Lsx = Csx - i; Lsy = Csy - j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } len = dot_pos(y, x, r); if (dc[len]) { Lsx = Csx + j; Lsy = Csy + i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } len = dot_pos(y, -x, r); if (dc[len]) { Lsx = Csx + j; Lsy = Csy - i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } len = dot_pos(-y, x, r); if (dc[len]) { Lsx = Csx - j; Lsy = Csy + i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } len = dot_pos(-y, -x, r); if (dc[len]) { Lsx = Csx - j; Lsy = Csy - i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } i++; } if (dc) { delete dc; dc = 0; } if (Image->Mask) Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TDrawForm::ellipse(TPenMode ch, COLORREF fc) { int i, j, sx, la, sa, lb, sb, lb2, sb2, a, b, pw; int lx, ly, dia, hx, hy; TTexpiaBitmap *tb = NULL; HDC dc = NULL; HPEN hPen = NULL; int x, y, xx, ls, rs, ec = EC_NONE; BYTE *bp; TPItemImage *Image = MainImageForm->iMainImage; if (isw==0) { a = 2 * abs(Lsx - Csx) + 1; b = 2 * abs(Lsy - Csy) + 1; } else { a = Ell_rx; b = Ell_ry; } hx = a / 2; hy = b / 2; if (ch == pmXor) { DrawEllipseLocate(Rect(Csx - hx, Csy - hy, Csx - hx + a + 1, Csy - hy + b + 1)); if (IsDraw) IsDraw = false; else IsDraw = true; } else if (ch == pmCopy) { if (PenManagerForm->sbMask->Down) { if (!(Image->Mask->StartScanLine())) {ec = EC_MEMORY_LACK; goto fail;} } else { if (!(Image->Bitmap->StartScanLine())) {ec = EC_MEMORY_LACK; goto fail;} if (MainImageForm->MaskArea) { if (!(Image->Mask->StartScanLine())) {ec = EC_MEMORY_LACK; goto fail;} } } ls = PenManagerForm->Pen->Thick >> 1; rs = PenManagerForm->Pen->Thick - ls; if ((tb = new TTexpiaBitmap)==NULL) {ec = EC_MEMORY_LACK; goto fail;} if (!tb->Create(a, b, 8)) {ec = EC_MEMORY_LACK; goto fail;} if ((dc = tb->CreateDC())==NULL) {ec = EC_RESOURCE_LACK; goto fail;} if (fill_not == 0) { SelectObject(dc, GetStockObject(NULL_BRUSH)); } else { SelectObject(dc, GetStockObject(WHITE_BRUSH)); } if ((hPen = CreatePen(PS_SOLID, PenManagerForm->Pen->Thick, clWhite))==NULL) {ec = EC_RESOURCE_LACK; goto fail;} SelectObject(dc, hPen); Ellipse(dc, ls, ls, a - rs + 1, b - rs + 1); DeleteObject(hPen); hPen = NULL; tb->DeleteDC(dc); dc = NULL; if (!tb->StartScanLine()) {ec = EC_MEMORY_LACK; goto fail;} for (y = 0; y < b; y++) { bp = tb->GetScanLine(y); for (x = 0; x < a;) { if (bp[x]) { for (xx = x; xx < a; xx++) { if (bp[xx]==0) break; } MainImageForm->set_hline(Csx - hx + x, Csy - hy + y, xx - x, fc); x = xx; } else { x++; } } } tb->StopScanLine(); delete tb; if (PenManagerForm->sbMask->Down) { Image->Mask->StopScanLine(); } else { Image->Bitmap->StopScanLine(); if (MainImageForm->MaskArea) Image->Mask->StopScanLine(); } Image->Repaint(); } switch (MainImageForm->CurrentUnit) { case uDot : eLength1->Text = a; eLength2->Text = b; break; case uInch: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)a / MainImageForm->CanvasInfor.DotsPerInch))); eLength2->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)b / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, (2.54 * a / MainImageForm->CanvasInfor.DotsPerInch))); eLength2->Text = Format("%.2f", OPENARRAY(TVarRec, (2.54 * b / MainImageForm->CanvasInfor.DotsPerInch))); } return; fail: if (tb) { if (dc) tb->DeleteDC(dc); delete tb; } Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); /* if (PenManagerForm->sbMask->Down) { Image->Mask->StopScanLine(); } else { Image->Bitmap->StopScanLine(); if (MainImageForm->MaskArea) Image->Mask->StopScanLine(); } */ EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TDrawForm::dotted_ellipse(TPenMode ch, int *value) { char *de = 0; int i, g, a, b, a1, b1, lb2, sb2, pw, gap, j = 0; double ratio, cmp; COLORREF c; TPItemImage *Image = MainImageForm->iMainImage; c = PaletteForm->DIB256Palette->GetFGCOLORREF(Image->Bitmap->BitsPerPixel); j = 0; pw = PenManagerForm->Pen->Thick; a = abs(Lsx - Csx) - pw / 2.0; b = abs(Lsy - Csy) - pw / 2.0; if (a == 0 && b == 0) return; lb2 = a * a; sb2 = b * b; gap = (value[0] + value[1]) * pw; Image->Bitmap->StartScanLine(); if (Image->Mask) Image->Mask->StartScanLine(); if (a > b) { cmp = (double)b / a; if (cmp > 0.55) { de = new char[a + 10]; memset(de, 0, a + 10); dot_line_mark(a, de, value); i = 0; while (i < a * 0.8) { if (de[i]) { j = b * sqrt(1.0 - (double)i * i / lb2) + 0.5; Lsx = Csx + i; Lsy = Csy + j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx + i; Lsy = Csy - j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - i; Lsy = Csy + j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - i; Lsy = Csy - j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } i++; } b1 = j; for (i = 0; i < b1; i++) { if (de[i]) { j = a * sqrt(1.0 - (double)i * i / sb2) + 0.5; Lsx = Csx + j; Lsy = Csy + i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx + j; Lsy = Csy - i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - j; Lsy = Csy + i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - j; Lsy = Csy - i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } } if (de) { delete de; de = 0; } } else { for (i = 0; i < a; i++) { g = i - (value[1] + 1) * pw / 2.0; if (g < 0) g = gap + g; if ((g % gap) < (value[0] * pw) - pw) { j = b * sqrt(1.0 - (double)i * i / lb2) + 0.5; Lsx = Csx + i; Lsy = Csy + j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx + i; Lsy = Csy - j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - i; Lsy = Csy + j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - i; Lsy = Csy - j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } } ratio = (double)b / (a + b); b1 = b * ratio + 0.5; for (i = 0; i < b1; i++) { g = i - (value[1] + 1) * pw / 2.0; if (g < 0) g = gap + g; if ((g % gap) < (value[0] * pw) - pw) { j = a * sqrt(1.0 - (double)i * i / sb2) + 0.5; Lsx = Csx + j; Lsy = Csy + i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx + j; Lsy = Csy - i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - j; Lsy = Csy + i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - j; Lsy = Csy - i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } } } } else { cmp = (double)a / b; if (cmp > 0.55) { de = new char[b + 10]; memset(de, 0, b + 10); dot_line_mark(b, de, value); for (i = 0; i < b * 0.8; i++) { if (de[i]) { j = a * sqrt(1.0 - (double)i * i / sb2) + 0.5; Lsx = Csx + j; Lsy = Csy + i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx + j; Lsy = Csy - i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - j; Lsy = Csy + i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - j; Lsy = Csy - i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } } a1 = j; for (i = 0; i < a1; i++) { if (de[i]) { j = b * sqrt(1.0 - (double)i * i / lb2) + 0.5; Lsx = Csx + i; Lsy = Csy + j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx + i; Lsy = Csy - j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - i; Lsy = Csy + j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - i; Lsy = Csy - j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } } if (de) { delete de; de = 0; } } else { for (i = 0; i < b; i++) { g = i - (value[1] + 1) * pw / 2.0; if (g < 0) g = gap + g; if ((g % gap) < (value[0] * pw) - pw) { j = a * sqrt(1.0 - (double)i * i / sb2) + 0.5; Lsx = Csx + j; Lsy = Csy + i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx + j; Lsy = Csy - i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - j; Lsy = Csy + i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - j; Lsy = Csy - i; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } } ratio = (double)a / (a + b); a1 = a * ratio + 0.5; for (i = 0; i < a1; i++) { g = i - (value[1] + 1) * pw / 2.0; if (g < 0) g = gap + g; if ((g % gap) < (value[0] * pw) - pw) { j = b * sqrt(1.0 - (double)i * i / lb2) + 0.5; Lsx = Csx + i; Lsy = Csy + j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx + i; Lsy = Csy - j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - i; Lsy = Csy + j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); Lsx = Csx - i; Lsy = Csy - j; MainImageForm->dotted_pen(Lsx, Lsy, Csx, Csy, c); } } } } if (Image->Mask) Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TDrawForm::LenAng_check(int x, int y) { double dx, dy, alpha, length; TPItemImage *Image = MainImageForm->iMainImage; dx = x - Lsx; dy = y - Lsy; if ((Asw == 2) && (Lsw == 0)) { length = sqrt(dx * dx + dy * dy); if (x > Lsx) { if (y > Lsy) { //I alpha = Line_angle * (M_PI / 180.0); Lex = Lsx + length * cos(alpha); Ley = Lsy + length * sin(alpha); if (Lex >= Image->Bitmap->Width) { Lex = Image->Bitmap->Width - 1; Ley = Lsy + (Lex - Lsx) * tan(alpha); } if (Ley >= Image->Bitmap->Height) { Ley = Image->Bitmap->Height - 1; Lex = Lsx + (Ley - Lsy) / tan(alpha); } } else { //IV alpha = (Line_angle + 270.0) * (M_PI / 180.0); Lex = Lsx + length * cos(alpha) + 0.5; Ley = Lsy + length * sin(alpha); if (Lex >= Image->Bitmap->Width) { Lex = Image->Bitmap->Width - 1; Ley = Lsy + (Lex - Lsx) * tan(alpha); } if (Ley < 0) { Ley = 0; Lex = Lsx + (Ley - Lsy) / tan(alpha); } } } else { if (y > Lsy) { //II alpha = (Line_angle + 90) * (M_PI / 180.0); Lex = Lsx + length * cos(alpha); Ley = Lsy + length * sin(alpha); if (Lex < 0) { Lex = 0; Ley = Lsy + (Lex - Lsx) * tan(alpha); } if (Ley >= Image->Bitmap->Height) { Ley = Image->Bitmap->Height - 1; Lex = Lsx + (Ley - Lsy) / tan(alpha); } } else { //III alpha = (Line_angle + 180.0) * (M_PI / 180.0); Lex = Lsx + length * cos(alpha); Ley = Lsy + length * sin(alpha); if (Lex < 0) { Lex = 0; Ley = Lsy + (Lex - Lsx) * tan(alpha); } if (Ley < 0) { Ley = 0; Lex = Lsx + (Ley - Lsy) / tan(alpha); } } } } else if ((Asw == 0) && (Lsw == 2)) { if ((dy == 0) && (dx == 0)) alpha = M_PI_2; else alpha = atan2(dy, dx); Lex = Lsx + Line_len * cos(alpha) + 0.5; Ley = Lsy + Line_len * sin(alpha) + 0.5; if (x > Lsx) { if (y > Lsy) { //I if (Lex >= Image->Bitmap->Width) { Lex = Image->Bitmap->Width - 1; Ley = Lsy + (Lex - Lsx) * tan(alpha); } if (Ley >= Image->Bitmap->Height) { Ley = Image->Bitmap->Height - 1; Lex = Lsx + (Ley - Lsy) / tan(alpha); } } else { //IV if (Lex >= Image->Bitmap->Width) { Lex = Image->Bitmap->Width - 1; Ley = Lsy + (Lex - Lsx) * tan(alpha); } if (Ley < 0) { Ley = 0; Lex = Lsx + (Ley - Lsy) / tan(alpha); } } } else { if (y > Lsy) { //II if (Lex < 0) { Lex = 0; Ley = Lsy + (Lex - Lsx + 1) * tan(alpha); } if (Ley >= Image->Bitmap->Height) { Ley = Image->Bitmap->Height - 1; Lex = Lsx + (Ley - Lsy) / tan(alpha); } } else { //III if (Lex < 0) { Lex = 0; Ley = Lsy + (Lex - Lsx) * tan(alpha); } if (Ley < 0) { Ley = 0; Lex = Lsx + (Ley - Lsy) / tan(alpha); } } } } else if ((Asw == 2) && (Lsw == 2)) { if (x > Lsx) { if (y > Lsy) { //I alpha = Line_angle * (M_PI / 180.0); Lex = Lsx + Line_len * cos(alpha) + 0.5; Ley = Lsy + Line_len * sin(alpha) + 0.5; if (Lex >= Image->Bitmap->Width) { Lex = Image->Bitmap->Width - 1; Ley = Lsy + (Lex - Lsx) * tan(alpha); } if (Ley >= Image->Bitmap->Height) { Ley = Image->Bitmap->Height - 1; Lex = Lsx + (Ley - Lsy) / tan(alpha); } } else { //IV alpha = (Line_angle + 270.0) * (M_PI / 180.0); Lex = Lsx + Line_len * cos(alpha) + 0.5; Ley = Lsy + Line_len * sin(alpha) + 0.5; if (Lex >= Image->Bitmap->Width) { Lex = Image->Bitmap->Width - 1; Ley = Lsy + (Lex - Lsx) * tan(alpha); } if (Ley < 0) { Ley = 0; Lex = Lsx + (Ley - Lsy) / tan(alpha); } } } else { if (y > Lsy) { //II alpha = (Line_angle + 90.0) * (M_PI / 180.0); Lex = Lsx + Line_len * cos(alpha) + 0.5; Ley = Lsy + Line_len * sin(alpha) + 0.5; if (Lex < 0) { Lex = 0; Ley = Lsy + (Lex - Lsx) * tan(alpha); } if (Ley >= Image->Bitmap->Height) { Ley = Image->Bitmap->Height - 1; Lex = Lsx + (Ley - Lsy) / tan(alpha); } } else { //III alpha = (Line_angle + 180.0) * (M_PI / 180.0); Lex = Lsx + Line_len * cos(alpha) + 0.5; Ley = Lsy + Line_len * sin(alpha) + 0.5; if (Lex < 0) { Lex = 0; Ley = Lsy + (Lex - Lsx) * tan(alpha); } if (Ley < 0) { Ley = 0; Lex = Lsx + (Ley - Lsy) / tan(alpha); } } } } } //---------------------------------------------------------------------------- void __fastcall TDrawForm::DotLineLocate(HDC dc, int x, int y, void *pData) { int i, sx, sy, ex, ey, lx, ly; int cnt, dx, dy; double lng, gap, th, ct, st, p; int ccsx, ccsy, ccex, ccey; HPEN hPen = NULL, hOldPen; if ((hPen = CreatePen(PS_SOLID, DrawLocate[Item].szPen, DrawLocate[Item].clPen))!=NULL) { hOldPen = SelectObject(dc, hPen); sx = Tstitch.l[1].sx; sy = Tstitch.l[1].sy; ex = Tstitch.l[1].ex; ey = Tstitch.l[1].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 = (Ltype[Item].value[0] + Ltype[Item].value[1]) * PenManagerForm->Pen->Thick; cnt = lng / gap + 1; if ((Item == TD_LINE) || (Item == TD_CURVE)) { ccsx = Lsx; ccsy = Lsy; ccex = Lex; ccey = Ley; 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 + ((Ltype[Item].value[0] - 1) * PenManagerForm->Pen->Thick)) <= lng) { Lex = (gap * i + ((Ltype[Item].value[0] - 1) * PenManagerForm->Pen->Thick)) * ct + sx + 0.5; Ley = (gap * i + ((Ltype[Item].value[0] - 1) * PenManagerForm->Pen->Thick)) * 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); } } Lsx = ccsx; Lsy = ccsy; Lex = ccex; Ley = ccey; } else { ccsx = Lsx; ccsy = Lsy; ccex = Lex; ccey = Ley; 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 + ((Ltype[Item].value[0] - 1) * PenManagerForm->Pen->Thick)) <= lng) { Lex = (gap * i + ((Ltype[Item].value[0] - 1) * PenManagerForm->Pen->Thick)) * ct + sx + 0.5; Ley = (gap * i + ((Ltype[Item].value[0] - 1) * PenManagerForm->Pen->Thick)) * st + sy + 0.5; } else { Lex = lng * ct + sx; Ley = lng * st + sy; } MoveToEx(dc, Lsx - x, Lsy - y, NULL); LineTo(dc, Lex - x, Ley - y); } } Lsx = ccsx; Lsy = ccsy; Lex = ccex; Ley = ccey; } SelectObject(dc, hOldPen); DeleteObject(hPen); } dx = Lex - Lsx; dy = Ley - Lsy; if (dy < 0) { p = (atan2(dy, dx) + 2 * M_PI) * 180.0 / M_PI; } else { if ((dx == 0) && (dy == 0)) p = 0; else p = (atan2(dy, dx)) * 180.0 / M_PI; } eAngle->Text = Format("%3.0f", OPENARRAY(TVarRec, (p))); lx = abs(dx) + 1; ly = abs(dy) + 1; p = sqrt(lx * lx + ly * ly) + PenManagerForm->Pen->Thick; switch (MainImageForm->CurrentUnit) { case uDot : eLength1->Text = p; break; case uInch: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, (p / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, (p / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); } } //---------------------------------------------------------------------------- void __fastcall TDrawForm::DrawDotLineLocate(POINT First, POINT Second) { RECT rt, Src, Dst; 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; Src.left = rt.left - ls * 2; Src.top = rt.top - ls * 2; Src.right = rt.right + rs * 2; Src.bottom = rt.bottom + rs * 2; UnionRect(&Dst, &Src, &DrawLocate[Item].rtInvalidate); DrawLocate[Item].szPen = PenManagerForm->Pen->Thick; DrawLocate[Item].clPen = MainImageForm->Palette->Color[PaletteForm->DIB256Palette->ChoiceIndex]; DrawLocate[Item].ptFirst.x = rt.left; DrawLocate[Item].ptFirst.y = rt.top; DrawLocate[Item].ptSecond.x = rt.right; DrawLocate[Item].ptSecond.y = rt.bottom; static RECT Dst2 = Dst; UnionRect(&Dst2, &Dst, &Dst2); Image->RectEditPaint(Dst2, DotLineLocate, NULL); Dst2=Dst; DrawLocate[Item].rtInvalidate = Src; } //--------------------------------------------------------------------------- void __fastcall TDrawForm::LineLocate(HDC dc, int x, int y, void *pData) { HPEN hPen = NULL, hOldPen; if ((hPen = CreatePen(PS_SOLID, DrawLocate[Item].szPen, DrawLocate[Item].clPen))!=NULL) { hOldPen = SelectObject(dc, hPen); if(DrawLocate[Item].ptFirst.x < DrawLocate[Item].ptSecond.x)DrawLocate[Item].ptSecond.x += 1; else if(DrawLocate[Item].ptFirst.x > DrawLocate[Item].ptSecond.x)DrawLocate[Item].ptSecond.x -= 1; if(DrawLocate[Item].ptFirst.y < DrawLocate[Item].ptSecond.y)DrawLocate[Item].ptSecond.y += 1; else if(DrawLocate[Item].ptFirst.y > DrawLocate[Item].ptSecond.y)DrawLocate[Item].ptSecond.y -= 1; MoveToEx(dc, DrawLocate[Item].ptFirst.x - x, DrawLocate[Item].ptFirst.y - y, NULL); LineTo(dc, DrawLocate[Item].ptSecond.x - x, DrawLocate[Item].ptSecond.y - y); SelectObject(dc, hOldPen); DeleteObject(hPen); } /* HPEN hPen, hOldPen; LOGBRUSH lplb = { BS_SOLID, DrawLocate[Item].clPen, HS_CROSS }; SetMiterLimit(dc, 5.0, NULL); hPen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT | PS_JOIN_MITER, DrawLocate[Item].szPen, &lplb, 0, NULL); hOldPen = SelectObject(dc, hPen); MoveToEx(dc, DrawLocate[Item].ptFirst.x - x, DrawLocate[Item].ptFirst.y - y, NULL); LineTo(dc, DrawLocate[Item].ptSecond.x - x, DrawLocate[Item].ptSecond.y - y); SelectObject(dc, hOldPen); DeleteObject(hPen); */ } //---------------------------------------------------------------------------- void __fastcall TDrawForm::DrawLineLocate(POINT First, POINT Second) { RECT Src, Dst; int ls, rs; TPItemImage *Image = MainImageForm->iMainImage; ls = PenManagerForm->Pen->Thick >> 1; rs = PenManagerForm->Pen->Thick - ls; Src.left = min(First.x, Second.x) - ls * 2; Src.top = min(First.y, Second.y) - ls * 2; Src.right = max(First.x, Second.x) + rs * 2; Src.bottom = max(First.y, Second.y) + rs * 2; UnionRect(&Dst, &Src, &DrawLocate[Item].rtInvalidate); DrawLocate[Item].szPen = PenManagerForm->Pen->Thick; DrawLocate[Item].clPen = MainImageForm->Palette->Color[PaletteForm->DIB256Palette->ChoiceIndex]; DrawLocate[Item].ptFirst.x = First.x; DrawLocate[Item].ptFirst.y = First.y; DrawLocate[Item].ptSecond.x = Second.x; DrawLocate[Item].ptSecond.y = Second.y; static RECT Dst2 = Dst; UnionRect(&Dst2, &Dst, &Dst2); Image->RectEditPaint(Dst2, LineLocate, NULL); Dst2=Dst; /* static RECT Dst2 = Rect(0,0,0,0); Image->RectPaint(Dst2); Dst2=Dst; Image->RectEditPaint(Dst, LineLocate, NULL); */ DrawLocate[Item].rtInvalidate = Src; } //--------------------------------------------------------------------------- void __fastcall TDrawForm::CurveLocate(HDC dc, int x, int y, void *pData) { int sx, sy, ex, ey, mx, my; double ct, st, ss, theta, alpha, d1, d2, d3; double tx, ty, a, b, xx, yy, pw, count; HPEN hPen = NULL, hOldPen; RECT rt; int ls, rs; if ((hPen = CreatePen(PS_SOLID, DrawLocate[Item].szPen, DrawLocate[Item].clPen))!=NULL) { hOldPen = SelectObject(dc, hPen); ls = PenManagerForm->Pen->Thick / 2.0; rs = PenManagerForm->Pen->Thick - ls; pw = PenManagerForm->Pen->Thick; sx = Lsx; sy = Lsy; ex = Lex; ey = Ley; mx = Csx; my = Csy; d1 = sqrt((double)(sx - mx) * (sx - mx) + (sy - my) * (sy - my)); d2 = sqrt((double)(ex - mx) * (ex - mx) + (ey - my) * (ey - my)); d3 = sqrt((double)(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)) { MoveToEx(dc, Lsx - x, Lsy - y, NULL); LineTo(dc, Lex - x, Ley - y); } else if ((sy == ey) && ((mx - sx) == (mx - ex))) { if (sx > mx) tx = sx - mx; else tx = mx - sx; if (tx==0) tx = 1; ty = sy - my; alpha = ty / (tx * tx); count = pw / 10 + 1; Lsx = mx; Lsy = my; xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = mx + xx; Ley = my + yy; 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[Item].Src, &DrawLocate[Item].Src, &rt); Lsx = Lex; Lsy = Ley; xx = xx + count; } if (sx > ex) Lex = sx; else Lex = ex; Ley = sy; 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[Item].Src, &DrawLocate[Item].Src, &rt); count = pw / 10 + 1; Lsx = mx; Lsy = my; xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = mx - xx; Ley = my + yy; 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[Item].Src, &DrawLocate[Item].Src, &rt); Lsx = Lex; Lsy = Ley; xx = xx + count; } if (sx < ex) Lex = sx; else Lex = ex; Ley = sy; 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[Item].Src, &DrawLocate[Item].Src, &rt); } 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) == 0) ss = (double)(ty - my); else ss = (double)(ty - my) / (tx - mx); 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); if (tx==0) tx = 1; alpha = ty / (tx * tx); count = pw / 10 + 1; Lsx = mx; Lsy = my; if (tx < 0) { xx = 0; while (xx >= tx) { yy = alpha * (xx * xx); Lex = ct * xx + st * yy + mx; Ley = ct * yy - st * xx + my; 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[Item].Src, &DrawLocate[Item].Src, &rt); Lsx = Lex; Lsy = Ley; xx = xx - count; } } else { xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = ct * xx + st * yy + mx; Ley = ct * yy - st * xx + my; 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[Item].Src, &DrawLocate[Item].Src, &rt); Lsx = Lex; Lsy = Ley; xx = xx + count; } } Lex = sx; Ley = sy; 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[Item].Src, &DrawLocate[Item].Src, &rt); tx = ct * (ex - mx) - st * (ey - my); ty = st * (ex - mx) + ct * (ey - my); if (tx==0) tx = 1; alpha = ty / (tx * tx); count = pw / 10 + 1; Lsx = mx; Lsy = my; if (tx < 0) { xx = 0; while (xx >= tx) { yy = alpha * (xx * xx); Lex = ct * xx + st * yy + mx; Ley = ct * yy - st * xx + my; 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[Item].Src, &DrawLocate[Item].Src, &rt); Lsx = Lex; Lsy = Ley; xx = xx - count; } } else { xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = ct * xx + st * yy + mx; Ley = ct * yy - st * xx + my; 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[Item].Src, &DrawLocate[Item].Src, &rt); Lsx = Lex; Lsy = Ley; xx = xx + count; } } Lex = ex; Ley = ey; 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[Item].Src, &DrawLocate[Item].Src, &rt); } Lsx = sx; Lex = ex; Lsy = sy; Ley = ey; DrawLocate[Item].Src.left -= ls; DrawLocate[Item].Src.top -= ls; DrawLocate[Item].Src.right += rs; DrawLocate[Item].Src.bottom += rs; SelectObject(dc, hOldPen); DeleteObject(hPen); } } //---------------------------------------------------------------------------- void __fastcall TDrawForm::DrawCurveLocate(POINT First, POINT Second, POINT Third) { RECT rt, dist; 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; 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[Item].Src.left = rt.left - dist.left; DrawLocate[Item].Src.top = rt.top - dist.top; DrawLocate[Item].Src.right = rt.right + dist.right; DrawLocate[Item].Src.bottom = rt.bottom + dist.bottom; UnionRect(&DrawLocate[Item].Dst, &DrawLocate[Item].Src, &DrawLocate[Item].rtInvalidate); DrawLocate[Item].szPen = PenManagerForm->Pen->Thick; DrawLocate[Item].clPen = MainImageForm->Palette->Color[PaletteForm->DIB256Palette->ChoiceIndex]; DrawLocate[Item].ptFirst.x = rt.left; DrawLocate[Item].ptFirst.y = rt.top; DrawLocate[Item].ptSecond.x = rt.right; DrawLocate[Item].ptSecond.y = rt.bottom; Image->RectEditPaint(DrawLocate[Item].Dst, CurveLocate, NULL); DrawLocate[Item].rtInvalidate = DrawLocate[Item].Src; } //--------------------------------------------------------------------------- void __fastcall TDrawForm::DotCurveLocate(HDC dc, int x, int y, void *pData) { int i, j, k, sx, sy, ex, ey; int ssx, eex, ssy, eey, mx, my; int cnt, dot, grade, total; double xx, yy, llsx, llsy, llex, lley; double tx, ty, a, b, pw, count; double lng, gap; double ct, st, ss, theta, alpha, d1, d2, d3; HPEN hPen = NULL, hOldPen; RECT rt; int ls, rs; if ((hPen = CreatePen(PS_SOLID, DrawLocate[Item].szPen, DrawLocate[Item].clPen))!=NULL) { hOldPen = SelectObject(dc, hPen); ls = PenManagerForm->Pen->Thick >> 1; rs = PenManagerForm->Pen->Thick - ls; pw = PenManagerForm->Pen->Thick; sx = Lsx; sy = Lsy; ex = Lex; ey = Ley; 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; DotLineLocate(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 = pw / 10.0 + 1; Lsx = mx; Lsy = my; xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = mx + xx; Ley = my + yy; 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[Item].Src, &DrawLocate[Item].Src, &rt); Lsx = Lex; Lsy = Ley; xx = xx + count; } if (sx > ex) Lex = sx; else Lex = ex; Ley = sy; 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[Item].Src, &DrawLocate[Item].Src, &rt); count = pw / 10.0 + 1; Lsx = mx; Lsy = my; xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = mx - xx; Ley = my + yy; 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[Item].Src, &DrawLocate[Item].Src, &rt); Lsx = Lex; Lsy = Ley; xx = xx + count; } if (sx < ex) Lex = sx; else Lex = ex; Ley = sy; 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[Item].Src, &DrawLocate[Item].Src, &rt); } 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; else ss = (ty - my) / (tx - mx); theta = M_PI_2 - 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 = (Ltype[Item].value[0] + Ltype[Item].value[1]) * PenManagerForm->Pen->Thick; cnt = lng / gap + 1; grade = (Ltype[Item].value[0] + Ltype[Item].value[1]) * 2; dot = (Ltype[Item].value[0] - 1) * 2; total = cnt * grade; for (i = 0; i < cnt; i++) { j = i * grade + 1 + Ltype[Item].value[1]; k = total - j; llsx = double(ssx * k + 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 + dot; k = k - dot; llex = double(ssx * k + eex * j) / total; lley = alpha * llex * llex; Lex = ct * llex + st * lley + mx + 0.5; Ley = ct * lley - st * llex + my + 0.5; 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[Item].Src, &DrawLocate[Item].Src, &rt); } 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 = (Ltype[Item].value[0] + Ltype[Item].value[1]) * PenManagerForm->Pen->Thick; cnt = lng / gap + 1; grade = (Ltype[Item].value[0] + Ltype[Item].value[1]) * 2; dot = (Ltype[Item].value[0] - 1) * 2; total = cnt * grade; for (i = 0; i < cnt; i++) { j = i * grade + 1 + Ltype[Item].value[1]; k = total - j; llsx = double(ssx * k + 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 + dot; k = k - dot; llex = double(ssx * k + eex * j) / total; lley = alpha * llex * llex; Lex = ct * llex + st * lley + mx + 0.5; Ley = ct * lley - st * llex + my + 0.5; 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[Item].Src, &DrawLocate[Item].Src, &rt); } } Lsx = sx; Lex = ex; Lsy = sy; Ley = ey; DrawLocate[Item].Src.left -= ls; DrawLocate[Item].Src.top -= ls; DrawLocate[Item].Src.right += rs; DrawLocate[Item].Src.bottom += rs; SelectObject(dc, hOldPen); DeleteObject(hPen); } } //---------------------------------------------------------------------------- void __fastcall TDrawForm::DrawDotCurveLocate(POINT First, POINT Second, POINT Third) { RECT rt, dist; 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; 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[Item].Src.left = rt.left - dist.left; DrawLocate[Item].Src.top = rt.top - dist.top; DrawLocate[Item].Src.right = rt.right + dist.right; DrawLocate[Item].Src.bottom = rt.bottom + dist.bottom; UnionRect(&DrawLocate[Item].Dst, &DrawLocate[Item].Src, &DrawLocate[Item].rtInvalidate); DrawLocate[Item].szPen = PenManagerForm->Pen->Thick; DrawLocate[Item].clPen = MainImageForm->Palette->Color[PaletteForm->DIB256Palette->ChoiceIndex]; DrawLocate[Item].ptFirst.x = rt.left; DrawLocate[Item].ptFirst.y = rt.top; DrawLocate[Item].ptSecond.x = rt.right; DrawLocate[Item].ptSecond.y = rt.bottom; Image->RectEditPaint(DrawLocate[Item].Dst, DotCurveLocate, NULL); DrawLocate[Item].rtInvalidate = DrawLocate[Item].Src; } //--------------------------------------------------------------------------- void __fastcall TDrawForm::DotRectangleLocate(HDC dc, int x, int y, void *pData) { int ssx, ssy, eex, eey, sx, sy, ex, ey, lx, ly, lng, l; HPEN hPen = NULL, hOldPen; if ((hPen = CreatePen(PS_SOLID, DrawLocate[Item].szPen, DrawLocate[Item].clPen))!=NULL) { hOldPen = SelectObject(dc, hPen); ssx = Tstitch.l[1].sx; ssy = Tstitch.l[1].sy; eex = Tstitch.l[1].ex; eey = Tstitch.l[1].ey; if (Item == TD_SQUR) { sx = Tstitch.sx; sy = Tstitch.sy; ex = Tstitch.ex; ey = Tstitch.ey; lx = ex - sx; ly = ey - sy; if (abs(lx) > abs(ly)) lng = ly; else lng = lx; l = abs(lng); if (lx * ly > 0) { Tstitch.l[1].sx = sx; Tstitch.l[1].sy = sy; Tstitch.l[1].ex = sx; Tstitch.l[1].ey = sy + lng; fit_dot_line(dc, x, y); Tstitch.l[1].ex = sx + lng; Tstitch.l[1].ey = sy; fit_dot_line(dc, x, y); Tstitch.l[1].sx = sx + lng; Tstitch.l[1].sy = sy + lng; Tstitch.l[1].ex = sx; Tstitch.l[1].ey = sy + lng; fit_dot_line(dc, x, y); Tstitch.l[1].ex = sx + lng; Tstitch.l[1].ey = sy; fit_dot_line(dc, x, y); } else { if (lx < 0) l = l * (-1); Tstitch.l[1].sx = sx; Tstitch.l[1].sy = sy; Tstitch.l[1].ex = sx; Tstitch.l[1].ey = sy - l; fit_dot_line(dc, x, y); Tstitch.l[1].ex = sx + l; Tstitch.l[1].ey = sy; fit_dot_line(dc, x, y); Tstitch.l[1].sx = sx + l; Tstitch.l[1].sy = sy - l; Tstitch.l[1].ex = sx; Tstitch.l[1].ey = sy - l; fit_dot_line(dc, x, y); Tstitch.l[1].ex = sx + l; Tstitch.l[1].ey = sy; fit_dot_line(dc, x, y); } l = abs(l) + PenManagerForm->Pen->Thick; switch (MainImageForm->CurrentUnit) { case uDot : eLength1->Text = l; break; case uInch: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)l / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)l / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); } } else if (Item == TD_RECT) { sx = Tstitch.sx; sy = Tstitch.sy; ex = Tstitch.ex; ey = Tstitch.ey; Tstitch.l[1].sx = sx; Tstitch.l[1].sy = sy; Tstitch.l[1].ex = ex; Tstitch.l[1].ey = sy; fit_dot_line(dc, x, y); Tstitch.l[1].ex = sx; Tstitch.l[1].ey = ey; fit_dot_line(dc, x, y); Tstitch.l[1].sx = ex; Tstitch.l[1].sy = ey; Tstitch.l[1].ex = sx; Tstitch.l[1].ey = ey; fit_dot_line(dc, x, y); Tstitch.l[1].ex = ex; Tstitch.l[1].ey = sy; fit_dot_line(dc, x, y); lx = abs(ex - sx) + PenManagerForm->Pen->Thick; ly = abs(ey - sy) + PenManagerForm->Pen->Thick; switch (MainImageForm->CurrentUnit) { case uDot : eLength1->Text = lx; eLength2->Text = ly; break; case uInch: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)lx / MainImageForm->CanvasInfor.DotsPerInch))); eLength2->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)ly / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)lx / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); eLength2->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)ly / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); } } Tstitch.l[1].sx = ssx; Tstitch.l[1].sy = ssy; Tstitch.l[1].ex = eex; Tstitch.l[1].ey = eey; SelectObject(dc, hOldPen); DeleteObject(hPen); } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::DrawDotRectangleLocate(RECT rc) { RECT rt, Src, Dst; int ls, rs; TPItemImage *Image = MainImageForm->iMainImage; ls = PenManagerForm->Pen->Thick >> 1; rs = PenManagerForm->Pen->Thick - ls; rt.left = min(rc.left, rc.right); rt.top = min(rc.top, rc.bottom); rt.right = max(rc.left, rc.right); rt.bottom = max(rc.top, rc.bottom); Src.left = rt.left - ls * 2; Src.top = rt.top - ls * 2; Src.right = rt.right + rs * 2; Src.bottom = rt.bottom + rs * 2; UnionRect(&Dst, &Src, &DrawLocate[Item].rtInvalidate); DrawLocate[Item].szPen = PenManagerForm->Pen->Thick; DrawLocate[Item].clPen = MainImageForm->Palette->Color[PaletteForm->DIB256Palette->ChoiceIndex]; DrawLocate[Item].ptFirst.x = rt.left; DrawLocate[Item].ptFirst.y = rt.top; DrawLocate[Item].ptSecond.x = rt.right; DrawLocate[Item].ptSecond.y = rt.bottom; Image->RectEditPaint(Dst, DotRectangleLocate, NULL); DrawLocate[Item].rtInvalidate = Src; } //--------------------------------------------------------------------------- void __fastcall TDrawForm::RectangleLocate(HDC dc, int x, int y, void *pData) { HPEN hPen = NULL, hOldPen; HBRUSH hOldBrush; if ((hPen = CreatePen(PS_SOLID, DrawLocate[Item].szPen, DrawLocate[Item].clPen))!=NULL) { hOldPen = SelectObject(dc, hPen); hOldBrush = SelectObject(dc, GetStockObject(NULL_BRUSH)); Rectangle(dc, DrawLocate[Item].ptFirst.x - x, DrawLocate[Item].ptFirst.y - y, DrawLocate[Item].ptSecond.x - x, DrawLocate[Item].ptSecond.y - y); SelectObject(dc, hOldBrush); SelectObject(dc, hOldPen); DeleteObject(hPen); } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::DrawRectangleLocate(RECT rc) { RECT rt, Src, Dst; int ls, rs; TPItemImage *Image = MainImageForm->iMainImage; ls = PenManagerForm->Pen->Thick >> 1; rs = PenManagerForm->Pen->Thick - ls; rt.left = min(rc.left, rc.right); rt.top = min(rc.top, rc.bottom); rt.right = max(rc.left, rc.right); rt.bottom = max(rc.top, rc.bottom); Src.left = rt.left - ls * 2; Src.top = rt.top - ls * 2; Src.right = rt.right + rs * 2; Src.bottom = rt.bottom + rs * 2; UnionRect(&Dst, &Src, &DrawLocate[Item].rtInvalidate); DrawLocate[Item].szPen = PenManagerForm->Pen->Thick; DrawLocate[Item].clPen = MainImageForm->Palette->Color[PaletteForm->DIB256Palette->ChoiceIndex]; DrawLocate[Item].ptFirst.x = rt.left; DrawLocate[Item].ptFirst.y = rt.top; DrawLocate[Item].ptSecond.x = rt.right; DrawLocate[Item].ptSecond.y = rt.bottom; Image->RectEditPaint(Dst, RectangleLocate, NULL); DrawLocate[Item].rtInvalidate = Src; } //--------------------------------------------------------------------------- void __fastcall TDrawForm::EllipseLocate(HDC dc, int x, int y, void *pData) { HPEN hPen = NULL, hOldPen; HBRUSH hOldBrush; if ((hPen = CreatePen(PS_SOLID, DrawLocate[Item].szPen, DrawLocate[Item].clPen))!=NULL) { hOldPen = SelectObject(dc, hPen); hOldBrush = SelectObject(dc, GetStockObject(NULL_BRUSH)); Ellipse(dc, DrawLocate[Item].ptFirst.x - x, DrawLocate[Item].ptFirst.y - y, DrawLocate[Item].ptSecond.x - x, DrawLocate[Item].ptSecond.y - y); SelectObject(dc, hOldBrush); SelectObject(dc, hOldPen); DeleteObject(hPen); } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::DrawEllipseLocate(RECT rc) { RECT rt, Src, Dst; int ls, rs; TPItemImage *Image = MainImageForm->iMainImage; ls = PenManagerForm->Pen->Thick >> 1; rs = PenManagerForm->Pen->Thick - ls; rt.left = min(rc.left, rc.right); rt.top = min(rc.top, rc.bottom); rt.right = max(rc.left, rc.right); rt.bottom = max(rc.top, rc.bottom); Src.left = rt.left - 10; Src.top = rt.top - 10; Src.right = rt.right + 10; Src.bottom = rt.bottom + 10; UnionRect(&Dst, &Src, &DrawLocate[Item].rtInvalidate); DrawLocate[Item].szPen = PenManagerForm->Pen->Thick; DrawLocate[Item].clPen = MainImageForm->Palette->Color[PaletteForm->DIB256Palette->ChoiceIndex]; DrawLocate[Item].ptFirst.x = rt.left + ls; DrawLocate[Item].ptFirst.y = rt.top + ls; DrawLocate[Item].ptSecond.x = rt.right - rs; DrawLocate[Item].ptSecond.y = rt.bottom - rs; Image->RectEditPaint(Dst, EllipseLocate, NULL); DrawLocate[Item].rtInvalidate = Src; } //--------------------------------------------------------------------------- // Public Function //--------------------------------------------------------------------------- void __fastcall TDrawForm::InitForm() { int i; TPItemImage *Image = MainImageForm->iMainImage; ParentHeight = Parent->Height+20; ClientHeight = 231; Parent->Height = ParentHeight+ClientHeight; if (PenManagerForm->sbMask->Down) { if (Image->Bitmap->BitsPerPixel==8) { MainImageForm->OnSetHLine = MainImageForm->SetHLineMask8; if (PenManagerForm->chDelete->Checked) { MainImageForm->MaskPixel = 0x00; } else { MainImageForm->MaskPixel = 0x0F; } } else { if (PenManagerForm->chDelete->Checked) { MainImageForm->OnSetHLine = MainImageForm->SetHLineMaskDelete24; MainImageForm->MaskPixel = 0x00; } else { MainImageForm->OnSetHLine = MainImageForm->SetHLineMask24; MainImageForm->MaskPixel = 0x80; } } } else { if (Image->Bitmap->BitsPerPixel==8) { MainImageForm->OnSetHLine = MainImageForm->SetHLine8ColorNo; } else { MainImageForm->OnSetHLine = MainImageForm->SetHLine24; } } for (i = 0; i <= 6; i++) { Ltype[i].sw = 0; Ltype[i].value[0] = 3; Ltype[i].value[1] = 1; } ReadIniFile(); isw = 0; Asw = 0; Lsw = 0; Dsw = 0; step = 0; undos = 0; IsDraw = false; view(); } //--------------------------------------------------------------------------- void __fastcall TDrawForm::ReadIniFile() { TIniFile *DrawIni = NULL; DrawIni = new TIniFile(DirectoryItem + "\\Draw.ini"); if (DrawIni) { Item = DrawIni->ReadInteger("Draw", "Type", 0); Ltype[Item].sw = DrawIni->ReadInteger("LineType", "DS", 0); Ltype[Item].value[0] = DrawIni->ReadInteger("LineType", "Dot", 3); Ltype[Item].value[1] = DrawIni->ReadInteger("LineType", "Gap", 1); Line_type = DrawIni->ReadInteger("Line", "Type", 1); Curve_type = DrawIni->ReadInteger("Curve", "Type", 1); fill_not = DrawIni->ReadInteger("Fill", "Ok", 0); delete DrawIni; } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::WriteIniFile() { TIniFile *DrawIni = NULL; DrawIni = new TIniFile(DirectoryItem + "\\Draw.ini"); if (DrawIni) { DrawIni->WriteInteger("Draw", "Type", Item); DrawIni->WriteInteger("LineType", "DS", Ltype[Item].sw); DrawIni->WriteInteger("LineType", "Dot", Ltype[Item].value[0]); DrawIni->WriteInteger("LineType", "Gap", Ltype[Item].value[1]); DrawIni->WriteInteger("Line", "Type", Line_type); DrawIni->WriteInteger("Curve", "Type", Curve_type); DrawIni->WriteInteger("Fill", "Ok", fill_not); delete DrawIni; } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::ExitForm(void) { WriteIniFile(); iMainImageChange(); } //--------------------------------------------------------------------------- void __fastcall TDrawForm::view(void) { TPItemImage *Image = MainImageForm->iMainImage; Image->Repaint(); if (Item == TD_OUT) { sbOut->Down = true; lLineType->Visible = false; lFillType->Visible = false; lLength->Visible = false; lDotType->Visible = false; lDotLength->Visible = false; lDotSpace->Visible = false; lAngle->Visible = false; eLength1->Visible = false; eLength2->Visible = false; eAngle->Visible = false; eDotLength->Visible = false; eDotSpace->Visible = false; btnFirst->Visible = false; } else if (Item == TD_LINE) { sbLine->Down = true; lLineType->Visible = true; lFillType->Visible = false; lLength->Visible = true; lLength->Caption = IDS_COMMON_LENGTH; lDotType->Visible = true; lAngle->Visible = true; eLength1->Visible = true; eLength2->Visible = false; eAngle->Visible = true; if (Ltype[TD_LINE].sw == 0) { lDotType->Caption = IDS_SOLID; lDotLength->Visible = false; lDotSpace->Visible = false; eDotLength->Visible = false; eDotSpace->Visible = false; } else if (Ltype[TD_LINE].sw == 1) { lDotType->Caption = IDS_DOT; lDotLength->Visible = true; lDotSpace->Visible = true; eDotLength->Visible = true; eDotSpace->Visible = true; } btnFirst->Caption = IDS_COMMON_FIRSTPOINT; btnFirst->Visible = true; if (Line_type == 0) lLineType->Caption = IDS_COMMON_SEPARATELINE; else if (Line_type == 1) lLineType->Caption = IDS_COMMON_CONTINUOUSLINE; } else if (Item == TD_CURVE) { sbCurve->Down = true; lLineType->Visible = true; lFillType->Visible = false; lLength->Visible = false; lDotType->Visible = true; lAngle->Visible = false; eLength1->Visible = false; eLength2->Visible = false; eAngle->Visible = false; if (Ltype[TD_CURVE].sw == 0) { lDotType->Caption = IDS_SOLID; lDotLength->Visible = false; lDotSpace->Visible = false; eDotLength->Visible = false; eDotSpace->Visible = false; } else if (Ltype[TD_CURVE].sw == 1) { lDotType->Caption = IDS_DOT; lDotLength->Visible = true; lDotSpace->Visible = true; eDotLength->Visible = true; eDotSpace->Visible = true; } btnFirst->Visible = false; if (Curve_type == 0) lLineType->Caption = IDS_COMMON_SEPARATELINE; else if (Curve_type == 1) lLineType->Caption = IDS_COMMON_CONTINUOUSLINE; } else { lLineType->Visible = false; lFillType->Visible = true; lLength->Visible = true; lDotType->Visible = true; lAngle->Visible = false; eLength1->Visible = true; if (Item == TD_CIRCLE) { sbCircle->Down = true; lLength->Caption = IDS_RADIUS; eLength2->Visible = false; btnFirst->Caption = IDS_LASTCENTER; btnFirst->Visible = true; } else if (Item == TD_ELLIP) { sbEllip->Down = true; lLength->Caption = IDS_AXIS; eLength2->Visible = true; btnFirst->Caption = IDS_LASTCENTER; btnFirst->Visible = true; } else if (Item == TD_SQUR) { sbSquare->Down = true; lLength->Caption = IDS_COMMON_LENGTH; eLength2->Visible = false; btnFirst->Visible = false; } else { sbRect->Down = true; lLength->Caption = IDS_COMMON_LENGTH; eLength2->Visible = true; btnFirst->Visible = false; } eAngle->Visible = false; if (Ltype[Item].sw == 0) { lDotType->Caption = IDS_SOLID; lDotLength->Visible = false; lDotSpace->Visible = false; eDotLength->Visible = false; eDotSpace->Visible = false; } else if (Ltype[Item].sw == 1) { lDotType->Caption = IDS_DOT; lDotLength->Visible = true; lDotSpace->Visible = true; eDotLength->Visible = true; eDotSpace->Visible = true; } if (fill_not == 0) lFillType->Caption = AnsiString(IDS_COMMON_FILL) + " : " + AnsiString(IDS_COMMON_BUTTONNO); else if (fill_not == 1) lFillType->Caption = AnsiString(IDS_COMMON_FILL) + " : " + AnsiString(IDS_COMMON_BUTTONYES); } eDotLength->Text = Ltype[Item].value[0]; eDotSpace->Text = Ltype[Item].value[1]; step = 0; undos = 0; } //--------------------------------------------------------------------------- void __fastcall TDrawForm::DrawMouseDown(TMouseButton Button, TShiftState Shift, int XD, int YD) { RECT rect; int pw; COLORREF c; TPItemImage *Image = MainImageForm->iMainImage; if (Button==mbMiddle || (Shift.Contains(ssShift) && Button==mbLeft)) return; c = PaletteForm->DIB256Palette->GetFGCOLORREF(Image->Bitmap->BitsPerPixel); pw = PenManagerForm->Pen->Thick + 10; BtnClick = true; rect = Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height); switch (Item) { case TD_OUT : if (PenManagerForm->sbMask->Down) { MainImageForm->UndoSave(UK_MASK, rect); if (Image->Bitmap->BitsPerPixel == 8) { MainImageForm->UndoSave(UK_PATTERN, rect); outline(XD, YD); Undo->Read(); ::RepaintImage(); } else { if(!outline_24(XD, YD)) Undo->RemoveLast(); // outline_24(XD, YD); } } else { MainImageForm->UndoSave(UK_PATTERN, rect); if (Image->Bitmap->BitsPerPixel == 8) { if (MainImageForm->Protect==false) { outline(XD, YD); } else { if (MainImageForm->Palette->ColorData[Image->Bitmap->GetPixelColor(XD, YD)]->Protect==0) { outline(XD, YD); } } } else { if(!outline_24(XD, YD)) Undo->RemoveLast(); //outline_24(XD, YD); } } break; case TD_LINE : if (isw == 0) { if (Ltype[TD_LINE].sw == 0) { if (step == 0) { firstln = Point(XD, YD); Lsx = XD; Lsy = YD; Lex = Lsx; Ley = Lsy; DrawLineLocate(Point(Lsx, Lsy), Point(Lex, Ley)); step = 1; } else if (step == 1) { Lex = XD; Ley = YD; if (Line_type == 0) { MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); } else { if (undos == 0) { MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); undos = 1; } } Line(c); if (Line_type == 0) { step = 0; } else if (Line_type == 1) { Lsx = Lex; Lsy = Ley; } } } else if (Ltype[TD_LINE].sw == 1) { if (step == 0) { firstln = Point(XD, YD); Tstitch.l[1].sx = XD; Tstitch.l[1].sy = YD; Tstitch.sx = Tstitch.l[1].sx; Tstitch.sy = Tstitch.l[1].sy; Tstitch.ex = Tstitch.l[1].sx; Tstitch.ey = Tstitch.l[1].sy; Tstitch.l[1].ex = Tstitch.l[1].sx; Tstitch.l[1].ey = Tstitch.l[1].sy; DrawDotLineLocate(Point(Tstitch.l[1].sx, Tstitch.l[1].sy), Point(Tstitch.l[1].ex, Tstitch.l[1].ey)); step = 1; } else if (step == 1) { if (Line_type == 0) { MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); } else { if (undos == 0) { MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); undos = 1; } } dot_line(pmCopy, 1, Ltype[TD_LINE].value, c); if (Line_type == 0) { step = 0; } else if (Line_type == 1) { Tstitch.l[1].sx = Tstitch.l[1].ex; Tstitch.l[1].sy = Tstitch.l[1].ey; } } } } else { Lex = XD; Ley = YD; LenAng_check(XD, YD); if (Line_type == 0) { MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); } else { if (undos == 0) { MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); undos = 1; } } Line(c); if (Line_type == 0) { step = 0; } else if (Line_type == 1) { Lsx = Lex; Lsy = Ley; } isw = 0; } break; case TD_SQUR : if (isw == 0) { if (Ltype[TD_SQUR].sw == 0) { if (step == 0) { Lsx = XD; Lsy = YD; Lex = Lsx; Ley = Lsy; square(pmXor, c); step = 1; } else if (step == 1) { Lex = XD; Ley = YD; MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); square(pmCopy, c); step = 0; } } else if (Ltype[TD_SQUR].sw == 1) { if (step == 0) { Tstitch.l[1].sx = XD; Tstitch.l[1].sy = YD; Tstitch.sx = Tstitch.l[1].sx; Tstitch.sy = Tstitch.l[1].sy; Tstitch.ex = Tstitch.l[1].sx; Tstitch.ey = Tstitch.l[1].sy; Tstitch.l[1].ex = Tstitch.l[1].sx; Tstitch.l[1].ey = Tstitch.l[1].sy; DrawDotRectangleLocate(Rect(Tstitch.l[1].sx, Tstitch.l[1].sy, Tstitch.l[1].ex, Tstitch.l[1].ey)); step = 1; } else if (step == 1) { MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); dotted_square(pmCopy, Ltype[TD_SQUR].value, c); step = 0; } } } else { sqr_len = Sqr_l - pw; Csx = XD; Csy = YD; Lsx = Csx - sqr_len / 2.0; Lsy = Csy - sqr_len / 2.0; if ((Csx >= 0) && (Csx <= sqr_len / 2.0)) Lsx = 0; else if ((Csx >= Image->Bitmap->Width - sqr_len / 2.0) && (Csx <= Image->Bitmap->Width)) Lsx = Image->Bitmap->Width - sqr_len; if ((Csy >= 0) && (Csy <= sqr_len / 2.0)) Lsy = 0; else if ((Csy >= Image->Bitmap->Height - sqr_len / 2.0) && (Csy <= Image->Bitmap->Height)) Lsy = Image->Bitmap->Height - sqr_len; Lex = Lsx + sqr_len - 1; Ley = Lsy + sqr_len - 1; MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); square(pmCopy, c); step = 0; isw = 0; } break; case TD_RECT : if (isw == 0) { if (Ltype[TD_RECT].sw == 0) { if (step == 0) { Lsx = XD; Lsy = YD; Lex = Lsx; Ley = Lsy; rectangle(pmXor, c); step = 1; } else if (step == 1) { Lex = XD; Ley = YD; MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); rectangle(pmCopy, c); step = 0; } } else if (Ltype[TD_RECT].sw == 1) { if (step == 0) { Tstitch.l[1].sx = XD; Tstitch.l[1].sy = YD; Tstitch.sx = Tstitch.l[1].sx; Tstitch.sy = Tstitch.l[1].sy; Tstitch.ex = Tstitch.l[1].sx; Tstitch.ey = Tstitch.l[1].sy; Tstitch.l[1].ex = Tstitch.l[1].sx; Tstitch.l[1].ey = Tstitch.l[1].sy; DrawDotRectangleLocate(Rect(Tstitch.l[1].sx, Tstitch.l[1].sy, Tstitch.l[1].ex, Tstitch.l[1].ey)); step = 1; } else if (step == 1) { MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); dotted_rectangle(pmCopy, Ltype[TD_RECT].value, c); step = 0; } } } else { MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); rec_x = Rec_lx - pw; rec_y = Rec_ly - pw; Csx = XD; Csy = YD; Lsx = Csx - rec_x / 2.0; Lsy = Csy - rec_y / 2.0; if ((Csx >= 0) && (Csx <= rec_x / 2.0)) Lsx = 0; else if ((Csx >= Image->Bitmap->Width - rec_x / 2.0) && (Csx < Image->Bitmap->Width)) Lsx = (Image->Bitmap->Width - 1) - rec_x; if ((Csy>=0) && (Csy <= rec_y / 2.0)) Lsy = 0; else if ((Csy >= Image->Bitmap->Height - rec_y / 2.0) && (Csy < Image->Bitmap->Height)) Lsy = (Image->Bitmap->Height - 1) - rec_y; Lex = Lsx + rec_x - 1; Ley = Lsy + rec_y - 1; rectangle(pmCopy, c); step = 0; isw = 0; } break; case TD_CIRCLE : if (isw == 0) { if (step == 0) { Csx = XD; Csy = YD; Lsx = Csx; Lsy = Csy; cirlast.x = Csx; cirlast.y = Csy; circle(pmXor, c); step = 1; } else if (step == 1) { Lsx = XD; Lsy = YD; MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); if (Ltype[TD_CIRCLE].sw == 0) { circle(pmCopy, c); } else if (Ltype[TD_CIRCLE].sw == 1) { dotted_circle(pmCopy, Ltype[TD_CIRCLE].value); } step = 0; } } else { Tradius = Radius - pw / 2.0; Csx = XD; Csy = YD; cirlast.x = Csx; cirlast.y = Csy; Lsx = Csx + Tradius - 1; Lsy = Csy + Tradius - 1; if (Lsx > Image->Bitmap->Width) Lsx = Csx - Tradius - 1; MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); if (Ltype[TD_CIRCLE].sw == 0) { circle(pmCopy, c); } else if (Ltype[TD_CIRCLE].sw == 1) { dotted_circle(pmCopy, Ltype[TD_CIRCLE].value); } step = 0; isw = 0; } break; case TD_ELLIP : if (isw == 0) { if (step == 0) { Csx = XD; Csy = YD; Lsx = Csx; Lsy = Csy; elliplast.x = Csx; elliplast.y = Csy; ellipse(pmXor, c); step = 1; } else if (step == 1) { Lsx = XD; Lsy = YD; MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); if (Ltype[TD_ELLIP].sw == 0) { ellipse(pmCopy, c); } else if (Ltype[TD_ELLIP].sw == 1) { dotted_ellipse(pmCopy, Ltype[TD_ELLIP].value); } step = 0; } } else { MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); ell_x = Ell_rx - pw / 2.0; ell_y = Ell_ry - pw / 2.0; Csx = XD; Csy = YD; elliplast.x = Csx; elliplast.y = Csy; Lsx = Csx + ell_x - 1; Lsy = Csy + ell_y - 1; if (Lsx > Image->Bitmap->Width) Lsx = Csx - ell_x - 1; if (Lsy > Image->Bitmap->Height) Lsy = Csy - ell_y - 1; if (Ltype[TD_ELLIP].sw == 0) { ellipse(pmCopy, c); } else if (Ltype[TD_ELLIP].sw == 1) { dotted_ellipse(pmCopy, Ltype[TD_ELLIP].value); } step = 0; isw = 0; } break; case TD_CURVE : if (Ltype[TD_CURVE].sw == 0) { if (step == 0) { Lsx = XD; Lsy = YD; Lex = Lsx; Ley = Lsy; DrawLineLocate(Point(Lsx, Lsy), Point(Lex, Ley)); step = 1; } else if (step == 1) { Lex = XD; Ley = YD; Csx = Lex; Csy = Ley; DrawLineLocate(Point(Lsx, Lsy), Point(Lex, Ley)); step = 2; } else if (step == 2) { Csx = XD; Csy = YD; if (Curve_type == 0) { MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); } else { if (undos == 0) { MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); undos = 1; } } curve(pmCopy, c); if (Curve_type == 0) { step = 0; } else if (Curve_type == 1) { step = 1; Lsx = Lex; Lsy = Ley; } } } else if (Ltype[TD_CURVE].sw == 1) { if (step == 0) { Tstitch.l[1].sx = XD; Tstitch.l[1].sy = YD; Tstitch.sx = Tstitch.l[1].sx; Tstitch.sy = Tstitch.l[1].sy; Tstitch.ex = Tstitch.l[1].sx; Tstitch.ey = Tstitch.l[1].sy; Tstitch.l[1].ex = Tstitch.l[1].sx; Tstitch.l[1].ey = Tstitch.l[1].sy; Lsx = Tstitch.sx; Lsy = Tstitch.sy; Lex = Lsx; Ley = Lsy; DrawDotLineLocate(Point(Tstitch.l[1].sx, Tstitch.l[1].sy), Point(Tstitch.l[1].ex, Tstitch.l[1].ey)); step = 1; } else if (step == 1) { Lex = XD; Ley = YD; Csx = Lex; Csy = Ley; DrawDotLineLocate(Point(Tstitch.l[1].sx, Tstitch.l[1].sy), Point(Tstitch.l[1].ex, Tstitch.l[1].ey)); step = 2; } else { Csx = XD; Csy = YD; if (Curve_type == 0) { MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); } else { if (undos == 0) { MainImageForm->UndoSave(PenManagerForm->sbMask->Down ? UK_MASK : UK_PATTERN, rect); undos = 1; } } dot_curve(pmCopy, Ltype[TD_CURVE].value, c); if (Curve_type == 0) { step = 0; } else if (Curve_type == 1) { step = 1; Tstitch.l[1].sx = Lex; Tstitch.l[1].sy = Ley; 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; } } } } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::DrawMouseMove(TShiftState Shift, int XD, int YD) { int pw; Byte c; TPItemImage *Image = MainImageForm->iMainImage; c = PaletteForm->DIB256Palette->ChoiceIndex; pw = PenManagerForm->Pen->Thick; switch (Item) { case TD_LINE : if (isw == 0) { if (Ltype[TD_LINE].sw == 0) { if (step == 1) { Lex = XD; Ley = YD; DrawLineLocate(Point(Lsx, Lsy), Point(Lex, Ley)); LengthAngle(); } } else if (Ltype[TD_LINE].sw == 1) { if (step == 1) { Tstitch.l[1].ex = XD; Tstitch.l[1].ey = YD; Tstitch.ex = Tstitch.l[1].ex; Tstitch.ey = Tstitch.l[1].ey; DrawDotLineLocate(Point(Tstitch.l[1].sx, Tstitch.l[1].sy), Point(Tstitch.l[1].ex, Tstitch.l[1].ey)); LengthAngle(); } } } else { Lex = XD; Ley = YD; LenAng_check(XD, YD); DrawLineLocate(Point(Lsx, Lsy), Point(Lex, Ley)); LengthAngle(); } break; case TD_SQUR : if (isw == 0) { if (Ltype[TD_SQUR].sw == 0) { if (step == 1) { Lex = XD; Ley = YD; square(pmXor, c); } } else if (Ltype[TD_SQUR].sw == 1) { if (step == 1) { Tstitch.l[1].ex = XD; Tstitch.l[1].ey = YD; Tstitch.ex = Tstitch.l[1].ex; Tstitch.ey = Tstitch.l[1].ey; DrawDotRectangleLocate(Rect(Tstitch.l[1].sx, Tstitch.l[1].sy, Tstitch.l[1].ex, Tstitch.l[1].ey)); } } } else { sqr_len = Sqr_l - pw; Csx = XD; Csy = YD; Lsx = Csx - sqr_len / 2.0; Lsy = Csy - sqr_len / 2.0; if ((Csx >= 0) && (Csx <= sqr_len / 2.0)) Lsx = 0; else if ((Csx >= Image->Bitmap->Width - sqr_len / 2.0) && (Csx <= Image->Bitmap->Width)) Lsx = Image->Bitmap->Width - sqr_len; if ((Csy >= 0) && (Csy <= sqr_len / 2.0)) Lsy = 0; else if ((Csy >= Image->Bitmap->Height - sqr_len / 2.0) && (Csy <= Image->Bitmap->Height)) Lsy = Image->Bitmap->Height - sqr_len; Lex = Lsx + sqr_len - 1; Ley = Lsy + sqr_len - 1; square(pmXor, c); } break; case TD_RECT : if (isw == 0) { if (Ltype[TD_RECT].sw == 0) { if (step == 1) { Lex = XD; Ley = YD; rectangle(pmXor, c); } } else if (Ltype[TD_RECT].sw == 1) { if (step == 1) { Tstitch.l[1].ex = XD; Tstitch.l[1].ey = YD; Tstitch.ex = Tstitch.l[1].ex; Tstitch.ey = Tstitch.l[1].ey; DrawDotRectangleLocate(Rect(Tstitch.l[1].sx, Tstitch.l[1].sy, Tstitch.l[1].ex, Tstitch.l[1].ey)); } } } else { rec_x = Rec_lx - pw; rec_y = Rec_ly - pw; Csx = XD; Csy = YD; Lsx = Csx - rec_x / 2.0; Lsy = Csy - rec_y / 2.0; if ((Csx >= 0) && (Csx <= rec_x / 2.0)) Lsx = 0; else if ((Csx >= Image->Bitmap->Width - rec_x / 2.0) && (Csx < Image->Bitmap->Width)) Lsx = (Image->Bitmap->Width - 1) - rec_x; if ((Csy >= 0) && (Csy <= rec_y / 2.0)) Lsy = 0; else if ((Csy >= Image->Bitmap->Height - rec_y / 2.0) && (Csy < Image->Bitmap->Height)) Lsy = (Image->Bitmap->Height - 1) - rec_y; Lex = Lsx + rec_x - 1; Ley = Lsy + rec_y - 1; rectangle(pmXor, c); } break; case TD_CIRCLE : if (isw == 0) { if (step == 1) { Lsx = XD; Lsy = YD; circle(pmXor, c); } } else { Tradius = Radius - pw / 2.0; Csx = XD; Csy = YD; Lsx = Csx + Tradius - 1; Lsy = Csy + Tradius - 1; if (Lsx > Image->Bitmap->Width) Lsx = Csx - Tradius; circle(pmXor, c); } break; case TD_ELLIP : if (isw == 0) { if (step == 1) { Lsx = XD; Lsy = YD; ellipse(pmXor, c); } } else { ell_x = Ell_rx - pw / 2.0; ell_y = Ell_ry - pw / 2.0; Csx = XD; Csy = YD; Lsx = Csx + ell_x - 1; Lsy = Csy + ell_y - 1; if (Lsx > Image->Bitmap->Width) Lsx = Csx - ell_x - 1; if (Lsy > Image->Bitmap->Height) Lsy = Csy - ell_y - 1; ellipse(pmXor, c); } break; case TD_CURVE : if (Ltype[TD_CURVE].sw == 0) { if (step == 1) { Lex = XD; Ley = YD; DrawLineLocate(Point(Lsx, Lsy), Point(Lex, Ley)); } else if (step == 2) { Csx = XD; Csy = YD; DrawCurveLocate(Point(Lsx, Lsy), Point(Lex, Ley), Point(Csx, Csy)); } } else if (Ltype[TD_CURVE].sw == 1) { if (step == 1) { Tstitch.l[1].ex = XD; Tstitch.l[1].ey = YD; Tstitch.ex = Tstitch.l[1].ex; Tstitch.ey = Tstitch.l[1].ey; Lex = XD; Ley = YD; DrawDotLineLocate(Point(Tstitch.l[1].sx, Tstitch.l[1].sy), Point(Tstitch.l[1].ex, Tstitch.l[1].ey)); } else if (step == 2) { Tstitch.l[1].ex = XD; Tstitch.l[1].ey = YD; Tstitch.ex = Tstitch.l[1].ex; Tstitch.ey = Tstitch.l[1].ey; Csx = XD; Csy = YD; DrawDotCurveLocate(Point(Tstitch.l[1].sx, Tstitch.l[1].sy), Point(Tstitch.l[1].ex, Tstitch.l[1].ey), Point(Csx, Csy)); } } } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::DrawMouseUp(int XD, int YD) { BtnClick = false; } //--------------------------------------------------------------------------- void __fastcall TDrawForm::iMainImageKeyDown(int Key) { if (Key == 120 || Key == 88) { // 120: x 88: X down , 122 : z 90: Z down iMainImageChange(); if (Line_type == 1 || Curve_type == 1) { step = 0; } } else if (Key == 122 || Key == 90) { if (Item == TD_LINE && Ltype[TD_LINE].sw == 0) { isw = 1; Line_angle = 0; Lsw = 0; Asw = 2; } } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::iMainImageKeyUp(int Key) { if (Key == 90) { // 88 : x 90 : z if (Item == TD_LINE && Ltype[TD_LINE].sw == 0) { isw = 0; Lsw = 0; Asw = 0; } } } //--------------------------------------------------------------------------- void __fastcall TDrawForm::iMainImageChange(void) { MainImageForm->iMainImage->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TDrawForm::FGChange(int Value) { PenManagerForm->PenShapeChange(Value); iMainImageChange(); } //--------------------------------------------------------------------------- void __fastcall TDrawForm::LengthAngle() { double p; int lx, ly, dx, dy; if (Ltype[TD_LINE].sw == 0) { dx = Lex - Lsx; dy = Ley - Lsy; }else if (Ltype[TD_LINE].sw == 1) { dx = Tstitch.l[1].ex - Tstitch.l[1].sx; dy = Tstitch.l[1].ey - Tstitch.l[1].sy; } if (dy < 0) { p = (atan2((double)dy, (double)dx) + 2 * M_PI) * 180.0 / M_PI; } else { if ((dx == 0) && (dy == 0)) p = 0; else p = atan2((double)dy, (double)dx) * 180.0 / M_PI; } eAngle->Text = Format("%3.1f", OPENARRAY(TVarRec, (p))); lx = abs(dx); ly = abs(dy); p = sqrt(lx * lx + ly * ly) + PenManagerForm->Pen->Thick; switch (MainImageForm->CurrentUnit) { case uDot : eLength1->Text = p; break; case uInch: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, (p / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, (p / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); } /* dx = Tstitch.l[1].ex - Tstitch.l[1].sx; dy = Tstitch.l[1].ey - Tstitch.l[1].sy; if (dy < 0) { p = (atan2(dy, dx) + 2 * M_PI) * 180.0 / M_PI; } else { if ((dx == 0) && (dy == 0)) p = 0; else p = (atan2(dy, dx)) * 180.0 / M_PI; } eAngle->Text = Format("%3.1f", OPENARRAY(TVarRec, (p))); lx = abs(dx) + 1; ly = abs(dy) + 1; p = sqrt(lx * lx + ly * ly) + PenManagerForm->Pen->Thick; switch (MainImageForm->CurrentUnit) { case uDot : eLength1->Text = p; break; case uInch: eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, (p / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : eLength1->Text = Format("%.2f", OPENARRAY(TVarRec, (p / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); }*/ } //--------------------------------------------------------------------------- void __fastcall TDrawForm::iMainImageMouseLeave(){ } //---------------------------------------------------------------------------