static void tree_callback( Fl_Widget* w, void* )
{
  Flu_Tree_Browser *t = (Flu_Tree_Browser*)w;

  int reason = t->callback_reason();
  Flu_Tree_Browser::Node *n = t->callback_node();

  if( tree->num_selected() )
    deleteNode->activate();
  else
    deleteNode->deactivate();

  switch( reason )
    {
    case FLU_HILIGHTED:
      printf( "%s hilighted\n", n->label() );
      break;

    case FLU_UNHILIGHTED:
      printf( "%s unhilighted\n", n->label() );
      break;

    case FLU_SELECTED:
      printf( "%s selected\n", n->label() );
      break;

    case FLU_UNSELECTED:
      printf( "%s unselected\n", n->label() );
      break;

    case FLU_OPENED:
      printf( "%s opened\n", n->label() );
      break;

    case FLU_CLOSED:
      printf( "%s closed\n", n->label() );
      break;

    case FLU_DOUBLE_CLICK:
      printf( "%s double-clicked\n", n->label() );
      break;

    case FLU_WIDGET_CALLBACK:
      printf( "%s widget callback\n", n->label() );
      break;

    case FLU_MOVED_NODE:
      printf( "%s moved\n", n->label() );
      break;

    case FLU_NEW_NODE:
      printf( "node '%s' added to the tree\n", n->label() );
      break;
    }
}
void makeTree()
{
  Flu_Tree_Browser::Node* n;

  // set the default leaf icon to be a blue dot
  tree->leaf_icon( &blue_dot );

  tree->clear();
  tree->label( "Tree Browser Demo" );
  //tree->select_under_mouse( true );

  n = tree->get_root();
  if( n ) n->branch_icons( &computer, &computer );

  //tree->move_only_same_group( true );

  /*
  char buf[32];
  for( int i = 0; i < 1000; i++ )
    {
      sprintf( buf, "%d", i );
      tree->add( "/", buf );
    }
  return;
  */

  n = tree->add( "/Customizable Icons!" );
  if( n ) n->leaf_icon( &red_dot );
  n = tree->add( "Text Entries!" );
  if( n ) n->leaf_icon( NULL );
  tree->add( "Identical Entries!" );
  tree->add( "Identical Entries!" );
  //n = tree->add( "/widgets!/" );
  n = tree->add_branch( "/widgets!" );
  n->always_open( true );
  //n->branch_icon( NULL );
  tree->add_branch( "two" );
  n = tree->add( "/widgets!/text item" );
  if( n ) n->leaf_icon( &text_doc );
  tree->add( "two/four" );
  n = tree->add( "/folders/six/123", "eight" );
  if( n ) n->leaf_icon( &green_dot );
  tree->add_leaf( "/folders/six/abc/" );
  tree->add( "/folders/six/seven/" );
  tree->add_leaf( "/uuu" );
  tree->add( "/folders/zilch/" );
  n = tree->find( "/folders" );
  if( n ) n->collapse_icons( &arrow_closed, &arrow_open );
  n = tree->add( "/branches/ten/eleven" );
  printf( "Path %s\n", tree->find_path( n ) );
  tree->add( "/two/this\\/that" ); // use the escape character for '/' (have to use \\ since the compiler automatically does escape replacement in strings)
  n = tree->add( "/zoom/" );
  if( n ) n->branch_icons( &cd_drive, &cd_drive );
  tree->add( "zoom", "zurb" );
  tree->add( "zoom", "zoom" );

  tree->open( true );

  // test the depth-first traversal interface
  /*
  printf( "----------------\n" );
  n = tree->last();//tree->first();
  while( n )
    {
      printf( "%s\n", n->label() );
      n = n->previous();//n->next();
    }
  */

  //return;

  Fl_Input *i = new Fl_Input( 0, 0, 100, 20 );
  tree->add( "/input/", i );

  Fl_Choice *c = new Fl_Choice( 0, 0, 100, 20 );
  c->add( "one" );
  c->add( "two" );
  c->add( "three" );
  c->add( "four" );
  c->value( 0 );
  n = tree->add( "/widgets!/choice", c );
  if( n ) n->expand_to_width( true );

  tree->leaf_icon( NULL );

  Fl_Button *b = new Fl_Button( 0, 0, 100, 20, "Button" );
  b->callback( button_callback );
  tree->add( "/widgets!/Button", b, false );
  printf( "Path %s\n", tree->find_path( b ) );

  {
    Fl_Check_Button *c = new Fl_Check_Button( 0, 0, 80, 20, "Check 1" );
    n = tree->add( "/widgets!/Check1", c, false );
    n->auto_label_color( true );
    c = new Fl_Check_Button( 0, 0, 80, 20, "Check 2" );
    n = tree->add( "/widgets!/Check2", c, true );
    n->auto_label_color( true );
    c = new Fl_Check_Button( 0, 0, 80, 20, "Check 3" );
    n = tree->add( "/widgets!/Check3", c, true );
    n->swap_label_and_widget( true );
    n->auto_label_color( true );
  }

  {
    Fl_Round_Button *r = new Fl_Round_Button( 0, 0, 70, 20, "Radio 1" );
    r->type( FL_RADIO_BUTTON );
    n = tree->add( "/widgets!/Radio1", r, false );
    n->auto_label_color( true );
    r = new Fl_Round_Button( 0, 0, 70, 20, "Radio 2" );
    r->type( FL_RADIO_BUTTON );
    n = tree->add( "/widgets!/Radio2", r, false );
    n->auto_label_color( true );
    r = new Fl_Round_Button( 0, 0, 70, 20, "Radio 3" );
    r->type( FL_RADIO_BUTTON );
    n = tree->add( "/widgets!/Radio3", r, false );
    n->auto_label_color( true );
    n->leaf_icon( &red_dot );
    n->icon_at_end( true );
  }

  {
    Fl_Round_Button *r = new Fl_Round_Button( 0, 0, 70, 20, "Radio 1" );
    r->type( FL_RADIO_BUTTON );
    n = tree->add( "/usr/Radio1", r, false );
    n->auto_label_color( true );
    r = new Fl_Round_Button( 0, 0, 70, 20, "Radio 2" );
    r->type( FL_RADIO_BUTTON );
    n->auto_label_color( true );
    n = tree->add( "/usr/Radio2", r, false );
    r = new Fl_Round_Button( 0, 0, 70, 20, "Radio 3" );
    r->type( FL_RADIO_BUTTON );
    n->auto_label_color( true );
    n = tree->add( "/usr/Radio3", r, false );
  }

  tree->add( "/usr/bin/foo" );
  tree->add( "/bin/foo" );
  tree->add( "/usr" );  // this should fail since there is already a branch called "usr"

  // disable the branch icons for this entry
  n = tree->find( "/usr" );
  if( n )
    n->branch_icons( 0, 0 );

  // test the find_next() interface
  /*
  printf( "%d\n", tree->find_number( "Identical Entries!" ) );
  n = tree->find( "Identical Entries!" );
  printf( "%d %d\n", n->id(), tree->find_next( "Identical Entries!", n )->id() );
  n = tree->find_next( "Identical Entries!", n );
  printf( "removed: %d\n", tree->remove( n ) );
  */

  //n = tree->find( "bin" );
  //if( n )
  //n->label( "New" );

  // find the absolute path of the node with unique ID = 10
  //printf( "%s\n", tree->find_path( 10 ) );

  // find the choice widget and deactivate it
  /*
  n = tree->find( c );
  if( n )
  n->deactivate();
  */

  tree->redraw();
}
예제 #3
0
void tree_callback( Fl_Widget* w, void *_gui )
{
	Flu_Tree_Browser *t = (Flu_Tree_Browser*)w;
	int reason = t->callback_reason();
	GUI *gui = (GUI *)_gui;
	
	Flu_Tree_Browser::Node *n = t->callback_node();

	Matrix4f &transform = gui->MVC->SelectedNodeMatrix();
	Vector3f translate = transform.getTranslation();
	RFO_Object *selectedObject=0;
	RFO_File *selectedFile=0;
	gui->MVC->GetSelectedRFO(&selectedObject, &selectedFile);

	switch( reason )
	{
	case FLU_HILIGHTED:
		printf( "%s hilighted\n", n->label() );
		break;

	case FLU_UNHILIGHTED:
		printf( "%s unhilighted\n", n->label() );
		break;

	case FLU_SELECTED:
		gui->TranslateX->value(translate.x);
		gui->TranslateY->value(translate.y);
		gui->TranslateZ->value(translate.z);

		if(selectedObject)
			gui->ObjectNameInput->value(selectedObject->name.c_str());
		else
			gui->ObjectNameInput->value("no selection");
		if(selectedFile)
		{
			gui->FileLocationInput->value(selectedFile->location.c_str());
			gui->FileTypeInput->value(selectedFile->filetype.c_str());
			gui->FileMaterialInput->value(selectedFile->material.c_str());
		}
		else
		{
			gui->FileLocationInput->value("no file selected");
			gui->FileTypeInput->value("no file selected");
			gui->FileMaterialInput->value("no file selected");
		}

		printf( "%s selected\n", n->label() );
		//transform
		break;

	case FLU_UNSELECTED:
		printf( "%s unselected\n", n->label() );
		break;

	case FLU_OPENED:
		printf( "%s opened\n", n->label() );
		break;

	case FLU_CLOSED:
		printf( "%s closed\n", n->label() );
		break;

	case FLU_DOUBLE_CLICK:
		printf( "%s double-clicked\n", n->label() );
		break;

	case FLU_WIDGET_CALLBACK:
		printf( "%s widget callback\n", n->label() );
		break;

	case FLU_MOVED_NODE:
		printf( "%s moved\n", n->label() );
		break;

	case FLU_NEW_NODE:
		printf( "node '%s' added to the tree\n", n->label() );
		break;
	}
	gui->MVC->redraw();
}