From f0ea268ab2f656f49300e9d0d109635feda24914 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 23 Jan 2024 13:48:31 +0900 Subject: [PATCH] Fix color picking --- src/state.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/state.cpp b/src/state.cpp index c974214..e4316eb 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -223,15 +223,17 @@ void Tri::State::handle_events() { int mx = GetMouseX(); int my = GetMouseY(); if(mx < 0) { mx = 0; } - else if(mx >= (int)width) { mx = width - 1; } + else if(mx >= drawImage.width) { mx = drawImage.width - 1; } if(my < 0) { my = 0; } - else if(my >= (int)height) { my = height - 1; } + else if(my >= drawImage.height) { my = drawImage.height - 1; } - colorPickerColor[0] = colors[mx + my * width].r; - colorPickerColor[1] = colors[mx + my * width].g; - colorPickerColor[2] = colors[mx + my * width].b; + my = drawImage.height - my; + + colorPickerColor[0] = (float)(colors[mx + my * drawImage.width].r) / 255.0F; + colorPickerColor[1] = (float)(colors[mx + my * drawImage.width].g) / 255.0F; + colorPickerColor[2] = (float)(colors[mx + my * drawImage.width].b) / 255.0F; colorPickerColor[3] = 1.0f; - pointCircle.fillColor = colors[mx + my * width]; + pointCircle.fillColor = colors[mx + my * drawImage.width]; flags.reset(F_COPY_COLOR_MODE); set_notification_text("Color set");