void FileDialog::update_filters() { filter->clear(); if (filters.size()>1) { String all_filters; const int max_filters=5; for(int i=0;i<MIN( max_filters, filters.size()) ;i++) { String flt=filters[i].get_slice(";",0); if (i>0) all_filters+=","; all_filters+=flt; } if (max_filters<filters.size()) all_filters+=", ..."; filter->add_item(RTR("All Recognized")+" ( "+all_filters+" )"); } for(int i=0;i<filters.size();i++) { String flt=filters[i].get_slice(";",0).strip_edges(); String desc=filters[i].get_slice(";",1).strip_edges(); if (desc.length()) filter->add_item(String(XL_MESSAGE(desc))+" ( "+flt+" )"); else filter->add_item("( "+flt+" )"); } filter->add_item(RTR("All Files (*)")); }
void ButtonArray::set_button_text(int p_button, const String &p_text) { ERR_FAIL_INDEX(p_button, buttons.size()); buttons[p_button].text = p_text; buttons[p_button].xl_text = XL_MESSAGE(p_text); update(); minimum_size_changed(); }
void PopupMenu::set_item_text(int p_idx,const String& p_text) { ERR_FAIL_INDEX(p_idx,items.size()); items[p_idx].text=XL_MESSAGE(p_text); update(); }
void PopupMenu::add_item(const String& p_label,int p_ID,uint32_t p_accel) { Item item; item.text=XL_MESSAGE(p_label); item.accel=p_accel; item.ID=(p_ID<0)?idcount++:p_ID; items.push_back(item); update(); }
void PopupMenu::add_submenu_item(const String& p_label, const String& p_submenu,int p_ID){ Item item; item.text=XL_MESSAGE(p_label); item.ID=(p_ID<0)?idcount++:p_ID; item.submenu=p_submenu; items.push_back(item); update(); }
void Button::set_text(const String& p_text) { if (text==p_text) return; text=XL_MESSAGE(p_text); update(); _change_notify("text"); minimum_size_changed(); }
void PopupMenu::add_icon_check_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID,uint32_t p_accel) { Item item; item.icon=p_icon; item.text=XL_MESSAGE(p_label); item.accel=p_accel; item.ID=(p_ID<0)?idcount++:p_ID; item.checkable=true; items.push_back(item); update(); }
void ButtonArray::add_icon_button(const Ref<Texture> &p_icon, const String &p_text, const String &p_tooltip) { Button button; button.text = p_text; button.xl_text = XL_MESSAGE(p_text); button.icon = p_icon; button.tooltip = p_tooltip; buttons.push_back(button); if (selected == -1) selected = 0; update(); }
void Label::set_text(const String& p_string) { String str = XL_MESSAGE(p_string); if (text==str) return; text=str; word_cache_dirty=true; update(); if (!autowrap) minimum_size_changed(); }
void ButtonArray::add_button(const String &p_text, const String &p_tooltip) { Button button; button.text = p_text; button.xl_text = XL_MESSAGE(p_text); button.tooltip = p_tooltip; buttons.push_back(button); update(); if (selected == -1) selected = 0; minimum_size_changed(); }
void Label::set_text(const String& p_string) { String str = XL_MESSAGE(p_string); if (text==str) return; text=str; word_cache_dirty=true; if (percent_visible<1) visible_chars=get_total_character_count()*percent_visible; update(); minimum_size_changed(); }
bool ButtonArray::_set(const StringName &p_name, const Variant &p_value) { String n = String(p_name); if (n.begins_with("button/")) { String what = n.get_slicec('/', 1); if (what == "count") { int new_size = p_value; if (new_size > 0 && buttons.size() == 0) { selected = 0; } if (new_size < buttons.size()) { if (selected >= new_size) selected = new_size - 1; } buttons.resize(new_size); _change_notify(); minimum_size_changed(); } else if (what == "align") { set_align(Align(p_value.operator int())); } else if (what == "selected") { set_selected(p_value); } else if (what == "min_button_size") { min_button_size = p_value; } else { int idx = what.to_int(); ERR_FAIL_INDEX_V(idx, buttons.size(), false); String f = n.get_slicec('/', 2); if (f == "text") { buttons[idx].text = p_value; buttons[idx].xl_text = XL_MESSAGE(p_value); } else if (f == "tooltip") buttons[idx].tooltip = p_value; else if (f == "icon") buttons[idx].icon = p_value; else return false; } update(); return true; } return false; }
void Node::set_name(const String& p_name) { String name=p_name.replace(":","").replace("/","").replace("@",""); ERR_FAIL_COND(name==""); data.name=XL_MESSAGE(name); if (data.parent) { data.parent->_validate_child_name(this); } if (is_inside_scene()) { emit_signal("renamed"); get_scene()->tree_changed(); } }
void LineEdit::set_placeholder(String p_text) { placeholder = XL_MESSAGE(p_text); update(); }
void WindowDialog::set_title(const String& p_title) { title=XL_MESSAGE(p_title); update(); }
StringName Object::tr(const StringName& p_message) const { return XL_MESSAGE(p_message); }
void TabContainer::_notification(int p_what) { switch(p_what) { case NOTIFICATION_DRAW: { RID ci = get_canvas_item(); Ref<StyleBox> panel = get_stylebox("panel"); Size2 size = get_size(); if (!tabs_visible) { panel->draw(ci, Rect2( 0, 0, size.width, size.height)); return; } Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); Ref<Texture> incr = get_icon("increment"); Ref<Texture> decr = get_icon("decrement"); Ref<Texture> menu = get_icon("menu"); Ref<Texture> menu_hl = get_icon("menu_hl"); Ref<Font> font = get_font("font"); Color color_fg = get_color("font_color_fg"); Color color_bg = get_color("font_color_bg"); int side_margin = get_constant("side_margin"); int top_margin = _get_top_margin(); Size2 top_size = Size2( size.width, top_margin ); int w=0; int idx=0; Vector<int> offsets; Vector<Control*> controls; int from=0; int limit=get_size().width; if (popup) { top_size.width-=menu->get_width(); limit-=menu->get_width(); } bool notdone=false; last_tab_cache=-1; for(int i=0; i<get_child_count(); i++) { Control *c = get_child(i)->cast_to<Control>(); if (!c) continue; if (c->is_set_as_toplevel()) continue; if (idx<tab_display_ofs) { idx++; from=idx; continue; } if (w>=get_size().width) { buttons_visible_cache=true; notdone=true; break; } offsets.push_back(w); controls.push_back(c); String s = c->has_meta("_tab_name")?String(XL_MESSAGE(String(c->get_meta("_tab_name")))):String(c->get_name()); w+=font->get_string_size(s).width; if (c->has_meta("_tab_icon")) { Ref<Texture> icon = c->get_meta("_tab_icon"); if (icon.is_valid()) { w+=icon->get_width(); if (s!="") w+=get_constant("hseparation"); } } if (idx==current) { w+=tab_fg->get_minimum_size().width; } else { w+=tab_bg->get_minimum_size().width; } if (idx<tab_display_ofs) { } last_tab_cache=idx; idx++; } int ofs; switch(align) { case ALIGN_LEFT: ofs = side_margin; break; case ALIGN_CENTER: ofs = (int(limit) - w)/2; break; case ALIGN_RIGHT: ofs = int(limit) - w - side_margin; break; }; tab_display_ofs=0; tabs_ofs_cache=ofs; idx=0; for(int i=0; i<controls.size(); i++) { idx=i+from; if (current>=from && current<from+controls.size()-1) { //current is visible! draw it last. if (i==controls.size()-1) { idx=current; } else if (idx>=current) { idx+=1; } } Control *c = controls[idx-from]; String s = c->has_meta("_tab_name")?String(c->get_meta("_tab_name")):String(c->get_name()); int w=font->get_string_size(s).width; Ref<Texture> icon; if (c->has_meta("_tab_icon")) { icon = c->get_meta("_tab_icon"); if (icon.is_valid()) { w+=icon->get_width(); if (s!="") w+=get_constant("hseparation"); } } Ref<StyleBox> sb; Color col; if (idx==current) { sb=tab_fg; col=color_fg; } else { sb=tab_bg; col=color_bg; } int lofs = ofs + offsets[idx-from]; Size2i sb_ms = sb->get_minimum_size(); Rect2 sb_rect = Rect2( lofs, 0, w+sb_ms.width, top_margin); sb->draw(ci, sb_rect ); Point2i lpos = sb_rect.pos; lpos.x+=sb->get_margin(MARGIN_LEFT); if (icon.is_valid()) { icon->draw(ci, Point2i( lpos.x, sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-icon->get_height())/2 ) ); if (s!="") lpos.x+=icon->get_width()+get_constant("hseparation"); } font->draw(ci, Point2i( lpos.x, sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-font->get_height())/2+font->get_ascent() ), s, col ); idx++; } if (buttons_visible_cache) { int vofs = (top_margin-incr->get_height())/2; decr->draw(ci,Point2(limit,vofs),Color(1,1,1,tab_display_ofs==0?0.5:1.0)); incr->draw(ci,Point2(limit+incr->get_width(),vofs),Color(1,1,1,notdone?1.0:0.5)); } if (popup) { int from = get_size().width-menu->get_width(); if (mouse_x_cache > from) menu_hl->draw(get_canvas_item(),Size2(from,0)); else menu->draw(get_canvas_item(),Size2(from,0)); } panel->draw(ci, Rect2( 0, top_size.height, size.width, size.height-top_size.height)); } break; case NOTIFICATION_THEME_CHANGED: { if (get_tab_count() > 0) { call_deferred("set_current_tab",get_current_tab()); //wait until all changed theme } } break; } }
void TabContainer::_input_event(const InputEvent& p_event) { if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index==BUTTON_LEFT) { // clicks Point2 pos( p_event.mouse_button.x, p_event.mouse_button.y ); int top_margin = _get_top_margin(); if (pos.y>top_margin) return; // no click (too far down) if (pos.x<tabs_ofs_cache) return; // no click (too far left) Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); Ref<Font> font = get_font("font"); Ref<Texture> incr = get_icon("increment"); Ref<Texture> decr = get_icon("decrement"); Ref<Texture> menu = get_icon("menu"); Ref<Texture> menu_hl = get_icon("menu_hl"); if (popup && pos.x>get_size().width-menu->get_width()) { emit_signal("pre_popup_pressed"); Vector2 pp_pos = get_global_pos(); pp_pos.x+=get_size().width; pp_pos.x-=popup->get_size().width; pp_pos.y+=menu->get_height(); popup->set_global_pos( pp_pos ); popup->popup();; return; } pos.x-=tabs_ofs_cache; int idx=0; int found=-1; bool rightroom=false; for(int i=0; i<get_child_count(); i++) { Control *c = get_child(i)->cast_to<Control>(); if (!c) continue; if (c->is_set_as_toplevel()) continue; if (idx<tab_display_ofs) { idx++; continue; } if (idx>last_tab_cache) { rightroom=true; break; } String s = c->has_meta("_tab_name")?String(XL_MESSAGE(String(c->get_meta("_tab_name")))):String(c->get_name()); int tab_width=font->get_string_size(s).width; if (c->has_meta("_tab_icon")) { Ref<Texture> icon = c->get_meta("_tab_icon"); if (icon.is_valid()) { tab_width+=icon->get_width(); if (s!="") tab_width+=get_constant("hseparation"); } } if (idx==current) { tab_width+=tab_fg->get_minimum_size().width; } else { tab_width+=tab_bg->get_minimum_size().width; } if (pos.x < tab_width) { found=idx; break; } pos.x-=tab_width; idx++; } if (buttons_visible_cache) { if (p_event.mouse_button.x>get_size().width-incr->get_width()) { if (rightroom) { tab_display_ofs+=1; update(); } } else if (p_event.mouse_button.x>get_size().width-incr->get_width()-decr->get_width()) { if (tab_display_ofs>0) { tab_display_ofs-=1; update(); } } } if (found!=-1) { set_current_tab(found); } } }
void Button::_notification(int p_what) { if (p_what==NOTIFICATION_TRANSLATION_CHANGED) { xl_text=XL_MESSAGE(text); minimum_size_changed(); update(); } if (p_what==NOTIFICATION_DRAW) { RID ci = get_canvas_item(); Size2 size=get_size(); Color color; //print_line(get_text()+": "+itos(is_flat())+" hover "+itos(get_draw_mode())); Ref<StyleBox> style = get_stylebox("normal"); switch( get_draw_mode() ) { case DRAW_NORMAL: { style = get_stylebox("normal"); if (!flat) style->draw( ci, Rect2(Point2(0,0), size) ); color=get_color("font_color"); } break; case DRAW_PRESSED: { style = get_stylebox("pressed"); style->draw( ci, Rect2(Point2(0,0), size) ); if (has_color("font_color_pressed")) color=get_color("font_color_pressed"); else color=get_color("font_color"); } break; case DRAW_HOVER: { style = get_stylebox("hover"); style->draw( ci, Rect2(Point2(0,0), size) ); color=get_color("font_color_hover"); } break; case DRAW_DISABLED: { style = get_stylebox("disabled"); style->draw( ci, Rect2(Point2(0,0), size) ); color=get_color("font_color_disabled"); } break; } if (has_focus()) { Ref<StyleBox> style = get_stylebox("focus"); style->draw(ci,Rect2(Point2(),size)); } Ref<Font> font=get_font("font"); Ref<Texture> _icon; if (icon.is_null() && has_icon("icon")) _icon=Control::get_icon("icon"); else _icon=icon; Point2 icon_ofs = (!_icon.is_null())?Point2( _icon->get_width() + get_constant("hseparation"), 0):Point2(); int text_clip=size.width - style->get_minimum_size().width - icon_ofs.width; Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - font->get_string_size( xl_text ) )/2.0; switch(align) { case ALIGN_LEFT: { text_ofs.x = style->get_margin(MARGIN_LEFT) + icon_ofs.x; text_ofs.y+=style->get_offset().y; } break; case ALIGN_CENTER: { if (text_ofs.x<0) text_ofs.x=0; text_ofs+=icon_ofs; text_ofs+=style->get_offset(); } break; case ALIGN_RIGHT: { text_ofs.x=size.x - style->get_margin(MARGIN_RIGHT) - font->get_string_size( xl_text ).x; text_ofs.y+=style->get_offset().y; } break; } text_ofs.y+=font->get_ascent(); font->draw( ci, text_ofs.floor(), xl_text, color,clip_text?text_clip:-1); if (!_icon.is_null()) { int valign = size.height-style->get_minimum_size().y; _icon->draw(ci,style->get_offset()+Point2(0, Math::floor( (valign-_icon->get_height())/2.0 ) ),is_disabled()?Color(1,1,1,0.4):Color(1,1,1) ); } } }