mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 02:26:05 +08:00
Follow-up of 745a45408143af16e1dbf5f74c7c405dd9762472 - Refactoring in ImGuiWrapper::init_font() to remove duplicated code
This commit is contained in:
parent
745a454081
commit
368d36089b
@ -1678,64 +1678,36 @@ void ImGuiWrapper::init_font(bool compress)
|
|||||||
int width, height;
|
int width, height;
|
||||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
|
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
|
||||||
|
|
||||||
// Fill rectangles from the SVG-icons
|
auto load_icon_from_svg = [this, &io, pixels, width, &rect_id](const std::pair<const wchar_t, std::string> icon, int icon_sz) {
|
||||||
for (auto icon : font_icons) {
|
|
||||||
if (const ImFontAtlas::CustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id)) {
|
if (const ImFontAtlas::CustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id)) {
|
||||||
assert(rect->Width == icon_sz);
|
assert(rect->Width == icon_sz);
|
||||||
assert(rect->Height == icon_sz);
|
assert(rect->Height == icon_sz);
|
||||||
std::vector<unsigned char> raw_data = load_svg(icon.second, icon_sz, icon_sz);
|
std::vector<unsigned char> raw_data = load_svg(icon.second, icon_sz, icon_sz);
|
||||||
if (raw_data.empty()) {
|
if (!raw_data.empty()) {
|
||||||
rect_id++;
|
const ImU32* pIn = (ImU32*)raw_data.data();
|
||||||
continue;
|
for (int y = 0; y < icon_sz; y++) {
|
||||||
}
|
ImU32* pOut = (ImU32*)pixels + (rect->Y + y) * width + (rect->X);
|
||||||
const ImU32* pIn = (ImU32*)raw_data.data();
|
for (int x = 0; x < icon_sz; x++)
|
||||||
for (int y = 0; y < icon_sz; y++) {
|
*pOut++ = *pIn++;
|
||||||
ImU32* pOut = (ImU32*)pixels + (rect->Y + y) * width + (rect->X);
|
}
|
||||||
for (int x = 0; x < icon_sz; x++)
|
|
||||||
*pOut++ = *pIn++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rect_id++;
|
rect_id++;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fill rectangles from the SVG-icons
|
||||||
|
for (auto icon : font_icons) {
|
||||||
|
load_icon_from_svg(icon, icon_sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
icon_sz *= 2; // default size of large icon is 32 px
|
icon_sz *= 2; // default size of large icon is 32 px
|
||||||
for (auto icon : font_icons_large) {
|
for (auto icon : font_icons_large) {
|
||||||
if (const ImFontAtlas::CustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id)) {
|
load_icon_from_svg(icon, icon_sz);
|
||||||
assert(rect->Width == icon_sz);
|
|
||||||
assert(rect->Height == icon_sz);
|
|
||||||
std::vector<unsigned char> raw_data = load_svg(icon.second, icon_sz, icon_sz);
|
|
||||||
if (raw_data.empty()) {
|
|
||||||
rect_id++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
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++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
icon_sz *= 2; // default size of extra large icon is 64 px
|
icon_sz *= 2; // default size of extra large icon is 64 px
|
||||||
for (auto icon : font_icons_extra_large) {
|
for (auto icon : font_icons_extra_large) {
|
||||||
if (const ImFontAtlas::CustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id)) {
|
load_icon_from_svg(icon, icon_sz);
|
||||||
assert(rect->Width == icon_sz);
|
|
||||||
assert(rect->Height == icon_sz);
|
|
||||||
std::vector<unsigned char> raw_data = load_svg(icon.second, icon_sz, icon_sz);
|
|
||||||
if (raw_data.empty()) {
|
|
||||||
rect_id++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
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
|
// Upload texture to graphics system
|
||||||
|
Loading…
x
Reference in New Issue
Block a user