Hello,

I am using clutter-cairo 0.82 and clutter 0.8.8 (pyclutter, actually, and pycairo) to create a custom GradientRectangle object to draw a basic rectangular gradient. The class extends CloneTexture and passes a CairoTexture object to the superclass constructor after drawing the requested gradient. I've been encountering two issues and am having trouble finding examples or documentation related to them. One, i'm not sure how to repaint the CairoTexture object on each redraw with do_paint(), so any overlapping windows erase those parts of the gradient. Two, when i specify a 1024x1024 texture object and a 1024x768 rectangle in cairo, the gradient is only drawn over about the top 2/3rds of the window. The size of the window itself is 1024x768. I've pasted the __init__ function below. Sorry for the long email, I'm fairly new to Clutter and am probably missing something obvious. Any ideas or comments would help!

Thanks!
Christine

def __init__(self, width, height, colors = None, alphas = None, x = 0, y = 0, visible = True, depth = 0, rotation = 0.0,
                scale_x = 1.0, scale_y = 1.0, name = None):
# Find the nearest power of 2 texture size which will fit this gradient
       import math
       widthlog2, heightlog2 = math.log(width, 2), math.log(height, 2)
tex_size_width, tex_size_height = math.pow(2, int(math.ceil(widthlog2))), math.pow(2, int(math.ceil(heightlog2))) #Create texture and pass to CloneTexture superclass constructor
       self.cr_tex = CairoTexture(tex_size_width, tex_size_height)
cr = self.cr_tex.cairo_create() # Returns the cluttercairo.CairoContext object to draw with
       # Clears the background to white
       cr.set_operator(cairo.OPERATOR_CLEAR)
       # Begins painting on the canvas
       cr.paint()
       # Default operator
       cr.set_operator(cairo.OPERATOR_OVER)
       # Draw the proper sized rectangle to apply the gradient to
       cr.rectangle(0.0, 0.0, width, height)
# Creates a linear gradient along the line defined by x0, y0 and x1, y1 (the respective parameters of the constructor) # In this case to create a straight up and down gradient we define the center y point and the beginning and ending xs.
       linear = cairo.LinearGradient(width/2, 0, width/2, height)
# Hardcoded gradient test values
       linear.add_color_stop_rgba(0, 0, 0.3, 0.8, 0.8)
       linear.add_color_stop_rgba(1, 0, 0.8, 0.3, 0.6)

       cr.set_source(linear)
       cr.fill()

       clutter.CloneTexture.__init__(self, self.cr_tex)
--
To unsubscribe send a mail to [email protected]

Reply via email to