Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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()
Ejemplo n.º 4
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()