Python pygame.MOUSEMOTION Examples
The following are 30
code examples of pygame.MOUSEMOTION().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pygame
, or try the search function
.

Example #1
Source File: rigeditor.py From renpy-shader with MIT License | 8 votes |
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)
Example #2
Source File: startinterface.py From Games with MIT License | 7 votes |
def startInterface(screen, begin_image_paths): begin_images = [pygame.image.load(begin_image_paths[0]), pygame.image.load(begin_image_paths[1])] begin_image = begin_images[0] while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.MOUSEMOTION: mouse_pos = pygame.mouse.get_pos() if mouse_pos[0] in list(range(419, 574)) and mouse_pos[1] in list(range(374, 416)): begin_image = begin_images[1] else: begin_image = begin_images[0] elif event.type == pygame.MOUSEBUTTONDOWN: mouse_pos = pygame.mouse.get_pos() if event.button == 1 and mouse_pos[0] in list(range(419, 574)) and mouse_pos[1] in list(range(374, 416)): return True screen.blit(begin_image, (0, 0)) pygame.display.update()
Example #3
Source File: game004.py From eduActiv8 with GNU General Public License v3.0 | 7 votes |
def handle(self, event): gd.BoardGame.handle(self, event) if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: pos = [event.pos[0] - self.layout.game_left, event.pos[1] - self.layout.top_margin] found = False for each in self.units: if (each.rect.left < pos[0] < each.rect.right and each.rect.top < pos[1] < each.rect.bottom): if each != self.unit_mouse_over: if self.unit_mouse_over is not None: self.unit_mouse_over.mouse_out() self.unit_mouse_over = each found = True each.handle(event) break if not found: if self.unit_mouse_over is not None: self.unit_mouse_over.mouse_out() self.unit_mouse_over = None self.board.mainloop.redraw_needed[0] = True
Example #4
Source File: game017.py From eduActiv8 with GNU General Public License v3.0 | 6 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN: self.active_item = self.board.ships[self.board.active_ship] if self.active_item.unit_id < self.abc_len: self.current_letter_index = self.active_item.unit_id self.activate_letter() else: pos = [event.pos[0] - self.layout.game_left, event.pos[1] - self.layout.top_margin] if self.lt.rect.topleft[0] < pos[0] < self.lt.rect.topleft[0] + self.lt.rect.width and \ self.lt.rect.topleft[1] < pos[1] < self.lt.rect.topleft[ 1] + self.lt.rect.height: self.next_slide(-1) elif self.rt.rect.topleft[0] < pos[0] < self.rt.rect.topleft[0] + self.rt.rect.width and \ self.rt.rect.topleft[1] < pos[1] < self.rt.rect.topleft[ 1] + self.rt.rect.height: self.next_slide(1) if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #5
Source File: sprite.py From pi-tracking-telescope with MIT License | 6 votes |
def handleEvent(self, event, clock): if not self.visible: self.focussed = False return 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.focussed and self.long_pressed: print event.pos[1], event.pos[0] self.pressed_time = 0 self.long_pressed = False self.focussed = False
Example #6
Source File: example-9.py From python-examples with MIT License | 6 votes |
def handle_event(self, event): if event.type == pygame.MOUSEMOTION: #if self.rect.collidepoint(event.pos) # self.hovered = True #else: # self.hovered = False self.hovered = self.rect.collidepoint(event.pos) # === FUNCTIONS === (lower_case names) # empty # === MAIN === (lower_case names)
Example #7
Source File: example-1.py From python-examples with MIT License | 6 votes |
def handle_event(self, event): if event.type == pygame.MOUSEMOTION: self.hovered = self.rect.collidepoint(event.pos) elif event.type == pygame.MOUSEBUTTONDOWN: if self.hovered: print('Clicked:', self.text) if self.command: self.command() # === FUNCTIONS === (lower_case names) # empty # === MAIN === (lower_case names)
Example #8
Source File: endinterface.py From Games with MIT License | 5 votes |
def endInterface(screen, end_image_path, again_image_paths, score_info, font_path, font_colors, screensize): end_image = pygame.image.load(end_image_path) again_images = [pygame.image.load(again_image_paths[0]), pygame.image.load(again_image_paths[1])] again_image = again_images[0] font = pygame.font.Font(font_path, 50) your_score_text = font.render('Your Score: %s' % score_info['your_score'], True, font_colors[0]) your_score_rect = your_score_text.get_rect() your_score_rect.left, your_score_rect.top = (screensize[0] - your_score_rect.width) / 2, 215 best_score_text = font.render('Best Score: %s' % score_info['best_score'], True, font_colors[1]) best_score_rect = best_score_text.get_rect() best_score_rect.left, best_score_rect.top = (screensize[0] - best_score_rect.width) / 2, 275 while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.MOUSEMOTION: mouse_pos = pygame.mouse.get_pos() if mouse_pos[0] in list(range(419, 574)) and mouse_pos[1] in list(range(374, 416)): again_image = again_images[1] else: again_image = again_images[0] elif event.type == pygame.MOUSEBUTTONDOWN: mouse_pos = pygame.mouse.get_pos() if event.button == 1 and mouse_pos[0] in list(range(419, 574)) and mouse_pos[1] in list(range(374, 416)): return True screen.blit(end_image, (0, 0)) screen.blit(again_image, (416, 370)) screen.blit(your_score_text, your_score_rect) screen.blit(best_score_text, best_score_rect) pygame.display.update()
Example #9
Source File: viewfinder.py From viewfinder with Apache License 2.0 | 5 votes |
def ProcessMotion(vf_time): """Process pygame events for the window. Mousedown in the target area starts the simulation. Mouse movement is reported to the 'vf_time' arg to adjust the current time. Mouseup stop the simulation. """ last_pos = None for event in pygame.event.get(): if event.type == pygame.QUIT or event.type == pygame.KEYDOWN: return sys.exit(0) if vf_time.IsActive(): if event.type == pygame.MOUSEMOTION: if event.buttons[0]: last_pos = event.pos elif event.type == pygame.MOUSEBUTTONUP: if event.button == 1: vf_time.Stop() else: if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: pos = PixelsToDimensions(event.pos) x, y = pos if x > iphone_dims[0] - target_box_width - target_box_padding and \ x < iphone_dims[0] - target_box_padding and \ y > target_box_padding and \ y < iphone_dims[1] - target_box_padding: vf_time.Start(pos) if last_pos: vf_time.AdjustTime(PixelsToDimensions(last_pos))
Example #10
Source File: timeline.py From viewfinder with Apache License 2.0 | 5 votes |
def ProcessMotion(active, last_pos): new_pos = last_pos for event in pygame.event.get(): if event.type == pygame.QUIT or event.type == pygame.KEYDOWN: return sys.exit(0) if active: if event.type == pygame.MOUSEMOTION: if event.buttons[0]: new_pos = event.pos elif event.type == pygame.MOUSEBUTTONUP: if event.button == 1: active = False else: if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: x_pos, y_pos = [float(pos) / dim for pos, dim in zip(event.pos, window_dimensions)] if x_pos > (1.0 - target_box_width - target_box_padding) and \ x_pos < (1.0 - target_box_padding) and \ y_pos > target_box_padding and \ y_pos < 1.0 - target_box_padding: active = True new_pos = event.pos x_ratio = EnforceBounds(float(new_pos[0]) / window_dimensions[0], 0.0, 1.0) old_y_ratio = EnforceBounds(float(last_pos[1]) / window_dimensions[1], 0.0, 1.0) y_ratio = EnforceBounds(float(new_pos[1]) / window_dimensions[1], 0.0, 1.0) y_delta = y_ratio - old_y_ratio return active, new_pos, x_ratio, y_ratio, y_delta
Example #11
Source File: viewfinder.py From viewfinder with Apache License 2.0 | 5 votes |
def ProcessMotion(vf_time): """Process pygame events for the window. Mousedown in the target area starts the simulation. Mouse movement is reported to the 'vf_time' arg to adjust the current time. Mouseup stop the simulation. """ last_pos = None for event in pygame.event.get(): if event.type == pygame.QUIT or event.type == pygame.KEYDOWN: return sys.exit(0) if vf_time.IsActive(): if event.type == pygame.MOUSEMOTION: if event.buttons[0]: last_pos = event.pos elif event.type == pygame.MOUSEBUTTONUP: if event.button == 1: vf_time.Stop() else: if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: pos = PixelsToDimensions(event.pos) x, y = pos if x > iphone_dims[0] - target_box_width - target_box_padding and \ x < iphone_dims[0] - target_box_padding and \ y > target_box_padding and \ y < iphone_dims[1] - target_box_padding: vf_time.Start(pos) if last_pos: vf_time.AdjustTime(PixelsToDimensions(last_pos))
Example #12
Source File: timeline.py From viewfinder with Apache License 2.0 | 5 votes |
def ProcessMotion(active, last_pos): new_pos = last_pos for event in pygame.event.get(): if event.type == pygame.QUIT or event.type == pygame.KEYDOWN: return sys.exit(0) if active: if event.type == pygame.MOUSEMOTION: if event.buttons[0]: new_pos = event.pos elif event.type == pygame.MOUSEBUTTONUP: if event.button == 1: active = False else: if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: x_pos, y_pos = [float(pos) / dim for pos, dim in zip(event.pos, window_dimensions)] if x_pos > (1.0 - target_box_width - target_box_padding) and \ x_pos < (1.0 - target_box_padding) and \ y_pos > target_box_padding and \ y_pos < 1.0 - target_box_padding: active = True new_pos = event.pos x_ratio = EnforceBounds(float(new_pos[0]) / window_dimensions[0], 0.0, 1.0) old_y_ratio = EnforceBounds(float(last_pos[1]) / window_dimensions[1], 0.0, 1.0) y_ratio = EnforceBounds(float(new_pos[1]) / window_dimensions[1], 0.0, 1.0) y_delta = y_ratio - old_y_ratio return active, new_pos, x_ratio, y_ratio, y_delta
Example #13
Source File: pyos.py From PythonOS with MIT License | 5 votes |
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
Example #14
Source File: MessageDialog.py From PhotonFileEditor with GNU General Public License v3.0 | 5 votes |
def waitforuser(self): """ Blocks all events to Main window and wait for user to click OK. """ while self.waiting: self.redraw() pygame.display.flip() for event in pygame.event.get(): pos = pygame.mouse.get_pos() gpos=GPoint().fromTuple(pos) if event.type == pygame.MOUSEBUTTONUP: if self.dragDiff==None: for ctrl in self.controls: ctrl.handleMouseUp(pos,event.button) else: # handle window move self.dragDiff=None if event.type == pygame.MOUSEBUTTONDOWN: if gpos.inGRect(self.titlerect): self.dragDiff = gpos - self.winrect.p1 else: for ctrl in self.controls: ctrl.handleMouseDown(pos,event.button) if event.type == pygame.MOUSEMOTION: if not self.dragDiff==None: self.winrect.p1=gpos-self.dragDiff self.reposControls() else: for ctrl in self.controls: ctrl.handleMouseMove(pos) if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: print("Escape key pressed down.") self.waiting = False
Example #15
Source File: FileDialog.py From PhotonFileEditor with GNU General Public License v3.0 | 5 votes |
def waitforuser(self): """ Blocks all events to Main window and wait for user to click OK. """ while self.waiting: self.redraw() pygame.display.flip() for event in pygame.event.get(): pos = pygame.mouse.get_pos() gpos=GPoint().fromTuple(pos) if event.type == pygame.MOUSEBUTTONUP: if self.dragDiff==None: for ctrl in self.controls: ctrl.handleMouseUp(pos,event.button) else: # handle window move self.dragDiff=None if event.type == pygame.MOUSEBUTTONDOWN: if gpos.inGRect(self.titlerect): self.dragDiff = gpos - self.winrect.p1 else: for ctrl in self.controls: ctrl.handleMouseDown(pos,event.button) if event.type == pygame.MOUSEMOTION: if not self.dragDiff==None: self.winrect.p1=gpos-self.dragDiff self.reposControls() else: for ctrl in self.controls: ctrl.handleMouseMove(pos) if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: print("Escape key pressed down.") self.waiting = False else: self.tbFilename.handleKeyDown(event.key, event.unicode)
Example #16
Source File: game078.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) if event.type == pygame.MOUSEBUTTONDOWN and self.history[1] is None and self.ai_enabled is False: if 0 <= self.board.active_ship < self.square_count: active = self.board.ships[self.board.active_ship] if not active.uncovered: if self.history[0] is None: self.history[0] = active self.semi_select(active) self.clicks += 1 active.uncovered = True elif self.history[1] is None: self.history[1] = active self.semi_select(active) self.clicks += 1 if self.chosen[self.history[0].unit_id] != self.chosen[self.history[1].unit_id]: self.ai_enabled = True self.history[0].uncovered = False else: self.select() self.found += 2 if self.found == self.square_count: self.completed_mode = True self.ai_enabled = True active.update_me = True if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.custom_hover(event)
Example #17
Source File: game039.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) if 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) self.auto_check() if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #18
Source File: game060.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) if event.type == pygame.MOUSEBUTTONDOWN and self.history[1] is None and self.ai_enabled is False: if 0 <= self.board.active_ship < self.square_count: active = self.board.ships[self.board.active_ship] if not active.uncovered: if self.history[0] is None: self.history[0] = active self.semi_select(active) self.clicks += 1 active.uncovered = True elif self.history[1] is None: self.history[1] = active self.semi_select(active) self.clicks += 1 if self.chosen[self.history[0].unit_id] != self.chosen[self.history[1].unit_id]: self.ai_enabled = True self.history[0].uncovered = False else: self.select() self.found += 2 if self.found == self.square_count: self.completed_mode = True self.ai_enabled = True active.update_me = True if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.custom_hover(event)
Example #19
Source File: game026.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if 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) self.check_result() if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN: self.auto_check_reset() elif event.type == pygame.KEYUP: self.check_result() if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #20
Source File: game049.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) if 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) if self.data[5] == 1: self.auto_check() self.check_result() if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #21
Source File: game041.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN: self.auto_check_reset() elif event.type == pygame.MOUSEBUTTONUP and event.button == 1: self.draw_lines() self.mainloop.redraw_needed[0] = True self.check_result() if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #22
Source File: game019.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) if 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) self.auto_check() if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #23
Source File: game020.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if 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) self.check_result() if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN: self.auto_check_reset() elif event.type == pygame.KEYUP: self.check_result() if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #24
Source File: game112.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) if 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) self.check_result() if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #25
Source File: game111.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) if 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) self.check_result() if event.type == pygame.MOUSEBUTTONDOWN: self.auto_check_reset() if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #26
Source File: game042.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN: self.auto_check_reset() if event.type == pygame.MOUSEMOTION: if self.drag: self.swap_font_color() # if self.drag and self.mouse_entered_new: # self.swap_font_color() elif event.type == pygame.MOUSEBUTTONUP: self.swap_font_color() self.check_result() # if self.drag and self.mouse_entered_new: # self.swap_font_color()
Example #27
Source File: game032.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN: self.auto_check_reset() if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #28
Source File: game082.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) if 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) self.check_result(auto=True) if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #29
Source File: game036.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) if event.type == pygame.MOUSEBUTTONDOWN: self.auto_check_reset() if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #30
Source File: game013.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if 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) self.check_result(auto=True) if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)