{"action":"created","issue":{"url":"https://api.github.com/repos/ocornut/imgui/issues/346","repository_url":"https://api.github.com/repos/ocornut/imgui","labels_url":"https://api.github.com/repos/ocornut/imgui/issues/346/labels{/name}","comments_url":"https://api.github.com/repos/ocornut/imgui/issues/346/comments","events_url":"https://api.github.com/repos/ocornut/imgui/issues/346/events","html_url":"https://github.com/ocornut/imgui/issues/346","id":107801252,"number":346,"title":"Color picker","user":{"login":"nem0","id":153526,"avatar_url":"https://avatars.githubusercontent.com/u/153526?v=3","gravatar_id":"","url":"https://api.github.com/users/nem0","html_url":"https://github.com/nem0","followers_url":"https://api.github.com/users/nem0/followers","following_url":"https://api.github.com/users/nem0/following{/other_user}","gists_url":"https://api.github.com/users/nem0/gists{/gist_id}","starred_url":"https://api.github.com/users/nem0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nem0/subscriptions","organizations_url":"https://api.github.com/users/nem0/orgs","repos_url":"https://api.github.com/users/nem0/repos","events_url":"https://api.github.com/users/nem0/events{/privacy}","received_events_url":"https://api.github.com/users/nem0/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ocornut/imgui/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/ocornut/imgui/labels/in%20progress","name":"in progress","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":33,"created_at":"2015-09-22T21:00:31Z","updated_at":"2016-02-22T12:41:24Z","closed_at":null,"body":"I've implemented advanced color picker, maybe somebody find this useful:\r\n\r\n![color_picker](https://cloud.githubusercontent.com/assets/153526/10031411/52197d38-617d-11e5-94cd-2b12f93211f2.gif)\r\n\r\n```cpp\r\n\r\n\tvoid ImDrawList::AddTriangleFilledMultiColor(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col_a, ImU32 col_b, ImU32 col_c)\r\n\t{\r\n\t\tif (((col_a | col_b | col_c) >> 24) == 0)\r\n\t\t\treturn;\r\n\r\n\t\tconst ImVec2 uv = GImGui->FontTexUvWhitePixel;\r\n\t\tPrimReserve(3, 3);\r\n\t\tPrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx)); PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx + 1)); PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx + 2));\r\n\t\tPrimWriteVtx(a, uv, col_a);\r\n\t\tPrimWriteVtx(b, uv, col_b);\r\n\t\tPrimWriteVtx(c, uv, col_c);\r\n\t}\r\n\r\n\tbool ColorPicker(const char* label, ImColor* color)\r\n\t{\r\n\t\tstatic const float HUE_PICKER_WIDTH = 20.0f;\r\n\t\tstatic const float CROSSHAIR_SIZE = 7.0f;\r\n\t\tstatic const ImVec2 SV_PICKER_SIZE = ImVec2(200, 200);\r\n\r\n\t\tbool value_changed = false;\r\n\r\n\t\tImDrawList* draw_list = ImGui::GetWindowDrawList();\r\n\r\n\t\tImVec2 picker_pos = ImGui::GetCursorScreenPos();\r\n\r\n\t\tImColor colors[] = {ImColor(255, 0, 0),\r\n\t\t\tImColor(255, 255, 0),\r\n\t\t\tImColor(0, 255, 0),\r\n\t\t\tImColor(0, 255, 255),\r\n\t\t\tImColor(0, 0, 255),\r\n\t\t\tImColor(255, 0, 255),\r\n\t\t\tImColor(255, 0, 0)};\r\n\r\n\t\tfor (int i = 0; i < 6; ++i)\r\n\t\t{\r\n\t\t\tdraw_list->AddRectFilledMultiColor(\r\n\t\t\t\tImVec2(picker_pos.x + SV_PICKER_SIZE.x + 10, picker_pos.y + i * (SV_PICKER_SIZE.y / 6)),\r\n\t\t\t\tImVec2(picker_pos.x + SV_PICKER_SIZE.x + 10 + HUE_PICKER_WIDTH,\r\n\t\t\t\t\tpicker_pos.y + (i + 1) * (SV_PICKER_SIZE.y / 6)),\r\n\t\t\t\tcolors[i],\r\n\t\t\t\tcolors[i],\r\n\t\t\t\tcolors[i + 1],\r\n\t\t\t\tcolors[i + 1]);\r\n\t\t}\r\n\r\n\t\tfloat hue, saturation, value;\r\n\t\tImGui::ColorConvertRGBtoHSV(\r\n\t\t\tcolor->Value.x, color->Value.y, color->Value.z, hue, saturation, value);\r\n\t\tauto hue_color = ImColor::HSV(hue, 1, 1);\r\n\r\n\t\tdraw_list->AddLine(\r\n\t\t\tImVec2(picker_pos.x + SV_PICKER_SIZE.x + 8, picker_pos.y + hue * SV_PICKER_SIZE.y),\r\n\t\t\tImVec2(picker_pos.x + SV_PICKER_SIZE.x + 12 + HUE_PICKER_WIDTH,\r\n\t\t\t\tpicker_pos.y + hue * SV_PICKER_SIZE.y),\r\n\t\t\tImColor(255, 255, 255));\r\n\r\n\t\tdraw_list->AddTriangleFilledMultiColor(picker_pos,\r\n\t\t\tImVec2(picker_pos.x + SV_PICKER_SIZE.x, picker_pos.y + SV_PICKER_SIZE.y),\r\n\t\t\tImVec2(picker_pos.x, picker_pos.y + SV_PICKER_SIZE.y),\r\n\t\t\tImColor(0, 0, 0),\r\n\t\t\thue_color,\r\n\t\t\tImColor(255, 255, 255));\r\n\r\n\t\tfloat x = saturation * value;\r\n\t\tImVec2 p(picker_pos.x + x * SV_PICKER_SIZE.x, picker_pos.y + value * SV_PICKER_SIZE.y);\r\n\t\tdraw_list->AddLine(ImVec2(p.x - CROSSHAIR_SIZE, p.y), ImVec2(p.x - 2, p.y), ImColor(255, 255, 255));\r\n\t\tdraw_list->AddLine(ImVec2(p.x + CROSSHAIR_SIZE, p.y), ImVec2(p.x + 2, p.y), ImColor(255, 255, 255));\r\n\t\tdraw_list->AddLine(ImVec2(p.x, p.y + CROSSHAIR_SIZE), ImVec2(p.x, p.y + 2), ImColor(255, 255, 255));\r\n\t\tdraw_list->AddLine(ImVec2(p.x, p.y - CROSSHAIR_SIZE), ImVec2(p.x, p.y - 2), ImColor(255, 255, 255));\r\n\r\n\t\tImGui::InvisibleButton(\"saturation_value_selector\", SV_PICKER_SIZE);\r\n\t\tif (ImGui::IsItemHovered())\r\n\t\t{\r\n\t\t\tImVec2 mouse_pos_in_canvas = ImVec2(\r\n\t\t\t\tImGui::GetIO().MousePos.x - picker_pos.x, ImGui::GetIO().MousePos.y - picker_pos.y);\r\n\t\t\tif (ImGui::GetIO().MouseDown[0])\r\n\t\t\t{\r\n\t\t\t\tmouse_pos_in_canvas.x =\r\n\t\t\t\t\tImMin(mouse_pos_in_canvas.x, mouse_pos_in_canvas.y);\r\n\r\n\t\t\t\tvalue = mouse_pos_in_canvas.y / SV_PICKER_SIZE.y;\r\n\t\t\t\tsaturation = value == 0 ? 0 : (mouse_pos_in_canvas.x / SV_PICKER_SIZE.x) / value;\r\n\t\t\t\tvalue_changed = true;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tImGui::SetCursorScreenPos(ImVec2(picker_pos.x + SV_PICKER_SIZE.x + 10, picker_pos.y));\r\n\t\tImGui::InvisibleButton(\"hue_selector\", ImVec2(HUE_PICKER_WIDTH, SV_PICKER_SIZE.y));\r\n\r\n\t\tif (ImGui::IsItemHovered())\r\n\t\t{\r\n\t\t\tif (ImGui::GetIO().MouseDown[0])\r\n\t\t\t{\r\n\t\t\t\thue = ((ImGui::GetIO().MousePos.y - picker_pos.y) / SV_PICKER_SIZE.y);\r\n\t\t\t\tvalue_changed = true;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t*color = ImColor::HSV(hue, saturation, value);\r\n\t\treturn value_changed | ImGui::ColorEdit3(label, &color->Value.x);\r\n\t}\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/ocornut/imgui/issues/comments/187155517","html_url":"https://github.com/ocornut/imgui/issues/346#issuecomment-187155517","issue_url":"https://api.github.com/repos/ocornut/imgui/issues/346","id":187155517,"user":{"login":"nem0","id":153526,"avatar_url":"https://avatars.githubusercontent.com/u/153526?v=3","gravatar_id":"","url":"https://api.github.com/users/nem0","html_url":"https://github.com/nem0","followers_url":"https://api.github.com/users/nem0/followers","following_url":"https://api.github.com/users/nem0/following{/other_user}","gists_url":"https://api.github.com/users/nem0/gists{/gist_id}","starred_url":"https://api.github.com/users/nem0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nem0/subscriptions","organizations_url":"https://api.github.com/users/nem0/orgs","repos_url":"https://api.github.com/users/nem0/repos","events_url":"https://api.github.com/users/nem0/events{/privacy}","received_events_url":"https://api.github.com/users/nem0/received_events","type":"User","site_admin":false},"created_at":"2016-02-22T12:41:24Z","updated_at":"2016-02-22T12:41:24Z","body":"@ocornut good job\r\n\r\n> RGB/HSV/HEX\r\n\r\ndoes this contex menu need to be in the core? Users can do it manually anyway. "}}