devices/devicevideo/ordevicevideo_layout.cxx

devices/devicevideo/ordevicevideo_layout.cxx
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2009 Autodesk, Inc. and/or its licensors
All rights reserved.
AUTODESK SOFTWARE LICENSE AGREEMENT
Autodesk, Inc. licenses this Software to you only upon the condition that
you accept all of the terms contained in the Software License Agreement ("Agreement")
that is embedded in or that is delivered with this Software. By selecting
the "I ACCEPT" button at the end of the Agreement or by copying, installing,
uploading, accessing or using all or any portion of the Software you agree
to enter into the Agreement. A contract is then formed between Autodesk and
either you personally, if you acquire the Software for yourself, or the company
or other legal entity for which you are acquiring the software.
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE REGARDING THESE MATERIALS, AND MAKES SUCH MATERIALS AVAILABLE SOLELY ON AN
"AS-IS" BASIS.
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE
OR USE OF THESE MATERIALS. THE SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC.,
REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE PURCHASE PRICE OF THE
MATERIALS DESCRIBED HEREIN.
Autodesk, Inc., reserves the right to revise and improve its products as it sees fit.
Autodesk and Open Reality are registered trademarks or trademarks of Autodesk, Inc.,
in the U.S.A. and/or other countries. All other brand names, product names, or
trademarks belong to their respective holders.
GOVERNMENT USE
Use, duplication, or disclosure by the U.S. Government is subject to restrictions as
set forth in FAR 12.212 (Commercial Computer Software-Restricted Rights) and
DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
Manufacturer is Autodesk, Inc., 10 Duke Street, Montreal, Quebec, Canada, H3C 2L7.
***************************************************************************************/
//--- Class declarations
#include "ordevicevideo_device.h"
#include "ordevicevideo_layout.h"
//--- Registration define
#define ORDEVICEVIDEO__LAYOUT ORDeviceVideoLayout
//--- FiLMBOX implementation and registration
FBDeviceLayoutImplementation( ORDEVICEVIDEO__LAYOUT );
FBRegisterDeviceLayout ( ORDEVICEVIDEO__LAYOUT,
ORDEVICEVIDEO__CLASSSTR,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* FiLMBOX constructor.
************************************************/
bool ORDeviceVideoLayout::FBCreate()
{
// Get a handle on the device.
mDevice = ((ORDeviceVideo*)(FBDevice *)Device);
UICreate ();
UIConfigure ();
UIReset ();
mSystem.OnUIIdle.Add ( this, (FBCallback) &ORDeviceVideoLayout::EventUIIdle );
mDevice->OnStatusChange.Add ( this, (FBCallback) &ORDeviceVideoLayout::EventDeviceStatusChange );
EventDeviceStatusChange( NULL, NULL );
return true;
}
/************************************************
* FiLMBOX destructor.
************************************************/
void ORDeviceVideoLayout::FBDestroy()
{
mSystem.OnUIIdle.Remove ( this, (FBCallback) &ORDeviceVideoLayout::EventUIIdle );
mDevice->OnStatusChange.Remove ( this, (FBCallback) &ORDeviceVideoLayout::EventDeviceStatusChange );
}
/************************************************
* Create the UI components' regions & set controls
************************************************/
void ORDeviceVideoLayout::UICreate()
{
int lS = 4;
int lH = 25;
AddRegion( "TabPanel", "TabPanel",
0, kFBAttachLeft, "", 1.0,
0, kFBAttachTop, "", 1.0,
0, kFBAttachRight, "", 1.0,
lH, kFBAttachNone, NULL, 1.0 );
AddRegion( "MainLayout", "MainLayout",
lS, kFBAttachLeft, "TabPanel", 1.0,
lS, kFBAttachBottom, "TabPanel", 1.0,
-lS, kFBAttachRight, "", 1.0,
-lS, kFBAttachBottom, "", 1.0 );
SetControl( "TabPanel", mTabPanel );
SetControl( "MainLayout", mLayout0 );
UICreateLayout0();
UICreateLayout1();
}
void ORDeviceVideoLayout::UICreateLayout0()
{
int lH = 18;
int lW = 200;
int lS = 4;
mLayout0.AddRegion( "SpreadPlaylist", "SpreadPlaylist",
lS, kFBAttachLeft, "", 1.0,
lS, kFBAttachTop, "", 1.0,
460, kFBAttachNone, NULL, 1.0,
-lS, kFBAttachBottom, "", 1.0 );
mLayout0.AddRegion( "ListExistingMedia", "ListExistingMedia",
lS, kFBAttachRight, "SpreadPlaylist", 1.0,
lS, kFBAttachTop, "", 1.0,
lW, kFBAttachNone, NULL, 1.0,
-(3*lS+2*lH), kFBAttachBottom, "", 1.0 );
mLayout0.AddRegion( "ButtonAddItem", "ButtonAddItem",
0, kFBAttachLeft, "ListExistingMedia", 1.0,
lS, kFBAttachBottom, "ListExistingMedia", 1.0,
-(lS/2), kFBAttachWidth, "ListExistingMedia", 0.5,
lH, kFBAttachNone, NULL, 1.0 );
mLayout0.AddRegion( "ButtonRemoveItem", "ButtonRemoveItem",
lS, kFBAttachRight, "ButtonAddItem", 1.0,
0, kFBAttachTop, "ButtonAddItem", 1.0,
0, kFBAttachRight, "ListExistingMedia", 1.0,
0, kFBAttachHeight, "ButtonAddItem", 1.0);
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",
lS, kFBAttachLeft, "", 1.0,
lS, kFBAttachTop, "", 1.0,
lW, kFBAttachNone, NULL, 1.0,
lH, kFBAttachNone, NULL, 1.0 );
mLayout1.AddRegion( "ButtonLoop", "ButtonLoop",
0, kFBAttachLeft, "ListPlaybackType", 1.0,
lS, kFBAttachBottom, "ListPlaybackType", 1.0,
0, kFBAttachWidth, "ListPlaybackType", 1.0,
0, kFBAttachHeight, "ListPlaybackType", 1.0 );
mLayout1.SetControl( "ListPlaybackType", mListPlaybackType );
mLayout1.SetControl( "ButtonLoop", mButtonLoop );
}
/************************************************
* Configure the UI elements.
************************************************/
void ORDeviceVideoLayout::UIConfigure()
{
SetBorder ("MainLayout", kFBStandardBorder, false,true, 1, 0,90,0);
mTabPanel.Items.SetString( "PlayList~Configuration~View" );
mTabPanel.OnChange.Add( this, (FBCallback) &ORDeviceVideoLayout::EventTabPanelChange );
UIConfigureLayout0();
UIConfigureLayout1();
}
void ORDeviceVideoLayout::UIConfigureLayout0()
{
// Configure borders
SetBorder ("SpreadPlaylist", kFBEmbossBorder, false,true, 2, 0,90,0);
// Configure UI
mButtonAddItem.Caption = "Add entry";
mButtonRemoveItem.Caption = "Remove entry";
mListExistingMedia.Style = kFBVerticalList;
// Add callbacks
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.Style = kFB2States;
mButtonLoop.Caption = "Loop";
mButtonLoop.OnClick.Add( this, (FBCallback)&ORDeviceVideoLayout::EventButtonLoopClick );
}
/************************************************
* Reset the UI elements from the device.
************************************************/
void ORDeviceVideoLayout::UIReset()
{
UIResetLayout0();
UIResetLayout1();
}
void ORDeviceVideoLayout::UIResetLayout0()
{
int i;
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;
int i;
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;
// Add columns
mSpreadPlaylist.ColumnAdd( "Label", 0 );
mSpreadPlaylist.GetColumn(0).Width = 100;
mSpreadPlaylist.GetColumn(0).ReadOnly = false;
mSpreadPlaylist.GetColumn(0).Style = kFBCellStyleString;
mSpreadPlaylist.ColumnAdd( "File", 1 );
mSpreadPlaylist.GetColumn(1).Width = 100;
mSpreadPlaylist.GetColumn(1).ReadOnly = true;
mSpreadPlaylist.GetColumn(1).Style = kFBCellStyleString;
mSpreadPlaylist.ColumnAdd( "Frames", 2 );
mSpreadPlaylist.GetColumn(2).Width = 50;
mSpreadPlaylist.GetColumn(2).ReadOnly = true;
mSpreadPlaylist.GetColumn(2).Style = kFBCellStyleInteger;
mSpreadPlaylist.ColumnAdd( "Length", 3 );
mSpreadPlaylist.GetColumn(3).Width = 75;
mSpreadPlaylist.GetColumn(3).ReadOnly = true;
mSpreadPlaylist.GetColumn(3).Style = kFBCellStyleString;
mSpreadPlaylist.ColumnAdd( "Play Count", 4 );
mSpreadPlaylist.GetColumn(4).Width = 50;
mSpreadPlaylist.GetColumn(4).ReadOnly = false;
mSpreadPlaylist.GetColumn(4).Style = kFBCellStyleInteger;
// Configure columns
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 );
}
}
/************************************************
* Refresh the UI elements on idle.
************************************************/
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()
{
}
/************************************************
* UI Idle event.
************************************************/
void ORDeviceVideoLayout::EventUIIdle( HISender pSender, HKEvent pEvent )
{
UIRefresh();
}
/************************************************
* UI Idle event.
************************************************/
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;
}
}
/************************************************
* Play list drag and drop callback.
************************************************/
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;
}
}
/************************************************
* Play list drag and drop callback.
************************************************/
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( IQ(lVideo->GetHIObject(),IKVideoSwitcher) )
{
FBMessageBox( "Video Switcher", "Cannot add video switcher to playlist.", "Ok", NULL, NULL );
}
else if(IQ(lVideo->GetHIObject(),IKVideoLive))
{
FBMessageBox( "Video Switcher", "Cannot add video-in to playlist.", "Ok", NULL, NULL );
}
else
*/
{
if( lRow > 0 )
{
ORVideoEntry* lEntry = (ORVideoEntry*) lRow;
lEntry->SetVideo( lVideo );
UIReset();
mSpreadPlaylist.GetRow( lRow ).Selected = true;
}
mListExistingMedia.ItemIndex = -1;
}
}
}
break;
}
}
/************************************************
* Add clip button click.
************************************************/
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;
}
}
/************************************************
* Remove clip button click.
************************************************/
void ORDeviceVideoLayout::EventButtonRemoveItemClick( HISender pSender, HKEvent pEvent )
{
int i;
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;
lEntry = NULL;
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;
}
}
/************************************************
* Media list drag and drop.
************************************************/
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;
}
}
/************************************************
* Existing media change.
************************************************/
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();
}
}
}
}
/************************************************
* Device status change.
************************************************/
void ORDeviceVideoLayout::EventDeviceStatusChange( HISender pSender, HKEvent pEvent )
{
bool lState = ! (bool) mDevice->Online;
mListExistingMedia.Enabled = lState;
mButtonAddItem.Enabled = lState;
mButtonRemoveItem.Enabled = lState;
}
/************************************************
* Playback mode button click callback.
************************************************/
void ORDeviceVideoLayout::EventListPlaybackTypeChange( HISender pSender, HKEvent pEvent )
{
mDevice->SetPlaybackMode( (ORPlaybackMode) mListPlaybackType.Items.GetReferenceAt( mListPlaybackType.ItemIndex ) );
UIResetLayout1();
}
/************************************************
* Loop mode button callback.
************************************************/
void ORDeviceVideoLayout::EventButtonLoopClick( HISender pSender, HKEvent pEvent )
{
mDevice->SetLoopMode( mButtonLoop.State != 0 );
UIResetLayout1();
}