public static void UnsubscribeMouseClick(MouseEventFunc method) { mouseEvents.RemoveAt(mouseEvents.IndexOfValue(method)); }
internal static void Update() //TODO rewrite { bool[] nowButtons = GetMouseButtons(); // [0]-left [1]-right [2]-middle [3]-4th mouse button [4]-5th mouse button..... if (mouseLeftButton) { MouseLeftButtonClick = false; } else if (nowButtons[0]) { MouseLeftButtonClick = true; } if (mouseRightButton) { MouseRightButtonClick = false; } else if (nowButtons[1]) { MouseRightButtonClick = true; } if (mouseMiddleButton) { MouseMiddleButtonClick = false; } else if (nowButtons[2]) { MouseMiddleButtonClick = true; } mouseLeftButton = nowButtons[0]; mouseRightButton = nowButtons[1]; mouseMiddleButton = nowButtons[2]; for (short i = 0; i < MouseButtons.Length; ++i) { int mouse = Glfw.GetMouseButton(Engine.MainWindow.GlfwWindow, i); if (mouse == Glfw.PRESS) { if (MouseButtons[i] != KeyState.Pressed) { foreach (KeyValuePair <int, MouseEventFunc> pair in mouseEvents) { if (pair.Value != null && pair.Value.Invoke(GetMousePosition(), i, KeyState.Pressed)) { clickReceiver = pair.Value; break; } } } MouseButtons[i] = KeyState.Pressed; } else if (mouse == Glfw.RELEASE) { if (MouseButtons[i] == KeyState.Pressed) { foreach (KeyValuePair <int, MouseEventFunc> pair in mouseEvents) { Vector2 mousePos = GetMousePosition(); if (pair.Value != null && pair.Value.Invoke(mousePos, i, KeyState.Released)) { if (clickReceiver != null && clickReceiver == pair.Value) { clickReceiver(mousePos, i, KeyState.Clicked); } } } clickReceiver = null; MouseButtons[i] = KeyState.Clicked; } else if (MouseButtons[i] == KeyState.Clicked) { MouseButtons[i] = KeyState.Released; } } } for (short i = 0; i < Keys.Length; ++i) { int key = Glfw.GetKey(Engine.MainWindow.GlfwWindow, i); if (key == Glfw.PRESS) { Keys[i] = KeyState.Pressed; } else if (key == Glfw.RELEASE) { if (Keys[i] == KeyState.Pressed) { Keys[i] = KeyState.Clicked; } else if (Keys[i] == KeyState.Clicked) { Keys[i] = KeyState.Released; } } } UpdateActions(); }
public static void SubscribeMouseClick(MouseEventFunc method, int priority) { mouseEvents.Add(priority, method); }