diff options
Diffstat (limited to 'gui.cpp')
-rw-r--r-- | gui.cpp | 59 |
1 files changed, 46 insertions, 13 deletions
@@ -1,7 +1,10 @@ #include <iostream> #include <fstream> #include <vector> +#include <unordered_map> +#include <functional> #include <cstdlib> +#include <cassert> #include <sys/time.h> #include <FL/Fl.H> @@ -19,14 +22,14 @@ using namespace std; struct ColourTeam{ - Team *team; + const Team *team; Fl_Color col; }; class BotList{ struct Item{ ColourTeam *cteam; - Fl_Box *box; + Fl_Group *grp; }; Fl_Scroll *listScr; @@ -36,17 +39,34 @@ public: BotList(Fl_Group *parent){ listScr=new Fl_Scroll(parent->x()+1,parent->y()+25,parent->w()-2,parent->h()-26); listScr->end(); + listScr->user_data(this); + } + + ~BotList(){ + delete listScr; } void add(ColourTeam *cteam){ - Fl_Box *box=new Fl_Box(listScr->x(),listScr->y()+20*teams.size(),listScr->w(),20); - box->color(cteam->col); - box->label(cteam->team->name.data()); - box->box(FL_FLAT_BOX); - box->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); - listScr->add(box); + Fl_Group *grp=new Fl_Group(listScr->x(),listScr->y()+20*teams.size(),listScr->w(),20); + grp->color(cteam->col); + grp->label(cteam->team->name.data()); + grp->labelcolor(fl_contrast(FL_WHITE,cteam->col)); + grp->box(FL_FLAT_BOX); + grp->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); + + Fl_Button *delBtn=new Fl_Button(grp->x()+grp->w()-20,grp->y()+2,grp->h()-4,grp->h()-4,"X"); + delBtn->box(FL_THIN_UP_BOX); + delBtn->labelcolor(FL_RED); + delBtn->labelfont(FL_BOLD); + delBtn->callback([](Fl_Widget *wid,void *cteam){ + BotList *self=(BotList*)wid->parent()->parent()->user_data(); + self->remove((ColourTeam*)cteam); + },(void*)cteam); + + grp->end(); + listScr->add(grp); listScr->redraw(); - teams.push_back({cteam,box}); + teams.push_back({cteam,grp}); } void remove(ColourTeam *cteam){ @@ -54,11 +74,13 @@ public: for(i=0;i<teams.size();i++){ if(teams[i].cteam==cteam)break; } - delete teams[i].box; + assert(i<teams.size()); + delete teams[i].grp; for(size_t j=i+1;j<teams.size();j++){ - teams[j].box->position(teams[j].box->x(),teams[j].box->y()-20); + teams[j].grp->position(teams[j].grp->x(),teams[j].grp->y()-20); } teams.erase(teams.begin()+i); + listScr->redraw(); } }; @@ -95,7 +117,7 @@ public: Simulation(World *world,BotList *botList) :world(world),botList(botList){} - void add(Team *team){ + void add(const Team *team){ (void)world; teams.push_back({{team,genColour()}}); botList->add(&teams.back().cteam); @@ -110,6 +132,17 @@ public: } add(new Team(assemble(preprocess(f)))); } + + void remove(const Team *team){ + size_t i; + for(i=0;i<teams.size();i++){ + if(teams[i].cteam.team==team)break; + } + assert(i<teams.size()); + botList->remove(&teams[i].cteam); + world->removeTeam(team); + teams.erase(teams.begin()+i); + } }; @@ -150,7 +183,7 @@ int main(int argc,char **argv){ window->hide(); });*/ - Fl_Group *botlistGroup=new Fl_Group(10,10,150,120); + Fl_Group *botlistGroup=new Fl_Group(10,10,150,300); botlistGroup->box(FL_BORDER_BOX); BotList *botList=makeBotlist(botlistGroup); botlistGroup->end(); |