diff options
author | Benji Dial <benji6283@gmail.com> | 2021-03-08 15:51:56 -0500 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2021-03-08 15:51:56 -0500 |
commit | af52ddac750311ace3bd997245771b26119e1659 (patch) | |
tree | 332c92a654ac97601be0e0a3ad2ff06d33bd645a /src/user/raleigh/w | |
parent | 8221fd5451f094defa9866f98026b74a969f7693 (diff) | |
download | portland-os-af52ddac750311ace3bd997245771b26119e1659.tar.gz |
colorpicker for raleigh
Diffstat (limited to 'src/user/raleigh/w')
-rw-r--r-- | src/user/raleigh/w/colorpicker.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/user/raleigh/w/colorpicker.cpp b/src/user/raleigh/w/colorpicker.cpp new file mode 100644 index 0000000..faa720e --- /dev/null +++ b/src/user/raleigh/w/colorpicker.cpp @@ -0,0 +1,55 @@ +#include <raleigh/w/colorpicker.h> + +namespace raleigh { + colorpicker::colorpicker(_pixel_t default_color, uint8_t resolution) + : picked_color(default_color), resolution(resolution), inv_res(256 / resolution) { + size = coord(inv_res * 2, inv_res * 2); + closest_opaque = this; + } + + __attribute__ ((pure)) + _pixel_t colorpicker::get_picked_color() { + return picked_color; + } + + void colorpicker::paint(_pixel_t *pixbuf, uint32_t pitch) { + _pixel_t *pb_ptr = pixbuf + window_offset.y * pitch + window_offset.x; + for (uint16_t b = 0; b < inv_res; ++b) + for (uint16_t g = 0; g < inv_res; ++g) + pb_ptr[b * pitch + g] = (_pixel_t){.r = picked_color.r, .g = g * resolution, .b = b * resolution}; + pb_ptr += inv_res; + for (uint16_t r = 0; r < inv_res; ++r) + for (uint16_t b = 0; b < inv_res; ++b) + pb_ptr[r * pitch + b] = (_pixel_t){.r = r * resolution, .g = picked_color.g, .b = b * resolution}; + pb_ptr += inv_res * (pitch - 1); + for (uint16_t g = 0; g < inv_res; ++g) + for (uint16_t r = 0; r < inv_res; ++r) + pb_ptr[g * pitch + r] = (_pixel_t){.r = r * resolution, .g = g * resolution, .b = picked_color.b}; + pb_ptr += inv_res; + for (uint16_t y = 0; y < inv_res; ++y) + for (uint16_t x = 0; x < inv_res; ++x) + pb_ptr[y * pitch + x] = picked_color; + } + + void colorpicker::handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) { + if (up || (click_type != mouse_packet::LEFT)) + return; + window_coords.x -= window_offset.x; + window_coords.y -= window_offset.y; + if ((window_coords.x < inv_res) && (window_coords.y < inv_res)) { + picked_color.g = window_coords.x * resolution; + picked_color.b = window_coords.y * resolution; + } + else if (window_coords.y < inv_res) { + picked_color.b = (window_coords.x - inv_res) * resolution; + picked_color.r = window_coords.y * resolution; + } + else if (window_coords.x < inv_res) { + picked_color.r = window_coords.x * resolution; + picked_color.g = (window_coords.y - inv_res) * resolution; + } + w->notify_needs_paint(*this); + } + + void colorpicker::notify_has_opaque_parent(widget *parent) {} +}
\ No newline at end of file |