Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.41 KB | None | 0 0
  1. // i_game_controller.hpp
  2. /*
  3.   neogfx C++ GUI Library
  4.   Copyright (c) 2020 Leigh Johnston.  All Rights Reserved.
  5.  
  6.   This program is free software: you can redistribute it and / or modify
  7.   it under the terms of the GNU General Public License as published by
  8.   the Free Software Foundation, either version 3 of the License, or
  9.   (at your option) any later version.
  10.  
  11.   This program is distributed in the hope that it will be useful,
  12.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.   GNU General Public License for more details.
  15.  
  16.   You should have received a copy of the GNU General Public License
  17.   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. */
  19.  
  20. #pragma once
  21.  
  22. #include <neogfx/neogfx.hpp>
  23. #include <neogfx/core/event.hpp>
  24. #include <neogfx/core/numerical.hpp>
  25. #include <neogfx/hid/i_keyboard.hpp>
  26.  
  27. namespace neogfx
  28. {
  29.     typedef uint32_t game_controller_port;
  30.  
  31.     enum class game_controller_button : uint64_t
  32.     {
  33.         None                = 0x0000000000000000,
  34.         A                   = 0x0000000000000001,
  35.         B                   = 0x0000000000000002,
  36.         X                   = 0x0000000000000004,
  37.         Y                   = 0x0000000000000008,
  38.         C                   = X,
  39.         D                   = Y,
  40.         Square              = A,
  41.         Cross               = B,
  42.         Circle              = X,
  43.         Triangle            = Y,
  44.         Red                 = A,
  45.         Yellow              = B,
  46.         Blue                = X,
  47.         Green               = Y,
  48.         LeftShoulder        = 0x0000000000000010,
  49.         RightShoulder       = 0x0000000000000020,
  50.         LeftTrigger         = 0x0000000000000040,
  51.         RightTrigger        = 0x0000000000000080,
  52.         DirectionalPadUp    = 0x0000000000000100,
  53.         DirectionalPadDown  = 0x0000000000000200,
  54.         DirectionalPadLeft  = 0x0000000000000400,
  55.         DirectionalPadRight = 0x0000000000000800,
  56.         LeftThumb           = 0x0000000000001000,
  57.         LeftThumbUp         = 0x0000000000002000,
  58.         LeftThumbDown       = 0x0000000000004000,
  59.         LeftThumbLeft       = 0x0000000000008000,
  60.         LeftThumbRight      = 0x0000000000010000,
  61.         LeftThumbUpLeft     = 0x0000000000020000,
  62.         LeftThumbUpRight    = 0x0000000000040000,
  63.         LeftThumbDownLeft   = 0x0000000000080000,
  64.         LeftThumbDownRight  = 0x0000000000100000,
  65.         RightThumb          = 0x0000000000200000,
  66.         RightThumbUp        = 0x0000000000400000,
  67.         RightThumbDown      = 0x0000000000800000,
  68.         RightThumbLeft      = 0x0000000001000000,
  69.         RightThumbRight     = 0x0000000002000000,
  70.         RightThumbUpLeft    = 0x0000000004000000,
  71.         RightThumbUpRight   = 0x0000000008000000,
  72.         RightThumbDownLeft  = 0x0000000010000000,
  73.         RightThumbDownRight = 0x0000000020000000,
  74.         Start               = 0x0000000040000000,
  75.         Back                = 0x0000000080000000,
  76.         Function1           = 0x0000000100000000,
  77.         Function2           = 0x0000000200000000,
  78.         Function3           = 0x0000000400000000,
  79.         Function4           = 0x0000000800000000,
  80.         Function5           = 0x0000001000000000,
  81.         Function6           = 0x0000002000000000,
  82.         Function7           = 0x0000004000000000,
  83.         Function8           = 0x0000008000000000,
  84.         Function9           = 0x0000010000000000,
  85.         Function10          = 0x0000020000000000,
  86.         Function11          = 0x0000040000000000,
  87.         Function12          = 0x0000080000000000,
  88.         Function13          = 0x0000100000000000,
  89.         Function14          = 0x0000200000000000,
  90.         Function15          = 0x0000400000000000,
  91.         Function16          = 0x0000800000000000,
  92.         Function17          = 0x0001000000000000,
  93.         Function18          = 0x0002000000000000,
  94.         Function19          = 0x0004000000000000,
  95.         Function20          = 0x0008000000000000,
  96.         Function21          = 0x0010000000000000,
  97.         Function22          = 0x0020000000000000,
  98.         Function23          = 0x0040000000000000,
  99.         Function24          = 0x0080000000000000,
  100.         Function25          = 0x0100000000000000,
  101.         Function26          = 0x0200000000000000,
  102.         Function27          = 0x0400000000000000,
  103.         Function28          = 0x0800000000000000,
  104.         Function29          = 0x1000000000000000,
  105.         Function30          = 0x2000000000000000,
  106.         Function31          = 0x4000000000000000,
  107.         Function32          = 0x8000000000000000
  108.     };
  109.  
  110.     typedef uint32_t game_controller_button_index;
  111.  
  112.     class i_game_controller
  113.     {
  114.     public:
  115.         declare_event(button_pressed, game_controller_button, key_modifiers_e)
  116.         declare_event(button_released, game_controller_button, key_modifiers_e)
  117.         declare_event(button_repeat, game_controller_button, key_modifiers_e)
  118.         declare_event(left_thumb_moved, const vec2&, key_modifiers_e)
  119.         declare_event(right_thumb_moved, const vec2&, key_modifiers_e)
  120.         declare_event(stick_moved, const vec3&, key_modifiers_e)
  121.         declare_event(stick_rotated, const vec3&, key_modifiers_e)
  122.         declare_event(slider_moved, const vec2&, key_modifiers_e)
  123.     public:
  124.         virtual ~i_game_controller() = default;
  125.     public:
  126.         virtual const i_string& name() const = 0;
  127.         virtual game_controller_port port() const = 0;
  128.         virtual bool enabled() const = 0;
  129.         virtual void enable() = 0;
  130.         virtual void disable() = 0;
  131.     public:
  132.         virtual bool is_button_pressed(game_controller_button_index aButtonIndex) const = 0;
  133.         virtual bool is_button_pressed(game_controller_button aButton) const = 0;
  134.         virtual double left_trigger_position() const = 0;
  135.         virtual double right_trigger_position() const = 0;
  136.         virtual const vec2& left_thumb_position() const = 0;
  137.         virtual const vec2& right_thumb_position() const = 0;
  138.         virtual const vec3& stick_position() const = 0;
  139.         virtual const vec3& stick_rotation() const = 0;
  140.         virtual const vec2& slider_position() const = 0;
  141.     public:
  142.         virtual game_controller_button_index button_to_button_index(game_controller_button aButton) const = 0;
  143.         virtual game_controller_button button_index_to_button(game_controller_button_index aButtonIndex) const = 0;
  144.     };
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement