#include "ordevicereclist_layout.h"
#define ORDEVICERECORDLIST__LAYOUT ORDeviceRecordListLayout
ORDEVICERECORDLIST__CLASSSTR,
bool ORDeviceRecordListLayout::FBCreate()
{
mDevice = ((ORDeviceRecordList *)(FBDevice *)Device);
UICreate ();
UIConfigure ();
UIReset ();
mDevice->OnStatusChange.Add (
this,(
FBCallback) &ORDeviceRecordListLayout::EventDeviceStatusChange );
mSystem.OnUIIdle.Add (
this,(
FBCallback) &ORDeviceRecordListLayout::EventUIIdle );
return true;
}
void ORDeviceRecordListLayout::FBDestroy()
{
mSystem.OnUIIdle.Remove (
this,(
FBCallback) &ORDeviceRecordListLayout::EventUIIdle );
mDevice->OnStatusChange.Remove (
this,(
FBCallback) &ORDeviceRecordListLayout::EventDeviceStatusChange );
}
void ORDeviceRecordListLayout::UICreate()
{
int lS = 5;
int lH = 25;
AddRegion ("LayoutButtons", "LayoutButtons",
AddRegion( "TabPanel", "TabPanel",
AddRegion( "TabPage", "TabPage",
SetControl( "LayoutButtons", mLayoutButtons );
SetControl( "TabPanel", mTabPanel );
SetControl( "TabPage", mLayoutSpreadTakes );
UICreateLayout0();
UICreateLayout1();
}
void ORDeviceRecordListLayout::UICreateLayout0()
{
int lH = 18;
int lS = 4;
mLayoutButtons.AddRegion ("ButtonLoad", "ButtonLoad",
mLayoutButtons.AddRegion ("ButtonClear", "ButtonClear",
mLayoutButtons.AddRegion ("LabelTakeName", "LabelTakeName",
mLayoutButtons.AddRegion ("LabelTimeLeft", "LabelTimeLeft",
mLayoutButtons.AddRegion ("LabelTiming", "LabelTiming",
mLayoutButtons.AddRegion ("ButtonRecFlag", "ButtonRecFlag",
mLayoutButtons.AddRegion ("ButtonStandBy", "ButtonStandBy",
mLayoutButtons.AddRegion ("ButtonStop", "ButtonStop",
mLayoutButtons.AddRegion ("ButtonPlay", "ButtonPlay",
mLayoutButtons.SetControl( "ButtonLoad", mButtonLoad );
mLayoutButtons.SetControl( "ButtonClear", mButtonClear );
mLayoutButtons.SetControl( "LabelTakeName", mLabelTakeName );
mLayoutButtons.SetControl( "LabelTimeLeft", mLabelTimeLeft );
mLayoutButtons.SetControl( "LabelTiming", mLabelTiming );
mLayoutButtons.SetControl( "ButtonRecFlag", mButtonRecFlag );
mLayoutButtons.SetControl( "ButtonStandBy", mButtonStandBy );
mLayoutButtons.SetControl( "ButtonStop", mButtonStop );
mLayoutButtons.SetControl( "ButtonPlay", mButtonPlay );
}
void ORDeviceRecordListLayout::UICreateLayout1()
{
int lS = 4;
int lH = 18;
int lW = 100;
mLayoutSpreadTakes.AddRegion( "SpreadTakes", "SpreadTakes",
mLayoutAbout.AddRegion( "LabelInformation", "LabelInformation",
mLayoutSpreadTakes.SetControl ( "SpreadTakes", mSpreadTakes );
mLayoutAbout.SetControl ( "LabelInformation", mLabelInformation );
}
void ORDeviceRecordListLayout::UIConfigure()
{
UIConfigureLayout0();
UIConfigureLayout1();
}
void ORDeviceRecordListLayout::UIConfigureLayout0()
{
if(mDevice->GetCurrentTakeIndex() < 0 )
{
mLabelTakeName.Caption = "No Take Selected";
}
else
{
mLabelTakeName.Caption = mDevice->GetListEntry(mDevice->GetCurrentTakeIndex())->mName;
}
mLabelTimeLeft.Caption = "Recording in: --- seconds" ;
mLabelTiming.Caption = "" ;
mButtonLoad.Caption = "Load...";
mButtonStandBy.Caption = "Standby";
mButtonStandBy.State = mDevice->GetStandbyState();
mButtonClear.Caption = "Clear";
mButtonRecFlag.Caption = "Recording";
mButtonRecFlag.State = mDevice->GetRecFlag();
mButtonPlay.Caption = "Play";
mButtonStop.Caption = "Stop";
mButtonLoad.OnClick.Add (
this, (
FBCallback) &ORDeviceRecordListLayout::EventButtonLoadClick );
mButtonStandBy.OnClick.Add (
this, (
FBCallback) &ORDeviceRecordListLayout::EventButtonStandByClick );
mButtonClear.OnClick.Add (
this, (
FBCallback) &ORDeviceRecordListLayout::EventButtonClearClick );
mButtonRecFlag.OnClick.Add (
this, (
FBCallback) &ORDeviceRecordListLayout::EventButtonRecFlagClick );
mButtonPlay.OnClick.Add (
this, (
FBCallback) &ORDeviceRecordListLayout::EventButtonPlayClick );
mButtonStop.OnClick.Add (
this, (
FBCallback) &ORDeviceRecordListLayout::EventButtonStopClick );
}
void ORDeviceRecordListLayout::UIConfigureLayout1()
{
mLabelInformation.Caption = "Information...";
mTabPanel.Items.SetString("Takes~About");
mTabPanel.OnChange.Add (
this,(
FBCallback) &ORDeviceRecordListLayout::EventTabPanelChange );
mSpreadTakes.OnCellChange.Add (
this,(
FBCallback) &ORDeviceRecordListLayout::EventSpreadCellChange );
mSpreadTakes.OnRowClick.Add (
this,(
FBCallback) &ORDeviceRecordListLayout::EventSpreadRowClick );
}
void ORDeviceRecordListLayout::UIReset()
{
UIResetSpreadSheet();
}
void ORDeviceRecordListLayout::UIResetSpreadSheet()
{
mSpreadTakes.Clear();
int lColumnIndex = -1;
mSpreadTakes.GetColumn(lColumnIndex).Width = 140;
mSpreadTakes.ColumnAdd ("No");
lColumnIndex++;
mSpreadTakes.GetColumn(lColumnIndex).Width = 50;
mSpreadTakes.ColumnAdd ("In");
lColumnIndex++;
mSpreadTakes.GetColumn(lColumnIndex).Width = 90;
mSpreadTakes.ColumnAdd ("Out");
lColumnIndex++;
mSpreadTakes.GetColumn(lColumnIndex).Width = 90;
mSpreadTakes.ColumnAdd ("Pre-roll");
lColumnIndex++;
mSpreadTakes.GetColumn(lColumnIndex).Width = 60;
mSpreadTakes.ColumnAdd ("Post-roll");
lColumnIndex++;
mSpreadTakes.GetColumn(lColumnIndex).Width = 60;
for (i=0;i<mDevice->GetListCount();i++)
{
mSpreadTakes.RowAdd( mDevice->GetListEntry(i)->mName,
i );
}
}
void ORDeviceRecordListLayout::UIRefresh()
{
FBTime lTimeLeft;
int lSecondsLeft;
char lBuffer[256];
kLongLong lMS;
if(mDevice->GetStandbyState())
{
if(mDevice->GetCurrentTakeIndex()>=0 && mDevice->GetCurrentTakeIndex() < mDevice->GetListCount())
{
lTimeLeft.SetMilliSeconds(mDevice->GetCurrentStartTime().GetMilliSeconds() - mDevice->GetReferenceTime().GetMilliSeconds());
lMS = lTimeLeft.GetMilliSeconds();
lSecondsLeft = (
int) lMS/1000;
if(mDevice->GetRecFlag())
{
sprintf(lBuffer, "Standby RECORD: %3d sec.", lSecondsLeft);
}
else
{
sprintf(lBuffer, "Standby PLAY: %3d sec.", lSecondsLeft);
}
mLabelTimeLeft.Caption = lBuffer;
}
}
else
{
mLabelTimeLeft.Caption = "<OFF>";
mButtonStandBy.State = 0;
}
sprintf(lBuffer,"%s %s",(const char*)mDevice->GetCurrentStartTime().GetTimeString(),
(const char*)mDevice->GetCurrentStopTime().GetTimeString());
mLabelTiming.Caption = lBuffer;
UIRefreshSpreadSheet();
}
void ORDeviceRecordListLayout::UIRefreshSpreadSheet()
{
for(i=0; i<mDevice->GetListCount();i++)
{
mSpreadTakes.SetCell( i, 0, mDevice->GetListEntry(i)->mTakeNumber );
mSpreadTakes.SetCell( i, 1, mDevice->GetListEntry(i)->mInTime.GetTimeString() );
mSpreadTakes.SetCell( i, 2, mDevice->GetListEntry(i)->mOutTime.GetTimeString() );
mSpreadTakes.SetCell( i, 3, mDevice->GetListEntry(i)->mPreroll );
mSpreadTakes.SetCell( i, 4, mDevice->GetListEntry(i)->mPostroll );
}
}
void ORDeviceRecordListLayout::EventUIIdle(
HISender pSender,
HKEvent pEvent)
{
UIRefresh();
}
void ORDeviceRecordListLayout::EventDeviceStatusChange(
HISender pSender,
HKEvent pEvent)
{
UIReset();
}
void ORDeviceRecordListLayout::EventTabPanelChange(
HISender pSender,
HKEvent pEvent)
{
switch( mTabPanel.ItemIndex )
{
case 0: SetControl("TabPage", mLayoutSpreadTakes ); break;
case 1: SetControl("TabPage", mLayoutAbout ); break;
}
}
void ORDeviceRecordListLayout::EventButtonLoadClick(
HISender pSender,
HKEvent pEvent)
{
FBString lPath( mSystem.ApplicationPath );
FBFilePopup lFilePopup;
lFilePopup.Path = lPath + "\\..\\OpenRealitySDK\\Samples\\devices\\devicereclist\\res";
lFilePopup.Filter = "*.txt";
if( lFilePopup.Execute() )
{
bool lWasOnline = mDevice->Online;
if( lWasOnline )
{
mDevice->DeviceSendCommand( FBDevice::kOpStop );
}
mDevice->LoadFile( lFilePopup.FullFilename );
if(lWasOnline)
{
mDevice->DeviceSendCommand( FBDevice::kOpStart );
}
UIReset();
}
}
void ORDeviceRecordListLayout::EventButtonStandByClick(
HISender pSender,
HKEvent pEvent)
{
int lCurrentTake;
FBString lTakeName;
bool lSuccess;
if( mDevice->GetStandbyState() )
{
mDevice->SetStandbyState(false);
mButtonStandBy.State = 0;
}
else
{
if( mDevice->GetListCount()==0 )
{
mButtonStandBy.State = 0;
}
else
{
lCurrentTake = mDevice->GetCurrentTakeIndex();
if(lCurrentTake<0 || lCurrentTake >= mDevice->GetListCount())
{
mButtonStandBy.State = 0;
}
else
{
FBString lIndexString, lCandidateName;
char lBuffer[32];
int lTakeIndex;
FBString lFBTakeName;
lTakeName = mDevice->GetListEntry(lCurrentTake)->mName;
sprintf(lBuffer,"_%d",mDevice->GetListEntry(lCurrentTake)->mTakeNumber);
lIndexString = lBuffer;
lCandidateName = lTakeName;
lCandidateName += lIndexString;
lTakeIndex = -1;
for(int i=0; i < mSystem.Scene->Takes.GetCount(); i++)
{
lFBTakeName = mSystem.Scene->Takes[
i]->Name;
if(lFBTakeName == lCandidateName)
{
break;
}
}
if( mDevice->GetRecFlag() )
{
if( lTakeIndex == -1 )
{
lSuccess = mDevice->CreateNewTake( lCandidateName );
}
else
{
int lRetVal;
char lBuffer2[256];
sprintf(lBuffer2, "%s exists...", (char*)lCandidateName );
lRetVal =
FBMessageBox(
"Warning",lBuffer2,
"Overwrite",
"New",
"Cancel", 0);
switch( lRetVal)
{
case 1:
{
lSuccess = mDevice->ChangeTake((char *)lCandidateName);
}
break;
case 2:
{
mDevice->GetListEntry(lCurrentTake)->mTakeNumber++;
sprintf(lBuffer2,"_%d",mDevice->GetListEntry(lCurrentTake)->mTakeNumber);
lIndexString = lBuffer2;
lCandidateName = lTakeName;
lCandidateName += lIndexString;
lSuccess = mDevice->CreateNewTake((char *)lCandidateName);
}
break;
default:
{
return;
}
}
}
if(! mDevice->PrepareToRecord() )
{
mButtonStandBy.State = 0;
return;
}
}
else
{
if(lTakeIndex == -1)
{
mButtonStandBy.State = 0;
return;
}
else
{
lSuccess = mDevice->ChangeTake((char *)lCandidateName);
}
lSuccess = mDevice->PrepareToPlay();
}
mDevice->SetStandbyState(true);
mButtonStandBy.State = 1;
}
}
}
}
void ORDeviceRecordListLayout::EventButtonPlayClick(
HISender pSender,
HKEvent pEvent)
{
mDevice->Play();
}
void ORDeviceRecordListLayout::EventButtonClearClick(
HISender pSender,
HKEvent pEvent)
{
mDevice->ClearList();
UIReset();
}
void ORDeviceRecordListLayout::EventButtonStopClick(
HISender pSender,
HKEvent pEvent)
{
mDevice->Stop();
}
void ORDeviceRecordListLayout::EventButtonRecFlagClick(
HISender pSender,
HKEvent pEvent)
{
mDevice->SetRecFlag( mButtonRecFlag.State != 0 );
}
void ORDeviceRecordListLayout::EventSpreadCellChange(
HISender pSender,
HKEvent pEvent)
{
FBEventSpread lSpreadEvent(pEvent);
int lRow = lSpreadEvent.Row;
int lColumn = lSpreadEvent.Column;
int lVal;
const char* lBuffer;
switch (lColumn)
{
case 0:
{
mSpreadTakes.GetCell( lRow, lColumn, lVal );
mDevice->GetListEntry( lRow )->mTakeNumber = lVal;
}
break;
case 1:
{
mSpreadTakes.GetCell( lRow, lColumn, lBuffer );
mDevice->GetListEntry( lRow )->mInTime.SetTimeString( lBuffer );
}
break;
case 2:
{
mSpreadTakes.GetCell( lRow, lColumn, lBuffer );
mDevice->GetListEntry( lRow )->mOutTime.SetTimeString( lBuffer );
}
case 3:
{
mSpreadTakes.GetCell( lRow, lColumn, lVal );
mDevice->GetListEntry( lRow )->mPreroll = lVal;
}
break;
case 4:
{
mSpreadTakes.GetCell( lRow, lColumn, lVal );
mDevice->GetListEntry( lRow )->mPostroll = lVal;
}
break;
}
if( lColumn >= 0 && lColumn <= 4)
{
UIRefreshSpreadSheet();
}
}
void ORDeviceRecordListLayout::EventSpreadRowClick(
HISender pSender,
HKEvent pEvent)
{
FBEventSpread Event(pEvent);
mDevice->SetCurrentTakeIndex(Event.Row);
if(mDevice->GetCurrentTakeIndex() < 0 )
{
mLabelTakeName.Caption = "No Take Selected";
}
else
{
mLabelTakeName.Caption = mDevice->GetListEntry(mDevice->GetCurrentTakeIndex())->mName;
}
}