texture

        classDiagram
  Texture <|-- Color
  Texture <|-- Transparent
    

Texture classes in Charmy.

Charmy provides several types of textures, ranging from basid colors (with trasnsparency) to more complicated effects such as Gaussian blur implemented by filters.

Types of Textures

Currently, following types of textures are provided.

Color:

Represents pure RGBA colors

Transparent:

Represents transparent (not visible) and will not be rendered

For details, see docstrings of each class inside this file.

TextureLike Types

TextureLike types are type aliases that are used to represent types that are not subclasses of the Texture base class, but can be used to represent colors. e.g. tuple[int, int, int, int] can be used to represent RGBA colors.

For full list of TextureLike types, see (NOT WRITTEN YET) section in the document.

class charmy.styles.texture.Texture

基类:object

Texture base class in Charmy.

type: ClassVar[str] = 'texture'
static find_class_by_type(type_name: str) type[Texture] | None

Find a texture class by line type, return None if not found.

参数:

type_name -- Texture type in string

static from_json(json_content: dict[str, Any] | str) Texture

Create a texture object from json content.

This function is a static method of Texture and its subclasses. It creates and returns a textre object base on the JSON content given. This will be useful when loading line config from styles.

参数:

json_content -- The JSON content, either Python dict or raw string data

JSON Format

Textures can be represented in JSON in a structured way. Each JSON data must has a type key that defines the type of the texture, and also other keys and values that specify the params for that texture. The following is an example for pure colors.

{
"type": "color", 
"color": (255, 0, 0, 0.5),
}
class charmy.styles.texture.Color(color: tuple[int, int, int] | tuple[int, int, int, float] | str)

基类:Texture

Represents pure colors.

type: ClassVar[str] = 'color'
__init__(color: tuple[int, int, int] | tuple[int, int, int, float] | str)

Initialize a color object.

参数:

color -- The RGB(A) tuple or the HEX string that represents the color

color: tuple[int, int, int, float]
property r: int
property g: int
property b: int
property a: float
class charmy.styles.texture.Transparent

基类:Texture

Represents transparent.

Note that, in actual rendering, items with Transparent texture should be skipped.

type: ClassVar[str] = 'transparent'
__init__()

Initialize a Transparent object.

charmy.styles.texture.ensure_texture(texture_like: Texture | tuple[int, int, int] | tuple[int, int, int, float] | str | None | tuple[int, int, int, Literal[0]]) Texture

Convert TextureLike types into Texture objects.

参数:

texture_like -- The TextureLike value

Return texture:

The converted Texture object.