Exemplo n.º 1
0
    void display_text_t::measure(extents_t& result)
    {
        assert(window_m);

        boost::shared_ptr<GG::Font> font = implementation::DefaultFont();

        extents_t space_extents(metrics::measure_text(std::string(" "), font));
        extents_t label_extents(metrics::measure_text(name_m, font));
        extents_t characters_extents(metrics::measure_text(std::string(characters_m, '0'), font));

        // set up default settings (baseline, etc.)
        result = space_extents;

        // set the width to the label width (if any)
        result.width() = label_extents.width();

        // add a guide for the label
        result.horizontal().guide_set_m.push_back(label_extents.width());

        // if there's a label, add space for a space
        if (label_extents.width() != 0)
            result.width() += space_extents.width();

        // append the character extents (if any)
        result.width() += characters_extents.width();

        // if there are character extents, add space for a space
        if (characters_extents.width() != 0)
            result.width() += space_extents.width();

        assert(result.horizontal().length_m);
    }
Exemplo n.º 2
0
void display_number_t::measure(extents_t& result)
{
    assert(window_m);

    extents_t space_extents(metrics::measure_text(std::string(" "), window_m, EP_EDITTEXT));
    extents_t unit_max_extents;
    extents_t label_extents(metrics::measure_text(name_m, window_m, EP_EDITTEXT));
    extents_t characters_extents =
        metrics::measure_text(std::string(characters_m, '0'), window_m, EP_EDITTEXT);

    for (display_number_t::unit_set_t::iterator iter(unit_set_m.begin()),
         end(unit_set_m.end()); iter != end; ++iter)
        {
            extents_t tmp(metrics::measure_text(iter->name_m, window_m, EP_EDITTEXT));

            if (tmp.width() > unit_max_extents.width())
                unit_max_extents = tmp;
        }

    // set up default settings (baseline, etc.)
    result = space_extents;

    // set the width to the label width (if any)
    result.width() = label_extents.width();

    // add a guide for the label
    result.horizontal().guide_set_m.push_back(label_extents.width());

    // if there's a label, add space for a space
    if (label_extents.width() != 0)
        result.width() += space_extents.width();

    // append the character extents (if any)
    result.width() += characters_extents.width();

    // if there are character extents, add space for a space
    if (characters_extents.width() != 0)
        result.width() += space_extents.width();

    // append the max unit extents (if any)
    result.width() += unit_max_extents.width();

    assert(result.horizontal().length_m);
}