+1 vote

Let's say I have a CanvasItem that needs to draw the background first, occupying the entire item rect, and then draw all its content within a smaller rect leaving a margin.

How should this be done in the NOTIFICATION_DRAW within _notofication?

This is what I've tried:

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();
    }

The problem with this is that it will clip everything to the margins including the background.

in Engine by (33 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.