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
|
// Copyright (c) 2013-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
using System.ComponentModel;
using Glfw;
namespace Crow
{
/// <summary>
/// generic class to build scrolling control in both directions
/// </summary>
[DesignIgnore]
public class ScrollingObject : Widget
{
#region CTOR
protected ScrollingObject () {}
public ScrollingObject (Interface iface, string style = null) : base (iface, style) { }
#endregion
int scrollX, scrollY, maxScrollX, maxScrollY, mouseWheelSpeed;
/// <summary>
/// if true, key stroke are handled in derrived class
/// </summary>
protected bool KeyEventsOverrides = false;
/// <summary> Horizontal Scrolling Position </summary>
[DefaultValue(0)]
public virtual int ScrollX {
get { return scrollX; }
set {
if (scrollX == value)
return;
int newS = value;
if (newS < 0)
newS = 0;
else if (newS > maxScrollX)
newS = maxScrollX;
if (newS == scrollX)
return;
scrollX = newS;
NotifyValueChangedAuto (scrollX);
RegisterForGraphicUpdate ();
}
}
/// <summary> Vertical Scrolling Position </summary>
[DefaultValue(0)]
public virtual int ScrollY {
get { return scrollY; }
set {
if (scrollY == value)
return;
int newS = value;
if (newS < 0)
newS = 0;
else if (newS > maxScrollY)
newS = maxScrollY;
if (newS == scrollY)
return;
scrollY = newS;
NotifyValueChangedAuto (scrollY);
RegisterForGraphicUpdate ();
}
}
/// <summary> Horizontal Scrolling maximum value </summary>
[DefaultValue(0)]
public virtual int MaxScrollX {
get { return maxScrollX; }
set {
if (maxScrollX == value)
return;
maxScrollX = Math.Max(0, value);
if (scrollX > maxScrollX)
ScrollX = maxScrollX;
NotifyValueChangedAuto (maxScrollX);
RegisterForGraphicUpdate ();
}
}
/// <summary> Vertical Scrolling maximum value </summary>
[DefaultValue(0)]
public virtual int MaxScrollY {
get { return maxScrollY; }
set {
if (maxScrollY == value)
return;
maxScrollY = Math.Max (0, value);
if (scrollY > maxScrollY)
ScrollY = maxScrollY;
NotifyValueChangedAuto (maxScrollY);
RegisterForGraphicUpdate ();
}
}
/// <summary> Mouse Wheel Scrolling multiplier </summary>
[DefaultValue(1)]
public virtual int MouseWheelSpeed {
get { return mouseWheelSpeed; }
set {
if (mouseWheelSpeed == value)
return;
mouseWheelSpeed = value;
NotifyValueChangedAuto (mouseWheelSpeed);
}
}
/// <summary> Process scrolling vertically, or if shift is down, vertically </summary>
public override void onMouseWheel (object sender, MouseWheelEventArgs e)
{
base.onMouseWheel (sender, e);
if (IFace.Shift)
ScrollX += e.Delta * MouseWheelSpeed;
else
ScrollY -= e.Delta * MouseWheelSpeed;
}
/// <summary> Process scrolling with arrow keys, home and end keys. </summary>
public override void onKeyDown (object sender, KeyEventArgs e)
{
base.onKeyDown (sender, e);
if (KeyEventsOverrides)
return;
switch (e.Key) {
case Key.Up:
ScrollY--;
break;
case Key.Down:
ScrollY++;
break;
case Key.Left:
ScrollX--;
break;
case Key.Right:
ScrollX++;
break;
case Key.Home:
ScrollX = 0;
ScrollY = 0;
break;
case Key.End:
ScrollX = MaxScrollX;
ScrollY = MaxScrollY;
break;
}
}
}
}
|