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/GUI_Utils.hpp')
-rw-r--r--src/slic3r/GUI/GUI_Utils.hpp77
1 files changed, 68 insertions, 9 deletions
diff --git a/src/slic3r/GUI/GUI_Utils.hpp b/src/slic3r/GUI/GUI_Utils.hpp
index 0d5249e25..3235d6e9e 100644
--- a/src/slic3r/GUI/GUI_Utils.hpp
+++ b/src/slic3r/GUI/GUI_Utils.hpp
@@ -18,12 +18,19 @@
#include <wx/debug.h>
#include <wx/settings.h>
+#include <chrono>
+
#include "Event.hpp"
class wxCheckBox;
class wxTopLevelWindow;
class wxRect;
+#if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
+#define wxVERSION_EQUAL_OR_GREATER_THAN(major, minor, release) ((wxMAJOR_VERSION > major) || ((wxMAJOR_VERSION == major) && (wxMINOR_VERSION > minor)) || ((wxMAJOR_VERSION == major) && (wxMINOR_VERSION == minor) && (wxRELEASE_NUMBER >= release)))
+#else
+#define wxVERSION_EQUAL_OR_GREATER_THAN(major, minor, release) 0
+#endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
namespace Slic3r {
namespace GUI {
@@ -48,9 +55,11 @@ void on_window_geometry(wxTopLevelWindow *tlw, std::function<void()> callback);
enum { DPI_DEFAULT = 96 };
-int get_dpi_for_window(wxWindow *window);
-wxFont get_default_font_for_dpi(int dpi);
+int get_dpi_for_window(const wxWindow *window);
+wxFont get_default_font_for_dpi(const wxWindow* window, int dpi);
+inline wxFont get_default_font(const wxWindow* window) { return get_default_font_for_dpi(window, get_dpi_for_window(window)); }
+#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
struct DpiChangedEvent : public wxEvent {
int dpi;
wxRect rect;
@@ -66,6 +75,7 @@ struct DpiChangedEvent : public wxEvent {
};
wxDECLARE_EVENT(EVT_DPI_CHANGED_SLICER, DpiChangedEvent);
+#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
template<class P> class DPIAware : public P
{
@@ -77,7 +87,7 @@ public:
int dpi = get_dpi_for_window(this);
m_scale_factor = (float)dpi / (float)DPI_DEFAULT;
m_prev_scale_factor = m_scale_factor;
- m_normal_font = get_default_font_for_dpi(dpi);
+ m_normal_font = get_default_font_for_dpi(this, dpi);
/* Because of default window font is a primary display font,
* We should set correct font for window before getting em_unit value.
@@ -85,22 +95,39 @@ public:
#ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList
this->SetFont(m_normal_font);
#endif
+ this->CenterOnParent();
+
+ // Linux specific issue : get_dpi_for_window(this) still doesn't responce to the Display's scale in new wxWidgets(3.1.3).
+ // So, calculate the m_em_unit value from the font size, as before
+#if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT && !defined(__WXGTK__)
+ m_em_unit = std::max<size_t>(10, 10.0f * m_scale_factor);
+#else
// initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window.
m_em_unit = std::max<size_t>(10, this->GetTextExtent("m").x - 1);
+#endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
// recalc_font();
- this->Bind(EVT_DPI_CHANGED_SLICER, [this](const DpiChangedEvent &evt) {
+#if wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
+ this->Bind(wxEVT_DPI_CHANGED, [this](wxDPIChangedEvent& evt) {
+ m_scale_factor = (float)evt.GetNewDPI().x / (float)DPI_DEFAULT;
+ m_new_font_point_size = get_default_font_for_dpi(this, evt.GetNewDPI().x).GetPointSize();
+ if (m_can_rescale && (m_force_rescale || is_new_scale_factor()))
+ rescale(wxRect());
+ });
+#else
+ this->Bind(EVT_DPI_CHANGED_SLICER, [this](const DpiChangedEvent& evt) {
m_scale_factor = (float)evt.dpi / (float)DPI_DEFAULT;
- m_new_font_point_size = get_default_font_for_dpi(evt.dpi).GetPointSize();
+ m_new_font_point_size = get_default_font_for_dpi(this, evt.dpi).GetPointSize();
if (!m_can_rescale)
return;
- if (is_new_scale_factor())
+ if (m_force_rescale || is_new_scale_factor())
rescale(evt.rect);
- });
+ });
+#endif // wxVERSION_EQUAL_OR_GREATER_THAN
this->Bind(wxEVT_MOVE_START, [this](wxMoveEvent& event)
{
@@ -124,6 +151,12 @@ public:
// set value to _true_ in purpose of possibility of a display dpi changing from System Settings
m_can_rescale = true;
});
+
+ this->Bind(wxEVT_SYS_COLOUR_CHANGED, [this](wxSysColourChangedEvent& event)
+ {
+ event.Skip();
+ on_sys_color_changed();
+ });
}
virtual ~DPIAware() {}
@@ -134,9 +167,11 @@ public:
int em_unit() const { return m_em_unit; }
// int font_size() const { return m_font_size; }
const wxFont& normal_font() const { return m_normal_font; }
+ void enable_force_rescale() { m_force_rescale = true; }
protected:
virtual void on_dpi_changed(const wxRect &suggested_rect) = 0;
+ virtual void on_sys_color_changed() {};
private:
float m_scale_factor;
@@ -146,6 +181,7 @@ private:
wxFont m_normal_font;
float m_prev_scale_factor;
bool m_can_rescale{ true };
+ bool m_force_rescale{ false };
int m_new_font_point_size;
@@ -185,17 +221,23 @@ private:
{
this->Freeze();
+ m_force_rescale = false;
+#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
// rescale fonts of all controls
scale_controls_fonts(this, m_new_font_point_size);
// rescale current window font
scale_win_font(this, m_new_font_point_size);
-
+#endif // wxVERSION_EQUAL_OR_GREATER_THAN
// set normal application font as a current window font
m_normal_font = this->GetFont();
// update em_unit value for new window font
+#if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
+ m_em_unit = std::max<int>(10, 10.0f * m_scale_factor);
+#else
m_em_unit = std::max<size_t>(10, this->GetTextExtent("m").x - 1);
+#endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
// rescale missed controls sizes and images
on_dpi_changed(suggested_rect);
@@ -334,7 +376,7 @@ public:
static WindowMetrics from_window(wxTopLevelWindow *window);
static boost::optional<WindowMetrics> deserialize(const std::string &str);
- wxRect get_rect() const { return rect; }
+ const wxRect& get_rect() const { return rect; }
bool get_maximized() const { return maximized; }
void sanitize_for_display(const wxRect &screen_rect);
@@ -343,6 +385,23 @@ public:
std::ostream& operator<<(std::ostream &os, const WindowMetrics& metrics);
+inline int hex_digit_to_int(const char c)
+{
+ return
+ (c >= '0' && c <= '9') ? int(c - '0') :
+ (c >= 'A' && c <= 'F') ? int(c - 'A') + 10 :
+ (c >= 'a' && c <= 'f') ? int(c - 'a') + 10 : -1;
+}
+
+class TaskTimer
+{
+ std::chrono::milliseconds start_timer;
+ std::string task_name;
+public:
+ TaskTimer(std::string task_name);
+
+ ~TaskTimer();
+};
}}