+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.

asked Nov 20, 2017 in Engine by rraallvv (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 How to use this Q&A? before posting your first questions.