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

#include <vcl.h>
#include "AppGlobalF.h"
#include "ITSLangTransF.h"
#pragma hdrstop

#include "FrmFullScreenF.h"
#include "FrmCrsStreamPlayerF.h"
#include "FrmCrsCmraF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxEdit"
#pragma link "cxGraphics"
#pragma link "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinMcSkin"
#pragma link "FRAME_CameraF"
#pragma resource "*.dfm"

//TFrmCrsStreamPlayer *FrmCrsStreamPlayer;
//---------------------------------------------------------------------------
__fastcall TFrmCrsStreamPlayer::TFrmCrsStreamPlayer(TComponent* Owner, TCross *ACrossObj)
    : TForm(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());

    FCross = ACrossObj;
    FParent = this->Parent;
	FFormList = new TObjectList();

    if (FCross != NULL) {
        Caption = FCross->CROSS_NM;
        PnlCrs->Caption = FCross->CROSS_NM;
        PnlCrsTitle->Caption = FCross->CROSS_NM;

        FOR_STL(TCrossCam *, pCrsCam, FCross->FLists)
        {
            TFRAMECamera *pFrameCamera = (TFRAMECamera*)FindComponent("FRAMECamera" + pCrsCam->DIRECTION);
            if (pFrameCamera) {
                pFrameCamera->Init(pCrsCam->CAM_ID, pCrsCam->CAM_ID, pCrsCam->CAM_NM, pCrsCam->RTSP_URL);
            }
        }
    }
}
//---------------------------------------------------------------------------
void __fastcall TFrmCrsStreamPlayer::FormShow(TObject *Sender)
{
    Refresh();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsStreamPlayer::FormClose(TObject *Sender, TCloseAction &Action)
{
    Action = caFree;
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsStreamPlayer::FormDestroy(TObject *Sender)
{
    ClearFormList();
    if (FCross) {
        FOR_STL(TCrossCam *, pCrsCam, FCross->FLists)
        {
            TFRAMECamera *pFrameCamera = (TFRAMECamera*)FindComponent("FRAMECamera" + pCrsCam->DIRECTION);
            if (pFrameCamera) {
                pFrameCamera->Disconnect();
            }
        }
        FCross->FData1 = NULL;
    }
}
//---------------------------------------------------------------------------
void __fastcall TFrmCrsStreamPlayer::ClearFormList()
{
	while(FFormList->Count)
    {
        TFrmCrsCamra *pCmraForm = (TFrmCrsCamra*)FFormList->Items[0];
    	FFormList->Delete(0);
    }
    FFormList->Clear();
}
//---------------------------------------------------------------------------

