~aleteoryx/muditaos

ref: 37c5c2fcc83cf7382610d8823a5f45e5066be83b muditaos/module-gui/gui/input/Profile.hpp -rw-r--r-- 1.4 KiB
37c5c2fc — Lucjan Bryndza [EGD-5153] Fix errors in generate image script 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "InputEvent.hpp"
#include <string>
#include <cstdint>
#include <vector>
#include <map>
namespace gui
{

    class KeyProfile
    {
      public:
        static const uint32_t none_key; /// defaults to 0
        uint32_t keyCode = none_key;
        bool cyclic      = false;
        std::vector<uint32_t> chars;
        std::vector<uint32_t> timeouts;

        virtual ~KeyProfile() = default;

        void addCharacters(const std::string &s);
        void addTimeouts(const std::string &s);
    };

    class Profile
    {
        std::string name;
        std::map<uint32_t, KeyProfile *> keys = {};

        void addCharacters(KeyProfile *pk, const std::string &s) const;
        void addTimeouts(KeyProfile *pk, const std::string &s) const;
        void addKeyProfile(KeyProfile *pk);
        void setName(const std::string &name);
        const KeyProfile *getKeyProfile(uint32_t keyCode) const;

      public:
        void clear();
        Profile() = default;
        Profile(const std::string &name);
        Profile(Profile &&p);
        virtual ~Profile();

        [[nodiscard]] std::string getName() const noexcept;
        bool load(const std::string &filename);

        uint32_t get(bsp::KeyCodes code, uint32_t times);
    };

} /* namespace gui */