void ResourceWindow::selectPawn(const std::string& name) { Fl_Tree_Item* tree = getTreeFromName("pawn"); for (int c = 0; c < tree->children(); c++) { Fl_Tree_Item* child = tree->child(c); if (strcmp(child->label(), name.c_str()) == 0) { if (child->is_selected()) return; resourceTree->deselect_all(); child->select(); resourceTree->redraw(); return; } } tree = getTreeFromName("character"); for (int c = 0; c < tree->children(); c++) { Fl_Tree_Item* child = tree->child(c); if (strcmp(child->label(), name.c_str()) == 0) { if (child->is_selected()) return; resourceTree->deselect_all(); child->select(); resourceTree->redraw(); return; } } }
int RemoveAIButton::handle(int evt) { if(evt == 2) { if(appended_ai_tree) { std::shared_ptr<AppendAIPatch> aip = std::dynamic_pointer_cast<AppendAIPatch>(mods->get("aip")); Fl_Tree_Item* first = appended_ai_tree->first(); if(first->is_selected()) { for(int child = 0; child < first->children(); child++) { delete (int*)(first->child(child)->user_data()); } first->clear_children(); aip->undo(); aip->set_appended_ai(AppendAIPatch::entity_storage()); mods_window->redraw(); return Fl_Button::handle(evt); } for(int pos = 0; pos < first->children(); pos++) { if(!first->child(pos)->is_selected()) { continue; } Fl_Tree_Item* selected = first->child(pos); int appended_idx = *(int*)selected->user_data(); //correct indices after removal for(int child = 0; child < first->children(); child++) { int* idx = (int*)(first->child(child)->user_data()); if(*idx > appended_idx) { (*idx)--; } } AppendAIPatch::entity_storage appended = aip->appended_ai(); appended.erase(appended.begin()+appended_idx); aip->set_appended_ai(appended); delete (int*)(selected->user_data()); appended_ai_tree->remove(selected); } mods_window->redraw(); if(aip->appended_ai().empty()) { aip->undo(); } } } return Fl_Button::handle(evt); }
void ShowModsGUI() { Fl_Double_Window* wind = make_mods_window(); wind->callback([](Fl_Widget* window) { if(visible_callback) { visible_callback(false); } if(window) { delete (Fl_Double_Window*)window; mods_window = nullptr; } if(appended_ai_tree) { Fl_Tree_Item* first = appended_ai_tree->first(); if(first) { for(int i = 0; i < first->children(); i++) { delete (int*)(first->child(i)->user_data()); } } appended_ai_tree = nullptr; } }); wind->show(); visible_callback(true); }
void ResourceWindow::showTree() { // show everything under the top-level items Fl_Tree_Item* root = resourceTree->first(); int numChildren = root->children(); for (int c = 0; c < numChildren; c++) { Fl_Tree_Item* item = root->child(c); item->open(); } }
void ResourceWindow::hideTree() { // show only top-level items Fl_Tree_Item* root = resourceTree->first(); int numChildren = root->children(); for (int c = 0; c < numChildren; c++) { Fl_Tree_Item* item = root->child(c); item->close(); } }
/// Insert a new item above this item. Fl_Tree_Item *Fl_Tree_Item::insert_above(const Fl_Tree_Prefs &prefs, const char *new_label) { Fl_Tree_Item *p = _parent; if ( ! p ) return(0); // Walk our parent's children to find ourself for ( int t=0; t<p->children(); t++ ) { Fl_Tree_Item *c = p->child(t); if ( this == c ) { return(p->insert(prefs, new_label, t)); } } return(0); }
void ResourceWindow::OnSelect(const std::string& value) { if (value == "") { // deselect all resourceTree->select_only(NULL); } SmartBody::SBObject* object = SmartBody::SBScene::getScene()->getObjectFromString(value); if (!object) return; Fl_Tree_Item* item = NULL; SmartBody::SBCharacter* character = dynamic_cast<SmartBody::SBCharacter*>(object); if (character) { // select a character for (std::map<Fl_Tree_Item*, std::string>::iterator iter = _treeMap.begin(); iter != _treeMap.end(); iter++) { if ((*iter).second == "character") { item = (*iter).first; // make sure that the parent is open so that the selection can be seen resourceTree->open(item); } } if (!item) return; } else { SmartBody::SBPawn* pawn = dynamic_cast<SmartBody::SBPawn*>(object); if (pawn) { // select a pawn for (std::map<Fl_Tree_Item*, std::string>::iterator iter = _treeMap.begin(); iter != _treeMap.end(); iter++) { if ((*iter).second == "pawn") { item = (*iter).first; // make sure that the parent is open so that the selection can be seen resourceTree->open(item); } } if (!item) return; } } if (!item) return; int numChildren = item->children(); for (int c = 0; c < numChildren; c++) { Fl_Tree_Item* child = item->child(c); if (object->getName() == child->label()) { resourceTree->select_only(child); } } }
int ResourceWindow::handle( int event ) { int ret = Fl_Group::handle(event); std::string dndText; switch ( event ) { case FL_DND_RELEASE: //LOG("DND Release"); ret = 1; break; case FL_DND_ENTER: // return(1) for these events to 'accept' dnd //LOG("DND Enter"); //Fl::belowmouse(this); // send the leave events first //Fl::focus(this); //handle(FL_FOCUS); ret = 1; break; case FL_DND_DRAG: ret = 1; break; case FL_DND_LEAVE: //LOG("DND Leave"); ret = 1; break; case FL_PASTE: // handle actual drop (paste) operation { //label(Fl::event_text()); //fprintf(stderr, "PASTE: %s\n", Fl::event_text()); //LOG("PASTE: %s\n", Fl::event_text()); dndText = Fl::event_text(); bool hasAsset = processedDragAndDrop(dndText); ret = 1; } break; case FL_PUSH: {// do 'copy/dnd' when someone clicks on box if (Fl::event_button() == 2) { LOG("press middle button"); LOG("lastClickedItemPath = %s",lastClickedItemPath.c_str()); Fl_Tree_Item* lastItem = resourceTree->find_item(lastClickedItemPath.c_str()); if (lastItem) { const char* itemType = (const char*)lastItem->user_data(); bool sendDND = false; std::string dndMsg = ""; if (strcmp(itemType, "skeleton") == 0) { std::string skName = lastItem->label(); dndMsg = "SKELETON:"; dndMsg += skName; sendDND = true; } else if (strcmp(itemType, "pawn") == 0) { dndMsg = "PAWN:dummy"; sendDND = true; } //Fl::copy("message",7,0); if (sendDND) { Fl::copy(dndMsg.c_str(),dndMsg.length(),0); Fl::dnd(); } ret = 1; } } break; } case FL_KEYDOWN: { switch (Fl::event_key()) { case FL_Delete: { // check pawns and characters for selection Fl_Tree_Item* tree = getTreeFromName("pawn"); int numChildren = tree->children(); for (int c = 0; c < numChildren; c++) { Fl_Tree_Item* child = tree->child(c); if (child->is_selected()) { const char* name = child->label(); int confirm = fl_choice(vhcl::Format("Are you sure you want to delete '%s'?",name).c_str(), "No", "Yes", NULL); if (confirm == 0) return 0; SmartBody::SBScene::getScene()->removePawn(name); updateGUI(); return 1; } } tree = getTreeFromName("character"); numChildren = tree->children(); for (int c = 0; c < numChildren; c++) { Fl_Tree_Item* child = tree->child(c); if (child->is_selected()) { const char* name = child->label(); int confirm = fl_choice(vhcl::Format("Are you sure you want to delete '%s'?",name).c_str(), "No", "Yes", NULL); if (confirm == 0) return 0; SmartBody::SBScene::getScene()->removeCharacter(name); updateGUI(); return 1; } } } break; default: break; } } } return ret; }