Commit a55c87b8 authored by Matej Vašek's avatar Matej Vašek Committed by Marek Trtík
Browse files

feat(osi): Simple text input handling

parent 3d5ea3be
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ namespace osi

        protected:
        friend struct InputSystem;
        void virtual init() {};
        void virtual init(InputSystem* input_system) {};
        void virtual update(float delta_time) {};


+5 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
#include "devices/input_device_all.hpp"

// For reflection constructors
#include "input_text.hpp"
#include "bindings/input_binding_all.hpp"
#include "processors/input_processor_all.hpp"

@@ -37,6 +38,8 @@ namespace osi
        InputActionSet* default_action_set() const { return m_default_action_set; }
        std::vector<InputActionSet*> const& action_sets() const { return m_action_sets; }

        InputText* text_input() const { return m_input_text; }

        template <typename TValue> InputAction<TValue>* create_action(
            std::string const& name,
            const std::vector<InputBindingDescriptorBase<TValue>>& binding_descs,
@@ -116,6 +119,8 @@ namespace osi

        std::vector<InputHandler*> m_handlers = {};
        com::Folder* m_handlers_folder;

        InputText* m_input_text;
    };
}

+31 −0
Original line number Diff line number Diff line
#ifndef AGE_APP_TEMPLATE_INPUT_TEXT_HPP
#define AGE_APP_TEMPLATE_INPUT_TEXT_HPP
#include "input_event.hpp"
#include "com/context.hpp"

namespace osi
{
    struct InputText : com::Folder
    {
        InputText() : Folder("text_input")
        {
            m_on_input = push_back<InputEvent<const std::string&>>("on_input");
            m_started = push_back<InputEvent<>>("on_started");
            m_stopped = push_back<InputEvent<>>("on_stopped");
        }

        void start() const { m_started->invoke(); }
        void stop() const { m_stopped->invoke(); }
        InputEvent<const std::string&>& on_input() const { return *m_on_input; }
        InputEvent<>& on_started() const { return *m_started; }
        InputEvent<>& on_stopped() const { return *m_stopped; }


        private:
        InputEvent<const std::string&>* m_on_input;
        InputEvent<>* m_started;
        InputEvent<>* m_stopped;
    };
}

#endif //AGE_APP_TEMPLATE_INPUT_TEXT_HPP
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ namespace osi
        }
        ~SdlInputHandler() override = default;

        void init() override;
        void init(InputSystem* input_system) override;
        void update(float delta_time) override;

        static void handle_sdl_input_event(SDL_Event const& event);
@@ -104,6 +104,7 @@ namespace osi
            }
        }

        static void set_text_input(bool enabled);

        static Key sdl_scancode_to_key(SDL_Scancode scancode);
    };
+3 −1
Original line number Diff line number Diff line
@@ -32,11 +32,13 @@ namespace osi
            }
        );

        m_input_text = system_folder()->push_back<InputText>();

        m_handlers_folder = system_folder()->push_back<com::Folder>("handlers");
        m_handlers.push_back(m_handlers_folder->push_back<SdlInputHandler>("sdl_input_handler"));

        for (const auto handler : m_handlers)
            handler->init();
            handler->init(this);
    }

    InputActionSet* InputSystem::create_action_set(std::string const &name)
Loading