void TextureFrame::_notification(int p_what) { if (p_what==NOTIFICATION_DRAW) { if (texture.is_null()) return; Size2 s=expand?get_size():texture->get_size(); RID ci = get_canvas_item(); draw_texture_rect(texture,Rect2(Point2(),s),false,modulate); /* Vector<Point2> points; points.resize(4); points[0]=Point2(0,0); points[1]=Point2(s.x,0); points[2]=Point2(s.x,s.y); points[3]=Point2(0,s.y); Vector<Point2> uvs; uvs.resize(4); uvs[0]=Point2(0,0); uvs[1]=Point2(1,0); uvs[2]=Point2(1,1); uvs[3]=Point2(0,1); VisualServer::get_singleton()->canvas_item_add_primitive(ci,points,Vector<Color>(),uvs,texture->get_rid()); */ } }
void MeshEditor::_notification(int p_what) { if (p_what==NOTIFICATION_FIXED_PROCESS) { } if (p_what==NOTIFICATION_READY) { //get_scene()->connect("node_removed",this,"_node_removed"); if (first_enter) { //it's in propertyeditor so.. could be moved around light_1_switch->set_normal_texture(get_icon("MaterialPreviewLight1","EditorIcons")); light_1_switch->set_pressed_texture(get_icon("MaterialPreviewLight1Off","EditorIcons")); light_2_switch->set_normal_texture(get_icon("MaterialPreviewLight2","EditorIcons")); light_2_switch->set_pressed_texture(get_icon("MaterialPreviewLight2Off","EditorIcons")); first_enter=false; } } if (p_what==NOTIFICATION_DRAW) { Ref<Texture> checkerboard = get_icon("Checkerboard","EditorIcons"); Size2 size = get_size(); draw_texture_rect(checkerboard,Rect2(Point2(),size),true); } }
void ViewportContainer::_notification(int p_what) { if (p_what == NOTIFICATION_RESIZED) { if (!stretch) return; for (int i = 0; i < get_child_count(); i++) { Viewport *c = Object::cast_to<Viewport>(get_child(i)); if (!c) continue; c->set_size(get_size() / shrink); } } if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_VISIBILITY_CHANGED) { for (int i = 0; i < get_child_count(); i++) { Viewport *c = Object::cast_to<Viewport>(get_child(i)); if (!c) continue; if (is_visible_in_tree()) c->set_update_mode(Viewport::UPDATE_ALWAYS); else c->set_update_mode(Viewport::UPDATE_DISABLED); } } if (p_what == NOTIFICATION_DRAW) { for (int i = 0; i < get_child_count(); i++) { Viewport *c = Object::cast_to<Viewport>(get_child(i)); if (!c) continue; if (stretch) draw_texture_rect(c->get_texture(), Rect2(Vector2(), get_size() * Size2(1, -1))); else draw_texture_rect(c->get_texture(), Rect2(Vector2(), c->get_size() * Size2(1, -1))); } } }
void ColorPickerButton::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { Ref<StyleBox> normal = get_stylebox("normal"); Rect2 r = Rect2(normal->get_offset(), get_size() - normal->get_minimum_size()); draw_texture_rect(Control::get_icon("bg", "ColorPickerButton"), r, true); draw_rect(r, color); } if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST && popup) { popup->hide(); } }
void VideoPlayer::_notification(int p_notification) { switch (p_notification) { case NOTIFICATION_ENTER_SCENE: { //set_idle_process(false); //don't annoy if (stream.is_valid() && autoplay && !get_scene()->is_editor_hint()) play(); } break; case NOTIFICATION_PROCESS: { if (stream.is_null()) return; if (paused) return; while (stream->get_pending_frame_count()) { Image img = stream->pop_frame(); if (texture->get_width() == 0) { texture->create(img.get_width(),img.get_height(),img.get_format(),Texture::FLAG_VIDEO_SURFACE|Texture::FLAG_FILTER); update(); minimum_size_changed(); } else { if (stream->get_pending_frame_count() == 0) texture->set_data(img); }; }; } break; case NOTIFICATION_DRAW: { if (texture.is_null()) return; if (texture->get_width() == 0) return; Size2 s=expand?get_size():texture->get_size(); RID ci = get_canvas_item(); printf("drawing with size %f, %f\n", s.x, s.y); draw_texture_rect(texture,Rect2(Point2(),s),false); } break; }; };
void TextureButton::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { DrawMode draw_mode = get_draw_mode(); Ref<Texture> texdraw; switch (draw_mode) { case DRAW_NORMAL: { if (normal.is_valid()) texdraw = normal; } break; case DRAW_PRESSED: { if (pressed.is_null()) { if (hover.is_null()) { if (normal.is_valid()) texdraw = normal; } else texdraw = hover; } else texdraw = pressed; } break; case DRAW_HOVER: { if (hover.is_null()) { if (pressed.is_valid() && is_pressed()) texdraw = pressed; else if (normal.is_valid()) texdraw = normal; } else texdraw = hover; } break; case DRAW_DISABLED: { if (disabled.is_null()) { if (normal.is_valid()) texdraw = normal; } else texdraw = disabled; } break; } if (texdraw.is_valid()) { Point2 ofs; Size2 size = texdraw->get_size(); Rect2 tex_regin = Rect2(Point2(), texdraw->get_size()); bool tile = false; if (expand) { switch (stretch_mode) { case STRETCH_KEEP: size = texdraw->get_size(); break; case STRETCH_SCALE: size = get_size(); break; case STRETCH_TILE: size = get_size(); tile = true; break; case STRETCH_KEEP_CENTERED: ofs = (get_size() - texdraw->get_size()) / 2; size = texdraw->get_size(); break; case STRETCH_KEEP_ASPECT_CENTERED: case STRETCH_KEEP_ASPECT: { Size2 _size = get_size(); float tex_width = texdraw->get_width() * _size.height / texdraw->get_height(); float tex_height = _size.height; if (tex_width > _size.width) { tex_width = _size.width; tex_height = texdraw->get_height() * tex_width / texdraw->get_width(); } if (stretch_mode == STRETCH_KEEP_ASPECT_CENTERED) { ofs.x = (_size.width - tex_width) / 2; ofs.y = (_size.height - tex_height) / 2; } size.width = tex_width; size.height = tex_height; } break; case STRETCH_KEEP_ASPECT_COVERED: { size = get_size(); Size2 tex_size = texdraw->get_size(); Size2 scaleSize(size.width / tex_size.width, size.height / tex_size.height); float scale = scaleSize.width > scaleSize.height ? scaleSize.width : scaleSize.height; Size2 scaledTexSize = tex_size * scale; Point2 ofs = ((scaledTexSize - size) / scale).abs() / 2.0f; tex_regin = Rect2(ofs, size / scale); } break; } } if (tile) draw_texture_rect(texdraw, Rect2(ofs, size), tile); else draw_texture_rect_region(texdraw, Rect2(ofs, size), tex_regin); } if (has_focus() && focused.is_valid()) { Rect2 drect(Point2(), get_size()); draw_texture_rect(focused, drect, false); }; } break; } }
void TextureButton::_notification(int p_what) { switch( p_what ) { case NOTIFICATION_DRAW: { RID canvas_item = get_canvas_item(); DrawMode draw_mode = get_draw_mode(); // if (normal.is_null()) // break; Ref<Texture> texdraw; switch (draw_mode) { case DRAW_NORMAL: { if (normal.is_valid()) texdraw=normal; } break; case DRAW_PRESSED: { if (pressed.is_null()) { if (hover.is_null()) { if (normal.is_valid()) texdraw=normal; } else texdraw=hover; } else texdraw=pressed; } break; case DRAW_HOVER: { if (hover.is_null()) { if (pressed.is_valid() && is_pressed()) texdraw=pressed; else if (normal.is_valid()) texdraw=normal; } else texdraw=hover; } break; case DRAW_DISABLED: { if (disabled.is_null()) { if (normal.is_valid()) texdraw=normal; } else texdraw=disabled; } break; } if (texdraw.is_valid()) { Rect2 drect(Point2(),texdraw->get_size()*scale); draw_texture_rect(texdraw,drect,false,modulate); } if (has_focus() && focused.is_valid()) { Rect2 drect(Point2(),focused->get_size()*scale); draw_texture_rect(focused,drect,false,modulate); }; } break; } }
void ItemList::_notification(int p_what) { if (p_what == NOTIFICATION_RESIZED) { shape_changed = true; update(); } if (p_what == NOTIFICATION_DRAW) { Ref<StyleBox> bg = get_stylebox("bg"); int mw = scroll_bar->get_minimum_size().x; scroll_bar->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -mw); scroll_bar->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); scroll_bar->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, bg->get_margin(MARGIN_TOP)); scroll_bar->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -bg->get_margin(MARGIN_BOTTOM)); Size2 size = get_size(); int width = size.width - bg->get_minimum_size().width; if (scroll_bar->is_visible()) { width -= mw + bg->get_margin(MARGIN_RIGHT); } draw_style_box(bg, Rect2(Point2(), size)); int hseparation = get_constant("hseparation"); int vseparation = get_constant("vseparation"); int icon_margin = get_constant("icon_margin"); int line_separation = get_constant("line_separation"); Ref<StyleBox> sbsel = has_focus() ? get_stylebox("selected_focus") : get_stylebox("selected"); Ref<StyleBox> cursor = has_focus() ? get_stylebox("cursor") : get_stylebox("cursor_unfocused"); Ref<Font> font = get_font("font"); Color guide_color = get_color("guide_color"); Color font_color = get_color("font_color"); Color font_color_selected = get_color("font_color_selected"); int font_height = font->get_height(); Vector<int> line_size_cache; Vector<int> line_limit_cache; if (max_text_lines) { line_size_cache.resize(max_text_lines); line_limit_cache.resize(max_text_lines); } if (has_focus()) { draw_style_box(get_stylebox("bg_focus"), Rect2(Point2(), size)); } if (shape_changed) { float max_column_width = 0; //1- compute item minimum sizes for (int i = 0; i < items.size(); i++) { Size2 minsize; if (items[i].icon.is_valid()) { if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) { minsize = fixed_icon_size * icon_scale; } else { minsize = items[i].get_icon_size() * icon_scale; } if (items[i].text != "") { if (icon_mode == ICON_MODE_TOP) { minsize.y += icon_margin; } else { minsize.x += icon_margin; } } } if (items[i].text != "") { Size2 s = font->get_string_size(items[i].text); //s.width=MIN(s.width,fixed_column_width); if (icon_mode == ICON_MODE_TOP) { minsize.x = MAX(minsize.x, s.width); if (max_text_lines > 0) { minsize.y += (font_height + line_separation) * max_text_lines; } else { minsize.y += s.height; } } else { minsize.y = MAX(minsize.y, s.height); minsize.x += s.width; } } if (fixed_column_width > 0) minsize.x = fixed_column_width; max_column_width = MAX(max_column_width, minsize.x); // elements need to adapt to the selected size minsize.y += vseparation; minsize.x += hseparation; items[i].rect_cache.size = minsize; items[i].min_rect_cache.size = minsize; } int fit_size = size.x - bg->get_minimum_size().width - mw; //2-attempt best fit current_columns = 0x7FFFFFFF; if (max_columns > 0) current_columns = max_columns; while (true) { //repeat util all fits bool all_fit = true; Vector2 ofs; int col = 0; int max_h = 0; separators.clear(); for (int i = 0; i < items.size(); i++) { if (current_columns > 1 && items[i].rect_cache.size.width + ofs.x > fit_size) { //went past current_columns = MAX(col, 1); all_fit = false; break; } if (same_column_width) items[i].rect_cache.size.x = max_column_width; items[i].rect_cache.position = ofs; max_h = MAX(max_h, items[i].rect_cache.size.y); ofs.x += items[i].rect_cache.size.x + hseparation; col++; if (col == current_columns) { if (i < items.size() - 1) separators.push_back(ofs.y + max_h + vseparation / 2); for (int j = i; j >= 0 && col > 0; j--, col--) { items[j].rect_cache.size.y = max_h; } ofs.x = 0; ofs.y += max_h + vseparation; col = 0; max_h = 0; } } for (int j = items.size() - 1; j >= 0 && col > 0; j--, col--) { items[j].rect_cache.size.y = max_h; } if (all_fit) { float page = size.height - bg->get_minimum_size().height; float max = MAX(page, ofs.y + max_h); if (auto_height) auto_height_value = ofs.y + max_h + bg->get_minimum_size().height; scroll_bar->set_max(max); scroll_bar->set_page(page); if (max <= page) { scroll_bar->set_value(0); scroll_bar->hide(); } else { scroll_bar->show(); } break; } } shape_changed = false; } //ensure_selected_visible needs to be checked before we draw the list. if (ensure_selected_visible && current >= 0 && current <= items.size()) { Rect2 r = items[current].rect_cache; int from = scroll_bar->get_value(); int to = from + scroll_bar->get_page(); if (r.position.y < from) { scroll_bar->set_value(r.position.y); } else if (r.position.y + r.size.y > to) { scroll_bar->set_value(r.position.y + r.size.y - (to - from)); } } ensure_selected_visible = false; Vector2 base_ofs = bg->get_offset(); base_ofs.y -= int(scroll_bar->get_value()); Rect2 clip(Point2(), size - bg->get_minimum_size() + Vector2(0, scroll_bar->get_value())); for (int i = 0; i < items.size(); i++) { Rect2 rcache = items[i].rect_cache; if (!clip.intersects(rcache)) continue; if (current_columns == 1) { rcache.size.width = width - rcache.position.x; } if (items[i].selected) { Rect2 r = rcache; r.position += base_ofs; r.position.y -= vseparation / 2; r.size.y += vseparation; r.position.x -= hseparation / 2; r.size.x += hseparation; draw_style_box(sbsel, r); } if (items[i].custom_bg.a > 0.001) { Rect2 r = rcache; r.position += base_ofs; // Size rect to make the align the temperature colors r.position.y -= vseparation / 2; r.size.y += vseparation; r.position.x -= hseparation / 2; r.size.x += hseparation; draw_rect(r, items[i].custom_bg); } Vector2 text_ofs; if (items[i].icon.is_valid()) { Size2 icon_size; //= _adjust_to_max_size(items[i].get_icon_size(),fixed_icon_size) * icon_scale; if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) { icon_size = fixed_icon_size * icon_scale; } else { icon_size = items[i].get_icon_size() * icon_scale; } Vector2 icon_ofs; Point2 pos = items[i].rect_cache.position + icon_ofs + base_ofs; if (icon_mode == ICON_MODE_TOP) { pos.x += Math::floor((items[i].rect_cache.size.width - icon_size.width) / 2); pos.y += MIN( Math::floor((items[i].rect_cache.size.height - icon_size.height) / 2), items[i].rect_cache.size.height - items[i].min_rect_cache.size.height); text_ofs.y = icon_size.height + icon_margin; text_ofs.y += items[i].rect_cache.size.height - items[i].min_rect_cache.size.height; } else { pos.y += Math::floor((items[i].rect_cache.size.height - icon_size.height) / 2); text_ofs.x = icon_size.width + icon_margin; } Rect2 draw_rect = Rect2(pos, icon_size); if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) { Rect2 adj = _adjust_to_max_size(items[i].get_icon_size() * icon_scale, icon_size); draw_rect.position += adj.position; draw_rect.size = adj.size; } Color modulate = Color(1, 1, 1, 1); if (items[i].disabled) modulate.a *= 0.5; if (items[i].icon_region.has_no_area()) draw_texture_rect(items[i].icon, draw_rect, false, modulate); else draw_texture_rect_region(items[i].icon, draw_rect, items[i].icon_region, modulate); } if (items[i].tag_icon.is_valid()) { draw_texture(items[i].tag_icon, items[i].rect_cache.position + base_ofs); } if (items[i].text != "") { int max_len = -1; Vector2 size = font->get_string_size(items[i].text); if (fixed_column_width) max_len = fixed_column_width; else if (same_column_width) max_len = items[i].rect_cache.size.x; else max_len = size.x; Color modulate = items[i].selected ? font_color_selected : (items[i].custom_fg != Color() ? items[i].custom_fg : font_color); if (items[i].disabled) modulate.a *= 0.5; if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) { int ss = items[i].text.length(); float ofs = 0; int line = 0; for (int j = 0; j <= ss; j++) { int cs = j < ss ? font->get_char_size(items[i].text[j], items[i].text[j + 1]).x : 0; if (ofs + cs > max_len || j == ss) { line_limit_cache[line] = j; line_size_cache[line] = ofs; line++; ofs = 0; if (line >= max_text_lines) break; } else { ofs += cs; } } line = 0; ofs = 0; text_ofs.y += font->get_ascent(); text_ofs = text_ofs.floor(); text_ofs += base_ofs; text_ofs += items[i].rect_cache.position; for (int j = 0; j < ss; j++) { if (j == line_limit_cache[line]) { line++; ofs = 0; if (line >= max_text_lines) break; } ofs += font->draw_char(get_canvas_item(), text_ofs + Vector2(ofs + (max_len - line_size_cache[line]) / 2, line * (font_height + line_separation)).floor(), items[i].text[j], items[i].text[j + 1], modulate); } //special multiline mode } else { if (fixed_column_width > 0) size.x = MIN(size.x, fixed_column_width); if (icon_mode == ICON_MODE_TOP) { text_ofs.x += (items[i].rect_cache.size.width - size.x) / 2; } else { text_ofs.y += (items[i].rect_cache.size.height - size.y) / 2; } text_ofs.y += font->get_ascent(); text_ofs = text_ofs.floor(); text_ofs += base_ofs; text_ofs += items[i].rect_cache.position; draw_string(font, text_ofs, items[i].text, modulate, max_len + 1); } } if (select_mode == SELECT_MULTI && i == current) { Rect2 r = rcache; r.position += base_ofs; r.position.y -= vseparation / 2; r.size.y += vseparation; r.position.x -= hseparation / 2; r.size.x += hseparation; draw_style_box(cursor, r); } } for (int i = 0; i < separators.size(); i++) { draw_line(Vector2(bg->get_margin(MARGIN_LEFT), base_ofs.y + separators[i]), Vector2(size.width - bg->get_margin(MARGIN_RIGHT), base_ofs.y + separators[i]), guide_color); } } }