-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathControls.cs
187 lines (160 loc) · 5.02 KB
/
Controls.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using System;
using System.Drawing;
using System.Windows.Forms;
/*
Normal key mapping
==================
Open file dialog: O
Toggle fullscreen: F
Quit: Escape, Enter
Next Pic: PageDown, Space, Down, Right, LeftMouseButton, MouseWheelDown
Prev Pic: PageUp, Up, Left, RightMouseButton, MouseWheelUp
First Pic: Home
Last Pic: End
Zoom in: +
Zoom out: -
Key remapping while in zoom mode
=================================
Zoom in: MouseWheelUp
Zoom out: MouseWheelDown
Move image section: Up, Down, Left, Right, LeftMouseButton+Drag
*/
namespace PictureViewer
{
public partial class Form1 : Form
{
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.PageDown || e.KeyData == Keys.Space)
{
ShowNextPic();
}
else if (e.KeyData == Keys.PageUp)
{
ShowPrevPic();
}
else if (e.KeyData == Keys.Home)
{
ShowFirstPic();
}
else if (e.KeyData == Keys.End)
{
ShowLastPic();
}
else if (e.KeyData == Keys.F)
{
ToggleFullscreen();
}
else if (e.KeyData == Keys.Add)
{
ZoomIn();
}
else if (e.KeyData == Keys.Subtract)
{
ZoomOut();
}
if (e.KeyData == Keys.Down)
{
if (zoomfactor > 1.01)
{
zoompos_y++;
pictureBox1.Location = new Point(pictureBox1.Left, (int)(pictureBox1.Top - 1.0 * zoomfactor));
}
else ShowNextPic();
}
else if (e.KeyData == Keys.Up)
{
if (zoomfactor > 1.01)
{
zoompos_y--;
pictureBox1.Location = new Point(pictureBox1.Left, (int)(pictureBox1.Top + 1.0 * zoomfactor));
}
else ShowPrevPic();
}
if (e.KeyData == Keys.Left)
{
if (zoomfactor > 1.01)
{
zoompos_x--;
pictureBox1.Location = new Point((int)(pictureBox1.Left + 1.0 * zoomfactor), pictureBox1.Top);
}
else ShowPrevPic();
}
else if (e.KeyData == Keys.Right)
{
if (zoomfactor > 1.01)
{
zoompos_x++;
pictureBox1.Location = new Point((int)(pictureBox1.Left - 1.0 * zoomfactor), pictureBox1.Top);
}
else ShowNextPic();
}
else if (e.KeyData == Keys.Escape || e.KeyData == Keys.Enter)
{
Application.Exit();
}
// Open
else if (e.KeyData == Keys.O)
{
OpenDialog();
}
}
private void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
{
// Mousewheel down
if (e.Delta < 0)
{
if (zoomfactor > 1.01) ZoomOut();
else ShowNextPic();
}
// Mousewheel up
else
{
if (zoomfactor > 1.01) ZoomIn();
else ShowPrevPic();
}
}
private void pictureBox1_MouseHover(object sender, EventArgs e)
{
// Cheat to make mousewheel working
pictureBox1.Focus();
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (zoomfactor > 1.01)
{
Mousepos = e.Location;
Mousedown = true;
}
else ShowNextPic();
}
else if (e.Button == MouseButtons.Right)
{
ShowPrevPic();
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (Mousedown)
{
int dx = e.X - Mousepos.X;
int dy = e.Y - Mousepos.Y;
pictureBox1.Location = new Point(pictureBox1.Left + dx, pictureBox1.Top + dy);
if (zoomfactor > 1.01)
{
zoompos_x += (int)(dx / zoomfactor);
zoompos_y += (int)(dy / zoomfactor);
}
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Mousedown = false;
}
}
}
}