Merge pull request #92 from memononen/master
Smoother mouse wheel scrolling
This commit is contained in:
commit
31654958f9
@ -131,7 +131,7 @@ static void glfw_mouse_button_callback(GLFWwindow* window, int button, int actio
|
|||||||
static void glfw_scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
static void glfw_scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.MouseWheel = (yoffset != 0.0f) ? yoffset > 0.0f ? 1 : - 1 : 0; // Mouse wheel: -1,0,+1
|
io.MouseWheel = yoffset; // Use fractional mouse wheel, 1.0 unit 3 lines.
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||||
|
@ -1433,16 +1433,15 @@ void ImGui::NewFrame()
|
|||||||
g.IO.WantCaptureKeyboard = (g.ActiveId != 0);
|
g.IO.WantCaptureKeyboard = (g.ActiveId != 0);
|
||||||
|
|
||||||
// Scale & Scrolling
|
// Scale & Scrolling
|
||||||
if (g.HoveredWindow && g.IO.MouseWheel != 0)
|
if (g.HoveredWindow && g.IO.MouseWheel != 0.0f)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = g.HoveredWindow;
|
ImGuiWindow* window = g.HoveredWindow;
|
||||||
const int mouse_wheel_dir = g.IO.MouseWheel > 0 ? +1 : -1;
|
|
||||||
if (g.IO.KeyCtrl)
|
if (g.IO.KeyCtrl)
|
||||||
{
|
{
|
||||||
if (g.IO.FontAllowUserScaling)
|
if (g.IO.FontAllowUserScaling)
|
||||||
{
|
{
|
||||||
// Zoom / Scale window
|
// Zoom / Scale window
|
||||||
float new_font_scale = ImClamp(window->FontWindowScale + mouse_wheel_dir * 0.10f, 0.50f, 2.50f);
|
float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
|
||||||
float scale = new_font_scale / window->FontWindowScale;
|
float scale = new_font_scale / window->FontWindowScale;
|
||||||
window->FontWindowScale = new_font_scale;
|
window->FontWindowScale = new_font_scale;
|
||||||
|
|
||||||
@ -1457,7 +1456,7 @@ void ImGui::NewFrame()
|
|||||||
{
|
{
|
||||||
// Scroll
|
// Scroll
|
||||||
const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5;
|
const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5;
|
||||||
window->NextScrollY -= mouse_wheel_dir * window->FontSize() * scroll_lines;
|
window->NextScrollY -= g.IO.MouseWheel * window->FontSize() * scroll_lines;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1607,7 +1606,7 @@ void ImGui::Render()
|
|||||||
g.Windows.swap(sorted_windows);
|
g.Windows.swap(sorted_windows);
|
||||||
|
|
||||||
// Clear data for next frame
|
// Clear data for next frame
|
||||||
g.IO.MouseWheel = 0;
|
g.IO.MouseWheel = 0.0f;
|
||||||
memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
|
memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
imgui.h
2
imgui.h
@ -488,7 +488,7 @@ struct ImGuiIO
|
|||||||
|
|
||||||
ImVec2 MousePos; // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
|
ImVec2 MousePos; // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
|
||||||
bool MouseDown[5]; // Mouse buttons. ImGui itself only uses button 0 (left button) but you can use others as storage for convenience.
|
bool MouseDown[5]; // Mouse buttons. ImGui itself only uses button 0 (left button) but you can use others as storage for convenience.
|
||||||
int MouseWheel; // Mouse wheel: -1,0,+1
|
float MouseWheel; // Mouse wheel: 1 unit scrolls about 3 lines text.
|
||||||
bool KeyCtrl; // Keyboard modifier pressed: Control
|
bool KeyCtrl; // Keyboard modifier pressed: Control
|
||||||
bool KeyShift; // Keyboard modifier pressed: Shift
|
bool KeyShift; // Keyboard modifier pressed: Shift
|
||||||
bool KeysDown[512]; // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data)
|
bool KeysDown[512]; // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data)
|
||||||
|
Loading…
Reference in New Issue
Block a user