Key_InputNode.cpp
Go to the documentation of this file.
1 #include "Key_InputNode.hpp"
2 #include "../Defs.hpp"
3 
4 namespace iv
5 {
6 
8  InputNode( inst ),
9  InputEvent( inst ),
10  cm( inst, this, "Key_InputNode" ),
11  ibq( inst ),
12  _input_id(),
13  _fallthrough( false ),
14  _active( std::nullopt )
15 {
16  this->cm.inherits( this->InputNode::cm, this->InputEvent::cm );
17  this->cm.owns( this->ibq.cm );
18 
19  this->input_id( input );
20 }
21 
23 {
24 }
25 
27 {
28  static iv::TableId DebugTable = TableId::create( "Key_InputNode" );
29  auto row = view->Table( DebugTable ).Row( this );
30 
31  row.Column( "input_id", this->input_id() );
32  row.Column( "fallthrough_enabled", this->fallthrough_enabled() );
33  row.Column( "active", this->_active );
34 }
35 
37 {
38  this->_input_id = val;
39  this->input_treeRefresh();
40 }
41 
43 {
44  return this->_input_id;
45 }
46 
48 {
49  this->_fallthrough = val;
50  this->input_treeRefresh();
51 }
52 
54 {
55  return this->_fallthrough;
56 }
57 
59 {
60  if( !this->ibq.IsBound( this->_input_id, key ) )
61  return true;
62 
63  this->ie_trigger();
64 
65  return false;
66 }
67 
68 void Key_InputNode::input_process( InputRoot * root, Input::DeviceKey key, bool & press, bool & real, bool & offspace )
69 {
70  if( !this->ibq.IsBound( this->_input_id, key ) )
71  {
72  this->cm.log( SRC_INFO, Defs::Log::Input, "Refuse input (not bound)." );
73  return;
74  }
75 
76  if( press )
77  {
78  if( !this->_active.has_value() || this->_active.value() == key )
79  { // first key
80  this->cm.log( SRC_INFO, Defs::Log::Input, "Accept input (change input to fake release)." );
81 
82  this->_active = key;
83  this->ie_start_duration();
84  if( real )
85  this->ie_start_activation();
86 
87  //
88  press = false;
89  real = false;
90  }
91  else
92  { // other keys
93  if( !this->_fallthrough )
94  {
95  press = false;
96  real = false;
97 
98  this->cm.log( SRC_INFO, Defs::Log::Input, "Block input (change it to fake release because fallthrough is not enabled)." );
99  }
100  else
101  {
102  this->cm.log( SRC_INFO, Defs::Log::Input, "Fallthrough input." );
103  }
104  }
105  }
106  else
107  {
108  if( this->_active == key )
109  { // first key
110  this->cm.log( SRC_INFO, Defs::Log::Input, "Accept input (change release to fake)." );
111 
112  this->_active = std::nullopt;
113  this->ie_stop_duration();
114  this->ie_stop_activation( real );
115 
116  if( this->_fallthrough )
117  this->input_treeRefresh();
118 
119  real = false;
120  }
121  else
122  { // other keys
123  if( !this->_fallthrough )
124  {
125  this->cm.log( SRC_INFO, Defs::Log::Input, "Block input (change release to fake because fallthrough is not enabled)." );
126  real = false;
127  }
128  else
129  {
130  this->cm.log( SRC_INFO, Defs::Log::Input, "Fallthrough input." );
131  }
132  }
133  }
134 }
135 
137 {
138  this->cm.log( SRC_INFO, Defs::Log::Input, "Activation interrupted from outside code." );
139  this->_active = std::nullopt;
140  this->ie_stop_activation( false );
141  this->input_treeRefresh();
142 }
143 
144 }