Python pygame.VIDEORESIZE Examples
The following are 8
code examples of pygame.VIDEORESIZE().
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: Input.py From three.py with MIT License | 7 votes |
def update(self): self.keyDownList = [] self.keyUpList = [] self.mouseButtonDown = False self.mouseButtonUp = False self.windowResize = False for event in pygame.event.get(): # checks input events (discrete) if event.type == pygame.KEYDOWN: self.keyDownList.append( event.key ) self.keyPressedList.append( event.key ) elif event.type == pygame.KEYUP: self.keyPressedList.remove( event.key ) self.keyUpList.append( event.key ) elif event.type == pygame.MOUSEBUTTONDOWN: self.mouseButtonDown = True self.mouseButtonPressed = True elif event.type == pygame.MOUSEBUTTONUP: self.mouseButtonPressed = False self.mouseButtonUp = True elif event.type == pygame.QUIT: self.quitStatus = True elif event.type == pygame.VIDEORESIZE: self.windowResize = True self.windowWidth = event.w self.windowHeight = event.h
Example #2
Source File: tank.py From Jtyoui with MIT License | 5 votes |
def get_event(self): global SCREEN_WIDTH, SCREEN_HEIGHT event_list = pygame.event.get() for event in event_list: if event.type == pygame.VIDEORESIZE: SCREEN_WIDTH, SCREEN_HEIGHT = event.size self.window = self.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT], pygame.RESIZABLE, 32) if event.type == pygame.QUIT: self.end_game() if event.type == pygame.KEYDOWN: if event.key == pygame.K_w: self.my_tank.direction = U elif event.key == pygame.K_s: self.my_tank.direction = D elif event.key == pygame.K_a: self.my_tank.direction = L elif event.key == pygame.K_d: self.my_tank.direction = R else: return None self.my_tank.move_stop = False elif event.type == pygame.MOUSEBUTTONDOWN: if len(TankGame.my_bullet_list) < 3: bullet = self.my_tank.fire() load_music('fire') TankGame.my_bullet_list.append(bullet) elif event.type == pygame.KEYUP: self.my_tank.move_stop = True
Example #3
Source File: gui.py From ct-Raspi-Radiowecker with GNU General Public License v3.0 | 5 votes |
def process_events(self): clicked = False events = pygame.event.get() for event in events: # if the event is any type of quit request end the program if event.type == pygame.QUIT: quit() # resize the window if its requested elif event.type == pygame.VIDEORESIZE: self.window_size = event.size self.display_resize() # evaluate keypresses elif event.type == pygame.KEYDOWN: # exit on Escape if event.key == pygame.K_ESCAPE: quit() # switch to fullscreen on F11 elif event.key == pygame.K_F11: self.fullscreen = not self.fullscreen # evaluate all presses of the left mousebutton elif event.type == pygame.MOUSEBUTTONUP and event.button == 1: clicked = True self.clicktime = pygame.time.get_ticks() self.clickEvent = event click = None timediff = pygame.time.get_ticks() - self.clicktime if clicked and self.await_dblclk == False and self.click is None: self.await_dblclk = True pass elif clicked and timediff < self.dblclktime and self.await_dblclk: click = "double" self.await_dblclk = False elif timediff > self.dblclktime and self.await_dblclk: click = "single" self.await_dblclk = False if click != None: self.await_dblclk = False self.clicktime = 0 for element in self.elements: if hasattr(element, 'Callback') and element.Callback != None and element.Rect.collidepoint(self.clickEvent.pos): if click == "double" and element.DblclkCallback != None: element.DblclkCallback() else: element.Callback() # exit the programm
Example #4
Source File: eduactiv8.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def on_resize(self, size, info): if android is None: 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.screen = pygame.display.set_mode(self.size, pygame.RESIZABLE) self.sizer.update_sizer(self.size[0], self.size[1]) self.fs_rescale(info) #self.create_subsurfaces() self.config.settings["screenw"] = self.size[0] self.config.settings["screenh"] = self.size[1] self.config.settings_changed = True self.config.save_settings(self.db) # TODO check if commenting out the following code affects Windows/MacOS """ 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()
Example #5
Source File: booth.py From pibooth with MIT License | 5 votes |
def find_resize_event(self, events): """Return the first found event if found in the list. """ for event in events: if event.type == pygame.VIDEORESIZE: return event return None
Example #6
Source File: RUN_ME.py From SciSlice with MIT License | 5 votes |
def run(self): ''' Create a pygame screen until it is closed. ''' pygame.init() self.myfont = pygame.font.SysFont('monospace', 15) #automatically translates image to center of window x, y = self.screen.get_size() self.translateAll('x', (x/2-self.wireframes[c.MODEL].findcenter()[0])) self.translateAll('y', (y/2-self.wireframes[c.MODEL].findcenter()[1])) self.scaleAll(4) while True: self.r = 0 self.b = 0 self.g = 0 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() elif event.type == pygame.KEYDOWN: if event.key in key_to_function: key_to_function[event.key](self) elif event.type == pygame.MOUSEBUTTONDOWN: if event.button == 4: self.scaleAll(1.25) elif event.button == 5: self.scaleAll(0.8) elif event.type == pygame.MOUSEMOTION: if event.buttons[0]: shiftX, shiftY = event.rel self.translateAll('x', shiftX) self.translateAll('y', -shiftY) elif event.buttons[2]: rotY, rotX = event.rel self.rotateAll('X', rotX/270) self.rotateAll('Y', rotY/270) elif event.type == pygame.VIDEORESIZE: os.environ['SDL_VIDEO_WINDOW_POS'] = '' # Clears the default window location self.width, self.height = event.dict['size'] self.screen = pygame.display.set_mode(event.dict['size'], pygame.RESIZABLE) self.display() pygame.display.flip()
Example #7
Source File: PyKinectInfraRed.py From PyKinect2 with MIT License | 5 votes |
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()
Example #8
Source File: PyKinectBodyGame.py From PyKinect2 with MIT License | 4 votes |
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()