home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
-
- #include "ChildWin.h"
- #include "ProgDiag.h"
- #include "Main.h"
- #include "SaveDlg.h"
- //---------------------------------------------------------------------
- #pragma link "LTOCX10N"
- #pragma resource "*.dfm"
- //---------------------------------------------------------------------
- __fastcall TMDIChild::TMDIChild(TComponent *Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------
- void __fastcall TMDIChild::FormClose(TObject *Sender, TCloseAction &Action)
- {
- Lead1->Bitmap = 0;
- Action = caFree;
- }
- //---------------------------------------------------------------------
-
- //---------------------------------------------------------------------
- void TMDIChild::InitStatusProcess(String Title)
- {
- ProgressDialog->Caption = Title;
- if(Lead1->EnableProgressEvent)
- ProgressDialog->Show();
- }
- //---------------------------------------------------------------------------
-
- void TMDIChild::ResetStatusProcess()
- {
- ProgressDialog->Hide();
- }
-
- void __fastcall TMDIChild::Lead1ProgressStatus(TObject *Sender, short iPercent)
- {
- ProgressDialog->ProgressBar1->Position=iPercent;
- Application->ProcessMessages();
- }
- //---------------------------------------------------------------------------
-
- void TMDIChild::SaveImage()
- {
- int nRet,nVal;
- int nFormat,nBits,nQFactor;
-
- MainForm->SaveDialog1->Filter = szSaveFilter;
- if(MainForm->SaveDialog1->Execute())
- {
- SaveOptions->ShowModal();
- if(SaveOptions->ModalResult == mrOk)
- {
- switch(SaveOptions->SaveBits->ItemIndex)
- {
- case 0:
- nBits=1;
- break;
- case 1:
- nBits=2;
- break;
- case 2:
- nBits=3;
- break;
- case 3:
- nBits=4;
- break;
- case 4:
- nBits=5;
- break;
- case 5:
- nBits=6;
- break;
- case 6:
- nBits=7;
- break;
- case 7:
- nBits=8;
- break;
- case 8:
- nBits=16;
- break;
- case 9:
- nBits=24;
- break;
- case 10:
- nBits=32;
- break;
- }
- switch(MainForm->SaveDialog1->FilterIndex)
- {
- case 1:
- if(nBits==1)
- nFormat=FILE_LEAD1BIT;
- else
- nFormat=FILE_LEAD;
- break;
- case 2: nFormat = FILE_JFIF; break;
- case 3: nFormat = FILE_CALS; break;
- case 4: nFormat = FILE_PNG; break;
- case 5: nFormat = FILE_EPS; break;
- case 6: nFormat = FILE_IMG; break;
- case 7: nFormat = FILE_GIF; break;
- case 8: nFormat = FILE_RAWICA_G3_1D; break;
- case 9: nFormat = FILE_PCT; break;
- case 10: nFormat = FILE_MAC; break;
- case 11: nFormat = FILE_MSP; break;
- case 12: nFormat = FILE_PCX; break;
- case 13: nFormat = FILE_PSD; break;
- case 14: nFormat = FILE_RAS; break;
- case 15: nFormat = FILE_TGA; break;
- case 16: nFormat = FILE_TIF; break;
- case 17: nFormat = FILE_CCITT; break;
- case 18: nFormat = FILE_JTIF; break;
- case 19: nFormat = FILE_TIFLZW; break;
- case 20: nFormat = FILE_BMP; break;
- case 21: nFormat = FILE_FPX; break;
- case 22: nFormat = FILE_BMP_RLE; break;
- case 23: nFormat = FILE_TIF_CMYK; break;
- case 24: nFormat = FILE_TIFLZW_CMYK; break;
- case 25: nFormat = FILE_TIF_PACKBITS; break;
- case 26: nFormat = FILE_TIF_PACKBITS_CMYK; break;
- case 27: nFormat = FILE_DICOM_GRAY; break;
- case 28: nFormat = FILE_DICOM_COLOR; break;
- case 29: nFormat = FILE_WIN_ICO; break;
- case 30: nFormat = FILE_WIN_CUR; break;
- case 31: nFormat = FILE_TIF_YCC; break;
- case 32: nFormat = FILE_TIFLZW_YCC; break;
- case 33: nFormat = FILE_TIF_PACKBITS_YCC; break;
- case 34: nFormat = FILE_EXIF; break;
- case 35: nFormat = FILE_EXIF_YCC; break;
- case 36: nFormat = FILE_EXIF_JPEG; break;
- case 37: nFormat = FILE_AWD; break;
- }
- nVal = SaveOptions->SaveQFactor->Text.ToInt();
- if(nVal==0)
- Application->MessageBox("Error Saving Image","Error",MB_ICONINFORMATION);
- else
- {
- nQFactor=nVal;
- Cursor=crHourGlass;
- InitStatusProcess("Saving File: " + MainForm->SaveDialog1->FileName);
- nRet=Lead1->Save(MainForm->SaveDialog1->FileName,(short)nFormat,
- (short)nBits,(short)nQFactor,false);
- ResetStatusProcess();
- Cursor=crDefault;
- }
- if(nRet<0)
- Application->MessageBox("Error Saving Image","Error",MB_ICONINFORMATION);
- }
- }
- }
- void __fastcall TMDIChild::Lead1MouseDown(TObject *Sender, TMouseButton Button,
- TShiftState Shift, int X, int Y)
- {
- if(Button == mbLeft)
- {
- if(Lead1->HasRgn && (Lead1->IsPtInRgn((X-Lead1->DstLeft) * Lead1->SrcWidth /
- Lead1->DstWidth,(Y-Lead1->DstTop)*Lead1->SrcHeight / Lead1->DstHeight)))
- {
- Lead1->RgnMarkingMode=RGNMARK_NONE;
- Lead1->RgnFrameType=RGNFRAME_NONE;
- xStart = X;
- yStart = Y;
- Lead1->FloaterVisible = false;
- Lead1->Floater = Lead1->Bitmap;
- Lead1->SetFloaterDstRect(Lead1->RgnLeft * Lead1->DstWidth / Lead1->SrcWidth +
- Lead1->DstLeft,Lead1->RgnTop * Lead1->DstHeight /
- Lead1->SrcHeight + Lead1->DstTop, Lead1->FloaterWidth *
- Lead1->DstWidth / Lead1->SrcWidth, Lead1->FloaterHeight *
- Lead1->DstHeight / Lead1->SrcHeight);
- if(Lead2->Bitmap!=0)
- {
- Lead1->Combine(Lead1->RgnLeft,Lead1->RgnTop,Lead1->FloaterWidth,
- Lead1->FloaterHeight,Lead2->Bitmap,0.0,0.0,CB_DST_0 | CB_OP_OR);
- Lead1->RepaintRect(Lead1->FloaterDstLeft,Lead1->FloaterDstTop,
- Lead1->FloaterDstWidth,Lead1->FloaterDstHeight,
- false);
- }
- Lead1->FloaterVisible=true;
- MovingFloater=true;
- }
- else if(RegionTool!=RGNMARK_NONE)
- {
- Lead1->RgnFrameType=RGNFRAME_NONE;
- Lead1->RgnMarkingMode=(short)RegionTool;
- }
- Lead2->Bitmap=0;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TMDIChild::Lead1MouseMove(TObject *Sender, TShiftState Shift,
- int X, int Y)
- {
- if(MovingFloater)
- {
- Lead1->SetFloaterDstRect(Lead1->FloaterDstLeft + X - xStart,
- Lead1->FloaterDstTop + Y - yStart,
- Lead1->FloaterDstWidth,Lead1->FloaterDstHeight);
- xStart=X;
- yStart=Y;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TMDIChild::FormCreate(TObject *Sender)
- {
- MovingFloater=false;
- Lead2->Visible=false;
- Lead3->Visible=false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMDIChild::Lead1MouseUp(TObject *Sender, TMouseButton Button,
- TShiftState Shift, int X, int Y)
- {
- int hRegion;
-
- if(Button!=mbLeft)
- return;
- if(Lead1->RgnMarkingMode!=RGNMARK_NONE)
- {
- Lead1->RgnMarkingMode=RGNMARK_NONE;
- if(Lead1->HasRgn)
- {
- Lead1->RgnFrameType=RGNFRAME_ANIMATED;
- MainForm->CancelRegion1->Enabled=true;
- }
- else
- Lead1->RgnFrameType=RGNFRAME_NONE;
- }
- else if(MovingFloater)
- {
- MovingFloater=false;
- Lead1->RgnFrameType=RGNFRAME_NONE;
- hRegion=Lead1->GetFloaterHandle();
- Lead1->SetRgnHandle(hRegion,(Lead1->FloaterDstLeft - Lead1->DstLeft) * Lead1->SrcWidth /
- Lead1->DstWidth,(Lead1->FloaterDstTop - Lead1->DstTop) * Lead1->SrcHeight /
- Lead1->DstHeight,L_RGN_SET);
- Lead2->CreateBitmap(Lead1->FloaterWidth,Lead1->FloaterHeight,Lead1->BitmapBits);
- Lead2->Combine(0.0,0.0,Lead1->FloaterWidth,Lead1->FloaterHeight,Lead1->Bitmap,
- Lead1->RgnLeft,Lead1->RgnTop,CB_DST_0 | CB_OP_OR);
- Lead1->Combine(Lead1->RgnLeft,Lead1->RgnTop,Lead1->FloaterWidth,Lead1->FloaterHeight,
- Lead1->Floater,0.0,0.0,CB_DST_0 | CB_OP_OR);
- Lead1->Floater=0;
- Lead1->FloaterVisible=false;
- Lead1->RepaintRect(Lead1->RgnLeft * Lead1->DstWidth / Lead1->SrcWidth - Lead1->DstLeft,
- Lead1->RgnTop * Lead1->DstHeight / Lead1->SrcHeight + Lead1->DstTop,
- Lead1->RgnWidth * Lead1->DstWidth / Lead1->SrcWidth,
- Lead1->RgnHeight * Lead1->DstHeight / Lead1->SrcHeight,
- false);
- Lead1->RgnFrameType = RGNFRAME_ANIMATED;
- Lead1->DeleteRgnHandle(hRegion);
- }
- }
- //---------------------------------------------------------------------------
-
- void TMDIChild::SaveBackground()
- {
- Lead2->CreateBitmap(Lead1->RgnWidth,Lead1->RgnHeight,Lead1->BitmapBits);
- Lead2->Combine(0.0,0.0,Lead1->RgnWidth,Lead1->RgnHeight,Lead1->Bitmap,Lead1->RgnLeft,
- Lead1->RgnTop,CB_DST_0 | CB_OP_OR);
- }
-
- void TMDIChild::RestoreBackground()
- {
- if(Lead2->Bitmap!=0)
- {
- Lead1->Combine(Lead1->RgnLeft,Lead1->RgnTop,Lead1->RgnWidth,Lead1->RgnHeight,
- Lead2->Bitmap,0.0,0.0,CB_DST_0 | CB_OP_OR);
- }
- }
-
- void TMDIChild::CancelRegion()
- {
- RestoreBackground();
- Lead1->RgnFrameType=RGNFRAME_NONE;
- Lead1->FreeRgn();
- Lead1->Floater=0;
- MainForm->CancelRegion1->Enabled=false;
- }
-
- void TMDIChild::ZoomImage(int amount,bool up)
- {
- int zoom;
-
- if(up)
- zoom=100 * amount;
- else
- zoom = 100 / amount;
- Lead1->PaintZoomFactor = zoom;
- }
-
- void TMDIChild::ProcessRegion(String what)
- {
- int xCenter,yCenter;
- int hRegion;
-
- Lead1->FloaterVisible=false;
- Lead1->Floater=Lead1->Bitmap;
- RestoreBackground();
- Lead3->Bitmap=Lead1->Floater;
- Lead1->Floater=0;
- Lead3->EnableProgressEvent=Lead1->EnableProgressEvent;
- if(what=="Flip")
- Lead3->Flip();
- else if(what=="Reverse")
- Lead3->Reverse();
- else if(what=="Rotate")
- Lead3->Rotate(rValue*100,true,clBlack);
- else if(what=="Shear")
- Lead3->Shear(rValue*100,true,clBlack);
- else if(what=="Resize")
- Lead3->Size(rValue,sValue,RESIZE_NORMAL);
- else if(what=="Resample");
- Lead3->Size(rValue,sValue,RESIZE_RESAMPLE);
- Lead1->RgnFrameType=RGNFRAME_NONE;
- hRegion=Lead3->GetRgnHandle();
- xCenter=Lead1->RgnLeft + Lead1->RgnWidth / 2;
- yCenter=Lead1->RgnTop + Lead1->RgnHeight / 2;
- Lead1->SetRgnHandle(hRegion,xCenter-Lead3->BitmapWidth/2,yCenter-Lead3->BitmapWidth/2,
- L_RGN_SET);
- Lead1->DeleteRgnHandle(hRegion);
- SaveBackground();
- Lead1->Combine(xCenter-Lead3->BitmapWidth/2,yCenter-Lead3->BitmapHeight/2,
- Lead3->BitmapWidth,Lead3->BitmapHeight,Lead3->Bitmap,0.0,0.0,
- CB_DST_0 | CB_OP_OR);
- Lead1->RgnFrameType=RGNFRAME_ANIMATED;
- Lead1->RepaintRect(Lead1->RgnLeft*Lead1->DstWidth/Lead1->SrcWidth+Lead1->DstLeft,
- Lead1->RgnTop*Lead1->DstWidth/Lead1->SrcWidth+Lead1->DstTop,
- Lead1->RgnWidth*Lead1->DstWidth/Lead1->SrcWidth,
- Lead1->RgnHeight*Lead1->DstWidth/Lead1->SrcWidth,
- false);
- Lead3->Bitmap=0;
- }
-