Skip to content

Gdk.RGBA

record (struct)

Represents a color, in a way that is compatible with cairo’s notion of color.

GdkRGBA is a convenient way to pass colors around. It’s based on cairo’s way to deal with colors and mirrors its behavior. All values are in the range from 0.0 to 1.0 inclusive. So the color (0.0, 0.0, 0.0, 0.0) represents transparent black and (1.0, 1.0, 1.0, 1.0) is opaque white. Other values will be clamped to this range when drawing.

Methods

copy

def copy(self) -> RGBA

Makes a copy of a GdkRGBA.

The result must be freed through RGBA.free.

equal

def equal(self, p2: RGBA) -> bool

Compares two GdkRGBA colors.

Parameters:

  • p2 — another GdkRGBA

free

def free(self) -> None

Frees a GdkRGBA.

hash

def hash(self) -> int

A hash function suitable for using for a hash table that stores GdkRGBAs.

is_clear

def is_clear(self) -> bool

Checks if an rgba value is transparent.

That is, drawing with the value would not produce any change.

is_opaque

def is_opaque(self) -> bool

Checks if an rgba value is opaque.

That is, drawing with the value will not retain any results from previous contents.

parse

def parse(self, spec: str) -> bool

Parses a textual representation of a color.

The string can be either one of:

  • A standard name (Taken from the CSS specification).
  • A hexadecimal value in the form “#rgb”, “#rrggbb”, “#rrrgggbbb” or ”#rrrrggggbbbb”
  • A hexadecimal value in the form “#rgba”, “#rrggbbaa”, or ”#rrrrggggbbbbaaaa”
  • A RGB color in the form “rgb(r,g,b)” (In this case the color will have full opacity)
  • A RGBA color in the form “rgba(r,g,b,a)”
  • A HSL color in the form “hsl(h,s,l)”
  • A HSLA color in the form “hsla(h,s,l,a)”

Where “r”, “g”, “b” and “a” are respectively the red, green, blue and alpha color values. In the last two cases, “r”, “g”, and “b” are either integers in the range 0 to 255 or percentage values in the range 0% to 100%, and a is a floating point value in the range 0 to 1. The range for “h” is 0 to 360, and “s”, “l” can be either numbers in the range 0 to 100 or percentages.

Parameters:

  • spec — the string specifying the color

print

def print(self, string: GLib.String) -> GLib.String

to_string

def to_string(self) -> str

Returns a textual specification of rgba in the form rgb(r,g,b) or rgba(r,g,b,a), where “r”, “g”, “b” and “a” represent the red, green, blue and alpha values respectively. “r”, “g”, and “b” are represented as integers in the range 0 to 255, and “a” is represented as a floating point value in the range 0 to 1.

These string forms are string forms that are supported by the CSS3 colors module, and can be parsed by RGBA.parse.

Note that this string representation may lose some precision, since “r”, “g” and “b” are represented as 8-bit integers. If this is a concern, you should use a different representation.

Properties

red

red: float  # read/write

green

green: float  # read/write

blue

blue: float  # read/write

alpha

alpha: float  # read/write