summaryrefslogtreecommitdiff
path: root/rotatingcube.cpp
blob: 224fc27d95846e313dbf00b3d6631fdc5edb3e31 (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
#include "rotatingcube.h"

bool ScreenRotatingCube::loadCubePlugin()
{
	CompDisplay* d = s->display;

	if (!checkPluginABI ("core", CORE_ABIVERSION))
		return false;

	if (!checkPluginABI ("cube", CUBE_ABIVERSION))
		return false;

	if (!getPluginDisplayIndex (d, "cube", &cubeDisplayPrivateIndex))
		return false;

	return cubeDisplayPrivateIndex >= 0;
}

bool ScreenRotatingCube::enable()
{
	if( !loadCubePlugin() )
		return false;
		
	CUBE_SCREEN(s);

	ss->zCamera = 0.0;
	ss->cubeRotX = 0.0;
	ss->cubeRotV = 0.0;
	cs->rotationState = RotationManual;
	WRAP( ss, cs, getRotation, screenSaverGetRotation );
	
	return ScreenEffect::enable();
}

void ScreenRotatingCube::disable()
{
	ss->zCameraFadeOut = ss->zCamera;
	ss->cubeRotXFadeOut = ss->cubeRotX;
	ss->cubeRotVFadeOut = ss->cubeRotV;
	
	ScreenEffect::disable();
}

void ScreenRotatingCube::clean()
{
	CUBE_SCREEN(s);
	cs->rotationState = RotationNone;
	UNWRAP (ss, cs, getRotation);
}

void ScreenRotatingCube::getRotation( float* x, float* v, float *progress )
{
	ScreenEffect::getRotation( x, v, progress );

	*x += ss->cubeRotX;
	*v += ss->cubeRotV;
}

void ScreenRotatingCube::preparePaintScreen( int msSinceLastPaint )
{
	
	ScreenEffect::preparePaintScreen( msSinceLastPaint );
	
	float rotX = screensaverGetCubeRotationSpeed(s->display)/100.0;
	float rotV = 0.0;
	
	SCREENSAVER_DISPLAY(s->display);
	
	if( sd->state.fadingIn )
	{
		rotX *= getProgress();
		ss->zCamera = -screensaverGetCubeZoom(s->display) * getProgress();
	}
	else if( sd->state.fadingOut )
	{
		ss->zCamera = ss->zCameraFadeOut * (1-getProgress());
		ss->cubeRotX = ss->cubeRotXFadeOut * (1-getProgress());
		ss->cubeRotV = ss->cubeRotVFadeOut * (1-getProgress());
	}
	
	if( !sd->state.fadingOut )
	{
		ss->cubeRotX += rotX * msSinceLastPaint;
		ss->cubeRotV += rotV * msSinceLastPaint;
	}
	if( ss->cubeRotX > 180.0 ) ss->cubeRotX -= 360.0;
	if( ss->cubeRotX < -180.0 ) ss->cubeRotX += 360.0;
}

void ScreenRotatingCube::donePaintScreen()
{
	damageScreen(s);
	ScreenEffect::donePaintScreen();
}

Bool ScreenRotatingCube::paintOutput(	const ScreenPaintAttrib *sAttrib, \
										const CompTransform* transform, Region region, \
										CompOutput* output, unsigned int mask)
{
	ScreenPaintAttrib sA = *sAttrib;
	sA.zCamera += ss->zCamera;
	
	mask &= ~PAINT_SCREEN_REGION_MASK;
	mask |= PAINT_SCREEN_TRANSFORMED_MASK;
	return ScreenEffect::paintOutput( &sA, transform, region, output, mask );
}