def from_color(self, color, size=(0, 0), bpp=32, masks=None): """Creates a sprite with a certain color. """ color = convert_to_color(color) if masks: rmask, gmask, bmask, amask = masks else: rmask = gmask = bmask = amask = 0 sf = sdlsurface.create_rgb_surface(size[0], size[1], bpp, rmask, gmask, bmask, amask) fmt = sf.format if fmt.Amask != 0: # Target has an alpha mask c = pixels.map_rgba(fmt, color.r, color.g, color.b, color.a) else: c = pixels.map_rgb(fmt, color.r, color.g, color.b) sdlsurface.fill_rect(sf, None, c) return self.from_surface(sf, True)
def prepare_color(color, target): """Prepares the passed color for the passed target. """ color = convert_to_color(color) pformat = None # Software surfaces if isinstance(target, sdlpixels.SDL_PixelFormat): pformat = target elif isinstance(target, sdlsurface.SDL_Surface): pformat = target.format elif isinstance(target, SoftwareSprite): pformat = target.surface.format if pformat is None: raise TypeError("unsupported target type") if pformat.Amask != 0: # Target has an alpha mask return sdlpixels.map_rgba(pformat, color.r, color.g, color.b, color.a) return sdlpixels.map_rgb(pformat, color.r, color.g, color.b)
def color(self, value): """The drawing color of the RenderContext.""" c = convert_to_color(value) render.set_render_draw_color(self.renderer, c.r, c.g, c.b, c.a)
def color(self): """The drawing color of the RenderContext.""" return convert_to_color(render.get_render_draw_color(self.renderer))