//--------------------------------------------------------------------------- #include #pragma hdrstop #include "TPWeaveImage.h" #pragma link "TPImage" #pragma package(smart_init) //--------------------------------------------------------------------------- // ValidCtrCheck is used to assure that the components created do not have // any pure virtual functions. // static inline void ValidCtrCheck(TPWeaveImage *) { new TPWeaveImage(NULL); } //--------------------------------------------------------------------------- __fastcall TPWeaveImage::TPWeaveImage(TComponent* Owner) : TPImage(Owner) { FBitmap = new TTexpiaBitmap; FBitmap->OnPropertyChange = PropertyChange; } //--------------------------------------------------------------------------- __fastcall TPWeaveImage::~TPWeaveImage() { if (FBitmap) delete FBitmap; } //--------------------------------------------------------------------------- // Private Function //--------------------------------------------------------------------------- void __fastcall TPWeaveImage::SetBorderColor(TColor Value) { if (FBorderColor!=Value) { FBorderColor = Value; Paint(); Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TPWeaveImage::SetRepeat(bool Value) { if (Value!=FRepeat) { FRepeat = Value; Paint(); Invalidate(); } } //--------------------------------------------------------------------------- bool __fastcall TPWeaveImage::PositionChange() { int m = FMarginY, r = FRealPosY; if (FBitmap->Handle) { int ps = Height*FZoomOut/FZoomIn; if (FRepeat) { if (ps>FBitmap->Height) { m = FZoomIn>1 ? Height%FZoomIn : 0; r = 0; FRepeatPosY[0] = FBitmap->Height-((Height-FMarginY)*FZoomOut/FZoomIn)%FBitmap->Height; FRepeatPosY[1] = ps-FBitmap->Height; } else { m = FZoomIn>1 ? Height-ps*FZoomIn/FZoomOut : 0; r = FBitmap->Height-FPositionY-ps; FRepeatPosY[0] = 0; FRepeatPosY[1] = 0; } } else { 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; } //--------------------------------------------------------------------------- #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 = (HPEN)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 = (HPEN)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()) == 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); 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; } } if (FCross) PAINT_CROSSLINE; // by playzzang if (FOnPaintLocate) FOnPaintLocate(this,dcMemV);///½Ç¼±À» ±×¸®´Âµ¥ À§Ä¡´Â ±×¶§±×¶§ Á¤ÇÑ´Ù if (FOnPaintZoom) FOnPaintZoom(this, dcMemV); BitBlt(dcDst, 0, FMarginY, vw, vh, dcMemV, 0, 0, SRCCOPY); DeleteDC(dcMemV); DeleteObject(bmMemV); FBitmap->DeleteDC(dcSrc); 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); } FBitmap->DeleteDC(dcSrc); } if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } } //--------------------------------------------------------------------------- void __fastcall TPWeaveImage::PaintBottomMask(BITMAPHANDLE *bh) { BITMAPHANDLE *mh; HPALETTE hpaintpal = NULL, holdpal = NULL; int pw, ph, vw, vh; double sx, sy, syy, gx, gy, gzx, gzy, p; HDC dcSrc = NULL, dcDst, dcMemV = NULL, dcMSrc = NULL; HBITMAP bmMemV =NULL; HPEN hPen = NULL, hOldPen; mh = FMask->Handle; if (mh) { PAINT_INIT; if ((dcMSrc = FMask->CreateDC()) == NULL) goto fail; 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; 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; } } if (FOnPaintLocate) FOnPaintLocate(this,dcMemV);///½Ç¼±À» ±×¸®´Âµ¥ À§Ä¡´Â ±×¶§±×¶§ Á¤ÇÑ´Ù if (FOnPaintZoom) FOnPaintZoom(this, dcMemV); if (FCross) PAINT_CROSSLINE; // by playzzang BitBlt(dcDst, 0, FMarginY, vw, vh, dcMemV, 0, 0, SRCCOPY); DeleteDC(dcMemV); DeleteObject(bmMemV); FBitmap->DeleteDC(dcSrc); FMask->DeleteDC(dcMSrc); if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } if (FOnPaint) FOnPaint(this); } return; fail: if (dcMSrc) { if (dcSrc) { if (bmMemV) { if (dcMemV) { if (hPen) DeleteObject(hPen); DeleteDC(dcMemV); } DeleteObject(bmMemV); } FBitmap->DeleteDC(dcSrc); } FMask->DeleteDC(dcMSrc); } if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } } //--------------------------------------------------------------------------- void __fastcall TPWeaveImage::RepeatBitBlt(HDC dcDst, int nXDst, int nYDst, int nWDst, int nHDst, HDC dcSrc, int nWSrc, int nHSrc, int nXSrc, int nYSrc) { HBITMAP bmMem = NULL; HDC dcMem = NULL; int sx, sy, dx, dy, w, h; if ((bmMem = CreateCompatibleBitmap(dcDst, nWDst, nHDst)) == NULL) goto fail; if ((dcMem = CreateCompatibleDC(dcDst)) == NULL) goto fail; SelectObject(dcMem, bmMem); dy = 0; sy = nYSrc; while (dynHSrc-sy) h = nHSrc-sy; dx = 0; sx = nXSrc; while (dxnWSrc-sx) w = nWSrc-sx; BitBlt(dcMem, dx, dy, w, h, dcSrc, sx, sy, SRCCOPY); dx += w; sx = 0; } dy += h; sy = 0; } BitBlt(dcDst, nXDst, nYDst, nWDst, nHDst, dcMem, 0, 0, SRCCOPY); DeleteDC(dcMem); DeleteObject(bmMem); return; fail: if (bmMem) DeleteObject(bmMem); } //--------------------------------------------------------------------------- #define PAINT_REPEATINIT \ 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; \ } \ rpw = Width*FZoomOut/FZoomIn; \ rph = Height*FZoomOut/FZoomIn; \ pw = rpw>FBitmap->Width-sx ? FBitmap->Width-sx : rpw; \ ph = rph>FBitmap->Height-sy ? FBitmap->Height-sy : rph; \ if (FZoomOut>1) { \ rpw -= rpw%FZoomOut; \ rph -= rph%FZoomOut; \ pw -= pw%FZoomOut; \ ph -= ph%FZoomOut; \ } \ rvw = rpw*FZoomIn/FZoomOut; \ rvh = rph*FZoomIn/FZoomOut; \ vw = pw*FZoomIn/FZoomOut; \ vh = ph*FZoomIn/FZoomOut; \ TGraphicControl::Canvas->Brush->Color = FColor; \ if (rvwFillRect(Rect(rvw, Height-rvh, Width, Height)); \ if (rvhFillRect(Rect(0, 0, Width, Height-rvh)); //--------------------------------------------------------------------------- #define PAINT_GRIDLINE_REPEAT \ SetROP2(dcMemV, R2_COPYPEN); \ if ((hPen = CreatePen(psSolid, 1, FGridColor)) == NULL) goto fail; \ if ((hBorderPen = CreatePen(psSolid, 1, FBorderColor)) == NULL) goto fail; \ p = sx-Floor(sx/gx)*gx; \ if (p>0) { \ hOldPen = (HPEN)SelectObject(dcMemV, hPen); \ p = (gx-p)*FZoomIn/FZoomOut; \ } else { \ if (sx==0) { \ hOldPen = (HPEN)SelectObject(dcMemV, hBorderPen); \ MoveToEx(dcMemV, 0, 0, NULL); \ LineTo(dcMemV, 0, vh); \ SelectObject(dcMemV, hPen); \ } else { \ hOldPen = (HPEN)SelectObject(dcMemV, hPen); \ MoveToEx(dcMemV, 0, 0, NULL); \ LineTo(dcMemV, 0, vh); \ } \ p = gzx; \ } \ while (p0) { \ hOldPen = (HPEN)SelectObject(dcMemV, hPen); \ p = (gy-p)*FZoomIn/FZoomOut; \ } else { \ if (syy==0) { \ hOldPen = (HPEN)SelectObject(dcMemV, hBorderPen); \ MoveToEx(dcMemV, 0, vh-1, NULL); \ LineTo(dcMemV, vw, vh-1); \ SelectObject(dcMemV, hPen); \ } else { \ hOldPen = (HPEN)SelectObject(dcMemV, hPen); \ MoveToEx(dcMemV, 0, vh-1, NULL); \ LineTo(dcMemV, vw, vh-1); \ } \ p = gzy; \ } \ 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 = (HPEN)SelectObject(dcMemV, hPen); \ p = sx-Floor(sx/gx)*gx; \ p = p>0 ? (gx-p)*FZoomIn/FZoomOut : gzx; \ while (p0 ? (gy-p)*FZoomIn/FZoomOut : gzy; \ while (pCreateDC()) == 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); py = rph>FBitmap->Height ? 0 : sy; SetStretchBltMode(dcMemV, COLORONCOLOR); StretchBlt(dcMemV, 0, 0, vw, vh, dcSrc, sx, py, pw, ph, SRCCOPY); 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_REPEAT; } } if (FCross) PAINT_CROSSLINE; // by playzzang if (FOnPaintLocate) FOnPaintLocate(this,dcMemV);///½Ç¼±À» ±×¸®´Âµ¥ À§Ä¡´Â ±×¶§±×¶§ Á¤ÇÑ´Ù if (FOnPaintZoom) FOnPaintZoom(this, dcMemV); RepeatBitBlt(dcDst, 0, FMarginY, rvw, rvh, dcMemV, vw, vh, 0, FRepeatPosY[0]*FZoomIn/FZoomOut); DeleteDC(dcMemV); DeleteObject(bmMemV); FBitmap->DeleteDC(dcSrc); if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } if (FOnPaint) FOnPaint(this); return; fail: if (dcSrc) { if (bmMemV) { if (dcMemV) { if (hPen) { if (hBorderPen) DeleteObject(hBorderPen); DeleteObject(hPen); } DeleteDC(dcMemV); } DeleteObject(bmMemV); } FBitmap->DeleteDC(dcSrc); } if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } } //--------------------------------------------------------------------------- void __fastcall TPWeaveImage::PaintRepeatBottomMask(BITMAPHANDLE *bh) { BITMAPHANDLE *mh; HPALETTE hpaintpal = NULL, holdpal = NULL; int pw, ph, vw, vh, rpw, rph, rvw, rvh, py; double sx, sy, syy, gx, gy, gzx, gzy, p; HDC dcSrc = NULL, dcDst, dcMemV = NULL, dcMSrc = NULL; HBITMAP bmMemV = NULL; HPEN hPen = NULL, hOldPen, hBorderPen = NULL; mh = FMask->Handle; if (mh) { PAINT_REPEATINIT; if ((dcMSrc = FMask->CreateDC()) == NULL) goto fail; 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); py = rph>FBitmap->Height ? 0 : sy; SetStretchBltMode(dcMemV, COLORONCOLOR); StretchBlt(dcMemV, 0, 0, vw, vh, dcSrc, sx, py, pw, ph, SRCCOPY); StretchBlt(dcMemV, 0, 0, vw, vh, dcMSrc, sx, py, 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; 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_REPEAT; } } if (FCross) PAINT_CROSSLINE; // by playzzang if (FOnPaintLocate) FOnPaintLocate(this,dcMemV);///½Ç¼±À» ±×¸®´Âµ¥ À§Ä¡´Â ±×¶§±×¶§ Á¤ÇÑ´Ù if (FOnPaintZoom) FOnPaintZoom(this, dcMemV); RepeatBitBlt(dcDst, 0, FMarginY, rvw, rvh, dcMemV, vw, vh, 0, FRepeatPosY[0]*FZoomIn/FZoomOut); DeleteDC(dcMemV); DeleteObject(bmMemV); FBitmap->DeleteDC(dcSrc); FMask->DeleteDC(dcMSrc); if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } if (FOnPaint) FOnPaint(this); } return; fail: if (dcMSrc) { if (dcSrc) { if (bmMemV) { if (dcMemV) { if (hPen) { if (hBorderPen) DeleteObject(hBorderPen); DeleteObject(hPen); } DeleteDC(dcMemV); } DeleteObject(bmMemV); } FBitmap->DeleteDC(dcSrc); } FMask->DeleteDC(dcMSrc); } if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } } //--------------------------------------------------------------------------- void __fastcall TPWeaveImage::PropertyChange() { if (PositionChange()) { if (FOnPositionChange) FOnPositionChange(this); } Invalidate(); } //--------------------------------------------------------------------------- // Protected Function //--------------------------------------------------------------------------- void __fastcall TPWeaveImage::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) { if (FRepeat) { PaintRepeatBottomMask(bh); } else { PaintBottomMask(bh); } } else { if (FRepeat) { PaintRepeatBottom(bh); } else { PaintBottom(bh); } } } } } //--------------------------------------------------------------------- void __fastcall TPWeaveImage::MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y) { int px, py; if (FCoordinationTransfer) { if (FBitmap->Handle) { if (FRepeat) { px = (FPositionX+X*FZoomOut/FZoomIn)%FBitmap->Width; py = (FRealPosY+FRepeatPosY[0]+(Y-FMarginY)*FZoomOut/FZoomIn)%FBitmap->Height; TControl::MouseDown(Button, Shift, px, py); } else { 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 TPWeaveImage::MouseMove(TShiftState Shift, int X, int Y) { int px, py; if (FCoordinationTransfer) { if (FBitmap->Handle) { if (FRepeat) { px = (FPositionX+X*FZoomOut/FZoomIn)%FBitmap->Width; py = (FRealPosY+FRepeatPosY[0]+(Y-FMarginY)*FZoomOut/FZoomIn)%FBitmap->Height; TControl::MouseMove(Shift, px, py); } else { 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 TPWeaveImage::MouseUp(TMouseButton Button, TShiftState Shift, int X, int Y) { int px, py; if (FCoordinationTransfer) { if (FBitmap->Handle) { if (FRepeat) { px = (FPositionX+X*FZoomOut/FZoomIn)%FBitmap->Width; py = (FRealPosY+FRepeatPosY[0]+(Y-FMarginY)*FZoomOut/FZoomIn)%FBitmap->Height; TControl::MouseUp(Button, Shift, px, py); } else { 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 //--------------------------------------------------------------------------- bool __fastcall TPWeaveImage::Create(int width, int height) { Bitmap->CoordinateSystem = csBottomLeft; if (!Bitmap->Create(width, height, 16)) return false; return true; } //--------------------------------------------------------------------------- void __fastcall TPWeaveImage::OutlineBitmapRgn() { 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 (FRepeat) { XForm.nYOffset = (FRepeatPosY[1]-FRealPosY)*FZoomIn/FZoomOut+1; } else { if (ZoomIn>1) { XForm.nYOffset = FMarginY-(FRealPosY-1)*FZoomIn/FZoomOut-FZoomIn; } else { XForm.nYOffset = FMarginY-(FRealPosY-1)*FZoomIn/FZoomOut; } } L_FrameBitmapRgn(TGraphicControl::Canvas->Handle, bh, &XForm, nFrameRgn); } } } //--------------------------------------------------------------------------- int __fastcall TPWeaveImage::BitmapToCanvasX(int X) { return (X-FPositionX)*ZoomIn/ZoomOut; } //--------------------------------------------------------------------------- int __fastcall TPWeaveImage::BitmapToCanvasY(int Y) { if (FRepeat) { return FMarginY+(FRepeatPosY[1]+Y-FRealPosY)*ZoomIn/ZoomOut; } else { return FMarginY+(Y-FRealPosY)*ZoomIn/ZoomOut; } } //--------------------------------------------------------------------------- int __fastcall TPWeaveImage::CanvasToBitmapX(int X) { if (FRepeat) { return (FPositionX+X*FZoomOut/FZoomIn)%FBitmap->Width; } else { return FPositionX+X*FZoomOut/FZoomIn; } } //--------------------------------------------------------------------------- int __fastcall TPWeaveImage::CanvasToBitmapY(int Y) { if (FRepeat) { return (FRealPosY+(Y-FMarginY-FRepeatPosY[0]*FZoomIn/FZoomOut)*FZoomOut/FZoomIn)%FBitmap->Height; } else { return FRealPosY+(Y-FMarginY)*FZoomOut/FZoomIn; } } //--------------------------------------------------------------------------- void __fastcall TPWeaveImage::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); } } //--------------------------------------------------------------------------- namespace Tpweaveimage { void __fastcall PACKAGE Register() { TComponentClass classes[1] = {__classid(TPWeaveImage)}; RegisterComponents("Texpia", classes, 0); } } //---------------------------------------------------------------------------