//--------------------------------------------------------------------------- #include #pragma hdrstop #include "TPTestKnitImage.h" #pragma link "TPImage" #pragma package(smart_init) //--------------------------------------------------------------------------- //TPTestKnitImage //--------------------------------------------------------------------------- // ValidCtrCheck is used to assure that the components created do not have // any pure virtual functions. // static inline void ValidCtrCheck(TPTestKnitImage *) { new TPTestKnitImage(NULL); } //--------------------------------------------------------------------------- __fastcall TPTestKnitImage::TPTestKnitImage(TComponent* Owner) : TPImage(Owner) { FBitmap = (TexproBitmap *) new TTexpiaBitmap; // by celberus FYarnBitmap = NULL;//new TTexpiaBitmap; FMarkBitmap = NULL;//new TTexpiaBitmap; FKnitBitmap = NULL;//new TTexpiaBitmap; FBitmap->OnPropertyChange = PropertyChange; FBitmap->CoordinateSystem = csBottomLeft; } //--------------------------------------------------------------------------- __fastcall TPTestKnitImage::~TPTestKnitImage() { if (FBitmap) delete FBitmap; } //--------------------------------------------------------------------------- // Private Function //--------------------------------------------------------------------------- #define PAINT_INIT \ sx = FPositionX; \ sy = FRealPosY; \ dcDst = TGraphicControl::Canvas->Handle; \ if (FBitmap->BitsPerPixel==8) { \ hpaintpal = L_CreatePaintPalette(dcDst, bh); \ if (hpaintpal) holdpal = SelectPalette(dcDst, hpaintpal, false); \ } \ if (FParentImage) { \ FGrid = FParentImage->Grid; \ FZoomIn = FParentImage->ZoomIn; \ FZoomOut = FParentImage->ZoomOut; \ } \ pw = Width*FZoomOut/FZoomIn; \ ph = Height*FZoomOut/FZoomIn; \ if (pw>FBitmap->Width-sx) pw = FBitmap->Width-sx; \ if (ph>FBitmap->Height-sy) ph = FBitmap->Height-sy; \ if (FZoomOut>1) { \ pw -= pw%FZoomOut; \ ph -= ph%FZoomOut; \ } \ vw = pw*FZoomIn/FZoomOut; \ vh = ph*FZoomIn/FZoomOut; \ TGraphicControl::Canvas->Brush->Color = FColor; \ if (vwFillRect(Rect(vw, Height-vh, Width, Height)); \ if (vhFillRect(Rect(0, 0, Width, Height-vh)); //--------------------------------------------------------------------------- #define PAINT_GRIDLINE \ SetROP2(dcMemV, R2_COPYPEN); \ if ((hPen = CreatePen(psSolid, 1, FGridColor)) == NULL) goto fail; \ hOldPen = SelectObject(dcMemV, hPen); \ p = sx-Floor(sx/gx)*gx; \ p = p>0 ? (gx-p)*FZoomIn/FZoomOut : 0; \ while (p0 ? (gy-p)*FZoomIn/FZoomOut : 0; \ while (p0) { \ gx = FGridGapX*FGridMark; \ gy = FGridGapY*FGridMark; \ gzx = gx*FZoomIn/FZoomOut; \ gzy = gy*FZoomIn/FZoomOut; \ if ((hPen = CreatePen(psSolid, 1, FGridMarkColor)) == NULL) goto fail; \ hOldPen = SelectObject(dcMemV, hPen); \ p = sx-Floor(sx/gx)*gx; \ p = p>0 ? (gx-p)*FZoomIn/FZoomOut : 0; \ while (p0 ? (gy-p)*FZoomIn/FZoomOut : 0; \ while (pCreateDC(); \ BitBlt(dcMemV, 0, 0, pw*16, ph*16, dcMark, sx*16, sy*16, SRCINVERT); \ FMarkBitmap->DeleteDC(dcMark); \ } //--------------------------------------------------------------------------- // by playzzang for CrossLine #define PAINT_CROSSLINE \ if (FCrossLine) { \ hOldPen = SelectObject(dcMemV, GetStockObject(WHITE_PEN)); \ SetROP2(dcMemV, R2_NOT); \ MoveToEx(dcMemV, FCrossPos.x, 0, NULL); \ LineTo(dcMemV, FCrossPos.x, vh); \ MoveToEx(dcMemV, 0, FCrossPos.y, NULL); \ LineTo(dcMemV, vw, FCrossPos.y); \ SelectObject(dcMemV, hOldPen); \ } //--------------------------------------------------------------------------- void __fastcall TPTestKnitImage::PaintBottom(BITMAPHANDLE *bh) { HPALETTE hpaintpal = NULL, holdpal = NULL; int pw, ph, vw, vh, n, w, x, y; double sx, sy, syy, gx, gy, gzx, gzy, p; HDC dcSrc = NULL, dcDst, dcMemV = NULL; HBITMAP bmMemV = NULL; HPEN hPen = NULL, hOldPen; BYTE *bp; PAINT_INIT; if ((dcSrc = FBitmap->CreateDC()) == NULL) goto fail; if ((bmMemV = CreateCompatibleBitmap(dcSrc, vw, vh)) == NULL) goto fail; if ((dcMemV = CreateCompatibleDC(dcSrc)) == NULL) goto fail; SelectObject(dcMemV, bmMemV); if (hpaintpal) SelectPalette(dcMemV, hpaintpal, false); if (!FYarnBitmap) { SetStretchBltMode(dcMemV, COLORONCOLOR); StretchBlt(dcMemV, 0, 0, vw, vh, dcSrc, sx, sy, pw, ph, SRCCOPY); } FBitmap->DeleteDC(dcSrc); if (FYarnBitmap) { if ((dcSrc = FYarnBitmap->CreateDC()) == NULL) goto fail; SetStretchBltMode(dcMemV, COLORONCOLOR); StretchBlt(dcMemV, (bmx-sx)*FZoomIn/FZoomOut, (bmy-sy)*FZoomIn/FZoomOut, bmw*FZoomIn/FZoomOut, bmh*FZoomIn/FZoomOut, dcSrc, 0, 0, FYarnBitmap->Width, FYarnBitmap->Height, SRCCOPY); FYarnBitmap->DeleteDC(dcSrc); } if (FMarkBitmap) { if ((dcSrc = FMarkBitmap->CreateDC()) == NULL) goto fail; SetStretchBltMode(dcMemV, COLORONCOLOR); StretchBlt(dcMemV, (bmx-sx)*FZoomIn/FZoomOut, (bmy-sy)*FZoomIn/FZoomOut, bmw*FZoomIn/FZoomOut, bmh*FZoomIn/FZoomOut, dcSrc, 0, 0, FMarkBitmap->Width, FMarkBitmap->Height, SRCINVERT); FMarkBitmap->DeleteDC(dcSrc); } if (FGrid) { gx = FGridGapX; gy = FGridGapY; gzx = gx*FZoomIn/FZoomOut; gzy = gy*FZoomIn/FZoomOut; if (gzx>=5 && gzy>=5) { if (FParentImage) { FGridColor = FParentImage->GridColor; FGridGapX = FParentImage->GridGapX; FGridGapY = FParentImage->GridGapY; FGridMark = FParentImage->GridMark; FGridMarkColor = FParentImage->GridMarkColor; sx = FParentImage->PositionX+(Left-FParentImage->Left)*FZoomOut/FZoomIn; sy = FParentImage->Bitmap->Height-FParentImage->PositionY- FParentImage->Height*FZoomOut/FZoomIn+(Top-FParentImage->Top)*FZoomOut/FZoomIn; if (Top < FParentImage->Top) sy--; syy = FParentImage->Bitmap->Height-ph-sy; } else { syy = FBitmap->Height-ph-sy; } PAINT_GRIDLINE; } } DrawPresentKo(dcMemV); if (FOnPaintKo) FOnPaintKo(this, dcMemV); if (FOnPaintZoom) FOnPaintZoom(this, dcMemV); BitBlt(dcDst, 0, FMarginY, vw, vh, dcMemV, 0, 0, SRCCOPY); DeleteDC(dcMemV); DeleteObject(bmMemV); if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } if (FOnPaint) FOnPaint(this); return; fail: if (dcSrc) { if (bmMemV) { if (dcMemV) { if (hPen) DeleteObject(hPen); DeleteDC(dcMemV); } DeleteObject(bmMemV); } } if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } } //--------------------------------------------------------------------------- #define RECTPAINT_INIT \ sx = FPositionX; \ sy = FRealPosY; \ dcDst = TGraphicControl::Canvas->Handle; \ if (FBitmap->BitsPerPixel==8) { \ hpaintpal = L_CreatePaintPalette(dcDst, bh); \ if (hpaintpal) holdpal = SelectPalette(dcDst, hpaintpal, false); \ } \ if (FParentImage) { \ FGrid = FParentImage->Grid; \ FZoomIn = FParentImage->ZoomIn; \ FZoomOut = FParentImage->ZoomOut; \ } \ Src.left -= sx; \ Src.top -= sy; \ Src.right -= sx; \ Src.bottom -= sy; \ pw = min(Width*FZoomOut/FZoomIn, int(FBitmap->Width-sx)); \ ph = min(Height*FZoomOut/FZoomIn, int(FBitmap->Height-sy)); \ if (Src.left<0) Src.left = 0; \ if (Src.top<0) Src.top = 0; \ if (Src.right>pw) Src.right = pw; \ if (Src.bottom>ph) Src.bottom = ph; \ if (FZoomOut>1) { \ Src.left -= Src.left%FZoomOut; \ Src.top -= Src.top%FZoomOut; \ Src.right = Src.right-Src.right%FZoomOut; \ Src.bottom = Src.bottom-Src.bottom%FZoomOut; \ } \ pw = Src.right-Src.left; \ ph = Src.bottom-Src.top; \ vw = pw*FZoomIn/FZoomOut; \ vh = ph*FZoomIn/FZoomOut; \ px = Src.left*FZoomIn/FZoomOut; \ py = FMarginY+Src.top*FZoomIn/FZoomOut; \ sx += Src.left; \ sy += Src.top; //--------------------------------------------------------------------------- void __fastcall TPTestKnitImage::RectPaint(RECT Src) { BITMAPHANDLE *bh, *mh; HPALETTE hpaintpal = NULL, holdpal = NULL; int px, py, pw, ph, vw, vh, x, y, n, w; double sx, sy, syy, gx, gy, gzx, gzy, p; HDC dcSrc = NULL, dcDst, dcMemV = NULL, dcMSrc = NULL; HBITMAP bmMemV = NULL; HPEN hPen = NULL, hOldPen; BYTE *bp; HDC dcMark; RECT SrcYarn; SrcYarn.left = Src.left; SrcYarn.right = Src.right; SrcYarn.top = Src.top; SrcYarn.bottom = Src.bottom; Src.left = Fbmx + (double)Src.left*FDPI/FWPI; Src.right = Fbmx + (double)(Src.right)*FDPI/FWPI; Src.top = Fbmy + (double)(Src.top)*FDPI/FCPI; Src.bottom = Fbmy + (double)(Src.bottom)*FDPI/FCPI; bh = FBitmap->Handle; if (FMaskEnabled) { /* mh = FMask->Handle; if (mh && bh) { if (Src.leftWidth && Src.right>=FPositionX && Src.topHeight && Src.bottom>=FRealPosY) { RECTPAINT_INIT; if ((dcMSrc = FMask->CreateDC()) == NULL) goto fail; if (isStitch) { if ((dcSrc = FArrayBitmap[0].CreateDC()) == NULL) goto fail; } else { if ((dcSrc = FBitmap->CreateDC()) == NULL) goto fail; } if ((bmMemV = CreateCompatibleBitmap(dcSrc, vw, vh)) == NULL) goto fail; if ((dcMemV = CreateCompatibleDC(dcSrc)) == NULL) goto fail; SelectObject(dcMemV, bmMemV); if (hpaintpal) SelectPalette(dcMemV, hpaintpal, false); SetStretchBltMode(dcMemV, COLORONCOLOR); StretchBlt(dcMemV, 0, 0, vw, vh, dcSrc, sx, sy, pw, ph, SRCCOPY); StretchBlt(dcMemV, 0, 0, vw, vh, dcMSrc, sx, sy, pw, ph, SRCINVERT); if (FGrid) { gx = FGridGapX; gy = FGridGapY; gzx = gx*FZoomIn/FZoomOut; gzy = gy*FZoomIn/FZoomOut; if (gzx>=5 && gzy>=5) { if (FParentImage) { FGridColor = FParentImage->GridColor; FGridGapX = FParentImage->GridGapX; FGridGapY = FParentImage->GridGapY; FGridMark = FParentImage->GridMark; FGridMarkColor = FParentImage->GridMarkColor; sx = FParentImage->PositionX+(Left-FParentImage->Left)*FZoomOut/FZoomIn+Src.left; sy = FParentImage->Bitmap->Height-FParentImage->PositionY- FParentImage->Height*FZoomOut/FZoomIn+(Top-FParentImage->Top)*FZoomOut/FZoomIn+Src.top; if (Top < FParentImage->Top) sy--; syy = FParentImage->Bitmap->Height-ph-sy; } else { syy = FBitmap->Height-ph-sy; } PAINT_GRIDLINE; } } if (FCross) PAINT_CROSSLINE // by playzzang PAINT_STITCH; BitBlt(dcDst, px, py, vw, vh, dcMemV, 0, 0, SRCCOPY); DeleteDC(dcMemV); DeleteObject(bmMemV); if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } if (isStitch) { FArrayBitmap[0].DeleteDC(dcSrc); } else { FBitmap->DeleteDC(dcSrc); } FMask->DeleteDC(dcMSrc); } } */ } else { if (bh) { if (Src.leftWidth && Src.right>=FPositionX && Src.topHeight && Src.bottom>=FRealPosY) { RECTPAINT_INIT if ((dcSrc = FBitmap->CreateDC()) == NULL) goto fail; if ((bmMemV = CreateCompatibleBitmap(dcSrc, vw, vh)) == NULL) goto fail; if ((dcMemV = CreateCompatibleDC(dcSrc)) == NULL) goto fail; SelectObject(dcMemV, bmMemV); if (hpaintpal) SelectPalette(dcMemV, hpaintpal, false); SetStretchBltMode(dcMemV, COLORONCOLOR); StretchBlt(dcMemV, 0, 0, vw, vh, dcSrc, sx, sy, pw, ph, SRCCOPY); FBitmap->DeleteDC(dcSrc); if (FYarnBitmap) { if ((dcSrc = FYarnBitmap->CreateDC()) == NULL) goto fail; SetStretchBltMode(dcMemV, COLORONCOLOR); StretchBlt(dcMemV, 0, 0, vw, vh, dcSrc, SrcYarn.left, SrcYarn.top, SrcYarn.right-SrcYarn.left, SrcYarn.bottom-SrcYarn.top, SRCCOPY); FYarnBitmap->DeleteDC(dcSrc); } if (FMarkBitmap) { if ((dcSrc = FMarkBitmap->CreateDC()) == NULL) goto fail; SetStretchBltMode(dcMemV, COLORONCOLOR); StretchBlt(dcMemV, 0, 0, vw, vh, dcSrc, SrcYarn.left*16, SrcYarn.top*16, (SrcYarn.right-SrcYarn.left)*16, (SrcYarn.bottom-SrcYarn.top)*16, SRCINVERT); FMarkBitmap->DeleteDC(dcSrc); } if (FGrid) { gx = FGridGapX; gy = FGridGapY; gzx = gx*FZoomIn/FZoomOut; gzy = gy*FZoomIn/FZoomOut; if (gzx>=5 && gzy>=5) { if (FParentImage) { FGridColor = FParentImage->GridColor; FGridGapX = FParentImage->GridGapX; FGridGapY = FParentImage->GridGapY; FGridMark = FParentImage->GridMark; FGridMarkColor = FParentImage->GridMarkColor; sx = FParentImage->PositionX+(Left-FParentImage->Left)*FZoomOut/FZoomIn+Src.left; sy = FParentImage->Bitmap->Height-FParentImage->PositionY- FParentImage->Height*FZoomOut/FZoomIn+(Top-FParentImage->Top)*FZoomOut/FZoomIn+Src.top; if (Top < FParentImage->Top) sy--; syy = FParentImage->Bitmap->Height-ph-sy; } else { syy = FBitmap->Height-ph-sy; } PAINT_GRIDLINE; } } if (FCross) PAINT_CROSSLINE // by playzzang BitBlt(dcDst, px, py, vw, vh, dcMemV, 0, 0, SRCCOPY); DeleteDC(dcMemV); DeleteObject(bmMemV); if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } } } } return; fail: if (dcSrc) { if (bmMemV) { if (dcMemV) { if (hPen) DeleteObject(hPen); DeleteDC(dcMemV); } DeleteObject(bmMemV); } } if (dcMSrc) FMask->DeleteDC(dcMSrc); if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } } //---------------------------------------------------------------------------- bool __fastcall TPTestKnitImage::PositionChange() { int m = FMarginY, r = FRealPosY; if (FBitmap->Handle) { int ps = Height*FZoomOut/FZoomIn; if (ps>FBitmap->Height) { m = Height-FBitmap->Height*FZoomIn/FZoomOut; r = 0; } else { m = FZoomIn>1 ? Height-ps*FZoomIn/FZoomOut : 0; r = FBitmap->Height-FPositionY-ps; } if (m != FMarginY || r != FRealPosY) { FMarginY = m; FRealPosY = r; return true; } } return false; } //--------------------------------------------------------------------------- void __fastcall TPTestKnitImage::PropertyChange() { if (PositionChange()) { if (FOnPositionChange) FOnPositionChange(this); } Invalidate(); } //--------------------------------------------------------------------------- void __fastcall TPTestKnitImage::DrawPresentKo(HDC dc) { double sx, sy, syy, gx, gy, gzx, gzy, p; HPEN hPen = NULL, hOldPen; POINT pt[4]; sx = FPositionX; sy = FRealPosY; pt[0].x=(Fbmx-sx)*FZoomIn/FZoomOut; pt[0].y=(Fbmy-sy)*FZoomIn/FZoomOut; pt[1].x=(Fbmx+Fbmw-sx)*FZoomIn/FZoomOut; pt[1].y=(Fbmy-sy)*FZoomIn/FZoomOut; pt[2].x=(Fbmx+Fbmw-sx)*FZoomIn/FZoomOut; pt[2].y=(Fbmy+Fbmh-sy)*FZoomIn/FZoomOut; pt[3].x=(Fbmx-sx)*FZoomIn/FZoomOut; pt[3].y=(Fbmy+Fbmh-sy)*FZoomIn/FZoomOut; if (dc) { SetROP2(dc, R2_COPYPEN); hPen = CreatePen(psSolid, 1, PALETTEINDEX(2)); hOldPen = SelectObject(dc, hPen); MoveToEx(dc, pt[0].x, pt[0].y, NULL); LineTo(dc, pt[1].x, pt[1].y); LineTo(dc, pt[2].x, pt[2].y); LineTo(dc, pt[3].x, pt[3].y); LineTo(dc, pt[0].x, pt[0].y); SelectObject(dc, hOldPen); DeleteObject(hPen); hPen = NULL; } } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // Protected Function //--------------------------------------------------------------------------- void __fastcall TPTestKnitImage::Paint() { BITMAPHANDLE *bh; if (ComponentState.Contains(csDesigning)) { TGraphicControl::Canvas->Pen->Style = psDash; TGraphicControl::Canvas->Brush->Style = bsClear; TGraphicControl::Canvas->Rectangle(0, 0, Width, Height); } else { bh = FBitmap->Handle; if (bh) { if (Width<=0 || Height<=0) return; // if (FMaskEnabled) { // PaintBottomMask(bh); // } else { PaintBottom(bh); // } } } } //--------------------------------------------------------------------- void __fastcall TPTestKnitImage::MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y) { int px, py; if (FCoordinationTransfer) { if (FBitmap->Handle) { px = FPositionX+X*FZoomOut/FZoomIn; py = FRealPosY+(Y-FMarginY)*FZoomOut/FZoomIn; TControl::MouseDown(Button, Shift, px, py); } else { TControl::MouseDown(Button, Shift, X, Y); } } else { TControl::MouseDown(Button, Shift, X, Y); } } //--------------------------------------------------------------------- void __fastcall TPTestKnitImage::MouseMove(TShiftState Shift, int X, int Y) { int px, py; if (FCoordinationTransfer) { if (FBitmap->Handle) { px = FPositionX+X*FZoomOut/FZoomIn; py = FRealPosY+(Y-FMarginY)*FZoomOut/FZoomIn; TControl::MouseMove(Shift, px, py); } else { TControl::MouseMove(Shift, X, Y); } } else { TControl::MouseMove(Shift, X, Y); } } //--------------------------------------------------------------------- void __fastcall TPTestKnitImage::MouseUp(TMouseButton Button, TShiftState Shift, int X, int Y) { int px, py; if (FCoordinationTransfer) { if (FBitmap->Handle) { px = FPositionX+X*FZoomOut/FZoomIn; py = FRealPosY+(Y-FMarginY)*FZoomOut/FZoomIn; TControl::MouseUp(Button, Shift, px, py); } else { TControl::MouseUp(Button, Shift, X, Y); } } else { TControl::MouseUp(Button, Shift, X, Y); } } //--------------------------------------------------------------------------- // Public Function //--------------------------------------------------------------------------- void __fastcall TPTestKnitImage::Line(int sx, int sy, int ex, int ey, int thick, COLORREF c) { HDC dcSrc=NULL; HPEN hPen=NULL, hOldPen; dcSrc = FBitmap->CreateDC(); SetROP2(dcSrc, R2_COPYPEN); hPen = CreatePen(psSolid, thick, c); hOldPen = SelectObject(dcSrc, hPen); MoveToEx(dcSrc, sx, sy, NULL); LineTo(dcSrc, ex, ey); SelectObject(dcSrc, hOldPen); FBitmap->DeleteDC(dcSrc); DeleteObject(hPen); hPen = NULL; } //--------------------------------------------------------------------------- bool __fastcall TPTestKnitImage::Create(int width, int height, int bpp, RGBQUAD *rgb) { FBitmap->CoordinateSystem = csBottomLeft; if (!FBitmap->Create(width, height, bpp, rgb)) return false; FKnitBitmap = (TTexpiaBitmap *) FBitmap; // by celberus return true; } //--------------------------------------------------------------------------- void __fastcall TPTestKnitImage::OutlineBitmapRgn(bool bComplex) { pBITMAPHANDLE bh; RGNXFORM XForm; HRGN rgn; HBRUSH hBrush; if (FBitmap->IsUse) return; bh = FBitmap->Handle; if (bh) { if (L_BitmapHasRgn(bh)) { if (FParentImage) { FZoomIn = FParentImage->ZoomIn; FZoomOut = FParentImage->ZoomOut; } nFrameRgn = (nFrameRgn+1)&7; XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = FZoomIn; XForm.nXScalarDen = FZoomOut; XForm.nYScalarNum = FZoomIn; XForm.nYScalarDen = FZoomOut; XForm.nXOffset = -FPositionX*FZoomIn/FZoomOut; if (ZoomIn>1) { XForm.nYOffset = FMarginY-(FRealPosY-1)*FZoomIn/FZoomOut-FZoomIn; } else { XForm.nYOffset = FMarginY-(FRealPosY-1)*FZoomIn/FZoomOut; } if (bComplex) { L_FrameBitmapRgn(TGraphicControl::Canvas->Handle, bh, &XForm, nFrameRgn); } else { L_GetBitmapRgnHandle(bh, &XForm, &rgn); if ((hBrush = CreatePatternBrush(bmFrameRgn[nFrameRgn])) != NULL) { FrameRgn(TGraphicControl::Canvas->Handle, rgn, hBrush, 1, 1); DeleteObject(hBrush); } DeleteObject(rgn); } } } } //--------------------------------------------------------------------------- void __fastcall TPTestKnitImage::RectEditPaint(RECT Src, TRectEditPaint func, void *pData) { ; } //--------------------------------------------------------------------------- int __fastcall TPTestKnitImage::BitmapToCanvasX(int X) { return (X-FPositionX)*FZoomIn/FZoomOut; } //--------------------------------------------------------------------------- int __fastcall TPTestKnitImage::BitmapToCanvasY(int Y) { return FMarginY+(Y-FRealPosY)*FZoomIn/FZoomOut; } //--------------------------------------------------------------------------- int __fastcall TPTestKnitImage::CanvasToBitmapX(int X) { return FPositionX+X*FZoomOut/FZoomIn; } //--------------------------------------------------------------------------- int __fastcall TPTestKnitImage::CanvasToBitmapY(int Y) { return FRealPosY+(Y-FMarginY)*FZoomOut/FZoomIn; } //--------------------------------------------------------------------------- void __fastcall TPTestKnitImage::FullViewPaint(HDC dcDst, int zi, int zo) { HPALETTE hpaintpal = NULL, holdpal = NULL; int pw, ph, vw, vh; HDC dcSrc = NULL; vw = FBitmap->Width *zi / zo; vh = FBitmap->Height *zi / zo; pw = vw * zo / zi; ph = vh * zo / zi; if (FBitmap->BitsPerPixel==8) { hpaintpal = L_CreatePaintPalette(dcDst, FBitmap->Handle); if (hpaintpal) holdpal = SelectPalette(dcDst, hpaintpal, false); } if ((dcSrc = FBitmap->CreateDC()) == NULL) goto fail; SetStretchBltMode(dcDst, COLORONCOLOR); StretchBlt(dcDst, 0, 0, vw, vh, dcSrc, 0, 0, pw, ph, SRCCOPY); FBitmap->DeleteDC(dcSrc); if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } return; fail: if (dcSrc) FBitmap->DeleteDC(dcSrc); if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } } //--------------------------------------------------------------------------- void __fastcall TPTestKnitImage::ChangeRGBColors(RGBQUAD *rgb) { FBitmap->PutColors(0, 256, rgb); if (FSubBitmap) FSubBitmap->PutColors(0, 256, rgb); if (FSubMask) FSubMask->PutColors(0, 256, rgb); } //--------------------------------------------------------------------------- bool __fastcall TPTestKnitImage::CreateMark() { return true; } //--------------------------------------------------------------------------- bool __fastcall TPTestKnitImage::SetMark() { return true; } //--------------------------------------------------------------------------- bool __fastcall TPTestKnitImage::SetMark(RECT rect) { return true; } //--------------------------------------------------------------------------- bool __fastcall TPTestKnitImage::DrawMark(int x, int y, int n) { return true; } //--------------------------------------------------------------------------- bool __fastcall TPTestKnitImage::ClearMark(int x, int y, int w, int h) { return true; } //--------------------------------------------------------------------------- void __fastcall TPTestKnitImage::SetCrossPos(POINT Pos) { FCrossPos.x = BitmapToCanvasX(Pos.x); FCrossPos.y = BitmapToCanvasY(Pos.y); } //--------------------------------------------------------------------------- namespace Tptestknitimage { void __fastcall PACKAGE Register() { TComponentClass classes[1] = {__classid(TPTestKnitImage)}; RegisterComponents("Texpia", classes, 0); } } //---------------------------------------------------------------------------