mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 21:05:56 +08:00
font style combo contain grayed style text
This commit is contained in:
parent
1ba66a0e71
commit
664fb8120c
@ -654,7 +654,6 @@ void GLGizmoEmboss::initialize()
|
|||||||
if (cfg.icon_width % 2 != 0) ++cfg.icon_width;
|
if (cfg.icon_width % 2 != 0) ++cfg.icon_width;
|
||||||
|
|
||||||
float icon_width_with_spacing = cfg.icon_width + space;
|
float icon_width_with_spacing = cfg.icon_width + space;
|
||||||
float scroll_width = icon_width_with_spacing; // TODO: fix it
|
|
||||||
cfg.delete_pos_x = cfg.max_font_name_width + space;
|
cfg.delete_pos_x = cfg.max_font_name_width + space;
|
||||||
int count_line_of_text = 3;
|
int count_line_of_text = 3;
|
||||||
cfg.text_size = ImVec2(-FLT_MIN, line_height_with_spacing * count_line_of_text);
|
cfg.text_size = ImVec2(-FLT_MIN, line_height_with_spacing * count_line_of_text);
|
||||||
@ -720,9 +719,10 @@ void GLGizmoEmboss::initialize()
|
|||||||
ImVec2(cfg.minimal_window_size.x,
|
ImVec2(cfg.minimal_window_size.x,
|
||||||
cfg.minimal_window_size.y + advance_height);
|
cfg.minimal_window_size.y + advance_height);
|
||||||
|
|
||||||
cfg.min_style_image_height = line_height_with_spacing;
|
int max_style_image_width = cfg.max_font_name_width -
|
||||||
cfg.max_style_image_width = cfg.max_font_name_width -
|
|
||||||
2 * style.FramePadding.x;
|
2 * style.FramePadding.x;
|
||||||
|
int max_style_image_height = 2 * input_height;
|
||||||
|
cfg.max_style_image_size = Vec2i(max_style_image_width, max_style_image_height);
|
||||||
m_gui_cfg.emplace(std::move(cfg));
|
m_gui_cfg.emplace(std::move(cfg));
|
||||||
|
|
||||||
init_icons();
|
init_icons();
|
||||||
@ -1359,7 +1359,6 @@ void GLGizmoEmboss::draw_font_list()
|
|||||||
// select font file by file browser
|
// select font file by file browser
|
||||||
if (draw_button(IconType::open_file)) {
|
if (draw_button(IconType::open_file)) {
|
||||||
if (choose_true_type_file()) {
|
if (choose_true_type_file()) {
|
||||||
m_font_manager.free_style_images();
|
|
||||||
process();
|
process();
|
||||||
}
|
}
|
||||||
} else if (ImGui::IsItemHovered())
|
} else if (ImGui::IsItemHovered())
|
||||||
@ -1370,7 +1369,6 @@ void GLGizmoEmboss::draw_font_list()
|
|||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (draw_button(IconType::system_selector)) {
|
if (draw_button(IconType::system_selector)) {
|
||||||
if (choose_font_by_wxdialog()) {
|
if (choose_font_by_wxdialog()) {
|
||||||
m_font_manager.free_style_images();
|
|
||||||
process();
|
process();
|
||||||
}
|
}
|
||||||
} else if (ImGui::IsItemHovered())
|
} else if (ImGui::IsItemHovered())
|
||||||
@ -1453,8 +1451,14 @@ void GLGizmoEmboss::draw_model_type()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoEmboss::draw_rename_style(bool start_rename)
|
void GLGizmoEmboss::draw_rename_style_botton()
|
||||||
{
|
{
|
||||||
|
bool start_rename = false;
|
||||||
|
if (draw_button(IconType::rename))
|
||||||
|
start_rename = true;
|
||||||
|
else if (ImGui::IsItemHovered())
|
||||||
|
ImGui::SetTooltip("%s", _u8L("Rename actual style.").c_str());
|
||||||
|
|
||||||
std::string title = _u8L("Rename style");
|
std::string title = _u8L("Rename style");
|
||||||
const char * popup_id = title.c_str();
|
const char * popup_id = title.c_str();
|
||||||
static FontItem * rename_item;
|
static FontItem * rename_item;
|
||||||
@ -1493,7 +1497,6 @@ void GLGizmoEmboss::draw_rename_style(bool start_rename)
|
|||||||
m_imgui->button(_L("ok"), ImVec2(0.f, 0.f), allow_change)) {
|
m_imgui->button(_L("ok"), ImVec2(0.f, 0.f), allow_change)) {
|
||||||
rename_item->name = new_name;
|
rename_item->name = new_name;
|
||||||
m_font_manager.get_truncated_name().clear();
|
m_font_manager.get_truncated_name().clear();
|
||||||
m_font_manager.free_style_images();
|
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
select_stored_font_item();
|
select_stored_font_item();
|
||||||
}
|
}
|
||||||
@ -1600,7 +1603,6 @@ void GLGizmoEmboss::draw_undo_style_button(bool is_stored, bool is_changed)
|
|||||||
m_font_manager.get_wx_font() = WxFontUtils::load_wxFont(font_item.path);
|
m_font_manager.get_wx_font() = WxFontUtils::load_wxFont(font_item.path);
|
||||||
m_font_manager.wx_font_changed();
|
m_font_manager.wx_font_changed();
|
||||||
}
|
}
|
||||||
m_font_manager.free_style_images();
|
|
||||||
process();
|
process();
|
||||||
} else if (ImGui::IsItemHovered()) {
|
} else if (ImGui::IsItemHovered()) {
|
||||||
if (can_undo)
|
if (can_undo)
|
||||||
@ -1640,7 +1642,8 @@ void GLGizmoEmboss::draw_style_list() {
|
|||||||
ImGui::SameLine(m_gui_cfg->style_offset);
|
ImGui::SameLine(m_gui_cfg->style_offset);
|
||||||
ImGui::SetNextItemWidth(m_gui_cfg->input_width);
|
ImGui::SetNextItemWidth(m_gui_cfg->input_width);
|
||||||
if (ImGui::BeginCombo("##style_selector", trunc_name.c_str())) {
|
if (ImGui::BeginCombo("##style_selector", trunc_name.c_str())) {
|
||||||
m_font_manager.init_style_images(m_gui_cfg->max_style_image_width);
|
m_font_manager.init_style_images(m_gui_cfg->max_style_image_size, m_text);
|
||||||
|
m_font_manager.init_trunc_names(max_width);
|
||||||
std::optional<std::pair<size_t,size_t>> swap_indexes;
|
std::optional<std::pair<size_t,size_t>> swap_indexes;
|
||||||
const std::vector<FontManager::Item> &styles = m_font_manager.get_styles();
|
const std::vector<FontManager::Item> &styles = m_font_manager.get_styles();
|
||||||
for (const auto &item : styles) {
|
for (const auto &item : styles) {
|
||||||
@ -1650,18 +1653,11 @@ void GLGizmoEmboss::draw_style_list() {
|
|||||||
ImGui::PushID(actual_style_name.c_str());
|
ImGui::PushID(actual_style_name.c_str());
|
||||||
bool is_selected = (&fi == &actual_font_item);
|
bool is_selected = (&fi == &actual_font_item);
|
||||||
|
|
||||||
ImVec2 select_size(0,0); // 0,0 --> calculate in draw
|
ImVec2 select_size(0,m_gui_cfg->max_style_image_size.y()); // 0,0 --> calculate in draw
|
||||||
std::string selectable_name = "##style_select"; // ## --> no visible
|
const std::optional<FontManager::StyleImage> img = item.image;
|
||||||
if (item.image.has_value()) {
|
|
||||||
const FontManager::StyleImage &img = *item.image;
|
|
||||||
select_size = ImVec2(0.f, std::max(img.tex_size.y, m_gui_cfg->min_style_image_height));
|
|
||||||
} else {
|
|
||||||
selectable_name = ImGuiWrapper::trunc(actual_style_name, max_width);
|
|
||||||
}
|
|
||||||
|
|
||||||
// allow click delete button
|
// allow click delete button
|
||||||
ImGuiSelectableFlags_ flags = ImGuiSelectableFlags_AllowItemOverlap;
|
ImGuiSelectableFlags_ flags = ImGuiSelectableFlags_AllowItemOverlap;
|
||||||
if (ImGui::Selectable(selectable_name.c_str(), is_selected, flags, select_size)) {
|
if (ImGui::Selectable(item.truncated_name.c_str(), is_selected, flags, select_size)) {
|
||||||
if (m_font_manager.load_font(index)) {
|
if (m_font_manager.load_font(index)) {
|
||||||
process();
|
process();
|
||||||
select_stored_font_item();
|
select_stored_font_item();
|
||||||
@ -1681,10 +1677,9 @@ void GLGizmoEmboss::draw_style_list() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// draw style name
|
// draw style name
|
||||||
if (item.image.has_value()) {
|
if (img.has_value()) {
|
||||||
const FontManager::StyleImage &img = *item.image;
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Image(img.texture_id, img.tex_size, img.uv0, img.uv1);
|
ImGui::Image(img->texture_id, img->tex_size, img->uv0, img->uv1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
@ -1693,15 +1688,15 @@ void GLGizmoEmboss::draw_style_list() {
|
|||||||
m_font_manager.swap(swap_indexes->first,
|
m_font_manager.swap(swap_indexes->first,
|
||||||
swap_indexes->second);
|
swap_indexes->second);
|
||||||
ImGui::EndCombo();
|
ImGui::EndCombo();
|
||||||
}else if (ImGui::IsItemHovered())
|
} else {
|
||||||
|
// do not keep in memory style images when no combo box open
|
||||||
|
m_font_manager.free_style_images();
|
||||||
|
if (ImGui::IsItemHovered())
|
||||||
ImGui::SetTooltip("%s", _u8L("Style selector").c_str());
|
ImGui::SetTooltip("%s", _u8L("Style selector").c_str());
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
bool start_rename = false;
|
draw_rename_style_botton();
|
||||||
if (draw_button(IconType::rename)) start_rename = true;
|
|
||||||
else if (ImGui::IsItemHovered())
|
|
||||||
ImGui::SetTooltip("%s", _u8L("Rename actual style.").c_str());
|
|
||||||
draw_rename_style(start_rename);
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (draw_button(IconType::duplicate)) m_font_manager.duplicate();
|
if (draw_button(IconType::duplicate)) m_font_manager.duplicate();
|
||||||
@ -1815,7 +1810,6 @@ bool GLGizmoEmboss::bold_button() {
|
|||||||
// bold font can't be loaded
|
// bold font can't be loaded
|
||||||
// set up boldness
|
// set up boldness
|
||||||
boldness = 20.f;
|
boldness = 20.f;
|
||||||
m_font_manager.free_style_images();
|
|
||||||
//font_file->cache.empty();
|
//font_file->cache.empty();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -1952,7 +1946,6 @@ void GLGizmoEmboss::draw_style_edit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (exist_change) {
|
if (exist_change) {
|
||||||
m_font_manager.free_style_images();
|
|
||||||
m_font_manager.clear_glyphs_cache();
|
m_font_manager.clear_glyphs_cache();
|
||||||
process();
|
process();
|
||||||
}
|
}
|
||||||
@ -2293,7 +2286,6 @@ void GLGizmoEmboss::draw_advanced()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (exist_change) {
|
if (exist_change) {
|
||||||
m_font_manager.free_style_images();
|
|
||||||
m_font_manager.clear_glyphs_cache();
|
m_font_manager.clear_glyphs_cache();
|
||||||
process();
|
process();
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ private:
|
|||||||
void draw_delete_style_button();
|
void draw_delete_style_button();
|
||||||
void draw_undo_style_button(bool is_stored, bool is_changed);
|
void draw_undo_style_button(bool is_stored, bool is_changed);
|
||||||
void draw_revert_all_styles_button();
|
void draw_revert_all_styles_button();
|
||||||
void draw_rename_style(bool start_rename);
|
void draw_rename_style_botton();
|
||||||
void draw_font_list();
|
void draw_font_list();
|
||||||
void draw_style_edit();
|
void draw_style_edit();
|
||||||
bool italic_button();
|
bool italic_button();
|
||||||
@ -175,8 +175,8 @@ private:
|
|||||||
float max_font_name_width = 0.f;
|
float max_font_name_width = 0.f;
|
||||||
unsigned int icon_width = 0;
|
unsigned int icon_width = 0;
|
||||||
|
|
||||||
float min_style_image_height = 0.f;
|
// maximal width and height of style image
|
||||||
int max_style_image_width = 0.f;
|
Vec2i max_style_image_size = Vec2i(0, 0);
|
||||||
|
|
||||||
float style_offset = 0.f;
|
float style_offset = 0.f;
|
||||||
float input_offset = 0.f;
|
float input_offset = 0.f;
|
||||||
|
@ -19,7 +19,9 @@ CreateFontStyleImagesJob::CreateFontStyleImagesJob(
|
|||||||
{
|
{
|
||||||
assert(m_input.result != nullptr);
|
assert(m_input.result != nullptr);
|
||||||
assert(!m_input.styles.empty());
|
assert(!m_input.styles.empty());
|
||||||
assert(m_input.max_width > 1);
|
assert(!m_input.text.empty());
|
||||||
|
assert(m_input.max_size.x() > 1);
|
||||||
|
assert(m_input.max_size.y() > 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateFontStyleImagesJob::process(Ctl &ctl)
|
void CreateFontStyleImagesJob::process(Ctl &ctl)
|
||||||
@ -32,7 +34,7 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
|
|||||||
for (auto &item : m_input.styles) {
|
for (auto &item : m_input.styles) {
|
||||||
size_t index = &item - &m_input.styles.front();
|
size_t index = &item - &m_input.styles.front();
|
||||||
ExPolygons &shapes = name_shapes[index];
|
ExPolygons &shapes = name_shapes[index];
|
||||||
shapes = Emboss::text2shapes(item.font, item.text.c_str(), item.prop);
|
shapes = Emboss::text2shapes(item.font, m_input.text.c_str(), item.prop);
|
||||||
|
|
||||||
// create image description
|
// create image description
|
||||||
FontManager::StyleImage &image = images[index];
|
FontManager::StyleImage &image = images[index];
|
||||||
@ -60,8 +62,11 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
|
|||||||
image.tex_size.y = std::ceil(bb2.max.y() - bb2.min.y());
|
image.tex_size.y = std::ceil(bb2.max.y() - bb2.min.y());
|
||||||
|
|
||||||
// crop image width
|
// crop image width
|
||||||
if (image.tex_size.x > m_input.max_width)
|
if (image.tex_size.x > m_input.max_size.x())
|
||||||
image.tex_size.x = m_input.max_width;
|
image.tex_size.x = m_input.max_size.x();
|
||||||
|
// crop image height
|
||||||
|
if (image.tex_size.y > m_input.max_size.y())
|
||||||
|
image.tex_size.y = m_input.max_size.y();
|
||||||
}
|
}
|
||||||
|
|
||||||
// arrange bounding boxes
|
// arrange bounding boxes
|
||||||
@ -100,6 +105,8 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
|
|||||||
// copy rastered data to pixels
|
// copy rastered data to pixels
|
||||||
sla::RasterEncoder encoder = [&offset = image.offset, &pix = pixels, w=width,h=height]
|
sla::RasterEncoder encoder = [&offset = image.offset, &pix = pixels, w=width,h=height]
|
||||||
(const void *ptr, size_t width, size_t height, size_t num_components) {
|
(const void *ptr, size_t width, size_t height, size_t num_components) {
|
||||||
|
// bigger value create darker image
|
||||||
|
unsigned char gray_level = 5;
|
||||||
size_t size {static_cast<size_t>(w*h)};
|
size_t size {static_cast<size_t>(w*h)};
|
||||||
assert((offset.x() + width) <= w);
|
assert((offset.x() + width) <= w);
|
||||||
assert((offset.y() + height) <= h);
|
assert((offset.y() + height) <= h);
|
||||||
@ -109,7 +116,7 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
|
|||||||
size_t index = (offset.y() + y)*w + offset.x() + x;
|
size_t index = (offset.y() + y)*w + offset.x() + x;
|
||||||
assert(index < size);
|
assert(index < size);
|
||||||
if (index >= size) continue;
|
if (index >= size) continue;
|
||||||
pix[index] = ptr2[y * width + x];
|
pix[index] = ptr2[y * width + x] / gray_level;
|
||||||
}
|
}
|
||||||
return sla::EncodedRaster();
|
return sla::EncodedRaster();
|
||||||
};
|
};
|
||||||
|
@ -344,13 +344,23 @@ ImFont* FontManager::extend_imgui_font_range(size_t index, const std::string& te
|
|||||||
return create_imgui_font(index, text);
|
return create_imgui_font(index, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FontManager::init_trunc_names(float max_width) {
|
||||||
|
for (auto &s : m_font_list) {
|
||||||
|
if (s.truncated_name.empty())
|
||||||
|
s.truncated_name = ImGuiWrapper::trunc(s.font_item.name, max_width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#include "slic3r/GUI/Jobs/CreateFontStyleImagesJob.hpp"
|
#include "slic3r/GUI/Jobs/CreateFontStyleImagesJob.hpp"
|
||||||
|
|
||||||
// for access to worker
|
// for access to worker
|
||||||
#include "slic3r/GUI/GUI_App.hpp"
|
#include "slic3r/GUI/GUI_App.hpp"
|
||||||
#include "slic3r/GUI/Plater.hpp"
|
#include "slic3r/GUI/Plater.hpp"
|
||||||
|
|
||||||
void FontManager::init_style_images(int max_width) {
|
void FontManager::init_style_images(const Vec2i &max_size,
|
||||||
|
const std::string &text)
|
||||||
|
{
|
||||||
// check already initialized
|
// check already initialized
|
||||||
if (m_exist_style_images) return;
|
if (m_exist_style_images) return;
|
||||||
|
|
||||||
@ -398,13 +408,13 @@ void FontManager::init_style_images(int max_width) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto &worker = wxGetApp().plater()->get_ui_job_worker();
|
auto &worker = wxGetApp().plater()->get_ui_job_worker();
|
||||||
StyleImagesData data{std::move(styles), max_width, m_temp_style_images};
|
StyleImagesData data{std::move(styles), max_size, text, m_temp_style_images};
|
||||||
queue_job(worker, std::make_unique<CreateFontStyleImagesJob>(std::move(data)));
|
queue_job(worker, std::make_unique<CreateFontStyleImagesJob>(std::move(data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FontManager::free_style_images() {
|
void FontManager::free_style_images() {
|
||||||
if (!is_activ_font()) return;
|
|
||||||
if (!m_exist_style_images) return;
|
if (!m_exist_style_images) return;
|
||||||
|
if (!is_activ_font()) return;
|
||||||
|
|
||||||
GLuint tex_id = 0;
|
GLuint tex_id = 0;
|
||||||
|
|
||||||
|
@ -106,10 +106,15 @@ public:
|
|||||||
// free used memory and font file data
|
// free used memory and font file data
|
||||||
void free_except_active_font();
|
void free_except_active_font();
|
||||||
|
|
||||||
|
// init truncated names of styles
|
||||||
|
void init_trunc_names(float max_width);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// initialization texture with rendered font style
|
/// Initialization texture with rendered font style
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void init_style_images(int max_width);
|
/// <param name="max_size">Maximal width and height of one style texture</param>
|
||||||
|
/// <param name="text">Text to render by style</param>
|
||||||
|
void init_style_images(const Vec2i& max_size, const std::string &text);
|
||||||
void free_style_images();
|
void free_style_images();
|
||||||
|
|
||||||
struct Item;
|
struct Item;
|
||||||
@ -208,9 +213,10 @@ private:
|
|||||||
|
|
||||||
// Keep styles to render
|
// Keep styles to render
|
||||||
Items styles;
|
Items styles;
|
||||||
|
// Maximal width and height in pixels of image
|
||||||
// Maximal width in pixels of image
|
Vec2i max_size;
|
||||||
int max_width;
|
// Text to render
|
||||||
|
std::string text;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Result of job
|
/// Result of job
|
||||||
|
Loading…
x
Reference in New Issue
Block a user