Hi,
(Take 2 on my question to the list; first attempt went to wrong addy.)

I am trying to make sense of pyClutter 1.0. Could anyone point me to an
example (or post one) that shows clipping from a path applied to child
objects?

For example: A star shape that contains a bunch of moving rectangles
which will travel/size/rotate with the star, but are clipped to the
shape of the star.

I suspect this will involve a custom clutter.Group class of some kind,
with cogl paths and an on_paint() method, but I can find no headway on
the web so far.

I have this code so far:


import clutter
from clutter import cogl

x,y=0,0

def boo(tl,frame,obj):
    global x,y
    obj.set_position(x, y)

def xy(obj,evt):
    global x,y
    x,y = evt.x,evt.y

class G(clutter.Group):
    """
    Attempt to make a Group that can clip its children to a path.
    """
    def __init__(self,*args):
        clutter.Group.__init__(self,*args)
        #self.set_clip(0,0,10,10) # works, but not for a path.

        #Not sure why I need to connect here, on_paint is a method
        #of clutter.Group, but overriding it does not make it happen
        self.connect("paint",self.do_paint)

        self._color = clutter.Color(255,200,100)

    def do_paint(self, args):
        width,height=200,200
        cogl.path_move_to(width / 2, 0)
        cogl.path_line_to(width, height)
        cogl.path_line_to(0, height)
        cogl.path_line_to(width / 2, 0)
        cogl.path_close()

        ## Colour me lost from here...
        cogl.clip_push_from_path()
        clutter.Group.do_paint(self)
        cogl.clip_pop()

def main():
    global group1
    stage = clutter.Stage()
    stage.set_size(500, 500)
    stage.set_color(clutter.color_from_string("#FFF"))

rect1, rect2, rect3 = clutter.Rectangle(), clutter.Rectangle(), clutter.Rectangle()
    group1, group2, group3 = G(), clutter.Group(), clutter.Group()

    #Some kind of parent-child thing to work with
    group1.add(rect1, group2)
    group2.add(rect2, group3)
    group3.add(rect3)

    group1.set_position(100, 100)
    group2.set_position(100, 100)
    group3.set_position(100, 100)

    rect1.set_position(0, 0)
    rect2.set_position(0, 0)
    rect3.set_position(0, 0)

    rect1.set_size(150, 150)
    rect2.set_size(150, 150)
    rect3.set_size(150, 150)

    rect1.set_color(clutter.color_from_string("#FF000090"))
    rect2.set_color(clutter.color_from_string("#00FF0090"))
    rect3.set_color(clutter.color_from_string("#0000FF90"))

    stage.add(group1)

    stage.show_all()
    group1.show_all()
    group2.show_all()
    group3.show_all()

    stage.connect("key-press-event", clutter.main_quit)
    stage.connect('destroy', clutter.main_quit)
    stage.connect('motion-event', xy)

    path = clutter.Path('M 0 0 L 300 0 L 300 300 L 0 300z')
    timeline = clutter.Timeline(4000)
    timeline.set_loop(True)
    alpha = clutter.Alpha(timeline,clutter.EASE_OUT_SINE)
    p_behaviour = clutter.BehaviourPath(alpha, path)
    path.add_move_to(0, 0)
    p_behaviour.apply(group3)

    timeline.add_marker_at_time("foo",2000)

    timeline.start()

    t=clutter.Timeline(1000)
    t.set_loop(True)
    t.connect('new-frame', boo, group1) #move the top group around some
    t.start()

    clutter.main()

if __name__ == '__main__':
    main()







Hope you can help!
\d

--
Fonty Python and Things! -- http://otherwise.relics.co.za/wiki/Software

--
To unsubscribe send a mail to [email protected]

Reply via email to