summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2023-04-24 03:58:04 -0400
committerrealtradam <[email protected]>2023-04-24 03:58:04 -0400
commit8f42815db1d3636c3fddc696b626c54ca7896d32 (patch)
treec8b691f85704abbe3becd21e6dac5efba17f4028
parent92b561030f7f713fc4e2893de05fdc7a06c8a139 (diff)
downloadRodeoKit-8f42815db1d3636c3fddc696b626c54ca7896d32.tar.gz
RodeoKit-8f42815db1d3636c3fddc696b626c54ca7896d32.zip
added unbounded ranges for the input system
-rw-r--r--include/rodeo/input.h8
-rw-r--r--include/rodeo/input_t.h27
-rw-r--r--src/input/rodeo_input.c75
3 files changed, 103 insertions, 7 deletions
diff --git a/include/rodeo/input.h b/include/rodeo/input.h
index 41a7849..8d3d775 100644
--- a/include/rodeo/input.h
+++ b/include/rodeo/input.h
@@ -48,7 +48,13 @@ rodeo_input_command_register_binary_mouseButton(
bool
rodeo_input_command_register_positional_mouse(
rodeo_input_command_t *input_command,
- rodeo_input_positional_mouse_t mouse_position
+ rodeo_input_positional_mouse_t mouse_axis
+);
+
+bool
+rodeo_input_command_register_unboundedRange_mouse(
+ rodeo_input_command_t *input_command,
+ rodeo_input_unboundedRange_mouse_t mouse_axis
);
// alternative proposed "general" registration methods
diff --git a/include/rodeo/input_t.h b/include/rodeo/input_t.h
index 6013eed..f717de3 100644
--- a/include/rodeo/input_t.h
+++ b/include/rodeo/input_t.h
@@ -766,6 +766,7 @@ rodeo_input_binary_mouseButton_t;
typedef
enum
{
+ rodeo_input_positional_mouse_Invalid = 0,
rodeo_input_positional_mouse_X = 1,
rodeo_input_positional_mouse_Y = 2
}
@@ -774,9 +775,19 @@ rodeo_input_positional_mouse_t;
typedef
enum
{
+ rodeo_input_unboundedRange_mouse_Invalid = 0,
+ rodeo_input_unboundedRange_mouse_X = 1,
+ rodeo_input_unboundedRange_mouse_Y = 2
+}
+rodeo_input_unboundedRange_mouse_t;
+
+typedef
+enum
+{
rodeo_input_type_Invalid = (1 << 0),
rodeo_input_type_Binary = (1 << 1),
rodeo_input_type_Positional = (1 << 2),
+ rodeo_input_type_UnboundedRange = (1 << 3),
}
rodeo_input_type_t ;
@@ -800,6 +811,8 @@ rodeo_input_binary_state_t;
typedef int64_t rodeo_input_positional_state_t;
+typedef float rodeo_input_unboundedRange_state_t;
+
typedef
struct
{
@@ -807,6 +820,7 @@ struct
{
rodeo_input_binary_state_t binary_state;
rodeo_input_positional_state_t positional_state;
+ rodeo_input_unboundedRange_state_t unbounded_range_state;
}
data;
rodeo_input_type_t input_type;
@@ -835,6 +849,10 @@ void
#define i_tag input_positional_mouse
#include <stc/cset.h>
+#define i_val rodeo_input_unboundedRange_mouse_t
+#define i_tag input_unboundedRange_mouse
+#include <stc/cset.h>
+
typedef
struct
{
@@ -850,11 +868,18 @@ struct
}
binary;
- // unbounded range
+ // positional
struct
{
cset_input_positional_mouse mouse_position;
}
+ positional;
+
+ // unbounded range
+ struct
+ {
+ cset_input_unboundedRange_mouse mouse_delta;
+ }
unbounded_range;
}
diff --git a/src/input/rodeo_input.c b/src/input/rodeo_input.c
index a6edfbb..426fda4 100644
--- a/src/input/rodeo_input.c
+++ b/src/input/rodeo_input.c
@@ -108,13 +108,23 @@ rodeo_input_events_poll(void)
{
rodeo_input_command_t *command = *j.ref;
const cset_input_positional_mouse_value *x_value = cset_input_positional_mouse_get(
- &command->unbounded_range.mouse_position,
+ &command->positional.mouse_position,
rodeo_input_positional_mouse_X
- );
+ );
const cset_input_positional_mouse_value *y_value = cset_input_positional_mouse_get(
- &command->unbounded_range.mouse_position,
+ &command->positional.mouse_position,
rodeo_input_positional_mouse_Y
- );
+ );
+ const cset_input_unboundedRange_mouse_value *rel_x_value =
+ cset_input_unboundedRange_mouse_get(
+ &command->unbounded_range.mouse_delta,
+ rodeo_input_unboundedRange_mouse_X
+ );
+ const cset_input_unboundedRange_mouse_value *rel_y_value =
+ cset_input_unboundedRange_mouse_get(
+ &command->unbounded_range.mouse_delta,
+ rodeo_input_unboundedRange_mouse_Y
+ );
if(x_value != NULL)
{
@@ -147,6 +157,37 @@ rodeo_input_events_poll(void)
(**k.ref)(input_state);
}
}
+ if(rel_x_value != NULL)
+ {
+ rodeo_input_any_state_t input_state = {
+ .data.unbounded_range_state = (float)event.motion.xrel,
+ .input_type = rodeo_input_type_UnboundedRange
+ };
+ c_foreach(
+ k,
+ cset_input_callback_functions,
+ command->callbacks
+ )
+ {
+ (**k.ref)(input_state);
+ }
+ }
+
+ if(rel_y_value != NULL)
+ {
+ rodeo_input_any_state_t input_state = {
+ .data.unbounded_range_state = (float)event.motion.yrel,
+ .input_type = rodeo_input_type_UnboundedRange
+ };
+ c_foreach(
+ k,
+ cset_input_callback_functions,
+ command->callbacks
+ )
+ {
+ (**k.ref)(input_state);
+ }
+ }
}
}
}
@@ -302,7 +343,31 @@ rodeo_input_command_register_positional_mouse(
else
{
cset_input_positional_mouse_insert(
- &input_command->unbounded_range.mouse_position,
+ &input_command->positional.mouse_position,
+ mouse_axis
+ );
+ return true;
+ }
+}
+
+bool
+rodeo_input_command_register_unboundedRange_mouse(
+ rodeo_input_command_t *input_command,
+ rodeo_input_unboundedRange_mouse_t mouse_axis
+)
+{
+ if((rodeo_input_type_UnboundedRange & input_command->valid_types) == 0)
+ {
+ rodeo_log(
+ rodeo_logLevel_error,
+ "Attempting to register input type which is invalid for this input command, failed to do so"
+ );
+ return false;
+ }
+ else
+ {
+ cset_input_unboundedRange_mouse_insert(
+ &input_command->unbounded_range.mouse_delta,
mouse_axis
);
return true;