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

#include <vcl.h>
#pragma hdrstop

#include "FrmMainF.h"
//#include "samsungPlayer1F.h"
#include "XnsCommon.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxButtons"
#pragma link "cxGraphics"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "dxSkinBlack"
#pragma link "dxSkinMcSkin"
#pragma link "dxSkinsCore"
#pragma link "ImageBtn"
#pragma link "cxControls"
#pragma link "cxPC"
#pragma link "cxPCdxBarPopupMenu"
#pragma link "dxSkinscxPCPainter"
#pragma link "AcesTechXPlayer2Lib_OCX"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    //::CoInitialize(NULL);
    FPlayerForm = NULL;
    FConHandle = 0;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ShowVmsWebCam()
{
#if 0
    if (FPlayerForm)
    {
        samsungPlayer1_play(FPlayerForm,
                            Edit7->Text.Trim(),
                            Edit8->Text.Trim(),
                            Edit1->Text.Trim(),
                            Edit2->Text.Trim().ToIntDef(4520),
                            Edit3->Text.Trim(),
                            Edit4->Text.Trim(),
                            Edit5->Text.Trim(),
                            Edit6->Text.Trim());
    }
#else
    if (FPlayerForm)
    {
        FPlayerForm->FId        = Edit7->Text.Trim();
        FPlayerForm->FLoc       = Edit8->Text.Trim();

        FPlayerForm->FIpAddress = WideString(Edit1->Text.Trim());
        FPlayerForm->FPort      = Edit2->Text.Trim().ToIntDef(4520);
        FPlayerForm->FConnId    = WideString(Edit3->Text.Trim());
        FPlayerForm->FConnPass  = WideString(Edit4->Text.Trim());

        FPlayerForm->FDefModel  = WideString(Edit5->Text.Trim());
        FPlayerForm->FModelName = WideString(Edit6->Text.Trim());

        FPlayerForm->WebCamPlay();
    }
#endif
}
//---------------------------------------------------------------------------

void __fastcall TForm1::controlCamera(int ACommand)
{
#if 0
    samsungPlayer1_control(FPlayerForm, ACommand, PTZSpeed->Position);
#else
    if (FPlayerForm)
    {
         FPlayerForm->CameraControl(ACommand, PTZSpeed->Position);
    }
#endif
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BtnUpLeftMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
          int X, int Y)
{
    try
    {
        TImageBtn *pBtn = (TImageBtn*)Sender;
        //	PTZ_FOCUS_NEAR	12		Focus near
        //	PTZ_FOCUS_FAR	13		Focus far
        //	PTZ_FOCUS_STOP	14		Stop focus moving
        if (pBtn->Tag == 0)
        {
        }
        else
        {
            controlCamera((int)pBtn->Tag);
        }
    }
    catch(...) {}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BtnUpLeftMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
          int X, int Y)
{
    try
    {
        TImageBtn *pBtn = (TImageBtn*)Sender;
        //	PTZ_FOCUS_NEAR	12		Focus near
        //	PTZ_FOCUS_FAR	13		Focus far
        //	PTZ_FOCUS_STOP	14		Stop focus moving
        if (pBtn->Tag == PTZ_FOCUS_NEAR || pBtn->Tag == PTZ_FOCUS_FAR)
        {
            controlCamera(PTZ_FOCUS_STOP);
        }
        else if (pBtn->Tag == 0)
        {
        }
        else
        {
            controlCamera(PTZ_STOP);
        }
    }
    catch(...) {}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    ShowVmsWebCam();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
    if (!FPlayerForm)
    {
#if 0
        FPlayerForm = samsungPlayer1_create(this, PnlVmsCam);
#else
        FPlayerForm = new TFrmSamsungPlayer1((TComponent*)this, (TWinControl*)PnlVmsCam);
        FPlayerForm->Show();
#endif
    }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
    AcesTechXPlayer21->Close();

    AcesTechXPlayer21->URL = Edit9->Text.Trim();
    FConHandle = AcesTechXPlayer21->ConnectAsync();
}
//---------------------------------------------------------------------------

