Beispiel #1
0
void GraphNode::_notification(int p_what) {

	if (p_what==NOTIFICATION_DRAW) {

		Ref<StyleBox> sb=get_stylebox("frame");
		Ref<Texture> port =get_icon("port");
		Ref<Texture> close =get_icon("close");
		int close_offset = get_constant("close_offset");
		Ref<Font> title_font = get_font("title_font");
		int title_offset = get_constant("title_offset");
		Color title_color = get_color("title_color");
		Point2i icofs = -port->get_size()*0.5;
		int edgeofs=get_constant("port_offset");
		icofs.y+=sb->get_margin(MARGIN_TOP);
		draw_style_box(sb,Rect2(Point2(),get_size()));

		int w = get_size().width-sb->get_minimum_size().x;

		if (show_close)
			w-=close->get_width();

		draw_string(title_font,Point2(sb->get_margin(MARGIN_LEFT),-title_font->get_height()+title_font->get_ascent()+title_offset),title,title_color,w);
		if (show_close) {
			Vector2 cpos = Point2(w+sb->get_margin(MARGIN_LEFT),-close->get_height()+close_offset);
			draw_texture(close,cpos);
			close_rect.pos=cpos;
			close_rect.size=close->get_size();
		} else {
			close_rect=Rect2();
		}

		for (Map<int,Slot>::Element *E=slot_info.front();E;E=E->next()) {

			if (E->key() < 0 || E->key()>=cache_y.size())
				continue;
			if (!slot_info.has(E->key()))
				continue;
			const Slot &s=slot_info[E->key()];
			//left
			if (s.enable_left)
				port->draw(get_canvas_item(),icofs+Point2(edgeofs,cache_y[E->key()]),s.color_left);
			if (s.enable_right)
				port->draw(get_canvas_item(),icofs+Point2(get_size().x-edgeofs,cache_y[E->key()]),s.color_right);

		}
	}

	if (p_what==NOTIFICATION_SORT_CHILDREN) {

		_resort();
	}

}
Beispiel #2
0
void Node2D::set_z_as_relative(bool p_enabled) {

	if (z_relative==p_enabled)
		return;
	z_relative=p_enabled;
	VS::get_singleton()->canvas_item_set_z_as_relative_to_parent(get_canvas_item(),p_enabled);
}
Beispiel #3
0
void CallDialog::_notification(int p_what) {
	
	if (p_what==NOTIFICATION_READY) {
		
		call->connect("pressed", this,"_call");
		cancel->connect("pressed", this,"_cancel");
		//filter->get_path()->connect("text_changed", this,"_text_changed");
		_update_method_list();
	}

	if (p_what==NOTIFICATION_EXIT_TREE) {

		call->disconnect("pressed", this,"_call");
		cancel->disconnect("pressed", this,"_cancel");

		//filter->get_path()->connect("text_changed", this,"_text_changed");
		_update_method_list();
	}

	if (p_what==NOTIFICATION_DRAW) {
		
		RID ci = get_canvas_item();
		get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));		
	}	
}
Beispiel #4
0
void SpinBox::_notification(int p_what) {

	if (p_what == NOTIFICATION_DRAW) {

		Ref<Texture> updown = get_icon("updown");

		int w = updown->get_width();
		if (w != last_w) {
			line_edit->set_margin(MARGIN_RIGHT, -w);
			last_w = w;
		}

		RID ci = get_canvas_item();
		Size2i size = get_size();

		updown->draw(ci, Point2i(size.width - updown->get_width(), (size.height - updown->get_height()) / 2));

	} else if (p_what == NOTIFICATION_FOCUS_EXIT) {

		//_value_changed(0);
	} else if (p_what == NOTIFICATION_ENTER_TREE) {

		_value_changed(0);
	}
}
Beispiel #5
0
void CheckButton::_notification(int p_what) {

	if (p_what == NOTIFICATION_THEME_CHANGED) {

		_set_internal_margin(MARGIN_RIGHT, get_icon_size().width);
	} else if (p_what == NOTIFICATION_DRAW) {

		RID ci = get_canvas_item();

		Ref<Texture> on = Control::get_icon("on");
		Ref<Texture> off = Control::get_icon("off");

		Ref<StyleBox> sb = get_stylebox("normal");
		Vector2 ofs;
		Size2 tex_size = get_icon_size();

		ofs.x = get_size().width - (tex_size.width + sb->get_margin(MARGIN_RIGHT));
		ofs.y = (get_size().height - tex_size.height) / 2;

		if (is_pressed())
			on->draw(ci, ofs);
		else
			off->draw(ci, ofs);
	}
}
Beispiel #6
0
void WindowDialog::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_DRAW: {

			RID ci = get_canvas_item();
			Size2 s = get_size();
			Ref<StyleBox> st = get_stylebox("panel","WindowDialog");
			st->draw(ci,Rect2(Point2(),s));
			int th = get_constant("title_height","WindowDialog");
			Color tc = get_color("title_color","WindowDialog");
			Ref<Font> font = get_font("title_font","WindowDialog");
			int ofs = (s.width-font->get_string_size(title).width)/2;
			//int ofs = st->get_margin(MARGIN_LEFT);
			draw_string(font,Point2(ofs,-th+font->get_ascent()),title,tc,s.width - st->get_minimum_size().width);


		} break;
		case NOTIFICATION_THEME_CHANGED:
		case NOTIFICATION_ENTER_TREE: {

			close_button->set_normal_texture( get_icon("close","WindowDialog"));
			close_button->set_pressed_texture( get_icon("close","WindowDialog"));
			close_button->set_hover_texture( get_icon("close_hilite","WindowDialog"));
			close_button->set_anchor(MARGIN_LEFT,ANCHOR_END);
			close_button->set_begin( Point2( get_constant("close_h_ofs","WindowDialog"), -get_constant("close_v_ofs","WindowDialog") ));

		} break;
	}

}
Beispiel #7
0
void Slider::_notification(int p_what) {


	switch(p_what) {

		case NOTIFICATION_MOUSE_ENTER: {

			mouse_inside=true;
			update();
		} break;
		case NOTIFICATION_MOUSE_EXIT: {

			mouse_inside=false;
			update();
		} break;
		case NOTIFICATION_DRAW: {
			RID ci = get_canvas_item();
			Size2i size = get_size();
			Ref<StyleBox> style = get_stylebox("slider");
			Ref<StyleBox> focus = get_stylebox("focus");
			Ref<Texture> grabber = get_icon(mouse_inside||has_focus()?"grabber_hilite":"grabber");
			Ref<Texture> tick = get_icon("tick");

			if (orientation==VERTICAL) {

				style->draw(ci,Rect2i(Point2i(),Size2i(style->get_minimum_size().width+style->get_center_size().width,size.height)));
				//if (mouse_inside||has_focus())
				//	focus->draw(ci,Rect2i(Point2i(),Size2i(style->get_minimum_size().width+style->get_center_size().width,size.height)));
				float areasize = size.height - grabber->get_size().height;
				if (ticks>1) {
					int tickarea = size.height - tick->get_height();
					for(int i=0;i<ticks;i++) {
					        if( ! ticks_on_borders && (i == 0 || i + 1 == ticks) ) continue;
						int ofs = i*tickarea/(ticks-1);
						tick->draw(ci,Point2(0,ofs));
					}

				}
				grabber->draw(ci,Point2i(size.width/2-grabber->get_size().width/2,size.height - get_unit_value()*areasize - grabber->get_size().height));
			} else {
				style->draw(ci,Rect2i(Point2i(),Size2i(size.width,style->get_minimum_size().height+style->get_center_size().height)));
				//if (mouse_inside||has_focus())
				//	focus->draw(ci,Rect2i(Point2i(),Size2i(size.width,style->get_minimum_size().height+style->get_center_size().height)));

				float areasize = size.width - grabber->get_size().width;
				if (ticks>1) {
					int tickarea = size.width - tick->get_width();
					for(int i=0;i<ticks;i++) {
					        if( (! ticks_on_borders) && ( (i == 0) || ((i + 1) == ticks)) ) continue;
						int ofs = i*tickarea/(ticks-1);
						tick->draw(ci,Point2(ofs,0));
					}

				}
				grabber->draw(ci,Point2i(get_unit_value()*areasize,size.height/2-grabber->get_size().height/2));
			}

		} break;
	}
}
Beispiel #8
0
void OptionButton::_notification(int p_what) {

	if (p_what == NOTIFICATION_DRAW) {

		if (!has_icon("arrow"))
			return;

		RID ci = get_canvas_item();
		Ref<Texture> arrow = Control::get_icon("arrow");
		Ref<StyleBox> normal = get_stylebox("normal");
		Color clr = Color(1, 1, 1);
		if (get_constant("modulate_arrow")) {
			switch (get_draw_mode()) {
				case DRAW_PRESSED:
					clr = get_color("font_color_pressed");
					break;
				case DRAW_HOVER:
					clr = get_color("font_color_hover");
					break;
				case DRAW_DISABLED:
					clr = get_color("font_color_disabled");
					break;
				default:
					clr = get_color("font_color");
			}
		}

		Size2 size = get_size();

		Point2 ofs(size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2)));
		arrow->draw(ci, ofs, clr);
	}
}
Beispiel #9
0
void PopupPanel::_notification(int p_what) {

	if (p_what == NOTIFICATION_DRAW) {

		get_stylebox("panel")->draw(get_canvas_item(), Rect2(Point2(), get_size()));
	}
}
Beispiel #10
0
void GraphEdit::_notification(int p_what) {

	if (p_what==NOTIFICATION_READY) {
		Size2 hmin = h_scroll->get_combined_minimum_size();
		Size2 vmin = v_scroll->get_combined_minimum_size();

		v_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,vmin.width);
		v_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0);
		v_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,0);
		v_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0);

		h_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,0);
		h_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0);
		h_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,hmin.height);
		h_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0);

	}
	if (p_what==NOTIFICATION_DRAW) {
		VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);

	}

	if (p_what==NOTIFICATION_RESIZED) {
		_update_scroll();
		top_layer->update();
	}
}
Beispiel #11
0
void Particles2D::_notification(int p_what) {

	if (p_what == NOTIFICATION_DRAW) {

		RID texture_rid;
		if (texture.is_valid())
			texture_rid = texture->get_rid();
		RID normal_rid;
		if (normal_map.is_valid())
			normal_rid = texture->get_rid();

		VS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid, normal_rid, h_frames, v_frames);

#ifdef TOOLS_ENABLED
		if (Engine::get_singleton()->is_editor_hint() && (this == get_tree()->get_edited_scene_root() || get_tree()->get_edited_scene_root()->is_a_parent_of(this))) {

			draw_rect(visibility_rect, Color(0, 0.7, 0.9, 0.4), false);
		}
#endif
	}

	if (p_what == NOTIFICATION_PAUSED || p_what == NOTIFICATION_UNPAUSED) {
		if (can_process()) {
			VS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
		} else {

			VS::get_singleton()->particles_set_speed_scale(particles, 0);
		}
	}

	if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
		_update_particle_emission_transform();
	}
}
Beispiel #12
0
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());
*/
	}
}
Beispiel #13
0
void ProgressBar::_notification(int p_what) {


	if (p_what==NOTIFICATION_DRAW) {

		Ref<StyleBox> bg = get_stylebox("bg");
		Ref<StyleBox> fg = get_stylebox("fg");
		Ref<Font> font = get_font("font");
		Color font_color=get_color("font_color");
		Color font_color_shadow=get_color("font_color_shadow");

		draw_style_box(bg,Rect2(Point2(),get_size()));
		float r = get_unit_value();
		int mp = fg->get_minimum_size().width;
		int p = r*get_size().width-mp;
		if (p>0) {

			draw_style_box(fg,Rect2(Point2(),Size2(p+fg->get_minimum_size().width,get_size().height)));
		}

		int fh=font->get_height();
		String txt=itos(int(get_unit_value()*100))+"%";
		font->draw_halign(get_canvas_item(),Point2(0,font->get_ascent()+(get_size().height-font->get_height())/2),HALIGN_CENTER,get_size().width,txt,font_color);
	}
}
Beispiel #14
0
void NinePatchRect::_notification(int p_what) {

	if (p_what==NOTIFICATION_DRAW) {

		if (texture.is_null())
			return;

		Size2 s=get_size();
		RID ci = get_canvas_item();
		VS::get_singleton()->canvas_item_add_nine_patch(ci,Rect2(Point2(),s),region_rect,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),VS::NINE_PATCH_STRETCH,VS::NINE_PATCH_STRETCH,draw_center);
		//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());
*/
	}
}
Beispiel #15
0
void CanvasItem::_update_callback() {



	if (!is_inside_tree()) {
		pending_update=false;
		return;
	}

	VisualServer::get_singleton()->canvas_item_clear(get_canvas_item());
	//todo updating = true - only allow drawing here
	if (is_visible()) { //todo optimize this!!
		if (first_draw) {
			notification(NOTIFICATION_VISIBILITY_CHANGED);
			first_draw=false;
		}
		drawing=true;
		notification(NOTIFICATION_DRAW);
		emit_signal(SceneStringNames::get_singleton()->draw);
		if (get_script_instance()) {
			Variant::CallError err;
			get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_draw,NULL,0);
		}
		drawing=false;

	}
	//todo updating = false
	pending_update=false; // don't change to false until finished drawing (avoid recursive update)
}
Beispiel #16
0
void ViewportSprite::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_TREE: {

			if (!viewport_path.is_empty()) {

				Node *n = get_node(viewport_path);
				ERR_FAIL_COND(!n);
				Viewport *vp=n->cast_to<Viewport>();
				ERR_FAIL_COND(!vp);

				Ref<RenderTargetTexture> rtt = vp->get_render_target_texture();
				texture=rtt;
				texture->connect("changed",this,"update");
				item_rect_changed();
			}
		} break;
		case NOTIFICATION_EXIT_TREE: {

			if (texture.is_valid()) {

				texture->disconnect("changed",this,"update");
				texture=Ref<Texture>();
			}
		} break;
		case NOTIFICATION_DRAW: {

			if (texture.is_null())
				return;

			RID ci = get_canvas_item();

			/*
			texture->draw(ci,Point2());
			break;
			*/

			Size2i s;
			Rect2i src_rect;

			s = texture->get_size();

			src_rect.size=s;

			Point2 ofs=offset;
			if (centered)
				ofs-=s/2;

			if (OS::get_singleton()->get_use_pixel_snap()) {
				ofs=ofs.floor();
			}
			Rect2 dst_rect(ofs,s);
			texture->draw_rect_region(ci,dst_rect,src_rect,modulate);

		} break;
	}
}
void ShaderEditor::_notification(int p_what) {


	switch(p_what) {

		case NOTIFICATION_DRAW: {

			_update_scrollbars();
			//VisualServer::get_singleton()->canvas_item_add_rect(get_canvas_item(),Rect2(Point2(),get_size()),Color(0,0,0,1));

			for(List<int>::Element *E=order.front();E;E=E->next()) {

				_draw_node(E->get());
			}

			if (click_type==CLICK_INPUT_SLOT || click_type==CLICK_OUTPUT_SLOT) {

				VisualServer::get_singleton()->canvas_item_add_line(get_canvas_item(),click_pos,click_motion,Color(0.5,1,0.5,0.8),2);
			}

			List<ShaderGraph::Connection> connections = shader_graph.get_connection_list();
			for(List<ShaderGraph::Connection>::Element *E=connections.front();E;E=E->next()) {

				const ShaderGraph::Connection &c=E->get();
				Point2 source = _get_slot_pos(c.src_id,false,c.src_slot);
				Point2 dest = _get_slot_pos(c.dst_id,true,c.dst_slot);
				bool vec = VisualServer::shader_is_input_vector( shader_graph.node_get_type(c.dst_id), c.dst_slot );
				Color col = vec?Color(1,0.5,0.5,0.8):Color(1,1,0.5,0.8);

				if (click_type==CLICK_NODE && click_node==c.src_id) {

					source+=click_motion-click_pos;
				}

				if (click_type==CLICK_NODE && click_node==c.dst_id) {

					dest+=click_motion-click_pos;
				}

				VisualServer::get_singleton()->canvas_item_add_line(get_canvas_item(),source,dest,col,2);

			}
		} break;
	}

}
Beispiel #18
0
void Node2D::set_z_index(int p_z) {

	ERR_FAIL_COND(p_z < VS::CANVAS_ITEM_Z_MIN);
	ERR_FAIL_COND(p_z > VS::CANVAS_ITEM_Z_MAX);
	z_index = p_z;
	VS::get_singleton()->canvas_item_set_z_index(get_canvas_item(), z_index);
	_change_notify("z_index");
}
Beispiel #19
0
void Node2D::set_z(int p_z) {

	ERR_FAIL_COND(p_z<VS::CANVAS_ITEM_Z_MIN);
	ERR_FAIL_COND(p_z>VS::CANVAS_ITEM_Z_MAX);
	z=p_z;
	VS::get_singleton()->canvas_item_set_z(get_canvas_item(),z);

}
Beispiel #20
0
void ConnectDialog::_notification(int p_what) {
	
	if (p_what==NOTIFICATION_DRAW) {
		
		RID ci = get_canvas_item();
		get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));		
	}	
}
Beispiel #21
0
void TileMap::set_y_sort_mode(bool p_enable) {

	_clear_quadrants();
	y_sort_mode=p_enable;
	VS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(),y_sort_mode);
	_recreate_quadrants();
	emit_signal("settings_changed");

}
Beispiel #22
0
void Panel::_notification(int p_what) {

	if (p_what == NOTIFICATION_DRAW) {

		RID ci = get_canvas_item();
		Ref<StyleBox> style = get_stylebox("panel");
		style->draw(ci, Rect2(Point2(), get_size()));
	}
}
Beispiel #23
0
void Sprite::_notification(int p_what) {

    switch(p_what) {

    case NOTIFICATION_DRAW: {

        if (texture.is_null())
            return;




        RID ci = get_canvas_item();

        /*
        texture->draw(ci,Point2());
        break;
        */

        Size2 s;
        Rect2 src_rect;

        if (region) {

            s=region_rect.size;
            src_rect=region_rect;
        } else {
            s = Size2(texture->get_size());
            s=s/Size2(hframes,vframes);

            src_rect.size=s;
            src_rect.pos.x+=float(frame%hframes)*s.x;
            src_rect.pos.y+=float(frame/hframes)*s.y;

        }

        Point2 ofs=offset;
        if (centered)
            ofs-=s/2;
        if (OS::get_singleton()->get_use_pixel_snap()) {
            ofs=ofs.floor();
        }

        Rect2 dst_rect(ofs,s);

        if (hflip)
            dst_rect.size.x=-dst_rect.size.x;
        if (vflip)
            dst_rect.size.y=-dst_rect.size.y;

        texture->draw_rect_region(ci,dst_rect,src_rect,modulate);

    }
    break;
    }
}
void BackBufferCopy::_update_copy_mode() {

	switch(copy_mode) {

		case COPY_MODE_DISABLED: {

			VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),false,Rect2());
		} break;
		case COPY_MODE_RECT: {

			VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),true,rect);
		} break;
		case COPY_MODE_VIEWPORT: {

			VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),true,Rect2());

		} break;

	}
}
Beispiel #25
0
void Separator::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_DRAW: {

			Size2i size = get_size();
			Ref<StyleBox> style = get_stylebox("separator");
			Size2i ssize = style->get_minimum_size() + style->get_center_size();

			if (orientation == VERTICAL) {

				style->draw(get_canvas_item(), Rect2((size.x - ssize.x) / 2, 0, ssize.x, size.y));
			} else {

				style->draw(get_canvas_item(), Rect2(0, (size.y - ssize.y) / 2, size.x, ssize.y));
			}

		} break;
	}
}
Beispiel #26
0
void Node2D::set_transform(const Matrix32& p_transform) {

	_mat=p_transform;
	_xform_dirty=true;

	VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(),_mat);

	if (!is_inside_tree())
		return;

	_notify_transform();
}
Beispiel #27
0
void Node2D::_update_transform() {

	_mat.set_rotation_and_scale(angle, _scale);
	_mat.elements[2] = pos;

	VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), _mat);

	if (!is_inside_tree())
		return;

	_notify_transform();
}
Beispiel #28
0
void UI_CheckBox::_notification(int p_what) {
	if (!checkbox_draw_)return;
	if (p_what == NOTIFICATION_MOUSE_ENTER && index_ != 1) {
		if (clipY_ > 1) {
			index_ = 2;
		}
		update();
	}
	else if (p_what == NOTIFICATION_MOUSE_EXIT && index_ != 1) {
		if (clipY_ > 1) {
			index_ = 0;
		}
		update();
	}
	else if (p_what == NOTIFICATION_DRAW) {

		RID ci = get_canvas_item();
		Size2 size = get_size();
		int w = 0;
		int h = 0;
		if (!texture_.is_null()) {
			w = texture_->get_width() / clipX_;
			h = texture_->get_height() / clipY_;
			int y = index_ / clipX_;
			int x = index_ % clipX_;

			Rect2 rect = Rect2(Point2(0, (size.height-w)), Point2(w,h));
			if (index_ < 0) {
				index_ = 0;

			}
			else if (index_ >= clipX_ * clipY_)
			{
				index_ = 0;
			}
			texture_->draw_rect_region(ci, rect, Rect2(x * w, y * h,w,h));
		}
		if (text_ != "") {
			Color color;
			Ref<Font> font = get_font("font");
			Point2 text_ofs = font->get_string_size(text_);
			int text_clip = text_ofs.width;
			text_ofs.x = (w + 2);
			text_ofs.y = size.height - text_ofs.height + font->get_ascent();
			font->draw(ci, text_ofs.floor(), text_, color, text_clip);
			minsize_.width = text_ofs.x + text_clip;
			minsize_.height = text_ofs.height > h ? text_ofs.height : h;
			if (minsize_.width > size.width || minsize_.height > size.height)minimum_size_changed();
		}
	}
}
Beispiel #29
0
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;
	};

};
Beispiel #30
0
void NinePatchRect::_notification(int p_what) {

	if (p_what == NOTIFICATION_DRAW) {

		if (texture.is_null())
			return;

		Rect2 rect = Rect2(Point2(), get_size());
		Rect2 src_rect = region_rect;

		texture->get_rect_region(rect, src_rect, rect, src_rect);

		RID ci = get_canvas_item();
		VS::get_singleton()->canvas_item_add_nine_patch(ci, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, draw_center);
	}
}