//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "LBIC_scan_solarniho_clanku.h"
#include "LBIC_ovladaci_panel.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
        : TForm(Owner)
{
//inicializace Form2 - aby se nemazal obrazek
  Form2->TransparentColor=true;
  Form2->TransparentColorValue=clRed;
//inicializace Form2 - aby se nemazal obrazek
}

bool PressedLeft,PressedRight,Smer;
TPoint ImgFromCursor;
int X1,Y1,X2,Y2;
TRect VybranyObdelnik;

//---------------------------------------------------------------------------
void __fastcall TForm2::ListBox1MouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
  if  (Smazane==false)
    if (Zvetseni==1)
      Form2->Caption=(" X: "+AnsiString(X)+"   Y: "+AnsiString(Y)+"  Hodnota: "+FloatToStrF(PoleHodnot[X][Y],2,6,5));
    else
      Form2->Caption=(" X: "+AnsiString(X)+"   Y: "+AnsiString(Y)+"  Hodnota: "+FloatToStrF(PoleHodnotZOOM[X][Y],2,6,5));
  else Form2->Caption=(" X: "+AnsiString(X)+"   Y: "+AnsiString(Y));

  if(PressedLeft)
  {
    TPoint pt(ListBox1->ClientToParent(TPoint(X,Y),Form2));
    ListBox1->Left = (pt.x-ImgFromCursor.x);
    ListBox1->Top = (pt.y-ImgFromCursor.y);
  }

  if(PressedRight)
  {
    if ((X1<X) && (Y1<Y)) {VybranyObdelnik=Rect(X1,Y1,X,Y);}
    if ((X1>X) && (Y1<Y)) {VybranyObdelnik=Rect(X,Y1,X1,Y);}
    if ((X1>X) && (Y1>Y)) {VybranyObdelnik=Rect(X,Y,X1,Y1);}
    if ((X1<X) && (Y1>Y)) {VybranyObdelnik=Rect(X1,Y,X,Y1);}

    Form2->ListBox1->Canvas->StretchDraw(VelikostObrazku,pObrazek);
    Form2->ListBox1->Canvas->FrameRect(VybranyObdelnik);
  }
}
//---------------------------------------------------------------------------


void __fastcall TForm2::ListBox1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  if (Shift.Contains(ssLeft)){
  PressedLeft=true;
  ImgFromCursor=TPoint(X,Y);
  Form2->ListBox1->Cursor=crHandPoint;
  }
  if (Shift.Contains(ssRight)){
  Form2->ListBox1->Cursor=crArrow;
  PressedRight=true;
  Form1->Edit1->Text=X+StartX;
  Form1->Edit2->Text=Y+StartY;
  X1=X;
  Y1=Y;        
  Smer=true;
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm2::ListBox1MouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  //po ukonceni presunu se obrazek vykresli
  if (PressedLeft) {
    PressedLeft=false;
    Form2->ListBox1->Cursor=crCross;
    VelikostObrazku=NastavVelikostObrazku(); //nastavi velikost obrazku
    Form2->ListBox1->Refresh(); //smaze ListBox
    Form2->ListBox1->Canvas->StretchDraw(VelikostObrazku,pObrazek);
    for (int i=0;i<pObrazekZOOM->Width;i++)   //prirazeni do promene namerene hodnoty
      for (int j=0;j<pObrazekZOOM->Height;j++){
        pObrazekZOOM->Canvas->Pixels[i][j]=Form2->ListBox1->Canvas->Pixels[i][j];
      }
    Form2->Show();
  Smazane = false;
  }
  //po ukonceni presunu se obrazek vykresli

  //zobrazeni a vybrani ctverce
  if (PressedRight) {
    Form2->ListBox1->Canvas->FrameRect(VybranyObdelnik);
    Form2->ListBox1->Cursor=crCross;
    PressedRight=false;

    //spravne nastaveni souradnic noveho obrazku
    if (X1<X) X2=X;
    else {X2=X1; X1=X;}
    if (Y1<Y) Y2=Y;
    else {Y2=Y1; Y1=Y;}
    pObrazekVyber->Width=X2-X1;
    pObrazekVyber->Height=Y2-Y1;
    Form1->Edit1->Text=X1+StartX;
    Form1->Edit2->Text=Y1+StartY;
    Form1->Edit3->Text=X2+StartX;
    Form1->Edit4->Text=Y2+StartY;
    //spravne nastaveni souradnic noveho obrazku

    // vyber obrazku
    //zatim s tim nijak nepracuji - momentalne je zbytecny
   for (int i=X1;i<=X2;i++)
      for (int j=Y1;j<=Y2;j++)
    pObrazekVyber->Canvas->Pixels[i-X1][j-Y1]=pObrazek->Canvas->Pixels[i][j];
    // vyber obrazku
  }
  //zobrazeni a vybrani ctverce
}
//---------------------------------------------------------------------------

