mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 00:09:18 +02:00
contextual interception of user input by imgui user interface implementation
This commit is contained in:
@@ -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;
|
Global.altState = ( Mods & GLFW_MOD_ALT ) ? true : false;
|
||||||
|
|
||||||
// give the ui first shot at the input processing...
|
// 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 the input is left untouched, pass it on
|
||||||
if( true == m_input.keyboard.key( Key, Action ) ) { return; }
|
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 ) {
|
driver_mode::on_mouse_button( int const Button, int const Action, int const Mods ) {
|
||||||
|
|
||||||
// give the ui first shot at the input processing...
|
// 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
|
// give the potential event recipient a shot at it, in the virtual z order
|
||||||
m_input.mouse.button( Button, Action );
|
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
|
void
|
||||||
driver_mode::on_scroll( double const Xoffset, double const Yoffset ) {
|
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 );
|
m_input.mouse.scroll( Xoffset, Yoffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,9 +40,7 @@ driver_ui::driver_ui() {
|
|||||||
|
|
||||||
// potentially processes provided input key. returns: true if key was processed, false otherwise
|
// potentially processes provided input key. returns: true if key was processed, false otherwise
|
||||||
bool
|
bool
|
||||||
driver_ui::on_key( int const Key, int const Action ) {
|
driver_ui::on_key_( int const Key, int const Scancode, int const Action, int const Mods ) {
|
||||||
// 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:
|
|
||||||
|
|
||||||
if( Key == GLFW_KEY_ESCAPE ) {
|
if( Key == GLFW_KEY_ESCAPE ) {
|
||||||
// toggle pause
|
// 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
|
// potentially processes provided mouse movement. returns: true if the input was processed, false otherwise
|
||||||
bool
|
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
|
// intercept mouse movement when the pause window is on
|
||||||
return m_paused;
|
return m_paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
// potentially processes provided mouse button. returns: true if the input was processed, false otherwise
|
// potentially processes provided mouse button. returns: true if the input was processed, false otherwise
|
||||||
bool
|
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
|
// intercept mouse movement when the pause window is on
|
||||||
return m_paused;
|
return m_paused;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,15 +18,6 @@ public:
|
|||||||
// constructors
|
// constructors
|
||||||
driver_ui();
|
driver_ui();
|
||||||
// methods
|
// 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
|
// updates state of UI elements
|
||||||
void
|
void
|
||||||
update() override;
|
update() override;
|
||||||
@@ -39,6 +30,15 @@ private:
|
|||||||
// render() subclass details
|
// render() subclass details
|
||||||
void
|
void
|
||||||
render_() override;
|
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
|
// members
|
||||||
drivingaid_panel m_aidpanel { "Driving Aid", true };
|
drivingaid_panel m_aidpanel { "Driving Aid", true };
|
||||||
timetable_panel m_timetablepanel { "Timetable", false };
|
timetable_panel m_timetablepanel { "Timetable", false };
|
||||||
|
|||||||
@@ -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;
|
Global.altState = ( Mods & GLFW_MOD_ALT ) ? true : false;
|
||||||
|
|
||||||
// give the ui first shot at the input processing...
|
// 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 the input is left untouched, pass it on
|
||||||
if( true == m_input.keyboard.key( Key, Action ) ) { return; }
|
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
|
void
|
||||||
editor_mode::on_mouse_button( int const Button, int const Action, int const Mods ) {
|
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( Button == GLFW_MOUSE_BUTTON_LEFT ) {
|
||||||
|
|
||||||
if( Action == GLFW_PRESS ) {
|
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 );
|
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
|
void
|
||||||
editor_mode::on_event_poll() {
|
editor_mode::on_event_poll() {
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public:
|
|||||||
void
|
void
|
||||||
on_mouse_button( int const Button, int const Action, int const Mods ) override;
|
on_mouse_button( int const Button, int const Action, int const Mods ) override;
|
||||||
void
|
void
|
||||||
on_scroll( double const Xoffset, double const Yoffset ) override { ; }
|
on_scroll( double const Xoffset, double const Yoffset ) override;
|
||||||
void
|
void
|
||||||
on_event_poll() override;
|
on_event_poll() override;
|
||||||
|
|
||||||
|
|||||||
@@ -20,13 +20,6 @@ editor_ui::editor_ui() {
|
|||||||
push_back( &m_itempropertiespanel );
|
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
|
// updates state of UI elements
|
||||||
void
|
void
|
||||||
editor_ui::update() {
|
editor_ui::update() {
|
||||||
|
|||||||
@@ -24,9 +24,6 @@ public:
|
|||||||
// constructors
|
// constructors
|
||||||
editor_ui();
|
editor_ui();
|
||||||
// methods
|
// 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
|
// updates state of UI elements
|
||||||
void
|
void
|
||||||
update() override;
|
update() override;
|
||||||
|
|||||||
@@ -17,10 +17,13 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
#include "scenenodegroups.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
itemproperties_panel::update( scene::basic_node const *Node ) {
|
itemproperties_panel::update( scene::basic_node const *Node ) {
|
||||||
|
|
||||||
|
m_node = Node;
|
||||||
|
|
||||||
if( false == is_open ) { return; }
|
if( false == is_open ) { return; }
|
||||||
|
|
||||||
text_lines.clear();
|
text_lines.clear();
|
||||||
@@ -196,6 +199,26 @@ itemproperties_panel::render() {
|
|||||||
for( auto const &line : text_lines ) {
|
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() );
|
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();
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,4 +21,11 @@ public:
|
|||||||
|
|
||||||
void update( scene::basic_node const *Node );
|
void update( scene::basic_node const *Node );
|
||||||
void render() override;
|
void render() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// methods
|
||||||
|
bool render_group();
|
||||||
|
|
||||||
|
// members
|
||||||
|
scene::basic_node const *m_node { nullptr }; // scene node bound to the panel
|
||||||
};
|
};
|
||||||
|
|||||||
26
uilayer.cpp
26
uilayer.cpp
@@ -137,21 +137,37 @@ ui_layer::shutdown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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
|
bool
|
||||||
ui_layer::on_cursor_pos( double const Horizontal, double const Vertical ) {
|
ui_layer::on_cursor_pos( double const Horizontal, double const Vertical ) {
|
||||||
|
|
||||||
return false;
|
return on_cursor_pos_( Horizontal, Vertical );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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
|
void
|
||||||
|
|||||||
24
uilayer.h
24
uilayer.h
@@ -66,17 +66,17 @@ public:
|
|||||||
void
|
void
|
||||||
shutdown();
|
shutdown();
|
||||||
// potentially processes provided input key. returns: true if the input was processed, false otherwise
|
// potentially processes provided input key. returns: true if the input was processed, false otherwise
|
||||||
virtual
|
|
||||||
bool
|
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
|
// potentially processes provided mouse movement. returns: true if the input was processed, false otherwise
|
||||||
virtual
|
|
||||||
bool
|
bool
|
||||||
on_cursor_pos( double const Horizontal, double const Vertical );
|
on_cursor_pos( double const Horizontal, double const Vertical );
|
||||||
// potentially processes provided mouse button. returns: true if the input was processed, false otherwise
|
// potentially processes provided mouse button. returns: true if the input was processed, false otherwise
|
||||||
virtual
|
|
||||||
bool
|
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
|
// updates state of UI elements
|
||||||
virtual
|
virtual
|
||||||
void
|
void
|
||||||
@@ -135,6 +135,20 @@ private:
|
|||||||
// draws a quad between coordinates x,y and z,w with uv-coordinates spanning 0-1
|
// draws a quad between coordinates x,y and z,w with uv-coordinates spanning 0-1
|
||||||
void
|
void
|
||||||
quad( glm::vec4 const &Coordinates, glm::vec4 const &Color );
|
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
|
// members
|
||||||
static GLint m_textureunit;
|
static GLint m_textureunit;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user