void tmenubar::item_selected(twidget* widget) { //std::cerr << "click.\n"; tselectable_* item = dynamic_cast<tselectable_*>(widget); assert(item); // Find the widget clicked upon. size_t index = 0; for(; index < get_item_count(); ++index) { if((*this)[index] == item) { break; } } assert(index < get_item_count()); // Set the selection. if(!item->get_value()) { // Deselected an item, allowed? if(must_select_) { item->set_value(true); } else { selected_item_ = -1; } } else { set_selected_item(index); } }
/** Returns the visibility of all the items as a bit set. */ boost::dynamic_bitset<> get_items_shown() const { boost::dynamic_bitset<> items_shown(get_item_count()); for (unsigned int i = 0u; i < get_item_count(); ++i) { items_shown[i] = get_item_shown(i); } return items_shown; }
void list_view::set_row_shown(const boost::dynamic_bitset<>& shown) { assert(generator_); assert(shown.size() == get_item_count()); window* window = get_window(); assert(window); const int selected_row = get_selected_row(); bool resize_needed = false; { window::invalidate_layout_blocker invalidate_layout_blocker(*window); for(size_t i = 0; i < shown.size(); ++i) { generator_->set_item_shown(i, shown[i]); } generator_->place(generator_->get_origin(), generator_->calculate_best_size()); // resize_needed = !content_resize_request(); } if(resize_needed) { window->invalidate_layout(); } else { // content_grid_->set_visible_rectangle(content_visible_rectangle()); set_is_dirty(true); } if(selected_row != get_selected_row()) { fire(event::NOTIFY_MODIFIED, *this, nullptr); } }
void tvertical_list::place(const tpoint& origin, const tpoint& size) { /* * - Set every item to its best size. * - The origin gets increased with the height of the last item. * - No item should be wider as the size. * - In the end the origin should be the sum or the origin and the wanted * height. */ tpoint current_origin = origin; for(size_t i = 0; i < get_item_count(); ++i) { tgrid& grid = item_ordered(i); if(grid.get_visible() == twidget::tvisible::invisible || !get_item_shown(get_item_at_ordered(i))) { continue; } tpoint best_size = grid.get_best_size(); assert(best_size.x <= size.x); // FIXME should we look at grow factors??? best_size.x = size.x; grid.place(current_origin, best_size); current_origin.y += best_size.y; } assert(current_origin.y == origin.y + size.y); }
void tvertical_list::handle_key_down_arrow(SDLMod /*modifier*/, bool& handled) { if(get_selected_item_count() == 0) { return; } // NOTE maybe this should only work if we can select only one item... handled = true; for(size_t i = get_ordered_index(get_selected_item()) + 1; i < get_item_count(); ++i) { // why do we do this check here but not in handle_key_up_arrow? if(item_ordered(i).get_visible() == twidget::tvisible::invisible || !get_item_shown(get_item_at_ordered(i))) { continue; } // NOTE we check the first widget to be active since grids have no // active flag. This method might not be entirely reliable. tcontrol* control = dynamic_cast<tcontrol*>(item_ordered(i).widget(0, 0)); if(control && control->get_active()) { select_item(get_item_at_ordered(i), true); return; } } }
void ItemListPlugin::_get_property_list( List<PropertyInfo> *p_list) const { for(int i=0;i<get_item_count();i++) { String base=itos(i)+"/"; p_list->push_back( PropertyInfo(Variant::STRING,base+"text") ); p_list->push_back( PropertyInfo(Variant::OBJECT,base+"icon",PROPERTY_HINT_RESOURCE_TYPE,"Texture") ); int flags = get_flags(); if (flags&FLAG_CHECKABLE) { p_list->push_back( PropertyInfo(Variant::BOOL,base+"checkable") ); p_list->push_back( PropertyInfo(Variant::BOOL,base+"checked") ); } if (flags&FLAG_ID) p_list->push_back( PropertyInfo(Variant::INT,base+"id",PROPERTY_HINT_RANGE,"-1,4096") ); if (flags&FLAG_ENABLE) p_list->push_back( PropertyInfo(Variant::BOOL,base+"enabled") ); if (flags&FLAG_SEPARATOR) p_list->push_back( PropertyInfo(Variant::BOOL,base+"separator") ); } }
void t_list_view::__calculate_item_positions(t_size index_start) { if (index_start >= get_item_count()) return; t_size y_pointer = 0; if (m_group_count) while (index_start && get_item_display_group_count(index_start) == 0) index_start--; if (!index_start) y_pointer += 0;//m_item_height * m_group_count; else { if (m_group_count) y_pointer = get_item_group_bottom(index_start-1)+1; else y_pointer = get_item_position(index_start-1)+get_item_height(index_start-1); } t_size i, count = m_items.get_count(), group_height_counter=0, group_minimum_inner_height = get_group_minimum_inner_height(); for (i=index_start; i<count; i++) { t_size groups = get_item_display_group_count(i); if (groups) { if (group_height_counter && group_height_counter < group_minimum_inner_height) y_pointer += group_minimum_inner_height - group_height_counter; group_height_counter=0; } group_height_counter+=get_item_height(i); y_pointer += groups*m_group_height; m_items[i]->m_display_position = y_pointer; y_pointer+= get_item_height(i); } }
void thorizontal_list::handle_key_right_arrow( SDLMod /*modifier*/, bool& handled) { if(get_selected_item_count() == 0) { return; } // NOTE maybe this should only work if we can select only one item... handled = true; for(size_t i = get_selected_item() + 1; i < get_item_count(); ++i) { if(item(i).get_visible() == twidget::INVISIBLE || !get_item_shown(i)) { continue; } // NOTE we check the first widget to be active since grids have no // active flag. This method might not be entirely reliable. tcontrol* control = dynamic_cast<tcontrol*>(item(i).widget(0, 0)); if(control && control->get_active()) { select_item(i); return; } } }
void tlistbox::set_row_shown(const std::vector<bool>& shown) { assert(generator_); assert(shown.size() == get_item_count()); twindow *window = get_window(); assert(window); const int selected_row = get_selected_row(); bool resize_needed; { twindow::tinvalidate_layout_blocker invalidate_layout_blocker(*window); for(size_t i = 0; i < shown.size(); ++i) { generator_->set_item_shown(i, shown[i]); } generator_->place(generator_->get_origin() , generator_->calculate_best_size()); resize_needed = !content_resize_request(); } if(resize_needed) { window->invalidate_layout(); } else { content_grid_->set_visible_area(content_visible_area()); set_dirty(); } if(selected_row != get_selected_row() && callback_value_changed_) { callback_value_changed_(this); } }
void PopupMenu::_set_items(const Array& p_items){ ERR_FAIL_COND(p_items.size() % 10); clear(); for(int i=0;i<p_items.size();i+=10) { String text=p_items[i+0]; Ref<Texture> icon=p_items[i+1]; bool checkable=p_items[i+2]; bool checked=p_items[i+3]; bool disabled=p_items[i+4]; int id=p_items[i+5]; int accel=p_items[i+6]; Variant meta=p_items[i+7]; String subm=p_items[i+8]; bool sep=p_items[i+9]; int idx=get_item_count(); add_item(text,id); set_item_icon(idx,icon); set_item_as_checkable(idx,checkable); set_item_checked(idx,checked); set_item_disabled(idx,disabled); set_item_ID(idx,id); set_item_metadata(idx,meta); set_item_as_separator(idx,sep); set_item_accelerator(idx,accel); set_item_submenu(idx,subm); } }
void tindependent::request_reduce_height(const unsigned maximum_height) { for(size_t i = 0; i < get_item_count(); ++i) { tgrid& grid = item(i); grid.request_reduce_height(maximum_height); } }
void tindependent::place(const tpoint& origin, const tpoint& size) { for(size_t i = 0; i < get_item_count(); ++i) { tgrid& grid = item(i); grid.place(origin, size); } }
bool tlistbox::any_rows_shown() const { for(size_t i = 0; i < get_item_count(); i++) { if(generator_->get_item_shown(i)) { return true; } } return false; }
twidget* tindependent::find(const std::string& id, const bool must_be_active) { for(size_t i = 0; i < get_item_count(); ++i) { if(is_selected(i)) { if(twidget* widget = item(i).find(id, must_be_active)) { return widget; } } } return NULL; }
Array ItemList::_get_items() const { Array items; for (int i = 0; i < get_item_count(); i++) { items.push_back(get_item_text(i)); items.push_back(get_item_icon(i)); items.push_back(is_item_disabled(i)); } return items; }
static void on_next (GtkButton *entry, gpointer user_data) { study_screen_info *info = user_data; info->current++; if(info->current == get_item_count ()) { gtk_button_set_label(GTK_BUTTON (info->next_button), "To Quiz"); update_text(info); } else if(info->current == get_item_count ()+1) { //! do not update text or we will have an overflow! shift_to_quiz_screen(); } else { update_text(info); } }
void listbox::remove_row(const unsigned row, unsigned count) { assert(generator_); if(row >= get_item_count()) { return; } if(!count || count + row > get_item_count()) { count = get_item_count() - row; } int height_reduced = 0; int width_reduced = 0; // TODO: Fix this for horizontal listboxes // Note the we have to use content_grid_ and cannot use "_list_grid" which is what generator_ uses. int row_pos_y = is_horizontal_ ? -1 : generator_->item(row).get_y() - content_grid_->get_y(); int row_pos_x = is_horizontal_ ? -1 : 0; for(; count; --count) { if(generator_->item(row).get_visible() != visibility::invisible) { if(is_horizontal_) { width_reduced += generator_->item(row).get_width(); } else { height_reduced += generator_->item(row).get_height(); } } generator_->delete_item(row); } if((height_reduced != 0 || width_reduced != 0) && get_item_count() != 0) { resize_content(-width_reduced, -height_reduced, row_pos_x, row_pos_y); } else { update_content_size(); } }
void tindependent::set_visible_rectangle(const SDL_Rect& rectangle) { /* * Set the visible rectangle for every item. * * @todo evaluate whether setting it only for the visible item is better * and what the consequences are. */ for(size_t i = 0; i < get_item_count(); ++i) { tgrid& grid = item(i); grid.set_visible_rectangle(rectangle); } }
void tvertical_list::set_origin(const tpoint& origin) { tpoint current_origin = origin; for(size_t i = 0; i < get_item_count(); ++i) { tgrid& grid = item(i); if(grid.get_visible() == twidget::INVISIBLE || !get_item_shown(i)) { continue; } grid.set_origin(current_origin); current_origin.y += grid.get_height(); } }
void tindependent::set_origin(const tpoint& origin) { /* * Set the origin for every item. * * @todo evaluate whether setting it only for the visible item is better * and what the consequences are. */ for(size_t i = 0; i < get_item_count(); ++i) { tgrid& grid = item(i); grid.set_origin(origin); } }
t_string tslider::get_value_label() const { if(value_labels_) { return value_labels_(get_item_position(), get_item_count()); } else if(!minimum_value_label_.empty() && get_value() == get_minimum_value()) { return minimum_value_label_; } else if(!maximum_value_label_.empty() && get_value() == get_maximum_value()) { return maximum_value_label_; } else { return t_string((formatter() << get_value()).str()); } }
void tvertical_list::set_visible_rectangle(const SDL_Rect& rectangle) { /* * Note for most implementations this function could work only for the * tindependent class it probably fails. Evaluate to make a generic * function in the tgenerator template class and call it from the wanted * placement functions. */ for(size_t i = 0; i < get_item_count(); ++i) { tgrid& grid = item(i); grid.set_visible_rectangle(rectangle); } }
Array OptionButton::_get_items() const { Array items; for (int i = 0; i < get_item_count(); i++) { items.push_back(get_item_text(i)); items.push_back(get_item_icon(i)); items.push_back(is_item_disabled(i)); items.push_back(get_item_ID(i)); items.push_back(get_item_metadata(i)); } return items; }
t_string tslider::get_value_label() const { if(!value_labels_.empty()) { VALIDATE(value_labels_.size() == get_item_count(), null_str); return value_labels_[get_item_position()]; } else if(!minimum_value_label_.empty() && get_value() == get_minimum_value()) { return minimum_value_label_; } else if(!maximum_value_label_.empty() && get_value() == get_maximum_value()) { return maximum_value_label_; } else { return t_string((formatter() << get_value()).str()); } }
t_string tslider::get_value_label() const { if(!value_labels_.empty()) { assert(value_labels_.size() == get_item_count()); return value_labels_[get_item_position()]; } else if(!minimum_value_label_.empty() && get_value() == get_minimum_value()) { return minimum_value_label_; } else if(!maximum_value_label_.empty() && get_value() == get_maximum_value()) { return maximum_value_label_; } else { return t_string(formatter_(get_value())); } }
const tselectable_* tmenubar::operator[](const size_t index) const { assert(index < get_item_count()); const tselectable_* widget = NULL; if(direction_ == VERTICAL) { widget = dynamic_cast<const tselectable_*>(grid().widget(index, 0)); } else { widget = dynamic_cast<const tselectable_*>(grid().widget(0, index)); } assert(widget); return widget; }
void list_view::remove_row(const unsigned row, unsigned count) { assert(generator_); if(row >= get_item_count()) { return; } if(!count || count > get_item_count()) { count = get_item_count(); } unsigned height_reduced = 0; for(; count; --count) { if(generator_->item(row).get_visible() != visibility::invisible) { height_reduced += generator_->item(row).get_height(); } generator_->delete_item(row); } if(height_reduced != 0) { // resize_content(0, -height_reduced); } }
void tlistbox::remove_row(const unsigned row, unsigned count) { assert(generator_); if(row >= get_item_count()) { return; } if(!count || count > get_item_count()) { count = get_item_count(); } int height_reduced = 0; for(; count; --count) { if(generator_->item(row).get_visible() != INVISIBLE) { height_reduced += generator_->item(row).get_height(); } generator_->delete_item(row); } if(height_reduced != 0) { resize_content(0, -height_reduced); } }
// The mouse is over the window // int List_Window::mouseover(window_info *win, int mx, int my) { if ((my < 0) || (cm_window_shown()!=CM_INIT_VALUE)) return 0; if (Vars::lists()->valid_active_list() && mx>=0 && mx<(get_grid_size()*6) && my>=0 && my<(get_grid_size()*num_grid_rows)) { size_t item_number = get_item_number(mx, my); if (item_number < Vars::lists()->get_list().get_num_items()) { Uint16 item_id = Vars::lists()->get_list().get_item_id(item_number); int image_id = Vars::lists()->get_list().get_image_id(item_number); if (show_item_desc_text && item_info_available() && (get_item_count(item_id, image_id) == 1)) desc_str = get_item_description(item_id, image_id); help_str.push_back(item_list_pickup_help_str); help_str.push_back(item_list_use_help_str); help_str.push_back(item_list_edit_help_str); } if ((storage_item_dragged != -1) || (item_dragged != -1)) help_str.push_back(item_list_add_help_str); else help_str.push_back(item_list_drag_help_str); } // check if over the add list button if (my>add_button_y && my<(add_button_y+2*DEFAULT_FONT_Y_LEN) && mx>add_button_x && mx<win->len_x) { help_str.push_back(item_list_create_help_str); mouse_over_add_button = true; } // check if over the list names and get which name int start_names = get_grid_size()*num_grid_rows; if ((my > start_names) && (my < (start_names+get_names_size_y()))) name_under_mouse = vscrollbar_get_pos (win_id, names_scroll_id) + static_cast<int>((my - start_names - get_list_gap()/2) / (get_list_gap() + names_list_height)); // name list context help if ((my > start_names) && (my < (start_names+get_names_size_y()))) { help_str.push_back(cm_help_options_str); if (!strlen(filter)) help_str.push_back(item_list_find_help_str); } return 0; }
void ItemList::_set_items(const Array &p_items) { ERR_FAIL_COND(p_items.size() % 3); clear(); for (int i = 0; i < p_items.size(); i += 3) { String text = p_items[i + 0]; Ref<Texture> icon = p_items[i + 1]; bool disabled = p_items[i + 2]; int idx = get_item_count(); add_item(text, icon); set_item_disabled(idx, disabled); } }