|
| 1 | +// Copyright 2017-2019, Nicholas Sharp and the Polyscope contributors. http://polyscope.run. |
| 2 | +#include "polyscope/imgui_config.h" |
| 3 | + |
| 4 | +namespace polyscope { |
| 5 | + |
| 6 | + |
| 7 | +// Forward declare compressed binary font functions |
| 8 | +namespace render { |
| 9 | +unsigned int getCousineRegularCompressedSize(); |
| 10 | +const unsigned int* getCousineRegularCompressedData(); |
| 11 | +unsigned int getLatoRegularCompressedSize(); |
| 12 | +const unsigned int* getLatoRegularCompressedData(); |
| 13 | +} // namespace render |
| 14 | + |
| 15 | +void configureImGuiStyle() { |
| 16 | + |
| 17 | + // Style |
| 18 | + ImGuiStyle* style = &ImGui::GetStyle(); |
| 19 | + style->WindowRounding = 1; |
| 20 | + style->FrameRounding = 1; |
| 21 | + style->FramePadding.y = 4; |
| 22 | + style->ScrollbarRounding = 1; |
| 23 | + style->ScrollbarSize = 20; |
| 24 | + |
| 25 | + |
| 26 | + // Colors |
| 27 | + ImVec4* colors = style->Colors; |
| 28 | + colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); |
| 29 | + colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); |
| 30 | + colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.70f); |
| 31 | + colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); |
| 32 | + colors[ImGuiCol_PopupBg] = ImVec4(0.11f, 0.11f, 0.14f, 0.92f); |
| 33 | + colors[ImGuiCol_Border] = ImVec4(0.50f, 0.50f, 0.50f, 0.50f); |
| 34 | + colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); |
| 35 | + colors[ImGuiCol_FrameBg] = ImVec4(0.63f, 0.63f, 0.63f, 0.39f); |
| 36 | + colors[ImGuiCol_FrameBgHovered] = ImVec4(0.47f, 0.69f, 0.59f, 0.40f); |
| 37 | + colors[ImGuiCol_FrameBgActive] = ImVec4(0.41f, 0.64f, 0.53f, 0.69f); |
| 38 | + colors[ImGuiCol_TitleBg] = ImVec4(0.27f, 0.54f, 0.42f, 0.83f); |
| 39 | + colors[ImGuiCol_TitleBgActive] = ImVec4(0.32f, 0.63f, 0.49f, 0.87f); |
| 40 | + colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.27f, 0.54f, 0.42f, 0.83f); |
| 41 | + colors[ImGuiCol_MenuBarBg] = ImVec4(0.40f, 0.55f, 0.48f, 0.80f); |
| 42 | + colors[ImGuiCol_ScrollbarBg] = ImVec4(0.63f, 0.63f, 0.63f, 0.39f); |
| 43 | + colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.00f, 0.00f, 0.00f, 0.30f); |
| 44 | + colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.80f, 0.62f, 0.40f); |
| 45 | + colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.39f, 0.80f, 0.61f, 0.60f); |
| 46 | + colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f); |
| 47 | + colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f); |
| 48 | + colors[ImGuiCol_SliderGrabActive] = ImVec4(0.39f, 0.80f, 0.61f, 0.60f); |
| 49 | + colors[ImGuiCol_Button] = ImVec4(0.35f, 0.61f, 0.49f, 0.62f); |
| 50 | + colors[ImGuiCol_ButtonHovered] = ImVec4(0.40f, 0.71f, 0.57f, 0.79f); |
| 51 | + colors[ImGuiCol_ButtonActive] = ImVec4(0.46f, 0.80f, 0.64f, 1.00f); |
| 52 | + colors[ImGuiCol_Header] = ImVec4(0.40f, 0.90f, 0.67f, 0.45f); |
| 53 | + colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.90f, 0.69f, 0.80f); |
| 54 | + colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.87f, 0.71f, 0.80f); |
| 55 | + colors[ImGuiCol_Separator] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); |
| 56 | + colors[ImGuiCol_SeparatorHovered] = ImVec4(0.60f, 0.70f, 0.66f, 1.00f); |
| 57 | + colors[ImGuiCol_SeparatorActive] = ImVec4(0.70f, 0.90f, 0.81f, 1.00f); |
| 58 | + colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.16f); |
| 59 | + colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.78f, 1.00f, 0.90f, 0.60f); |
| 60 | + colors[ImGuiCol_ResizeGripActive] = ImVec4(0.78f, 1.00f, 0.90f, 0.90f); |
| 61 | + colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); |
| 62 | + colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); |
| 63 | + colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); |
| 64 | + colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); |
| 65 | + colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f); |
| 66 | + colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f); |
| 67 | + colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f); |
| 68 | + colors[ImGuiCol_Tab] = ImVec4(0.27f, 0.54f, 0.42f, 0.83f); |
| 69 | + colors[ImGuiCol_TabHovered] = ImVec4(0.34f, 0.68f, 0.53f, 0.83f); |
| 70 | + colors[ImGuiCol_TabActive] = ImVec4(0.38f, 0.76f, 0.58f, 0.83f); |
| 71 | +} |
| 72 | + |
| 73 | + |
| 74 | +std::tuple<ImFontAtlas*, ImFont*, ImFont*> prepareImGuiFonts() { |
| 75 | + |
| 76 | + ImGuiIO& io = ImGui::GetIO(); |
| 77 | + |
| 78 | + // outputs |
| 79 | + ImFontAtlas* globalFontAtlas; |
| 80 | + ImFont* regularFont; |
| 81 | + ImFont* monoFont; |
| 82 | + |
| 83 | + { // add regular font |
| 84 | + ImFontConfig config; |
| 85 | + regularFont = io.Fonts->AddFontFromMemoryCompressedTTF(render::getLatoRegularCompressedData(), |
| 86 | + render::getLatoRegularCompressedSize(), 18.0f, &config); |
| 87 | + } |
| 88 | + |
| 89 | + { // add mono font |
| 90 | + ImFontConfig config; |
| 91 | + monoFont = io.Fonts->AddFontFromMemoryCompressedTTF(render::getCousineRegularCompressedData(), |
| 92 | + render::getCousineRegularCompressedSize(), 16.0f, &config); |
| 93 | + } |
| 94 | + |
| 95 | + // io.Fonts->AddFontFromFileTTF("test-font-name.ttf", 16); |
| 96 | + |
| 97 | + io.Fonts->Build(); |
| 98 | + globalFontAtlas = io.Fonts; |
| 99 | + |
| 100 | + return std::tuple<ImFontAtlas*, ImFont*, ImFont*>{globalFontAtlas, regularFont, monoFont}; |
| 101 | +} |
| 102 | + |
| 103 | +} // namespace polyscope |
0 commit comments