//--------------------------------------------------------------------------- #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 resource "*.dfm" TAutoRepViewForm *AutoRepViewForm; //--------------------------------------------------------------------------- __fastcall TAutoRepViewForm::TAutoRepViewForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TAutoRepViewForm::FormCreate(TObject *Sender) { StringTable.Create(DirectoryItem, Language, "viewform"); SetSmallFont(Font); sbZoomOut->Caption = IDS_ZOOMOUT; sbZoomIn->Caption = IDS_ZOOMIN; zoom = 0; stZoom->Caption = IntToStr(1); ReadIniFile(); } //--------------------------------------------------------------------------- void __fastcall TAutoRepViewForm::FormShow(TObject *Sender) { ReDrawImage(); } //--------------------------------------------------------------------------- void __fastcall TAutoRepViewForm::sbZoomClick(TObject *Sender) { int cnt, i; AnsiString 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; RGBQUAD srcrgb[256]; 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; izoom; i--) { dw = dw/2; dh = dh/2; } } */ if (zoom < 0) { for (i=0; i>zoom; i--) { dw = dw/2; dh = dh/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) goto fail; if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { MainImageForm->iMainImage->Bitmap->GetColors(0, 256, srcrgb); if (!Image->Bitmap->Create(www, hhh, 8, srcrgb)) goto fail; if (!tbmp->Create(w, h, 8, srcrgb)) goto fail; } else { if (!Image->Bitmap->Create(www, hhh, 24)) goto fail; if (!tbmp->Create(w, h, 24)) goto fail; } if ((ThDC = tbmp->CreateDC()) == NULL) goto fail; if ((RhDC = Image->Bitmap->CreateDC()) == NULL) 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/dw)%2) gab = dh/2; else gab = 0; 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/dh)%2) gab = dw/2; else gab = 0; 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->Bitmap->BitsPerPixel == 8) { MainImageForm->iMainImage->Bitmap->GetColors(0, 256, srcrgb); if (!Image->Bitmap->Create(www, hhh, 8, srcrgb)) goto fail; } else { if (!Image->Bitmap->Create(www, hhh, 24)) goto fail; } if ((ThDC = MainImageForm->iMainImage->Bitmap->CreateDC()) == NULL) goto fail; if ((RhDC = Image->Bitmap->CreateDC()) == NULL) goto fail; 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, sx, sy, w, h, SRCCOPY); } } else if (MainImageForm->ARTItem == AREPEAT_HDVER) { for (x = 0; x < www; x += dw) { if ((x/dw)%2) gab = dh/2; else gab = 0; for (y = 0; y < hhh+gab; y += dh) StretchBlt(RhDC, x, y - gab, dw, dh, ThDC, sx, sy, w, h, SRCCOPY); } } else { for (y = 0; y < hhh; y += dh) { if ((y/dh)%2) gab = dw/2; else gab = 0; for (x = 0; x < www+gab; x += dw) StretchBlt(RhDC, x - gab, y, dw, dh, ThDC, sx, sy, w, h, SRCCOPY); } } Image->Bitmap->DeleteDC(RhDC); MainImageForm->iMainImage->Bitmap->DeleteDC(ThDC); } 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 (ThDC) MainImageForm->iMainImage->Bitmap->DeleteDC(ThDC); if (Image->Bitmap) Image->Bitmap->Destroy(); } EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- 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(DirectoryItem + "\\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(DirectoryItem + "\\AutoRepView.ini"); if (AutoRepViewIni) { AutoRepViewIni->WriteInteger("Form", "Left", Left); AutoRepViewIni->WriteInteger("Form", "Top", Top); delete AutoRepViewIni; } } //---------------------------------------------------------------------------