summaryrefslogtreecommitdiff
path: root/plugins/Zoom.cs
blob: 4ab767532990e3fb0a49b42e62e16d86475378d5 (plain)
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
/* Copyright 2006 Alp Toker <alp@atoker.com> */

using System;
using Compiz;
//using Tao.FreeGlut;
//using Tao.OpenGl;

/*
public class ZoomEffect
{
}
*/

public class ZoomScreen
{
	const float SensitivityFactor = 0.001f;

	[Option ("Pointer Invert Y")]
		public bool invertY = false;

	//Warning:
	//sensitivity factor breaks consistency between interface and implementation
	//Use a property?
	[Option ("Pointer Sensitivity")]
		public float sensitivity = 1.0f * SensitivityFactor;

	//TODO: maybe do key bindings as methods?
	//[Option ("Zoom In")]
	//public Binding zoomIn;

	[Option ("Zoom Speed")]
		public float speed = 1.5f;

	[Option ("Zoom Timestep")]
		public float timestep = 1.2f;

	[Option ("Filter Linear")]
		public bool filterLinear = false;

	int grabIndex;

	//begin GL floats
	float currentZoom = 1.0f;
	float newZoom = 1.0f;

	float xVelocity = 0.0f;
	float yVelocity = 0.0f;
	float zVelocity = 0.0f;

	float xTranslate = 0.0f;
	float yTranslate = 0.0f;

	float xtrans;
	float ytrans;
	float ztrans;
	//end GL floats

	//XPoint savedPointer;
	bool grabbed = false;

	float maxTranslate = 0.0f;

	//TODO: fabs() etc. misported
	bool AdjustVelocity ()
	{
		float d, adjust, amount;

		d = (newZoom - currentZoom) * 75.0f;

		adjust = d * 0.002f;
		amount = Math.Abs (d);
		if (amount < 1.0f)
			amount = 1.0f;
		else if (amount > 5.0f)
			amount = 5.0f;

		zVelocity = (amount * zVelocity + adjust) / (amount + 1.0f);

		return (Math.Abs (d) < 0.1f && Math.Abs (zVelocity) < 0.005f);
	}

	void PreparePaint (int msSinceLastPaint)
	{
		int   steps;
		float amount, chunk;

		amount = msSinceLastPaint * 0.05f * speed;
		steps = (int) (amount / (0.5f * timestep));
		if (steps == 0)
			steps = 1;
		chunk = amount / (float) steps;

		//for (; steps != 0 ; steps--)
		while (steps-- != 0)
		{
			xVelocity /= 1.25f;
			yVelocity /= 1.25f;

			if (AdjustVelocity ())
			{
				currentZoom = newZoom;
				zVelocity = 0.0f;
			}
			else
			{
				currentZoom += (zVelocity * msSinceLastPaint) / 1;//s->redrawTime;
			}

		}

	}

	void DonePaint ()
	{
		if (currentZoom != newZoom || xVelocity != 0 || yVelocity != 0 || zVelocity != 0)
			//screen.Damage ();
			Console.WriteLine ("damage");
	}

	void Paint (ScreenPaintAttrib sa, ScreenPaint mask)
	{
		sa.xTranslate += xtrans;
		sa.yTranslate += ytrans;

		sa.zCamera = -ztrans;

		/* hack to get sides rendered correctly */
		if (xtrans > 0.0f)
			sa.xRotate += 0.000001f;
		else
			sa.xRotate -= 0.000001f;

		mask &= ScreenPaint.Region;
		mask |= ScreenPaint.Transformed;

		//base.Paint (ref sa, mask);
	}

	void ZoomIn (int x, int y)
	{
	}

	void ZoomOut ()
	{
	}

	void ZoomTerminate ()
	{
		if (false) {
			newZoom = 1.0f;
			grabbed = false;

			//screen.Damage ();
		}
	}
}