Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/slic3r/GUI/ImGuiWrapper.cpp')
-rw-r--r--src/slic3r/GUI/ImGuiWrapper.cpp82
1 files changed, 77 insertions, 5 deletions
diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp
index 8e4d9eebf..a44e843b8 100644
--- a/src/slic3r/GUI/ImGuiWrapper.cpp
+++ b/src/slic3r/GUI/ImGuiWrapper.cpp
@@ -96,7 +96,7 @@ void ImGuiWrapper::set_language(const std::string &language)
ranges = ranges_turkish;
} else if (lang == "vi") {
ranges = ranges_vietnamese;
- } else if (lang == "jp") {
+ } else if (lang == "ja") {
ranges = ImGui::GetIO().Fonts->GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
m_font_cjk = true;
} else if (lang == "ko") {
@@ -254,6 +254,16 @@ bool ImGuiWrapper::begin(const wxString &name, int flags)
return begin(into_u8(name), flags);
}
+bool ImGuiWrapper::begin(const std::string& name, bool* close, int flags)
+{
+ return ImGui::Begin(name.c_str(), close, (ImGuiWindowFlags)flags);
+}
+
+bool ImGuiWrapper::begin(const wxString& name, bool* close, int flags)
+{
+ return begin(into_u8(name), close, flags);
+}
+
void ImGuiWrapper::end()
{
ImGui::End();
@@ -276,6 +286,12 @@ bool ImGuiWrapper::input_double(const std::string &label, const double &value, c
return ImGui::InputDouble(label.c_str(), const_cast<double*>(&value), 0.0f, 0.0f, format.c_str());
}
+bool ImGuiWrapper::input_double(const wxString &label, const double &value, const std::string &format)
+{
+ auto label_utf8 = into_u8(label);
+ return input_double(label_utf8, value, format);
+}
+
bool ImGuiWrapper::input_vec3(const std::string &label, const Vec3d &value, float width, const std::string &format)
{
bool value_changed = false;
@@ -317,6 +333,22 @@ void ImGuiWrapper::text(const wxString &label)
this->text(label_utf8.c_str());
}
+bool ImGuiWrapper::slider_float(const char* label, float* v, float v_min, float v_max, const char* format/* = "%.3f"*/, float power/* = 1.0f*/)
+{
+ return ImGui::SliderFloat(label, v, v_min, v_max, format, power);
+}
+
+bool ImGuiWrapper::slider_float(const std::string& label, float* v, float v_min, float v_max, const char* format/* = "%.3f"*/, float power/* = 1.0f*/)
+{
+ return this->slider_float(label.c_str(), v, v_min, v_max, format, power);
+}
+
+bool ImGuiWrapper::slider_float(const wxString& label, float* v, float v_min, float v_max, const char* format/* = "%.3f"*/, float power/* = 1.0f*/)
+{
+ auto label_utf8 = into_u8(label);
+ return this->slider_float(label_utf8.c_str(), v, v_min, v_max, format, power);
+}
+
bool ImGuiWrapper::combo(const wxString& label, const std::vector<std::string>& options, int& selection)
{
// this is to force the label to the left of the widget:
@@ -409,15 +441,37 @@ bool ImGuiWrapper::want_any_input() const
return io.WantCaptureMouse || io.WantCaptureKeyboard || io.WantTextInput;
}
+#ifdef __APPLE__
+static const ImWchar ranges_keyboard_shortcuts[] =
+{
+ 0x21E7, 0x21E7, // OSX Shift Key symbol
+ 0x2318, 0x2318, // OSX Command Key symbol
+ 0x2325, 0x2325, // OSX Option Key symbol
+ 0,
+};
+#endif // __APPLE__
+
void ImGuiWrapper::init_font(bool compress)
{
destroy_font();
ImGuiIO& io = ImGui::GetIO();
io.Fonts->Clear();
- //FIXME replace with io.Fonts->AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, m_font_size, nullptr, m_glyph_ranges);
+
+ // Create ranges of characters from m_glyph_ranges, possibly adding some OS specific special characters.
+ ImVector<ImWchar> ranges;
+ ImFontAtlas::GlyphRangesBuilder builder;
+ builder.AddRanges(m_glyph_ranges);
+#ifdef __APPLE__
+ if (m_font_cjk)
+ // Apple keyboard shortcuts are only contained in the CJK fonts.
+ builder.AddRanges(ranges_keyboard_shortcuts);
+#endif
+ builder.BuildRanges(&ranges); // Build the final result (ordered ranges with all the unique characters submitted)
+
+ //FIXME replace with io.Fonts->AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, m_font_size, nullptr, ranges.Data);
//https://github.com/ocornut/imgui/issues/220
- ImFont* font = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/" + (m_font_cjk ? "NotoSansCJK-Regular.ttc" : "NotoSans-Regular.ttf")).c_str(), m_font_size, nullptr, m_glyph_ranges);
+ ImFont* font = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/" + (m_font_cjk ? "NotoSansCJK-Regular.ttc" : "NotoSans-Regular.ttf")).c_str(), m_font_size, nullptr, ranges.Data);
if (font == nullptr) {
font = io.Fonts->AddFontDefault();
if (font == nullptr) {
@@ -425,6 +479,16 @@ void ImGuiWrapper::init_font(bool compress)
}
}
+#ifdef __APPLE__
+ ImFontConfig config;
+ config.MergeMode = true;
+ if (! m_font_cjk) {
+ // Apple keyboard shortcuts are only contained in the CJK fonts.
+ ImFont *font_cjk = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/NotoSansCJK-Regular.ttc").c_str(), m_font_size, &config, ranges_keyboard_shortcuts);
+ assert(font_cjk != nullptr);
+ }
+#endif
+
// Build texture atlas
unsigned char* pixels;
int width, height;
@@ -498,13 +562,18 @@ void ImGuiWrapper::init_style()
(hex_color & 0xff) / 255.0f);
};
- static const unsigned COL_GREY_DARK = 0x444444ff;
+ static const unsigned COL_WINDOW_BACKGROND = 0x222222cc;
+ static const unsigned COL_GREY_DARK = 0x555555ff;
static const unsigned COL_GREY_LIGHT = 0x666666ff;
static const unsigned COL_ORANGE_DARK = 0xc16737ff;
static const unsigned COL_ORANGE_LIGHT = 0xff7d38ff;
- // Generics
+ // Window
+ style.WindowRounding = 4.0f;
+ set_color(ImGuiCol_WindowBg, COL_WINDOW_BACKGROND);
set_color(ImGuiCol_TitleBgActive, COL_ORANGE_DARK);
+
+ // Generics
set_color(ImGuiCol_FrameBg, COL_GREY_DARK);
set_color(ImGuiCol_FrameBgHovered, COL_GREY_LIGHT);
set_color(ImGuiCol_FrameBgActive, COL_GREY_LIGHT);
@@ -528,6 +597,9 @@ void ImGuiWrapper::init_style()
// Slider
set_color(ImGuiCol_SliderGrab, COL_ORANGE_DARK);
set_color(ImGuiCol_SliderGrabActive, COL_ORANGE_LIGHT);
+
+ // Separator
+ set_color(ImGuiCol_Separator, COL_ORANGE_LIGHT);
}
void ImGuiWrapper::render_draw_data(ImDrawData *draw_data)