Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache calls to set custom clipping rectangles on a CanvasItem #13101

Open
rraallvv opened this issue Nov 20, 2017 · 3 comments
Open

Cache calls to set custom clipping rectangles on a CanvasItem #13101

rraallvv opened this issue Nov 20, 2017 · 3 comments

Comments

@rraallvv
Copy link
Contributor

For instance in this snipped of code:

void MyCustomItem::_notification(int p_what) {

	case NOTIFICATION_DRAW: {
		// Enable clipping
		VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);

		draw_background();

		// Clip to margins
		VisualServer::get_singleton()->canvas_item_set_custom_rect(get_canvas_item(), true, Rect2(
			Point2(
			 margin_left,
			 margin_top
			),
			Size2(
			 width - margin_left - margin_right,
			 height - margin_top - margin_bottom
			)
		));

		draw_stuff();
		break;
	}
}

I need draw_background() to paint something within the CanvasItem clipping area and draw_stuff() to draw everything else within some margin. Such thing would be possible if calls to canvas_item_set_clip() and canvas_item_set_custom_rect() were cached.

@27thLiz 27thLiz added this to the 3.1 milestone Jan 10, 2018
@akien-mga akien-mga modified the milestones: 3.1, 3.2 Jan 9, 2019
@akien-mga
Copy link
Member

Is this issue still relevant in the current master branch?

If so, could you provide an example project that shows what happens currently, and describe what you'd expect?

@akien-mga akien-mga modified the milestones: 3.2, 4.0 Nov 14, 2019
@rraallvv
Copy link
Contributor Author

@akien-mga I'm not sure, I'll try to reproduce it with the current master branch and report back.

@tom-jk
Copy link

tom-jk commented Aug 8, 2020

The issue as I understand it is as follows: we want to clip drawing to some area A, and draw some things X, then clip it to some area B, and draw some other things Y. The draw commands are queued up to be drawn but the clip setting commands are performed immediately(?); the result is that both X and Y are drawn clipped to area B (the last clip we set).

Tested in 2.1.4, 3.0, 3.2.3.rc3
Can reproduce issue in all

Tested with a control with this script:

extends Control


func _notification(what):
	
	if what == NOTIFICATION_DRAW:
		# Enable clipping
		VisualServer.canvas_item_set_clip(get_canvas_item(), true)
		
		# clip to size area A
		if true:
			VisualServer.canvas_item_set_custom_rect(get_canvas_item(), true,
			Rect2(Vector2(0, 0), Vector2(128, 128)));
		
		# draw some X
		draw_circle(get_local_mouse_position(), 128, Color(0,1,0,1))
		
		# clip to size area B
		if true:
			VisualServer.canvas_item_set_custom_rect(get_canvas_item(), true,
			Rect2(Vector2(32, 32), Vector2(64, 64)));
		
		# draw some Y
		draw_circle(get_local_mouse_position(),  80, Color(1,0,0,1))


func _physics_process(delta):
	update()

Expected (left): a large green circle clipped by a large square area, and a small red circle clipped by a smaller square area. (Both circles are drawn at the mouse position.)

Result (right): large green circle and small red circle both clipped by the smaller square area.

Godot13101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants