Add Music fluctuations project and Chinese plan docs
This commit is contained in:
3
MVS/Music fluctuations/source/myinput/CMakeLists.txt
Normal file
3
MVS/Music fluctuations/source/myinput/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
file(GLOB_RECURSE INPUT ./ *.cpp)
|
||||
|
||||
add_library(myinput ${INPUT} )
|
||||
65
MVS/Music fluctuations/source/myinput/DKey.h
Normal file
65
MVS/Music fluctuations/source/myinput/DKey.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
enum class dKey
|
||||
{
|
||||
KEY_UNKNOWN = -1,
|
||||
KEY_SPACE = 32,
|
||||
KEY_0 = 48,
|
||||
KEY_1 = 49,
|
||||
KEY_2 = 50,
|
||||
KEY_3 = 51,
|
||||
KEY_4 = 52,
|
||||
KEY_5 = 53,
|
||||
KEY_6 = 54,
|
||||
KEY_7 = 55,
|
||||
KEY_8 = 56,
|
||||
KEY_9 = 57,
|
||||
KEY_SEMICOLON = 59,
|
||||
KEY_EQUAL = 61,
|
||||
KEY_A = 65,
|
||||
KEY_B = 66,
|
||||
KEY_C = 67,
|
||||
KEY_D = 68,
|
||||
KEY_E = 69,
|
||||
KEY_F = 70,
|
||||
KEY_G = 71,
|
||||
KEY_H = 72,
|
||||
KEY_I = 73,
|
||||
KEY_J = 74,
|
||||
KEY_K = 75,
|
||||
KEY_L = 76,
|
||||
KEY_M = 77,
|
||||
KEY_N = 78,
|
||||
KEY_O = 79,
|
||||
KEY_P = 80,
|
||||
KEY_Q = 81,
|
||||
KEY_R = 82,
|
||||
KEY_S = 83,
|
||||
KEY_T = 84,
|
||||
KEY_U = 85,
|
||||
KEY_V = 86,
|
||||
KEY_W = 87,
|
||||
KEY_X = 88,
|
||||
KEY_Y = 89,
|
||||
KEY_Z = 90,
|
||||
KEY_ESCAPE = 27,
|
||||
KEY_TAB = 9,
|
||||
KEY_BACKSPACE = 8,
|
||||
KEY_DELETE = 46,
|
||||
KEY_RIGHT = 39,
|
||||
KEY_LEFT = 37,
|
||||
KEY_DOWN = 40,
|
||||
KEY_UP = 38,
|
||||
KEY_KP_0 = 96,
|
||||
KEY_KP_1 = 97,
|
||||
KEY_KP_2 = 98,
|
||||
KEY_KP_3 = 99,
|
||||
KEY_KP_4 = 100,
|
||||
KEY_KP_5 = 101,
|
||||
KEY_KP_6 = 102,
|
||||
KEY_KP_7 = 103,
|
||||
KEY_KP_8 = 104,
|
||||
KEY_KP_9 = 105,
|
||||
KEY_ENTER = 13,
|
||||
KEY_SHIFT = 16,
|
||||
KEY_CONTROL = 17,
|
||||
};
|
||||
40
MVS/Music fluctuations/source/myinput/Input.h
Normal file
40
MVS/Music fluctuations/source/myinput/Input.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
#include<Windows.h>
|
||||
#include"../event/Event.h"
|
||||
#include"DKey.h"
|
||||
#include<iostream>
|
||||
class Input
|
||||
{
|
||||
public:
|
||||
Input();
|
||||
~Input();
|
||||
void HandelInput(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
void HandelMouseInput(int p_x, int p_y);
|
||||
bool IsKeyDown(dKey p_key);
|
||||
void ClearEvents();
|
||||
//这个方法有BUG,用不了
|
||||
std::pair<int, int>GetMousePosition() { return m_mousePosition; };
|
||||
private:
|
||||
void OnKeyDown(int p_key);
|
||||
void OnKeyUp(int p_key);
|
||||
void OnMouseButtonDown(int p_mouseButton);
|
||||
void OnMouseButtonUp(int p_mouseButton);
|
||||
void OnMouseMove(int p_x, int p_y);
|
||||
|
||||
public:
|
||||
Event<int> KeyDown;
|
||||
Event<int> KeyUp;
|
||||
Event<int> MouseButtonDown;
|
||||
Event<int> MouseButtonUp;
|
||||
Event<int, int> MouseMoving;//传position
|
||||
Event<int, int> MouseMove;//传delta position
|
||||
|
||||
private:
|
||||
std::vector<dKey> downKeys;
|
||||
std::pair<int, int> m_mousePosition;
|
||||
ListenerID keyDownID;
|
||||
ListenerID keyUpID;
|
||||
ListenerID mouseButtonDownID;
|
||||
ListenerID mouseButtonUpID;
|
||||
ListenerID mouseMovingID;
|
||||
};
|
||||
75
MVS/Music fluctuations/source/myinput/input.cpp
Normal file
75
MVS/Music fluctuations/source/myinput/input.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include"Input.h"
|
||||
#include<iostream>
|
||||
|
||||
|
||||
Input::Input()
|
||||
{
|
||||
keyDownID = KeyDown.AddListener(std::bind(&Input::OnKeyDown, this, std::placeholders::_1));
|
||||
keyUpID = KeyUp.AddListener(std::bind(&Input::OnKeyUp, this, std::placeholders::_1));
|
||||
mouseButtonDownID = MouseButtonDown.AddListener(std::bind(&Input::OnMouseButtonDown, this, std::placeholders::_1));
|
||||
mouseButtonUpID = MouseButtonUp.AddListener(std::bind(&Input::OnMouseButtonUp, this, std::placeholders::_1));
|
||||
mouseMovingID = MouseMoving.AddListener(std::bind(&Input::OnMouseMove, this, std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
Input::~Input()
|
||||
{
|
||||
KeyDown.RemoveListener(keyDownID);
|
||||
KeyUp.RemoveListener(keyUpID);
|
||||
MouseButtonDown.RemoveListener(mouseButtonDownID);
|
||||
MouseButtonUp.RemoveListener(mouseButtonUpID);
|
||||
}
|
||||
|
||||
void Input::HandelInput(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
case WM_KEYUP:
|
||||
KeyUp.Invoke(wParam);
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
KeyDown.Invoke(wParam);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Input::HandelMouseInput(int p_x, int p_y)
|
||||
{
|
||||
MouseMove.Invoke(p_x - m_mousePosition.first, p_y - m_mousePosition.second);
|
||||
MouseMoving.Invoke(p_x, p_y);
|
||||
}
|
||||
|
||||
void Input::OnKeyDown(int p_key)
|
||||
{
|
||||
downKeys.push_back((dKey)p_key);
|
||||
if (p_key == (int)dKey::KEY_SPACE) { ClearEvents(); }
|
||||
}
|
||||
|
||||
void Input::OnKeyUp(int p_key)
|
||||
{
|
||||
downKeys.erase(std::remove(downKeys.begin(), downKeys.end(), (dKey)p_key), downKeys.end());
|
||||
}
|
||||
|
||||
void Input::OnMouseButtonDown(int p_mouseButton)
|
||||
{
|
||||
//downKeys.push_back((dKey)p_mouseButton);
|
||||
}
|
||||
|
||||
void Input::OnMouseButtonUp(int p_mouseButton)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Input::OnMouseMove(int p_x, int p_y)
|
||||
{
|
||||
m_mousePosition = std::make_pair(p_x, p_y);
|
||||
}
|
||||
|
||||
bool Input::IsKeyDown(dKey p_key)
|
||||
{
|
||||
return std::find(downKeys.begin(), downKeys.end(), p_key) != downKeys.end();
|
||||
}
|
||||
|
||||
void Input::ClearEvents()
|
||||
{
|
||||
downKeys.clear();
|
||||
}
|
||||
Reference in New Issue
Block a user