Exemplo n.º 1
0
MenuBar::MenuBar(WContainerWidget * parent) : WContainerWidget(parent)
{

  // create demo menu
  Wt::WComboBox *cb = new Wt::WComboBox(this);
  cb->addItem("Display a map");
  cb->addItem("Create and style clusters");
  cb->addItem("Change a map's style");
  cb->addItem("Create a heatmap from points");
  cb->addItem("Height Lines");
  cb->addItem("Raster Tiles");
  cb->addItem("Fit to Bounds");
  cb->addItem("Set Language");
  cb->addItem("Pitch and Bearing");
  cb->addItem("Change map colors");
  cb->addItem("Layer Order");
  cb->addItem("Add a GeoJSON line");
  cb->addItem("Add a GeoJSON polygon");
  cb->addItem("Draw GeoJSON points");
  cb->addItem("Get coordinates from mouse");
  cb->addItem("Display a Popup");
  cb->addItem("Get features below mouse pointer");
  cb->addItem("Get feature on click");
  cb->addItem("Info in Popup");
  cb->addItem("Mouse Highlight");
  cb->addItem("Data Driven Colors");
  cb->addItem("Add an image");
  cb->addItem("Add a video");
  cb->addItem("Realtime Data");
  cb->addItem("Add Controls");

  cb->setCurrentIndex(0);
  cb->setMargin(10);

  // add all demo's to stack
  Wt::WStackedWidget * stack = new Wt::WStackedWidget(this);
  stack->addWidget(new DisplayMap());
  stack->addWidget(new CreateClusters());
  stack->addWidget(new MapStyle());
  stack->addWidget(new Heatmap());
  stack->addWidget(new HeightLines());
  stack->addWidget(new RasterTiles());
  stack->addWidget(new FitBounds());
  stack->addWidget(new SetLanguage());
  stack->addWidget(new PitchAndBearing());
  stack->addWidget(new ChangeColors());
  stack->addWidget(new LayerOrder());
  stack->addWidget(new GeoJSONLine());
  stack->addWidget(new GeoJSONPoly());
  stack->addWidget(new GeoJSONPoint());
  stack->addWidget(new GetCoordinates());
  stack->addWidget(new DisplayPopup());
  stack->addWidget(new FeaturesBelowMouse());
  stack->addWidget(new FeatureOnClick());
  stack->addWidget(new InfoPopup());
  stack->addWidget(new MouseHighlight());
  stack->addWidget(new DataDrivenColors());
  stack->addWidget(new AddImage());
  stack->addWidget(new AddVideo());
  stack->addWidget(new RealtimeData());
  stack->addWidget(new AddControls());

  cb->changed().connect(std::bind([=]() {
    int choice = cb->currentIndex();
    if (choice < stack->count()) {
      ((Demo *)stack->currentWidget())->onHide();
      stack->setCurrentIndex(choice);
      ((Demo *)stack->currentWidget())->onShow();
    }
  }));

}
Exemplo n.º 2
0
// Updates all ranks
void RecentMatchesContainer::update()
{
    this->clear();
    
    std::vector<RecentMatch> recent_matches = Spartan_->getRecentMatches();
    
    // Create halo api with an api key (get api key from 343i api site)
    //HaloAPI halo_api("05cdc66c52ca4465b0b6e3c56bb87b71");
    
    for (int i = 0; i < recent_matches.size() && i < 10; i++)
    {
        // CUSTOM CONTAINERS
        Wt::WContainerWidget *myContainer = new Wt::WContainerWidget();
        myContainer->decorationStyle().setBorder(Wt::WBorder(Wt::WBorder::Style::Solid, Wt::WBorder::Width::Thin, Wt::WColor(0, 0, 0)));
        myContainer->decorationStyle().setBackgroundColor(Wt::WColor(240, 240, 240));
        myContainer->setPadding(3);
        myContainer->setMargin(3, Wt::Bottom);
        
        std::string title_string = "<b>" + getNameFromHopper(recent_matches[i].hopper_id_) + " / </b>" + getNameFromBaseVariant(recent_matches[i].base_variant_) + "<b> / </b>" + getNameFromMap(recent_matches[i].map_id_) + "";
        Wt::WText *someText = new Wt::WText(title_string, myContainer);
        
        Wt::WPushButton *myButton = new Wt::WPushButton(" + ", myContainer);
        myButton->setFloatSide(Wt::Right);
        
        std::string game_time = time_from_double(recent_matches[i].match_length_);
        Wt::WText *someMoreText = new Wt::WText(game_time, myContainer);
        someMoreText->setFloatSide(Wt::Right);
        
        Wt::WStackedWidget *myStack = new Wt::WStackedWidget(myContainer);
        Wt::WText *text1 = new Wt::WText("text1", myStack);

        
        myButton->clicked().connect(std::bind([=]()
        {
            if (myStack->currentIndex() == 0)
            {
                myButton->setText(" - ");
                Wt::WContainerWidget *stats_table = new Wt::WContainerWidget(myStack);
                Wt::WTable *table = new Wt::WTable(stats_table);
                table->setHeaderCount(1);
                table->elementAt(0, 0)->addWidget(new Wt::WText("Gamertag"));
                HaloAPI halo_api("05cdc66c52ca4465b0b6e3c56bb87b71");
                std::vector<std::string> gamertags;
                
                std::string json_data = halo_api.getPostGameCarnageArena(recent_matches[i].match_id_);
                Json::Value root;   // will contains the root value after parsing.
                Json::Reader reader;
                bool parsingSuccessful = reader.parse( json_data, root );
                if ( !parsingSuccessful )
                {
                    // report to the user the failure and their locations in the document.
                    std::cout  << "Failed to parse configuration\n"
                    << reader.getFormattedErrorMessages();
                }
                const Json::Value plugins = root;
                
                for (int j = 0; j < plugins["PlayerStats"].size(); j++)
                {
                    std::string tag(
                                    plugins["PlayerStats"][j]["Player"]["Gamertag"].asString()
                                    );
                    gamertags.push_back(tag);
                    table->elementAt(j+1, 0)->addWidget(new Wt::WText(tag));
                }
                table->addStyleClass("table table-condensed");
                myStack->setCurrentIndex(1);
            } else
            {
                delete myStack->currentWidget();
                myStack->setCurrentIndex(0);
                myButton->setText(" + ");
            }
        }));
        this->addWidget(myContainer);
    }
}