Repainting Cairo windows?

I am facing a problem that I suspect is to do draw / paint elements in cairo.

I have a borderless window in pygtk but I am drawing two rectangles with cairo.a a black rectangle and a gray rectangle inside. When the window is resized, it appears that parts of the inner rectangle are not being drawn / painted. I have included 3 screenshots to show this problem.

enter image description hereenter image description hereenter image description here

As you can see in the second and third pictures, some parts of the window are not grayed out. One way to fix this is to call the pygtk window present () method, but this makes my program quite slow as the window height changes with almost every key press. So I was wondering what alternatives I need to fix.

below is the corresponding cairo code i am using

def expose(self, widget, e):
    cr = widget.window.cairo_create()

    # Draw the background
    cr.set_operator(cairo.OPERATOR_SOURCE)

    # Create black rectangle with 60% opacity (serves as border)
    (width, height) = widget.get_size()
    cr.set_source_rgba(0, 0, 0, 0.6)
    cr.rectangle(0, 0, width, height)
    cr.fill()

    # Inside the black rectangle, put a lighter one (will hold widgets)
    (width, height) = widget.get_size()
    cr.set_source_rgb(205/255, 205/255, 193/255)
    cr.rectangle(10, 10, width-20, height-20)
    cr.fill()   

    return False

def screen_changed(self, widget, old_screen = None):
    screen = widget.get_screen()
    colormap = screen.get_rgba_colormap()
    widget.set_colormap(colormap)

      

+3


source to share


2 answers


This is mostly a GTK + bug I believe. When the window is resized, GTK + does not always queue the entire window for redrawing. As a workaround, you can call window.queue_draw () wherever you are resizing the window.



+2


source


Try using the following right after creating your cairo widget:

cr.set_source_rgb(0,0,0)
cr.paint()

      



This will ensure that you always have a blank canvas.

+1


source







All Articles