From 97d60a9b0ea71c8df0ffb4ad73f241c3f5a14d65 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Thu, 15 Nov 2018 23:02:21 +0100 Subject: [PATCH] contextual interception of user input by imgui user interface implementation --- drivermode.cpp | 7 +++++-- driveruilayer.cpp | 8 +++----- driveruilayer.h | 18 +++++++++--------- editormode.cpp | 14 +++++++++++++- editormode.h | 2 +- editoruilayer.cpp | 7 ------- editoruilayer.h | 3 --- editoruipanels.cpp | 23 +++++++++++++++++++++++ editoruipanels.h | 7 +++++++ uilayer.cpp | 26 +++++++++++++++++++++----- uilayer.h | 24 +++++++++++++++++++----- 11 files changed, 101 insertions(+), 38 deletions(-) diff --git a/drivermode.cpp b/drivermode.cpp index 6bcc62ad..94029c02 100644 --- a/drivermode.cpp +++ b/drivermode.cpp @@ -322,7 +322,7 @@ driver_mode::on_key( int const Key, int const Scancode, int const Action, int co Global.altState = ( Mods & GLFW_MOD_ALT ) ? true : false; // give the ui first shot at the input processing... - if( true == m_userinterface->on_key( Key, Action ) ) { return; } + if( true == m_userinterface->on_key( Key, Scancode, Action, Mods ) ) { return; } // ...if the input is left untouched, pass it on if( true == m_input.keyboard.key( Key, Action ) ) { return; } @@ -370,7 +370,7 @@ void driver_mode::on_mouse_button( int const Button, int const Action, int const Mods ) { // give the ui first shot at the input processing... - if( true == m_userinterface->on_mouse_button( Button, Action ) ) { return; } + if( true == m_userinterface->on_mouse_button( Button, Action, Mods ) ) { return; } // give the potential event recipient a shot at it, in the virtual z order m_input.mouse.button( Button, Action ); @@ -379,6 +379,9 @@ driver_mode::on_mouse_button( int const Button, int const Action, int const Mods void driver_mode::on_scroll( double const Xoffset, double const Yoffset ) { + // give the ui first shot at the input processing... + if( true == m_userinterface->on_scroll( Xoffset, Yoffset ) ) { return; } + m_input.mouse.scroll( Xoffset, Yoffset ); } diff --git a/driveruilayer.cpp b/driveruilayer.cpp index d2ac22b9..7a30dcde 100644 --- a/driveruilayer.cpp +++ b/driveruilayer.cpp @@ -40,9 +40,7 @@ driver_ui::driver_ui() { // potentially processes provided input key. returns: true if key was processed, false otherwise bool -driver_ui::on_key( int const Key, int const Action ) { - // TODO: pass the input first through an active ui element if there's any - // if the ui element shows no interest or we don't have one, try to interpret the input yourself: +driver_ui::on_key_( int const Key, int const Scancode, int const Action, int const Mods ) { if( Key == GLFW_KEY_ESCAPE ) { // toggle pause @@ -130,14 +128,14 @@ driver_ui::on_key( int const Key, int const Action ) { // potentially processes provided mouse movement. returns: true if the input was processed, false otherwise bool -driver_ui::on_cursor_pos( double const Horizontal, double const Vertical ) { +driver_ui::on_cursor_pos_( double const Horizontal, double const Vertical ) { // intercept mouse movement when the pause window is on return m_paused; } // potentially processes provided mouse button. returns: true if the input was processed, false otherwise bool -driver_ui::on_mouse_button( int const Button, int const Action ) { +driver_ui::on_mouse_button_( int const Button, int const Action, int const Mods ) { // intercept mouse movement when the pause window is on return m_paused; } diff --git a/driveruilayer.h b/driveruilayer.h index 28a6d94b..f90beccb 100644 --- a/driveruilayer.h +++ b/driveruilayer.h @@ -18,15 +18,6 @@ public: // constructors driver_ui(); // methods - // potentially processes provided input key. returns: true if the input was processed, false otherwise - bool - on_key( int const Key, int const Action ) override; - // potentially processes provided mouse movement. returns: true if the input was processed, false otherwise - bool - on_cursor_pos( double const Horizontal, double const Vertical ) override; - // potentially processes provided mouse button. returns: true if the input was processed, false otherwise - bool - on_mouse_button( int const Button, int const Action ) override; // updates state of UI elements void update() override; @@ -39,6 +30,15 @@ private: // render() subclass details void render_() override; + // on_key() subclass details + bool + on_key_( int const Key, int const Scancode, int const Action, int const Mods ) override; + // on_cursor_pos() subclass details + bool + on_cursor_pos_( double const Horizontal, double const Vertical ) override; + // on_mouse_button() subclass details + bool + on_mouse_button_( int const Button, int const Action, int const Mods ) override; // members drivingaid_panel m_aidpanel { "Driving Aid", true }; timetable_panel m_timetablepanel { "Timetable", false }; diff --git a/editormode.cpp b/editormode.cpp index 30bb12cf..eb34f510 100644 --- a/editormode.cpp +++ b/editormode.cpp @@ -139,7 +139,7 @@ editor_mode::on_key( int const Key, int const Scancode, int const Action, int co Global.altState = ( Mods & GLFW_MOD_ALT ) ? true : false; // give the ui first shot at the input processing... - if( true == m_userinterface->on_key( Key, Action ) ) { return; } + if( true == m_userinterface->on_key( Key, Scancode, Action, Mods ) ) { return; } // ...if the input is left untouched, pass it on if( true == m_input.keyboard.key( Key, Action ) ) { return; } @@ -222,6 +222,9 @@ editor_mode::on_cursor_pos( double const Horizontal, double const Vertical ) { void editor_mode::on_mouse_button( int const Button, int const Action, int const Mods ) { + // give the ui first shot at the input processing... + if( true == m_userinterface->on_mouse_button( Button, Action, Mods ) ) { return; } + if( Button == GLFW_MOUSE_BUTTON_LEFT ) { if( Action == GLFW_PRESS ) { @@ -245,6 +248,15 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods m_input.mouse.button( Button, Action ); } +void +editor_mode::on_scroll( double const Xoffset, double const Yoffset ) { + + // give the ui first shot at the input processing... + if( true == m_userinterface->on_scroll( Xoffset, Yoffset ) ) { return; } + + // TBD, TODO: implement scroll wheel handling +} + void editor_mode::on_event_poll() { diff --git a/editormode.h b/editormode.h index ef856eb1..a801492c 100644 --- a/editormode.h +++ b/editormode.h @@ -42,7 +42,7 @@ public: void on_mouse_button( int const Button, int const Action, int const Mods ) override; void - on_scroll( double const Xoffset, double const Yoffset ) override { ; } + on_scroll( double const Xoffset, double const Yoffset ) override; void on_event_poll() override; diff --git a/editoruilayer.cpp b/editoruilayer.cpp index 342bd20e..b0e75e87 100644 --- a/editoruilayer.cpp +++ b/editoruilayer.cpp @@ -20,13 +20,6 @@ editor_ui::editor_ui() { push_back( &m_itempropertiespanel ); } -// potentially processes provided input key. returns: true if key was processed, false otherwise -bool -editor_ui::on_key( int const Key, int const Action ) { - - return false; -} - // updates state of UI elements void editor_ui::update() { diff --git a/editoruilayer.h b/editoruilayer.h index 95b06169..daa050ef 100644 --- a/editoruilayer.h +++ b/editoruilayer.h @@ -24,9 +24,6 @@ public: // constructors editor_ui(); // methods - // potentially processes provided input key. returns: true if the input was processed, false otherwise - bool - on_key( int const Key, int const Action ) override; // updates state of UI elements void update() override; diff --git a/editoruipanels.cpp b/editoruipanels.cpp index 0d1ded79..34f1eb30 100644 --- a/editoruipanels.cpp +++ b/editoruipanels.cpp @@ -17,10 +17,13 @@ http://mozilla.org/MPL/2.0/. #include "Event.h" #include "renderer.h" #include "utilities.h" +#include "scenenodegroups.h" void itemproperties_panel::update( scene::basic_node const *Node ) { + m_node = Node; + if( false == is_open ) { return; } text_lines.clear(); @@ -196,6 +199,26 @@ itemproperties_panel::render() { for( auto const &line : text_lines ) { ImGui::TextColored( ImVec4( line.color.r, line.color.g, line.color.b, line.color.a ), line.data.c_str() ); } + // group section + render_group(); } ImGui::End(); } + +bool +itemproperties_panel::render_group() { + + if( m_node == nullptr ) { return false; } + if( m_node->group() == null_handle ) { return false; } + + if( false == ImGui::CollapsingHeader( "Parent Group" ) ) { return false; } + + auto const &nodegroup { scene::Groups.group( m_node->group() ) }; + auto const &linecolor { Global.UITextColor }; + + ImGui::TextColored( ImVec4( linecolor.r, linecolor.g, linecolor.b, linecolor.a ), + ( "Nodes: " + to_string( static_cast( nodegroup.nodes.size() ) ) + + "\nEvents: " + to_string( static_cast( nodegroup.events.size() ) ) ).c_str() ); + + return true; +} diff --git a/editoruipanels.h b/editoruipanels.h index 3a18c4d8..5f4c325b 100644 --- a/editoruipanels.h +++ b/editoruipanels.h @@ -21,4 +21,11 @@ public: void update( scene::basic_node const *Node ); void render() override; + +private: +// methods + bool render_group(); + +// members + scene::basic_node const *m_node { nullptr }; // scene node bound to the panel }; diff --git a/uilayer.cpp b/uilayer.cpp index 0784c6ca..6ad6929f 100644 --- a/uilayer.cpp +++ b/uilayer.cpp @@ -137,21 +137,37 @@ ui_layer::shutdown() { } bool -ui_layer::on_key( int const Key, int const Action ) { +ui_layer::on_key( int const Key, int const Scancode, int const Action, int const Mods ) { - return false; + ImGui_ImplGlfw_KeyCallback( m_window, Key, Scancode, Action, Mods ); + if( m_imguiio->WantTextInput ) { return true; } + + return on_key_( Key, Scancode, Action, Mods ); } bool ui_layer::on_cursor_pos( double const Horizontal, double const Vertical ) { - return false; + return on_cursor_pos_( Horizontal, Vertical ); } bool -ui_layer::on_mouse_button( int const Button, int const Action ) { +ui_layer::on_mouse_button( int const Button, int const Action, int const Mods ) { - return false; + ImGui_ImplGlfw_MouseButtonCallback( m_window, Button, Action, Mods ); + if( m_imguiio->WantCaptureMouse ) { return true; } + + return on_mouse_button_( Button, Action, Mods ); +} + +// potentially processes provided mouse scroll event. returns: true if the input was processed, false otherwise +bool +ui_layer::on_scroll( double const Xoffset, double const Yoffset ) { + + ImGui_ImplGlfw_ScrollCallback( m_window, Xoffset, Yoffset ); + if( m_imguiio->WantCaptureMouse ) { return true; } + + return on_scroll_( Xoffset, Yoffset ); } void diff --git a/uilayer.h b/uilayer.h index 9d120827..ee524d0a 100644 --- a/uilayer.h +++ b/uilayer.h @@ -66,17 +66,17 @@ public: void shutdown(); // potentially processes provided input key. returns: true if the input was processed, false otherwise - virtual bool - on_key( int const Key, int const Action ); + on_key( int const Key, int const Scancode, int const Action, int const Mods ); // potentially processes provided mouse movement. returns: true if the input was processed, false otherwise - virtual bool on_cursor_pos( double const Horizontal, double const Vertical ); // potentially processes provided mouse button. returns: true if the input was processed, false otherwise - virtual bool - on_mouse_button( int const Button, int const Action ); + on_mouse_button( int const Button, int const Action, int const Mods ); + // potentially processes provided mouse scroll event. returns: true if the input was processed, false otherwise + bool + on_scroll( double const Xoffset, double const Yoffset ); // updates state of UI elements virtual void @@ -135,6 +135,20 @@ private: // draws a quad between coordinates x,y and z,w with uv-coordinates spanning 0-1 void quad( glm::vec4 const &Coordinates, glm::vec4 const &Color ); + // input methods subclass details + virtual + bool + on_key_( int const Key, int const Scancode, int const Action, int const Mods ) { return false; } + virtual + bool + on_cursor_pos_( double const Horizontal, double const Vertical ) { return false; } + virtual + bool + on_mouse_button_( int const Button, int const Action, int const Mods ) { return false; } + virtual + bool + on_scroll_( double const Xoffset, double const Yoffset ) { return false; } + // members static GLint m_textureunit;