contextual interception of user input by imgui user interface implementation

This commit is contained in:
tmj-fstate
2018-11-15 23:02:21 +01:00
parent 45119e64bd
commit 97d60a9b0e
11 changed files with 101 additions and 38 deletions

View File

@@ -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 );
}

View File

@@ -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;
}

View File

@@ -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 };

View File

@@ -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() {

View File

@@ -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;

View File

@@ -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() {

View File

@@ -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;

View File

@@ -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<int>( nodegroup.nodes.size() ) )
+ "\nEvents: " + to_string( static_cast<int>( nodegroup.events.size() ) ) ).c_str() );
return true;
}

View File

@@ -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
};

View File

@@ -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

View File

@@ -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;