#include "ordevicevideo_device.h"
#include "ordevicevideo_layout.h"
#define ORDEVICEVIDEO__LAYOUT ORDeviceVideoLayout
ORDEVICEVIDEO__CLASSSTR,
bool ORDeviceVideoLayout::FBCreate()
{
mDevice = ((ORDeviceVideo*)(FBDevice *)Device);
UICreate ();
UIConfigure ();
UIReset ();
mSystem.OnUIIdle.Add (
this, (
FBCallback) &ORDeviceVideoLayout::EventUIIdle );
mDevice->OnStatusChange.Add (
this, (
FBCallback) &ORDeviceVideoLayout::EventDeviceStatusChange );
return true;
}
void ORDeviceVideoLayout::FBDestroy()
{
mSystem.OnUIIdle.Remove (
this, (
FBCallback) &ORDeviceVideoLayout::EventUIIdle );
mDevice->OnStatusChange.Remove (
this, (
FBCallback) &ORDeviceVideoLayout::EventDeviceStatusChange );
}
void ORDeviceVideoLayout::UICreate()
{
int lS = 4;
int lH = 25;
AddRegion( "TabPanel", "TabPanel",
AddRegion( "MainLayout", "MainLayout",
SetControl( "TabPanel", mTabPanel );
SetControl( "MainLayout", mLayout0 );
UICreateLayout0();
UICreateLayout1();
}
void ORDeviceVideoLayout::UICreateLayout0()
{
int lH = 18;
int lW = 200;
int lS = 4;
mLayout0.AddRegion( "SpreadPlaylist", "SpreadPlaylist",
mLayout0.AddRegion( "ListExistingMedia", "ListExistingMedia",
mLayout0.AddRegion( "ButtonAddItem", "ButtonAddItem",
mLayout0.AddRegion( "ButtonRemoveItem", "ButtonRemoveItem",
mLayout0.SetControl ( "SpreadPlaylist", mSpreadPlaylist );
mLayout0.SetControl ( "ListExistingMedia", mListExistingMedia );
mLayout0.SetControl ( "ButtonAddItem", mButtonAddItem );
mLayout0.SetControl ( "ButtonRemoveItem", mButtonRemoveItem );
}
void ORDeviceVideoLayout::UICreateLayout1()
{
int lS = 4;
int lH = 18;
int lW = 200;
mLayout1.AddRegion( "ListPlaybackType", "ListPlaybackType",
mLayout1.AddRegion( "ButtonLoop", "ButtonLoop",
mLayout1.SetControl( "ListPlaybackType", mListPlaybackType );
mLayout1.SetControl( "ButtonLoop", mButtonLoop );
}
void ORDeviceVideoLayout::UIConfigure()
{
mTabPanel.Items.SetString( "PlayList~Configuration~View" );
mTabPanel.OnChange.Add(
this, (
FBCallback) &ORDeviceVideoLayout::EventTabPanelChange );
UIConfigureLayout0();
UIConfigureLayout1();
}
void ORDeviceVideoLayout::UIConfigureLayout0()
{
mButtonAddItem.Caption = "Add entry";
mButtonRemoveItem.Caption = "Remove entry";
mSpreadPlaylist.OnDragAndDrop.Add (
this, (
FBCallback) &ORDeviceVideoLayout::EventSpreadPlaylistDragAndDrop );
mSpreadPlaylist.OnCellChange.Add (
this, (
FBCallback) &ORDeviceVideoLayout::EventSpreadPlaylistCellChange );
mButtonAddItem.OnClick.Add (
this, (
FBCallback) &ORDeviceVideoLayout::EventButtonAddItemClick );
mButtonRemoveItem.OnClick.Add (
this, (
FBCallback) &ORDeviceVideoLayout::EventButtonRemoveItemClick );
mListExistingMedia.OnDragAndDrop.Add(
this, (
FBCallback) &ORDeviceVideoLayout::EventListExistingMediaDragAndDrop );
mListExistingMedia.OnChange.Add (
this, (
FBCallback) &ORDeviceVideoLayout::EventListExistingMediaChange );
}
void ORDeviceVideoLayout::UIConfigureLayout1()
{
mListPlaybackType.Items.Add( "FreeRunning", kORPlaybackFreeRunning );
mListPlaybackType.Items.Add( "Local Frame", kORPlaybackLocalFrame );
mListPlaybackType.Items.Add( "Global Frame", kORPlaybackGlobalFrame );
mListPlaybackType.OnChange.Add(
this, (
FBCallback)&ORDeviceVideoLayout::EventListPlaybackTypeChange );
mButtonLoop.Caption = "Loop";
mButtonLoop.OnClick.Add(
this, (
FBCallback)&ORDeviceVideoLayout::EventButtonLoopClick );
}
void ORDeviceVideoLayout::UIReset()
{
UIResetLayout0();
UIResetLayout1();
}
void ORDeviceVideoLayout::UIResetLayout0()
{
UIResetSpreadPlaylist();
mListExistingMedia.Items.Clear();
for( i=0; i<mSystem.Scene->VideoClips.GetCount(); i++ )
{
FBVideoClip* lVideo = mSystem.Scene->VideoClips[
i];
mListExistingMedia.Items.Add( lVideo->Name, (kReference) lVideo );
}
mListExistingMedia.Items.Add( "New media...", (kReference)-2 );
mListExistingMedia.ItemIndex = -1;
}
void ORDeviceVideoLayout::UIResetLayout1()
{
mListPlaybackType.ItemIndex = mListPlaybackType.Items.Find( mDevice->GetPlaybackMode() );
mButtonLoop.State = mDevice->GetLoopMode() ? 1:0;
}
void ORDeviceVideoLayout::UIResetSpreadPlaylist()
{
FBVideoClip* lVideo =
NULL;
char lBuffer[50];
FBTime lTime;
int lFrames;
int lLoopCnt;
kReference lRef;
ORVideoEntry* lClip =
NULL;
mSpreadPlaylist.Clear();
mSpreadPlaylist.Caption = "Clips";
mSpreadPlaylist.MultiSelect = false;
mSpreadPlaylist.GetColumn(-1).Width = 50;
mSpreadPlaylist.ColumnAdd( "Label", 0 );
mSpreadPlaylist.GetColumn(0).Width = 100;
mSpreadPlaylist.GetColumn(0).ReadOnly = false;
mSpreadPlaylist.ColumnAdd( "File", 1 );
mSpreadPlaylist.GetColumn(1).Width = 100;
mSpreadPlaylist.GetColumn(1).ReadOnly = true;
mSpreadPlaylist.ColumnAdd( "Frames", 2 );
mSpreadPlaylist.GetColumn(2).Width = 50;
mSpreadPlaylist.GetColumn(2).ReadOnly = true;
mSpreadPlaylist.ColumnAdd( "Length", 3 );
mSpreadPlaylist.GetColumn(3).Width = 75;
mSpreadPlaylist.GetColumn(3).ReadOnly = true;
mSpreadPlaylist.ColumnAdd( "Play Count", 4 );
mSpreadPlaylist.GetColumn(4).Width = 50;
mSpreadPlaylist.GetColumn(4).ReadOnly = false;
for( i=0; i<mDevice->mClips.GetCount(); i++ )
{
lClip = mDevice->mClips[
i];
sprintf(lBuffer,"Clip %d", i );
lRef = (kReference) lClip;
mSpreadPlaylist.RowAdd( lBuffer, lRef );
mSpreadPlaylist.SetCell(lRef,0, lClip->GetName() );
lVideo = lClip->GetVideo();
if( lVideo )
{
lFrames = lVideo->LastFrame;
lTime = lVideo->LastFrameTime;
mSpreadPlaylist.SetCell(lRef,1, lVideo->Name );
mSpreadPlaylist.SetCell(lRef,2, lFrames );
mSpreadPlaylist.SetCell(lRef,3, lTime.GetTimeString() );
}
lLoopCnt= lClip->GetLoopCount();
mSpreadPlaylist.SetCell(lRef,4, lLoopCnt );
}
}
void ORDeviceVideoLayout::UIRefresh()
{
UIRefreshLayout0();
UIRefreshLayout1();
if( mTabPanel.ItemIndex == 2 )
{
FBVideoClip* lVideo = mDevice->GetCurrentVideo();
if( lVideo && lVideo != mViewImageSwitcher.GetVideoClip() )
{
mViewImageSwitcher.SetVideoClip( lVideo );
}
mViewImageSwitcher.Refresh(true);
}
}
void ORDeviceVideoLayout::UIRefreshLayout0()
{
}
void ORDeviceVideoLayout::UIRefreshLayout1()
{
}
{
UIRefresh();
}
void ORDeviceVideoLayout::EventTabPanelChange(
HISender pSender,
HKEvent pEvent )
{
switch( mTabPanel.ItemIndex )
{
case 0: SetControl ( "MainLayout", mLayout0 ); break;
case 1: SetControl ( "MainLayout", mLayout1 ); break;
case 2: SetView ( "MainLayout", mViewImageSwitcher ); break;
}
}
void ORDeviceVideoLayout::EventSpreadPlaylistCellChange(
HISender pSender,
HKEvent pEvent )
{
FBEventSpread lEvent( pEvent );
char lText[1024];
ORVideoEntry* lClip;
const char* lPtr = lText;
int lValue;
switch( lEvent.Column )
{
case 0:
{
lClip = (ORVideoEntry*) (kReference) lEvent.Row;
mSpreadPlaylist.GetCell( lEvent.Row, lEvent.Column, lPtr );
lClip->SetName( lPtr );
mSpreadPlaylist.SetCell( lEvent.Row, lEvent.Column, lClip->GetName() );
}
break;
case 4:
{
lClip = (ORVideoEntry*) (kReference) lEvent.Row;
mSpreadPlaylist.GetCell( lEvent.Row, lEvent.Column, lValue );
lClip->SetLoopCount( lValue );
mSpreadPlaylist.SetCell( lEvent.Row, lEvent.Column, lClip->GetLoopCount() );
}
break;
}
}
void ORDeviceVideoLayout::EventSpreadPlaylistDragAndDrop(
HISender pSender,
HKEvent pEvent )
{
FBEventDragAndDrop lEvent(pEvent);
switch( lEvent.State )
{
{
lEvent.Accept();
}
break;
{
FBComponent* lComponent =
NULL;
lComponent = lEvent.Get(0);
if( lComponent && lComponent->Is( FBVideo::TypeInfo ) )
{
FBVideoClip* lVideo =
NULL;
kReference lRow = 0;
lVideo = (FBVideoClip*) lComponent;
lRow = lEvent.Data[0];
{
if( lRow > 0 )
{
ORVideoEntry* lEntry = (ORVideoEntry*) lRow;
lEntry->SetVideo( lVideo );
UIReset();
mSpreadPlaylist.GetRow( lRow ).Selected = true;
}
mListExistingMedia.ItemIndex = -1;
}
}
}
break;
}
}
void ORDeviceVideoLayout::EventButtonAddItemClick(
HISender pSender,
HKEvent pEvent )
{
kReference lRef;
mDevice->AddNewVideoClip();
UIReset();
if ( mDevice->mClips.GetCount() )
{
lRef = (kReference) mDevice->mClips.GetLast();
mSpreadPlaylist.GetRow(lRef).RowSelected = true;
}
}
void ORDeviceVideoLayout::EventButtonRemoveItemClick(
HISender pSender,
HKEvent pEvent )
{
kReference lRef;
ORVideoEntry* lEntry;
for(i=0; i<mDevice->mClips.GetCount(); i++ )
{
lRef = (kReference) mDevice->mClips[i];
if( mSpreadPlaylist.GetRow(lRef).RowSelected )
{
lEntry = mDevice->mClips[
i];
mDevice->mClips.Remove( lEntry );
delete lEntry;
UIReset();
}
}
bool lFound = false;
for(i=0; i<mDevice->mClips.GetCount(); i++ )
{
lRef = (kReference) mDevice->mClips[i];
if( ! mDevice->mClips[i]->GetVideo() )
{
lFound = true;
mSpreadPlaylist.GetRow(lRef).Selected = true;
}
}
if( !lFound && mDevice->mClips.GetCount() )
{
lRef = (kReference) mDevice->mClips.GetLast();
mSpreadPlaylist.GetRow(lRef).Selected = true;
}
}
void ORDeviceVideoLayout::EventListExistingMediaDragAndDrop(
HISender pSender,
HKEvent pEvent )
{
FBEventDragAndDrop lEvent( pEvent );
switch( lEvent.State )
{
{
if( mListExistingMedia.ItemIndex >= 0 )
{
lEvent.Add( (FBComponent*) mListExistingMedia.Items.GetReferenceAt( mListExistingMedia.ItemIndex ), 0 );
}
}
break;
{
lEvent.Clear();
}
break;
}
}
void ORDeviceVideoLayout::EventListExistingMediaChange(
HISender pSender,
HKEvent pEvent )
{
if( mListExistingMedia.Items.GetReferenceAt( mListExistingMedia.ItemIndex ) == (kReference)-2 )
{
mListExistingMedia.ItemIndex = -1;
FBFilePopup lPopup;
FBVideoClip* lVideo;
lPopup.Caption = "Load new media";
lPopup.Filter = "*.*";
lPopup.Path = mSystem.PathImages;
if(lPopup.Execute())
{
lVideo = new FBVideoClip( lPopup.FullFilename );
if( lVideo )
{
UIReset();
}
}
}
}
void ORDeviceVideoLayout::EventDeviceStatusChange(
HISender pSender,
HKEvent pEvent )
{
bool lState = ! (
bool) mDevice->Online;
mListExistingMedia.Enabled = lState;
mButtonAddItem.Enabled = lState;
mButtonRemoveItem.Enabled = lState;
}
void ORDeviceVideoLayout::EventListPlaybackTypeChange(
HISender pSender,
HKEvent pEvent )
{
mDevice->SetPlaybackMode( (ORPlaybackMode) mListPlaybackType.Items.GetReferenceAt( mListPlaybackType.ItemIndex ) );
UIResetLayout1();
}
void ORDeviceVideoLayout::EventButtonLoopClick(
HISender pSender,
HKEvent pEvent )
{
mDevice->SetLoopMode( mButtonLoop.State != 0 );
UIResetLayout1();
}