1 /** 2 * Copyright: Copyright (C) 2018 Gabriel Gheorghe, All Rights Reserved 3 * Authors: $(Gabriel Gheorghe) 4 * License: $(LINK2 https://www.gnu.org/licenses/gpl-3.0.txt, GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007) 5 * Source: $(LINK2 https://github.com/GabyForceQ/LibertyEngine/blob/master/source/liberty/input/impl.d) 6 * Documentation: 7 * Coverage: 8 **/ 9 module liberty.input.impl; 10 11 import bindbc.glfw; 12 13 import liberty.core.platform; 14 import liberty.core.window; 15 import liberty.math.vector; 16 import liberty.input.keyboard.impl; 17 import liberty.input.mouse.impl; 18 import liberty.input.mouse.picker; 19 import liberty.input.joystick.impl; 20 import liberty.input.profiler.impl; 21 22 /** 23 * 24 **/ 25 final abstract class Input { 26 private { 27 static Keyboard keyboard; 28 static Mouse mouse; 29 static Joystick joystick; 30 static MousePicker mousePicker; 31 static InputProfiler[string] profilerMap; 32 } 33 34 /** 35 * Create the implicit mouse picker. 36 **/ 37 static void initialize() { 38 keyboard = new Keyboard(); 39 mouse = new Mouse(); 40 joystick = new Joystick(); 41 mousePicker = new MousePicker(); 42 } 43 44 /** 45 * Returns reference to keyboard. 46 **/ 47 static Keyboard getKeyboard() { 48 return keyboard; 49 } 50 51 /** 52 * Returns reference to mouse. 53 **/ 54 static Mouse getMouse() { 55 return mouse; 56 } 57 58 /** 59 * Returns reference to joystick. 60 **/ 61 static Joystick getJoystick() { 62 return joystick; 63 } 64 65 /** 66 * Returns reference to mouse picker. 67 **/ 68 static MousePicker getMousePicker() { 69 return mousePicker; 70 } 71 72 /** 73 * Returns mouse position in normalized device coordinates. 74 **/ 75 static Vector2F getNormalizedDeviceCoords(Vector2F mousePos = mouse.getPostion(), 76 Window window = Platform.getWindow()) 77 do { 78 return Vector2F( 79 (2.0f * mousePos.x) / window.getWidth() - 1.0f, 80 -((2.0f * mousePos.y) / window.getHeight() - 1.0f) 81 ); 82 } 83 84 /** 85 * 86 **/ 87 static InputProfiler createProfile(string id) { 88 profilerMap[id] = new InputProfiler(id); 89 return profilerMap[id]; 90 } 91 92 /** 93 * 94 **/ 95 static void removeProfile(string id) { 96 profilerMap[id].destroy(); 97 profilerMap[id] = null; 98 profilerMap.remove(id); 99 } 100 101 /** 102 * 103 **/ 104 static InputProfiler getProfile(string id) { 105 return profilerMap[id]; 106 } 107 108 package(liberty) static void update() { 109 keyboard.update(); 110 mouse.update(); 111 joystick.update(); 112 } 113 }