From 267da90e91186f9f70be76a4d650c2e4d43ba8ba Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Sun, 17 Nov 2024 19:38:13 -0700 Subject: [PATCH] Fixed hsv conversion of black, and fixed default state for editor --- client/src/editor.c | 39 ++++++++++++++++++++++++--------------- client/src/hsv.c | 5 +++++ client/test/hsv.c | 2 +- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/client/src/editor.c b/client/src/editor.c index 49cc329..d9fe8f8 100644 --- a/client/src/editor.c +++ b/client/src/editor.c @@ -501,73 +501,73 @@ VkResult color_ui(ClientContext* context) { { .pos = {146, 2}, .size = {20, 20}, - .color = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}, + .color = {{0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}}, .events = UI_EVENT_BUTTON, }, { .pos = {168, 2}, .size = {20, 20}, - .color = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}, + .color = {{0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}}, .events = UI_EVENT_BUTTON, }, { .pos = {146, 24}, .size = {20, 20}, - .color = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}, + .color = {{0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}}, .events = UI_EVENT_BUTTON, }, { .pos = {168, 24}, .size = {20, 20}, - .color = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}, + .color = {{0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}}, .events = UI_EVENT_BUTTON, }, { .pos = {146, 46}, .size = {20, 20}, - .color = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}, + .color = {{0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}}, .events = UI_EVENT_BUTTON, }, { .pos = {168, 46}, .size = {20, 20}, - .color = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}, + .color = {{0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}}, .events = UI_EVENT_BUTTON, }, { .pos = {146, 68}, .size = {20, 20}, - .color = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}, + .color = {{0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}}, .events = UI_EVENT_BUTTON, }, { .pos = {168, 68}, .size = {20, 20}, - .color = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}, + .color = {{0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}}, .events = UI_EVENT_BUTTON, }, { .pos = {146, 90}, .size = {20, 20}, - .color = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}, + .color = {{0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}}, .events = UI_EVENT_BUTTON, }, { .pos = {168, 90}, .size = {20, 20}, - .color = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}, + .color = {{0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}}, .events = UI_EVENT_BUTTON, }, { .pos = {146, 112}, .size = {20, 20}, - .color = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}, + .color = {{0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}}, .events = UI_EVENT_BUTTON, }, { .pos = {168, 112}, .size = {20, 20}, - .color = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}, + .color = {{0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}}, .events = UI_EVENT_BUTTON, }, }; @@ -594,13 +594,22 @@ VkResult color_ui(ClientContext* context) { data->string[4] = '0'; data->string[5] = '0'; data->string[6] = '0'; - data->string[7] = '0'; - data->string[8] = '0'; + data->string[7] = 'F'; + data->string[8] = 'F'; data->string[9] = '\0'; + data->current[0] = 0; data->current[1] = 0; data->current[2] = 0; - data->current[3] = 0; + data->current[3] = 1; + + for(uint32_t i = 0; i < 12; i++) { + data->saved[i][0] = 0; + data->saved[i][1] = 0; + data->saved[i][2] = 0; + data->saved[i][3] = 1; + } + UICallbacks callbacks[] = { { diff --git a/client/src/hsv.c b/client/src/hsv.c index a5d5fc7..809c4ca 100644 --- a/client/src/hsv.c +++ b/client/src/hsv.c @@ -20,6 +20,11 @@ void rgb_to_hsv(vec3 rgb, double hsv[3]) { float M = min(rgb[0], min(rgb[1], rgb[2])); float C = hsv[2] - M; hsv[1] = C / hsv[2]; + if(C == 0) { + hsv[0] = 0; + return; + } + float X; if(hsv[2] == rgb[0] && M == rgb[2]) { diff --git a/client/test/hsv.c b/client/test/hsv.c index 4a897ea..cde6e72 100644 --- a/client/test/hsv.c +++ b/client/test/hsv.c @@ -33,7 +33,7 @@ int main() { for(int r = 0; r < 256; r++) { for(int g = 0; g < 256; g++) { for(int b = 0; b < 256; b++) { - if(test_conv(r, g, b, 0.001) != OK) { + if(test_conv(r, g, b, 0.000001) != OK) { return -1; } }