FIX:mousewheel delta of slider turn to 5 at times
Change-Id: I64db714b26a315fa443a0ab2796b4bf21a6ec2f5
This commit is contained in:
parent
f600af7b73
commit
895e90733b
|
@ -3438,7 +3438,13 @@ void GLCanvas3D::on_mouse_wheel(wxMouseEvent& evt)
|
|||
evt.SetY(evt.GetY() * scale);
|
||||
#endif
|
||||
|
||||
IMSlider* m_layers_slider = get_gcode_viewer().get_layers_slider();
|
||||
IMSlider* m_moves_slider = get_gcode_viewer().get_moves_slider();
|
||||
m_layers_slider->on_mouse_wheel(evt);
|
||||
m_moves_slider->on_mouse_wheel(evt);
|
||||
|
||||
if (wxGetApp().imgui()->update_mouse_data(evt)) {
|
||||
render();
|
||||
m_dirty = true;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -12,16 +12,6 @@
|
|||
#include "Tab.hpp"
|
||||
#include "GUI_ObjectList.hpp"
|
||||
|
||||
#include <wx/button.h>
|
||||
#include <wx/dialog.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/slider.h>
|
||||
#include <wx/menu.h>
|
||||
#include <wx/bmpcbox.h>
|
||||
#include <wx/statline.h>
|
||||
#include <wx/dcclient.h>
|
||||
#include <wx/colordlg.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
|
@ -441,7 +431,7 @@ IMSlider::IMSlider(int lowerValue, int higherValue, int minValue, int maxValue,
|
|||
m_style = style == wxSL_HORIZONTAL || style == wxSL_VERTICAL ? style : wxSL_HORIZONTAL;
|
||||
// BBS set to none style by default
|
||||
m_extra_style = style == wxSL_VERTICAL ? 0 : 0;
|
||||
m_selection = ssUndef;
|
||||
m_selection = ssHigher;
|
||||
m_is_need_post_tick_changed_event = false;
|
||||
m_tick_change_event_type = Type::Unknown;
|
||||
|
||||
|
@ -1055,7 +1045,7 @@ bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower
|
|||
if (!one_layer_flag)
|
||||
{
|
||||
// select higher handle by default
|
||||
static bool h_selected = true;
|
||||
bool h_selected = (selection == ssHigher);
|
||||
if (ImGui::ItemHoverable(higher_handle, id) && context.IO.MouseClicked[0]) {
|
||||
selection = ssHigher;
|
||||
h_selected = true;
|
||||
|
@ -1488,6 +1478,58 @@ void IMSlider::set_scale(float scale)
|
|||
if(m_scale != scale) m_scale = scale;
|
||||
}
|
||||
|
||||
void IMSlider::on_mouse_wheel(wxMouseEvent& evt) {
|
||||
auto moves_slider_window = ImGui::FindWindowByName("moves_slider");
|
||||
auto layers_slider_window = ImGui::FindWindowByName("laysers_slider");
|
||||
if (!moves_slider_window || !layers_slider_window) {
|
||||
BOOST_LOG_TRIVIAL(info) << "Couldn't find slider window";
|
||||
return;
|
||||
}
|
||||
|
||||
float wheel = 0.0f;
|
||||
wheel = evt.GetWheelRotation() > 0 ? 1.0f : -1.0f;
|
||||
if (wheel == 0.0f)
|
||||
return;
|
||||
|
||||
#ifdef __WXOSX__
|
||||
if (wxGetKeyState(WXK_SHIFT)) {
|
||||
wheel *= -5;
|
||||
}
|
||||
else if (wxGetKeyState(WXK_RAW_CONTROL)) {
|
||||
wheel *= 5;
|
||||
}
|
||||
#else
|
||||
if (wxGetKeyState(WXK_COMMAND) || wxGetKeyState(WXK_SHIFT))
|
||||
wheel *= 5;
|
||||
#endif
|
||||
if (is_horizontal()) {
|
||||
if( evt.GetPosition().x > moves_slider_window->Pos.x &&
|
||||
evt.GetPosition().x < moves_slider_window->Pos.x + moves_slider_window->Size.x &&
|
||||
evt.GetPosition().y > moves_slider_window->Pos.y &&
|
||||
evt.GetPosition().y < moves_slider_window->Pos.y + moves_slider_window->Size.y){
|
||||
const int new_pos = GetHigherValue() + wheel;
|
||||
SetHigherValue(new_pos);
|
||||
set_as_dirty();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (evt.GetPosition().x > layers_slider_window->Pos.x &&
|
||||
evt.GetPosition().x < layers_slider_window->Pos.x + layers_slider_window->Size.x &&
|
||||
evt.GetPosition().y > layers_slider_window->Pos.y &&
|
||||
evt.GetPosition().y < layers_slider_window->Pos.y + layers_slider_window->Size.y) {
|
||||
if (is_one_layer()) {
|
||||
const int new_pos = GetHigherValue() + wheel;
|
||||
SetHigherValue(new_pos);
|
||||
}
|
||||
else {
|
||||
const int new_pos = m_selection == ssLower ? GetLowerValue() + wheel : GetHigherValue() + wheel;
|
||||
m_selection == ssLower ? SetLowerValue(new_pos) : SetHigherValue(new_pos);
|
||||
}
|
||||
set_as_dirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IMSlider::correct_lower_value()
|
||||
{
|
||||
if (m_lower_value < m_min_value)
|
||||
|
|
|
@ -261,6 +261,7 @@ public:
|
|||
|
||||
void UseDefaultColors(bool def_colors_on) { m_ticks.set_default_colors(def_colors_on); }
|
||||
|
||||
void on_mouse_wheel(wxMouseEvent& evt);
|
||||
void post_ticks_changed_event(Type type = Custom);
|
||||
bool check_ticks_changed_event(Type type);
|
||||
bool switch_one_layer_mode();
|
||||
|
|
|
@ -141,7 +141,6 @@ int ImGuiWrapper::TOOLBAR_WINDOW_FLAGS = ImGuiWindowFlags_AlwaysAutoResize
|
|||
| ImGuiWindowFlags_NoCollapse
|
||||
| ImGuiWindowFlags_NoTitleBar;
|
||||
|
||||
static float accer = 1.f;
|
||||
|
||||
bool get_data_from_svg(const std::string &filename, unsigned int max_size_px, ThumbnailData &thumbnail_data)
|
||||
{
|
||||
|
@ -212,15 +211,7 @@ bool slider_behavior(ImGuiID id, const ImRect& region, const ImS32 v_min, const
|
|||
// Process interacting with the slider
|
||||
ImS32 v_new = *out_value;
|
||||
bool value_changed = false;
|
||||
// wheel behavior
|
||||
ImRect mouse_wheel_responsive_region;
|
||||
if (axis == ImGuiAxis_X)
|
||||
mouse_wheel_responsive_region = ImRect(region.Min - ImVec2(handle_sz.x / 2, 0), region.Max + ImVec2(handle_sz.x / 2, 0));
|
||||
if (axis == ImGuiAxis_Y)
|
||||
mouse_wheel_responsive_region = ImRect(region.Min - ImVec2(0, handle_sz.y), region.Max + ImVec2(0, handle_sz.y));
|
||||
if (ImGui::ItemHoverable(mouse_wheel_responsive_region, id)) {
|
||||
v_new = ImClamp(*out_value + (ImS32)(context.IO.MouseWheel * accer), v_min, v_max);
|
||||
}
|
||||
|
||||
// drag behavior
|
||||
if (context.ActiveId == id)
|
||||
{
|
||||
|
@ -451,19 +442,6 @@ bool ImGuiWrapper::update_key_data(wxKeyEvent &evt)
|
|||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
if (evt.CmdDown()) {
|
||||
accer = 5.f;
|
||||
}
|
||||
else if (evt.ShiftDown()) {
|
||||
#ifdef __APPLE__
|
||||
accer = -5.f;
|
||||
#else
|
||||
accer = 5.f;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
accer = 1.f;
|
||||
|
||||
if (evt.GetEventType() == wxEVT_CHAR) {
|
||||
// Char event
|
||||
const auto key = evt.GetUnicodeKey();
|
||||
|
|
Loading…
Reference in New Issue