From 5544adf345e8822f328df25880a1f36fe476c4a9 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 19 Jun 2024 14:25:09 +0200 Subject: [PATCH] split icons to their own files --- src/CMakeLists.txt | 6 ++ src/chat_gui/contact_list.cpp | 132 +--------------------------------- src/chat_gui/icons/cloud.cpp | 41 +++++++++++ src/chat_gui/icons/cloud.hpp | 11 +++ src/chat_gui/icons/direct.cpp | 49 +++++++++++++ src/chat_gui/icons/direct.hpp | 10 +++ src/chat_gui/icons/mail.cpp | 50 +++++++++++++ src/chat_gui/icons/mail.hpp | 11 +++ 8 files changed, 181 insertions(+), 129 deletions(-) create mode 100644 src/chat_gui/icons/cloud.cpp create mode 100644 src/chat_gui/icons/cloud.hpp create mode 100644 src/chat_gui/icons/direct.cpp create mode 100644 src/chat_gui/icons/direct.hpp create mode 100644 src/chat_gui/icons/mail.cpp create mode 100644 src/chat_gui/icons/mail.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 63596938..d4c908bb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -67,6 +67,12 @@ target_sources(tomato PUBLIC ./chat_gui/theme.hpp ./chat_gui/theme.cpp + ./chat_gui/icons/direct.hpp + ./chat_gui/icons/direct.cpp + ./chat_gui/icons/cloud.hpp + ./chat_gui/icons/cloud.cpp + ./chat_gui/icons/mail.hpp + ./chat_gui/icons/mail.cpp ./chat_gui/contact_list.hpp ./chat_gui/contact_list.cpp ./chat_gui/file_selector.hpp diff --git a/src/chat_gui/contact_list.cpp b/src/chat_gui/contact_list.cpp index a9c6434f..62b017fb 100644 --- a/src/chat_gui/contact_list.cpp +++ b/src/chat_gui/contact_list.cpp @@ -5,135 +5,9 @@ #include //#include -#include - -static void drawIconDirectLines( - const ImVec2 p0, - const ImVec2 p1_o, - const ImU32 col, - const float thickness -) { -#define PLINE(x0, y0, x1, y1) \ - ImGui::GetWindowDrawList()->AddLine( \ - {p0.x + p1_o.x*(x0), p0.y + p1_o.y*(y0)}, \ - {p0.x + p1_o.x*(x1), p0.y + p1_o.y*(y1)}, \ - col, \ - thickness \ - ); - - // arrow 1 - // (3,1) -> (9,7) - PLINE(0.3f, 0.1f, 0.9f, 0.7f) - // (9,7) -> (9,5) - PLINE(0.9f, 0.7f, 0.9f, 0.5f) - // (9,7) -> (7,7) - PLINE(0.9f, 0.7f, 0.7f, 0.7f) - - // arrow 2 - // (7,9) -> (1,3) - PLINE(0.7f, 0.9f, 0.1f, 0.3f) - // (1,3) -> (3,3) - PLINE(0.1f, 0.3f, 0.3f, 0.3f) - // (1,3) -> (1,5) - PLINE(0.1f, 0.3f, 0.1f, 0.5f) -#undef PLINE -} - -static void drawIconDirect( - const ImVec2 p0, - const ImVec2 p1_o, - const ImU32 col_main, - const ImU32 col_back -) { - // dark background - // the circle looks bad in light mode - //ImGui::GetWindowDrawList()->AddCircleFilled({p0.x + p1_o.x*0.5f, p0.y + p1_o.y*0.5f}, p1_o.x*0.5f, col_back); - drawIconDirectLines(p0, p1_o, col_back, 4.0f); - drawIconDirectLines(p0, p1_o, col_main, 1.5f); -} - -static void drawIconCloud( - const ImVec2 p0, - const ImVec2 p1_o, - const ImU32 col_main, - const ImU32 col_back -) { - std::array points {{ - {0.2f, 0.9f}, - {0.8f, 0.9f}, - {0.9f, 0.8f}, - {0.9f, 0.7f}, - {0.7f, 0.7f}, - {0.9f, 0.5f}, - {0.9f, 0.4f}, - {0.8f, 0.2f}, - {0.6f, 0.2f}, - {0.5f, 0.3f}, - {0.5f, 0.5f}, - {0.4f, 0.4f}, - {0.3f, 0.4f}, - {0.2f, 0.5f}, - {0.2f, 0.6f}, - {0.3f, 0.7f}, - {0.1f, 0.7f}, - {0.1f, 0.8f}, - {0.2f, 0.9f}, - }}; - for (auto& v : points) { - v.y -= 0.1f; - v = {p0.x + p1_o.x*v.x, p0.y + p1_o.y*v.y}; - } - // the circle looks bad in light mode - //ImGui::GetWindowDrawList()->AddCircleFilled({p0.x + p1_o.x*0.5f, p0.y + p1_o.y*0.5f}, p1_o.x*0.5f, col_back); - ImGui::GetWindowDrawList()->AddPolyline(points.data(), points.size(), col_back, ImDrawFlags_None, 4.f); - ImGui::GetWindowDrawList()->AddPolyline(points.data(), points.size(), col_main, ImDrawFlags_None, 1.5f); -} - -static void drawIconMailLines( - const ImVec2 p0, - const ImVec2 p1_o, - const ImU32 col, - const float thickness -) { -#define PLINE(x0, y0, x1, y1) \ - ImGui::GetWindowDrawList()->AddLine( \ - {p0.x + p1_o.x*(x0), p0.y + p1_o.y*(y0)}, \ - {p0.x + p1_o.x*(x1), p0.y + p1_o.y*(y1)}, \ - col, \ - thickness \ - ); - - // quad - // (1,2) -> (1,8) - PLINE(0.1f, 0.2f, 0.1f, 0.8f) - // (1,8) -> (9,8) - PLINE(0.1f, 0.8f, 0.9f, 0.8f) - // (9,8) -> (9,2) - PLINE(0.9f, 0.8f, 0.9f, 0.2f) - // (9,2) -> (1,2) - PLINE(0.9f, 0.2f, 0.1f, 0.2f) - - // lip - // (1,2) -> (5,5) - PLINE(0.1f, 0.2f, 0.5f, 0.5f) - // (5,5) -> (9,2) - PLINE(0.5f, 0.5f, 0.9f, 0.2f) - -#undef PLINE -} - -static void drawIconMail( - const ImVec2 p0, - const ImVec2 p1_o, - const ImU32 col_main, - const ImU32 col_back -) { - // dark background - // the circle looks bad in light mode - //ImGui::GetWindowDrawList()->AddCircleFilled({p0.x + p1_o.x*0.5f, p0.y + p1_o.y*0.5f}, p1_o.x*0.5f, col_back); - drawIconMailLines(p0, p1_o, col_back, 4.0f); - drawIconMailLines(p0, p1_o, col_main, 1.5f); -} +#include "./icons/direct.hpp" +#include "./icons/cloud.hpp" +#include "./icons/mail.hpp" void renderAvatar( const Theme& th, diff --git a/src/chat_gui/icons/cloud.cpp b/src/chat_gui/icons/cloud.cpp new file mode 100644 index 00000000..74045124 --- /dev/null +++ b/src/chat_gui/icons/cloud.cpp @@ -0,0 +1,41 @@ +#include "./cloud.hpp" + +#include + +void drawIconCloud( + const ImVec2 p0, + const ImVec2 p1_o, + const ImU32 col_main, + const ImU32 col_back +) { + std::array points {{ + {0.2f, 0.9f}, + {0.8f, 0.9f}, + {0.9f, 0.8f}, + {0.9f, 0.7f}, + {0.7f, 0.7f}, + {0.9f, 0.5f}, + {0.9f, 0.4f}, + {0.8f, 0.2f}, + {0.6f, 0.2f}, + {0.5f, 0.3f}, + {0.5f, 0.5f}, + {0.4f, 0.4f}, + {0.3f, 0.4f}, + {0.2f, 0.5f}, + {0.2f, 0.6f}, + {0.3f, 0.7f}, + {0.1f, 0.7f}, + {0.1f, 0.8f}, + {0.2f, 0.9f}, + }}; + for (auto& v : points) { + v.y -= 0.1f; + v = {p0.x + p1_o.x*v.x, p0.y + p1_o.y*v.y}; + } + // the circle looks bad in light mode + //ImGui::GetWindowDrawList()->AddCircleFilled({p0.x + p1_o.x*0.5f, p0.y + p1_o.y*0.5f}, p1_o.x*0.5f, col_back); + ImGui::GetWindowDrawList()->AddPolyline(points.data(), points.size(), col_back, ImDrawFlags_None, 4.f); + ImGui::GetWindowDrawList()->AddPolyline(points.data(), points.size(), col_main, ImDrawFlags_None, 1.5f); +} + diff --git a/src/chat_gui/icons/cloud.hpp b/src/chat_gui/icons/cloud.hpp new file mode 100644 index 00000000..98c6eceb --- /dev/null +++ b/src/chat_gui/icons/cloud.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include + +void drawIconCloud( + const ImVec2 p0, + const ImVec2 p1_o, + const ImU32 col_main, + const ImU32 col_back +); + diff --git a/src/chat_gui/icons/direct.cpp b/src/chat_gui/icons/direct.cpp new file mode 100644 index 00000000..1a59f051 --- /dev/null +++ b/src/chat_gui/icons/direct.cpp @@ -0,0 +1,49 @@ +#include "./direct.hpp" + +#include + +static void drawIconDirectLines( + const ImVec2 p0, + const ImVec2 p1_o, + const ImU32 col, + const float thickness +) { +#define PLINE(x0, y0, x1, y1) \ + ImGui::GetWindowDrawList()->AddLine( \ + {p0.x + p1_o.x*(x0), p0.y + p1_o.y*(y0)}, \ + {p0.x + p1_o.x*(x1), p0.y + p1_o.y*(y1)}, \ + col, \ + thickness \ + ); + + // arrow 1 + // (3,1) -> (9,7) + PLINE(0.3f, 0.1f, 0.9f, 0.7f) + // (9,7) -> (9,5) + PLINE(0.9f, 0.7f, 0.9f, 0.5f) + // (9,7) -> (7,7) + PLINE(0.9f, 0.7f, 0.7f, 0.7f) + + // arrow 2 + // (7,9) -> (1,3) + PLINE(0.7f, 0.9f, 0.1f, 0.3f) + // (1,3) -> (3,3) + PLINE(0.1f, 0.3f, 0.3f, 0.3f) + // (1,3) -> (1,5) + PLINE(0.1f, 0.3f, 0.1f, 0.5f) +#undef PLINE +} + +void drawIconDirect( + const ImVec2 p0, + const ImVec2 p1_o, + const ImU32 col_main, + const ImU32 col_back +) { + // dark background + // the circle looks bad in light mode + //ImGui::GetWindowDrawList()->AddCircleFilled({p0.x + p1_o.x*0.5f, p0.y + p1_o.y*0.5f}, p1_o.x*0.5f, col_back); + drawIconDirectLines(p0, p1_o, col_back, 4.0f); + drawIconDirectLines(p0, p1_o, col_main, 1.5f); +} + diff --git a/src/chat_gui/icons/direct.hpp b/src/chat_gui/icons/direct.hpp new file mode 100644 index 00000000..93a9eecd --- /dev/null +++ b/src/chat_gui/icons/direct.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include + +void drawIconDirect( + const ImVec2 p0, + const ImVec2 p1_o, + const ImU32 col_main, + const ImU32 col_back +); diff --git a/src/chat_gui/icons/mail.cpp b/src/chat_gui/icons/mail.cpp new file mode 100644 index 00000000..3a271c6a --- /dev/null +++ b/src/chat_gui/icons/mail.cpp @@ -0,0 +1,50 @@ +#include "./mail.hpp" + +#include + +static void drawIconMailLines( + const ImVec2 p0, + const ImVec2 p1_o, + const ImU32 col, + const float thickness +) { +#define PLINE(x0, y0, x1, y1) \ + ImGui::GetWindowDrawList()->AddLine( \ + {p0.x + p1_o.x*(x0), p0.y + p1_o.y*(y0)}, \ + {p0.x + p1_o.x*(x1), p0.y + p1_o.y*(y1)}, \ + col, \ + thickness \ + ); + + // quad + // (1,2) -> (1,8) + PLINE(0.1f, 0.2f, 0.1f, 0.8f) + // (1,8) -> (9,8) + PLINE(0.1f, 0.8f, 0.9f, 0.8f) + // (9,8) -> (9,2) + PLINE(0.9f, 0.8f, 0.9f, 0.2f) + // (9,2) -> (1,2) + PLINE(0.9f, 0.2f, 0.1f, 0.2f) + + // lip + // (1,2) -> (5,5) + PLINE(0.1f, 0.2f, 0.5f, 0.5f) + // (5,5) -> (9,2) + PLINE(0.5f, 0.5f, 0.9f, 0.2f) + +#undef PLINE +} + +void drawIconMail( + const ImVec2 p0, + const ImVec2 p1_o, + const ImU32 col_main, + const ImU32 col_back +) { + // dark background + // the circle looks bad in light mode + //ImGui::GetWindowDrawList()->AddCircleFilled({p0.x + p1_o.x*0.5f, p0.y + p1_o.y*0.5f}, p1_o.x*0.5f, col_back); + drawIconMailLines(p0, p1_o, col_back, 4.0f); + drawIconMailLines(p0, p1_o, col_main, 1.5f); +} + diff --git a/src/chat_gui/icons/mail.hpp b/src/chat_gui/icons/mail.hpp new file mode 100644 index 00000000..428d97e5 --- /dev/null +++ b/src/chat_gui/icons/mail.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include + +void drawIconMail( + const ImVec2 p0, + const ImVec2 p1_o, + const ImU32 col_main, + const ImU32 col_back +); +