__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
bmp = new Graphics::TBitmap;
}
//---------------------------------------------------------------------------
static int x = 0;
static int y = 0;
bool bZoom = false;
//---------------------------------------------------------------------------
void __fastcall TForm1::ZoomIn(TObject *Sender)
{
int test;
if(bmp->Width >= bmp->Height)
test = bmp->Width/2 - (Image1->Width) / 100;
else
test = bmp->Height/2 - (Image1->Height) / 100;
if(x < test)
{
x += (Image1->Width) / 100;
y += (Image1->Height) / 100;
Graphics::TBitmap *tmp = new Graphics::TBitmap;
tmp->Width = bmp->Width;
tmp->Height = bmp->Height;
tmp->Canvas->CopyRect(Rect(0, 0, tmp->Width, tmp->Height), bmp->Canvas, Rect(x, y, bmp->Width - x, bmp->Height - y));
Image1->Canvas->Draw(0, 0, tmp);
delete tmp;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ZoomOut(TObject *Sender)
{
if(x > 0)
{
x -= (Image1->Width) / 100;
y -= (Image1->Height) / 100;
Graphics::TBitmap *tmp = new Graphics::TBitmap;
tmp->Width = bmp->Width;
tmp->Height = bmp->Height;
tmp->Canvas->CopyRect(Rect(0, 0, tmp->Width, tmp->Height), bmp->Canvas, Rect(x, y, bmp->Width - x, bmp->Height - y));
Image1->Canvas->Draw(0, 0, tmp);
delete tmp;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseWheelUp(TObject *Sender, TShiftState Shift, TPoint &MousePos,
bool &Handled) /* zdarzenie OnMouseWheelUp dla Form1 */
{
if(bZoom) ZoomIn(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseWheelDown(TObject *Sender, TShiftState Shift,
TPoint &MousePos, bool &Handled) /* zdarzenie OnMouseWheelDown dla Form1 */
{
if(bZoom) ZoomOut(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift, int X,
int Y) /* zdarzenie OnMouseMove dla Image1 */
{
if( !bZoom )
{
bmp->Assign(Image1->Picture->Graphic);
Image1->Picture->Graphic = NULL;
Image1->Canvas->Draw(0, 0, bmp);
bZoom = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseLeave(TObject *Sender)
{ /* zdarzenie OnMouseLeave dla Image1 */
bZoom = false;
}