Merge branch 'master' of https://github.com/prusa3d/PrusaSlicer into et_gcode_viewer

This commit is contained in:
enricoturri1966 2020-05-15 17:58:07 +02:00
commit c49f46d904
12 changed files with 240 additions and 454 deletions

View File

@ -34,17 +34,6 @@
#define ENABLE_HACK_CLOSING_ON_OSX_10_9_5 (1 && ENABLE_2_2_0_RC1)
//==================
// 2.2.0.final techs
//==================
#define ENABLE_2_2_0_FINAL 1
// Enable tooltips for GLCanvas3D using ImGUI
#define ENABLE_CANVAS_TOOLTIP_USING_IMGUI (1 && ENABLE_2_2_0_FINAL)
// Enable fix for dragging mouse event handling for gizmobar
#define ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX (1 && ENABLE_2_2_0_FINAL)
//===================
// 2.3.0.alpha1 techs
//===================

View File

@ -92,6 +92,12 @@ void Field::PostInitialize()
case '2': { tab_id = 1; break; }
case '3': { tab_id = 2; break; }
case '4': { tab_id = 3; break; }
#ifdef __APPLE__
case 'f':
#else /* __APPLE__ */
case WXK_CONTROL_F:
#endif /* __APPLE__ */
case 'F': { wxGetApp().plater()->search(false); break; }
default: break;
}
if (tab_id >= 0)

View File

@ -63,11 +63,6 @@
#include <algorithm>
#include <cmath>
#include "DoubleSlider.hpp"
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
#if ENABLE_RENDER_STATISTICS
#include <chrono>
#endif // ENABLE_RENDER_STATISTICS
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
#include <imgui/imgui_internal.h>
@ -1381,7 +1376,6 @@ void GLCanvas3D::Labels::render(const std::vector<const ModelInstance*>& sorted_
}
}
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
void GLCanvas3D::Tooltip::set_text(const std::string& text)
{
// If the mouse is inside an ImGUI dialog, then the tooltip is suppressed.
@ -1433,7 +1427,6 @@ void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position, GLCanvas3D& canvas
imgui.end();
ImGui::PopStyleVar(2);
}
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
#if ENABLE_SLOPE_RENDERING
void GLCanvas3D::Slope::render() const
@ -2122,7 +2115,6 @@ void GLCanvas3D::render()
m_camera.debug_render();
#endif // ENABLE_CAMERA_STATISTICS
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
std::string tooltip;
// Negative coordinate means out of the window, likely because the window was deactivated.
@ -2152,7 +2144,6 @@ void GLCanvas3D::render()
if (m_tooltip_enabled)
m_tooltip.render(m_mouse.position, *this);
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
wxGetApp().plater()->get_mouse3d_controller().render_settings_dialog(*this);
@ -2164,30 +2155,6 @@ void GLCanvas3D::render()
auto end_time = std::chrono::high_resolution_clock::now();
m_render_stats.last_frame = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count();
#endif // ENABLE_RENDER_STATISTICS
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
std::string tooltip = "";
if (tooltip.empty())
tooltip = m_layers_editing.get_tooltip(*this);
if (tooltip.empty())
tooltip = m_gizmos.get_tooltip();
if (tooltip.empty())
tooltip = m_main_toolbar.get_tooltip();
if (tooltip.empty())
tooltip = m_undoredo_toolbar.get_tooltip();
if (tooltip.empty())
tooltip = m_collapse_toolbar.get_tooltip();
if (tooltip.empty())
tooltip = m_view_toolbar.get_tooltip();
set_tooltip(tooltip);
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
void GLCanvas3D::render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool show_bed, bool transparent_background) const
@ -2911,9 +2878,7 @@ void GLCanvas3D::bind_event_handlers()
m_canvas->Bind(wxEVT_MIDDLE_DCLICK, &GLCanvas3D::on_mouse, this);
m_canvas->Bind(wxEVT_RIGHT_DCLICK, &GLCanvas3D::on_mouse, this);
m_canvas->Bind(wxEVT_PAINT, &GLCanvas3D::on_paint, this);
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
m_canvas->Bind(wxEVT_SET_FOCUS, &GLCanvas3D::on_set_focus, this);
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
}
@ -2941,9 +2906,7 @@ void GLCanvas3D::unbind_event_handlers()
m_canvas->Unbind(wxEVT_MIDDLE_DCLICK, &GLCanvas3D::on_mouse, this);
m_canvas->Unbind(wxEVT_RIGHT_DCLICK, &GLCanvas3D::on_mouse, this);
m_canvas->Unbind(wxEVT_PAINT, &GLCanvas3D::on_paint, this);
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
m_canvas->Unbind(wxEVT_SET_FOCUS, &GLCanvas3D::on_set_focus, this);
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
}
@ -3561,29 +3524,20 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
Point pos(evt.GetX(), evt.GetY());
ImGuiWrapper* imgui = wxGetApp().imgui();
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if (m_tooltip.is_in_imgui() && evt.LeftUp())
// ignore left up events coming from imgui windows and not processed by them
m_mouse.ignore_left_up = true;
m_tooltip.set_in_imgui(false);
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if (imgui->update_mouse_data(evt)) {
m_mouse.position = evt.Leaving() ? Vec2d(-1.0, -1.0) : pos.cast<double>();
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
m_tooltip.set_in_imgui(true);
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
render();
#ifdef SLIC3R_DEBUG_MOUSE_EVENTS
printf((format_mouse_event_debug_message(evt) + " - Consumed by ImGUI\n").c_str());
#endif /* SLIC3R_DEBUG_MOUSE_EVENTS */
// do not return if dragging or tooltip not empty to allow for tooltip update
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if (!m_mouse.dragging && m_tooltip.is_empty())
return;
#else
if (!m_mouse.dragging && m_canvas->GetToolTipText().empty())
return;
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
#ifdef __WXMSW__
@ -3642,9 +3596,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
mouse_up_cleanup();
m_mouse.set_start_position_3D_as_invalid();
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
m_mouse.position = pos.cast<double>();
#endif /// ENABLE_CANVAS_TOOLTIP_USING_IMGUI
return;
}
@ -3676,18 +3628,14 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
if (top_level_wnd && top_level_wnd->IsActive())
m_canvas->SetFocus();
m_mouse.position = pos.cast<double>();
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
m_tooltip_enabled = false;
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
// 1) forces a frame render to ensure that m_hover_volume_idxs is updated even when the user right clicks while
// the context menu is shown, ensuring it to disappear if the mouse is outside any volume and to
// change the volume hover state if any is under the mouse
// 2) when switching between 3d view and preview the size of the canvas changes if the side panels are visible,
// so forces a resize to avoid multiple renders with different sizes (seen as flickering)
_refresh_if_shown_on_screen();
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
m_tooltip_enabled = true;
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
m_mouse.set_start_position_2D_as_invalid();
//#endif
@ -4005,14 +3953,12 @@ void GLCanvas3D::on_paint(wxPaintEvent& evt)
this->render();
}
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
void GLCanvas3D::on_set_focus(wxFocusEvent& evt)
{
m_tooltip_enabled = false;
_refresh_if_shown_on_screen();
m_tooltip_enabled = true;
}
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
Size GLCanvas3D::get_canvas_size() const
{
@ -4062,26 +4008,7 @@ void GLCanvas3D::reset_legend_texture()
void GLCanvas3D::set_tooltip(const std::string& tooltip) const
{
if (m_canvas != nullptr)
{
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
m_tooltip.set_text(tooltip);
#else
wxString txt = wxString::FromUTF8(tooltip.data());
if (m_canvas->GetToolTipText() != txt)
m_canvas->SetToolTip(txt);
// wxToolTip* t = m_canvas->GetToolTip();
// if (t != nullptr)
// {
// if (tooltip.empty())
// m_canvas->UnsetToolTip();
// else
// t->SetTip(wxString::FromUTF8(tooltip.data()));
// }
// else if (!tooltip.empty()) // Avoid "empty" tooltips => unset of the empty tooltip leads to application crash under OSX
// m_canvas->SetToolTip(wxString::FromUTF8(tooltip.data()));
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
}
void GLCanvas3D::do_move(const std::string& snapshot_type)

View File

@ -3,9 +3,7 @@
#include <stddef.h>
#include <memory>
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
#include <chrono>
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
#include "3DScene.hpp"
#include "GLToolbar.hpp"
@ -399,7 +397,6 @@ private:
void render(const std::vector<const ModelInstance*>& sorted_instances) const;
};
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
class Tooltip
{
std::string m_text;
@ -415,7 +412,6 @@ private:
void set_in_imgui(bool b) { m_in_imgui = b; }
bool is_in_imgui() const { return m_in_imgui; }
};
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
#if ENABLE_SLOPE_RENDERING
class Slope
@ -526,10 +522,8 @@ private:
int m_selected_extruder;
Labels m_labels;
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
mutable Tooltip m_tooltip;
mutable bool m_tooltip_enabled{ true };
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
#if ENABLE_SLOPE_RENDERING
Slope m_slope;
#endif // ENABLE_SLOPE_RENDERING
@ -687,9 +681,7 @@ public:
void on_timer(wxTimerEvent& evt);
void on_mouse(wxMouseEvent& evt);
void on_paint(wxPaintEvent& evt);
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
void on_set_focus(wxFocusEvent& evt);
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
Size get_canvas_size() const;
Vec2d get_local_mouse_position() const;

View File

@ -153,9 +153,6 @@ GLToolbar::GLToolbar(GLToolbar::EType type, const std::string& name)
, m_name(name)
, m_enabled(false)
, m_icons_texture_dirty(true)
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
, m_tooltip("")
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
, m_pressed_toggable_id(-1)
{
}
@ -359,7 +356,6 @@ int GLToolbar::get_item_id(const std::string& name) const
return -1;
}
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
std::string GLToolbar::get_tooltip() const
{
std::string tooltip;
@ -382,7 +378,6 @@ std::string GLToolbar::get_tooltip() const
return tooltip;
}
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
void GLToolbar::get_additional_tooltip(int item_id, std::string& text)
{
@ -449,17 +444,11 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
// prevents loosing selection into the scene if mouse down was done inside the toolbar and mouse up was down outside it,
// as when switching between views
m_mouse_capture.reset();
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if (contains_mouse(mouse_pos, parent) == -1)
// mouse is outside the toolbar
m_tooltip.clear();
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
return true;
}
m_mouse_capture.reset();
}
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if (evt.Moving())
update_hover_state(mouse_pos, parent);
else if (evt.LeftUp())
@ -500,31 +489,9 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
else
return false;
}
#else
if (evt.Moving())
m_tooltip = update_hover_state(mouse_pos, parent);
else if (evt.LeftUp())
m_mouse_capture.left = false;
else if (evt.MiddleUp())
m_mouse_capture.middle = false;
else if (evt.RightUp())
m_mouse_capture.right = false;
else if (evt.Dragging() && m_mouse_capture.any())
// if the button down was done on this toolbar, prevent from dragging into the scene
processed = true;
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
int item_id = contains_mouse(mouse_pos, parent);
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if (item_id != -1)
#else
if (item_id == -1)
{
// mouse is outside the toolbar
m_tooltip.clear();
}
else
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
{
// mouse inside toolbar
if (evt.LeftDown() || evt.LeftDClick())
@ -532,12 +499,8 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
m_mouse_capture.left = true;
m_mouse_capture.parent = &parent;
processed = true;
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if ((item_id != -2) && !m_items[item_id]->is_separator() && !m_items[item_id]->is_disabled() &&
((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action_type() == GLToolbarItem::Left)))
#else
if ((item_id != -2) && !m_items[item_id]->is_separator() && ((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action_type() == GLToolbarItem::Left)))
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
{
// mouse is inside an icon
do_action(GLToolbarItem::Left, item_id, parent, true);
@ -554,22 +517,14 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
m_mouse_capture.right = true;
m_mouse_capture.parent = &parent;
processed = true;
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if ((item_id != -2) && !m_items[item_id]->is_separator() && !m_items[item_id]->is_disabled() &&
((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action_type() == GLToolbarItem::Right)))
#else
if ((item_id != -2) && !m_items[item_id]->is_separator() && ((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action_type() == GLToolbarItem::Right)))
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
{
// mouse is inside an icon
do_action(GLToolbarItem::Right, item_id, parent, true);
parent.set_as_dirty();
}
}
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
else if (evt.LeftUp())
processed = true;
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
return processed;
@ -654,11 +609,7 @@ void GLToolbar::do_action(GLToolbarItem::EActionType type, int item_id, GLCanvas
if ((0 <= item_id) && (item_id < (int)m_items.size()))
{
GLToolbarItem* item = m_items[item_id];
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if ((item != nullptr) && !item->is_separator() && !item->is_disabled() && (!check_hover || item->is_hovered()))
#else
if ((item != nullptr) && !item->is_separator() && (!check_hover || item->is_hovered()))
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
{
if (((type == GLToolbarItem::Right) && item->is_right_toggable()) ||
((type == GLToolbarItem::Left) && item->is_left_toggable()))
@ -712,7 +663,6 @@ void GLToolbar::do_action(GLToolbarItem::EActionType type, int item_id, GLCanvas
}
}
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
void GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent)
{
if (!m_enabled)
@ -725,26 +675,8 @@ void GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent)
case Layout::Vertical: { update_hover_state_vertical(mouse_pos, parent); break; }
}
}
#else
std::string GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent)
{
if (!m_enabled)
return "";
switch (m_layout.type)
{
default:
case Layout::Horizontal: { return update_hover_state_horizontal(mouse_pos, parent); }
case Layout::Vertical: { return update_hover_state_vertical(mouse_pos, parent); }
}
}
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent)
#else
std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent)
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
{
// NB: mouse_pos is already scaled appropriately
@ -765,10 +697,6 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC
float left = m_layout.left + scaled_border;
float top = m_layout.top - scaled_border;
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
std::string tooltip;
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
for (GLToolbarItem* item : m_items)
{
if (!item->is_visible())
@ -783,18 +711,6 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC
GLToolbarItem::EState state = item->get_state();
bool inside = (left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top);
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if (inside)
{
tooltip = item->get_tooltip();
if (!item->is_pressed())
{
const std::string& additional_tooltip = item->get_additional_tooltip();
if (!additional_tooltip.empty())
tooltip += "\n" + additional_tooltip;
}
}
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
switch (state)
{
@ -838,7 +754,6 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC
break;
}
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
case GLToolbarItem::Disabled:
{
if (inside)
@ -863,29 +778,14 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC
{
break;
}
#else
default:
case GLToolbarItem::Disabled:
{
break;
}
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
left += icon_stride;
}
}
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
return tooltip;
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent)
#else
std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent)
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
{
// NB: mouse_pos is already scaled appropriately
@ -905,10 +805,6 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan
float left = m_layout.left + scaled_border;
float top = m_layout.top - scaled_border;
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
std::string tooltip;
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
for (GLToolbarItem* item : m_items)
{
if (!item->is_visible())
@ -923,18 +819,6 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan
GLToolbarItem::EState state = item->get_state();
bool inside = (left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top);
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if (inside)
{
tooltip = item->get_tooltip();
if (!item->is_pressed())
{
const std::string& additional_tooltip = item->get_additional_tooltip();
if (!additional_tooltip.empty())
tooltip += "\n" + additional_tooltip;
}
}
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
switch (state)
{
@ -978,7 +862,6 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan
break;
}
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
case GLToolbarItem::Disabled:
{
if (inside)
@ -1003,22 +886,11 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan
{
break;
}
#else
default:
case GLToolbarItem::Disabled:
{
break;
}
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
top -= icon_stride;
}
}
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
return tooltip;
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
int GLToolbar::contains_mouse(const Vec2d& mouse_pos, const GLCanvas3D& parent) const
@ -1367,37 +1239,21 @@ bool GLToolbar::generate_icons_texture() const
std::vector<std::pair<int, bool>> states;
if (m_name == "Top")
{
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
states.push_back({ 1, false }); // Normal
states.push_back({ 0, false }); // Pressed
states.push_back({ 2, false }); // Disabled
states.push_back({ 0, false }); // Hover
states.push_back({ 0, false }); // HoverPressed
states.push_back({ 2, false }); // HoverDisabled
#else
states.push_back(std::make_pair(1, false));
states.push_back(std::make_pair(0, false));
states.push_back(std::make_pair(2, false));
states.push_back(std::make_pair(0, false));
states.push_back(std::make_pair(0, false));
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
else if (m_name == "View")
{
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
states.push_back({ 1, false }); // Normal
states.push_back({ 1, true }); // Pressed
states.push_back({ 1, false }); // Disabled
states.push_back({ 0, false }); // Hover
states.push_back({ 1, true }); // HoverPressed
states.push_back({ 1, false }); // HoverDisabled
#else
states.push_back(std::make_pair(1, false));
states.push_back(std::make_pair(1, true));
states.push_back(std::make_pair(1, false));
states.push_back(std::make_pair(0, false));
states.push_back(std::make_pair(1, true));
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
unsigned int sprite_size_px = (unsigned int)(m_layout.icons_size * m_layout.scale);

View File

@ -61,9 +61,7 @@ public:
Disabled,
Hover,
HoverPressed,
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
HoverDisabled,
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
Num_States
};
@ -123,15 +121,9 @@ public:
void do_left_action() { m_last_action_type = Left; m_data.left.action_callback(); }
void do_right_action() { m_last_action_type = Right; m_data.right.action_callback(); }
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
bool is_enabled() const { return (m_state != Disabled) && (m_state != HoverDisabled); }
bool is_disabled() const { return (m_state == Disabled) || (m_state == HoverDisabled); }
bool is_hovered() const { return (m_state == Hover) || (m_state == HoverPressed) || (m_state == HoverDisabled); }
#else
bool is_enabled() const { return m_state != Disabled; }
bool is_disabled() const { return m_state == Disabled; }
bool is_hovered() const { return (m_state == Hover) || (m_state == HoverPressed); }
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
bool is_pressed() const { return (m_state == Pressed) || (m_state == HoverPressed); }
bool is_visible() const { return m_data.visible; }
bool is_separator() const { return m_type == Separator; }
@ -262,9 +254,6 @@ private:
};
MouseCapture m_mouse_capture;
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
std::string m_tooltip;
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
int m_pressed_toggable_id;
public:
@ -310,11 +299,7 @@ public:
void force_left_action(int item_id, GLCanvas3D& parent) { do_action(GLToolbarItem::Left, item_id, parent, false); }
void force_right_action(int item_id, GLCanvas3D& parent) { do_action(GLToolbarItem::Right, item_id, parent, false); }
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
std::string get_tooltip() const;
#else
const std::string& get_tooltip() const { return m_tooltip; }
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
void get_additional_tooltip(int item_id, std::string& text);
void set_additional_tooltip(int item_id, const std::string& text);
@ -336,15 +321,9 @@ private:
float get_height_vertical() const;
float get_main_size() const;
void do_action(GLToolbarItem::EActionType type, int item_id, GLCanvas3D& parent, bool check_hover);
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
void update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent);
void update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent);
void update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent);
#else
std::string update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent);
std::string update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent);
std::string update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent);
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
// returns the id of the item under the given mouse position or -1 if none
int contains_mouse(const Vec2d& mouse_pos, const GLCanvas3D& parent) const;
int contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const;

View File

@ -479,22 +479,9 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt)
int selected_object_idx = selection.get_object_idx();
bool processed = false;
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
// mouse anywhere
if (!evt.Dragging() && !evt.Leaving() && !evt.Entering() && (m_mouse_capture.parent != nullptr))
{
if (m_mouse_capture.any() && (evt.LeftUp() || evt.MiddleUp() || evt.RightUp()))
// prevents loosing selection into the scene if mouse down was done inside the toolbar and mouse up was down outside it
processed = true;
m_mouse_capture.reset();
}
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
// mouse anywhere
if (evt.Moving())
m_tooltip = update_hover_state(mouse_pos);
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
else if (evt.LeftUp())
{
if (m_mouse_capture.left)
@ -551,11 +538,7 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt)
// else
// return false;
}
#if ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX
else if (evt.Dragging() && !is_dragging())
#else
else if (evt.Dragging())
#endif // ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX
{
if (m_mouse_capture.any())
// if the button down was done on this toolbar, prevent from dragging into the scene
@ -563,25 +546,6 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt)
// else
// return false;
}
#else
else if (evt.LeftUp())
m_mouse_capture.left = false;
else if (evt.MiddleUp())
m_mouse_capture.middle = false;
else if (evt.RightUp())
{
m_mouse_capture.right = false;
if (pending_right_up)
{
pending_right_up = false;
processed = true;
}
}
else if (evt.Dragging() && m_mouse_capture.any())
// if the button down was done on this toolbar, prevent from dragging into the scene
processed = true;
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
#if ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX
else if (evt.Dragging() && is_dragging())
{
if (!m_parent.get_wxglcanvas()->HasCapture())
@ -628,7 +592,6 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt)
m_parent.set_as_dirty();
processed = true;
}
#endif // ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX
if (get_gizmo_idx_from_mouse(mouse_pos) == Undefined)
{
@ -680,77 +643,6 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt)
m_parent.set_as_dirty();
processed = true;
}
#if !ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX
else if (evt.Dragging() && is_dragging())
{
if (!m_parent.get_wxglcanvas()->HasCapture())
m_parent.get_wxglcanvas()->CaptureMouse();
m_parent.set_mouse_as_dragging();
update(m_parent.mouse_ray(pos), pos);
switch (m_current)
{
case Move:
{
// Apply new temporary offset
selection.translate(get_displacement());
wxGetApp().obj_manipul()->set_dirty();
break;
}
case Scale:
{
// Apply new temporary scale factors
TransformationType transformation_type(TransformationType::Local_Absolute_Joint);
if (evt.AltDown())
transformation_type.set_independent();
selection.scale(get_scale(), transformation_type);
if (evt.ControlDown())
selection.translate(get_scale_offset(), true);
wxGetApp().obj_manipul()->set_dirty();
break;
}
case Rotate:
{
// Apply new temporary rotations
TransformationType transformation_type(TransformationType::World_Relative_Joint);
if (evt.AltDown())
transformation_type.set_independent();
selection.rotate(get_rotation(), transformation_type);
wxGetApp().obj_manipul()->set_dirty();
break;
}
default:
break;
}
m_parent.set_as_dirty();
processed = true;
}
#endif // !ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
else if (evt.LeftUp() && is_dragging())
{
switch (m_current) {
case Move : m_parent.do_move(L("Gizmo-Move")); break;
case Scale : m_parent.do_scale(L("Gizmo-Scale")); break;
case Rotate : m_parent.do_rotate(L("Gizmo-Rotate")); break;
default : break;
}
stop_dragging();
update_data();
wxGetApp().obj_manipul()->set_dirty();
// Let the plater know that the dragging finished, so a delayed refresh
// of the scene with the background processing data should be performed.
m_parent.post_event(SimpleEvent(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED));
// updates camera target constraints
m_parent.refresh_camera_scene_box();
processed = true;
}
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
else if (evt.LeftUp() && (m_current == SlaSupports || m_current == Hollow || m_current == FdmSupports) && !m_parent.is_mouse_dragging())
{
// in case SLA/FDM gizmo is selected, we just pass the LeftUp event and stop processing - neither
@ -794,10 +686,6 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt)
m_mouse_capture.right = true;
m_mouse_capture.parent = &m_parent;
}
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
else if (evt.LeftUp())
processed = true;
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
return processed;

View File

@ -747,7 +747,6 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
// add checkboxes for show/hide Categories and Groups
text(_L("Use for search")+":");
check_box(_L("Category"), view_params.category);
check_box(_L("Group"), view_params.group);
if (is_localized)
check_box(_L("Search in English"), view_params.english);
}

View File

@ -1434,6 +1434,12 @@ SettingsDialog::SettingsDialog(MainFrame* mainframe)
case '2': { m_main_frame->select_tab(1); break; }
case '3': { m_main_frame->select_tab(2); break; }
case '4': { m_main_frame->select_tab(3); break; }
#ifdef __APPLE__
case 'f':
#else /* __APPLE__ */
case WXK_CONTROL_F:
#endif /* __APPLE__ */
case 'F': { m_main_frame->plater()->search(false); break; }
default:break;
}
}

View File

@ -6,6 +6,8 @@
#include <boost/optional.hpp>
#include <boost/nowide/convert.hpp>
#include "wx/dataview.h"
#include "libslic3r/PrintConfig.hpp"
#include "GUI_App.hpp"
#include "Tab.hpp"
@ -199,10 +201,8 @@ bool OptionsSearcher::search(const std::string& search, bool force/* = false*/)
const std::wstring *prev = nullptr;
for (const std::wstring * const s : {
view_params.category ? &opt.category_local : nullptr,
view_params.group ? &opt.group_local : nullptr,
&opt.label_local })
&opt.group_local, &opt.label_local })
if (s != nullptr && (prev == nullptr || *prev != *s)) {
// if (! out.empty())
if (out.size()>2)
out += sep;
out += *s;
@ -218,10 +218,8 @@ bool OptionsSearcher::search(const std::string& search, bool force/* = false*/)
const std::wstring*prev = nullptr;
for (const std::wstring * const s : {
view_params.category ? &opt.category : nullptr,
view_params.group ? &opt.group : nullptr,
&opt.label })
&opt.group, &opt.label })
if (s != nullptr && (prev == nullptr || *prev != *s)) {
// if (! out.empty())
if (out.size()>2)
out += sep;
out += *s;
@ -272,9 +270,9 @@ bool OptionsSearcher::search(const std::string& search, bool force/* = false*/)
label += L" [" + std::to_wstring(score) + L"]";// add score value
std::string label_u8 = into_u8(label);
std::string label_plain = label_u8;
boost::erase_all(label_plain, std::string(1, char(ImGui::ColorMarkerStart)));
boost::erase_all(label_plain, std::string(1, char(ImGui::ColorMarkerEnd)));
found.emplace_back(FoundOption{ label_plain, label_u8, boost::nowide::narrow(get_tooltip(opt)), i, score });
boost::replace_all(label_plain, std::string(1, char(ImGui::ColorMarkerStart)), "<b>");
boost::replace_all(label_plain, std::string(1, char(ImGui::ColorMarkerEnd)), "</b>");
found.emplace_back(FoundOption{ label_plain, label_u8, boost::nowide::narrow(get_tooltip(opt)), i, score });
}
}
@ -415,6 +413,14 @@ void SearchComboPopup::OnKeyDown(wxKeyEvent& event)
// SearchDialog
//------------------------------------------
static const std::map<const char, int> icon_idxs = {
{ImGui::PrintIconMarker , 0},
{ImGui::PrinterIconMarker , 1},
{ImGui::PrinterSlaIconMarker, 2},
{ImGui::FilamentIconMarker , 3},
{ImGui::MaterialIconMarker , 4},
};
SearchDialog::SearchDialog(OptionsSearcher* searcher)
: GUI::DPIDialog(NULL, wxID_ANY, _L("Search"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
searcher(searcher)
@ -425,23 +431,35 @@ SearchDialog::SearchDialog(OptionsSearcher* searcher)
default_string = _L("Type here to search");
int border = 10;
int em = em_unit();
search_line = new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize);
search_line = new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
// wxWANTS_CHARS style is neede for process Enter key press
search_list = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxSize(em_unit() * 40, em_unit() * 30), 0, NULL, wxWANTS_CHARS);
search_list = new wxDataViewCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(em * 40, em * 30), wxDV_NO_HEADER | wxDV_SINGLE | wxBORDER_SIMPLE);
search_list_model = new SearchListModel(this);
search_list->AssociateModel(search_list_model);
search_list->AppendBitmapColumn("", SearchListModel::colIcon);
wxDataViewTextRenderer* const markupRenderer = new wxDataViewTextRenderer();
#if wxUSE_MARKUP
markupRenderer->EnableMarkup();
#endif // wxUSE_MARKUP
search_list->AppendColumn(new wxDataViewColumn("", markupRenderer, SearchListModel::colMarkedText, wxCOL_WIDTH_AUTOSIZE, wxALIGN_LEFT));
search_list->GetColumn(SearchListModel::colIcon )->SetWidth(3 * em_unit());
search_list->GetColumn(SearchListModel::colMarkedText)->SetWidth(40 * em_unit());
wxBoxSizer* check_sizer = new wxBoxSizer(wxHORIZONTAL);
check_category = new wxCheckBox(this, wxID_ANY, _L("Category"));
check_group = new wxCheckBox(this, wxID_ANY, _L("Group"));
if (GUI::wxGetApp().is_localized())
check_english = new wxCheckBox(this, wxID_ANY, _L("Search in English"));
wxStdDialogButtonSizer* cancel_btn = this->CreateStdDialogButtonSizer(wxCANCEL);
check_sizer->Add(new wxStaticText(this, wxID_ANY, _L("Use for search") + ":"), 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, border);
check_sizer->Add(check_category, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, border);
check_sizer->Add(check_group, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, border);
if (GUI::wxGetApp().is_localized())
check_sizer->Add(check_english, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, border);
check_sizer->AddStretchSpacer(border);
@ -458,16 +476,19 @@ SearchDialog::SearchDialog(OptionsSearcher* searcher)
// process wxEVT_KEY_DOWN to navigate inside search_list, if ArrowUp/Down was pressed
search_line->Bind(wxEVT_KEY_DOWN,&SearchDialog::OnKeyDown, this);
search_list->Bind(wxEVT_MOTION, &SearchDialog::OnMouseMove, this);
search_list->Bind(wxEVT_LEFT_UP, &SearchDialog::OnMouseClick, this);
search_list->Bind(wxEVT_KEY_DOWN,&SearchDialog::OnKeyDown, this);
search_list->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &SearchDialog::OnSelect, this);
search_list->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, &SearchDialog::OnActivate, this);
#ifdef __WXMSW__
search_list->GetMainWindow()->Bind(wxEVT_MOTION, &SearchDialog::OnMotion, this);
search_list->GetMainWindow()->Bind(wxEVT_LEFT_DOWN, &SearchDialog::OnLeftDown, this);
#endif //__WXMSW__
check_category->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this);
if (GUI::wxGetApp().is_localized())
check_english ->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this);
check_category->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this);
check_group ->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this);
this->Bind(wxEVT_LISTBOX, &SearchDialog::OnSelect, this);
Bind(wxEVT_MOTION, &SearchDialog::OnMotion, this);
Bind(wxEVT_LEFT_DOWN, &SearchDialog::OnLeftDown, this);
SetSizer(topSizer);
topSizer->SetSizeHints(this);
@ -484,19 +505,18 @@ void SearchDialog::Popup(wxPoint position /*= wxDefaultPosition*/)
const OptionViewParameters& params = searcher->view_params;
check_category->SetValue(params.category);
check_group->SetValue(params.group);
check_english->SetValue(params.english);
this->SetPosition(position);
this->ShowModal();
}
void SearchDialog::ProcessSelection(int selection)
void SearchDialog::ProcessSelection(wxDataViewItem selection)
{
if (selection < 0)
if (!selection.IsOk())
return;
GUI::wxGetApp().sidebar().jump_to_option(selection);
GUI::wxGetApp().sidebar().jump_to_option(search_list_model->GetRow(selection));
this->EndModal(wxID_CLOSE);
}
@ -521,39 +541,6 @@ void SearchDialog::OnLeftUpInTextCtrl(wxEvent& event)
event.Skip();
}
void SearchDialog::OnMouseMove(wxMouseEvent& event)
{
wxPoint pt = wxGetMousePosition() - search_list->GetScreenPosition();
int selection = search_list->HitTest(pt);
search_list->Select(selection);
}
void SearchDialog::OnMouseClick(wxMouseEvent&)
{
int selection = search_list->GetSelection();
search_list->SetSelection(wxNOT_FOUND);
wxCommandEvent event(wxEVT_LISTBOX, search_list->GetId());
event.SetInt(selection);
event.SetEventObject(search_list);
ProcessEvent(event);
}
void SearchDialog::OnSelect(wxCommandEvent& event)
{
int selection = event.GetSelection();
ProcessSelection(selection);
}
void SearchDialog::update_list()
{
search_list->Clear();
const std::vector<FoundOption>& filters = searcher->found_options();
for (const FoundOption& item : filters)
search_list->Append(from_u8(item.label).Remove(0, 1));
}
void SearchDialog::OnKeyDown(wxKeyEvent& event)
{
int key = event.GetKeyCode();
@ -561,17 +548,23 @@ void SearchDialog::OnKeyDown(wxKeyEvent& event)
// change selected item in the list
if (key == WXK_UP || key == WXK_DOWN)
{
int selection = search_list->GetSelection();
if (key == WXK_UP && selection > 0)
selection--;
if (key == WXK_DOWN && selection < int(search_list->GetCount() - 1))
selection++;
search_list->Select(selection);
// This function could be called from search_line,
// So, for the next correct navigation, set focus on the search_list
search_list->SetFocus();
auto item = search_list->GetSelection();
if (item.IsOk()) {
unsigned selection = search_list_model->GetRow(item);
if (key == WXK_UP && selection > 0)
selection--;
if (key == WXK_DOWN && selection < unsigned(search_list_model->GetCount() - 1))
selection++;
prevent_list_events = true;
search_list->Select(search_list_model->GetItem(selection));
prevent_list_events = false;
}
}
// process "Enter" pressed
else if (key == WXK_NUMPAD_ENTER || key == WXK_RETURN)
@ -580,21 +573,76 @@ void SearchDialog::OnKeyDown(wxKeyEvent& event)
event.Skip(); // !Needed to have EVT_CHAR generated as well
}
void SearchDialog::OnActivate(wxDataViewEvent& event)
{
ProcessSelection(event.GetItem());
}
void SearchDialog::OnSelect(wxDataViewEvent& event)
{
// To avoid selection update from Select() under osx
if (prevent_list_events)
return;
// wxEVT_DATAVIEW_SELECTION_CHANGED is processed, when selection is changed after mouse click or press the Up/Down arrows
// But this two cases should be processed in different way:
// Up/Down arrows -> leave it as it is (just a navigation)
// LeftMouseClick -> call the ProcessSelection function
if (wxGetMouseState().LeftIsDown())
ProcessSelection(search_list->GetSelection());
}
void SearchDialog::update_list()
{
search_list_model->Clear();
const std::vector<FoundOption>& filters = searcher->found_options();
for (const FoundOption& item : filters)
search_list_model->Prepend(item.label);
// select first item
prevent_list_events = true;
search_list->Select(search_list_model->GetItem(0));
prevent_list_events = false;
}
void SearchDialog::OnCheck(wxCommandEvent& event)
{
OptionViewParameters& params = searcher->view_params;
params.english = check_english->GetValue();
params.category = check_category->GetValue();
params.group = check_group->GetValue();
searcher->search();
update_list();
}
void SearchDialog::OnMotion(wxMouseEvent& event)
{
wxDataViewItem item;
wxDataViewColumn* col;
wxWindow* win = this;
#ifdef __WXMSW__
win = search_list;
#endif
search_list->HitTest(wxGetMousePosition() - win->GetScreenPosition(), item, col);
search_list->Select(item);
event.Skip();
}
void SearchDialog::OnLeftDown(wxMouseEvent& event)
{
ProcessSelection(search_list->GetSelection());
}
void SearchDialog::on_dpi_changed(const wxRect& suggested_rect)
{
const int& em = em_unit();
search_list_model->msw_rescale();
search_list->GetColumn(SearchListModel::colIcon )->SetWidth(3 * em);
search_list->GetColumn(SearchListModel::colMarkedText)->SetWidth(45 * em);
msw_buttons_rescale(this, em, { wxID_CANCEL });
const wxSize& size = wxSize(40 * em, 30 * em);
@ -604,6 +652,65 @@ void SearchDialog::on_dpi_changed(const wxRect& suggested_rect)
Refresh();
}
// ----------------------------------------------------------------------------
// SearchListModel
// ----------------------------------------------------------------------------
SearchListModel::SearchListModel(wxWindow* parent) : wxDataViewVirtualListModel(0)
{
int icon_id = 0;
for (const std::string& icon : { "cog", "printer", "sla_printer", "spool", "resin" })
m_icon[icon_id++] = ScalableBitmap(parent, icon);
}
void SearchListModel::Clear()
{
m_values.clear();
Reset(0);
}
void SearchListModel::Prepend(const std::string& label)
{
const char icon_c = label.at(0);
int icon_idx = icon_idxs.at(icon_c);
wxString str = from_u8(label).Remove(0, 1);
m_values.emplace_back(str, icon_idx);
RowPrepended();
}
void SearchListModel::msw_rescale()
{
for (ScalableBitmap& bmp : m_icon)
bmp.msw_rescale();
}
wxString SearchListModel::GetColumnType(unsigned int col) const
{
if (col == colIcon)
return "wxBitmap";
return "string";
}
void SearchListModel::GetValueByRow(wxVariant& variant,
unsigned int row, unsigned int col) const
{
switch (col)
{
case colIcon:
variant << m_icon[m_values[row].second].bmp();
break;
case colMarkedText:
variant = m_values[row].first;
break;
case colMax:
wxFAIL_MSG("invalid column");
default:
break;
}
}
}

View File

@ -67,7 +67,6 @@ struct FoundOption {
struct OptionViewParameters
{
bool category {false};
bool group {true };
bool english {false};
int hovered_id {0};
@ -158,48 +157,86 @@ protected:
wxString m_input_string;
};
//------------------------------------------
// SearchDialog
//------------------------------------------
class SearchListModel;
class SearchDialog : public GUI::DPIDialog
{
wxString search_str;
wxString default_string;
wxTextCtrl* search_line { nullptr };
wxListBox* search_list { nullptr };
wxCheckBox* check_category { nullptr };
wxCheckBox* check_group { nullptr };
wxCheckBox* check_english { nullptr };
bool prevent_list_events {false};
OptionsSearcher* searcher;
wxTextCtrl* search_line { nullptr };
wxDataViewCtrl* search_list { nullptr };
SearchListModel* search_list_model { nullptr };
wxCheckBox* check_category { nullptr };
wxCheckBox* check_english { nullptr };
void update_list();
OptionsSearcher* searcher { nullptr };
void OnInputText(wxCommandEvent& event);
void OnLeftUpInTextCtrl(wxEvent& event);
void OnMouseMove(wxMouseEvent& event);
void OnMouseClick(wxMouseEvent& event);
void OnSelect(wxCommandEvent& event);
void OnKeyDown(wxKeyEvent& event);
void OnActivate(wxDataViewEvent& event);
void OnSelect(wxDataViewEvent& event);
void OnCheck(wxCommandEvent& event);
void OnMotion(wxMouseEvent& event);
void OnLeftDown(wxMouseEvent& event);
void update_list();
public:
SearchDialog(OptionsSearcher* searcher);
~SearchDialog() {}
void Popup(wxPoint position = wxDefaultPosition);
void ProcessSelection(int selection);
void ProcessSelection(wxDataViewItem selection);
protected:
void on_dpi_changed(const wxRect& suggested_rect) override;
};
// ----------------------------------------------------------------------------
// SearchListModel
// ----------------------------------------------------------------------------
class SearchListModel : public wxDataViewVirtualListModel
{
std::vector<std::pair<wxString, int>> m_values;
ScalableBitmap m_icon[5];
public:
enum {
colIcon,
colMarkedText,
colMax
};
SearchListModel(wxWindow* parent);
// helper methods to change the model
void Clear();
void Prepend(const std::string& text);
void msw_rescale();
// implementation of base class virtuals to define model
virtual unsigned int GetColumnCount() const wxOVERRIDE { return colMax; }
virtual wxString GetColumnType(unsigned int col) const wxOVERRIDE;
virtual void GetValueByRow(wxVariant& variant, unsigned int row, unsigned int col) const wxOVERRIDE;
virtual bool GetAttrByRow(unsigned int row, unsigned int col, wxDataViewItemAttr& attr) const wxOVERRIDE { return true; }
virtual bool SetValueByRow(const wxVariant& variant, unsigned int row, unsigned int col) wxOVERRIDE { return false; }
};
} // Search namespace
}

View File

@ -53,7 +53,7 @@ void Tab::Highlighter::init(BlinkingBitmap* bmp)
if (!bmp)
return;
timer.Start(100, false);
timer.Start(300, false);
bbmp = bmp;
bbmp->activate();
@ -74,7 +74,7 @@ void Tab::Highlighter::blink()
return;
bbmp->blink();
if ((++blink_counter) == 29)
if ((++blink_counter) == 11)
invalidate();
}