def __init__(self, scrsurf, charsurf, cellwidth, cellheight, refreshfn, rfnparams): self.NCOLS = 80 self.NROWS = 25 self.blankchar = 32 self.tabs = range(0, self.NCOLS, 5) self.cellwidth = cellwidth self.cellheight = cellheight self.scrsurf = scrsurf self.charsurf = charsurf try: len(self.charsurf) except TypeError: self.charsurf = (self.charsurf, ) except IndexError: raise ValueError('charsurf must be indexable using integers beginning with 0') for a in self.charsurf: sdl2.SDL_SetSurfaceBlendMode(a, sdl2.SDL_BLENDMODE_NONE) self.refreshfn = refreshfn self.rfnparams = rfnparams self.cbuf = ByteBuf2D(self.NCOLS, self.NROWS, self.blankchar) self.catt = 7 if (len(self.charsurf) >= 8) else 0 self.ccol = 0 self.crow = 0 self.abuf = ByteBuf2D(self.NCOLS, self.NROWS, self.catt) self.refresh() return
def __init__(бре, површ, положај, шкработине, име_боје): print("РамОдСлике __init__", име_боје) бре.положај = положај # претпоставка је да се положај мења споља бре.површ = површ бре.пуо = sdl2.SDL_Rect() бре.пуо.x = 0 бре.пуо.y = 0 бре.пуо.w = 16 бре.пуо.h = 16 средина = sdl2.SDL_Rect() средина.x = 3 средина.y = 3 средина.w = 10 средина.h = 10 бре.плава = sdl2.SDL_CreateRGBSurfaceWithFormat( 0, 16, 16, 32, sdl2.SDL_PIXELFORMAT_RGBA32) sdl2.SDL_SetSurfaceBlendMode(бре.плава, sdl2.SDL_BLENDMODE_BLEND) sdl2.SDL_FillRect(бре.плава, бре.пуо, инт_боја(бре.плава.contents.format, БОЈЕ[име_боје])) sdl2.SDL_FillRect( бре.плава, средина, инт_боја(бре.плава.contents.format, БОЈЕ['transparent'])) бре.шкработине = шкработине бре.шкработине.додај(2, бре)
def smoothscale(surface, size, DestSurface=None): """Scale a surface to an arbitrary size smoothly. Uses one of two different algorithms for scaling each dimension of the input surface as required. For shrinkage, the output pixels are area averages of the colors they cover. For expansion, a bilinear filter is used. For the amd64 and i686 architectures, optimized MMX routines are included and will run much faster than other machine types. The size is a 2 number sequence for (width, height). This function only works for 24-bit or 32-bit surfaces. An exception will be thrown if the input surface bit depth is less than 24. Usage: smoothscale(Surface, (width, height), DestSurface = None) Returns: Surface """ scale_x = size[0] // surface.w scale_y = size[1] // surface.h rsurf = None rsurf = gfxdraw.rotozoomSurfaceXY(surface.surface, 0.0, scale_x, scale_y, sdl2.sdlgfx.SMOOTHING_ON) if rsurf is None: raise sdl2.SDLError # This is inefficient. if DestSurface: sdl2.SDL_SetSurfaceBlendMode(rsurf.surface, sdl2.SDL_BLENDMODE_NONE) sdl2.SDL_UpperBlit(rsurf.surface, None, DestSurface.surface, None) return rsurf
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
def __init__(бре, главна_површ, стаклена_површ, обрада_догађаја, шкработине): print("Лупа __init__") обрада_догађаја.региструј(sdl2.SDL_KEYDOWN, бре.обради) бре.главна_површ = главна_површ бре.стаклена_површ = стаклена_површ бре.извор = sdl2.SDL_Rect(0, 0, 16, 16) бре.притока = sdl2.SDL_Rect(16, 16, 16*4, 16*4) бре.фокус = sdl2.SDL_CreateRGBSurfaceWithFormat(0, 16, 16, 24, sdl2.SDL_PIXELFORMAT_RGB888) sdl2.SDL_SetSurfaceBlendMode(бре.фокус, sdl2.SDL_BLENDMODE_NONE) бре.шкработине = шкработине бре.шкработине.додај(10000, бре)
def blit(self, source, dest, area=None, special_flags=0): """...""" sdl2.SDL_SetSurfaceBlendMode(source.surface, sdl2.SDL_BLENDMODE_BLEND) dest_rect = to_sdl_rect(dest) area_rect = to_sdl_rect(area) if area is not None else None err = sdl2.SDL_BlitSurface(source.surface, area_rect, self.surface, dest_rect) if err: raise sdl2.SDLError() dirty = Rect(dest[0], dest[1], source.w, source.h) return dirty.clip(self.get_rect())
def RGBAsurface(w, h, data = None): bpp = ctypes.c_int() rmask = ctypes.c_uint() gmask = ctypes.c_uint() bmask = ctypes.c_uint() amask = ctypes.c_uint() sdl2.pixels.SDL_PixelFormatEnumToMasks(sdl2.pixels.SDL_PIXELFORMAT_ABGR8888, ctypes.byref(bpp), ctypes.byref(rmask), ctypes.byref(gmask), ctypes.byref(bmask), ctypes.byref(amask)) if data is not None: if type(data) is bytearray: data_ptr = bar2voidp(data) elif type(data) is bytes: data_ptr = bytes2voidp(data) else: data_ptr = None rv = sdl2.surface.SDL_CreateRGBSurfaceFrom(data_ptr, w, h, bpp, w*4, rmask, gmask, bmask, amask) else: rv = sdl2.surface.SDL_CreateRGBSurface(0, w, h, bpp, rmask, gmask, bmask, amask) sdl2.SDL_SetSurfaceBlendMode(rv, sdl2.SDL_BLENDMODE_NONE) rv._data_ref = data # keep a ref return rv