예제 #1
0
 def _do_flip(self):
     """Draw the canvas to the screen."""
     sdl2.SDL_FillRect(self.work_surface, None, self.border_attr)
     if self.composite_artifacts:
         self.work_pixels[:] = video_graphical.apply_composite_artifacts(
             self.pixels[self.vpagenum], 4 // self.bitsperpixel)
         sdl2.SDL_SetSurfacePalette(self.work_surface,
                                    self.composite_palette)
     else:
         self.work_pixels[:] = self.pixels[self.vpagenum]
         sdl2.SDL_SetSurfacePalette(self.work_surface,
                                    self.show_palette[self.blink_state])
     # apply cursor to work surface
     self._show_cursor(True)
     # convert 8-bit work surface to (usually) 32-bit display surface format
     pixelformat = self.display_surface.contents.format
     conv = sdl2.SDL_ConvertSurface(self.work_surface, pixelformat, 0)
     # scale converted surface and blit onto display
     if not self.smooth:
         sdl2.SDL_BlitScaled(conv, None, self.display_surface, None)
     else:
         # smooth-scale converted surface
         w, h = self.window_width, self.window_height
         zoomx = ctypes.c_double(w / (self.size[0] + 2.0 * self.border_x))
         zoomy = ctypes.c_double(h / (self.size[1] + 2.0 * self.border_y))
         # only free the surface just before zoomSurface needs to re-allocate
         # so that the memory block is highly likely to be easily available
         # this seems to avoid unpredictable delays
         sdl2.SDL_FreeSurface(self.zoomed)
         self.zoomed = sdl2.sdlgfx.zoomSurface(conv, zoomx, zoomy,
                                               sdl2.sdlgfx.SMOOTHING_ON)
         # blit onto display
         sdl2.SDL_BlitSurface(self.zoomed, None, self.display_surface, None)
     # create clipboard feedback
     if self.clipboard.active():
         rects = (sdl2.SDL_Rect(r[0] + self.border_x, r[1] + self.border_y,
                                r[2], r[3])
                  for r in self.clipboard.selection_rect)
         sdl_rects = (sdl2.SDL_Rect *
                      len(self.clipboard.selection_rect))(*rects)
         sdl2.SDL_FillRect(
             self.overlay, None,
             sdl2.SDL_MapRGBA(self.overlay.contents.format, 0, 0, 0, 0))
         sdl2.SDL_FillRects(
             self.overlay, sdl_rects, len(sdl_rects),
             sdl2.SDL_MapRGBA(self.overlay.contents.format, 128, 0, 128, 0))
         sdl2.SDL_BlitScaled(self.overlay, None, self.display_surface, None)
     # flip the display
     sdl2.SDL_UpdateWindowSurface(self.display)
     # destroy the temporary surface
     sdl2.SDL_FreeSurface(conv)
예제 #2
0
 def _set_icon(self):
     """Set the icon on the SDL window."""
     mask = numpy.array(self.icon).T.repeat(2, 0).repeat(2, 1)
     icon = sdl2.SDL_CreateRGBSurface(0, mask.shape[0], mask.shape[1], 8, 0, 0, 0, 0)
     pixels2d(icon.contents)[:] = mask
     # icon palette (black & white)
     icon_palette = sdl2.SDL_AllocPalette(256)
     icon_colors = [ sdl2.SDL_Color(x, x, x, 255) for x in [0, 255] + [255]*254 ]
     sdl2.SDL_SetPaletteColors(icon_palette, (sdl2.SDL_Color * 256)(*icon_colors), 0, 2)
     sdl2.SDL_SetSurfacePalette(icon, icon_palette)
     sdl2.SDL_SetWindowIcon(self.display, icon)
     sdl2.SDL_FreeSurface(icon)
     sdl2.SDL_FreePalette(icon_palette)