-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMouseControl.cs
65 lines (51 loc) · 1.58 KB
/
MouseControl.cs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Diagnostics;
using System.Collections.Generic;
//using System.Linq;
using OpenTK;
using OpenTK.Input;
using Poincare.Geometry;
namespace Poincare.Application {
public class MouseControl {
bool isDragging;
bool isDraggingAngle;
Complex mousePos, initialMousePos;
public PoincareWindow PoincareWindow { get; private set; }
public MouseControl(PoincareWindow poincareWindow) {
PoincareWindow = poincareWindow;
PoincareWindow.Mouse.ButtonDown += Mouse_ButtonDown;
PoincareWindow.Mouse.ButtonUp += Mouse_ButtonUp;
}
private void Mouse_ButtonDown(object sender, MouseButtonEventArgs ea) {
isDragging = true;
mousePos = MousePos;
if (mousePos.ModulusSquared > 0.98)
isDraggingAngle = true;
initialMousePos = mousePos;
}
private void Mouse_ButtonUp(object sender, MouseButtonEventArgs ea) {
isDragging = false;
isDraggingAngle = false;
}
public void Sample() {
if (isDragging) {
mousePos = MousePos;
if (isDraggingAngle)
PoincareWindow.AngleOffset = MousePos.Argument - initialMousePos.Argument;
else {
if (mousePos.ModulusSquared > 0.98)
mousePos = Complex.CreatePolar(0.98, mousePos.Argument);
PoincareWindow.Offset = mousePos - initialMousePos;
}
}
initialMousePos = mousePos;
}
public Complex MousePos {
get {
int width = PoincareWindow.Width;
int height = PoincareWindow.Height;
return 2 * new Complex(PoincareWindow.Mouse.X, width - PoincareWindow.Mouse.Y) / width - Complex.I * (width - height) / width - new Complex(1, 1);
}
}
}
}