<commit_before>// Copyright (C) 2016 <NAME>
// This file is part of the Ouzel engine.

#include <cstring>
#include "Input.h"
#include "core/Engine.h"
#include "events/EventDispatcher.h"
#include "scene/Scene.h"
#include "scene/Node.h"
#include "utils/Utils.h"

namespace ouzel
{
    namespace input
    {
        Input::Input()
        {
            memset(keyboardKeyStates, 0, sizeof(keyboardKeyStates));
            memset(mouseButtonStates, 0, sizeof(mouseButtonStates));
        }

        Input::~Input()
        {

        }

        void Input::update()
        {

        }

        void Input::setCursorVisible(bool visible)
        {
            OUZEL_UNUSED(visible);
        }

        bool Input::isCursorVisible() const
        {
            return false;
        }

        void Input::startGamepadDiscovery()
        {

        }

        void Input::stopGamepadDiscovery()
        {

        }

        void Input::keyDown(KeyboardKey key, uint32_t modifiers)
        {
            Event event;
            event.sender = shared_from_this();

            event.keyboardEvent.key = key;
            event.keyboardEvent.modifiers = modifiers;

            if (!keyboardKeyStates[static_cast<uint32_t>(key)])
            {
                keyboardKeyStates[static_cast<uint32_t>(key)] = true;

                event.type = Event::Type::KEY_DOWN;
                sharedEngine->getEventDispatcher()->dispatchEvent(event);
            }
            else
            {
                event.type = Event::Type::KEY_REPEAT;
                sharedEngine->getEventDispatcher()->dispatchEvent(event);
            }
        }

        void Input::keyUp(KeyboardKey key, uint32_t modifiers)
        {
            keyboardKeyStates[static_cast<uint32_t>(key)] = false;

            Event event;
            event.sender = shared_from_this();
            event.type = Event::Type::KEY_UP;

            event.keyboardEvent.key = key;
            event.keyboardEvent.modifiers = modifiers;

            sharedEngine->getEventDispatcher()->dispatchEvent(event);
        }

        void Input::mouseDown(MouseButton button, const Vector2& position, uint32_t modifiers)
        {
            mouseButtonStates[static_cast<uint32_t>(button)] = true;

            Event event;
            event.sender = shared_from_this();
            event.type = Event::Type::MOUSE_DOWN;

            event.mouseEvent.button = button;
            event.mouseEvent.position = position;
            event.mouseEvent.modifiers = modifiers;

            sharedEngine->getEventDispatcher()->dispatchEvent(event);

            if (scene::ScenePtr scene = sharedEngine->getSceneManager()->getScene())
            {
                scene::NodePtr node = scene->pickNode(position);
                pointerDownOnNode(0, node, position);
            }
        }

        void Input::mouseUp(MouseButton button, const Vector2& position, uint32_t modifiers)
        {
            mouseButtonStates[static_cast<uint32_t>(button)] = false;

            Event event;
            event.sender = shared_from_this();
            event.type = Event::Type::MOUSE_UP;

            event.mouseEvent.button = button;
            event.mouseEvent.position = position;
            event.mouseEvent.modifiers = modifiers;

            sharedEngine->getEventDispatcher()->dispatchEvent(event);

            if (scene::ScenePtr scene = sharedEngine->getSceneManager()->getScene())
            {
                scene::NodePtr node = scene->pickNode(position);
                pointerUpOnNode(0, node, position);
            }
        }

        void Input::mouseMove(const Vector2& position, uint32_t modifiers)
        {
            cursorPosition = position;

            Event event;
            event.sender = shared_from_this();
            event.type = Event::Type::MOUSE_MOVE;

            event.mouseEvent.position = position;
            event.mouseEvent.modifiers = modifiers;

            sharedEngine->getEventDispatcher()->dispatchEvent(event);

            if (scene::ScenePtr scene = sharedEngine->getSceneManager()->getScene())
            {
                scene::NodePtr node = scene->pickNode(position);
                pointerEnterNode(0, node, position);
            }

            if (scene::NodePtr pointerDownOnNode = getPointerDownOnNode(0))
            {
                pointerDragNode(0, pointerDownOnNode, position);
            }
        }

        void Input::mouseRelativeMove(const Vector2& relativePosition, uint32_t modifiers)
        {
            Vector2 newPosition = cursorPosition + relativePosition;

            if (newPosition.x < -1.0f) newPosition.x = -1.0f;
            if (newPosition.x > 1.0f) newPosition.x = 1.0f;
            if (newPosition.y < -1.0f) newPosition.y = -1.0f;
            if (newPosition.y > 1.0f) newPosition.y = 1.0f;

            mouseMove(newPosition, modifiers);
        }

        void Input::mouseScroll(const Vector2& scroll, const Vector2& position, uint32_t modifiers)
        {
            Event event;
            event.sender = shared_from_this();
            event.type = Event::Type::MOUSE_SCROLL;

            event.mouseEvent.position = position;
            event.mouseEvent.scroll = scroll;
            event.mouseEvent.modifiers = modifiers;

            sharedEngine->getEventDispatcher()->dispatchEvent(event);
        }

        void Input::touchBegin(uint64_t touchId, const Vector2& position)
        {
            Event event;
            event.sender = shared_from_this();
            event.type = Event::Type::TOUCH_BEGIN;

            event.touchEvent.touchId = touchId;
            event.touchEvent.position = position;

            sharedEngine->getEventDispatcher()->dispatchEvent(event);

            if (scene::ScenePtr scene = sharedEngine->getSceneManager()->getScene())
            {
                scene::NodePtr node = scene->pickNode(position);<commit_msg>Use clamp for mouse position limiting<commit_after>// Copyright (C) 2016 <NAME>
// This file is part of the Ouzel engine.

#include <cstring>
#include "Input.h"
#include "core/Engine.h"
#include "events/EventDispatcher.h"
#include "scene/Scene.h"
#include "scene/Node.h"
#include "utils/Utils.h"
#include "math/MathUtils.h"

namespace ouzel
{
    namespace input
    {
        Input::Input()
        {
            memset(keyboardKeyStates, 0, sizeof(keyboardKeyStates));
            memset(mouseButtonStates, 0, sizeof(mouseButtonStates));
        }

        Input::~Input()
        {

        }

        void Input::update()
        {

        }

        void Input::setCursorVisible(bool visible)
        {
            OUZEL_UNUSED(visible);
        }

        bool Input::isCursorVisible() const
        {
            return false;
        }

        void Input::startGamepadDiscovery()
        {

        }

        void Input::stopGamepadDiscovery()
        {

        }

        void Input::keyDown(KeyboardKey key, uint32_t modifiers)
        {
            Event event;
            event.sender = shared_from_this();

            event.keyboardEvent.key = key;
            event.keyboardEvent.modifiers = modifiers;

            if (!keyboardKeyStates[static_cast<uint32_t>(key)])
            {
                keyboardKeyStates[static_cast<uint32_t>(key)] = true;

                event.type = Event::Type::KEY_DOWN;
                sharedEngine->getEventDispatcher()->dispatchEvent(event);
            }
            else
            {
                event.type = Event::Type::KEY_REPEAT;
                sharedEngine->getEventDispatcher()->dispatchEvent(event);
            }
        }

        void Input::keyUp(KeyboardKey key, uint32_t modifiers)
        {
            keyboardKeyStates[static_cast<uint32_t>(key)] = false;

            Event event;
            event.sender = shared_from_this();
            event.type = Event::Type::KEY_UP;

            event.keyboardEvent.key = key;
            event.keyboardEvent.modifiers = modifiers;

            sharedEngine->getEventDispatcher()->dispatchEvent(event);
        }

        void Input::mouseDown(MouseButton button, const Vector2& position, uint32_t modifiers)
        {
            mouseButtonStates[static_cast<uint32_t>(button)] = true;

            Event event;
            event.sender = shared_from_this();
            event.type = Event::Type::MOUSE_DOWN;

            event.mouseEvent.button = button;
            event.mouseEvent.position = position;
            event.mouseEvent.modifiers = modifiers;

            sharedEngine->getEventDispatcher()->dispatchEvent(event);

            if (scene::ScenePtr scene = sharedEngine->getSceneManager()->getScene())
            {
                scene::NodePtr node = scene->pickNode(position);
                pointerDownOnNode(0, node, position);
            }
        }

        void Input::mouseUp(MouseButton button, const Vector2& position, uint32_t modifiers)
        {
            mouseButtonStates[static_cast<uint32_t>(button)] = false;

            Event event;
            event.sender = shared_from_this();
            event.type = Event::Type::MOUSE_UP;

            event.mouseEvent.button = button;
            event.mouseEvent.position = position;
            event.mouseEvent.modifiers = modifiers;

            sharedEngine->getEventDispatcher()->dispatchEvent(event);

            if (scene::ScenePtr scene = sharedEngine->getSceneManager()->getScene())
            {
                scene::NodePtr node = scene->pickNode(position);
                pointerUpOnNode(0, node, position);
            }
        }

        void Input::mouseMove(const Vector2& position, uint32_t modifiers)
        {
            cursorPosition = position;

            Event event;
            event.sender = shared_from_this();
            event.type = Event::Type::MOUSE_MOVE;

            event.mouseEvent.position = position;
            event.mouseEvent.modifiers = modifiers;

            sharedEngine->getEventDispatcher()->dispatchEvent(event);

            if (scene::ScenePtr scene = sharedEngine->getSceneManager()->getScene())
            {
                scene::NodePtr node = scene->pickNode(position);
                pointerEnterNode(0, node, position);
            }

            if (scene::NodePtr pointerDownOnNode = getPointerDownOnNode(0))
            {
                pointerDragNode(0, pointerDownOnNode, position);
            }
        }

        void Input::mouseRelativeMove(const Vector2& relativePosition, uint32_t modifiers)
        {
            Vector2 newPosition = cursorPosition + relativePosition;

            newPosition.x = clamp(newPosition.x, -1.0f, 1.0f);
            newPosition.y = clamp(newPosition.y, -1.0f, 1.0f);

            mouseMove(newPosition, modifiers);
        }

        void Input::mouseScroll(const Vector2& scroll, const Vector2& position, uint32_t modifiers)
        {
            Event event;
            event.sender = shared_from_this();
            event.type = Event::Type::MOUSE_SCROLL;

            event.mouseEvent.position = position;
            event.mouseEvent.scroll = scroll;
            event.mouseEvent.modifiers = modifiers;

            sharedEngine->getEventDispatcher()->dispatchEvent(event);
        }

        void Input::touchBegin(uint64_t touchId, const Vector2& position)
        {
            Event event;
            event.sender = shared_from_this();
            event.type = Event::Type::TOUCH_BEGIN;

            event.touchEvent.touchId = touchId;
            event.touchEvent.position = position;

            sharedEngine->getEventDispatcher()->dispatchEvent(event);

            if (scene::ScenePtr scene = sharedEngine->getSceneManager()->getScene())
            {
                scene::NodePtr node = scene->pickNode(position);
{'fraction_non_alphanumeric': 0.1049634540200578, 'fraction_numerical': 0.009688934217236104, 'mean_word_length': 1.932951146560319, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5409758', 'n_tokens_mistral': 3226, 'n_tokens_neox': 3066, 'n_words': 546}