本文整理汇总了Python中pygame.MOUSEMOTION属性的典型用法代码示例。如果您正苦于以下问题:Python pygame.MOUSEMOTION属性的具体用法?Python pygame.MOUSEMOTION怎么用?Python pygame.MOUSEMOTION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pygame
的用法示例。
在下文中一共展示了pygame.MOUSEMOTION属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startInterface
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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()
示例2: handleEvents
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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)
示例3: handle
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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
示例4: handle
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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)
示例5: handleEvent
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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
示例6: handle_event
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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)
示例7: handle_event
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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)
示例8: endInterface
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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()
示例9: ProcessMotion
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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))
示例10: ProcessMotion
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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
示例11: check
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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
示例12: waitforuser
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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
示例13: waitforuser
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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)
示例14: handle
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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)
示例15: handle
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEMOTION [as 别名]
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)