void GPInfoDialog::addTracks() { const std::vector<std::string> tracks = m_gp.getTrackNames(); const unsigned int track_amount = tracks.size(); int height_of_one_line = std::min((m_lower_bound - m_over_body)/(track_amount+1), (unsigned int)(GUIEngine::getFontHeight()*1.5f)); // Count the number of label already existing labels representing a track unsigned int existing = 0; for (unsigned int i = 0; i < m_widgets.size(); i++) { if (m_widgets.get(i)->m_properties[PROP_ID] == "Track label") existing++; } unsigned int reuse = std::min(existing, track_amount); // m_widgets has the type PtrVector<Widget, HOLD> unsigned int widgets_iter = 0; for (unsigned int i = 0; i < reuse; i++) { Track* track = track_manager->getTrack(tracks[i]); // Find the next widget that is a track label while (m_widgets.get(widgets_iter)->m_properties[PROP_ID] != "Track label") widgets_iter++; Label* widget = dynamic_cast<Label*>(m_widgets.get(widgets_iter)); widget->setText(translations->fribidize(track->getName()), false); widget->move(20, m_over_body + height_of_one_line*i, m_area.getWidth()/2 - 20, height_of_one_line); widgets_iter++; } if (existing < track_amount) { // There are not enough labels for all the track names, so we have to // add some more for (unsigned int i = reuse; i < track_amount; i++) { Track* track = track_manager->getTrack(tracks[i]); assert(track != NULL); Label* widget = new Label(); widget->m_properties[PROP_ID] = "Track label"; widget->setText(translations->fribidize(track->getName()), false); widget->setParent(m_irrlicht_window); m_widgets.push_back(widget); widget->add(); widget->move(20, m_over_body + height_of_one_line*i, m_area.getWidth()/2 - 20, height_of_one_line); } } else if (existing > track_amount) { // There are label which are not necessary anymore so they're deleted for (unsigned int i = widgets_iter; i < m_widgets.size(); i++) { if (m_widgets.get(i)->m_properties[PROP_ID] == "Track label") { m_irrlicht_window->removeChild(m_widgets.get(i)->getIrrlichtElement()); m_widgets.remove(i); i--; } } } }