//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "TPLayerImage.h" #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) #pragma link "TPImage" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- // À̸§ Á¤ÇÏ´Â ÇÔ¼ö //--------------------------------------------------------------------------- static AnsiString __fastcall getTempLayerFilename() // temp fileÀº »ç¿ëµÇÁö ¾ÊÀ½ { char tp[MAX_PATH+1]; static char fn[MAX_PATH+1]; GetTempPath(MAX_PATH, tp); if (tp[strlen(tp)-1]=='\\') tp[strlen(tp)-1] = 0; while (1) { sprintf(fn, "%s\\TPL%05X.TMP", tp, rand() & 0xFFFFF); if (!FileExists(fn)) break; } return fn; } //--------------------------------------------------------------------------- // TPLayerPart Class ------------ each layer property //--------------------------------------------------------------------------- __fastcall TPLayer::TPLayer(TLayerType lt) { FLayerType = lt; Visible = true; LBitmap = new TUnionBitmap; LMask = FLayerType==LTInitial ? NULL : new TUnionBitmap; MiniBitmap = new TTexpiaBitmap; ARLBitmap = NULL; //by linuxjun ARLMask = NULL; //by linuxjun } //--------------------------------------------------------------------------- __fastcall TPLayer::TPLayer(AnsiString str, AnsiString fn, TLayerType lt) { FLayerType = lt; Name = str; // layer name FileName = fn; Visible = true; LBitmap = new TUnionBitmap; LMask = FLayerType==LTInitial ? NULL : new TUnionBitmap; MiniBitmap = new TTexpiaBitmap; ARLBitmap = NULL; //by linuxjun ARLMask = NULL; //by linuxjun } //--------------------------------------------------------------------------- __fastcall TPLayer::~TPLayer() { if (FileExists(FileName)) DeleteFile(FileName); if (LMask) delete LMask; if (LBitmap) delete LBitmap; if (MiniBitmap) delete MiniBitmap; if(LBitmap != ARLBitmap && ARLBitmap) delete ARLBitmap; if(LMask != ARLMask && ARLMask) delete ARLMask; } //--------------------------------------------------------------------------- void __fastcall TPLayer::UpdateMiniBitmap(RGBQUAD *rgb, RECT rc, bool repaintAll) { ///////////////////////////////////////////////minibitmap // º¸ÅëÀÇ StretchBlt¿¡¼­ Ãà¼Ò ºñÀ²ÀÌ ³Ê¹« ÀÛÀ¸¸é °Ë°Ô º¯ÇÑ´Ù ///////////////////////////////////////////////minibitmap const int widthOfMiniBitmap=500, heightOfMiniBitmap=500; const TRect updateRect = TRect(rc); const int widthOfLayerBitmap = LBitmap->Width; const int heightOfLayerBitmap = LBitmap->Height; if(MiniBitmap->Handle==NULL){ if (LBitmap->BitsPerPixel == 8) { MiniBitmap->Create(widthOfMiniBitmap, heightOfMiniBitmap, 8, rgb); HDC dcMiniBitmap = MiniBitmap->CreateDC(); if(dcMiniBitmap==NULL)return; MiniBitmap->FillRect(Rect(0, 0, widthOfMiniBitmap, heightOfMiniBitmap), LBitmap->BackgroundColor); LBitmap->FullViewUpdate(dcMiniBitmap, widthOfMiniBitmap, heightOfMiniBitmap, true, LBitmap); // by celberus MiniBitmap->DeleteDC(dcMiniBitmap); } else { MiniBitmap->Create(widthOfMiniBitmap, heightOfMiniBitmap, 24); HDC dcMiniBitmap = MiniBitmap->CreateDC(); if(dcMiniBitmap==NULL)return; MiniBitmap->FillRect(Rect(0, 0, widthOfMiniBitmap, heightOfMiniBitmap), LBitmap->BackgroundColor); LBitmap->FullViewUpdate(dcMiniBitmap, widthOfMiniBitmap, heightOfMiniBitmap, true, LBitmap); // by celberus MiniBitmap->DeleteDC(dcMiniBitmap); } } else if(LBitmap->BitsPerPixel == 8) MiniBitmap->PutColors(0,256,rgb); HDC dcMiniBitmap = MiniBitmap->CreateDC(); if(dcMiniBitmap==NULL)return; SetStretchBltMode(dcMiniBitmap, COLORONCOLOR); if(updateRect.left==0&&updateRect.right==0&&updateRect.top==0&&updateRect.bottom==0){ // is all? // LBitmap->UnionStretchBlt(dcMiniBitmap, 0, 0, widthOfMiniBitmap, // heightOfMiniBitmap, 0, 0, widthOfLayerBitmap, heightOfLayerBitmap, SRCCOPY); LBitmap->FullViewUpdate(dcMiniBitmap, widthOfMiniBitmap, heightOfMiniBitmap, repaintAll, LBitmap); // by celberus } else { if(heightOfLayerBitmap==0||widthOfLayerBitmap==0)return; LBitmap->ViewUpdate(dcMiniBitmap, updateRect.Width() * widthOfMiniBitmap / widthOfLayerBitmap, updateRect.Height() * heightOfMiniBitmap / heightOfLayerBitmap, updateRect.left, updateRect.top, updateRect.Width(), updateRect.Height(), repaintAll, LBitmap); } if(dcMiniBitmap) MiniBitmap->DeleteDC(dcMiniBitmap); } // RF by celberus //--------------------------------------------------------------------------- bool __fastcall TPLayer::LoadFromSwapFile(RGBQUAD *rgb) { HANDLE hFile; if ((hFile = CreateFile(FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) goto fail; if (!LoadFromFile(hFile, rgb)) goto fail; CloseHandle(hFile); return true; fail: if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); return false; } //--------------------------------------------------------------------------- bool __fastcall TPLayer::SaveToSwapFile() { LightWeight(); return true; } //--------------------------------------------------------------------------- bool __fastcall TPLayer::LoadFromFile(HANDLE hFile, RGBQUAD *rgb) { DWORD dwRead; int w, h; Byte bpp; if (!ReadFile(hFile, &w, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(hFile, &h, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(hFile, &bpp, sizeof(Byte), &dwRead, NULL)) return false; if (LMask) { if (bpp == 8) { if (!LBitmap->Create(w, h, 8, rgb)) return false; if (!LMask->Create(w, h, 8, rgb)) return false; LMask->BackgroundColor = PALETTEINDEX(255); // by celberus ·¹ÀÌ¾î ÆÄÀÏ ·ÎµåÇÒ ¶§ LayerMaskÀÇ blank¹®Á¦ } else { if (!LBitmap->Create(w, h, 24)) return false; if (!LMask->Create(w, h, 1)) return false; LMask->BackgroundColor = clWhite; // by celberus } if (!LBitmap->LoadFromTexpiaFile(hFile, cmZLib)) return false; if (!LMask->LoadFromTexpiaFile(hFile, cmZLib)) return false; } else { if (bpp == 8) { if (!LBitmap->Create(w, h, 8, rgb)) return false; } else { if (!LBitmap->Create(w, h, 24)) return false; } if (!LBitmap->LoadFromTexpiaFile(hFile, cmZLib)) return false; } return true; } //--------------------------------------------------------------------------- bool __fastcall TPLayer::LoadFromOldFile(HANDLE hFile, RGBQUAD *rgb) { DWORD dwRead; int w, h; Byte bpp; TTexpiaBitmap *tempBitmap = NULL, *tempMask = NULL; if (!ReadFile(hFile, &w, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &h, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &bpp, sizeof(Byte), &dwRead, NULL)) goto fail; if (LMask) { tempBitmap = new TTexpiaBitmap; tempMask = new TTexpiaBitmap; if (bpp == 8) { if (!LBitmap->Create(w, h, 8, rgb)) goto fail; if (!LMask->Create(w, h, 8, rgb)) goto fail; if (!tempBitmap->Create(w, h, 8, rgb)) goto fail; if (!tempMask->Create(w, h, 8, rgb)) goto fail; } else { if (!LBitmap->Create(w, h, 24)) goto fail; if (!LMask->Create(w, h, 1)) goto fail; if (!tempBitmap->Create(w, h, 24)) goto fail; if (!tempMask->Create(w, h, 1)) goto fail; } if (!tempBitmap->LoadFromTexpiaFile(hFile, cmZLib)) goto fail; if (!LBitmap->Copy(tempBitmap, SRCCOPY)) goto fail; if (!tempMask->LoadFromTexpiaFile(hFile, cmZLib)) goto fail; if (!LMask->Copy(tempMask, SRCCOPY)) goto fail; if (tempBitmap) delete tempBitmap; if (tempMask) delete tempMask; } else { tempBitmap = new TTexpiaBitmap; if (bpp == 8) { if (!LBitmap->Create(w, h, 8, rgb)) goto fail; if (!tempBitmap->Create(w, h, 8, rgb)) goto fail; } else { if (!LBitmap->Create(w, h, 24)) goto fail; if (!tempBitmap->Create(w, h, 24)) goto fail; } if (!tempBitmap->LoadFromTexpiaFile(hFile, cmZLib)) goto fail; if (!LBitmap->Copy(tempBitmap, SRCCOPY)) goto fail; if (tempBitmap) delete tempBitmap; } return true; fail: if (tempBitmap) delete tempBitmap; if (tempMask) delete tempMask; return false; } //--------------------------------------------------------------------------- bool __fastcall TPLayer::SaveToFile(HANDLE hFile, bool oldfile) { DWORD dwWrite; Byte bpp; int w, h; w = LBitmap->Width; h = LBitmap->Height; bpp = LBitmap->BitsPerPixel; if (!WriteFile(hFile, &w, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &h, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &bpp, sizeof(Byte), &dwWrite, NULL)) return false; if (!LBitmap->SaveToTexpiaFile(hFile, cmZLib, oldfile)) return false; if (LMask) { if (!LMask->SaveToTexpiaFile(hFile, cmZLib, oldfile)) return false; } return true; } //--------------------------------------------------------------------------- bool __fastcall TPLayer::LoadFromLayerFile(HANDLE FH, int ver, RGBQUAD *rgb) // tex ÆÄÀÏ¿¡¼­ load ÇÒ ¶§ »ç¿ë { DWORD dwRead; char *ch = NULL; int size; if (!ReadFile(FH, &size, sizeof(int), &dwRead, NULL)) goto fail; if ((ch = new char[size]) == NULL) goto fail; if (!ReadFile(FH, ch, size, &dwRead, NULL)) goto fail; Name = AnsiString(ch, size); delete[] ch; ch = NULL; FileName = getTempLayerFilename(); if (!ReadFile(FH, &Visible, sizeof(bool), &dwRead, NULL)) goto fail; if (!ReadFile(FH, &FLayerType, sizeof(bool), &dwRead, NULL)) goto fail; if (ver < 300) { if (!LoadFromOldFile(FH, rgb)) goto fail; } else { if (!LoadFromFile(FH, rgb)) goto fail; } return true; fail: if (ch) delete[] ch; return false; } //--------------------------------------------------------------------------- bool __fastcall TPLayer::SaveToLayerFile(HANDLE FH, RECT r, bool current, bool oldfile) // tex ÆÄÀÏ·Î ÀúÀåÇÒ ¶§ »ç¿ë { DWORD dwRead; Byte bpp; int w, h, size; size = Name.Length(); if (!WriteFile(FH, &size, sizeof(int), &dwRead, NULL)) return false; if (!WriteFile(FH, Name.c_str(), size, &dwRead, NULL)) return false; if (!WriteFile(FH, &Visible, sizeof(bool), &dwRead, NULL)) return false; if (!WriteFile(FH, &FLayerType, sizeof(bool), &dwRead, NULL)) return false; w = r.right - r.left; h = r.bottom - r.top; bpp = LBitmap->BitsPerPixel; if (!WriteFile(FH, &w, sizeof(int), &dwRead, NULL)) return false; if (!WriteFile(FH, &h, sizeof(int), &dwRead, NULL)) return false; if (!WriteFile(FH, &bpp, sizeof(Byte), &dwRead, NULL)) return false; if (!LBitmap->SaveToTexpiaFile(FH, r, cmZLib, oldfile)) return false; if (LMask) { if (!LMask->SaveToTexpiaFile(FH, r, cmZLib, oldfile)) return false; } if (!current) LightWeight(); return true; } //--------------------------------------------------------------------------- bool __fastcall TPLayer::SaveToLayerFile(HANDLE FH, bool current, bool oldfile) { DWORD dwWrite; int size; size = Name.Length(); if (!WriteFile(FH, &size, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(FH, Name.c_str(), size, &dwWrite, NULL)) return false; if (!WriteFile(FH, &Visible, sizeof(bool), &dwWrite, NULL)) return false; if (!WriteFile(FH, &FLayerType, sizeof(bool), &dwWrite, NULL)) return false; if (!SaveToFile(FH,oldfile)) return false; if (!current) LightWeight(); return true; } //--------------------------------------------------------------------------- void __fastcall TPLayer::LightWeight()//////////100°³ÀÇ ·¹À̾ ½ÇÁ¦ÀûÀÎ ÅØ½ºÇÇ¾Æ ºñÆ®¸ÊÀ» ÇÒ´çÇϱ⿡´Â ¸Þ¸ð¸®ÀÇ ¼Ò¸ð°¡ { // ³Ê¹« ¸¹´Ù µû¶ó¼­ ÇöÀç ¼±ÅÃµÈ ·¹À̾ Á¦¿ÜÇÑ ³ª¸ÓÁö ·¹À̾îÀÇ µ¥ÀÌŸ´Â È­ÀÏ¿¡ ///ÀúÀåµÇ°í °¢°¢ÀÇ ÅØ½ºÇÇ¾Æ ºñÆ®¸ÊÀº Áö¿î´Ù //if (LMask) LMask->Destroy(); ///±×·¡¼­ ¹«°Ô¸¦ ´ú¾î Áشٴ ¶æÀ¸·Î LightWeight¶ó°í ÃßÃøÇÑ´Ù--; by jeegeo if (LMask) LMask->UnloadAll(); LBitmap->UnloadAll(); } //--------------------------------------------------------------------------- void __fastcall ScreenInfo::initScreenInfo(int positionX, int positionY, int bitmapWidth, int bitmapHeight, int sZoomIn, int sZoomOut) { zoomIn = sZoomIn; // zoomOut = sZoomOut; // RF ´ú³¡³² SrcX = positionX; SrcY = positionY; setSrcWidth(bitmapWidth); setSrcHeight(bitmapHeight); calViewWidth(); calViewHeight(); } //--------------------------------------------------------------------------- void __fastcall ScreenInfo::setSrcWidth(int bitmapWidth) { SrcW = screenWidth * zoomOut / zoomIn; if (SrcW > bitmapWidth - SrcX) SrcW = bitmapWidth - SrcX; if (zoomOut > 1) { SrcW -= SrcW % zoomOut; } } //--------------------------------------------------------------------------- void __fastcall ScreenInfo::setSrcHeight(int bitmapHeight) { SrcH = screenHeight * zoomOut / zoomIn; if (SrcH > bitmapHeight - SrcY) SrcH = bitmapHeight - SrcY; if (zoomOut > 1) { SrcH -= SrcH % zoomOut; } } //--------------------------------------------------------------------------- void __fastcall ScreenInfo::calViewWidth() { ViewW = SrcW * zoomIn / zoomOut; } //--------------------------------------------------------------------------- void __fastcall ScreenInfo::calViewHeight() { ViewH = SrcH * zoomIn / zoomOut; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // TPLayerImage //--------------------------------------------------------------------------- // ValidCtrCheck is used to assure that the components created do not have // any pure virtual functions. // //--------------------------------------------------------------------------- static inline void ValidCtrCheck(TPLayerImage *) { new TPLayerImage(NULL); } //--------------------------------------------------------------------------- __fastcall TPLayerImage::TPLayerImage(TComponent* Owner) : TPImage(Owner) { TPLayer *lay; FBackGroundLock = 0; FIndex = -1; FPositionX = FPositionY = 0; LayerList = new TList; // AutoRepeatLayerList = new TList; // ARDeletedLayerList = new TList; FUpperMask = NULL; FLowerBitmap = FUpperBitmap = NULL; FbmFullView = new TTexpiaBitmap; //qe FbmScreen = new TTexpiaBitmap; FLayerVisible = true; FCurrentBitmap = NULL; FOnPaintRange = NULL; FOnPaintDirectly = NULL; FOnPaintVector = NULL; FOnFullViewRectPaint=NULL; FOnLayerGridRectPaint=NULL; isRepaintAll = false; //by celberus isZoomChanged = false; // by celberus isColorChanged = false; // by celberus useRealLayerForLower = false; //by celberus useRealLayerForUpper = false; //by celberus _subPaintType = typeNone; // by celberus screenInfo.screenPosX = 0; screenInfo.screenPosY = 0; AccumulatedIndexNum=0; //by linuxjun Undo_Method FIsActivate = true; lay = new TPLayer("Background", getTempLayerFilename(), LTInitial); LayerList->Add(lay); lay->SetLayerOrder(AccumulatedIndexNum++); //by linuxjun Undo_Method SetIndex(LayerList->Count - 1); ChangeBitmap(lay); } //--------------------------------------------------------------------------- __fastcall TPLayerImage::~TPLayerImage() { TPLayer *oneLayer; while (LayerList->Count) { oneLayer = (TPLayer *) LayerList->Last(); LayerList->Remove(oneLayer); delete oneLayer; } delete LayerList; //////////for new AutoRepeat Undo /*while (ARDeletedLayerList->Count) { oneLayer = (TPLayer *) ARDeletedLayerList->Last(); ARDeletedLayerList->Remove(oneLayer); delete oneLayer; } delete ARDeletedLayerList; while (AutoRepeatLayerList->Count) { oneLayer = (TPLayer *) AutoRepeatLayerList->Last(); AutoRepeatLayerList->Remove(oneLayer); //delete oneLayer; } delete AutoRepeatLayerList; */ ////////////////////////////////// DeleteAfter(); DeleteBefore(); doDestroy(FbmFullView) //qe doDestroy(FbmScreen) } //--------------------------------------------------------------------------- bool __fastcall TPLayerImage::Create(int width, int height, int bpp, COLORREF bgcolor, RGBQUAD *rgb) { if (!FCurrentBitmap->Create(width, height, bpp)) return false; if (bpp == 8) { if (FCurrentMask) if (!FCurrentMask->Create(width, height, 8)) return false; memcpy(Frgb, rgb, sizeof(RGBQUAD) * 256); ChangeRGBColors(rgb); } else { if (FCurrentMask) if (!FCurrentMask->Create(width, height, 1)) return false; } FLayerBGColor = bgcolor; MakeBeforeBitmap(); return true; } //--------------------------------------------------------------------------- // ÀÌÇÏ Repaint °ü·Ã //--------------------------------------------------------------------------- \ //--------------------------------------------------------------------------- HDC __fastcall TPLayerImage::paint_init() { HDC canvasDC; screen_init(); canvasDC = TGraphicControl::Canvas->Handle; if (FCurrentBitmap->BitsPerPixel==8) { // hpaintpal = L_CreatePaintPalette(dcDst, bh); // if (hpaintpal) holdpal = SelectPalette(dcDst, hpaintpal, false); // FCurrentBitmap->BackgroundColor = PALETTERGB(Frgb[1].rgbRed, Frgb[1].rgbGreen, Frgb[1].rgbBlue); // ¹ÙÅÁ»ö ¼³Á¤À» À§ÇÑ ÀӽùæÆí by celberus } TGraphicControl::Canvas->Brush->Color = FColor; // image°¡ ±×·ÁÁöÁö ¾Ê´Â ºÎºÐÀ» ȸ»ö(clBtnFace)À¸·Î ä¿î´Ù. if (screenInfo.ViewWFillRect(Rect(screenInfo.ViewW, 0, Width, Height)); if (screenInfo.ViewHFillRect(Rect(0, screenInfo.ViewH, Width, Height)); return canvasDC; } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::screen_init() { screenInfo.screenWidth = Width; // screenInfo.screenHeight = Height; // RF ´ú³¡³² screenInfo.initScreenInfo(FPositionX, FPositionY, FCurrentBitmap->Width, FCurrentBitmap->Height, FZoomIn, FZoomOut); // } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::rectpaint_init(RECT &Src, int &px, int &py) { /*sx = Src.left; sy = Src.top; if (FZoomOut>1 && FZoomIn == 1) { Src.left -= Src.left%FZoomOut; Src.top -= Src.top%FZoomOut; Src.right -= Src.right%FZoomOut; Src.bottom -= Src.bottom%FZoomOut; } if (FZoomIn>1 && FZoomOut != 1) { Src.left -= Src.left%FZoomOut; Src.top -= Src.top%FZoomOut; Src.right += Src.right%FZoomOut; Src.bottom += Src.bottom%FZoomOut; } pw = Src.right - Src.left; ph = Src.bottom - Src.top; RECT canvasRect = BitmapToCanvasRect(Src); px = canvasRect.left; py = canvasRect.top; vw = canvasRect.right - canvasRect.left; vh = canvasRect.bottom - canvasRect.top; */ int screenWidth, screenHeight; screenInfo.SrcX = FPositionX; screenInfo.SrcY = FPositionY; Src.left -= screenInfo.SrcX; Src.top -= screenInfo.SrcY; Src.right -= screenInfo.SrcX; Src.bottom -= screenInfo.SrcY; screenWidth = min(Width*FZoomOut/FZoomIn, int(FCurrentBitmap->Width-screenInfo.SrcX)); screenHeight = min(Height*FZoomOut/FZoomIn, int(FCurrentBitmap->Height-screenInfo.SrcY)); if (Src.left<0) Src.left = 0; if (Src.top<0) Src.top = 0; if (Src.right<0) Src.right = 0; if (Src.bottom<0) Src.bottom = 0; if (Src.left>screenWidth) Src.left = screenWidth; if (Src.top>screenHeight) Src.top = screenHeight; if (Src.right>screenWidth) Src.right = screenWidth; if (Src.bottom>screenHeight) Src.bottom = screenHeight; if (FZoomOut>1 && FZoomIn == 1) { Src.left -= Src.left%FZoomOut; Src.top -= Src.top%FZoomOut; Src.right -= Src.right%FZoomOut; Src.bottom -= Src.bottom%FZoomOut; } if (FZoomIn>1 && FZoomOut != 1) { Src.left -= Src.left%FZoomOut; Src.top -= Src.top%FZoomOut; if(Src.right%FZoomOut!=0) Src.right += FZoomOut-Src.right%FZoomOut; if(Src.bottom%FZoomOut!=0) Src.bottom += FZoomOut-Src.bottom%FZoomOut; } screenInfo.SrcW = Src.right-Src.left; screenInfo.SrcH = Src.bottom-Src.top; screenInfo.ViewW = screenInfo.SrcW*FZoomIn/FZoomOut; screenInfo.ViewH = screenInfo.SrcH*FZoomIn/FZoomOut; px = Src.left*FZoomIn/FZoomOut; py = Src.top*FZoomIn/FZoomOut; screenInfo.SrcX += Src.left; screenInfo.SrcY += Src.top; } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::rectpaint_init2(BITMAPHANDLE *bh, HDC &dcDst, HPALETTE &hpaintpal, HPALETTE &holdpal){ dcDst = TGraphicControl::Canvas->Handle; if (FCurrentBitmap->BitsPerPixel==8) { hpaintpal = L_CreatePaintPalette(dcDst, bh); if (hpaintpal) holdpal = SelectPalette(dcDst, hpaintpal, false); } } //--------------------------------------------------------------------------- #define RECTPAINT_INIT \ rectpaint_init(Src, px, py); \ rectpaint_init2(bh, dcDst, hpaintpal, holdpal); //--------------------------------------------------------------------------- #define PAINT_END \ if (bmMemL) { \ if (dcMemL) { \ DeleteDC(dcMemL); \ dcMemL=NULL; \ } \ DeleteObject(bmMemL); \ bmMemL=NULL; \ } \ if (bmMemV) { \ if (dcMemV) { \ DeleteDC(dcMemV); \ dcMemV=NULL; \ } \ DeleteObject(bmMemV); \ bmMemV=NULL; \ } \ if(temp) { \ if(dcSrc) { \ temp->DeleteDC(dcSrc); \ dcSrc=NULL; \ } \ delete temp; temp = NULL; \ } else { \ if (bmMemB) { \ if (dcSrc) { \ DeleteDC(dcSrc); \ dcSrc=NULL; \ } \ DeleteObject(bmMemB); \ bmMemB=NULL; \ } \ } \ if (hpaintpal) { \ if (holdpal) SelectPalette(dcDst, holdpal, false); \ DeleteObject(hpaintpal); \ hpaintpal=NULL; \ } //ÆÈ·¹Æ®´Â ¹«Á¶°Ç Á¦ÀÏ ³ªÁß¿¡ Áö¿öÁà¾ßÇÑ´Ù. ±×·¸Áö ¾ÊÀ¸¸é ¾Ë¼ö¾ø´Â ¸Þ¸ð¸® ´©ÃâÀÌ »ý±æ¼ö ÀÖ´Ù //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TPLayerImage::Paint() { HDC dc; if (ComponentState.Contains(csDesigning)) { TGraphicControl::Canvas->Pen->Style = psDash; TGraphicControl::Canvas->Brush->Style = bsClear; TGraphicControl::Canvas->Rectangle(0, 0, Width, Height); } else { if (Width<=0 || Height<=0) return; if (FIsActivate||LayerList->Count<=1) { // FBackGround´Â ·¹À̾ 2°³ ÀÌ»óÀ϶§ NULLÀÌ ¾Æ´Ñ °ªÀ» °¡Áø´Ù if (FCurrentBitmap->BitsPerPixel != 0) PaintTop(); // clear whole ó·³ ¸ðµç Á¶°¢ÀÌ ¸Þ¸ð¸®¿¡ ¾øÀ» ¶§¿¡µµ repaint°¡ °¡´ÉÇØ¾ß µÇ¹Ç·Î ÀÌ·¸°Ô ¹Ù²Þ by celberus } else { dc = FbmScreen->CreateDC(); BitBlt(TGraphicControl::Canvas->Handle, 0, 0, FbmScreen->Width, FbmScreen->Height, dc, 0, 0, SRCCOPY); FbmScreen->DeleteDC(dc); } } } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TPLayerImage::PaintTop() { //static bool isPainting = false; //if(isPainting) return; //isPainting = true; int anyUpdated; HPALETTE hpaintpal = NULL, holdpal = NULL; HDC dcSrc, dcDst, dcBufDst = NULL; HBITMAP bmBufDst = NULL; TTexpiaBitmap *TempForSubBitmap = NULL; // static lastsx = 0, lastsy = 0; dcDst = paint_init(); if (FbmScreen->Width != screenInfo.ViewW || FbmScreen->Height != screenInfo.ViewH) bmScreenResize(screenInfo.ViewW, screenInfo.ViewH); if (FbmScreen->Blank || screenInfo.SrcX != screenInfo.screenPosX || screenInfo.SrcY != screenInfo.screenPosY || isRepaintAll || isZoomChanged){ // isRepaintAll Àº layer visible change, Exchange Layer, whole clear¶§ true·Î ¹Ù²ãÁØ´Ù. screenInfo.screenPosX = screenInfo.SrcX; screenInfo.screenPosY = screenInfo.SrcY; if ((dcSrc = FbmScreen->CreateDC()) == NULL) goto fail; if (FLowerBitmap) { if((anyUpdated = FLowerBitmap->ViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, true, FCurrentBitmap)) < 0 ) goto fail; if (FLayerVisible) { if((anyUpdated = FLowerBitmap->MergedViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, FCurrentBitmap, FCurrentMask, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, true, FCurrentBitmap)) < 0 ) goto fail; } } else { if (FLayerVisible) { if((anyUpdated = FCurrentBitmap->ViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, true, FCurrentBitmap)) < 0 ) goto fail; } else if(!FUpperBitmap) { BitBlt(dcSrc, 0, 0, screenInfo.ViewW, screenInfo.ViewH, NULL, 0, 0, WHITENESS); // mark U } } if (FSubEnabled && FSubVisible) { TempForSubBitmap = new TTexpiaBitmap; if (dcSrc) FbmScreen->DeleteDC(dcSrc); TempForSubBitmap->Copy(FbmScreen, SRCCOPY); dcSrc = TempForSubBitmap->CreateDC(); SubPaint(dcSrc, hpaintpal, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH); } if (FUpperBitmap) { if(!FLowerBitmap && !FLayerVisible) { // mark U if((anyUpdated = FUpperBitmap->ViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, true, FCurrentBitmap)) < 0 ) goto fail; // mark U bitblt¸¦ whiteness·Î Çϸé upperbitmapÀÌ ±×·ÁÁöÁö ¾Ê´Â ¹®Á¦ ¶§¹®¿¡.. by celberus } else { if((anyUpdated = FCurrentBitmap->MergedViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, FUpperBitmap, FUpperMask, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, true, FCurrentBitmap)) < 0 ) goto fail; } } if(isRepaintAll){ FullViewUpdate(true); } FbmScreen->Blank = false; isRepaintAll = false; } // modify repaint ºÎºÐ else { if ((dcSrc = FbmScreen->CreateDC()) == NULL) goto fail; if (FLowerBitmap) { if((anyUpdated = FLowerBitmap->ViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, false, FCurrentBitmap)) < 0 ) goto fail; if (FLayerVisible) { anyUpdated = FLowerBitmap->MergedViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, FCurrentBitmap, FCurrentMask, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, false, FCurrentBitmap); } } else { if (FLayerVisible) { if((anyUpdated = FCurrentBitmap->ViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, false, FCurrentBitmap)) < 0 ) goto fail; } else if(!FUpperBitmap) { BitBlt(dcSrc, 0, 0, screenInfo.ViewW, screenInfo.ViewH, NULL, 0, 0, WHITENESS); // mark U } } if (FSubEnabled && FSubVisible) { if (dcSrc) FbmScreen->DeleteDC(dcSrc); TempForSubBitmap = new TTexpiaBitmap; TempForSubBitmap->Copy(FbmScreen, SRCCOPY); dcSrc = TempForSubBitmap->CreateDC(); SubPaint(dcSrc, hpaintpal, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH); if (FUpperBitmap) { if (!FLowerBitmap && !FLayerVisible) { if((anyUpdated = FUpperBitmap->ViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, true, FCurrentBitmap)) < 0 ) goto fail; } else { if((anyUpdated = FCurrentBitmap->MergedViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, FUpperBitmap, FUpperMask, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, true, FCurrentBitmap)) < 0 ) goto fail; } } } if (FUpperBitmap) { if (!FLowerBitmap && !FLayerVisible) { if((anyUpdated = FUpperBitmap->ViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, false, FCurrentBitmap)) < 0 ) goto fail; } else { if((anyUpdated = FCurrentBitmap->MergedViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, FUpperBitmap, FUpperMask, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, false, FCurrentBitmap)) < 0 ) goto fail; } } if(isColorChanged) { isColorChanged = false; } else { anyUpdated = FullViewUpdate(false); } if(anyUpdated)FCurrentBitmap->RepaintFinished(0, 0, FCurrentBitmap->Width, FCurrentBitmap->Height); // ¿µ¿ªÀÌ Àüü°¡ µÈ´Ù. FbmScreen->Blank = false; } // ¿©±â±îÁö modify repaint if (FMaskEnabled&&FMask->BitsPerPixel != 0) { if (!TempForSubBitmap) { // subbitmapÀÇ repaint ¹æ¹ýÀ» µû¿Ô½À´Ï´Ù ³ªÁß¿¡ °íÃÄÁÖ¼¼¿ä by celberus if (dcSrc) FbmScreen->DeleteDC(dcSrc); TempForSubBitmap = new TTexpiaBitmap; TempForSubBitmap->Copy(FbmScreen, SRCCOPY); dcSrc = TempForSubBitmap->CreateDC(); } FMask->UnionStretchBlt(dcSrc, 0, 0, screenInfo.ViewW, screenInfo.ViewH, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, SRCINVERT); } /////////////////////////////////////////////////¼±±×¸®±â ±ô¹ÚÀÓÁ¦°Å by jeegeo if ((bmBufDst = CreateCompatibleBitmap(dcDst, screenInfo.ViewW, screenInfo.ViewH)) == NULL) goto fail; if ((dcBufDst = CreateCompatibleDC(dcDst)) == NULL) goto fail; SelectObject(dcBufDst, bmBufDst); BitBlt(dcBufDst, 0, 0, screenInfo.ViewW, screenInfo.ViewH, dcSrc, 0, 0, SRCCOPY); if (FOnPaintRange) FOnPaintRange(this, dcBufDst, 0, 0); // range, gridline, vector¿¡¼­ dcMemV -> dcSrc by celberus // if (FOnPaintZoom) FOnPaintZoom(this, dcMemV); if (FGrid) { if (!Paint_GridLine(dcBufDst, screenInfo.SrcX, screenInfo.SrcY, screenInfo.ViewW, screenInfo.ViewH)) goto fail; } if (FOnPaintVector) FOnPaintVector(dcBufDst, 0, 0, 0, 0); if(FOnPaintDirectly)FOnPaintDirectly(dcBufDst, 0, 0, screenInfo.ViewW, screenInfo.ViewH); BitBlt(dcDst, 0, 0, screenInfo.ViewW, screenInfo.ViewH, dcBufDst, 0, 0, SRCCOPY); if (bmBufDst) { if (dcBufDst) { DeleteDC(dcBufDst); } DeleteObject(bmBufDst); } if (TempForSubBitmap) { if (dcSrc) { TempForSubBitmap->DeleteDC(dcSrc); } delete TempForSubBitmap; } else if (dcSrc) { FbmScreen->DeleteDC(dcSrc); } ////////////////////////////////////////////////////////////////////////////// //FOnPaint´Â TPStretchImage¿¡¼­´Â ¾²ÀÌÁö¸¸ ¿©±â¼­´Â »ç½Ç»ó ÇÊ¿ä¾ø´Ù if (FOnPaint) FOnPaint(this); // FbmScreen->DeleteDC(dcSrc); //PAINT_END¿¡´Ù°¡ Áý¾î³Ö¾î¾ß ÇÑ´Ù. if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } //isPainting = false; // screenInfo.screenPosX = screenInfo.SrcX; screenInfo.screenPosY = screenInfo.SrcY; return; fail: /////////////////////////////////////////////////¼±±×¸®±â ±ô¹ÚÀÓÁ¦°Å by jeegeo if (bmBufDst) { if (dcBufDst) { DeleteDC(dcBufDst); } DeleteObject(bmBufDst); } ////////////////////////////////////////////////////////////////////////////// if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } //isPainting = false; } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::bmScreenResize(int w, int h) { if (!FCurrentBitmap) return; if (FCurrentBitmap->BitsPerPixel == 8) { if (!FbmScreen->Create(w, h, 8, Frgb)) goto fail; } else { if (!FbmScreen->Create(w, h, 24)) goto fail; } FbmScreen->Blank = true; return; fail: } //--------------------------------------------------------------------------- bool __fastcall TPLayerImage::RectPaint(RECT Src, bool ShowOnly) { BITMAPHANDLE *bh; HPALETTE hpaintpal = NULL, holdpal = NULL; int px, py; HDC dcSrc, dcDst=NULL, dcScreen; HBITMAP bmTemp; int anyUpdated; if(FCurrentBitmap->BitsPerPixel == 0) return false; bh = FbmScreen->Handle; if (Src.leftWidth && Src.right>=FPositionX && Src.topHeight && Src.bottom>=FPositionY) { RECTPAINT_INIT; if(Src.left == Src.right || Src.top == Src.bottom) goto fail; // È­¸é ¹ÛÀ¸·Î ±×¸±¶§ ÇÚµéÀ» ÀÒ´Â ¹®Á¦ ¶§¹®¿¡ 03-04-07 by celberus if ((dcScreen = FbmScreen->CreateDC()) == NULL) goto fail; if ((bmTemp = CreateCompatibleBitmap(dcScreen, screenInfo.ViewW, screenInfo.ViewH)) == NULL) goto fail; if ((dcSrc = CreateCompatibleDC(dcScreen)) == NULL) goto fail; SelectObject(dcSrc, bmTemp); if (hpaintpal) SelectPalette(dcSrc, hpaintpal, false); if (FLowerBitmap) { if((anyUpdated = FLowerBitmap->ViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, true, FCurrentBitmap)) < 0 ) goto fail; if (FLayerVisible) { if((anyUpdated = FLowerBitmap->MergedViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, FCurrentBitmap, FCurrentMask, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, true, FCurrentBitmap)) < 0 ) goto fail; } } else { if (FLayerVisible) { if((anyUpdated = FCurrentBitmap->ViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, true, FCurrentBitmap)) < 0 ) goto fail; } else if(!FUpperBitmap) { BitBlt(dcSrc, 0, 0, screenInfo.ViewW, screenInfo.ViewH, NULL, 0, 0, WHITENESS); } } if (FSubEnabled && FSubVisible) SubPaint(dcSrc, hpaintpal, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH); if (FUpperBitmap) { if(!FLowerBitmap && !FLayerVisible) { // mark U if((anyUpdated = FUpperBitmap->ViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, true, FCurrentBitmap)) < 0 ) goto fail; // mark U bitblt¸¦ whiteness·Î Çϸé upperbitmapÀÌ ±×·ÁÁöÁö ¾Ê´Â ¹®Á¦ ¶§¹®¿¡.. by celberus } else { if((anyUpdated = FCurrentBitmap->MergedViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, FUpperBitmap, FUpperMask, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, true, FCurrentBitmap)) < 0 ) goto fail; } } FbmScreen->Blank = false; FbmScreen->DeleteDC(dcScreen); dcScreen = NULL; if(FMaskEnabled&&FMask->BitsPerPixel != 0){ FMask->UnionStretchBlt(dcSrc, 0, 0, screenInfo.ViewW, screenInfo.ViewH, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, SRCINVERT); } if (FOnPaintRange) FOnPaintRange(this, dcSrc, px, py); if (FGrid) { if (!Paint_GridLine(dcSrc, screenInfo.SrcX, screenInfo.SrcY, screenInfo.ViewW, screenInfo.ViewH)) goto fail; } if (FOnPaintVector) FOnPaintVector(dcSrc, px, py, 0, 0); BitBlt(dcDst, px, py, screenInfo.ViewW, screenInfo.ViewH, dcSrc, 0, 0, SRCCOPY); if(FOnLayerGridRectPaint){ FOnLayerGridRectPaint(NULL,screenInfo.SrcX,screenInfo.SrcY,screenInfo.SrcW,screenInfo.SrcH);//layergrid ¾÷µ¥ÀÌÆ® } if(!ShowOnly){ if (!FSubEnabled||!FSubVisible){ FullViewUpdateRect(screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH); // rename by celberus } } if (dcSrc) { DeleteDC(dcSrc); } if (bmTemp) { DeleteObject(bmTemp); } if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } } return true; fail: if (dcScreen) { FbmScreen->DeleteDC(dcScreen); } if (dcSrc) { DeleteDC(dcSrc); } if (bmTemp) { DeleteObject(bmTemp); } if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); hpaintpal=NULL; } return false; } //---------------------------------------------------------------------------- bool __fastcall TPLayerImage::RectEditPaint(RECT Src, TRectEditPaint func, void *pData) { BITMAPHANDLE *bh; HPALETTE hpaintpal = NULL, holdpal = NULL; int px, py; HDC dcSrc, dcDst=NULL, dcScreen; HBITMAP bmTemp, bmDraw; HDC realSizedDC = NULL; int anyUpdated; Src.left--; Src.right++; Src.top--; Src.bottom++; if(FCurrentBitmap->BitsPerPixel == 0) return false; bh = FbmScreen->Handle; if (Src.leftWidth && Src.right>=FPositionX && Src.topHeight && Src.bottom>=FPositionY) { rectpaint_init(Src, px, py); rectpaint_init2(bh, dcDst, hpaintpal, holdpal); if(Src.left == Src.right || Src.top == Src.bottom) goto fail; // È­¸é ¹ÛÀ¸·Î ±×¸±¶§ ÇÚµéÀ» ÀÒ´Â ¹®Á¦ ¶§¹®¿¡ 03-04-07 by celberus if ((dcScreen = FbmScreen->CreateDC()) == NULL) goto fail; if ((bmTemp = CreateCompatibleBitmap(dcScreen, screenInfo.ViewW, screenInfo.ViewH)) == NULL) goto fail; if ((dcSrc = CreateCompatibleDC(dcScreen)) == NULL) goto fail; SelectObject(dcSrc, bmTemp); if (hpaintpal) SelectPalette(dcSrc, hpaintpal, false); BitBlt(dcSrc, 0, 0, screenInfo.ViewW, screenInfo.ViewH, dcScreen, BitmapToCanvasX(screenInfo.SrcX), BitmapToCanvasY(screenInfo.SrcY), SRCCOPY); // ·¹À̾î ÁÜ 1/3 µîÀ϶§ÀÇ ²ÞƲ°Å¸² ¶§¹®¿¡.. °ú¿¬ Àß µÉ±î? if (FSubEnabled && FSubVisible) SubPaint(dcSrc, hpaintpal, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH); FbmScreen->Blank = false; if (func) { if(screenInfo.zoomIn <= screenInfo.zoomOut) { func(dcSrc, screenInfo.SrcX, screenInfo.SrcY, pData); } else { // by celberus zoomIn ÇßÀ»¶§ ²ÞƲ°Å¸®´Â ¹®Á¦ ¶§¹®¿¡.. if ((bmDraw = CreateCompatibleBitmap(dcScreen, screenInfo.SrcW, screenInfo.SrcH)) == NULL) goto fail; if ((realSizedDC = CreateCompatibleDC(dcScreen)) == NULL) goto fail; SelectObject(realSizedDC, bmDraw); SetStretchBltMode(realSizedDC, COLORONCOLOR); StretchBlt(realSizedDC, 0, 0, screenInfo.SrcW, screenInfo.SrcH, dcSrc, 0, 0, screenInfo.ViewW, screenInfo.ViewH, SRCCOPY); func(realSizedDC, screenInfo.SrcX, screenInfo.SrcY, pData); SetStretchBltMode(dcSrc, COLORONCOLOR); StretchBlt(dcSrc, 0, 0, screenInfo.ViewW, screenInfo.ViewH, realSizedDC, 0, 0, screenInfo.SrcW, screenInfo.SrcH, SRCCOPY); if (realSizedDC) { DeleteDC(realSizedDC); realSizedDC = NULL; } if (bmDraw) { DeleteObject(bmDraw); bmDraw = NULL; } } } if (FUpperBitmap) { if(!FLowerBitmap && !FLayerVisible) { // mark U if((anyUpdated = FUpperBitmap->ViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, true, FCurrentBitmap)) < 0 ) goto fail; // mark U bitblt¸¦ whiteness·Î Çϸé upperbitmapÀÌ ±×·ÁÁöÁö ¾Ê´Â ¹®Á¦ ¶§¹®¿¡.. by celberus } else { if((anyUpdated = FCurrentBitmap->MergedViewUpdate(dcSrc, screenInfo.ViewW, screenInfo.ViewH, FUpperBitmap, FUpperMask, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, true, FCurrentBitmap)) < 0 ) goto fail; } } FbmScreen->DeleteDC(dcScreen); dcScreen = NULL; // by celberus if(FMaskEnabled&&FMask->BitsPerPixel != 0){ FMask->UnionStretchBlt(dcSrc, 0, 0, screenInfo.ViewW, screenInfo.ViewH, screenInfo.SrcX, screenInfo.SrcY, screenInfo.SrcW, screenInfo.SrcH, SRCINVERT); } if (FOnPaintRange) FOnPaintRange(this, dcSrc, px, py); if (FGrid) { if (!Paint_GridLine(dcSrc, screenInfo.SrcX, screenInfo.SrcY, screenInfo.ViewW, screenInfo.ViewH)) goto fail; } if (FOnPaintVector) FOnPaintVector(dcSrc, px, py, 0, 0); BitBlt(dcDst, px, py, screenInfo.ViewW, screenInfo.ViewH, dcSrc, 0, 0, SRCCOPY); if(FOnLayerGridRectPaint){ FOnLayerGridRectPaint(NULL,screenInfo.SrcX,screenInfo.SrcY,screenInfo.SrcW,screenInfo.SrcH);//layergrid ¾÷µ¥ÀÌÆ® } if (dcSrc) { DeleteDC(dcSrc); } // by celberus if (bmTemp) { DeleteObject(bmTemp); } if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } } return true; fail: // ¹º°¡ ºÎÁ·Çѵí.. if (realSizedDC) { DeleteDC(realSizedDC); } if (bmDraw) { DeleteObject(bmDraw); } if (dcScreen) { FbmScreen->DeleteDC(dcScreen); dcScreen = NULL; } if (dcSrc) { DeleteDC(dcSrc); } // by celberus if (bmTemp) { DeleteObject(bmTemp); } \ if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } return false; } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::PaintImageEdit(TEditPaintEvent func) { BITMAPHANDLE *bh; HPALETTE hpaintpal = NULL, holdpal = NULL; int pw, ph, vw, vh; HDC dcDst, dcMem = NULL; HBITMAP bmMem; // bh = FCurrentBitmap->Handle; if (/*bh*/FCurrentBitmap->BitsPerPixel != 0) { bh = FbmScreen->Handle; dcDst = TGraphicControl::Canvas->Handle; if (FCurrentBitmap->BitsPerPixel==8) { hpaintpal = L_CreatePaintPalette(dcDst, bh); if (hpaintpal) holdpal = SelectPalette(dcDst, hpaintpal, false); } pw = Width*FZoomOut/FZoomIn; ph = Height*FZoomOut/FZoomIn; if (pw>FCurrentBitmap->Width-FPositionX) pw = FCurrentBitmap->Width-FPositionX; if (ph>FCurrentBitmap->Height-FPositionY) ph = FCurrentBitmap->Height-FPositionY; if (FZoomOut>1) { pw -= pw%FZoomOut; ph -= ph%FZoomOut; } vw = pw*FZoomIn/FZoomOut; vh = ph*FZoomIn/FZoomOut; if ((bmMem = CreateCompatibleBitmap(dcDst, vw, vh)) == NULL) goto fail; if ((dcMem = CreateCompatibleDC(dcDst)) == NULL) goto fail; SelectObject(dcMem, bmMem); if (hpaintpal) SelectPalette(dcMem, hpaintpal, false); BitBlt(dcMem, 0, 0, vw, vh, dcDst, 0, 0, SRCCOPY); if (func) func(this, dcMem); BitBlt(dcDst, 0, 0, vw, vh, dcMem, 0, 0, SRCCOPY); DeleteDC(dcMem); DeleteObject(bmMem); if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } } return; fail: if (bmMem) { if (dcMem) DeleteDC(dcMem); DeleteObject(bmMem); } if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::FbmFullViewUdate(HDC dcSrc, int sx, int sy, int pw, int ph, int vw, int vh) { HBITMAP bmTemp; HDC dcFullView, dcTemp; int fvsx=FbmFullView->Width*sx/FCurrentBitmap->Width; int fvsy=FbmFullView->Height*sy/FCurrentBitmap->Height; int fvpw=FbmFullView->Width*pw/FCurrentBitmap->Width; int fvph=FbmFullView->Height*ph/FCurrentBitmap->Height; dcFullView = FbmFullView->CreateDC(); SetStretchBltMode(dcFullView, COLORONCOLOR); StretchBlt(dcFullView, fvsx, fvsy, fvpw, fvph, dcSrc, 0 ,0, vw, vh, SRCCOPY); if ((bmTemp = CreateCompatibleBitmap(dcFullView, FbmFullView->Width, FbmFullView->Height)) == NULL) return; if ((dcTemp = CreateCompatibleDC(dcFullView)) == NULL) return; SelectObject(dcTemp, bmTemp); BitBlt(dcTemp, 0, 0, FbmFullView->Width, FbmFullView->Height, dcFullView, 0, 0, SRCCOPY); if (FOnPaintVector) { FOnPaintVector(dcTemp, -1, -1, FbmFullView->Width, FbmFullView->Height); // by celberus } if(FOnFullViewRectPaint)FOnFullViewRectPaint(dcTemp, fvsx, fvsy, fvpw, fvph); FbmFullView->DeleteDC(dcFullView); if (bmTemp) { if (dcTemp) { DeleteDC(dcTemp); } DeleteObject(bmTemp); } } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::FullViewUpdateRect(int srcFCurrentBitmapX, int srcFCurrentBitmapY, int srcWidth, int srcHeight) // rename by celberus { HBITMAP bmTemp; HDC dcFullView, dcTemp; int fullViewX = (float)srcFCurrentBitmapX * FbmFullView->Width / FCurrentBitmap->Width; int fullViewY = (float)srcFCurrentBitmapY * FbmFullView->Height / FCurrentBitmap->Height; int fullViewWidth = (float)srcWidth * FbmFullView->Width / FCurrentBitmap->Width; int fullViewHeight= (float)srcHeight * FbmFullView->Height / FCurrentBitmap->Height; FullViewUpdate(false); // by celberus ¾à°£ ºñÈ¿À²Àû dcFullView = FbmFullView->CreateDC(); if ((bmTemp = CreateCompatibleBitmap(dcFullView, FbmFullView->Width, FbmFullView->Height)) == NULL) return; if ((dcTemp = CreateCompatibleDC(dcFullView)) == NULL) return; SelectObject(dcTemp, bmTemp); BitBlt(dcTemp, 0, 0, FbmFullView->Width, FbmFullView->Height, dcFullView, 0, 0, SRCCOPY); if (FOnPaintVector) { FOnPaintVector(dcTemp, -1, -1, FbmFullView->Width, FbmFullView->Height); // by celberus } if(FOnFullViewRectPaint)FOnFullViewRectPaint(dcTemp, fullViewX, fullViewY, fullViewWidth, fullViewHeight); FbmFullView->DeleteDC(dcFullView); if (bmTemp) { if (dcTemp) { DeleteDC(dcTemp); } DeleteObject(bmTemp); } } //--------------------------------------------------------------------------- // fullviewÀÇ viewÇÔ¼ö¿¡¼­ È£ÃâµÈ´Ù// ³Ñ°Ü¹ÞÀº dcDst¿¡ Àüüº¸±â À̹ÌÁö¸¦ ±×·ÁÁØ´Ù void __fastcall TPLayerImage::FullViewPaint(HDC dcDst, int zi, int zo) { HBITMAP bmTemp; HDC dcFullView = NULL, dcTemp = NULL; HPALETTE hpaintpal = NULL, holdpal = NULL; // by celberus int anyUpdated; if (FCurrentBitmap->BitsPerPixel==8) { hpaintpal = L_CreatePaintPalette(dcDst, FbmFullView->Handle); if (hpaintpal) holdpal = SelectPalette(dcDst, hpaintpal, false); } if (FbmFullView->Width == 0 || FbmFullView->Height == 0) goto fail; if(FCurrentBitmap && FbmFullView) { anyUpdated = FullViewUpdate(false); } if ((dcFullView = FbmFullView->CreateDC()) == NULL) goto fail; if ((bmTemp = CreateCompatibleBitmap(dcFullView, FbmFullView->Width, FbmFullView->Height)) == NULL) goto fail; if ((dcTemp = CreateCompatibleDC(dcFullView)) == NULL) goto fail; SelectObject(dcTemp, bmTemp); if (hpaintpal) SelectPalette(dcTemp, hpaintpal, false); BitBlt(dcTemp, 0, 0, FbmFullView->Width, FbmFullView->Height, dcFullView, 0, 0, SRCCOPY); if (FOnPaintVector) { FOnPaintVector(dcTemp, -1, -1, FbmFullView->Width, FbmFullView->Height); // by celberus } BitBlt(dcDst, 0, 0, FbmFullView->Width, FbmFullView->Height, dcTemp, 0, 0, SRCCOPY); if (dcFullView) FbmFullView->DeleteDC(dcFullView); //PAINT_END¿¡´Ù°¡ Áý¾î³Ö¾î¾ß ÇÑ´Ù. //isPainting = false; if (bmTemp) { if (dcTemp) { DeleteDC(dcTemp); } DeleteObject(bmTemp); } if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } return; fail: if (dcFullView) FbmFullView->DeleteDC(dcFullView); if (bmTemp) { if (dcTemp) { DeleteDC(dcTemp); } DeleteObject(bmTemp); } if (hpaintpal) { if (holdpal) SelectPalette(dcDst, holdpal, false); DeleteObject(hpaintpal); } //isPainting = false; } //--------------------------------------------------------------------------- bool __fastcall TPLayerImage::Paint_GridLine(HDC dcMemV, double sx, double sy, int vw, int vh) { double gx, gy, gzx, gzy, p; HPEN hPen = NULL, hOldPen = NULL; gx = FGridGapX; gy = FGridGapY; gzx = gx*FZoomIn/FZoomOut; gzy = gy*FZoomIn/FZoomOut; if (gzx>=5 && gzy>=5) { 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 (p FSubRange.left) { dsx = 0; ssx = sx; } else { dsx = FSubRange.left - sx; ssx = FSubRange.left; } if (sy > FSubRange.top) { dsy = 0; ssy = sy; } else { dsy = FSubRange.top - sy; ssy = FSubRange.top; } psw = FSubRange.right - ssx; psh = FSubRange.bottom - ssy; if (psw > pw - dsx) psw = pw - dsx; if (psh > ph - dsy) psh = ph - dsy; if (psw > FCurrentBitmap->Width - ssx) psw = FCurrentBitmap->Width - ssx; if (psh > FCurrentBitmap->Height - ssy) psh = FCurrentBitmap->Height - ssy; pdw = (dsx + psw) * FZoomIn / FZoomOut - dsx * FZoomIn / FZoomOut; // by celberus pdh = (dsy + psh) * FZoomIn / FZoomOut - dsy * FZoomIn / FZoomOut; // by celberus dsx = dsx * FZoomIn / FZoomOut; dsy = dsy * FZoomIn / FZoomOut; if ((bmMemT = CreateCompatibleBitmap(dcSrc, bmScreen->Width, bmScreen->Height)) == NULL) goto fail; // by celberus if ((dcMemT = CreateCompatibleDC(dcSrc)) == NULL) goto fail; SelectObject(dcMemT, bmMemT); if (hpaintpal) SelectPalette(dcMemT, hpaintpal, false); SetStretchBltMode(dcMemT, COLORONCOLOR); FSubMask->UnionStretchBlt(dcMemT, 0, 0, bmScreen->Width, bmScreen->Height, screenInfo.screenPosX, screenInfo.screenPosY, bmScreen->Width * FZoomOut / FZoomIn, bmScreen->Height * FZoomOut / FZoomIn, SRCCOPY); BitBlt(dcSrc, dsx, dsy, pdw, pdh, dcMemT, BitmapToCanvasX(ssx), BitmapToCanvasY(ssy), SRCAND); // by celberus BitBlt(dcMemT, 0, 0, bmScreen->Width, bmScreen->Height, NULL, 0, 0, DSTINVERT); FSubBitmap->UnionStretchBlt(dcMemT, 0, 0, bmScreen->Width, bmScreen->Height, screenInfo.screenPosX, screenInfo.screenPosY, bmScreen->Width * FZoomOut / FZoomIn, bmScreen->Height * FZoomOut / FZoomIn, SRCAND); BitBlt(dcSrc, dsx, dsy, pdw, pdh, dcMemT, BitmapToCanvasX(ssx), BitmapToCanvasY(ssy), SRCPAINT); // by celberus DeleteDC(dcMemT); DeleteObject(bmMemT); } else { // the others Expression if (_subPaintType == typeNone) { canvasRect = BitmapToCanvasRect(FSubRange); if (sx > FSubRange.left) { dsx = 0; ssx = sx - FSubRange.left; } else { dsx = FSubRange.left - sx; ssx = 0; } if (sy > FSubRange.top) { dsy = 0; ssy = sy - FSubRange.top; } else { dsy = FSubRange.top - sy; ssy = 0; } psw = FSubBitmap->Width - ssx; psh = FSubBitmap->Height - ssy; if (psw > pw - dsx) psw = pw - dsx; if (psh > ph - dsy) psh = ph - dsy; if (psw > FCurrentBitmap->Width - ssx) psw = FCurrentBitmap->Width - ssx; if (psh > FCurrentBitmap->Height - ssy) psh = FCurrentBitmap->Height - ssy; pdw = psw * FZoomIn / FZoomOut; pdh = psh * FZoomIn / FZoomOut; dsx = dsx * FZoomIn / FZoomOut; dsy = dsy * FZoomIn / FZoomOut; SetStretchBltMode(dcSrc, COLORONCOLOR); FSubMask->UnionStretchBlt(dcSrc, dsx, dsy, pdw, pdh, ssx, ssy, psw, psh, SRCAND); if ((bmMemT = CreateCompatibleBitmap(dcSrc, screenInfo.screenWidth, screenInfo.screenHeight)) == NULL) goto fail; // by celberus if ((dcMemT = CreateCompatibleDC(dcSrc)) == NULL) goto fail; SelectObject(dcMemT, bmMemT); if (hpaintpal) SelectPalette(dcMemT, hpaintpal, false); SetStretchBltMode(dcMemT, COLORONCOLOR); FSubMask->UnionStretchBlt(dcMemT, dsx, dsy, pdw, pdh, ssx, ssy, psw, psh, NOTSRCCOPY); // by celberus FSubBitmap->UnionStretchBlt(dcMemT, dsx, dsy, pdw, pdh, ssx, ssy, psw, psh, SRCAND); //by celberus BitBlt(dcSrc, dsx, dsy, pdw, pdh, dcMemT, dsx, dsy, SRCPAINT); // by celberus DeleteDC(dcMemT); DeleteObject(bmMemT); } else if (_subPaintType == typeExpansion) { canvasRect = BitmapToCanvasRect(FSubRange); if (sx > FSubRange.left) { dsx = 0; ssx = sx - FSubRange.left; } else { dsx = FSubRange.left - sx; ssx = 0; } if (sy > FSubRange.top) { dsy = 0; ssy = sy - FSubRange.top; } else { dsy = FSubRange.top - sy; ssy = 0; } psw = FSubBitmap->Width * _subPaintRatioX - ssx; psh = FSubBitmap->Height * _subPaintRatioY - ssy; if (psw > pw - dsx) psw = pw - dsx; if (psh > ph - dsy) psh = ph - dsy; if (psw > FCurrentBitmap->Width - ssx) psw = FCurrentBitmap->Width - ssx; if (psh > FCurrentBitmap->Height - ssy) psh = FCurrentBitmap->Height - ssy; if (FZoomIn > FZoomOut) { int tdw = psw; int tdh = psh; pdw = psw * FZoomIn / FZoomOut; pdh = psh * FZoomIn / FZoomOut; dsx = dsx * FZoomIn / FZoomOut; dsy = dsy * FZoomIn / FZoomOut; if ((bmMemT = CreateCompatibleBitmap(dcSrc, tdw, tdh)) == NULL) goto fail; // by celberus if ((dcMemT = CreateCompatibleDC(dcSrc)) == NULL) goto fail; SelectObject(dcMemT, bmMemT); if (hpaintpal) SelectPalette(dcMemT, hpaintpal, false); ssx /= _subPaintRatioX; ssy /= _subPaintRatioY; psw /= _subPaintRatioX; psh /= _subPaintRatioY; FSubMask->UnionStretchBlt(dcMemT, 0, 0, tdw, tdh, ssx, ssy, psw, psh, SRCCOPY); StretchBlt(dcSrc, dsx, dsy, pdw, pdh, dcMemT, 0, 0, tdw, tdh, SRCAND); BitBlt(dcMemT, 0, 0, tdw, tdh, NULL, 0, 0, DSTINVERT); FSubBitmap->UnionStretchBlt(dcMemT, 0, 0, tdw, tdh, ssx, ssy, psw, psh, SRCAND); StretchBlt(dcSrc, dsx, dsy, pdw, pdh, dcMemT, 0, 0, tdw, tdh, SRCPAINT); DeleteDC(dcMemT); DeleteObject(bmMemT); } else { pdw = psw * FZoomIn / FZoomOut; pdh = psh * FZoomIn / FZoomOut; dsx = dsx * FZoomIn / FZoomOut; dsy = dsy * FZoomIn / FZoomOut; SetStretchBltMode(dcSrc, COLORONCOLOR); ssx /= _subPaintRatioX; ssy /= _subPaintRatioY; psw /= _subPaintRatioX; psh /= _subPaintRatioY; FSubMask->UnionStretchBlt(dcSrc, dsx, dsy, pdw, pdh, ssx, ssy, psw, psh, SRCAND); if ((bmMemT = CreateCompatibleBitmap(dcSrc, screenInfo.screenWidth, screenInfo.screenHeight)) == NULL) goto fail; // by celberus if ((dcMemT = CreateCompatibleDC(dcSrc)) == NULL) goto fail; SelectObject(dcMemT, bmMemT); if (hpaintpal) SelectPalette(dcMemT, hpaintpal, false); SetStretchBltMode(dcMemT, COLORONCOLOR); FSubMask->UnionStretchBlt(dcMemT, dsx, dsy, pdw, pdh, ssx, ssy, psw, psh, NOTSRCCOPY); // by celberus FSubBitmap->UnionStretchBlt(dcMemT, dsx, dsy, pdw, pdh, ssx, ssy, psw, psh, SRCAND); //by celberus BitBlt(dcSrc, dsx, dsy, pdw, pdh, dcMemT, dsx, dsy, SRCPAINT); // by celberus DeleteDC(dcMemT); DeleteObject(bmMemT); } } } return; fail: if (bmMemT) { if (dcMemT) DeleteDC(dcMemT); DeleteObject(bmMemT); } // if (dcSubMask) FSubMask->DeleteDC(dcSubMask); if (dcSubSrc) FSubBitmap->DeleteDC(dcSubSrc); } //--------------------------------------------------------------------------- // ÀÛ¾÷±¸¿ª °ü·Ã //--------------------------------------------------------------------------- // È­¸é¿¡ ÀÛ¾÷±¸¿ªÀ» ±×·ÁÁØ´Ù void __fastcall TPLayerImage::OutlineBitmapRgn(bool bComplex) { pBITMAPHANDLE bh; RGNXFORM XForm; HRGN rgn=NULL; HBRUSH hBrush; if (FCurrentBitmap->RgnBitmap->IsUse) return; bh = FCurrentBitmap->RgnBitmap->Handle; if (bh) { if (L_BitmapHasRgn(bh)) { 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; XForm.nYOffset = -FPositionY*FZoomIn/FZoomOut; if (bComplex) { L_FrameBitmapRgn(TGraphicControl::Canvas->Handle, bh, &XForm, nFrameRgn); } else { if (L_GetBitmapRgnHandle(bh, &XForm, &rgn) == SUCCESS){ if ((hBrush = CreatePatternBrush(bmFrameRgn[nFrameRgn])) != NULL) { FrameRgn(TGraphicControl::Canvas->Handle, rgn, hBrush, 1, 1); DeleteObject(hBrush); } } } } } } //--------------------------------------------------------------------------- // ³Ñ°Ü¹ÞÀº ºñÆ®¸Ê¿¡ ÀÛ¾÷±¸¿ªÀ» ±×·ÁÁØ´Ù void __fastcall TPLayerImage::WAOutlineBitmapRgn(TTexpiaBitmap *bm, bool bComplex) { pBITMAPHANDLE bh; RGNXFORM XForm; HRGN rgn=NULL; HBRUSH hBrush; if (bm->IsUse) return; bh = bm->Handle; if (bh) { if (L_BitmapHasRgn(bh)) { nFrameRgn = (nFrameRgn+1)&7; XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = 1;//FZoomIn; XForm.nXScalarDen = 1;//FZoomOut; XForm.nYScalarNum = 1;//FZoomIn; XForm.nYScalarDen = 1;//FZoomOut; XForm.nXOffset = 0;//-FPositionX*FZoomIn/FZoomOut; XForm.nYOffset = 0;//-FPositionY*FZoomIn/FZoomOut; if (bComplex) { HDC dc=bm->CreateDC(); L_FrameBitmapRgn(dc, bh, &XForm, nFrameRgn); bm->DeleteDC(dc); } else { if (L_GetBitmapRgnHandle(bh, &XForm, &rgn) == SUCCESS){ if ((hBrush = CreatePatternBrush(bmFrameRgn[nFrameRgn])) != NULL) { HDC dc=bm->CreateDC(); FrameRgn(dc, rgn, hBrush, 1, 1); bm->DeleteDC(dc); DeleteObject(hBrush); } DeleteObject(rgn); } } } } } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::WAOutlineBitmapRgn(TUnionBitmap *bm, bool bComplex) { pBITMAPHANDLE bh; RGNXFORM XForm; HRGN rgn=NULL; HBRUSH hBrush = NULL; TTexpiaBitmap *tempBitmap; HDC tempDC = NULL; tempBitmap = new TTexpiaBitmap; if(!tempBitmap->Create(bm->Width, bm->Height, bm->BitsPerPixel, bm->RGB)) goto fail; if (tempBitmap->IsUse) return; bh = tempBitmap->Handle; if (bh) { if (L_BitmapHasRgn(bh)) { nFrameRgn = (nFrameRgn+1)&7; XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = 1;//FZoomIn; XForm.nXScalarDen = 1;//FZoomOut; XForm.nYScalarNum = 1;//FZoomIn; XForm.nYScalarDen = 1;//FZoomOut; XForm.nXOffset = 0;//-FPositionX*FZoomIn/FZoomOut; XForm.nYOffset = 0;//-FPositionY*FZoomIn/FZoomOut; if (bComplex) { tempDC=tempBitmap->CreateDC(); L_FrameBitmapRgn(tempDC, bh, &XForm, nFrameRgn); tempBitmap->DeleteDC(tempDC); tempDC = NULL; } else { if (L_GetBitmapRgnHandle(bh, &XForm, &rgn) == SUCCESS){ if ((hBrush = CreatePatternBrush(bmFrameRgn[nFrameRgn])) != NULL) { tempDC = tempBitmap->CreateDC(); FrameRgn(tempDC, rgn, hBrush, 1, 1); tempBitmap->DeleteDC(tempDC); tempDC = NULL; DeleteObject(hBrush); } DeleteObject(rgn); } } } } tempDC = tempBitmap->CreateDC(); if(!bm->UnionBitBlt(tempDC, 0, 0, bm->Width, bm->Height, 0, 0, SRCCOPY, true)) goto fail; tempBitmap->DeleteDC(tempDC); return; fail: if(tempBitmap) { if (tempDC) tempBitmap->DeleteDC(tempDC); delete tempBitmap; } if (hBrush) DeleteObject(hBrush); if (rgn) DeleteObject(rgn); } //--------------------------------------------------------------------------- // ·¹ÀÌ¾î ¸®½ºÆ® °ü·Ã //--------------------------------------------------------------------------- //À̹ÌÁö°¡ ÀÖ´Â formÀÌ È°¼ºÈ­ µÉ¶§ È£ÃâÇØ¾ß ÇÑ´Ù. bool __fastcall TPLayerImage::Activate() { if (LayerList->Count > 1) { doDestroy(FBackGround) MakeBeforeBitmap(); if (FBackGroundLock) { if ((FBackGround = new TUnionBitmap) == NULL) goto fail; if (!MakeBackGround()) goto fail; } } FIsActivate = true; return true; fail: doDestroy(FBackGround) return false; } //--------------------------------------------------------------------------- //À̹ÌÁö°¡ ÀÖ´Â formÀÌ ºñȰ¼ºÈ­ µÉ¶§ È£ÃâÇØ¾ß ÇÑ´Ù. bool __fastcall TPLayerImage::Deactivate() { FIsActivate = false; if (LayerList->Count > 1) { if (FBackGroundLock) { doDestroy(FBackGround) } DeleteBefore(); DeleteAfter(); } OSVERSIONINFO osvi; osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osvi); int osVERSION = osvi.dwPlatformId; //WINDOWS 98 == 1, WIN_NT==2; if(osVERSION<2) UnLoadAllBitmap(); //98ÀÌÀüÀº ¸ðµÎ swap ÇØÁÖ°í XP¿¡¼± ¾Ë¾Æ¼­ ¸Â±â±¸... return true; } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::MergeVisibleList(int numOfFirstVL) { TPLayer *nextLayer, *srclay; int i, cnt = LayerList->Count; nextLayer = (TPLayer *) LayerList->Items[numOfFirstVL]; CopyRGN(nextLayer); for(i = cnt - 1; i > numOfFirstVL; i--) { srclay = (TPLayer *) LayerList->Items[i]; if (srclay->Visible) { LayerList->Remove(srclay); delete srclay; } } ChangeBitmap(nextLayer); FIndex = numOfFirstVL; MakeBeforeBitmap(); } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::FlattenList() { TPLayer *dstlay, *srclay; dstlay = (TPLayer *) LayerList->Items[0]; CopyRGN(dstlay); while (LayerList->Count > 1) { srclay = (TPLayer *) LayerList->Last(); LayerList->Remove(srclay); delete srclay; } ChangeBitmap(dstlay); FIndex = 0; MakeBeforeBitmap(); } //--------------------------------------------------------------------------- bool __fastcall TPLayerImage::CreateBefore() { if(useRealLayerForLower) { FLowerBitmap = NULL; useRealLayerForLower = false; } if (FLowerBitmap == NULL) { if ((FLowerBitmap = new TUnionBitmap) == NULL) return false; if (FCurrentBitmap->BitsPerPixel == 8) { if (!FLowerBitmap->Create(FCurrentBitmap->Width, FCurrentBitmap->Height, 8, Frgb)) return false; } else { if (!FLowerBitmap->Create(FCurrentBitmap->Width, FCurrentBitmap->Height, 24)) return false; } } if (FCurrentBitmap->BitsPerPixel == 8) { FLowerBitmap->FillRect(Rect(0, 0, FCurrentBitmap->Width, FCurrentBitmap->Height), PALETTERGB(Frgb[1].rgbRed, Frgb[1].rgbGreen, Frgb[1].rgbBlue)); } else { FLowerBitmap->FillRect(Rect(0, 0, FCurrentBitmap->Width, FCurrentBitmap->Height), FLayerBGColor); } return true; } //--------------------------------------------------------------------------- bool __fastcall TPLayerImage::CreateAfter() { if(useRealLayerForUpper) { FUpperBitmap = NULL; FUpperMask = NULL; useRealLayerForUpper = false; } if (FUpperBitmap == NULL) { if ((FUpperBitmap = new TUnionBitmap) == NULL) return false; if (FCurrentBitmap->BitsPerPixel == 8) { if (!FUpperBitmap->Create(FCurrentBitmap->Width, FCurrentBitmap->Height, 8, Frgb)) return false; } else { if (!FUpperBitmap->Create(FCurrentBitmap->Width, FCurrentBitmap->Height, 24)) return false; } } if (FUpperMask == NULL) { if ((FUpperMask = new TUnionBitmap) == NULL) return false; if (FCurrentBitmap->BitsPerPixel == 8) { if (!FUpperMask->Create(FCurrentBitmap->Width, FCurrentBitmap->Height, 8, Frgb)) return false; } else { if (!FUpperMask->Create(FCurrentBitmap->Width, FCurrentBitmap->Height, 1)) return false; } } if (FCurrentBitmap->BitsPerPixel == 8) { FUpperBitmap->FillRect(Rect(0, 0, FCurrentBitmap->Width, FCurrentBitmap->Height), PALETTERGB(Frgb[1].rgbRed, Frgb[1].rgbGreen, Frgb[1].rgbBlue)); FUpperMask->FillRect(Rect(0, 0, FCurrentBitmap->Width, FCurrentBitmap->Height), PALETTEINDEX(255)); } else { FUpperBitmap->FillRect(Rect(0, 0, FCurrentBitmap->Width, FCurrentBitmap->Height), FLayerBGColor); FUpperMask->FillRect(Rect(0, 0, FCurrentBitmap->Width, FCurrentBitmap->Height), clWhite); } return true; } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::DeleteBefore() { if(useRealLayerForLower) { FLowerBitmap = NULL; useRealLayerForLower = false; } else if(FLowerBitmap) { delete FLowerBitmap; FLowerBitmap = NULL; } } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::DeleteAfter() { if(useRealLayerForUpper) { FUpperMask = NULL; FUpperBitmap = NULL; useRealLayerForUpper = false; } else { if(FUpperMask) { delete FUpperMask; FUpperMask = NULL; } if(FUpperBitmap) { delete FUpperBitmap; FUpperBitmap = NULL; } } } //--------------------------------------------------------------------------- //ÇöÀç ¼³Á¤µÈ layerÀÇ ÀÌÀü layer¸¦ ¸ðµÎ ÇÕ¼º½ÃÄѼ­ ÇϳªÀÇ bitmapÀ» ¸¸µç´Ù. bool __fastcall TPLayerImage::MakeBeforeBitmap() { int i, cnt; TPLayer *lay; if(FCurrentBitmap->BitsPerPixel == 8) { int layerCount = LayerList->Count; for(int i = 0; i < layerCount; i++) { lay = (TPLayer *)LayerList->Items[i]; lay->LBitmap->PutColors(0, 256, Frgb); if(lay->LMask) lay->LMask->PutColors(0, 256, Frgb); } } // Ctrl+C, Ctrl+V ÈÄ LayerVisible ¹Ù²Ü¶§ ¹®Á¦ by celberus cnt = LayerList->Count; if (cnt > 1) { if (FIndex == 1) { DeleteBefore(); lay = (TPLayer *)LayerList->Items[0]; if (lay->Visible) { FLowerBitmap = lay->LBitmap; useRealLayerForLower = true; } else { // if(!CreateBefore()) goto fail; } } else if (FIndex > 1) { if(!CreateBefore()) goto fail; lay = (TPLayer *) LayerList->First(); if (lay->Visible) { FLowerBitmap->ExactCopy(lay->LBitmap); } for (i = 1; i < FIndex; i++) { lay = (TPLayer *) LayerList->Items[i]; if (lay->Visible) { FLowerBitmap->MergeBitmap(lay->LBitmap, lay->LMask); } } } else { DeleteBefore(); } // make after bitmap if (FIndex == cnt - 2) { DeleteAfter(); lay = (TPLayer *)LayerList->Items[cnt - 1]; if(lay->Visible) { FUpperBitmap = lay->LBitmap; FUpperMask = lay->LMask; useRealLayerForUpper = true; } else { // if(!CreateAfter()) goto fail; } } else if (FIndex < cnt - 2) { if(!CreateAfter()) goto fail; for (i = FIndex + 1; i < cnt; i++) { lay = (TPLayer *) LayerList->Items[i]; if (lay->Visible) { FUpperBitmap->MergeBitmap(lay->LBitmap, lay->LMask); FUpperMask->ExactANDCopy(lay->LMask); } } } else { DeleteAfter(); } } else { DeleteBefore(); DeleteAfter(); } return true; fail: DeleteBefore(); DeleteAfter(); return false; } //--------------------------------------------------------------------------- //layer¸¦ Ãß°¡ÇÑ´Ù. (nameÀº layerÀÇ À̸§À̰í, w,h´Â layerÀÇ Å©±âÀÌ´Ù. //bpp´Â bits/pixelÀ̰í bg´Â background colorÀ̰í rgb´Â bpp°¡ 8Àϰæ¿ì¿¡ paletteÀÌ´Ù. bool __fastcall TPLayerImage::AddLayer(AnsiString name, int w, int h, int bpp, COLORREF bg, RGBQUAD *rgb) { if(LayerList->Count>=MAX_LAYER_NUM-1) return false; TPLayer *lay; if (LayerList->Count) { if ((lay = new TPLayer(name, getTempLayerFilename(), LTTransparency)) == NULL) goto fail; } else { if ((lay = new TPLayer(name, getTempLayerFilename(), LTInitial)) == NULL) goto fail; } if (bpp == 8 && rgb) { memcpy(Frgb, rgb, sizeof(RGBQUAD) * 256); if (!lay->LBitmap->Create(w, h, 8, rgb)) goto fail; lay->LBitmap->BackgroundColor = bg; // by celberus // lay->LBitmap->FillRect(Rect(0, 0, w, h), bg); if (lay->LMask) { if (!lay->LMask->Create(w, h, 8, rgb)) goto fail; lay->LMask->BackgroundColor = PALETTEINDEX(255); // by celberus // lay->LMask->Activate(0, PALETTEINDEX(255), rgb); // lay->LMask->FillRect(Rect(0, 0, w, h), PALETTEINDEX(255)); // Transparency } } else { if (!lay->LBitmap->Create(w, h, 24)) goto fail; // lay->LBitmap->FillRect(Rect(0, 0, w, h), bg); // lay->LBitmap->BackgroundColor = bg; // by celberus lay->LBitmap->BackgroundColor = clWhite; // by celberus // lay->LBitmap->FillRect(Rect(0, 0, w, h), clWhite); if (lay->LMask) { if (!lay->LMask->Create(w, h, 1)) goto fail; lay->LMask->BackgroundColor = clWhite; // by celberus // lay->LMask->FillRect(Rect(0, 0, w, h), clWhite); // Transparency } } LayerList->Add(lay); lay->SetLayerOrder(AccumulatedIndexNum++); //by linuxjun Undo_Method SetIndex(LayerList->Count - 1); ChangeBitmap(lay); if (FBackGroundLock) InitBackGround(); return true; fail: if (lay) delete lay; return false; } //--------------------------------------------------------------------------- // layer¸¦ ÇöÀçÀ§Ä¡¿¡ »ðÀÔÇÑ´Ù. (nameÀº layerÀÇ À̸§À̰í, w,h´Â layerÀÇ Å©±âÀ̰í, // bpp´Â bits / pixelÀ̰í bg´Â background colorÀ̰í rgb´Â bpp°¡ 8ÀÏ °æ¿ì¿¡ paletteÀÌ´Ù. bool __fastcall TPLayerImage::InsertLayer(AnsiString name, int w, int h, int bpp, COLORREF bg, RGBQUAD *rgb) { TPLayer *lay; if ((lay = new TPLayer(name, getTempLayerFilename(), LTTransparency)) == NULL) goto fail; if (bpp == 8 && rgb) { memcpy(Frgb, rgb, sizeof(RGBQUAD) * 256); if (!lay->LBitmap->Create(w, h, 8, rgb)) goto fail; lay->LBitmap->BackgroundColor = bg; // by celberus if (lay->LMask) { if (!lay->LMask->Create(w, h, 8, rgb)) goto fail; lay->LMask->BackgroundColor = PALETTEINDEX(255); // by celberus } } else { if (!lay->LBitmap->Create(w, h, 24)) goto fail; lay->LBitmap->BackgroundColor = clWhite; // by celberus if (lay->LMask) { if (!lay->LMask->Create(w, h, 1)) goto fail; lay->LMask->BackgroundColor = clWhite; // by celberus } } LayerList->Insert(FIndex, lay); CopyRGN(lay); ChangeBitmap(lay); MakeBeforeBitmap(); if (FBackGroundLock) InitBackGround(); return true; fail: if (lay) delete lay; return false; } //--------------------------------------------------------------------------- // ÇöÀç À§Ä¡ÀÇ layer¸¦ Á¦°ÅÇÑ´Ù. void __fastcall TPLayerImage::DeleteLayer() { int i; TPLayer *srclay, *dstlay; if (FIndex > 1) i = FIndex - 1; else i = 0; dstlay = (TPLayer *) LayerList->Items[i]; // dstlay->LoadFromLayerFile(Frgb); CopyRGN(dstlay); srclay = (TPLayer *) LayerList->Items[FIndex]; LayerList->Remove(srclay); delete srclay; FIndex = i; if (FIndex == 0) { if (dstlay->LMask) dstlay->LMask->FillRect(Rect(0, 0, dstlay->LMask->Width, dstlay->LMask->Height), 0); // Transparency --> BackGround } ChangeBitmap(dstlay); MakeBeforeBitmap(); if (FBackGroundLock) InitBackGround(); isRepaintAll = true; // delete ÇÑ ÈÄ fullview°¡ repaint¾ÈµÇ´Â ¹®Á¦ ¶§¹®¿¡.. by celberus } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::LayerVisibleChange(int Value, bool IsView) { if (FIndex == Value) FLayerVisible = IsView; MakeBeforeBitmap(); if (FBackGroundLock) InitBackGround(); isRepaintAll = true; } //--------------------------------------------------------------------------- // ÇöÀç visibleµÈ layer¸¦ ¸ðµÎ ÇÕ¼ºÇÑ´Ù. bool __fastcall TPLayerImage::MergeVisibleLayer() { int i, j, numOfVisibleLayer, numOfFirstVL,cnt, w, h; TPLayer *lay=NULL, *dstLayer = NULL; TUnionBitmap *bmMerge, *bmTemp; //by celberus HRGN hRgn = NULL; cnt = LayerList->Count; numOfFirstVL = -1; numOfVisibleLayer = 0; for (j = 0; j < cnt; j++) { lay = (TPLayer *) LayerList->Items[j]; if (lay->Visible) { if (numOfFirstVL == -1) numOfFirstVL = j; numOfVisibleLayer++; } } if (numOfVisibleLayer <= 1) return true; w = FCurrentBitmap->Width; h = FCurrentBitmap->Height; bmTemp = new TUnionBitmap; if(!bmTemp->Create(w, h, FCurrentBitmap->BitsPerPixel, Frgb))goto fail; bmTemp->BackgroundColor = 0; // by celberus dstLayer = (TPLayer *) LayerList->Items[numOfFirstVL]; bmMerge = dstLayer->LBitmap; if(FCurrentBitmap->RgnBitmap) hRgn = FCurrentBitmap->RgnBitmap->GetRegion(true); for (i = numOfFirstVL + 1; i < cnt; i++) { lay = (TPLayer *) LayerList->Items[i]; if (lay->Visible) { if (lay->LMask) { bmMerge->MergeBitmap(lay->LBitmap, lay->LMask); if(dstLayer->LMask) { dstLayer->LMask->ExactANDCopy(lay->LMask); } } else { bmMerge->ExactCopy(lay->LBitmap); // } } } MergeVisibleList(numOfFirstVL); if(hRgn) { if(FCurrentBitmap->RgnBitmap) FCurrentBitmap->RgnBitmap->PutRegion(hRgn, L_RGN_SET); } if(bmTemp) { delete bmTemp; } if (FBackGroundLock) InitBackGround(); return true; fail: if(lay->LMask)lay->LMask->Destroy(); if(dstLayer->LMask)dstLayer->LMask->Destroy(); if(bmTemp) delete bmTemp; return false; } //--------------------------------------------------------------------------- // layer¸ðµÎ ÇÕ¼ºÇÑ´Ù. bool __fastcall TPLayerImage::FlattenLayer() { int i, cnt; TPLayer *lay; // HRGN hRgn = NULL; TUnionBitmap *bmMerge; // by celberus cnt = LayerList->Count; lay = (TPLayer *) LayerList->Items[0]; lay->Visible = true; // FlattenÇÒ¶§ backgroundÀÇ visibleÀÌ falseÀ̸é flattenÈÄ visibleÀ» ¹Ù²ÙÁö ¸øÇØ °è¼Ó falseÀÎ »óŰ¡ µÈ´Ù. by celberus bmMerge = lay->LBitmap; for (i = 1; i < cnt; i++) { lay = (TPLayer *) LayerList->Items[i]; if (lay->LMask) { bmMerge->MergeBitmap(lay->LBitmap, lay->LMask); } else { bmMerge->ExactCopy(lay->LBitmap); // } } FlattenList(); if (FBackGroundLock) InitBackGround(); isRepaintAll = true; return true; } //--------------------------------------------------------------------------- // ÇöÀç layer¸¦ º¹»çÇÑ´Ù. bool __fastcall TPLayerImage::CopyLayer(AnsiString name) { RGBQUAD rgb[256]; int w, h, bpp; TPLayer *dlay; if ((dlay = new TPLayer(name, getTempLayerFilename(), LTTransparency)) == NULL) goto fail; bpp = FCurrentBitmap->BitsPerPixel; w = FCurrentBitmap->Width; h = FCurrentBitmap->Height; if (bpp == 8) { FCurrentBitmap->GetColors(0, 256, rgb); if (!dlay->LBitmap->Create(w, h, 8, rgb)) goto fail; if (!dlay->LMask->Create(w, h, 8, rgb)) goto fail; dlay->LBitmap->BackgroundColor = FCurrentBitmap->BackgroundColor; dlay->LMask->BackgroundColor = PALETTEINDEX(255); } else { if (!dlay->LBitmap->Create(w, h, 24)) goto fail; if (!dlay->LMask->Create(w, h, 1)) goto fail; dlay->LBitmap->BackgroundColor = FCurrentBitmap->BackgroundColor; dlay->LMask->BackgroundColor = clWhite; } dlay->LBitmap->Copy(FCurrentBitmap, SRCCOPY); if (FCurrentMask) dlay->LMask->Copy(FCurrentMask, SRCCOPY); else dlay->LMask->FillRect(Rect(0, 0, dlay->LMask->Width, dlay->LMask->Height), 0); LayerList->Add(dlay); SetIndex(LayerList->Count - 1); ChangeBitmap(dlay); if (FBackGroundLock) InitBackGround(); return true; fail: if (dlay) delete dlay; return false; } //--------------------------------------------------------------------------- // µÎ layerÀÇ À§Ä¡¸¦ ±³È¯ÇÑ´Ù. void __fastcall TPLayerImage::ExchangeLayer(int srcIndex, int dstIndex) { // TPLayer *dlay=NULL, *slay=NULL; // dlay = (TPLayer *) LayerList->Items[dstIndex]; // slay = (TPLayer *) LayerList->Items[srcIndex]; LayerList->Exchange(srcIndex, dstIndex); if (FIndex == dstIndex) FIndex = srcIndex; else if (FIndex == srcIndex) FIndex = dstIndex; MakeBeforeBitmap(); if (FBackGroundLock) InitBackGround(); isRepaintAll = true; } //--------------------------------------------------------------------------- // ÇöÀç ¼³Á¤µÈ size¸¦ º¯°æÇÑ´Ù. // È®´ë½Ã´Â À̹ÌÁöÀÇ º¯È­´Â ¾ø°í ºó°ø°£¿¡´Â bc¶ó´Â color·Î ä¿î´Ù. // Ãà¼Ò½Ã´Â À̹ÌÁö°¡ À߸°´Ù. void __fastcall TPLayerImage::ResizeLayer(int w, int h, COLORREF bc) { // by celberus int i, bpp, cnt = LayerList->Count; TPLayer *lay; COLORREF mbc; bpp = FCurrentBitmap->BitsPerPixel; if (bpp == 8) mbc = PALETTEINDEX(255); else mbc = clWhite; if (FLowerBitmap && !useRealLayerForLower) FLowerBitmap->Resize(w, h, bc); if (FUpperBitmap && !useRealLayerForUpper) FUpperBitmap->Resize(w, h, bc); if (FUpperMask && !useRealLayerForUpper) FUpperMask->Resize(w, h, mbc); for (i = 0; i < cnt; i++) { lay = (TPLayer *) LayerList->Items[i]; lay->LBitmap->Resize(w, h, bc); if (lay->LMask) { if (bpp == 8) { lay->LMask->Resize(w, h, PALETTEINDEX(255)); } else { lay->LMask->Resize(w, h, clWhite); } } } isRepaintAll = true; } //--------------------------------------------------------------------------- //void __fastcall TPLayerImage::InitAutoRepeat(int layerCNT,RECT rt,int w,int h, COLORREF bc){ void __fastcall TPLayerImage::InitAutoRepeat(int layerCNT,RECT rt,COLORREF bc){ int i, bpp, cnt = LayerList->Count; TPLayer *lay; COLORREF mbc; int w, h, www, hhh,sx,sy; int tempw,temph; tempw=FCurrentBitmap->Width; temph=FCurrentBitmap->Height; w = rt.right - rt.left; h = rt.bottom - rt.top; www = FCurrentBitmap->Width; hhh = FCurrentBitmap->Height; sx = rt.left; sy = rt.top; if ((2*w > www) || (2*h > hhh)) { //Move Bitmap /* if (2*w > www) www = 2*w; if (2*h > hhh) hhh = 2*h; */ www = 2*w; hhh = 2*h; //MainImageForm->EnlargeCanvas(www, hhh); } if ((sx < w/2) || ((sx+w) > (www-w/2)) || (sy < h/2) || ((sy+h) > (hhh-h/2))) { sx = www/2 - w/2; sy = hhh/2 - h/2; } if(2*w > FCurrentBitmap->Width || 2*h > FCurrentBitmap->Height){ bpp = FCurrentBitmap->BitsPerPixel; if (bpp == 8) mbc = PALETTEINDEX(255); else mbc = clWhite; if (FLowerBitmap && !useRealLayerForLower) FLowerBitmap->Resize(2*w, 2*h, bc); if (FUpperBitmap && !useRealLayerForUpper) FUpperBitmap->Resize(2*w, 2*h, bc); if (FUpperMask && !useRealLayerForUpper) FUpperMask->Resize(2*w, 2*h, mbc); if (Mask) { tempw=FCurrentBitmap->Width; temph=FCurrentBitmap->Height; if(2*w>tempw)tempw=2*w; if(2*h>temph)temph=2*h; Mask->Resize(tempw, temph, 0); } for (i = 0; i < cnt; i++) { lay = (TPLayer *) LayerList->Items[i]; if(i != layerCNT){ ResizeAutoBitmap(lay,2*w, 2*h, bc); }else{ ReCreateAutoBitmap(lay,rt,sx,sy,2*w,2*h,bc); } /* lay->LBitmap->Resize(w, h, bc); if (lay->LMask) { if (bpp == 8) { lay->LMask->Resize(w, h, PALETTEINDEX(255)); } else { lay->LMask->Resize(w, h, clWhite); } }*/ } isRepaintAll = true; //AutoRepeatLayerList = new TList; //ARDeletedLayerList = new TList; }else{ lay = (TPLayer *) LayerList->Items[layerCNT]; // ResizeAutoBitmap(lay,FCurrentBitmap->Width, FCurrentBitmap->Height, bc); ReCreateAutoBitmap(lay,rt,sx,sy,FCurrentBitmap->Width,FCurrentBitmap->Height,bc); } MakeBeforeBitmap(); //////////////////////////////////////////////////// //////////////////////////////////////////////////// lay = (TPLayer *) LayerList->Items[layerCNT]; FCurrentBitmap = lay->LBitmap; // FCurrentBitmap->OnPropertyChange = PropertyChange; FCurrentMask = lay->LMask; FLayerVisible = lay->Visible; FBitmap = (TexproBitmap *) FCurrentBitmap; // ±âÁ¸ÀÇ FuBitmap°úÀÇ È£È¯À» À§ÇØ »ç¿ë TPImage¿¡ FuBitmapÀ» »ç¿ëÇÏ´Â ¸Þ¼Òµå°¡ ÀÖÀ½ by celberus //////////////////////////////////////////////////// } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::ResizeAutoBitmap(TPLayer *lay,int w,int h, COLORREF bc) { int bpp; bpp = FCurrentBitmap->BitsPerPixel; if(lay->ARLBitmap){ delete lay->ARLBitmap; lay->ARLBitmap = NULL; } if(lay->ARLMask){ delete lay->ARLMask; lay->ARLMask = NULL; } ///////////////////////////////// lay->ARLBitmap = lay->LBitmap; lay->ARLMask = lay->LMask; lay->LBitmap = new TUnionBitmap; if(lay->LMask)lay->LMask = new TUnionBitmap; ///////////////////////////////// lay->LBitmap->ARResize(lay->ARLBitmap,w, h, bc); if (lay->LMask) { if (bpp == 8) { lay->LMask->ARResize(lay->ARLMask,w, h, PALETTEINDEX(255)); } else { lay->LMask->ARResize(lay->ARLMask,w, h, clWhite); } } } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::ReCreateAutoBitmap(TPLayer *lay,RECT rt,int sx,int sy, int w,int h, COLORREF bc) { if(lay->ARLBitmap){ delete lay->ARLBitmap; lay->ARLBitmap = NULL; } if(lay->ARLMask){ delete lay->ARLMask; lay->ARLMask = NULL; } ///////////////////////////////// lay->ARLBitmap = lay->LBitmap; lay->ARLMask = lay->LMask; lay->LBitmap = new TUnionBitmap; if(lay->LMask)lay->LMask = new TUnionBitmap; lay->LBitmap->setLayerOrder(lay->ARLBitmap->getLayerOrder()); ///////////////////////////////// if(lay->ARLBitmap->BitsPerPixel == 8){ lay->LBitmap->Create(w, h, 8 ,Frgb); lay->LBitmap->FillRect(Rect(0,0,w,h), bc); lay->LBitmap->Copy(sx,sy, rt.right-rt.left,rt.bottom-rt.top,lay->ARLBitmap,rt.left,rt.top,SRCCOPY); if (lay->LMask) { lay->LMask->Create(w,h,8,Frgb); lay->LMask->FillRect(Rect(0,0,w,h), PALETTEINDEX(255)); lay->LMask->Copy(sx,sy, rt.right-rt.left,rt.bottom-rt.top,lay->ARLMask,rt.left,rt.top,SRCCOPY); } }else{ lay->LBitmap->Create(w, h, 24); lay->LBitmap->FillRect(Rect(0,0,w,h), bc); lay->LBitmap->Copy(sx,sy, rt.right-rt.left,rt.bottom-rt.top,lay->ARLBitmap,rt.left,rt.top,SRCCOPY); if (lay->LMask) { lay->LMask->Create(w, h, 1); lay->LMask->FillRect(Rect(0,0,w,h), clWhite); lay->LMask->Copy(sx,sy, rt.right-rt.left,rt.bottom-rt.top,lay->ARLMask,rt.left,rt.top,SRCCOPY); } } } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::ReplaceAutoBitmap(int layerCNT){ RGBQUAD rgb[256]; int i, cnt = LayerList->Count; TPLayer *lay; TUnionBitmap *tempBitmap; for (i = 0; i < cnt; i++) { lay = (TPLayer *) LayerList->Items[i]; if(lay->ARLBitmap){ tempBitmap = lay->ARLBitmap; lay->ARLBitmap = lay->LBitmap; lay->LBitmap = tempBitmap; lay->ARLBitmap->GetColors(0, 256, rgb); lay->LBitmap->PutColors(0, 256, rgb); } if(lay->ARLMask){ tempBitmap = lay->ARLMask; lay->ARLMask = lay->LMask; lay->LMask = tempBitmap; lay->ARLBitmap->GetColors(0, 256, rgb); lay->LBitmap->PutColors(0, 256, rgb); } } lay = (TPLayer *) LayerList->Items[layerCNT]; FCurrentBitmap = lay->LBitmap; // FCurrentBitmap->OnPropertyChange = PropertyChange; FCurrentMask = lay->LMask; FLayerVisible = lay->Visible; FBitmap = (TexproBitmap *) FCurrentBitmap; // ±âÁ¸ÀÇ FuBitmap°úÀÇ È£È¯À» À§ÇØ »ç¿ë TPImage¿¡ FuBitmapÀ» »ç¿ëÇÏ´Â ¸Þ¼Òµå°¡ ÀÖÀ½ by celberus } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::EndAutoRepeat(){ int i, cnt = LayerList->Count; TPLayer *lay; for (i = 0; i < cnt; i++) { lay = (TPLayer *) LayerList->Items[i]; if(lay->ARLBitmap){ delete lay->ARLBitmap; lay->ARLBitmap = NULL; } if(lay->ARLMask){ delete lay->ARLMask; lay->ARLMask = NULL; } } /* while (ARDeletedLayerList->Count) { lay = (TPLayer *) ARDeletedLayerList->Last(); ARDeletedLayerList->Remove(lay); delete lay; lay = NULL; } ARDeletedLayerList = new TList; */ MakeBeforeBitmap(); FCurrentBitmap->SetAllToModified(); } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::ResizeStretchLayer(int w, int h) { // by celberus int i, cnt = LayerList->Count; TPLayer *lay; /* FCurrentBitmap->ResizeStretch(w, h); if (FCurrentMask) FCurrentMask->ResizeStretch(w, h); */ if (FLowerBitmap && !useRealLayerForLower) FLowerBitmap->ResizeStretch(w, h); if (FUpperBitmap && !useRealLayerForUpper) FUpperBitmap->ResizeStretch(w, h); if (FUpperMask && !useRealLayerForUpper) FUpperMask->ResizeStretch(w, h); for (i = 0; i < cnt; i++) { // if (i != FIndex) { lay = (TPLayer *) LayerList->Items[i]; // lay->LoadFromLayerFile(Frgb); need-conversion lay->LBitmap->ResizeStretch(w, h); if (lay->LMask) lay->LMask->ResizeStretch(w, h); // lay->SaveToLayerFile(); need-conversion // } } isRepaintAll = true; } //--------------------------------------------------------------------------- bool __fastcall TPLayerImage::LoadFromLayerFile(HANDLE FH, int ver, RGBQUAD *rgb) { DWORD dwRead; TPLayer *lay = NULL; int i, cnt; while (LayerList->Count) { lay = (TPLayer *) LayerList->Last(); LayerList->Remove(lay); delete lay; lay = NULL; } if (rgb) memcpy(Frgb, rgb, sizeof(RGBQUAD) * 256); if (!ReadFile(FH, &cnt, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(FH, &FIndex, sizeof(int), &dwRead, NULL)) goto fail; for (i = 0; i < cnt; i++) { if ((lay = new TPLayer(i ? LTTransparency : LTInitial)) == NULL) goto fail; if (!lay->LoadFromLayerFile(FH, ver, Frgb)) goto fail; lay->UpdateMiniBitmap(Frgb); ////////////È­ÀÏ ·Îµå½Ã ·¹ÀÌ¾î ¹Ì´Ï¸Ê º¸¿©ÁÖ±âÀ§ÇØ /by jeegeo LayerList->Add(lay); lay->SetLayerOrder(AccumulatedIndexNum++); //by linuxjun Undo_Method if (i != FIndex) { if (!lay->SaveToSwapFile()) goto fail; // SaveToLayerFile() -> SaveToSwapFile() by celberus } else { ChangeBitmap(lay); } } MakeBeforeBitmap(); return true; fail: if (lay) delete lay; return false; } //--------------------------------------------------------------------------- bool __fastcall TPLayerImage::SaveToLayerFile(HANDLE FH, RECT r, bool oldfile) { DWORD dwWrite; TPLayer *lay; int i, cnt = LayerList->Count; if (!WriteFile(FH, &cnt, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(FH, &FIndex, sizeof(int), &dwWrite, NULL)) return false; for (i = 0; i < cnt; i++) { lay = (TPLayer *) LayerList->Items[i]; if (i == FIndex) { if (!lay->SaveToLayerFile(FH, r, true, oldfile)) return false; } else { if (!lay->SaveToLayerFile(FH, r, false, oldfile)) return false; } } return true; } //--------------------------------------------------------------------------- bool __fastcall TPLayerImage::SaveToLayerFile(HANDLE FH, bool oldfile) { DWORD dwWrite; TPLayer *lay; int i, cnt = LayerList->Count; if (!WriteFile(FH, &cnt, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(FH, &FIndex, sizeof(int), &dwWrite, NULL)) return false; for (i = 0; i < cnt; i++) { lay = (TPLayer *) LayerList->Items[i]; if (i == FIndex) { if (!lay->SaveToLayerFile(FH, true, oldfile)) return false; } else { if (!lay->SaveToLayerFile(FH, false, oldfile)) return false; } } return true; } //--------------------------------------------------------------------------- bool __fastcall TPLayerImage::MakeBackGround() { RGBQUAD r[256]; int w, h; if (FBackGround == NULL) return false; w = FCurrentBitmap->Width; h = FCurrentBitmap->Height; if (FCurrentBitmap->BitsPerPixel == 8) { FCurrentBitmap->GetColors(0, 256, r); if (!FBackGround->Create(w, h, 8, r)) goto fail; } else { if (!FBackGround->Create(w, h, 24)) goto fail; } if (FLowerBitmap) { FBackGround->ExactCopy(FLowerBitmap); if (FLayerVisible) { FBackGround->MergeBitmap(FCurrentBitmap, FCurrentMask); } } else { FBackGround->ExactCopy(FCurrentBitmap); } return true; fail: if (FBackGround) { delete FBackGround; FBackGround = NULL; } return false; } //--------------------------------------------------------------------------- bool __fastcall TPLayerImage::IsBack() { TPLayer *lay = (TPLayer *) LayerList->Items[FIndex]; return !(lay->LayerType == LTTransparency); } //--------------------------------------------------------------------------- bool __fastcall TPLayerImage::InitBackGround() { if (LayerList->Count > 1 && FIndex > 0) { if (FBackGround == NULL) { if ((FBackGround = new TUnionBitmap) == NULL) goto fail; } if (!MakeBackGround()) goto fail; } else { doDestroy(FBackGround) } return true; fail: doDestroy(FBackGround) return false; } //--------------------------------------------------------------------------- bool __fastcall TPLayerImage::InitBackGround(Byte lock) { if (LayerList->Count > 1 && FIndex > 0) { if (FBackGround == NULL) { if ((FBackGround = new TUnionBitmap) == NULL) goto fail; } if (!MakeBackGround()) goto fail; } FBackGroundLock |= lock; return true; fail: doDestroy(FBackGround) return false; } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::ExitBackGround(Byte lock) { if (FBackGroundLock) { FBackGroundLock &= ~lock; if (FBackGroundLock == 0) doDestroy(FBackGround) } } //--------------------------------------------------------------------------- TUnionBitmap *__fastcall TPLayerImage::Composition() // by celberus print ºÎºÐ ±¸ÇöÇÒ¶§ ¼öÁ¤ 03-01-28 { int w, h; TUnionBitmap *bmSrc; RGBQUAD rgb[256]; if ((bmSrc = new TUnionBitmap) == NULL) goto fail; // by celberus w = FCurrentBitmap->Width; h = FCurrentBitmap->Height; if (FCurrentBitmap->BitsPerPixel == 8) { FCurrentBitmap->GetColors(0, 256, rgb); if (!bmSrc->Create(w, h, 8, rgb)) goto fail; } else { if (!bmSrc->Create(w, h, FCurrentBitmap->BitsPerPixel)) goto fail; } bmSrc->BackgroundColor = 0; // by celberus if (FLowerBitmap) { bmSrc->ExactCopy(FLowerBitmap); if (FLayerVisible) { bmSrc->MergeBitmap(FCurrentBitmap, FCurrentMask); } } else { if (FLayerVisible) { bmSrc->ExactCopy(FCurrentBitmap); } else { bmSrc->UnionBitBlt(NULL, 0, 0, w, h, 0, 0, WHITENESS, true); } } if (FUpperBitmap) { bmSrc->MergeBitmap(FUpperBitmap, FUpperMask); } return bmSrc; fail: if (bmSrc) { delete bmSrc; } return NULL; } //--------------------------------------------------------------------------- TUnionBitmap *__fastcall TPLayerImage::Composition(RECT r) // by celberus print ¹Ì¸®º¸±â ¶§¹®¿¡ ±¸Çö { int w, h; TUnionBitmap *bmSrc, *bmMemL = NULL; RGBQUAD rgb[256]; w = r.right - r.left; h = r.bottom - r.top; if ((bmSrc = new TUnionBitmap) == NULL) goto fail; // by celberus if ((bmMemL = new TUnionBitmap) == NULL) goto fail; if (FCurrentBitmap->BitsPerPixel == 8) { FCurrentBitmap->GetColors(0, 256, rgb); if (!bmSrc->Create(w, h, 8, rgb)) goto fail; if (!bmMemL->Create(w, h, 8, rgb)) goto fail; } else { if (!bmSrc->Create(w, h, FCurrentBitmap->BitsPerPixel)) goto fail; if (!bmMemL->Create(w, h, FCurrentBitmap->BitsPerPixel)) goto fail; } bmSrc->BackgroundColor = FCurrentBitmap->BackgroundColor; if (FLowerBitmap) { bmSrc->Copy(0, 0, w, h, FLowerBitmap, r.left, r.top, SRCCOPY); if (FLayerVisible) { bmSrc->Copy(0, 0, w, h, FCurrentMask, r.left, r.top, SRCAND); bmMemL->Copy(0, 0, w, h, FCurrentMask, r.left, r.top, NOTSRCCOPY); bmMemL->Copy(0, 0, w, h, FCurrentBitmap, r.left, r.top, SRCAND); bmSrc->Copy(0, 0, w, h, bmMemL, 0, 0, SRCPAINT); } } else { if (FLayerVisible) { bmSrc->Copy(0, 0, w, h, FCurrentBitmap, r.left, r.top, SRCCOPY); } else { bmSrc->UnionBitBlt(NULL, 0, 0, w, h, 0, 0, WHITENESS, true); } } if (FUpperBitmap) { bmSrc->Copy(0, 0, w, h, FUpperMask, r.left, r.top, SRCAND); bmMemL->Copy(0, 0, w, h, FUpperMask, r.left, r.top, NOTSRCCOPY); bmMemL->Copy(0, 0, w, h, FUpperBitmap, r.left, r.top, SRCAND); bmSrc->Copy(0, 0, w, h, bmMemL, 0, 0, SRCPAINT); } delete bmMemL; return bmSrc; fail: if (bmMemL) { delete bmMemL; } if (bmSrc) { delete bmSrc; } return NULL; } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::Composition(HDC dcDst, RECT r) { int w, h; TTexpiaBitmap *bmMemL; RGBQUAD rgb[256]; HDC dcMemL = NULL; w = r.right - r.left; h = r.bottom - r.top; if ((bmMemL = new TTexpiaBitmap) == NULL) goto fail; if (FCurrentBitmap->BitsPerPixel == 8) { FCurrentBitmap->GetColors(0, 256, rgb); if (!bmMemL->Create(w, h, 8, rgb)) goto fail; } else { if (!bmMemL->Create(w, h, FCurrentBitmap->BitsPerPixel)) goto fail; } if ((dcMemL = bmMemL->CreateDC()) == NULL) goto fail; if (FLowerBitmap) { FLowerBitmap->UnionBitBlt(dcDst, 0, 0, w, h, r.left, r.top, SRCCOPY, false); if (FLayerVisible) { FCurrentMask->UnionBitBlt(dcDst, 0, 0, w, h, r.left, r.top, SRCAND, false); FCurrentMask->UnionBitBlt(dcMemL, 0, 0, w, h, r.left, r.top, NOTSRCCOPY, false); FCurrentBitmap->UnionBitBlt(dcMemL, 0, 0, w, h, r.left, r.top, SRCAND, false); BitBlt(dcDst, 0, 0, w, h, dcMemL, 0, 0, SRCPAINT); } } else { if (FLayerVisible) { FCurrentBitmap->UnionBitBlt(dcDst, 0, 0, w, h, r.left, r.top, SRCCOPY, false); } else { BitBlt(dcDst, 0, 0, w, h, NULL, 0, 0, WHITENESS); } } if (FUpperBitmap) { FUpperMask->UnionBitBlt(dcDst, 0, 0, w, h, r.left, r.top, SRCAND, false); FUpperMask->UnionBitBlt(dcMemL, 0, 0, w, h, r.left, r.top, NOTSRCCOPY, false); FUpperBitmap->UnionBitBlt(dcMemL, 0, 0, w, h, r.left, r.top, SRCAND, false); BitBlt(dcDst, 0, 0, w, h, dcMemL, 0, 0, SRCPAINT); } bmMemL->DeleteDC(dcMemL); delete bmMemL; return; fail: if (bmMemL) { if (dcMemL) bmMemL->DeleteDC(dcMemL); delete bmMemL; } } //--------------------------------------------------------------------------- TUnionBitmap *__fastcall TPLayerImage::GetLayerBitmap(int i, TUnionBitmap **LMask) { TPLayer *lay = (TPLayer *)LayerList->Items[i]; // if (i != FIndex) lay->LoadFromLayerFile(Frgb); if (LMask) *LMask = lay->LMask; return lay->LBitmap; } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::SetLayerBitmap(int i) { // } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::CopyRGN(TPLayer *lay) { BITMAPHANDLE *srcbh, *dstbh; HRGN rgn=NULL; RGNXFORM XForm; if (FCurrentBitmap && FCurrentBitmap->RgnBitmap) { srcbh = FCurrentBitmap->RgnBitmap->Handle; dstbh = lay->LBitmap->RgnBitmap->Handle; if (srcbh && dstbh) { if (L_BitmapHasRgn(dstbh)) L_FreeBitmapRgn(dstbh); if (L_BitmapHasRgn(srcbh)) { XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = 1; XForm.nXScalarDen = 1; XForm.nYScalarNum = 1; XForm.nYScalarDen = 1; XForm.nXOffset = 0; XForm.nYOffset = 0; L_GetBitmapRgnHandle(srcbh, &XForm, &rgn); L_SetBitmapRgnHandle(dstbh, &XForm, rgn, L_RGN_SET); DeleteObject(rgn); } } } } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::ChangeBitmap(TPLayer *lay) { FCurrentBitmap = lay->LBitmap; FCurrentBitmap->OnPropertyChange = PropertyChange; FCurrentMask = lay->LMask; FLayerVisible = lay->Visible; FBitmap = (TexproBitmap *) FCurrentBitmap; // ±âÁ¸ÀÇ FuBitmap°úÀÇ È£È¯À» À§ÇØ »ç¿ë TPImage¿¡ FuBitmapÀ» »ç¿ëÇÏ´Â ¸Þ¼Òµå°¡ ÀÖÀ½ by celberus } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::setCurrentBitmap(TUnionBitmap *aBitmap) // ¿ÜºÎ¿¡¼­ FCurrentBitmap ¿¡ °ªÀ» ´ëÀÔÇÒ ¶§ È£ÃâµÇ¸ç file ·Îµå½Ã¿¡ »ç¿ëÇÑ´Ù. by celberus { FCurrentBitmap = aBitmap; FBitmap = (TexproBitmap *) FCurrentBitmap; } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::SetIndex(int Value) { TPLayer *dstlay; if (FIndex != Value) { dstlay = (TPLayer *) LayerList->Items[Value]; // dstlay->LoadFromLayerFile(Frgb); CopyRGN(dstlay); // if (FIndex >= 0) { // srclay = (TPLayer *) LayerList->Items[FIndex]; // srclay->SaveToLayerFile(); // } FIndex = Value; ChangeBitmap(dstlay); MakeBeforeBitmap(); } } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::StartLayerVisibleChange(int Value, bool IsView){ ((TPLayer *)LayerList->Items[Value])->Visible = IsView; } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::EndOfLayerVisibleChange(int Value, bool IsView){ TPLayer *dstlay; if (FIndex != Value) { dstlay = (TPLayer *) LayerList->Items[Value]; CopyRGN(dstlay); if (FIndex >= 0) { // srclay = (TPLayer *) LayerList->Items[FIndex]; // srclay->SaveToLayerFile(); } FIndex = Value; dstlay->Visible = IsView; ChangeBitmap(dstlay); } FLayerVisible = IsView; MakeBeforeBitmap(); isRepaintAll = true; // by celberus if (FBackGroundLock) InitBackGround(); } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TPLayerImage::SetCrossPos(POINT Pos) { FCrossPos.x = BitmapToCanvasX(Pos.x); FCrossPos.y = BitmapToCanvasY(Pos.y); } //--------------------------------------------------------------------------- int __fastcall TPLayerImage::BitmapToCanvasX(int X) { return (X-FPositionX)*FZoomIn/FZoomOut; // return (double)(X-FPositionX)*FZoomIn/FZoomOut + 0.5; // return (int)((double)X*FZoomIn/FZoomOut + 0.5) - (int)((double)FPositionX*FZoomIn/FZoomOut + 0.5); } //--------------------------------------------------------------------------- int __fastcall TPLayerImage::BitmapToCanvasY(int Y) { return (Y-FPositionY)*FZoomIn/FZoomOut; // return (double)(Y-FPositionY)*FZoomIn/FZoomOut + 0.5; // return (int)((double)Y*FZoomIn/FZoomOut + 0.5) - (int)((double)FPositionY*FZoomIn/FZoomOut + 0.5); } //--------------------------------------------------------------------------- RECT __fastcall TPLayerImage::BitmapToCanvasRect(RECT src) { RECT rc; rc.left = (src.left-FPositionX)*FZoomIn/FZoomOut; rc.top = (src.top-FPositionY)*FZoomIn/FZoomOut; rc.right = (src.right-FPositionX)*FZoomIn/FZoomOut; rc.bottom = (src.bottom-FPositionY)*FZoomIn/FZoomOut; return rc; } //--------------------------------------------------------------------------- int __fastcall TPLayerImage::CanvasToBitmapX(int X) { return FPositionX+X*FZoomOut/FZoomIn; } //--------------------------------------------------------------------------- int __fastcall TPLayerImage::CanvasToBitmapY(int Y) { return FPositionY+Y*FZoomOut/FZoomIn; } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y) { int px, py; if (FCoordinationTransfer) { // if (FCurrentBitmap->Handle) { if(FCurrentBitmap->BitsPerPixel != 0) { // HandleÀÌ NULLÀÏ ¶§ ¿À·ù ¼öÁ¤ by celberus px = FPositionX+X*FZoomOut/FZoomIn; py = FPositionY+Y*FZoomOut/FZoomIn; TControl::MouseDown(Button, Shift, px, py); } else { TControl::MouseDown(Button, Shift, X, Y); } } else { TControl::MouseDown(Button, Shift, X, Y); } } //--------------------------------------------------------------------- void __fastcall TPLayerImage::MouseMove(TShiftState Shift, int X, int Y) { int px, py; if (FCoordinationTransfer) { // if (FCurrentBitmap->Handle) { if(FCurrentBitmap->BitsPerPixel != 0) { // HandleÀÌ NULLÀÏ ¶§ ¿À·ù ¼öÁ¤ by celberus px = FPositionX+X*FZoomOut/FZoomIn; py = FPositionY+Y*FZoomOut/FZoomIn; TControl::MouseMove(Shift, px, py); } else { TControl::MouseMove(Shift, X, Y); } } else { TControl::MouseMove(Shift, X, Y); } } //--------------------------------------------------------------------- void __fastcall TPLayerImage::MouseUp(TMouseButton Button, TShiftState Shift, int X, int Y) { int px, py; if (FCoordinationTransfer) { // if (FCurrentBitmap->Handle) { if(FCurrentBitmap->BitsPerPixel != 0) { // HandleÀÌ NULLÀÏ ¶§ ¿À·ù ¼öÁ¤ by celberus px = FPositionX+X*FZoomOut/FZoomIn; py = FPositionY+Y*FZoomOut/FZoomIn; TControl::MouseUp(Button, Shift, px, py); } else { TControl::MouseUp(Button, Shift, X, Y); } } else { TControl::MouseUp(Button, Shift, X, Y); } } //--------------------------------------------------------------------------- // ÇÁ·ÎÆÛƼ °ü·Ã //--------------------------------------------------------------------------- void __fastcall TPLayerImage::PropertyChange() { Invalidate(); } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::SetBorderColor(TColor Value) { if (FBorderColor!=Value) { FBorderColor = Value; Paint(); Invalidate(); } } //--------------------------------------------------------------------------- bool __fastcall TPLayerImage::PositionChange() { return true; } //--------------------------------------------------------------------------- // ¼¼ºÎÀû ±â´É °ü·Ã //--------------------------------------------------------------------------- void __fastcall TPLayerImage::InitbmFullView(int zi, int zo, COLORREF bgcolor, RGBQUAD *rgb) { if(FbmFullView->Handle) FbmFullView->Destroy(); // by celberus int vw = FCurrentBitmap->Width * zi / zo; int vh = FCurrentBitmap->Height * zi / zo; if (FCurrentBitmap->BitsPerPixel == 8) FbmFullView->Create(vw, vh, 8, rgb); else FbmFullView->Create(vw, vh, 24); FbmFullView->FillRect(Rect(0, 0, vw, vh), bgcolor); } //--------------------------------------------------------------------------- // Background color¸¦ ¼³Á¤ÇÑ´Ù. void __fastcall TPLayerImage::SetBackgroundColor(COLORREF bgcolor, RGBQUAD *rgb) { FLayerBGColor = bgcolor; FCurrentBitmap->BackgroundColor = bgcolor; if (FCurrentBitmap->BitsPerPixel == 8) { memcpy(Frgb, rgb, sizeof(RGBQUAD) * 256); } } //--------------------------------------------------------------------------- // ÇöÀç palette¸¦ rgb·Î ¼³Á¤ÇÑ´Ù. void __fastcall TPLayerImage::ChangeRGBColors(RGBQUAD *rgb) { /* TPLayer *lay; memcpy(Frgb, rgb, sizeof(RGBQUAD) * 256); if(FCurrentBitmap->BitsPerPixel == 8) { int layerCount = LayerList->Count; for(int i = 0; i < layerCount; i++) { lay = (TPLayer *)LayerList->Items[i]; lay->LBitmap->PutColors(0, 256, rgb); if(lay->LMask) lay->LMask->PutColors(0, 256, rgb); } FbmFullView->PutColors(0, 256, rgb); FbmScreen->PutColors(0, 256, rgb); if(!useRealLayerForLower && FLowerBitmap) FLowerBitmap->PutColors(0, 256, rgb); if(!useRealLayerForUpper && FUpperBitmap) FUpperBitmap->PutColors(0, 256, rgb); if(!useRealLayerForUpper && FUpperMask) FUpperMask->PutColors(0, 256, rgb); if (FSubBitmap) FSubBitmap->PutColors(0, 256, rgb); if (FSubMask) FSubMask->PutColors(0, 256, rgb); } // visible changeÇÒ¶§ makebeforebitmap¿¡¼­ rgb¸¦ ÅëÀÏ ¾È½ÃŰ¹Ç·Î À§¿Í°°ÀÌ ¹Ù²å´Ù. ·¹À̾¼­ Ctrl+C, Ctrl+VÈÄ Layer Visible Change·Î Å×½ºÆ® ÇØ º¼°Í by celberus */ memcpy(Frgb, rgb, sizeof(RGBQUAD) * 256); if (FLowerBitmap) FLowerBitmap->PutColors(0, 256, rgb); FCurrentBitmap->PutColors(0, 256, rgb); if (FCurrentMask) FCurrentMask->PutColors(0, 256, rgb); if (FUpperBitmap) FUpperBitmap->PutColors(0, 256, rgb); if (FUpperMask) FUpperMask->PutColors(0, 256, rgb); if (FSubBitmap) FSubBitmap->PutColors(0, 256, rgb); if (FSubMask) FSubMask->PutColors(0, 256, rgb); /* if (FCurrentBitmap->BitsPerPixel == 24) { if (FLowerBitmap) FLowerBitmap->BackgroundColor = (rgb[1].rgbBlue << 16) + (rgb[1].rgbGreen << 8) + rgb[1].rgbRed; FCurrentBitmap->BackgroundColor = (rgb[1].rgbBlue << 16) + (rgb[1].rgbGreen << 8) + rgb[1].rgbRed; if (FUpperBitmap) FUpperBitmap->BackgroundColor = (rgb[1].rgbBlue << 16) + (rgb[1].rgbGreen << 8) + rgb[1].rgbRed; if (FSubBitmap) FSubBitmap->BackgroundColor = (rgb[1].rgbBlue << 16) + (rgb[1].rgbGreen << 8) + rgb[1].rgbRed; }*/ FbmFullView->PutColors(0, 256, rgb); FbmScreen->PutColors(0, 256, rgb); } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::ColorChange(int index, RGBQUAD *rgb) { // RGB°¡ ¹Ù²î¾îµµ ÀÌ ÇÔ¼ö¿¡ ¾Èµé¾î¿À´Â ºÎºÐÀÌ Àִµí... TPLayer *lay; if(index == 1 && Frgb[1].rgbRed == 0 && Frgb[1].rgbGreen == 0 && Frgb[1].rgbBlue == 0) isRepaintAll = true; memcpy(&Frgb[index], &rgb[index], sizeof(RGBQUAD)); if(FCurrentBitmap->BitsPerPixel == 8) { int layerCount = LayerList->Count; for(int i = 0; i < layerCount; i++) { lay = (TPLayer *)LayerList->Items[i]; lay->LBitmap->PutColors(index,1,&rgb[index]); if(lay->LMask) lay->LMask->PutColors(index,1,&rgb[index]); lay->MiniBitmap->PutColors(index, 1,&rgb[index]); } FbmFullView->PutColors(index, 1,&rgb[index]); FbmScreen->PutColors(index, 1,&rgb[index]); if(!useRealLayerForLower && FLowerBitmap) FLowerBitmap->PutColors(index,1,&rgb[index]); if(!useRealLayerForUpper && FUpperBitmap) FUpperBitmap->PutColors(index,1,&rgb[index]); if(!useRealLayerForUpper && FUpperMask) FUpperMask->PutColors(index,1,&rgb[index]); if (FSubBitmap) FSubBitmap->PutColors(index, 1, &rgb[index]); if (FSubMask) FSubMask->PutColors(index, 1, &rgb[index]); } } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::RearrangeColors(RGBQUAD *rgb) { TPLayer *lay; memcpy(Frgb, rgb, sizeof(RGBQUAD) * 256); if(FCurrentBitmap->BitsPerPixel == 8) // by celberus { // layer°¡ Á¸ÀçÇÒ¶§ color change¹®Á¦ ¶§¹®¿¡;;¤¤ int layerCount = LayerList->Count; for(int i = 0; i < layerCount; i++) { lay = (TPLayer *)LayerList->Items[i]; lay->LBitmap->PutColors(0,256,Frgb); if(lay->LMask)lay->LMask->PutColors(0,256,Frgb); } bmScreen->PutColors(0,256,Frgb); if(FLowerBitmap)FLowerBitmap->PutColors(0,256,Frgb); if(FUpperBitmap)FUpperBitmap->PutColors(0,256,Frgb); } // MakeBeforeBitmap(); } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::FloodFill(TPoint start, TFloodFillReadLayer read, TFloodFillSave save, TRect &rcBound, TRect *pZone) { int x, y, savex, savey, xr, xl; TPoint now, *sp; TList *stack; Byte *p, *lp; TRect rcZone = pZone ? *pZone : Rect(0, 0, FCurrentBitmap->Width, FCurrentBitmap->Height); stack = new TList; rcBound.Left = start.x; rcBound.Right = start.x+1; rcBound.Top = start.y; rcBound.Bottom = start.y+1; stack->Add(new TPoint(start)); FCurrentBitmap->StartScanLine(); FCurrentMask->StartScanLine(); while (stack->Count) { sp = (TPoint *)stack->Last(); stack->Remove(sp); x = sp->x; y = sp->y; delete sp; if (yrcBound.Bottom-1) rcBound.Bottom = y+1; p = FCurrentBitmap->GetScanLine(y); lp = FCurrentMask->GetScanLine(y); save(p, x); savex = x; while (1) { x++; if (xrcBound.Right-1) rcBound.Right = xr+1; x = savex; while (1) { x--; if (x>=rcZone.Left && read(p, lp, x)) save(p, x); else break; } xl = x+1; if (xlrcBound.Right-1) rcBound.Right = xl+1; if(xr-xl>0){ FCurrentBitmap->PutScanLine(y,xl,xr-xl); } x = xl; savey = y; y++; if (yGetScanLine(y); lp = FCurrentMask->GetScanLine(y); // if (yAdd(new TPoint(now)); } } // } x = xl; } y = savey; y--; if (y>=rcZone.Top) { p = FCurrentBitmap->GetScanLine(y); lp = FCurrentMask->GetScanLine(y); // if (y>=rcZone.Top) { while (x<=xr) { if (!read(p, lp, x)) x++; else { while (1) { if (x<=xr) { if (read(p, lp, x)) x++; else { now.x = x-1; x++; break; } } else { now.x = x-1; break; } } now.y = y; stack->Add(new TPoint(now)); } } // } } } FCurrentBitmap->StopScanLine(); FCurrentMask->StopScanLine(); delete stack; } //--------------------------------------------------------------------------- bool __fastcall TPLayerImage::FloodFillMask(TPoint start, TFloodFillReadLayer read, TFloodFillSave save, TRect &rcBound, TPBitmap *PMask, TRect *pZone) { int x, y, savex, savey, xr, xl; TPoint now, *sp; TList *stack; Byte *p, *m, *lp; TRect rcZone = pZone ? *pZone : Rect(0, 0, FCurrentBitmap->Width, FCurrentBitmap->Height); if (PMask==NULL) return false; if (!PMask->Create(FCurrentBitmap->Width, FCurrentBitmap->Height, 1)) return false; if ((stack = new TList)==NULL) goto fail; rcBound.Left = start.x; rcBound.Right = start.x+1; rcBound.Top = start.y; rcBound.Bottom = start.y+1; stack->Add(new TPoint(start)); FCurrentBitmap->StartScanLine(); FCurrentMask->StartScanLine(); PMask->Lock(); PMask->Fill(0); while (stack->Count) { sp = (TPoint *)stack->Last(); stack->Remove(sp); x = sp->x; y = sp->y; delete sp; if (yrcBound.Bottom-1) rcBound.Bottom = y+1; p = FCurrentBitmap->GetScanLine(y); lp = FCurrentMask->GetScanLine(y); m = PMask->ScanLine(y); *(m+(x>>3)) |= 0x80>>(x&7); if (save) save(p, x); savex = x; while (1) { x++; if (x>3))&(0x80>>(x&7)))==0 && read(p, lp, x)) { *(m+(x>>3)) |= 0x80>>(x&7); if (save) save(p, x); } else break; } xr = x-1; if (xrrcBound.Right-1) rcBound.Right = xr+1; x = savex; while (1) { x--; if (x>=rcZone.Left && (*(m+(x>>3))&(0x80>>(x&7)))==0 && read(p, lp, x)) { *(m+(x>>3)) |= 0x80>>(x&7); if (save) save(p, x); } else break; } xl = x+1; if (xlrcBound.Right-1) rcBound.Right = xl+1; x = xl; savey = y; y++; if (yGetScanLine(y); lp = FCurrentMask->GetScanLine(y); m = PMask->ScanLine(y); // if (y>3))&(0x80>>(x&7))) || !read(p, lp, x)) x++; else { while (1) { if (x<=xr) { if ((*(m+(x>>3))&(0x80>>(x&7)))==0 && read(p, lp, x)) x++; else { now.x = x-1; x++; break; } } else { now.x = x-1; break; } } now.y = y; stack->Add(new TPoint(now)); } } // } x = xl; } y = savey; y--; if (y>=rcZone.Top) { p = FCurrentBitmap->GetScanLine(y); lp = FCurrentMask->GetScanLine(y); m = PMask->ScanLine(y); // if (y>=rcZone.Top) { while (x<=xr) { if ((*(m+(x>>3))&(0x80>>(x&7))) || !read(p, lp, x)) x++; else { while (1) { if (x<=xr) { if ((*(m+(x>>3))&(0x80>>(x&7)))==0 && read(p, lp, x)) x++; else { now.x = x-1; x++; break; } } else { now.x = x-1; break; } } now.y = y; stack->Add(new TPoint(now)); } } // } } } PMask->Unlock(); FCurrentMask->StopScanLine(); FCurrentBitmap->StopScanLine(); delete stack; return true; fail: if (stack) delete stack; return false; } //--------------------------------------------------------------------------- int __fastcall TPLayerImage::FullViewUpdate(bool isAll) { HDC dcFullView; int anyUpdated; if((dcFullView = FbmFullView->CreateDC()) == NULL) goto fail; if (FLowerBitmap) { if((anyUpdated = FLowerBitmap->FullViewUpdate(dcFullView, FbmFullView->Width, FbmFullView->Height, isAll, FCurrentBitmap)) < 0 ) goto fail; if (FLayerVisible) { if((anyUpdated = FLowerBitmap->MergedFullViewUpdate(dcFullView, FbmFullView->Width, FbmFullView->Height, FCurrentBitmap, FCurrentMask, isAll, FCurrentBitmap)) < 0 ) goto fail; } } else { if (FLayerVisible) { if((anyUpdated = FCurrentBitmap->FullViewUpdate(dcFullView, FbmFullView->Width, FbmFullView->Height, isAll, FCurrentBitmap)) < 0 ) goto fail; } else if(!FUpperBitmap) { BitBlt(dcFullView, 0, 0, FbmFullView->Width, FbmFullView->Height, NULL, 0, 0, WHITENESS); } } if (FUpperBitmap) { if(!FLowerBitmap && !FLayerVisible) { // mark U if((anyUpdated = FUpperBitmap->FullViewUpdate(dcFullView, FbmFullView->Width, FbmFullView->Height, isAll, FCurrentBitmap)) < 0 ) goto fail; } else { if((anyUpdated = FCurrentBitmap->MergedFullViewUpdate(dcFullView, FbmFullView->Width, FbmFullView->Height, FUpperBitmap, FUpperMask, isAll, FCurrentBitmap)) < 0 ) goto fail; } } FbmFullView->DeleteDC(dcFullView); if(anyUpdated)((TPLayer *)LayerList->Items[FIndex])->UpdateMiniBitmap(Frgb, Rect(0,0,0,0), isAll); // by celberus return anyUpdated; fail: return -1; } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::UnLoadAllBitmap() { TPLayer *lay; for (int i = 0; i < LayerList->Count; i++) { lay = (TPLayer *)LayerList->Items[i]; lay->LightWeight(); } } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::setSubPaintType(SubPaintType value) { _subPaintType = value; } //--------------------------------------------------------------------------- void __fastcall TPLayerImage::setSubPaintRatio(double valueX, double valueY) { _subPaintRatioX = valueX; _subPaintRatioY = valueY; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- namespace Tplayerimage { void __fastcall PACKAGE Register() { TComponentClass classes[1] = {__classid(TPLayerImage)}; RegisterComponents("Texpia", classes, 0); } } //---------------------------------------------------------------------------