void menu::update_size() { unsigned int h = heading_height(); for(size_t i = get_position(), i_end = std::min(items_.size(), i + max_items_onscreen()); i < i_end; ++i) h += get_item_rect(i).h; h = std::max(h, height()); if (max_height_ > 0 && h > static_cast<unsigned>(max_height_)) { h = max_height_; } use_ellipsis_ = false; std::vector<int> const &widths = column_widths(); unsigned w = std::accumulate(widths.begin(), widths.end(), 0); if (items_.size() > max_items_onscreen()) w += scrollbar_width(); w = std::max(w, width()); if (max_width_ > 0 && w > static_cast<unsigned>(max_width_)) { use_ellipsis_ = true; w = max_width_; } update_scrollbar_grip_height(); set_measurements(w, h); }
dialog_image(label *const caption, CVideo &video, surface img) : widget(video, false), surf_(img), caption_(caption) { if(!img.null()) { set_measurements(img->w, img->h); } }
unit_preview_pane::unit_preview_pane(const gui::filter_textbox *filter, TYPE type, bool on_left_side) : gui::preview_pane(resources::screen->video()), index_(0), details_button_(resources::screen->video(), _("Profile"), gui::button::TYPE_PRESS,"lite_small", gui::button::DEFAULT_SPACE), filter_(filter), weapons_(type == SHOW_ALL), left_(on_left_side) { unsigned w = font::relative_size(weapons_ ? 200 : 190); // advance test unsigned h = font::relative_size(weapons_ ? 440 : 140); set_measurements(w, h); }
void label::render_text() { font::ttext txt; txt.set_text(text_, true); const Uint32 color = (color_.r << 16) + (color_.g << 16) + (color_.b); txt.set_foreground_color(color); txt.set_font_size(size_); text_image_ = txt.render_as_texture(); set_measurements(text_image_.width(), text_image_.height()); }
textbox::textbox(CVideo &video, int width, const std::string& text, bool editable, size_t max_size, double alpha, double alpha_focus, const bool auto_join) : scrollarea(video, auto_join), max_size_(max_size), text_(utils::string_to_wstring(text)), cursor_(text_.size()), selstart_(-1), selend_(-1), grabmouse_(false), text_pos_(0), editable_(editable), show_cursor_(true), show_cursor_at_(0), text_image_(NULL), wrap_(false), line_height_(0), yscroll_(0), alpha_(alpha), alpha_focus_(alpha_focus) { // static const SDL_Rect area = d.screen_area(); // const int height = font::draw_text(NULL,area,font_size,font::NORMAL_COLOUR,"ABCD",0,0).h; set_measurements(width, font::get_max_height(font_size)); set_scroll_rate(font::get_max_height(font_size) / 2); update_text_cache(true); }
help_browser::help_browser(CVideo& video, const section &toplevel) : gui::widget(video), menu_(video, toplevel), text_area_(video, toplevel), toplevel_(toplevel), ref_cursor_(false), back_topics_(), forward_topics_(), back_button_(video, "", gui::button::TYPE_PRESS, "button_normal/button_small_H22", gui::button::DEFAULT_SPACE, true, "icons/arrows/long_arrow_ornate_left"), forward_button_(video, "", gui::button::TYPE_PRESS, "button_normal/button_small_H22", gui::button::DEFAULT_SPACE, true, "icons/arrows/long_arrow_ornate_right"), shown_topic_(nullptr) { // Hide the buttons at first since we do not have any forward or // back topics at this point. They will be unhidden when history // appears. back_button_.hide(true); forward_button_.hide(true); // Set sizes to some default values. set_measurements(font::relative_size(400), font::relative_size(500)); }
help_browser::help_browser(display &disp, const section &toplevel) : gui::widget(disp.video()), disp_(disp), menu_(disp.video(), toplevel), text_area_(disp.video(), toplevel), toplevel_(toplevel), ref_cursor_(false), back_topics_(), forward_topics_(), back_button_(disp.video(), _(" < Back"), gui::button::TYPE_PRESS), forward_button_(disp.video(), _("Forward >"), gui::button::TYPE_PRESS), shown_topic_(NULL) { // Hide the buttons at first since we do not have any forward or // back topics at this point. They will be unhidden when history // appears. back_button_.hide(true); forward_button_.hide(true); // Set sizes to some default values. set_measurements(font::relative_size(400), font::relative_size(500)); }
battle_prediction_pane::battle_prediction_pane(const battle_context &bc, const map_location &attacker_loc, const map_location &defender_loc) : gui::preview_pane(resources::screen->video()), attacker_loc_(attacker_loc), defender_loc_(defender_loc), attacker_(*resources::units->find(attacker_loc)), defender_(*resources::units->find(defender_loc)), attacker_label_(), defender_label_(), attacker_label_width_(0), defender_label_width_(0), attacker_left_strings_(), attacker_right_strings_(), defender_left_strings_(), defender_right_strings_(), attacker_strings_width_(0), attacker_left_strings_width_(0), attacker_right_strings_width_(0), defender_strings_width_(0), defender_left_strings_width_(0), defender_right_strings_width_(0), units_strings_height_(0), hp_distrib_string_(), attacker_hp_distrib_(), defender_hp_distrib_(), hp_distrib_string_width_(0), attacker_hp_distrib_width_(0), defender_hp_distrib_width_(0), attacker_hp_distrib_height_(0), defender_hp_distrib_height_(0), hp_distribs_height_(0), attacker_width_(0), defender_width_(0), units_width_(0), dialog_width_(0), dialog_height_(0) { // Predict the battle outcome. combatant attacker_combatant(bc.get_attacker_stats()); combatant defender_combatant(bc.get_defender_stats()); attacker_combatant.fight(defender_combatant); const battle_context_unit_stats& attacker_stats = bc.get_attacker_stats(); const battle_context_unit_stats& defender_stats = bc.get_defender_stats(); // Create the hitpoints distribution graphics. std::vector<std::pair<int, double> > hp_prob_vector; get_hp_prob_vector(attacker_combatant.hp_dist, hp_prob_vector); get_hp_distrib_surface(hp_prob_vector, attacker_stats, defender_stats, attacker_hp_distrib_, attacker_hp_distrib_width_, attacker_hp_distrib_height_); get_hp_prob_vector(defender_combatant.hp_dist, hp_prob_vector); get_hp_distrib_surface(hp_prob_vector, defender_stats, attacker_stats, defender_hp_distrib_, defender_hp_distrib_width_, defender_hp_distrib_height_); hp_distribs_height_ = std::max<int>(attacker_hp_distrib_height_, defender_hp_distrib_height_); // Build the strings and compute the layout. attacker_label_ = _("Attacker"); defender_label_ = _("Defender"); attacker_label_width_ = font::line_width(attacker_label_, font::SIZE_PLUS, TTF_STYLE_BOLD); defender_label_width_ = font::line_width(defender_label_, font::SIZE_PLUS, TTF_STYLE_BOLD); // Get the units strings. get_unit_strings(attacker_stats, attacker_, attacker_loc_, static_cast<float>(attacker_combatant.untouched), defender_, defender_loc_, defender_stats.weapon, attacker_left_strings_, attacker_right_strings_, attacker_left_strings_width_, attacker_right_strings_width_, attacker_strings_width_); get_unit_strings(defender_stats, defender_, defender_loc_, static_cast<float>(defender_combatant.untouched), attacker_, attacker_loc_, attacker_stats.weapon, defender_left_strings_, defender_right_strings_, defender_left_strings_width_, defender_right_strings_width_, defender_strings_width_); units_strings_height_ = std::max<int>(attacker_left_strings_.size(), defender_left_strings_.size()) * (font::SIZE_NORMAL + inter_line_gap_) + 14; hp_distrib_string_ = _("Expected Battle Result (HP)"); hp_distrib_string_width_ = font::line_width(hp_distrib_string_, font::SIZE_SMALL); attacker_width_ = std::max<int>(attacker_label_width_, attacker_strings_width_); attacker_width_ = std::max<int>(attacker_width_, hp_distrib_string_width_); attacker_width_ = std::max<int>(attacker_width_, attacker_hp_distrib_width_); defender_width_ = std::max<int>(defender_label_width_, defender_strings_width_); defender_width_ = std::max<int>(defender_width_, hp_distrib_string_width_); defender_width_ = std::max<int>(defender_width_, defender_hp_distrib_width_); units_width_ = std::max<int>(attacker_width_, defender_width_); dialog_width_ = 2 * units_width_ + inter_units_gap_; dialog_height_ = 15 + 24 + units_strings_height_ + 14 + 19 + hp_distribs_height_ + 18; // Set the dialog size. set_measurements(dialog_width_, dialog_height_); }
void label::update_label_size() { SDL_Rect area = font::text_area(text_, size_); set_measurements(area.w, area.h); }