//--------------------------------------------------------------------------- #include #pragma hdrstop #include "AutoRepView.h" #include "MainImage.h" //#define IDS_ZOOMIN StringTable[0] //#define IDS_ZOOMOUT StringTable[1] //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "TPImage" #pragma link "TPTextileImage" #pragma link "RzButton" #pragma resource "*.dfm" TAutoRepViewForm *AutoRepViewForm; //--------------------------------------------------------------------------- __fastcall TAutoRepViewForm::TAutoRepViewForm(TComponent* Owner) : TForm(Owner) { StringTable.Create(DirectoryItem, Language, "viewform"); SetSmallFont(Font); // sbZoomOut->Caption = IDS_ZOOMOUT; // sbZoomIn->Caption = IDS_ZOOMIN; zoom = 0; stZoom->Caption = IntToStr(1); } //--------------------------------------------------------------------------- void __fastcall TAutoRepViewForm::FormCreate(TObject *Sender) { ReadIniFile(); } //--------------------------------------------------------------------------- void __fastcall TAutoRepViewForm::FormShow(TObject *Sender) { ReDrawImage(); } //--------------------------------------------------------------------------- void __fastcall TAutoRepViewForm::sbZoomClick(TObject *Sender) { int cnt, i; String str; TSpeedButton *sp = (TSpeedButton *)Sender; cnt = 1; if (sp->Tag) { if (zoom == 0) return; zoom++; } else { if (zoom == -4) return; zoom--; } /* if (zoom > 0) { for (i=0; izoom; i--) cnt = 2*cnt; str = "1/"; str = str + IntToStr(cnt); } else { str = IntToStr(1); } */ if (zoom < 0) { for (i=0; i>zoom; i--) cnt = 2*cnt; str = "1/"; str = str + IntToStr(cnt); } else { str = IntToStr(1); } stZoom->Caption = str; ReDrawImage(); } //--------------------------------------------------------------------------- void __fastcall TAutoRepViewForm::ReDrawImage() { int x, y, w, h, www, hhh, gab; int i, dw, dh, sx, sy; RECT rt; TTexpiaBitmap *tbmp = NULL; HDC ThDC = NULL, RhDC = NULL; int Wdiv = MainImageForm->MWdiv, Hdiv = MainImageForm->MHdiv; RGBQUAD srcrgb[256]; TPException ec = EC_NONE; www = Image->Width; hhh = Image->Height; w = MainImageForm->arwindow.size.x; h = MainImageForm->arwindow.size.y; dw = w; dh = h; sx = MainImageForm->arwindow.s.x; sy = MainImageForm->arwindow.s.y; if (zoom < 0) { for (i=0; i>zoom; i--) { dw = dw/2; dh = dh/2; Wdiv = Wdiv/2; Hdiv = Hdiv/2; } } if (MainImageForm->iMainImage->LayerList->Count > 1) { rt = Rect(MainImageForm->arwindow.s.x, MainImageForm->arwindow.s.y, MainImageForm->arwindow.e.x, MainImageForm->arwindow.e.y); if ((tbmp = new TTexpiaBitmap) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { MainImageForm->iMainImage->uBitmap->GetColors(0, 256, srcrgb); if (!Image->Bitmap->Create(www, hhh, 8, srcrgb)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!tbmp->Create(w, h, 8, srcrgb)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if (!Image->Bitmap->Create(www, hhh, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!tbmp->Create(w, h, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } if ((ThDC = tbmp->CreateDC()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((RhDC = Image->Bitmap->CreateDC()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } MainImageForm->iMainImage->Composition(ThDC, rt); SetStretchBltMode(RhDC, COLORONCOLOR); if (MainImageForm->ARTItem == AREPEAT_NORMAL) { for (y = 0; y < hhh; y += dh) { for (x = 0; x < www; x += dw) StretchBlt(RhDC, x, y, dw, dh, ThDC, 0, 0, w, h, SRCCOPY); } }else if (MainImageForm->ARTItem == AREPEAT_HDVER) { for (x = 0; x < www; x += dw) { if (x==0) gab = 0; else gab += dh-Hdiv; for (y = 0; y < hhh+gab; y += dh) StretchBlt(RhDC, x, y - gab, dw, dh, ThDC, 0, 0, w, h, SRCCOPY); } } else { for (y = 0; y < hhh; y += dh) { if (y==0) gab = 0; else gab += dw-Wdiv; for (x = 0; x < www+gab; x += dw) StretchBlt(RhDC, x - gab, y, dw, dh, ThDC, 0, 0, w, h, SRCCOPY); } } Image->Bitmap->DeleteDC(RhDC); tbmp->DeleteDC(ThDC); delete tbmp; } else { if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { MainImageForm->iMainImage->uBitmap->GetColors(0, 256, srcrgb); if (!Image->Bitmap->Create(www, hhh, 8, srcrgb)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if (!Image->Bitmap->Create(www, hhh, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } if ((RhDC = Image->Bitmap->CreateDC()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } SetStretchBltMode(RhDC, COLORONCOLOR); if (MainImageForm->ARTItem == AREPEAT_NORMAL) { for (y = 0; y < hhh; y += dh) { for (x = 0; x < www; x += dw) MainImageForm->iMainImage->uBitmap->UnionStretchBlt(RhDC, x, y , dw, dh, sx, sy, w, h, SRCCOPY); // convert by celberus } } else if (MainImageForm->ARTItem == AREPEAT_HDVER) { for (x = 0; x < www; x += dw) { if (x==0) gab = 0; else gab += dh-Hdiv; for (y = 0; y < hhh+gab; y += dh) MainImageForm->iMainImage->uBitmap->UnionStretchBlt(RhDC, x, y - gab , dw, dh, sx, sy, w, h, SRCCOPY); // convert by celberus } } else { for (y = 0; y < hhh; y += dh) { if (y==0) gab = 0; else gab += dw-Wdiv; for (x = 0; x < www+gab; x += dw) MainImageForm->iMainImage->uBitmap->UnionStretchBlt(RhDC, x - gab, y , dw, dh, sx, sy, w, h, SRCCOPY); // convert by celberus } } Image->Bitmap->DeleteDC(RhDC); } #ifdef TRIAL RhDC = Image->Bitmap->CreateDC(); PaintWaterMark(RhDC, 0, 0, Image->Bitmap->Width, Image->Bitmap->Height, 1, abs(zoom)+1); Image->Bitmap->DeleteDC(RhDC); #endif Image->Repaint(); return; fail: if (MainImageForm->iMainImage->LayerList->Count > 1) { if (ThDC) tbmp->DeleteDC(ThDC); if (Image->Bitmap) Image->Bitmap->Destroy(); if (tbmp) delete tbmp; } else { if (Image->Bitmap) Image->Bitmap->Destroy(); } EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TAutoRepViewForm::FormResize(TObject *Sender) { int w; Panel1->Width = ClientWidth; Panel1->Height = ClientHeight - Panel2->Height; w = (Panel2->Width)/3 - 5; //-14 sbZoomOut->Width = w; sbZoomOut->Left = 5; stZoom->Width = w; stZoom->Left = 5+2+w; sbZoomIn->Width = w; sbZoomIn->Left = 5+4+2*w; ReDrawImage(); } //--------------------------------------------------------------------------- void __fastcall TAutoRepViewForm::FormClose(TObject *Sender, TCloseAction &Action) { // MainImageForm->sbAutoRepView->Down = false; MainImageForm->ARViewExitForm(); } //--------------------------------------------------------------------------- void __fastcall TAutoRepViewForm::ReadIniFile() { TIniFile *AutoRepViewIni = NULL; int l, t; AutoRepViewIni = new TIniFile(AppDataItem + "\\AutoRepView.ini"); if (AutoRepViewIni) { l = AutoRepViewIni->ReadInteger("Form", "Left", (Screen->Width-Width)>>1); t = AutoRepViewIni->ReadInteger("Form", "Top", (Screen->Height-Height)>>1); delete AutoRepViewIni; } if (l < 0) Left = 0; else Left = l; if (t < 0) Top = 0; else Top = t; } //--------------------------------------------------------------------------- void __fastcall TAutoRepViewForm::WriteIniFile() { TIniFile *AutoRepViewIni = NULL; AutoRepViewIni = new TIniFile(AppDataItem + "\\AutoRepView.ini"); if (AutoRepViewIni) { AutoRepViewIni->WriteInteger("Form", "Left", Left); AutoRepViewIni->WriteInteger("Form", "Top", Top); delete AutoRepViewIni; } } //---------------------------------------------------------------------------