Add api for messing with color palette in text mode

This is important so we have more flexibility over
what colors show up in the text splash
calculate-0.9.5
Ray Strode 16 years ago
parent 77073321d9
commit aae9a4da8f

@ -9,3 +9,4 @@
- rotate boot.log per boot cycle (might be easiest to just fork/exec out to logrotate directly)
- fix error handling. In particular, ply_open_module gets it completely wrong (replies on errno instead of dlerror())
- consider moving text code from ply-window to a ply-text-buffer analog of ply-frame-buffer
- restore text color palette on exit

@ -540,6 +540,86 @@ ply_window_get_foreground_color (ply_window_t *window)
return window->foreground_color;
}
static uint8_t *
ply_window_get_color_palette (ply_window_t *window)
{
uint8_t *palette;
palette = malloc (48);
if (ioctl (window->tty_fd, GIO_CMAP, palette) < 0)
{
free (palette);
return NULL;
}
return palette;
}
static bool
ply_window_set_color_palette (ply_window_t *window,
uint8_t *palette)
{
if (ioctl (window->tty_fd, PIO_CMAP, palette) < 0)
return false;
return true;
}
uint32_t
ply_window_get_color_hex_value (ply_window_t *window,
ply_window_color_t color)
{
uint8_t *palette;
uint8_t red, green, blue;
uint32_t hex_value;
assert (window != NULL);
assert (color >= 0 && color <= PLY_WINDOW_COLOR_WHITE);
palette = ply_window_get_color_palette (window);
if (palette == NULL)
return 0;
red = (uint8_t) *(palette + 3 * color);
green = (uint8_t) *(palette + 3 * color + 1);
blue = (uint8_t) *(palette + 3 * color + 2);
free (palette);
hex_value = red << 16 | green << 8 | blue;
return hex_value;
}
void
ply_window_set_color_hex_value (ply_window_t *window,
ply_window_color_t color,
uint32_t hex_value)
{
uint8_t *palette;
uint8_t red, green, blue;
assert (window != NULL);
assert (color >= 0 && color <= PLY_WINDOW_COLOR_WHITE);
palette = ply_window_get_color_palette (window);
if (palette == NULL)
return;
red = (uint8_t) ((hex_value >> 16) & 0xff);
green = (uint8_t) ((hex_value >> 8) & 0xff);
blue = (uint8_t) (hex_value & 0xff);
*(palette + 3 * color) = red;
*(palette + 3 * color + 1) = green;
*(palette + 3 * color + 2) = blue;
ply_window_set_color_palette (window, palette);
free (palette);
}
void
ply_window_hide_text_cursor (ply_window_t *window)
{

@ -97,10 +97,15 @@ void ply_window_set_background_color (ply_window_t *window,
ply_window_color_t color);
void ply_window_set_foreground_color (ply_window_t *window,
ply_window_color_t color);
ply_window_color_t ply_window_get_background_color (ply_window_t *window);
ply_window_color_t ply_window_get_foreground_color (ply_window_t *window);
uint32_t ply_window_get_color_hex_value (ply_window_t *window,
ply_window_color_t color);
void ply_window_set_color_hex_value (ply_window_t *window,
ply_window_color_t color,
uint32_t hex_value);
void ply_window_attach_to_event_loop (ply_window_t *window,
ply_event_loop_t *loop);
ply_frame_buffer_t *ply_window_get_frame_buffer (ply_window_t *window);

Loading…
Cancel
Save