Skip to content

Commit

Permalink
Add cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurSonzogni committed Nov 28, 2021
1 parent 7189ee8 commit d013831
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)

FetchContent_Declare(ftxui
GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
GIT_TAG 18d1b04b7adb1c85515b7663a81d3ca18f255d23
GIT_TAG cecd54df42dd66fdf8386ed461e16b725bffc827
)

FetchContent_Declare(fmt
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ rgb-tui

A color picker with a terminal UI. Built with [FTXUI](https://github.com/ArthurSonzogni/FTXUI)

![demo](./demo.gif)
![demo](./demo.webp)

See [youtube](https://www.youtube.com/watch?v=ERtUrToBWEM)

Expand Down
Binary file removed demo.gif
Binary file not shown.
Binary file added demo.webp
Binary file not shown.
23 changes: 22 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,34 @@ class MainComponent : public ComponentBase {
int hue = h_;
Elements array;
int x_length = std::max(10, box_color_.x_max - box_color_.x_min) + 1;
int y_length = 11;
int y_length = 15;

int h, s, v;
ToHSV(r_, g_, b_, h, s, v);
int target_x = std::max(0, std::min(x_length - 1, (v * x_length) / 255));
int target_y =
std::max(0, std::min(2 * y_length - 1, (s * 2 * y_length) / 255));

for (int y = 0; y < y_length; ++y) {
Elements line;
for (int x = 0; x < x_length; ++x) {
int saturation_1 = 255 * (y + 0.0f) / float(y_length);
int saturation_2 = 255 * (y + 0.5f) / float(y_length);
int value = 255 * x / float(x_length);
if (x == target_x) {
if (2 * y == target_y) {
line.push_back(text(L"") //
| color(Color::HSV(hue, saturation_1, value)) //
| bgcolor(Color::Black)); //
continue;
}
if (2 * y == target_y + 1) {
line.push_back(text(L"") //
| color(Color::Black)//
| bgcolor(Color::HSV(hue, saturation_2, value)));
continue;
}
}
line.push_back(text(L"") //
| color(Color::HSV(hue, saturation_1, value)) //
| bgcolor(Color::HSV(hue, saturation_2, value)));
Expand Down

0 comments on commit d013831

Please sign in to comment.