Large notification buttons and icons

This commit is contained in:
David Kocik 2020-11-09 12:08:24 +01:00
parent a72fb79f72
commit 870aba8d15
3 changed files with 59 additions and 31 deletions

View file

@ -42,16 +42,16 @@ static const std::map<const char, std::string> font_icons = {
{ImGui::PrinterSlaIconMarker , "sla_printer" },
{ImGui::FilamentIconMarker , "spool" },
{ImGui::MaterialIconMarker , "resin" },
{ImGui::CloseIconMarker , "notification_close" },
{ImGui::CloseIconHoverMarker , "notification_close_hover" },
//{ImGui::TimerDotMarker , "timer_dot" },
//{ImGui::TimerDotEmptyMarker , "timer_dot_empty" },
{ImGui::MinimalizeMarker , "notification_minimalize" },
{ImGui::MinimalizeHoverMarker , "notification_minimalize_hover" },
{ImGui::WarningMarker , "notification_warning" },
{ImGui::ErrorMarker , "notification_error" },
{ImGui::EjectMarker , "notification_eject_sd" },
{ImGui::EjectHoverMarker , "notification_eject_sd_hover" },
{ImGui::MinimalizeButton , "notification_minimalize" },
{ImGui::MinimalizeHoverButton , "notification_minimalize_hover" }
};
static const std::map<const char, std::string> font_icons_large = {
{ImGui::CloseNotifButton , "notification_close" },
{ImGui::CloseNotifHoverButton , "notification_close_hover" },
{ImGui::EjectButton , "notification_eject_sd" },
{ImGui::EjectHoverButton , "notification_eject_sd_hover" },
{ImGui::WarningMarker , "notification_warning" },
{ImGui::ErrorMarker , "notification_error" }
};
const ImVec4 ImGuiWrapper::COL_GREY_DARK = { 0.333f, 0.333f, 0.333f, 1.0f };
@ -950,6 +950,8 @@ void ImGuiWrapper::init_font(bool compress)
// add rectangles for the icons to the font atlas
for (auto& icon : font_icons)
io.Fonts->AddCustomRectFontGlyph(font, icon.first, icon_sz, icon_sz, 3.0 * font_scale + icon_sz);
for (auto& icon : font_icons_large)
io.Fonts->AddCustomRectFontGlyph(font, icon.first, icon_sz * 2, icon_sz * 2, 3.0 * font_scale + icon_sz * 2);
// Build texture atlas
unsigned char* pixels;
@ -969,6 +971,20 @@ void ImGuiWrapper::init_font(bool compress)
}
rect_id++;
}
icon_sz = lround(32 * font_scale); // default size of large icon is 32 px
for (auto icon : font_icons_large) {
if (const ImFontAtlas::CustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id)) {
std::vector<unsigned char> raw_data = load_svg(icon.second, icon_sz, icon_sz);
const ImU32* pIn = (ImU32*)raw_data.data();
for (int y = 0; y < icon_sz; y++) {
ImU32* pOut = (ImU32*)pixels + (rect->Y + y) * width + (rect->X);
for (int x = 0; x < icon_sz; x++)
*pOut++ = *pIn++;
}
}
rect_id++;
}
// Upload texture to graphics system
GLint last_texture;