#include "ortoolnote_tool.h"
#define ORTOOLNOTE__CLASS ORTOOLNOTE__CLASSNAME
#define ORTOOLNOTE__LABEL "Note"
#define ORTOOLNOTE__DESC "OR - Note Description"
ORTOOLNOTE__LABEL,
ORTOOLNOTE__DESC,
bool ORToolNote::FBCreate()
{
StartSize[0] = 600;
StartSize[1] = 300;
UICreate ();
UIConfigure ();
((FBScene*)mSystem.Scene)->OnChange.Add(
this, (
FBCallback) &ORToolNote::EventSceneChange );
OnIdle.Add(
this, (
FBCallback) &ORToolNote::EventToolIdle );
return true;
}
void ORToolNote::FBDestroy()
{
((FBScene*)mSystem.Scene)->OnChange.Remove(
this, (
FBCallback) &ORToolNote::EventSceneChange );
OnIdle.Remove(
this, (
FBCallback) &ORToolNote::EventToolIdle );
}
void ORToolNote::UICreate()
{
int lS = 4;
AddRegion("TabPanel","TabPanel",
AddRegion("Layout", "Layout",
SetControl( "TabPanel", mTabPanel );
SetControl( "Layout", mLayoutNote );
UICreateLayoutNote();
UICreateLayoutNoteProperties();
}
void ORToolNote::UICreateLayoutNote()
{
int lH = 22;
int lS = 4;
mLayoutNote.AddRegion( "LabelNotes", "LabelNotes",
mLayoutNote.AddRegion( "ListNotes", "ListNotes",
mLayoutNote.AddRegion( "LabelDescription", "LabelDescription",
mLayoutNote.AddRegion( "ContainerNote", "ContainerNote",
mLayoutNote.AddRegion( "ButtonCreate", "ButtonCreate",
mLayoutNote.AddRegion( "ButtonAttach", "ButtonAttach",
mLayoutNote.AddRegion( "ButtonDetach", "ButtonDetach",
mLayoutNote.AddRegion( "ButtonDestroy", "ButtonDestroy",
mLayoutNote.SetControl( "LabelNotes", mLabelNotes );
mLayoutNote.SetControl( "ListNotes", mListNotes );
mLayoutNote.SetControl( "LabelDescription", mLabelDescription );
mLayoutNote.SetControl( "ContainerNote", mContainerNote );
mLayoutNote.SetControl( "ButtonCreate", mButtonCreateNote );
mLayoutNote.SetControl( "ButtonAttach", mButtonAttachNote );
mLayoutNote.SetControl( "ButtonDetach", mButtonDetachNote );
mLayoutNote.SetControl( "ButtonDestroy", mButtonDestroyNote );
}
void ORToolNote::UICreateLayoutNoteProperties()
{
mLayoutNoteProperties.AddRegion( "ButtonAdd", "ButtonAdd",
mLayoutNoteProperties.AddRegion( "ButtonRemove", "ButtonRemove",
mLayoutNoteProperties.AddRegion( "ButtonList", "ButtonList",
mLayoutNoteProperties.AddRegion( "ListProperties", "ListProperties",
mLayoutNoteProperties.SetControl( "ButtonAdd", mButtonAddProperty );
mLayoutNoteProperties.SetControl( "ButtonRemove", mButtonRemoveProperty );
mLayoutNoteProperties.SetControl( "ButtonList", mButtonListKeys );
mLayoutNoteProperties.SetControl( "ListProperties", mListProperties );
}
void ORToolNote::UIConfigure()
{
mTabPanel.Items.SetString("Note~Note Custom Properties");
mTabPanel.OnChange.Add(
this, (
FBCallback) &ORToolNote::EventTabPanelChange );
UIConfigureLayoutNote();
UIConfigureLayoutNoteProperties();
}
void ORToolNote::UIConfigureLayoutNote()
{
mLabelDescription.Caption = "Current note (drag)";
mLabelNotes.Caption = "Notes in the scene";
mButtonCreateNote. Caption = FBString( BUTTON_CAPTIONS[kOpCreateNote] );
mButtonAttachNote. Caption = FBString( BUTTON_CAPTIONS[kOpAttachNote] );
mButtonDetachNote. Caption = FBString( BUTTON_CAPTIONS[kOpDetachNote] );
mButtonDestroyNote.Caption = FBString( BUTTON_CAPTIONS[kOpDestroyNote] );
mButtonCreateNote. OnClick.Add(
this, (
FBCallback) &ORToolNote::EventCreateNote );
mButtonAttachNote. OnClick.Add(
this, (
FBCallback) &ORToolNote::EventAttachNote );
mButtonDetachNote. OnClick.Add(
this, (
FBCallback) &ORToolNote::EventDetachNote );
mButtonDestroyNote.OnClick.Add(
this, (
FBCallback) &ORToolNote::EventDestroyNote );
mContainerNote.OnDragAndDrop.Add(
this, (
FBCallback) &ORToolNote::EventNoteDragAndDrop );
mContainerNote.OnDblClick.Add (
this, (
FBCallback) &ORToolNote::EventContainerNoteDblClick );
mNotesCount = 0;
}
void ORToolNote::UIConfigureLayoutNoteProperties()
{
mButtonAddProperty.Caption = "Add Property...";
mButtonRemoveProperty.Caption = "Remove Property";
mButtonListKeys.Caption = "List Keys";
mButtonAddProperty.OnClick.Add(
this, (
FBCallback) &ORToolNote::EventAddProperty );
mButtonRemoveProperty.OnClick.Add(
this, (
FBCallback) &ORToolNote::EventRemoveProperty );
mButtonListKeys.OnClick.Add(
this, (
FBCallback) &ORToolNote::EventListKeys );
}
void ORToolNote::UIEnable()
{
bool lEnable = mHdlCurrentNote.Ok();
mButtonAttachNote.Enabled = lEnable;
mButtonDetachNote.Enabled = lEnable;
mButtonDestroyNote.Enabled = lEnable;
mButtonAddProperty.Enabled = lEnable;
mButtonRemoveProperty.Enabled = lEnable;
mButtonListKeys.Enabled = lEnable;
if( !lEnable )
{
mListProperties.Items.Clear();
}
}
void ORToolNote::SetCurrentNote( FBNote* pNote )
{
mHdlCurrentNote = pNote;
mContainerNote.Items.Clear();
mListProperties.Items.Clear();
if( mHdlCurrentNote.Ok() )
{
mContainerNote.Items.Add( mHdlCurrentNote->Name, (kReference)mHdlCurrentNote.GetPlug() );
UpdatePropertyList();
}
UIEnable();
}
{
FBEventSceneChange lEvent( pEvent );
switch( lEvent.Type )
{
{
FBComponent* lChildComp = (FBComponent*)lEvent.ChildComponent;
FBNote* lNote = (lChildComp && lChildComp->Is( FBNote::TypeInfo )) ? (FBNote*)lChildComp :
NULL;
if( lNote && mHdlCurrentNote() == lNote )
}
break;
}
}
{
UpdateNoteList();
}
{
switch( mTabPanel.ItemIndex )
{
case 0: SetControl( "Layout", mLayoutNote ); break;
case 1: SetControl( "Layout", mLayoutNoteProperties ); UpdatePropertyList(); break;
}
}
class FBPropertyAddDlg : public FBPopup
{
public:
FBPropertyAddDlg()
{
int lS = 10;
Region.X = 300;
Region.Y = 300;
Region.Width = 250;
Region.Height = 100;
AddRegion(
"LabelName",
"LabelName", lS,
kFBAttachLeft,
"", 1.0, lS,
kFBAttachTop,
"", 1.0, 40,
kFBAttachNone,
"", 1.0, 20,
kFBAttachNone,
"", 1.0 );
AddRegion(
"EditName",
"EditName", lS,
kFBAttachRight,
"LabelName", 1.0, 0,
kFBAttachTop,
"LabelName", 1.0, -lS,
kFBAttachRight,
"", 1.0, 20,
kFBAttachNone,
"", 1.0 );
AddRegion(
"LabelType",
"LabelType", 0,
kFBAttachLeft,
"LabelName", 1.0, lS,
kFBAttachBottom,
"LabelName", 1.0, 0,
kFBAttachWidth,
"LabelName", 1.0, 0,
kFBAttachHeight,
"LabelName", 1.0 );
AddRegion(
"ListType",
"ListType", lS,
kFBAttachRight,
"LabelType", 1.0, 0,
kFBAttachTop,
"LabelType", 1.0, -lS,
kFBAttachRight,
"", 1.0, 20,
kFBAttachNone,
"", 1.0 );
AddRegion(
"ButtonOk",
"ButtonOk", lS,
kFBAttachLeft,
"", 1.0, lS,
kFBAttachBottom,
"LabelType", 1.0, 100,
kFBAttachNone,
"", 1.0, 20,
kFBAttachNone,
"", 1.0 );
AddRegion(
"ButtonCancel",
"ButtonCancel", -100-lS,
kFBAttachRight,
"", 1.0, lS,
kFBAttachBottom,
"LabelType", 1.0, 100,
kFBAttachNone,
"", 1.0, 20,
kFBAttachNone,
"", 1.0 );
SetControl( "LabelName", mLabelName );
SetControl( "LabelType", mLabelType );
SetControl( "EditName", mEditName );
SetControl( "ListType", mListType );
SetControl( "ButtonOk", mButtonOk );
SetControl( "ButtonCancel", mButtonCancel );
Caption = "Add Note Property";
Modal = true;
mLabelName.Caption = "Name";
mLabelType.Caption = "Type";
mButtonOk.Caption = "Ok";
mButtonCancel.Caption = "Cancel";
mButtonOk.OnClick.Add(
this, (
FBCallback) &FBPropertyAddDlg::EventButtonOkClick );
mButtonCancel.OnClick.Add(
this, (
FBCallback) &FBPropertyAddDlg::EventButtonCancelClick );
}
protected:
{
mPropertyType = mListType.Items[ mListType.ItemIndex ];
mPropertyName = mEditName.Text;
Close(true);
}
{
Close();
}
public:
FBString mPropertyType;
FBString mPropertyName;
private:
FBLabel mLabelName;
FBLabel mLabelType;
FBEdit mEditName;
FBList mListType;
FBButton mButtonOk;
FBButton mButtonCancel;
};
{
FBPropertyAddDlg lAddDlg;
if( lAddDlg.Show() )
{
mHdlCurrentNote->AnimationNodeInCreate( 0, lAddDlg.mPropertyName, lAddDlg.mPropertyType,
true,
NULL,
NULL,
true );
UpdatePropertyList();
}
}
{
if( mListProperties.ItemIndex != -1 ) {
FBAnimationNode* lNode = (FBAnimationNode*)mListProperties.Items.GetReferenceAt( mListProperties.ItemIndex );
mHdlCurrentNote->AnimationNodeDestroy( lNode );
UpdatePropertyList();
}
}
{
if( mListProperties.ItemIndex != -1 ) {
FBAnimationNode* lNode = (FBAnimationNode*)mListProperties.Items.GetReferenceAt( mListProperties.ItemIndex );
if( lNode ) {
static char lTmp[1024];
FBString lMessage( "Keys:" );
FBFCurve* lFCurve = lNode->FCurve;
int lIdx = 0;
for( ; lIdx < lFCurve->Keys.GetCount(); ++lIdx ) {
FBTime lTime( lFCurve->Keys[lIdx].Time );
sprintf( lTmp, "\n %ld: %f", lTime.GetFrame(), (double)lFCurve->Keys[lIdx].Value );
lMessage += lTmp;
}
}
else {
FBMessageBox(
"List Keys",
"The selected property does not possess any keys.",
"OK", 0, 0 );
}
}
else {
FBMessageBox(
"List Keys",
"No property selected.",
"OK", 0, 0 );
}
}
{
FBEventDragAndDrop lDragAndDrop( pEvent );
switch( lDragAndDrop.State )
{
{
lDragAndDrop.Accept();
}
break;
{
FBComponent* lComponent = lDragAndDrop.Get(0);
if( lComponent && lComponent->Is( FBNote::TypeInfo ) )
SetCurrentNote( (FBNote*)lComponent );
}
break;
}
}
{
}
{
FBNote* lNote = new FBNote( "My Note" );
lNote->FBCreate();
lNote->Attach();
SetCurrentNote( lNote );
}
{
if( !mHdlCurrentNote.Ok() )
return;
FBScene* lScene = mSystem.Scene;
int lCnt = lScene->Components.GetCount();
for( i=0; i<lCnt; i++ )
{
AddNoteToSelected( lScene->Components[i] );
}
AddNoteToSelected( mSystem.Renderer );
lCnt = mSystem.Manipulators.GetCount();
for( i=0; i<lCnt; i++ )
{
AddNoteToSelected( mSystem.Manipulators[i] );
}
for( i=0; i<lCnt; i++ )
{
if( !lComp->Is(FBNote::TypeInfo) )
{
AddNoteToSelected( lComp );
}
}
}
void ORToolNote::AddNoteToSelected( FBComponent* pComp )
{
if( !pComp || !mHdlCurrentNote.Ok() || pComp->Is(FBNote::TypeInfo) )
return;
if( pComp->Selected )
mHdlCurrentNote->Attach( pComp );
int lCnt = pComp->Components.GetCount();
for( i=0; i<lCnt; i++ )
{
FBComponent* lComp = pComp->Components[
i];
AddNoteToSelected( lComp );
}
}
{
if( !mHdlCurrentNote.Ok() )
return;
FBScene* lScene = mSystem.Scene;
int lCnt = lScene->Components.GetCount();
for( i=0; i<lCnt; i++ )
{
DetachNoteFromSelected( lScene->Components[i] );
}
lCnt = 1;
for( i=0; i < lCnt; i++ )
{
DetachNoteFromSelected( mSystem.Renderer );
}
lCnt = mSystem.Manipulators.GetCount();
for( i=0; i<lCnt; i++ )
{
DetachNoteFromSelected( mSystem.Manipulators[i] );
}
for( i=0; i<lCnt; i++ )
{
if( !lComp->Is(FBNote::TypeInfo) )
{
DetachNoteFromSelected( lComp );
}
}
}
void ORToolNote::DetachNoteFromSelected( FBComponent* pComp )
{
if( !pComp || !mHdlCurrentNote.Ok() )
return;
if( pComp->Selected )
mHdlCurrentNote->Detach( pComp );
int lCnt = pComp->Components.GetCount();
for( i=0; i<lCnt; i++ )
{
FBComponent* lComp = pComp->Components[
i];
DetachNoteFromSelected( lComp );
}
}
{
if( mHdlCurrentNote.Ok() )
{
mHdlCurrentNote->Selected = false;
mHdlCurrentNote->FBDelete();
}
}
void WalkNodes( FBAnimationNode* pNode, int lIndent = 0 )
{
if( pNode )
{
char lMsg[128];
FBFCurve* lCurve = pNode->FCurve;
sprintf( lMsg, "%*sNode: '%s': %d/%d keys\n", lIndent, " ", (const char*)pNode->Name, (int)pNode->KeyCount, lCurve ? lCurve->Keys.GetCount() : -1 );
int pIdx;
for( pIdx = 0; pIdx < pNode->Nodes.GetCount(); ++pIdx )
{
WalkNodes( pNode->Nodes[pIdx], lIndent + 2 );
}
}
}
void ORToolNote::UpdatePropertyList()
{
if( mHdlCurrentNote.Ok() )
{
mListProperties.Items.Clear();
int lCount = mHdlCurrentNote->PropertyList.GetCount();
int lIdx = 0;
for( ; lIdx < lCount; ++lIdx )
{
FBProperty* lProperty = mHdlCurrentNote->PropertyList[lIdx];
if (lProperty->IsAnimatable())
{
FBPropertyAnimatable* lAnimatableProperty = (FBPropertyAnimatable*)lProperty;
lAnimatableProperty->SetAnimated( true );
FBAnimationNode* lNode = lAnimatableProperty->GetAnimationNode();
FBString lPropName( lProperty->GetName() );
mListProperties.Items.Add( lPropName, (kReference)lNode );
}
}
}
}
void ORToolNote::UpdateNoteList()
{
FBScene* lScene = (FBScene*)mSystem.Scene;
int lCount = lScene->Notes.GetCount();
for( int i = 0; i < lCount; i++ )
{
if( i >= mNotesCount )
{
mListNotes.Items.Add( lScene->Notes[i]->Name );
mNotesCount++;
}
else
{
if( strcmp( mListNotes.Items[i], lScene->Notes[i]->Name ) != 0 )
mListNotes.Items.SetAt( i, lScene->Notes[i]->Name );
}
}
while( mNotesCount != lCount )
{
mListNotes.Items.RemoveAt( --mNotesCount );
}
}