//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "MarkDraw_F.h" #include "MainImage.h" #include "PenManager.h" #include "Undo.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- TMarkDrawForm *MarkDrawForm; //--------------------------------------------------------------------------- __fastcall TMarkDrawForm::TMarkDrawForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::sbItemClick(TObject *Sender) { TSpeedButton *sp = (TSpeedButton *)Sender; step = 0; Item = sp->Tag; // Decide Draw Type stContinue->Enabled = sbLine->Down || sbCurve->Down; stFill->Enabled = sbSquare->Down || sbRectangle->Down || sbCircle->Down || sbEllipse->Down; sbStartPoint->Enabled = sbLine->Down && Continuous; IsDraw = false; MainImageForm->iMainImage->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::stContinueClick(TObject *Sender) { if (Continuous) { stContinue->Caption = IDS_COMMON_SEPARATELINE; Continuous = false; sbStartPoint->Enabled = false; step = 0; } else { stContinue->Caption = IDS_COMMON_CONTINUOUSLINE; Continuous = true; sbStartPoint->Enabled = true; } IsDraw = false; MainImageForm->iMainImage->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::stFillClick(TObject *Sender) { if (Fill) { stFill->Caption = AnsiString(IDS_COMMON_FILL) +" : " + AnsiString(IDS_COMMON_BUTTONNO); Fill = false; } else { stFill->Caption = AnsiString(IDS_COMMON_FILL) +" : "+AnsiString(IDS_COMMON_BUTTONYES); Fill = true; } IsDraw = false; MainImageForm->iMainImage->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::sbStartPointClick(TObject *Sender) { DrawLine(First.x, First.y, Start.x, Start.y); iMainImageChange(); step = 0; } //--------------------------------------------------------------------------- /// Private Method ////////////////////////////////////////////////////////// //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::DrawLine(int sx, int sy, int ex, int ey) { int exx, exy; TTexpiaBitmap *bmp; Byte MarkSet; bool undo = true; if (MainImageForm->Arrange->Dmark.set & 0x3F) { if (MainImageForm->Arrange->Dmark.set & 0x40) { MarkSet = 0x41; } else { MarkSet = 0x01; } } else { if (MainImageForm->Arrange->Dmark.set & 0x40) { MarkSet = 0x40; } else { MarkSet = 0x00; } } bmp = &MainImageForm->iMainImage->ArrayBitmap[1]; pw = PenManagerForm->Pen->Thick; if (!(undo = MainImageForm->UndoSave(UK_MARK, Rect(0, 0, bmp->Width, bmp->Height), true))) goto fail; if (bmp->StartScanLine() == false) goto fail; PartLine(MarkSet, sx, sy, ex, ey, bmp); bmp->StopScanLine(); // 7.41 DrawPenWidthÀ¸·Î À̵¿ MainImageForm->iMainImage->SetMark(); // ????????????????????? ::RepaintImage(); return; fail: if (undo) Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::PartLine(Byte set, int sx, int sy, int ex, int ey, TTexpiaBitmap *bmp) { double a, b; int x, y; Byte *IP; if (sx == ex) { if (sy > ey) { for (y = ey; y < sy; y++) { DrawPenWidth(bmp, sx, y, set); } } else { for (y = sy; y < ey; y++) { DrawPenWidth(bmp, sx, y, set); } } } else { a = (double)(ey-sy) / (ex-sx); b = sy-a*sx; if (fabs(a)<=1) { if (sx > ex) { for (x = ex; x < sx; x++) { y = a*x+b; DrawPenWidth(bmp, x, y, set); } } else { for (x = sx; x < ex; x++) { y = a*x+b; DrawPenWidth(bmp, x, y, set); } } } else { if (sy > ey) { for (y = ey; y < sy; y++) { x = (y-b)/a; DrawPenWidth(bmp, x, y, set); } } else { for (y = sy; y < ey; y++) { x = (y-b)/a; DrawPenWidth(bmp, x, y, set); } } } } } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::DrawCurve() { int sx, sy, ex, ey, mx, my, nDrawMode, hDCState, Lsx, Lsy, Lex, Ley; double ct, st, ss, theta, alpha, d1, d2, d3; double tx, ty, a, b, xx, yy; TTexpiaBitmap *bmp; bool undo = false; Byte MarkSet; if (MainImageForm->Arrange->Dmark.set & 0x3F) { if (MainImageForm->Arrange->Dmark.set & 0x40) { MarkSet = 0x41; } else { MarkSet = 0x01; } } else { if (MainImageForm->Arrange->Dmark.set & 0x40) { MarkSet = 0x40; } else { MarkSet = 0x00; } } bmp = &MainImageForm->iMainImage->ArrayBitmap[1]; if (!(undo = MainImageForm->UndoSave(UK_MARK, Rect(0, 0, bmp->Width, bmp->Height) , true))) goto fail; if (bmp->StartScanLine() == false) goto fail; sx = Lsx = First.x; sy = Lsy = First.y; ex = Lex = Second.x; ey = Ley = Second.y; mx = Third.x; my = Third.y; pw = PenManagerForm->Pen->Thick; 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)) { PartLine(MarkSet, Lsx, Lsy, Lex, Ley, bmp); } 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); Lsx = mx; Lsy = my; xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = mx + xx; Ley = my + yy; PartLine(MarkSet, Lsx, Lsy, Lex, Ley, bmp); Lsx = Lex; Lsy = Ley; xx ++; } if (sx > ex) Lex = sx; else Lex = ex; Ley = sy; PartLine(MarkSet, Lsx, Lsy, Lex, Ley, bmp); Lsx = mx; Lsy = my; xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = mx - xx; Ley = my + yy; PartLine(MarkSet, Lsx, Lsy, Lex, Ley, bmp); Lsx = Lex; Lsy = Ley; xx++; } if (sx < ex) Lex = sx; else Lex = ex; Ley = sy; PartLine(MarkSet, Lsx, Lsy, Lex, Ley, bmp); } 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); 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; PartLine(MarkSet, Lsx, Lsy, Lex, Ley, bmp); Lsx = Lex; Lsy = Ley; xx--; } } else { xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = ct * xx + st * yy + mx; Ley = ct * yy - st * xx + my; PartLine(MarkSet, Lsx, Lsy, Lex, Ley, bmp); Lsx = Lex; Lsy = Ley; xx++; } } Lex = sx; Ley = sy; PartLine(MarkSet, Lsx, Lsy, Lex, Ley, bmp); tx = ct * (ex - mx) - st * (ey - my); ty = st * (ex - mx) + ct * (ey - my); if (tx==0) tx = 1; alpha = ty / (tx * tx); 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; PartLine(MarkSet, Lsx, Lsy, Lex, Ley, bmp); Lsx = Lex; Lsy = Ley; xx--; } } else { xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = ct * xx + st * yy + mx; Ley = ct * yy - st * xx + my; PartLine(MarkSet, Lsx, Lsy, Lex, Ley, bmp); Lsx = Lex; Lsy = Ley; xx++; } } Lex = ex; Ley = ey; PartLine(MarkSet, Lsx, Lsy, Lex, Ley, bmp); } bmp->StopScanLine(); // 7.41 DrawPenWidthÀ¸·Î À̵¿ MainImageForm->iMainImage->SetMark(); // ????????????????????? ::RepaintImage(); return; fail: if (undo) Undo->RemoveLast(); bmp->StopScanLine(); } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::DrawCurveLocate() { int sx, sy, ex, ey, mx, my, nDrawMode, hDCState, Lsx, Lsy, Lex, Ley; double ct, st, ss, theta, alpha, d1, d2, d3; double tx, ty, a, b, xx, yy; HDC hDC; HBRUSH hOldBrush; HPEN hOldPen; hDC = MainImageForm->iMainImage->Canvas->Handle; hDCState = SaveDC(hDC); hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); hOldPen = SelectObject(hDC, GetStockObject(WHITE_PEN)); nDrawMode = GetROP2(hDC); SetROP2(hDC, R2_NOT); sx = Lsx = MainImageForm->iMainImage->BitmapToCanvasX(First.x); sy = Lsy = MainImageForm->iMainImage->BitmapToCanvasY(First.y); ex = Lex = MainImageForm->iMainImage->BitmapToCanvasX(Second.x); ey = Ley = MainImageForm->iMainImage->BitmapToCanvasY(Second.y); mx = MainImageForm->iMainImage->BitmapToCanvasX(Third.x); my = MainImageForm->iMainImage->BitmapToCanvasY(Third.y); 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(hDC, Lsx, Lsy, NULL); LineTo(hDC, Lex, Ley); } 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); Lsx = mx; Lsy = my; xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = mx + xx; Ley = my + yy; MoveToEx(hDC, Lsx, Lsy, NULL); LineTo(hDC, Lex, Ley); Lsx = Lex; Lsy = Ley; xx ++; } if (sx > ex) Lex = sx; else Lex = ex; Ley = sy; MoveToEx(hDC, Lsx, Lsy, NULL); LineTo(hDC, Lex, Ley); Lsx = mx; Lsy = my; xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = mx - xx; Ley = my + yy; MoveToEx(hDC, Lsx, Lsy, NULL); LineTo(hDC, Lex, Ley); Lsx = Lex; Lsy = Ley; xx++; } if (sx < ex) Lex = sx; else Lex = ex; Ley = sy; MoveToEx(hDC, Lsx, Lsy, NULL); LineTo(hDC, Lex, Ley); } 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); 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(hDC, Lsx, Lsy, NULL); LineTo(hDC, Lex, Ley); Lsx = Lex; Lsy = Ley; xx--; } } else { xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = ct * xx + st * yy + mx; Ley = ct * yy - st * xx + my; MoveToEx(hDC, Lsx, Lsy, NULL); LineTo(hDC, Lex, Ley); Lsx = Lex; Lsy = Ley; xx++; } } Lex = sx; Ley = sy; MoveToEx(hDC, Lsx, Lsy, NULL); LineTo(hDC, Lex, Ley); tx = ct * (ex - mx) - st * (ey - my); ty = st * (ex - mx) + ct * (ey - my); if (tx==0) tx = 1; alpha = ty / (tx * tx); 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(hDC, Lsx, Lsy, NULL); LineTo(hDC, Lex, Ley); Lsx = Lex; Lsy = Ley; xx--; } } else { xx = 0; while (xx <= tx) { yy = alpha * (xx * xx); Lex = ct * xx + st * yy + mx; Ley = ct * yy - st * xx + my; MoveToEx(hDC, Lsx, Lsy, NULL); LineTo(hDC, Lex, Ley); Lsx = Lex; Lsy = Ley; xx++; } } Lex = ex; Ley = ey; MoveToEx(hDC, Lsx, Lsy, NULL); LineTo(hDC, Lex, Ley); } SetROP2(hDC, nDrawMode); SelectObject(hDC, hOldBrush); SelectObject(hDC, hOldPen); RestoreDC(hDC, hDCState); } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::DrawSquare_Rectangle() { TTexpiaBitmap *bmp; int x, y; Byte *IP, MarkSet; bool undo = true; if (MainImageForm->Arrange->Dmark.set & 0x3F) { if (MainImageForm->Arrange->Dmark.set & 0x40) { MarkSet = 0x41; } else { MarkSet = 0x01; } } else { if (MainImageForm->Arrange->Dmark.set & 0x40) { MarkSet = 0x40; } else { MarkSet = 0x00; } } bmp = &MainImageForm->iMainImage->ArrayBitmap[1]; pw = PenManagerForm->Pen->Thick; if (!(undo = MainImageForm->UndoSave(UK_MARK, Rect(0, 0, bmp->Width, bmp->Height), true))) goto fail; if (!bmp->StartScanLine()) goto fail; if (Fill) { for (y = Temp.top; y < Temp.bottom; y++) { IP = bmp->GetScanLine(y) + Temp.left; for (x = Temp.left; x < Temp.right; x++, IP++) { if ((*IP & 0x3F) < 2) { *IP = MarkSet; } } bmp->PutScanLine(y); } MainImageForm->iMainImage->SetMark(Temp); //7.41 } for (x = Temp.left; x < Temp.right; x++) { DrawPenWidth(bmp, x, Temp.top, MarkSet); DrawPenWidth(bmp, x, Temp.bottom - 1, MarkSet); } for (y = Temp.top; y < Temp.bottom; y++) { DrawPenWidth(bmp, Temp.left, y, MarkSet); DrawPenWidth(bmp, Temp.right - 1, y, MarkSet); } bmp->StopScanLine(); // 7.41 DrawPenWidthÀ¸·Î À̵¿ MainImageForm->iMainImage->SetMark(); // ????????????????????? ::RepaintImage(); return; fail: if (undo) Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::DrawCircle_Ellipse() { TTexpiaBitmap *bmp, *tmp = NULL; int sx, sy, ex, ey, w, h, x, y; HDC hDC = NULL; HPEN hPen = NULL; Byte *IP, *DP, MarkSet; bool undo = false, bscan= false, tscan = false; if (MainImageForm->Arrange->Dmark.set & 0x3F) { if (MainImageForm->Arrange->Dmark.set & 0x40) { MarkSet = 0x41; } else { MarkSet = 0x01; } } else { if (MainImageForm->Arrange->Dmark.set & 0x40) { MarkSet = 0x40; } else { MarkSet = 0x40; } } sx = min(Temp.left, Temp.right); sy = min(Temp.top, Temp.bottom); ex = max(Temp.left, Temp.right); ey = max(Temp.top, Temp.bottom); w = ex - sx; h = ey - sy; bmp = &MainImageForm->iMainImage->ArrayBitmap[1]; pw = PenManagerForm->Pen->Thick; if (!(undo = MainImageForm->UndoSave(UK_MARK, Rect(0, 0, bmp->Width, bmp->Height), true))) goto fail; if ((tmp = new TTexpiaBitmap) == NULL) goto fail; if (tmp->Create(w, h, 8) == false) goto fail; if ((bscan = bmp->StartScanLine()) == false) goto fail; if (Fill) { tmp->FillRect(Rect(0, 0, w, h), 0); if ((hDC = tmp->CreateDC()) == NULL) goto fail; SelectObject(hDC, GetStockObject(WHITE_BRUSH)); hPen = CreatePen(PS_SOLID, 1, clWhite); SelectObject(hDC, hPen); Ellipse(hDC, 0, 0, w, h); DeleteObject(hPen); tmp->DeleteDC(hDC); hDC = NULL; if ((tscan = tmp->StartScanLine()) == false) goto fail; for (y = 0; y < h; y++) { if ((sy + y) >= 0 && (sy + y) < bmp->Height) { IP = tmp->GetScanLine(y); DP = bmp->GetScanLine(sy + y); for (x = 0; x < w; x++) { if ((sx + x) >= 0 && (sx + x) < bmp->Width) { if (IP[x]) { DP[sx+x] = MarkSet; } } } bmp->PutScanLine(sy + y); } } tmp->StopScanLine(); MainImageForm->iMainImage->SetMark(Temp); //7.41 } tmp->FillRect(Rect(0, 0, w, h), 0); if ((hDC = tmp->CreateDC()) == NULL) goto fail; SelectObject(hDC, GetStockObject(NULL_BRUSH)); hPen = CreatePen(PS_SOLID, 1, clWhite); SelectObject(hDC, hPen); Ellipse(hDC, 0, 0, w, h); DeleteObject(hPen); tmp->DeleteDC(hDC); hDC = NULL; if ((tscan = tmp->StartScanLine()) == false) goto fail; for (y = 0; y < h; y++) { IP = tmp->GetScanLine(y); for (x = 0; x < w; x++) { if (IP[x]) DrawPenWidth(bmp, sx + x, sy + y, MarkSet); } } tmp->StopScanLine(); bmp->StopScanLine(); // 7.41 DrawPenWidthÀ¸·Î À̵¿ MainImageForm->iMainImage->SetMark(); // ????????????????????? delete tmp; ::RepaintImage(); return; fail: if (undo) Undo->RemoveLast(); if (tmp) { if (hDC) tmp->DeleteDC(hDC); if (bscan) bmp->StopScanLine(); if (tscan) tmp->StopScanLine(); delete tmp; } bmp->StopScanLine(); tmp->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::DrawPenWidth(TTexpiaBitmap *bmp, int x, int y, Byte set) { Byte *IP; int sx, sy, ex, ey, i, j, ls, rs; ls = pw / 2.0; rs = pw - ls; sx = x - ls; if (sx < 0) sx = 0; ex = x + rs; if (ex > bmp->Width) ex = bmp->Width; sy = y - ls; if (sy < 0) sy = 0; ey = y + rs; if (ey > bmp->Height) ey = bmp->Height; for (i = sy; i < ey; i++) { IP = bmp->GetScanLine(i); for (j = sx; j < ex; j++) { if ((IP[j] & 0x3F) < 2) { IP[j] = set; } } bmp->PutScanLine(i); } MainImageForm->iMainImage->SetMark(Rect(sx, sy, ex, ey)); //7.41 } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::CalculateRect(int sx, int sy, int ex, int ey) { int dx, dy; dx = ex - sx; dy = ey - sy; if (dx >= 0) { if (dy >= 0) { if (dx > dy) { Second.x = sx + dy; Second.y = ey; } else { Second.x = ex; Second.y = sy + dx; } } else { if (dx > abs(dy)) { Second.x = sx + abs(dy); Second.y = ey; } else { Second.x = ex; Second.y = sy - dx; } } } else { if (dy >= 0) { if (abs(dx) > dy) { Second.x = sx - dy; Second.y = ey; } else { Second.x = ex; Second.y = sy + abs(dx); } } else { if (abs(dx) > abs(dy)) { Second.x = sx + dy; Second.y = ey; } else { Second.x = ex; Second.y = sy + dx; } } } } /* void __fastcall TMarkDrawForm::CalculateRect(int sx, int sy, int ex, int ey) { int dx, dy; dx = ex - sx; dy = ey - sy; if (dx >= 0) { if (dy >= 0) { if (dx > dy) { Temp.right = sx + dy; Temp.bottom = ey; } else { Temp.right = ex; Temp.bottom = sy + dx; } } else { if (dx > abs(dy)) { Temp.right = sx + abs(dy); Temp.bottom = ey; } else { Temp.right = ex; Temp.bottom = sy - dx; } } } else { if (dy >= 0) { if (abs(dx) > dy) { Temp.right = sx - dy; Temp.bottom = ey; } else { Temp.right = ex; Temp.bottom = sy + abs(dx); } } else { if (abs(dx) > abs(dy)) { Temp.right = sx + dy; Temp.bottom = ey; } else { Temp.right = ex; Temp.bottom = sy + dx; } } } } */ //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::CalculateCircle(int sx, int sy, int ex, int ey) { double r; int dx, dy; dx = ex - sx; dy = ey - sy; r = sqrt(dx*dx + dy*dy); Temp.left = sx - r; Temp.right = sx + r; Temp.top = sy - r; Temp.bottom = sy + r; } //--------------------------------------------------------------------------- /// Public Method ////////////////////////////////////////////////////////// //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::InitForm() { //======================================================================== SetSmallFont(Font); SetSmallFont(stContinue->Font); SetSmallFont(stFill->Font); sbLine->Caption = IDS_COMMON_LINE; sbCurve->Caption = IDS_COMMON_CURVE; sbSquare->Caption = IDS_COMMON_SQUARE; sbRectangle->Caption = IDS_COMMON_RECTANGLE; sbCircle->Caption = IDS_COMMON_CIRCLE; sbEllipse->Caption = IDS_COMMON_ELLIPSE; stContinue->Caption = IDS_COMMON_CONTINUOUSLINE; stFill->Caption = AnsiString(IDS_COMMON_FILL) + " : " + AnsiString(IDS_COMMON_BUTTONNO); sbStartPoint->Caption = IDS_COMMON_FIRSTPOINT; //======================================================================== ParentHeight = Parent->Height+20; ClientHeight = 135; Parent->Height = ParentHeight+ClientHeight; stContinue->Enabled = true; stFill->Enabled = false; Continuous = true; Fill = false; Item = 0; step = 0; IsDraw = false; } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::ExitForm() { if (IsDraw) MainImageForm->iMainImage->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::DrawMouseDown(TMouseButton Button, TShiftState Shift, int X, int Y) { RECT r; if (Button == mbLeft) { switch (Item) { case 0: if (step > 0) { if (IsDraw) MainImageForm->DrawLineLocate(First, Second); IsDraw = false; Second = Point(X, Y); DrawLine(First.x, First.y, Second.x, Second.y); if (Continuous) First = Point(X, Y); else step = 0; } else { First = Point(X, Y); Second = Point(X, Y); Start = Point(X, Y); IsDraw = false; step = 1; } break; case 1: // Curve if (step == 0) { First = Point(X, Y); Second = Point(X, Y); IsDraw = false; step = 1; } else if (step == 1) { if(IsDraw) { MainImageForm->DrawLineLocate(First, Second); IsDraw = false; } Third = Point(X, Y); step = 2; } else { if (IsDraw) { DrawCurveLocate(); IsDraw = false; } DrawCurve(); if (Continuous) { First = Second; step = 1; } else { step = 0; } } break; case 2: if (step > 0) { if (IsDraw) { MainImageForm->DrawRectangleLocate(Temp); IsDraw = false; } /* CalculateRect(Temp.left, Temp.top, X, Y); r.left = min(Temp.left, Temp.right); r.right = max(Temp.left, Temp.right); r.top = min(Temp.top, Temp.bottom); r.bottom = max(Temp.top, Temp.bottom); Temp = r; */ DrawSquare_Rectangle(); step = 0; } else { First = Point(X, Y); IsDraw = false; step = 1; } break; case 3: // Rectangle if (step > 0) { if (IsDraw) { MainImageForm->DrawRectangleLocate(Temp); IsDraw = false; } DrawSquare_Rectangle(); step = 0; } else { First = Point(X, Y); IsDraw = false; step = 1; } break; case 4: // Circle if (step > 0) { if (IsDraw) { MainImageForm->DrawEllipseLocate(Temp); IsDraw = false; } DrawCircle_Ellipse(); step = 0; } else { First = Point(X, Y); IsDraw = false; step = 1; } break; case 5: // Ellipse if (step > 0) { if (IsDraw) { MainImageForm->DrawEllipseLocate(Temp); IsDraw = false; } DrawCircle_Ellipse(); step = 0; } else { Temp = Rect(X, Y, X, Y); IsDraw = false; step = 1; } break; } } } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::DrawMouseMove(int X, int Y) { RECT r; switch (Item) { case 0: if (step > 0) { if (IsDraw) MainImageForm->DrawLineLocate(First, Second); Second = Point(X, Y); MainImageForm->DrawLineLocate(First, Second); IsDraw = true; } break; case 1: if (step == 1) { if (IsDraw) MainImageForm->DrawLineLocate(First, Second); Second = Point(X, Y); MainImageForm->DrawLineLocate(First, Second); IsDraw = true; } else if (step == 2) { if (IsDraw) DrawCurveLocate(); Third = Point(X, Y); DrawCurveLocate(); IsDraw = true; } break; case 2: if (step > 0) { if (IsDraw) MainImageForm->DrawRectangleLocate(Temp); CalculateRect(First.x, First.y, X, Y); Temp.left = min(First.x, Second.x); Temp.right = max(First.x, Second.x) + 1; Temp.top = min(First.y, Second.y); Temp.bottom = max(First.y, Second.y) + 1; MainImageForm->DrawRectangleLocate(Temp); IsDraw = true; } break; case 3: if (step > 0) { if (IsDraw) MainImageForm->DrawRectangleLocate(Temp); Second = Point(X, Y); Temp.left = min(First.x, Second.x); Temp.right = max(First.x, Second.x) + 1; Temp.top = min(First.y, Second.y); Temp.bottom = max(First.y, Second.y) + 1; MainImageForm->DrawRectangleLocate(Temp); IsDraw = true; } break; case 4: if (step > 0) { if (IsDraw) MainImageForm->DrawEllipseLocate(Temp); CalculateCircle(First.x, First.y, X, Y); MainImageForm->DrawEllipseLocate(Temp); IsDraw = true; } break; case 5: if (step > 0) { if (IsDraw) MainImageForm->DrawEllipseLocate(Temp); Temp.right = X; Temp.bottom = Y; MainImageForm->DrawEllipseLocate(Temp); IsDraw = true; } break; } } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::iMainImageKeyDown(int Key) { } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::iMainImageChange() { if (IsDraw) { IsDraw = false; MainImageForm->iMainImage->Repaint(); } } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::iMainImagePaint() { IsDraw = false; } //--------------------------------------------------------------------------- void __fastcall TMarkDrawForm::iMainImageMouseLeave(){ if (IsDraw) { IsDraw = false; MainImageForm->iMainImage->Repaint(); } } //---------------------------------------------------------------------------