Beispiel #1
0
 def on_activate(self):
     self._Cprepare(_c.FollowPath, len(self.points), self.lead, self.align)
     ObjectManager.register(self)
     for i, p in enumerate(self.points):
         self._cObj.SetPoint(i, _c.Vec2(*p))
     self._cObj.SetSpeed(self.speed)
     self._cObj.Start()
Beispiel #2
0
 def handle_mousebuttonup(self, event):
     if self.busy:
         return
     try:
         selected = self.selectOnUp()
     except:
         pass
     else:
         x, y = selected.get_root_layer().convert_pos(*event.pos)
         if selected._cObj.Pick(_c.Vec2(x, y)):
             wx.CallAfter(self.interface.set_selection, [self.selectOnUp()])
     self.selectOnUp = None
Beispiel #3
0
    def pick_all(self, x, y):
        """pick_all(x,y)

Get all nodes whose rects overlap (x,y)
"""
        nodelist = PigDirector.scene.get_ordered_nodes()
        picklist = []
        for node in nodelist:
            l = node.get_root_layer()
            x, y = l.convert_pos(x, y)
            if node._cObj.Pick(_c.Vec2(x, y)):
                picklist.append(node)
        return picklist
Beispiel #4
0
 def tick(self, evs):
     mx, my = Mouse.get_position()
     scene = Director.get_scene()
     results = []
     i = 0
     for e in self._elements:
         l = e.get_root_layer()
         wx, wy = l.convert_pos(mx, my)
         p = e._cObj.Pick(_c.Vec2(wx, wy))
         p = ObjectManager.c2py(p)
         if self._drag and self._drag._element is p:
             continue
         if p and p in self._elements:
             idx = scene.layers.index(l.get_name())
             results.append((idx, i, p))
             i += 1
     if not results:
         under = None
     else:
         results.sort()
         under = results[-1][2]
     self._update_under(under)
     if under is not None:
         under.on_hover()
     for ev in evs:
         if ev.type == pygame.MOUSEBUTTONDOWN:
             self._clicking = under
             if under is not None:
                 under.on_press()
         elif ev.type == pygame.MOUSEBUTTONUP:
             if self._drag is not None:
                 self._drag._update_pos(mx, my)
                 self._drag._element.on_drag_end()
                 if self._under is not None and self._under is not self._drag._element:
                     self._under.on_exit()
                     self._under = self._drag._element
                 self._drag = None
                 self._clicking.on_release()
                 self._clicking = None
             elif self._clicking is not None:
                 self._clicking.on_release()
                 self._clicking.on_click()
                 self._clicking = None
         elif ev.type == pygame.MOUSEMOTION and self._clicking is under:
             if self._drag is None and under is not None and under.draggable:
                 self._drag = Drag(under, (wx, wy))
                 under.on_drag_begin()
                 self._under = None
     if self._drag is not None:
         self._drag._element.on_drag()
         self._drag._update_pos(mx, my)
Beispiel #5
0
 def _init_c(self):
     c = self._cObj = _c.CodeObj()
     c.max_stack = self.stack
     c.varcount_f = self.varcount_f
     c.varcount_i = self.varcount_i
     c.varcount_v = self.varcount_v
     c.varcount_p = self.varcount_p
     c.init_code(self.code)
     c.init_const_f(len(self.consts_f))
     c.init_const_i(len(self.consts_i))
     c.init_const_v(len(self.consts_v))
     c.init_const_p(len(self.consts_p))
     for i, v in enumerate(self.consts_f):
         c.set_const_f(i, v)
     for i, v in enumerate(self.consts_i):
         c.set_const_i(i, v)
     for i, v in enumerate(self.consts_v):
         c.set_const_v(i, _c.Vec2(*v))
     for i, v in enumerate(self.consts_p):
         c.set_const_p(i, v._cObj)
Beispiel #6
0
 def emit(cls, system, position=None):
     node = None
     if isinstance(position, Node):
         node = position
     cls.prepare()
     cobj = cls._cImpl()
     cobj.InitFrom(cls._cTemplate)
     if node is not None:
         cobj.AttachTo(node._cObj)
     else:
         cobj.SetPosition(_c.Vec2(*position))
     cobj.SetSystem(system._cObj)
     pyobj = ParticleEmitterInstance(cobj)
     pyobj._argcache = cls._argcache
     if cls.image is not None:
         image = ResourceManager.get_image(cls.image)
         if image is None:
             raise ValueError("could not load image %r" % imagename)
         pyobj.image = image
         cobj.image = image._cObj
     cobj.Start()
     return pyobj
Beispiel #7
0
 def __init__(self, x=0, y=0, direction=None, length=None):
     if direction is not None:
         self._cObj = _c.Vec2(direction,length).rad2xy()
         self._cObj.thisown = True
     else:
         self._cObj = _c.Vec2(x,y)
Beispiel #8
0
 def pick(self, x, y):
     sprite = self._cObj.Pick(_c.Vec2(x,y))
     return ObjectManager.c2py(sprite)
Beispiel #9
0
 def convert_pos(self, x, y):
     v = _c.Vec2(x,y)
     self._scene._camera._cObj.ScreenToWorld(v, self._layer)
     return v.x,v.y
Beispiel #10
0
    def tick(self, evs=None):
        mx, my = Mouse.get_position()
        self._pos_dict = {'root': (mx, my)}
        scene = PigDirector.get_scene()
        results = []
        i = 0
        for e in self._single_objects:
            l = e.get_root_layer()
            if not l:
                continue
            wx, wy = self.get_relative_pos(l)
            p = e._cObj.Pick(_c.Vec2(wx, wy))
            p = ObjectManager.c2py(p)
            if self._drag and self._drag._object is p:
                continue
            if p and p in self._single_objects:
                idx = scene.layers.index(l.get_name())
                results.append((idx, i, p))
                i += 1
        if results:
            results.sort()
            under = [results[-1][2]]


#            under[0].on_hover()
        else:
            under = []
            for e in self._multi_objects:
                l = e.get_root_layer()
                if not l:
                    continue
                wx, wy = self.get_relative_pos(l)
                p = e._cObj.Pick(_c.Vec2(wx, wy))
                p = ObjectManager.c2py(p)
                if self._drag and self._drag._object is p:
                    continue
                if p and p in self._multi_objects:
                    under.append(p)
        if not pygame.mouse.get_focused():
            under = []
        self._update_under(under)
        for ev in evs:
            if ev.type == pygame.MOUSEBUTTONDOWN:
                self._clicking = under
                for object in under:
                    object.on_press()
                for e in self._click_objects:
                    l = e.get_root_layer()
                    if not l:
                        continue
                    wx, wy = self.get_relative_pos(l)
                    p = e._cObj.Pick(_c.Vec2(wx, wy))
                    p = ObjectManager.c2py(p)
                    if p and p in self._click_objects:
                        self._clicking.append(p)
                        p.on_press()
            elif ev.type == pygame.MOUSEBUTTONUP:
                if self._drag is not None:
                    self._drag._update_pos(mx, my)
                    self._drag._object.on_drag_end()
                    self._drag._object.on_release()
                    self._drag = None
                    self._clicking = []
                elif self._clicking != []:
                    for object in self._clicking:
                        if object in self._under:
                            object.on_click()
                    self._clicking = []
                for object in self._under:
                    object.on_release()
            elif ev.type == pygame.MOUSEMOTION and self._clicking != []:
                dragger = None
                if len(self._clicking) > 1:
                    results = []
                    i = 0
                    for object in self._clicking:
                        if not object.draggable:
                            continue
                        idx = scene.layers.index(
                            object.get_root_layer().get_name())
                        results.append((idx, i, object))
                    results.sort()
                    dragger = results[-1][2]
                elif self._clicking[0].draggable:
                    dragger = self._clicking[0]
                if self._drag is None and dragger is not None:
                    l = dragger.get_root_layer()
                    if l:
                        wx, wy = self.get_relative_pos(l)
                        self._drag = Drag(dragger, (wx, wy))
                        dragger.on_drag_begin()
                        try:
                            self._under.remove(dragger)
                        except:
                            pass
                    self._clicking = []
        if self._drag is not None:
            self._drag._update_pos(mx, my)
            self._drag._object.on_drag()
Beispiel #11
0
 def on_activate(self):
     self._Cactivate(_c.ScaleTo, _c.Vec2(*self.dstscale))
Beispiel #12
0
 def on_activate(self):
     self._Cactivate(_c.MoveTo, _c.Vec2(*self.pos))
Beispiel #13
0
 def on_activate(self):
     self._Cactivate(_c.MoveDelta, _c.Vec2(*self.delta))
Beispiel #14
0
 def on_activate(self):
     self._Cactivate(_c.Move, _c.Vec2(*self.velocity))
Beispiel #15
0
 def get_var(self, f, p):
     return _c.Vec2(*p)
Beispiel #16
0
 def c_push(self, f, p):
     f.pushv(_c.Vec2(*p))