summaryrefslogtreecommitdiff
path: root/plugins/GLTest.cs
blob: d3bd29ead9865aad66cce075ac8dc6f1ab908ce7 (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
using System;
using System.Collections.Generic;
using Compiz;
using Tao.FreeGlut;
using Tao.OpenGl;
//using Tao.OpenGl.Glu;

public class MgltestPlugin : Plugin
{
	//not very clever or efficient, but ok for now
	protected Dictionary<IntPtr,Screen> screens = new Dictionary<IntPtr,Screen> ();
	protected Dictionary<IntPtr,Window> windowPtrs = new Dictionary<IntPtr,Window> ();
	protected List<Window> windows = new List<Window> ();

	public override bool InitScreen (IntPtr plugin, IntPtr screen)
	{
		Console.WriteLine ("initScreen");

		Screen s = new Screen (screen);
		screens[screen] = s;

		s.PreparePaint += OnPreparePaintScreen;
		s.Paint += OnPaintScreen;
		s.DonePaint += OnDonePaintScreen;

		return true;
	}

	public void OnPreparePaintScreen (PreparePaintScreenHandler inner, IntPtr s, int msSinceLastPaint)
	{
		Screen screen = screens[s];

		Console.Error.WriteLine ("PreparePaintScreen (managed) " + msSinceLastPaint);

		inner (s, msSinceLastPaint);
	}

	public bool OnPaintScreen (PaintScreenHandler inner, IntPtr s, ref ScreenPaintAttrib sa, IntPtr region, ScreenPaint mask)
	{
		Screen screen = screens[s];

		Console.Error.WriteLine ("PaintScreen (managed) " + " " +  s + " " + mask);

		Console.Error.WriteLine ("xRotate: " + sa.xRotate);
		Console.Error.WriteLine ("yRotate: " + sa.yRotate);
		Console.Error.WriteLine ("vRotate: " + sa.vRotate);

		bool ret = inner (s, ref sa, region, mask);

		Gl.glPushMatrix();
		Gl.glRotatef (sa.vRotate, sa.vRotate, 0, 0);
		Glu.gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
		Glut.glutSolidTorus(0.275, 0.85, 8, 15);
		Gl.glPopMatrix();

		return ret;
	}

	public void OnDonePaintScreen (DonePaintScreenHandler inner, IntPtr s)
	{
		Screen screen = screens[s];

		Console.Error.WriteLine ("DonePaintScreen (managed)");

		inner (s);
	}

	public override bool InitWindow (IntPtr plugin, IntPtr window)
	{
		Console.WriteLine ("initWindow");

		Window w = new Window (window);
		windowPtrs[window] = w;
		windows.Add (w);

		return true;
	}

	public override void FiniWindow (IntPtr plugin, IntPtr window)
	{
		Console.WriteLine ("finiWindow");

		windows.Remove (windowPtrs[window]);
		windowPtrs.Remove (window);
	}
}