当前位置: 首页>>代码示例>>C++>>正文


C++ Label::add方法代码示例

本文整理汇总了C++中Label::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Label::add方法的具体用法?C++ Label::add怎么用?C++ Label::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Label的用法示例。


在下文中一共展示了Label::add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: addTracks

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--;
            }
        }
    }
}
开发者ID:clasik,项目名称:stk-code,代码行数:69,代码来源:gp_info_dialog.cpp


注:本文中的Label::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。