Beispiel #1
0
 def set_mode(self, mode_info):
     """Initialise a given text or graphics mode."""
     self.text_mode = mode_info.is_text_mode
     # unpack mode info struct
     self.font_height = mode_info.font_height
     self.font_width = mode_info.font_width
     # prebuilt glyphs
     # NOTE: [x][y] format - change this if we change pixels2d
     self.glyph_dict = {
         u'\0': numpy.zeros((self.font_width, self.font_height))
     }
     self.num_pages = mode_info.num_pages
     self.mode_has_blink = mode_info.has_blink
     self.mode_has_artifacts = False
     if not self.text_mode:
         self.bitsperpixel = mode_info.bitsperpixel
         self.mode_has_artifacts = mode_info.supports_artifacts
     # logical size
     self.size = (mode_info.pixel_width, mode_info.pixel_height)
     self._resize_display(*self._find_display_size(
         self.size[0], self.size[1], self.border_width))
     # set standard cursor
     self.set_cursor_shape(self.font_width, self.font_height, 0,
                           self.font_height)
     # screen pages
     canvas_width, canvas_height = self.size
     self.canvas = [
         sdl2.SDL_CreateRGBSurface(0, canvas_width, canvas_height, 8, 0, 0,
                                   0, 0) for _ in range(self.num_pages)
     ]
     self.pixels = [pixels2d(canvas.contents) for canvas in self.canvas]
     # create work surface for border and composite
     self.border_x = int(canvas_width * self.border_width // 200)
     self.border_y = int(canvas_height * self.border_width // 200)
     work_width = canvas_width + 2 * self.border_x
     work_height = canvas_height + 2 * self.border_y
     sdl2.SDL_FreeSurface(self.work_surface)
     self.work_surface = sdl2.SDL_CreateRGBSurface(0, work_width,
                                                   work_height, 8, 0, 0, 0,
                                                   0)
     self.work_pixels = pixels2d(
         self.work_surface.contents)[self.border_x:work_width -
                                     self.border_x,
                                     self.border_y:work_height -
                                     self.border_y]
     # create overlay for clipboard selection feedback
     # use convertsurface to create a copy of the display surface format
     pixelformat = self.display_surface.contents.format
     self.overlay = sdl2.SDL_ConvertSurface(self.work_surface, pixelformat,
                                            0)
     sdl2.SDL_SetSurfaceBlendMode(self.overlay, sdl2.SDL_BLENDMODE_ADD)
     # initialise clipboard
     self.clipboard = video_graphical.ClipboardInterface(
         self, mode_info.width, mode_info.height)
     self.screen_changed = True
     self._has_window = True
Beispiel #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)
Beispiel #3
0
    def __init__(self,
                 width,
                 height,
                 angle=0,
                 depth=32,
                 mask=(255, 65280, 16711680, 4278190080)):

        self.type = "rect"

        self.surface = sdl2.SDL_CreateRGBSurface(0, width, height, depth,
                                                 mask[0], mask[1], mask[2],
                                                 mask[3]).contents
        self.renderer = sdl2.SDL_CreateSoftwareRenderer(self.surface, -1, 0)

        self.w = width
        self.h = height

        self.depth = depth
        self.mask = mask

        self.angle = angle
Beispiel #4
0
sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO)

#This will return a handle to an open 'Notepad.exe' window.
window_handle = get_windows_bytitle("Untitled", False)

#Create a window so that the hint below can be set
a = sdl2.SDL_CreateWindow("test window", sdl2.SDL_WINDOWPOS_UNDEFINED,
                          sdl2.SDL_WINDOWPOS_UNDEFINED, 200, 200, 0)
#Set hint as recommended by SDL documentation: https://wiki.libsdl.org/SDL_CreateWindowFrom#Remarks
result = sdl2.SDL_SetHint(sdl2.SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT,
                          hex(id(a)))
print(sdl2.SDL_GetError())

np_window = sdl2.SDL_CreateWindowFrom(window_handle[0])
print(sdl2.SDL_GetError())

np_sur = sdl2.SDL_GetWindowSurface(np_window)
print(sdl2.SDL_GetError())

save_sur = sdl2.SDL_CreateRGBSurface(0, np_sur[0].w, np_sur[0].h, 32, 0, 0, 0,
                                     0)
print(sdl2.SDL_GetError())
r = sdl2.SDL_BlitSurface(np_sur, None, save_sur, None)
print(sdl2.SDL_GetError())

result = sdl2.SDL_SaveBMP(save_sur, 'test.bmp')
print(sdl2.SDL_GetError())
sdl2.SDL_FreeSurface(save_sur)
print(sdl2.SDL_GetError())
Beispiel #5
0
 def create_surface(self, w, h, bpp=32, masks=None):
     """..."""
     masks = masks or (0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF)
     rmask, gmask, bmask, amask = masks
     return sdl2.SDL_CreateRGBSurface(0, w, h, bpp, rmask, gmask, bmask,
                                      amask)