ColorPicker

class pygamelib.gfx.ui.ColorPicker(orientation: int = None, config: UiConfig = None)

Bases: object

The ColorPicker widget is a simple object to select the red, green and blue components of a color.

It provides the API to set/get each color channel independently as well as the mechanism to select and draw a selection box around one specific channel to give the user a visual cue about what he is modifying.

__init__(orientation: int = None, config: UiConfig = None) None

The constructor is really simple and takes only 2 arguments.

Parameters:
  • orientation (Orientation) – One of the orientation constants.

  • config (UiConfig) – The configuration object.

The default orientation is horizontal.

Warning

The orientation parameter is ignored for the moment.

Example:

color_picker = ColorPicker(constants.Orientation.HORIZONTAL, conf)
screen.place(color_picker, 10, 10)
screen.update()

Methods

__init__([orientation, config])

The constructor is really simple and takes only 2 arguments.

render_to_buffer(buffer, row, column, ...)

Render the object from the display buffer to the frame buffer.

Attributes

blue

Get / set the blue component of the color, the value needs to be an int between 0 and 255.

color

Get / set the edited color.

green

Get / set the green component of the color, the value needs to be an int between 0 and 255.

red

Get / set the red component of the color, the value needs to be an int between 0 and 255.

selection

Get / set the selection, it needs to be an int between 0 and 2 included.

property blue

Get / set the blue component of the color, the value needs to be an int between 0 and 255.

property color

Get / set the edited color.

The setter automatically forward the individual red, green and blue values to to the proper properties of that widget.

Parameters:

value (Color) – The color object.

Example:

current_color = color_picker.color
current_color.r += 10
color_picker.color = current_color
property green

Get / set the green component of the color, the value needs to be an int between 0 and 255.

property red

Get / set the red component of the color, the value needs to be an int between 0 and 255.

render_to_buffer(buffer, row: int, column: int, buffer_height: int, buffer_width: int) None

Render the object from the display buffer to the frame buffer.

This method is automatically called by pygamelib.engine.Screen.render().

Parameters:
  • buffer (numpy.array) – A screen buffer to render the item into.

  • row (int) – The row to render in.

  • column (int) – The column to render in.

  • height (int) – The total height of the display buffer.

  • width (int) – The total width of the display buffer.

property selection

Get / set the selection, it needs to be an int between 0 and 2 included.

0 correspond to the red channel, 1 to the green channel and 2 to the blue channel.

When this widget is rendered a Box will be rendered around the specified channel.