Python pygame 模块,MOUSEMOTION 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pygame.MOUSEMOTION

项目:PyCut    作者:FOSSRIT    | 项目源码 | 文件源码
def ProcessInput(self, events, pressed_keys):
        for event in events:
            if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
                # Move to the next scene when the user pressed Enter
                pass

            if event.type == pygame.MOUSEBUTTONDOWN:
                self.start_button.isClicked(event)
                self.help_button.isClicked(event)
                self.difficulty_button.isClicked(event)

            if event.type == pygame.MOUSEBUTTONUP:
                self.start_button.isClicked(event)
                self.help_button.isClicked(event)
                self.difficulty_button.isClicked(event)

            if event.type == pygame.MOUSEMOTION:
                self.start_button.isHovered(event)
                self.help_button.isHovered(event)
                self.difficulty_button.isHovered(event)
项目:PyCut    作者:FOSSRIT    | 项目源码 | 文件源码
def ProcessInput(self, events, pressed_keys):
        for event in events:
            if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
                # Move to the next scene when the user pressed Enter
                pass

            if event.type == pygame.MOUSEBUTTONDOWN:
                for button in self.buttons:
                    button.isClicked(event)

            if event.type == pygame.MOUSEBUTTONUP:
                for button in self.buttons:
                    button.isClicked(event)

            if event.type == pygame.MOUSEMOTION:
                for button in self.buttons:
                    button.isHovered(event)
项目:PyCut    作者:FOSSRIT    | 项目源码 | 文件源码
def ProcessInput(self, events, pressed_keys):
        """
        Process Input from user
        Inherited from SceneBase
                Args:   self
                        events - list of pygame events
                        pressed_keys
        """

        for event in events:
            if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
                # Move to the next scene when the user pressed Enter
                pass

            if event.type == pygame.MOUSEBUTTONDOWN:
                self.easy_button.isClicked(event)
                self.adv_button.isClicked(event)

            if event.type == pygame.MOUSEBUTTONUP:
                self.easy_button.isClicked(event)
                self.adv_button.isClicked(event)

            if event.type == pygame.MOUSEMOTION:
                self.easy_button.isHovered(event)
                self.adv_button.isHovered(event)
项目:PyCut    作者:FOSSRIT    | 项目源码 | 文件源码
def _mousemove_cb(self, widget, event):
        # From http://www.learningpython.com/2006/07/25/writing-a-custom-widget-using-pygtk/
        # if this is a hint, then let's get all the necessary 
        # information, if not it's all we need.
        if event.is_hint:
            win, x, y, state = event.window.get_device_position(event.device)
        else:
            x = event.x
            y = event.y
            state = event.get_state()

        rel = (x - self.__mouse_pos[0], y - self.__mouse_pos[1])
        self.__mouse_pos = (x, y)

        self.__button_state = [
            state & Gdk.ModifierType.BUTTON1_MASK and 1 or 0,
            state & Gdk.ModifierType.BUTTON2_MASK and 1 or 0,
            state & Gdk.ModifierType.BUTTON3_MASK and 1 or 0,
        ]

        evt = pygame.event.Event(pygame.MOUSEMOTION,
                                 pos=self.__mouse_pos, rel=rel, buttons=self.__button_state)
        self._post(evt)
        return True
项目:Traptris    作者:JesperDramsch    | 项目源码 | 文件源码
def __init__(self):
        pygame.init()
        pygame.key.set_repeat(250,25)
        self.width = cell_size*(2*cols+2)
        self.height = cell_size*rows
        self.rlim = cell_size*cols

        self.default_font =  pygame.font.Font(
            pygame.font.get_default_font(), 12)

        self.screen = pygame.display.set_mode((self.width, self.height))
        pygame.event.set_blocked(pygame.MOUSEMOTION) # We do not need
                                                     # mouse movement
                                                     # events, so we
                                                     # block them.
        self.next_stone = tetris_shapes[rand(len(tetris_shapes))]

        self.init_game()
        pygame.mixer.init()
        pygame.mixer.music.load(file)
        pygame.mixer.music.play(loops=-1)
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if self.show_msg == False:
            if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                elif not self.board.grid[4][18]:
                    char = event.unicode
                    if len(char) > 0 and lhv < 2 and char in self.digits:
                        self.home_square.value += char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
            elif event.type == pygame.MOUSEMOTION and self.drag:
                if self.board.grid[4][18]:
                    self.home_square.value = ""
                    self.home_square.update_me = True
            elif event.type == pygame.MOUSEBUTTONUP:
                for each in self.board.units:
                    if each.is_door is True:
                        self.board.all_sprites_list.move_to_front(each)
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if self.show_msg == False:
            if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                elif not self.board.grid[4][18]:
                    char = event.unicode
                    if len(char) > 0 and char in self.digits:
                        self.home_square.value = char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
            elif event.type == pygame.MOUSEMOTION and self.drag:
                if self.board.grid[4][18]:
                    self.home_square.value = ""
                    self.home_square.update_me = True
            elif event.type == pygame.MOUSEBUTTONUP:
                for each in self.board.units:
                    if each.is_door is True:
                        self.board.all_sprites_list.move_to_front(each)
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if self.show_msg == False:
            if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                elif not self.board.grid[4][16]:
                    char = event.unicode
                    if len(char) > 0 and char in self.digits:
                        self.home_square.value = char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
            elif event.type == pygame.MOUSEMOTION and self.drag:
                if self.board.grid[4][16]:
                    self.home_square.value = ""
                    self.home_square.update_me = True
            elif event.type == pygame.MOUSEBUTTONUP:
                for each in self.board.units:
                    if each.is_door is True:
                        self.board.all_sprites_list.move_to_front(each)
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        # TO DO
        if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            self.mouse_dn = True
        elif event.type == pygame.MOUSEBUTTONUP and event.button == 1 and self.mouse_dn:
            self.menu.active_cat = self.cat_id
            if self.menu.active_cat_o is not None:
                if self.menu.active_cat_o != self:
                    self.menu.active_cat_o.deactivate()
            self.activate()

            self.menu.mainloop.redraw_needed[1] = True
            self.menu.mainloop.redraw_needed[2] = True

        elif event.type == pygame.MOUSEMOTION:
            self.on_mouse_over()
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        # TO DO
        if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            self.mouse_dn = True
        elif event.type == pygame.MOUSEBUTTONUP and event.button == 1 and self.mouse_dn:
            pass
            """
            self.menu.active_cat = self.cat_id
            #self.tab_l_scroll = (self.scroll_l // self.scroll_step)
            if self.menu.mainloop.config.settings["sounds"]:
                s3.play()
            self.menu.mainloop.redraw_needed[1] = True
            self.menu.mainloop.redraw_needed[2] = True
            """
        elif event.type == pygame.MOUSEMOTION:
            self.on_mouse_over()
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
def handle_event(self, event):
        """ Slider event handler

        :param event: event to handle
        """
        if not self.visible:
            return
        mouse_events = [pygame.MOUSEBUTTONUP, pygame.MOUSEBUTTONDOWN, pygame.MOUSEMOTION]        
        if getattr(event, "source", None):
            self.event_source_local = False
        else:
            self.event_source_local = True        

        if event.type in mouse_events:
            pos = event.pos        
            if not self.bounding_box.collidepoint(pos):
                return            
            self.mouse_action(event)
        elif event.type == USER_EVENT_TYPE:
            self.user_event_action(event)
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
def mouse_action(self, event):
        """ Mouse event handler

        :param event: event to handle
        """
        pos = event.pos

        if self.selected and not(self.last_knob_position < pos[0] < self.last_knob_position + self.knob_width and pos[1] > self.bounding_box.y) and event.type != pygame.KEYUP:
            return

        button_press_simulation = getattr(event, "p", None)

        if event.type == pygame.MOUSEBUTTONUP and self.clicked:
            self.release_action(pos)                
        elif event.type == pygame.MOUSEBUTTONDOWN and self.bounding_box.collidepoint(pos):
            self.press_action()            
        elif event.type == pygame.MOUSEMOTION and (pygame.mouse.get_pressed()[0] or button_press_simulation) and self.bounding_box.collidepoint(pos) and self.clicked:
            self.motion_action(pos)
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
def handle_command(self, d):
        """ Handles commands sent from web client 

        :param d: command object
        """

        if d["command"] == "init":
            json_data = self.screen_to_json()
            web_socket.send_message(json_data)
        elif d["command"] == "mouse":
            a = {}
            a["pos"] = (d["x"], d["y"])
            a["button"] = d["b"]
            event = None
            if d["d"] == 0:
                event = pygame.event.Event(pygame.MOUSEBUTTONDOWN, **a)
            elif d["d"] == 1:
                event = pygame.event.Event(pygame.MOUSEBUTTONUP, **a)
            elif d["d"] == 2:
                event = pygame.event.Event(pygame.MOUSEMOTION, **a)
                event.p = True
            event.source = "browser"
            thread = Thread(target=pygame.event.post, args=[event])
            thread.start()
项目:HFOSSFinal    作者:AlanLeeson    | 项目源码 | 文件源码
def _mousemove_cb(self, widget, event):
        # From http://www.learningpython.com/2006/07/25/writing-a-custom-widget-using-pygtk/
        # if this is a hint, then let's get all the necessary 
        # information, if not it's all we need.
        if event.is_hint:
            win, x, y, state = event.window.get_device_position(event.device)
        else:
            x = event.x
            y = event.y
            state = event.get_state()

        rel = (x - self.__mouse_pos[0], y - self.__mouse_pos[1])
        self.__mouse_pos = (x, y)

        self.__button_state = [
            state & Gdk.ModifierType.BUTTON1_MASK and 1 or 0,
            state & Gdk.ModifierType.BUTTON2_MASK and 1 or 0,
            state & Gdk.ModifierType.BUTTON3_MASK and 1 or 0,
        ]

        evt = pygame.event.Event(pygame.MOUSEMOTION,
                                 pos=self.__mouse_pos, rel=rel, buttons=self.__button_state)
        self._post(evt)
        return True
项目:PyBot    作者:Pentabyteman    | 项目源码 | 文件源码
def update(self, event):
        try:
            if not self.contains(*event.pos):
                if not self.focussed:
                    return
        except AttributeError:
            return
        if event.type == pygame.MOUSEMOTION:
            if self.contains(*event.pos):
                self.focussed = True
                self.mouse_entered()
            else:
                self.focussed = False
                self.mouse_left()
            self.mouse_moved(event)
        elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            if self.contains(*event.pos):
                self.clicked(event)
项目:math-hurdler    作者:craigcabrey    | 项目源码 | 文件源码
def _mousemove_cb(self, widget, event):
        # From http://www.learningpython.com/2006/07/25/writing-a-custom-widget-using-pygtk/
        # if this is a hint, then let's get all the necessary 
        # information, if not it's all we need.
        if event.is_hint:
            win, x, y, state = event.window.get_device_position(event.device)
        else:
            x = event.x
            y = event.y
            state = event.get_state()

        rel = (x - self.__mouse_pos[0], y - self.__mouse_pos[1])
        self.__mouse_pos = (x, y)

        self.__button_state = [
            state & Gdk.ModifierType.BUTTON1_MASK and 1 or 0,
            state & Gdk.ModifierType.BUTTON2_MASK and 1 or 0,
            state & Gdk.ModifierType.BUTTON3_MASK and 1 or 0,
        ]

        evt = pygame.event.Event(pygame.MOUSEMOTION,
                                 pos=self.__mouse_pos, rel=rel, buttons=self.__button_state)
        self._post(evt)
        return True
项目:renpy-shader    作者:bitsawer    | 项目源码 | 文件源码
def handleEvents(self):
        self.mouse = self.get(MOUSE)

        for event, pos in self.context.events:
            self.mouse = pos

            handled = self.mode.handleEvent((event, pos))
            if not handled:
                if event.type == pygame.MOUSEBUTTONDOWN:
                    self.handleMouseDown(event, pos)
                elif event.type == pygame.MOUSEMOTION:
                    self.handleMouseMotion(pos)
                elif event.type == pygame.MOUSEBUTTONUP:
                    self.handleMouseUp(pos)

        if self.mouse:
            self.set(MOUSE, self.mouse)
项目:AAAI    作者:vignesh0710    | 项目源码 | 文件源码
def __init__(self):
        pygame.init()
        pygame.key.set_repeat(250,25)
        self.width = cell_size*(cols+6)
        self.height = cell_size*rows
        self.rlim = cell_size*cols
        self.bground_grid = [[ 8 if x%2==y%2 else 0 for x in xrange(cols)] for y in xrange(rows)]

        self.default_font =  pygame.font.Font(
            pygame.font.get_default_font(), 12)

        self.screen = pygame.display.set_mode((self.width, self.height))
        pygame.event.set_blocked(pygame.MOUSEMOTION) # We do not need
                                                     # mouse movement
                                                     # events, so we
                                                     # block them.
        self.next_stone = tetris_shapes[rand(len(tetris_shapes))]
        self.init_game()
项目:AAAI    作者:vignesh0710    | 项目源码 | 文件源码
def __init__(self):
        pygame.init()
        pygame.key.set_repeat(250,25)
        self.width = cell_size*(cols+6)
        self.height = cell_size*rows
        self.rlim = cell_size*cols
        self.bground_grid = [[ 8 if x%2==y%2 else 0 for x in xrange(cols)] for y in xrange(rows)]

        self.default_font =  pygame.font.Font(
            pygame.font.get_default_font(), 12)

        self.screen = pygame.display.set_mode((self.width, self.height))
        pygame.event.set_blocked(pygame.MOUSEMOTION) # We do not need
                                                     # mouse movement
                                                     # events, so we
                                                     # block them.
        self.next_stone = tetris_shapes[rand(len(tetris_shapes))]
        self.init_game()
项目:opseilen    作者:Baal221    | 项目源码 | 文件源码
def Update(self, events):
        for event in events:
            if event.type == pygame.MOUSEMOTION:
                if self.Rect.collidepoint(event.pos):                    
                    self.Text = (pygame.font.Font(None, 40)).render(self.DefaultText, 1, (255, 190, 0))            
                else:
                    self.Text = (pygame.font.Font(None, 40)).render(self.DefaultText, 1, (130, 130, 130))
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if self.Rect.collidepoint(event.pos):                    
                    return self.Action()
        return self
项目:PyCut    作者:FOSSRIT    | 项目源码 | 文件源码
def ProcessInput(self, events, pressed_keys):
        """
        Process input from user
        Inherits from SceneBase
                Args:   self
                        events - pygame events
                        pressed_keys
        """

        for event in events:
            if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
                # Move to the next scene when the user pressed Enter
                pass

            if event.type == pygame.MOUSEBUTTONDOWN:
                for button in self.buttons:
                    button.isClicked(event)
                if self.leveling_up:
                    self.continue_button.isClicked(event)

            if event.type == pygame.MOUSEBUTTONUP:
                for button in self.buttons:
                    button.isClicked(event)
                if self.leveling_up:
                    self.continue_button.isClicked(event)

            if event.type == pygame.MOUSEMOTION:
                #for button in self.buttons:
                #    button.isHovered(event)
                if self.leveling_up:
                    self.continue_button.isHovered(event)
项目:oficina2017    作者:helioh2    | 项目源码 | 文件源码
def big_bang(inic, tela,
             quando_tick=lambda e: e, \
             frequencia=28, \
             desenhar=lambda e: pg.Surface((0,0)), \
             quando_tecla=lambda e, k: e, \
             quando_mouse=lambda e, x, y, ev: e, \
             parar_quando=lambda e: False):

    pg.init()
    estado = inic
    clock = pg.time.Clock()


    while True:

        pg.display.flip()

        if parar_quando(estado):
            print(estado)
            sys.exit(0)

        for event in pg.event.get():
            if event.type == pg.QUIT:
                print(estado)
                sys.exit(0)

            if event.type == pg.KEYDOWN:
                estado = quando_tecla(estado, event.key)

            elif event.type in [pg.MOUSEBUTTONDOWN, pg.MOUSEBUTTONUP, pg.MOUSEMOTION]:
                x, y = pg.mouse.get_pos()
                estado = quando_mouse(estado, x, y, event.type)

        estado = quando_tick(estado)

        tela.fill(COR_BRANCO)
        desenhar(estado)

        clock.tick(frequencia)
项目:wargame    作者:maximinus    | 项目源码 | 文件源码
def __init__(self, text, signal, align=Align.NONE):
        # make a label of the text - but we only want the image
        label = GuiLabel(text, (0, 0, 0), (214, 214, 214)).image
        # get the contents to render themselves
        border = Resources.configs.get(self.border_config)
        image = add_border(label, border, Resources.get_image(border.image))
        rect = pygame.Rect(0, 0, image.get_width(), image.get_height())
        super().__init__(rect, image, align, False)
        self.messages = [pygame.MOUSEMOTION, pygame.MOUSEBUTTONUP, pygame.MOUSEBUTTONDOWN]
        self.highlight = self.get_highlight()
        self.normal_image = self.image
        self.signal = signal
        self.changed = False
项目:wargame    作者:maximinus    | 项目源码 | 文件源码
def __init__(self, highlight, image, rect):
        super().__init__(rect, image)
        self.highlight = highlight
        self.normal_image = image
        self.messages.append(pygame.MOUSEMOTION)
        self.inside = False
        # create a new message type and save it
        self.message_id = MessageType.get_new()
项目:wargame    作者:maximinus    | 项目源码 | 文件源码
def __init__(self, highlight, image, rect):
        super().__init__(rect, image)
        self.highlight = highlight
        self.normal_image = image
        self.messages.append(pygame.MOUSEMOTION)
        self.inside = False
项目:rpi_lcars    作者:tobykurien    | 项目源码 | 文件源码
def handleEvent(self, event, clock):
        handled = False
        if not self.visible:
            self.focussed = False
            return handled

        if self.groups()[0].UI_PLACEMENT_MODE:
            if event.type == pygame.MOUSEBUTTONDOWN:
                self.pressed_time = pygame.time.get_ticks()
                self.focussed = True

            if event.type == pygame.MOUSEMOTION:
                if (self.focussed and pygame.time.get_ticks() - self.pressed_time > 1000):
                    self.long_pressed = True
                    self.rect.top = event.pos[1]
                    self.rect.left = event.pos[0]
                    self.dirty = 1            

            if event.type == pygame.MOUSEBUTTONUP:
                if self.handler:
                    self.handler(self, event, clock)
                    handled = True

                if self.focussed and self.long_pressed:
                    print event.pos[1], event.pos[0]

                self.pressed_time = 0
                self.long_pressed = False
                self.focussed = False

        return handled
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        if event.type == pygame.MOUSEMOTION:
            # check if cursor is not in the top right corner as it would happen on mobile after finger up
            if event.pos[0] + event.pos[1] > 0:
                self.on_mouse_over()
            else:
                self.deselect_all()
                self.mainloop.info.buttons_restore()
                self.mainloop.info.reset_titles()

        elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
            if not (self.mainloop.m.ldrag or self.mainloop.m.rdrag):
                if self.mainloop.m.active_o is not None:
                    self.mainloop.m.active_o.state = 0
                    self.mainloop.m.active_o = None
                if self.mainloop.m.active_cat_o is not None:
                    self.mainloop.m.active_cat_o.deactivate()
                    self.mainloop.m.active_cat_o = None
                if self.state < 2:
                    self.mainloop.sfx.play(4)
                self.state = 2
                self.mainloop.m.active_cat = 0
                self.mainloop.m.game_constructor = game000.Board
                self.mainloop.m.game_variant = 0
                self.mainloop.m.active_game_id = 0
                self.mainloop.m.game_started_id = -1
                self.mainloop.m.tab_game_id = -5
                self.mainloop.m.tab_r_scroll = 0
                self.mainloop.redraw_needed = [True, True, True]
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        if self.visible:
            if event.type == pygame.MOUSEMOTION:
                self.onMouseMotion(event)
            elif event.type == pygame.MOUSEBUTTONDOWN:
                self.onMouseButtonDown()
            elif event.type == pygame.MOUSEBUTTONUP:
                self.onMouseButtonUp()
            elif event.type == pygame.KEYDOWN:
                self.onKeyDown(event)
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        if event.type == pygame.MOUSEMOTION:
            pos = event.pos
            for each in self.keys:
                if each.x < pos[0] < each.x + each.w and each.y < pos[1] < each.y + each.h:
                    each.mouse_over()
                    #each.handle(event)
                else:
                    each.mouse_out()

        elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            if self.enabled:
                pos = event.pos
                for each in self.keys:
                    if each.x < pos[0] < each.x + each.w and each.y < pos[1] < each.y + each.h:
                        each.mouse_down()
                        each.handle(event)
                    else:
                        each.mouse_up()
        elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
            if self.enabled:
                pos = event.pos
                for each in self.keys:
                    each.mouse_up()
                    if each.x < pos[0] < each.x + each.w and each.y < pos[1] < each.y + each.h:
                        each.handle(event)
                        return
            self.update()
            self.ls.update_me = True
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONDOWN or event.type == pygame.MOUSEBUTTONUP:
            pos = [event.pos[0] - self.mainloop.game_board.layout.dialogwnd_pos[0],
                   event.pos[1] - self.mainloop.game_board.layout.dialogwnd_pos[1]]
            found = False
            for each in self.elements:
                if each.rect.topleft[0] + each.rect.width >= pos[0] >= each.rect.topleft[0] and each.rect.topleft[
                    1] + each.rect.height >= pos[1] >= each.rect.topleft[1]:
                    each.handle(event)
                    found = True
            if not found:
                for each in self.elements:
                    each.mouse_out()
        else:
            pass
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONDOWN or event.type == pygame.MOUSEBUTTONUP:
            self.on_mouse_over()
            pos = [event.pos[0] - self.mainloop.game_board.layout.score_bar_pos[0], event.pos[1]]
            for each in self.elements:
                if each.rect.topleft[0] + each.rect.width >= pos[0] >= each.rect.topleft[0] and each.rect.topleft[
                    1] + each.rect.height >= pos[1] >= each.rect.topleft[1]:
                    each.handle(event)
        else:
            pass
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def toggle_select(self):
        if not self.menu.ldrag:
            if self.selected:
                self.hide_icons()
                self.play_sound(6)
                pygame.event.post(
                    pygame.event.Event(pygame.MOUSEMOTION,
                                       {"pos": pygame.mouse.get_pos(), "rel": None, "buttons": None}))
            else:
                self.show_icons()
                self.play_sound(5)
            self.menu.update_panel_height()
项目:tingbot-gui    作者:furbrain    | 项目源码 | 文件源码
def touch_handler(self, event):
        action = None
        if event.type == pygame.MOUSEBUTTONDOWN:
            action = "down"

        elif event.type == pygame.MOUSEMOTION:
            action = "move"

        elif event.type == pygame.MOUSEBUTTONUP:
            action = "up"
        pos = pygame.mouse.get_pos()
        pos = tingbot.graphics._xy_subtract(pos, self.surface.get_abs_offset())
        self.on_touch(pos, action)
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
def dispatch(self, player, shutdown):
        """ Dispatch events.  

        Runs the main event loop. Redirects events to corresponding handler.
        Distinguishes four types of events:
        - Quit event - when user closes window (Windows only)
        - Keyboard events
        - Mouse events
        - User Events    

        :param player: reference to player object
        "param shutdown: shutdown method to use when user exits
        """        
        self.player = player
        self.shutdown = shutdown
        mouse_events = [pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP, pygame.MOUSEMOTION]
        pygame.event.clear()
        clock = Clock()        

        while self.run_dispatcher:
            for event in pygame.event.get():
                s = str(event)
                logging.debug("Received event: %s", s) 
                if event.type == pygame.QUIT:
                    self.shutdown(event) 
                elif (event.type == pygame.KEYDOWN or event.type == pygame.KEYUP) and not self.config[USAGE][USE_LIRC]:
                    self.handle_keyboard_event(event)                                
                elif event.type in mouse_events or event.type == USER_EVENT_TYPE:
                    self.handle_event(event)                    
            if self.lirc != None:
                code = self.lirc.nextcode()
                if code != None:
                    self.handle_lirc_event(code)
            self.current_screen.refresh()
            self.screensaver_dispatcher.refresh()
            clock.tick(self.frame_rate)
项目:pyweek-game-poor-man-medal-of-honor-game    作者:ReekenX    | 项目源码 | 文件源码
def event_loop(self):
        for event in pg.event.get():
            self.keys = pg.key.get_pressed()
            if event.type == pg.QUIT or self.keys[pg.K_ESCAPE]:
                self.done = True
                self.closed = True
            elif event.type == pg.KEYDOWN and self.keys[pg.K_i]:
                #  import pdb
                #  pdb.set_trace()
                print 'Player at: '
                print self.player.rect
                print self.player.rect.x
                print self.player.rect.y
                print 'Camera at: '
                print self.camera.state
                print 'Painting at: '
                print  [(self.mouse[0], self.mouse[1]), (self.player.rect.centerx + abs(self.camera.state.x), self.player.rect.centery + abs(self.camera.state.y))]
                print 'Angle:'
                print self.angle
            elif event.type == pg.KEYDOWN:
                self.player.add_direction(event.key)
            elif event.type == pg.KEYUP:
                self.player.pop_direction(event.key)

            if event.type == pg.MOUSEBUTTONDOWN and event.button == 1:
                if self.player.bullets_left > 0 and self.player.weapon:
                    self.player_bullets.add(Bullet(self.player.rect.center, self.angle))
                    self.player.bullets_left -= 1
            elif event.type == pg.MOUSEMOTION:
                self.get_angle(event.pos)
项目:OfMagesAndMagic    作者:munnellg    | 项目源码 | 文件源码
def __init__(self):
        self.callbacks = {
            pygame.KEYDOWN           : self.key_state_change,
            pygame.KEYUP             : self.key_state_change,
            pygame.MOUSEMOTION       : self.mouse_motion,
            pygame.MOUSEBUTTONUP     : self.mouse_button_state_change,
            pygame.MOUSEBUTTONDOWN   : self.mouse_button_state_change,
            pygame.QUIT              : self.quit,
            STATE_CHANGED            : self.state_change,
            SOUND_EFFECT             : self.sound_effect,
            SETTINGS_UPDATED         : self.settings_updated,
            SET_GAME_STATE           : self.set_game_state,
            MUSIC_STOPPED            : self.music_stopped
        }

        self.key_states = defaultdict(int)
        self.mouse_button_states = defaultdict(int)

        self.key_listeners  = []
        self.state_change_listeners = []
        self.sound_effect_listeners = []
        self.mouse_button_listeners = []
        self.settings_listeners     = []
        self.set_game_state_listeners = []
        self.quit_listeners = []
        self.game_start_listeners = []
        self.music_stopped_listeners = []
项目:15-112-Term-Project--Tetris-God    作者:davidlizhang98    | 项目源码 | 文件源码
def run(self):
        screen = pygame.display.set_mode((self.width, self.height))
        pygame.display.set_caption(self.title)        
        clock = pygame.time.Clock()
        self._keys = dict()
        self.init()

        runGame = True
        while runGame:
            time = clock.tick(self.fps)
            self.timerFired(time)
            for event in pygame.event.get():
                if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
                    self.mousePressed(*(event.pos))
                elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                    self.mouseReleased(*(event.pos))
                elif (event.type == pygame.MOUSEMOTION and
                      event.buttons == (0, 0, 0)):
                    self.mouseMotion(*(event.pos))
                elif (event.type == pygame.MOUSEMOTION and
                      event.buttons[0] == 1):
                    self.mouseDrag(*(event.pos))
                elif event.type == pygame.KEYDOWN:
                    self._keys[event.key] = True
                    self.keyPressed(event.key, event.mod, screen)
                elif event.type == pygame.QUIT:
                    runGame = False
            screen.fill(self.bgColor)
            self.redrawAll(screen)
            pygame.display.flip()
            if (self.isGameOver == True): 
                return self.score
                runGame = False
            if (self.score > self.lineCap):
                return self.score
                runGame = False
        pygame.quit()
项目:15-112-Term-Project--Tetris-God    作者:davidlizhang98    | 项目源码 | 文件源码
def run(width = 800, height = 600, fps = 60, title = "Tetris"):
    class Struct(object): pass
    data = Struct()
    screen = pygame.display.set_mode((width,height))
    pygame.display.set_caption(title)        
    clock = pygame.time.Clock()
    init(data)
    backgroundColor = (255,255,255)
    runGame = True
    while (runGame == True):
        time = clock.tick(fps)
        timerFired(time, data)
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
                mousePressed(data, *(event.pos))
            elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                mouseReleased(data, *(event.pos))
            elif (event.type == pygame.MOUSEMOTION and
                  event.buttons == (0, 0, 0)):
                mouseMotion(data, *(event.pos))
            elif (event.type == pygame.MOUSEMOTION and
                  event.buttons[0] == 1):
                mouseDrag(data, *(event.pos))
            elif event.type == pygame.KEYDOWN:
                keyPressed(event.key, event.mod, screen, data)
            elif event.type == pygame.QUIT:
                runGame = False
        screen.fill(backgroundColor)
        redrawAll(screen, data)            
        pygame.display.flip()
    pygame.quit()

###########################################
# Mode Dispatcher
###########################################
项目:CoolesSpiel    作者:AlinaGri    | 项目源码 | 文件源码
def update(self, *args):
        """
        Handles the clicking of the Button and calls the function given in the constructor.

        parameters: tuple arguments for the update (first argument should be an instance pygame.event.Event)
        return values: -
        """
        if self._state:
            if self._state >= 2:
                self._state = 1
            else:
                self._state = 0
            self.markDirty()
        if len(args) > 0 and self.isActive():
            event = args[0]
            if event.type == pygame.MOUSEBUTTONUP:
                if self.rect.collidepoint(event.pos):
                    if event.button == 1:
                        try:
                            self._callback()
                        except:
                            pass
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if self.rect.collidepoint(event.pos):
                    if event.button == 1:
                        self._state = 2
                    else:
                        self._state = 1
                    self.markDirty()
            elif event.type == pygame.MOUSEMOTION:
                if self.rect.collidepoint(event.pos):
                    if event.buttons[0]:
                        self._state = 2
                    else:
                        self._state = 1
                    self.markDirty()

        super(Button, self).update(*args)
项目:CoolesSpiel    作者:AlinaGri    | 项目源码 | 文件源码
def update(self, *args):
        """
        Handles the selection and keyboard-input

        parameters: tuple arguments for the update (first argument should be an instance pygame.event.Event)
        return values: -
        """
        if len(args) > 0 and self.isActive():
            event = args[0]
            if event.type == pygame.KEYDOWN and self.isFocused():
                if event.key == pygame.K_LEFT:
                    self.moveCursor(-1)
                elif event.key == pygame.K_RIGHT:
                    self.moveCursor(1)
                elif event.key == pygame.K_BACKSPACE or event.key == pygame.K_DELETE:
                    if self._selection == self._cursor:
                        if event.key == pygame.K_DELETE:
                            self.delete(self._selection + 1, CURSOR)
                        else:
                            self.delete(self._selection - 1, CURSOR)
                            self.moveCursor(-1)
                    else:
                        self.delete(SELECTION, CURSOR)
                        self.setCursor(self._sort(SELECTION, CURSOR)[0])
                else:
                    char = event.unicode.encode("ascii", "ignore")
                    if (char != "" and (char == " " or not char.isspace())
                    and self._validation(self._text + char, self._text, self)):
                        self.delete(SELECTION, CURSOR)
                        s = self._sort(SELECTION, CURSOR)[0]
                        self.insert(s, char)
                        self.setCursor(s + 1)
            elif event.type == pygame.MOUSEMOTION:
                if self.rect.collidepoint(event.pos) and event.buttons[0]:
                    self.setSelection(SELECTION, self._posToIndex(event.pos[0] - self.rect.x))
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if self.rect.collidepoint(event.pos):
                    self.setCursor(self._posToIndex(event.pos[0] - self.rect.x))

        super(Entry, self).update(*args)
项目:fruit    作者:felko    | 项目源码 | 文件源码
def from_pygame_event(cls, event):
        if event.type == pygame.MOUSEMOTION:
            return MouseMotion(event.pos, event.rel)
项目:PythonOS    作者:furmada    | 项目源码 | 文件源码
def check(self):
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    State.exit()
                if event.type == pygame.MOUSEBUTTONDOWN:
                    self.events.append(GUI.LongClickEvent(event))
                if event.type == pygame.MOUSEMOTION and len(self.events) > 0 and isinstance(self.events[len(self.events)-1], GUI.LongClickEvent):
                    self.events[len(self.events)-1].intermediateUpdate(event)
                if event.type == pygame.MOUSEBUTTONUP and len(self.events) > 0 and isinstance(self.events[len(self.events)-1], GUI.LongClickEvent):
                    self.events[len(self.events)-1].end(event)
                    if not self.events[len(self.events)-1].checkValidLongClick():
                        self.events[len(self.events)-1] = self.events[len(self.events)-1].mouseUp
项目:adbmirror    作者:fhorinek    | 项目源码 | 文件源码
def events(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.exit()

            if hasattr(event, "pos"):
                ix, iy = event.pos
                self.mouse_inmenu = ix <= self.size[1] * MENU_BORDER / 100.0

                fx = min(max(0, (ix - self.proj[0]) / float(self.proj[2])), 1)
                fy = min(max(0, (iy - self.proj[1]) / float(self.proj[3])), 1)

                if self.rotation == 0:
                    x = fx
                    y = fy

                if self.rotation == 90:
                    x = 1.0 - fy
                    y = fx

                if self.rotation == 180:
                    x = 1.0 - fx
                    y = 1.0 - fy   

                if self.rotation == 270:
                    x = fy
                    y = 1.0 - fx                                 

            if hasattr(event, "button"):
                if event.button is not 1:
                    continue

                if event.type == pygame.MOUSEBUTTONDOWN:
                    if ix < self.menu_w and self.show_menu:
                        self.menu_action(iy / (self.size[1] / 3))
                    elif ix > self.size[0] - self.nav_w and self.show_nav:
                        self.nav_action(iy / (self.size[1] / 3))
                    else:
                        self.touch.write(["down", x, y])
                        self.mouse_down = True
                        self.mouse_time = time()

                if event.type == pygame.MOUSEBUTTONUP:
                    self.touch.write(["up"])
                    self.mouse_down = False

            if event.type == pygame.MOUSEMOTION:
                if self.mouse_down:
                    self.touch.write(["move", x, y])
项目:oficina2017    作者:helioh2    | 项目源码 | 文件源码
def big_bang(inic, tela,
             quando_tick=lambda e: e, \
             frequencia=28, \
             desenhar=lambda e: pg.Surface((0,0)), \
             quando_tecla=lambda e, k: e, \
             quando_solta_tecla=lambda e, k: e, \
             quando_mouse=lambda e, x, y, ev: e, \
             parar_quando=lambda e: False,\
             modo_debug=False,
             fonte_debug = 15):

    pg.init()
    estado = inic
    clock = pg.time.Clock()


    while True:

        pg.display.flip()

        if parar_quando(estado):
            print(estado)
            sys.exit(0)

        for event in pg.event.get():
            if event.type == pg.QUIT:
                print(estado)
                sys.exit(0)

            if event.type == pg.KEYDOWN:
                estado = quando_tecla(estado, event.key)
            elif event.type == pg.KEYUP:
                estado = quando_solta_tecla(estado, event.key)
            elif event.type in [pg.MOUSEBUTTONDOWN, pg.MOUSEBUTTONUP, pg.MOUSEMOTION]:
                x, y = pg.mouse.get_pos()
                estado = quando_mouse(estado, x, y, event.type)

        estado = quando_tick(estado)

        tela.fill(COR_BRANCO)
        desenhar(estado)
        if modo_debug:
            escreve_estado(estado, tela, fonte_debug)

        clock.tick(frequencia)
项目:oficina2017    作者:helioh2    | 项目源码 | 文件源码
def big_bang(inic, tela,
             quando_tick=lambda e: e, \
             frequencia=28, \
             desenhar=lambda e: pg.Surface((0,0)), \
             quando_tecla=lambda e, k: e, \
             quando_solta_tecla=lambda e, k: e, \
             quando_mouse=lambda e, x, y, ev: e, \
             parar_quando=lambda e: False,\
             modo_debug=False,
             fonte_debug = 15):

    pg.init()
    estado = inic
    clock = pg.time.Clock()


    while True:

        pg.display.flip()

        if parar_quando(estado):
            print(estado)
            sys.exit(0)

        for event in pg.event.get():
            if event.type == pg.QUIT:
                print(estado)
                sys.exit(0)

            if event.type == pg.KEYDOWN:
                estado = quando_tecla(estado, event.key)
            elif event.type == pg.KEYUP:
                estado = quando_solta_tecla(estado, event.key)
            elif event.type in [pg.MOUSEBUTTONDOWN, pg.MOUSEBUTTONUP, pg.MOUSEMOTION]:
                x, y = pg.mouse.get_pos()
                estado = quando_mouse(estado, x, y, event.type)

        estado = quando_tick(estado)

        tela.fill(COR_BRANCO)
        desenhar(estado)
        if modo_debug:
            escreve_estado(estado, tela, fonte_debug)

        clock.tick(frequencia)
项目:oficina2017    作者:helioh2    | 项目源码 | 文件源码
def big_bang(inic, tela,
             quando_tick=lambda e: e, \
             frequencia=28, \
             desenhar=lambda e: pg.Surface((0,0)), \
             quando_tecla=lambda e, k: e, \
             quando_solta_tecla=lambda e, k: e, \
             quando_mouse=lambda e, x, y, ev: e, \
             parar_quando=lambda e: False,\
             modo_debug=False,
             fonte_debug = 15):

    pg.init()
    estado = inic
    clock = pg.time.Clock()


    while True:

        pg.display.flip()

        if parar_quando(estado):
            print(estado)
            sys.exit(0)

        for event in pg.event.get():
            if event.type == pg.QUIT:
                print(estado)
                sys.exit(0)

            if event.type == pg.KEYDOWN:
                estado = quando_tecla(estado, event.key)
            elif event.type == pg.KEYUP:
                estado = quando_solta_tecla(estado, event.key)
            elif event.type in [pg.MOUSEBUTTONDOWN, pg.MOUSEBUTTONUP, pg.MOUSEMOTION]:
                x, y = pg.mouse.get_pos()
                estado = quando_mouse(estado, x, y, event.type)

        estado = quando_tick(estado)

        tela.fill(COR_BRANCO)
        desenhar(estado)
        if modo_debug:
            escreve_estado(estado, tela, fonte_debug)

        clock.tick(frequencia)
项目:oficina2017    作者:helioh2    | 项目源码 | 文件源码
def big_bang(inic, tela,
             quando_tick=lambda e: e, \
             frequencia=28, \
             desenhar=lambda e: pg.Surface((0,0)), \
             quando_tecla=lambda e, k: e, \
             quando_mouse=lambda e, x, y, ev: e, \
             parar_quando=lambda e: False):

    def desenha_tela():
        tela.fill(COR_BRANCO)
        desenhar(estado)

    pg.init()
    estado = inic
    clock = pg.time.Clock()


    while True:

        pg.display.flip()

        if parar_quando(estado):
            print(estado)
            sys.exit(0)

        for event in pg.event.get():
            if event.type == pg.QUIT:
                print(estado)
                sys.exit(0)

            if event.type == pg.KEYDOWN:
                estado = quando_tecla(estado, event.key)
                desenha_tela()

            elif event.type in [pg.MOUSEBUTTONDOWN, pg.MOUSEBUTTONUP, pg.MOUSEMOTION]:
                x, y = pg.mouse.get_pos()
                estado = quando_mouse(estado, x, y, event.type)
                desenha_tela()

        estado = quando_tick(estado)

        desenha_tela()

        clock.tick(frequencia)
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if event.type == pygame.MOUSEBUTTONDOWN:
            pos = event.pos
            column = (pos[0] - self.px_padding) // (self.layout.width)
            row = (pos[1] - self.layout.top_margin) // (self.layout.height)
            if event.button == 1 and column >= 0 and 2 <= row < self.data[1]:
                if self.points_count == 0:
                    self.new_screen()

        elif event.type == pygame.MOUSEBUTTONUP:
            pos = event.pos
            active = self.board.active_ship
            column = (pos[0] - self.px_padding) // (self.layout.width)
            row = (pos[1] - self.layout.top_margin) // (self.layout.height)
            if active != self.canvas_block.unit_id:
                if active == self.poli_btn.unit_id:
                    self.change_tool(4)
                elif active == self.tria_btn.unit_id:
                    self.change_tool(3)
                elif active == self.circle_btn.unit_id:
                    self.change_tool(2)
                elif active == self.next_btn.unit_id and self.next_btn.keyable == True:
                    self.next_shape()

            if event.button == 1 and column >= 0 and 2 <= row < self.data[1]:
                if self.points_count < self.max_points:
                    canvas_pos = self.snap_to_guide(
                        [pos[0] - self.px_padding, pos[1] - self.layout.top_margin - self.board.scale * 2])
                    if canvas_pos not in self.points:
                        self.points.append(canvas_pos)
                        self.p_current = canvas_pos
                        self.paint_line(0)
                        self.paint_line(2)
                        self.points_count += 1
                        if self.points_count >= self.max_points:
                            self.check_drawing()

        elif event.type == pygame.MOUSEMOTION and 0 < self.points_count < self.max_points:
            active = self.board.active_ship
            pos = event.pos
            column = (pos[0] - self.px_padding) // (self.layout.width)
            row = (pos[1] - self.layout.top_margin) // (self.layout.height)
            if column >= 0 and 2 <= row < self.data[1]:
                canvas_pos = self.snap_to_guide(
                    [pos[0] - self.px_padding, pos[1] - self.layout.top_margin - self.board.scale * 2])
                self.p_current = canvas_pos[:]
                if self.prev_snap is None:
                    self.prev_snap = canvas_pos[:]
                if self.prev_snap != self.p_current:
                    self.prev_snap = canvas_pos[:]
                    self.paint_line(1)
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if event.type == pygame.MOUSEBUTTONDOWN:
            pos = event.pos
            active = self.board.active_ship
            column = (pos[0] - self.px_padding) // (self.layout.width)
            row = (pos[1] - self.layout.top_margin) // (self.layout.height)
            if event.button == 1 and column >= 0 and 0 <= row < self.data[1]:
                if self.points_count == 0:
                    pass  # self.new_screen()

        elif event.type == pygame.MOUSEBUTTONUP:
            pos = event.pos
            active = self.board.active_ship
            column = (pos[0] - self.px_padding) // (self.layout.width)
            row = (pos[1] - self.layout.top_margin) // (self.layout.height)
            if active != self.canvas_block.unit_id:
                if active == self.poli_btn.unit_id:
                    self.change_tool(4)
                elif active == self.tria_btn.unit_id:
                    self.change_tool(3)
                elif active == self.circle_btn.unit_id:
                    self.change_tool(2)

            if event.button == 1 and column >= 0 and 0 <= row < self.data[1]:
                if self.points_count < self.max_points:
                    canvas_pos = self.snap_to_guide([pos[0] - self.px_padding, pos[1] - self.layout.top_margin])
                    if canvas_pos not in self.points:
                        self.points.append(canvas_pos)

                        self.p_current = canvas_pos
                        self.paint_line(0)

                        self.paint_line(2)
                        self.points_count += 1
                        if self.points_count >= self.max_points:
                            self.check_drawing()

        elif event.type == pygame.MOUSEMOTION and 0 < self.points_count < self.max_points:
            active = self.board.active_ship
            pos = event.pos
            column = (pos[0] - self.px_padding) // (self.layout.width)
            row = (pos[1] - self.layout.top_margin) // (self.layout.height)

            if column >= 0 and 0 <= row < self.data[1]:
                canvas_pos = self.snap_to_guide([pos[0] - self.px_padding, pos[1] - self.layout.top_margin])

                self.p_current = canvas_pos[:]

                if self.prev_snap is None:
                    self.prev_snap = canvas_pos[:]

                if self.prev_snap != self.p_current:
                    self.prev_snap = canvas_pos[:]
                    self.paint_line(1)
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        self.tm = self.time[:]
        if event.type == pygame.MOUSEMOTION and self.hand_id > 0:
            pos = [event.pos[0] - self.layout.game_left, event.pos[1] - self.layout.top_margin]
            r = self.vector_len([pos[0] - self.center[0], pos[1] - self.center[1]])
            if r == 0: r = 0.1
            if self.hand_id == 1:
                h = (self.current_angle(pos, r)) / self.angle_step_12
                if int(h) == 0:
                    self.tm[0] = 12
                else:
                    self.tm[0] = int(h)
            elif self.hand_id == 2:
                m = (self.current_angle(pos, r)) / self.angle_step_60
                self.tm[1] = int(m)
                if 0 <= self.tm[1] < 5 and 55 <= self.time[1] <= 59:
                    if self.tm[0] == 12:
                        self.tm[0] = 1
                    else:
                        self.tm[0] += 1
                elif 0 <= self.time[1] < 5 and 55 <= self.tm[1] <= 59:
                    if self.tm[0] == 1:
                        self.tm[0] = 12
                    else:
                        self.tm[0] -= 1
        elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            active = self.board.active_ship
            pos = [event.pos[0] - self.layout.game_left, event.pos[1] - self.layout.top_margin]
            if active == 0:
                r = self.vector_len([pos[0] - self.center[0], pos[1] - self.center[1]])
                if r == 0: r = 0.1
                self.hand_id = 0
                if self.is_contained(pos, coords_id=0):
                    self.hand_id = 1
                elif self.is_contained(pos, coords_id=1):
                    self.hand_id = 2
                elif self.rs[0] * 1.1 > r:
                    h = (self.current_angle(pos, r)) / self.angle_step_12
                    if int(h) == 0:
                        h = 12
                    self.tm[0] = int(h)
                else:
                    m = (self.current_angle(pos, r)) / self.angle_step_60
                    self.tm[1] = int(m)
            elif active == 1:
                self.change_time_btn(1, 0)
            elif active == 2:
                self.change_time_btn(0, 1)
            elif active == 3:
                self.change_time_btn(-1, 0)
            elif active == 4:
                self.change_time_btn(0, -1)

        elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
            self.hand_id = 0
        if self.tm != self.time:
            self.time = self.tm[:]
            self.draw_hands()
            self.clock_canvas.painting = self.canvas.copy()