Class RGBA
- All Implemented Interfaces:
Proxy
GdkRGBA
is used to represent 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.
-
Constructor Summary
ConstructorDescriptionRGBA()
Allocate a new RGBA.RGBA
(float red, float green, float blue, float alpha) Allocate a new RGBA with the fields set to the provided values.Allocate a new RGBA with the fields set to the provided values.Allocate a new RGBA.RGBA
(MemorySegment address) Create a RGBA proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Makes a copy of aGdkRGBA
.boolean
Compares twoGdkRGBA
colors.void
free()
Frees aGdkRGBA
.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the RGBA classint
hash()
A hash function suitable for using for a hash table that storesGdkRGBA
s.boolean
isClear()
Checks if an this RGBA value is transparent.boolean
isOpaque()
Checks if an this RGBA value is opaque.boolean
Parses a textual representation of a color.float
Read the value of the fieldalpha
.float
readBlue()
Read the value of the fieldblue
.float
Read the value of the fieldgreen
.float
readRed()
Read the value of the fieldred
.toString()
Returns a textual specification of this RGBA in the formrgb(r,g,b)
orrgba(r,g,b,a)
, where “r”, “g”, “b” and “a” represent the red, green, blue and alpha values respectively.void
writeAlpha
(float alpha) Write a value in the fieldalpha
.void
writeBlue
(float blue) Write a value in the fieldblue
.void
writeGreen
(float green) Write a value in the fieldgreen
.void
writeRed
(float red) Write a value in the fieldred
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
RGBA
Create a RGBA proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
RGBA
Allocate a new RGBA.- Parameters:
arena
- to control the memory allocation scope
-
RGBA
public RGBA()Allocate a new RGBA. The memory is allocated withArena.ofAuto()
. -
RGBA
Allocate a new RGBA with the fields set to the provided values.- Parameters:
red
- value for the fieldred
green
- value for the fieldgreen
blue
- value for the fieldblue
alpha
- value for the fieldalpha
arena
- to control the memory allocation scope
-
RGBA
public RGBA(float red, float green, float blue, float alpha) Allocate a new RGBA with the fields set to the provided values. The memory is allocated withArena.ofAuto()
.- Parameters:
red
- value for the fieldred
green
- value for the fieldgreen
blue
- value for the fieldblue
alpha
- value for the fieldalpha
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readRed
public float readRed()Read the value of the fieldred
.- Returns:
- The value of the field
red
-
writeRed
public void writeRed(float red) Write a value in the fieldred
.- Parameters:
red
- The new value for the fieldred
-
readGreen
public float readGreen()Read the value of the fieldgreen
.- Returns:
- The value of the field
green
-
writeGreen
public void writeGreen(float green) Write a value in the fieldgreen
.- Parameters:
green
- The new value for the fieldgreen
-
readBlue
public float readBlue()Read the value of the fieldblue
.- Returns:
- The value of the field
blue
-
writeBlue
public void writeBlue(float blue) Write a value in the fieldblue
.- Parameters:
blue
- The new value for the fieldblue
-
readAlpha
public float readAlpha()Read the value of the fieldalpha
.- Returns:
- The value of the field
alpha
-
writeAlpha
public void writeAlpha(float alpha) Write a value in the fieldalpha
.- Parameters:
alpha
- The new value for the fieldalpha
-
copy
-
equal
Compares twoGdkRGBA
colors.- Parameters:
p2
- anotherGdkRGBA
- Returns:
true
if the two colors compare equal
-
free
public void free()Frees aGdkRGBA
. -
hash
public int hash()A hash function suitable for using for a hash table that storesGdkRGBA
s.- Returns:
- The hash value for this RGBA
-
isClear
public boolean isClear()Checks if an this RGBA value is transparent.That is, drawing with the value would not produce any change.
- Returns:
true
if the this RGBA is clear
-
isOpaque
public boolean isOpaque()Checks if an this RGBA value is opaque.That is, drawing with the value will not retain any results from previous contents.
- Returns:
true
if the this RGBA is opaque
-
parse
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(hue, saturation, lightness)"
- A HSLA color in the form "hsla(hue, saturation, lightness, alpha)"
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.
- Parameters:
spec
- the string specifying the color- Returns:
true
if the parsing succeeded
-
toString
Returns a textual specification of this RGBA in the formrgb(r,g,b)
orrgba(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
parse(java.lang.String)
.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.
-