def handle_events(*args):
settings_window, camera, scroll, done, dims, screen, bodies, G, COR = args
for event in pg.event.get():
if event.type == pg.VIDEORESIZE:
width, height = event.w, event.h
dims, screen = V2(width, height), pg.display.set_mode((width, height), pg.RESIZABLE)
elif event.type == pg.KEYDOWN:
scroll.key(event.key, 1)
camera.key_down(event.key)
elif event.type == pg.KEYUP:
scroll.key(event.key, 0)
camera.key_up(event.key)
elif event.type == pg.MOUSEBUTTONDOWN:
handle_mouse(settings_window, camera, event, bodies, dims, G, COR, scroll)
done |= event.type == pg.QUIT
return done, dims, screen
python类VIDEORESIZE的实例源码
def _evHandle(self):
"Handle events in the pygame event queue"
for ev in pygame.event.get():
try:
if ev.type != pygame.VIDEORESIZE:
self.evMgr.dispatch(ev)
elif ev.size != self.size:
self.resize(ev.size)
if hasattr(self, "onresize"): self.onresize(ev)
except: logError()
def _resize_cb(self, widget, event):
evt = pygame.event.Event(pygame.VIDEORESIZE,
size=(event.width,event.height), width=event.width, height=event.height)
pygame.event.post(evt)
return False # continue processing
def run(self):
# -------- Main Program Loop -----------
while not self._done:
# --- Main event loop
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
self._done = True # Flag that we are done so we exit this loop
elif event.type == pygame.VIDEORESIZE: # window resized
self._screen = pygame.display.set_mode(event.dict['size'],
pygame.HWSURFACE|pygame.DOUBLEBUF|pygame.RESIZABLE, 32)
# --- Getting frames and drawing
if self._kinect.has_new_infrared_frame():
frame = self._kinect.get_last_infrared_frame()
self.draw_infrared_frame(frame, self._frame_surface)
frame = None
self._screen.blit(self._frame_surface, (0,0))
pygame.display.update()
# --- Go ahead and update the screen with what we've drawn.
pygame.display.flip()
# --- Limit to 60 frames per second
self._clock.tick(60)
# Close our Kinect sensor, close the window and quit.
self._kinect.close()
pygame.quit()
def on_resize(self, size, info):
if android is None:
# pygame.event.set_blocked(pygame.VIDEORESIZE)
repost = False
if size[0] < self.config.size_limits[0]:
size[0] = self.config.size_limits[0]
repost = True
if size[0] > self.config.size_limits[2]:
size[0] = self.config.size_limits[2]
repost = True
if size[1] < self.config.size_limits[1]:
size[1] = self.config.size_limits[1]
repost = True
if size[1] > self.config.size_limits[3]:
size[1] = self.config.size_limits[3]
repost = True
if size != self.fs_size or self.config.platform == "macos":
self.wn_size = size[:]
self.size = size[:]
self.config.settings["screenw"] = self.size[0]
self.config.settings["screenh"] = self.size[1]
self.screen = pygame.display.set_mode(self.size, pygame.RESIZABLE)
self.fs_rescale(info)
self.config.settings_changed = True
self.config.save_settings(self.db)
# pygame.event.set_allowed(pygame.VIDEORESIZE)
if repost:
pygame.event.post(
pygame.event.Event(pygame.VIDEORESIZE, size=self.size[:], w=self.size[0], h=self.size[1]))
if android is not None:
self.size = self.android_screen_size[:]
self.info.rescale_title_space()
def handleEvents(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.VIDEORESIZE:
global screenWidth, screenHeight, gameWidth, gameHeight
screenWidth, screenHeight = event.size
if screenWidth < self.minScreenWidth: screenWidth = self.minScreenWidth
if screenHeight < self.minScreenHeight: screenHeight = self.minScreenHeight
self.screen = pygame.display.set_mode((screenWidth, screenHeight), HWSURFACE|DOUBLEBUF|RESIZABLE)
gameWidth, gameHeight = screenWidth, screenHeight - self.toolbarHeight
self.initUI()
self.renderScreen = True
# Make sure that all food objects are within the bounds of the world.
for obj in objects:
if type(obj) is not Food: continue
if obj.pos[0] < 0: obj.pos[0] = 0
if obj.pos[1] < 0: obj.pos[1] = 0
if obj.pos[0] > screenWidth: obj.pos[0] = screenWidth
if obj.pos[1] > screenHeight: obj.pos[1] = screenHeight
self.updateKeys(event)
self.gui.event(event)
def run(self):
self.screen = pygame.display.get_surface()
while self.running:
# Pump GTK messages.
# Pump PyGame messages.
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
elif event.type == pygame.VIDEORESIZE:
pygame.display.set_mode(event.size, pygame.RESIZABLE)
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
self.currentPlayState = self.playStates.Paused
# Clear Display
self.screen.fill(self.white)
options = { 0 : self.drawMenuState,
1 : self.drawPlayState,
2 : self.drawInstructionState
}
options[self.currentPlayState]()
# Flip Display
pygame.display.flip()
# Try to stay at 30 FPS
self.clock.tick(30)
# This function is called when the game is run directly from the command line:
# ./TestGame.py
def _resize_cb(self, widget, event):
evt = pygame.event.Event(pygame.VIDEORESIZE,
size=(event.width,event.height), width=event.width, height=event.height)
pygame.event.post(evt)
return False # continue processing
def from_pygame_event(cls, event):
if event.type == pygame.VIDEORESIZE:
return ResizeWindow(Size(event.w, event.h))
def _resize_cb(self, widget, event):
evt = pygame.event.Event(pygame.VIDEORESIZE,
size=(event.width,event.height), width=event.width, height=event.height)
pygame.event.post(evt)
return False # continue processing
def run(self):
# -------- Main Program Loop -----------
while not self._done:
# --- Main event loop
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
self._done = True # Flag that we are done so we exit this loop
elif event.type == pygame.VIDEORESIZE: # window resized
self._screen = pygame.display.set_mode(event.dict['size'],
pygame.HWSURFACE|pygame.DOUBLEBUF|pygame.RESIZABLE, 32)
# --- Game logic should go here
# --- Getting frames and drawing
# --- Woohoo! We've got a color frame! Let's fill out back buffer surface with frame's data
if self._kinect.has_new_color_frame():
frame = self._kinect.get_last_color_frame()
self.draw_color_frame(frame, self._frame_surface)
frame = None
# --- Cool! We have a body frame, so can get skeletons
if self._kinect.has_new_body_frame():
self._bodies = self._kinect.get_last_body_frame()
# --- draw skeletons to _frame_surface
if self._bodies is not None:
for i in range(0, self._kinect.max_body_count):
body = self._bodies.bodies[i]
if not body.is_tracked:
continue
joints = body.joints
# convert joint coordinates to color space
joint_points = self._kinect.body_joints_to_color_space(joints)
self.draw_body(joints, joint_points, SKELETON_COLORS[i])
# --- copy back buffer surface pixels to the screen, resize it if needed and keep aspect ratio
# --- (screen size may be different from Kinect's color frame size)
h_to_w = float(self._frame_surface.get_height()) / self._frame_surface.get_width()
target_height = int(h_to_w * self._screen.get_width())
surface_to_draw = pygame.transform.scale(self._frame_surface, (self._screen.get_width(), target_height));
self._screen.blit(surface_to_draw, (0,0))
surface_to_draw = None
pygame.display.update()
# --- Go ahead and update the screen with what we've drawn.
pygame.display.flip()
# --- Limit to 60 frames per second
self._clock.tick(60)
# Close our Kinect sensor, close the window and quit.
self._kinect.close()
pygame.quit()
def main():
pygame.init()
pygame.font.init()
screen = init_screen(*screen_size)
font = pygame.font.Font(font_name, font_size)
clock = pygame.time.Clock()
compute_curve()
generate_images(font)
init_grid(*screen_size)
frame_number = 0
running = True
while running:
if not save_to_disk:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.VIDEORESIZE:
if not screen_size == (event.w, event.h):
screen = init_screen(event.w, event.h)
init_grid(event.w, event.h)
burn_set.clear()
elif event.type == pygame.QUIT:
running = False
update_burners()
# update and draw grid to the screen
screen_blit = screen.blit
for glyph in (i for i in glyphs if i.ttl):
# have random chance to change the glyph
if random() > .9:
glyph.index = randrange(len(charset))
# update the glyphs's life and image
# if it becomes 0, then it won't be updated next frame
glyph.ttl -= 1
# get image and draw it
screen_blit(cache[glyph.index][glyph.ttl], glyph.pos)
screen_blit(logo, (0, 0), None, pygame.BLEND_RGBA_MULT)
if save_to_disk:
filename = "snapshot%05d.tga" % frame_number
pygame.image.save(screen, filename)
frame_number += 1
else:
pygame.display.flip()
def show(Runner, arg=None, fps=24, rows=17, cols=165, scale=8, withArgs=False):
import pygame, sys
FPS = fps
fpsClock = pygame.time.Clock()
board_dimensions = (cols, rows)
#yep
disp_size = (cols * scale, rows * scale)
pygame.init()
screen_opts = pygame.RESIZABLE | pygame.DOUBLEBUF
screen = pygame.display.set_mode(disp_size, screen_opts)
changed = False
if arg is None:
runner = Runner(board_dimensions)
else:
runner = Runner(board_dimensions, arg)
font = pygame.font.Font('slkscr.ttf', 32)
while True:
events = pygame.event.get()
for e in events:
if e.type == pygame.QUIT:
sys.exit()
if e.type == pygame.VIDEORESIZE:
disp_size = e.dict['size']
screen = pygame.display.set_mode(disp_size, screen_opts)
screen.fill((0, 0, 0))
# draw the pixels
txts = ["FPS: {0:.2f}".format(fpsClock.get_fps())]
if withArgs:
pixels, txt = runner.run(events)
txts.append(txt)
else:
pixels = runner.run()
if type(pixels) is tuple:
pixels, txt = pixels
txts.append(txt)
temp_surface = pygame.Surface(board_dimensions)
pygame.surfarray.blit_array(temp_surface, pixels)
pygame.transform.scale(temp_surface, disp_size, screen)
i = 1
for txt in txts:
for line in txt.splitlines():
screen.blit(font.render(line.replace('[', '').replace(']', '').strip(), 1, (255, 255, 255)),
(30, 30 * i))
i += 1
pygame.display.flip()
fpsClock.tick(FPS)
def process_event(self, event):
# perf: local for faster access
io = self.io
if event.type == pygame.MOUSEMOTION:
io.mouse_pos = event.pos
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
io.mouse_down[0] = 1
if event.button == 2:
io.mouse_down[1] = 1
if event.button == 3:
io.mouse_down[2] = 1
if event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
io.mouse_down[0] = 0
if event.button == 2:
io.mouse_down[1] = 0
if event.button == 3:
io.mouse_down[2] = 0
if event.button == 4:
io.mouse_wheel = .5
if event.button == 5:
io.mouse_wheel = -.5
if event.type == pygame.KEYDOWN:
for char in event.unicode:
code = ord(char)
if 0 < code < 0x10000:
io.add_input_character(code)
io.keys_down[event.key] = True
if event.type == pygame.KEYUP:
io.keys_down[event.key] = False
if event.type in (pygame.KEYDOWN, pygame.KEYUP):
io.key_ctrl = (
io.keys_down[pygame.K_LCTRL] or
io.keys_down[pygame.K_RCTRL]
)
io.key_alt = (
io.keys_down[pygame.K_LALT] or
io.keys_down[pygame.K_RALT]
)
io.key_shift = (
io.keys_down[pygame.K_LSHIFT] or
io.keys_down[pygame.K_RSHIFT]
)
io.key_super = (
io.keys_down[pygame.K_LSUPER] or
io.keys_down[pygame.K_LSUPER]
)
if event.type == pygame.VIDEORESIZE:
io.display_size = event.size