summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Mikos <metastability@opencompositing.org>2008-01-12 11:12:32 +1030
committerDavid Mikos <metastability@opencompositing.org>2008-01-12 11:12:32 +1030
commitefd6804ea24aef32bb9f983eb54b3a3ec0c4c307 (patch)
treec7b844247dae425480459779db01f37e2f10929f
parentc8986593fc2b1af3ba507aa2d1d462b0f5cfa992 (diff)
downloadrubik-efd6804ea24aef32bb9f983eb54b3a3ec0c4c307.tar.gz
rubik-efd6804ea24aef32bb9f983eb54b3a3ec0c4c307.tar.bz2
Windows contents on all viewports rotate with Rubik's cube.
-rw-r--r--rubik.c92
-rw-r--r--rubik.xml.in5
-rw-r--r--util.c218
3 files changed, 201 insertions, 114 deletions
diff --git a/rubik.c b/rubik.c
index 2f0ade6..81b52ff 100644
--- a/rubik.c
+++ b/rubik.c
@@ -287,33 +287,64 @@ static void rubikPaintInside (CompScreen *s,
if (rs->initiated && rubikGetRotateDesktop(s)) {
Bool coloredSides = rubikGetColoredSides(s);
- int winCounter = 0;
+ int winCounter = 0, screenCounter = 0;
+
CompWindow *w;
+ //CompScreen *screen;
+
+ int screenX = s->x;
+
+ int viewport;
int numWindows=1;
+
if (!coloredSides) {
- for (w = s->windows; w; w = w->next) {
+ moveScreenViewport (s, screenX, 0, FALSE);
+
+ for (viewport = 0; viewport<4; viewport++) {
+ moveScreenViewport (s, -1, 0, FALSE);
+
+ int tempNumWindows = 0;
+ if (!coloredSides) {
+ for (w = s->windows; w; w = w->next) {
if (w->destroyed) continue;
if (w->hidden) continue;
if (w->invisible) continue;
- if (!w->desktop && !rubikGetPaintWindowContents(s)) continue;
-
- numWindows++;
+ //if (!w->desktop && !rubikGetPaintWindowContents(s)) continue;
+
+ tempNumWindows++;
+ }
}
+ if (tempNumWindows > numWindows) numWindows = tempNumWindows;
+ }
}
+
+ //if (!coloredSides)
+ // moveScreenViewport (s, screenX, 0, FALSE);
+
+ for (viewport = 0; viewport<4; viewport++) {
+ if (screenCounter>0 && coloredSides)
+ break;
+
+ if (screenCounter>0 && !coloredSides)
+ moveScreenViewport (s, -1, 0, FALSE);
+
+ screenCounter++;
+ winCounter = 0;
+
for (w = s->windows; w; w = w->next) {
if (!coloredSides) {
if (w->destroyed) continue;
if (w->hidden) continue;
if (w->invisible) continue;
- if (!w->desktop && !rubikGetPaintWindowContents(s)) continue;
+ //if (!w->desktop && !rubikGetPaintWindowContents(s)) continue;
enableTexture (s, w->texture,
COMP_TEXTURE_FILTER_GOOD);
- glEnable (w->texture->target);
+ //glEnable (w->texture->target);
}
else {
if (winCounter>0)
@@ -366,10 +397,18 @@ static void rubikPaintInside (CompScreen *s,
glColor4fv (rs->faces[square->side].color);
else if (!rubikGetDesktopCaps(s) && square->side>=4)
continue;
- else if (!w->desktop) {
- float winX = WIN_REAL_X(w) + WIN_REAL_W(w)/2.0+w->screen->x*w->screen->width;
- float screenW = w->screen->width;
- if (((int) (winX/screenW))!=square->side)
+ else {
+ //float winX = WIN_REAL_X(w) + WIN_REAL_W(w)/2.0+((screen->x+screenCounter-1)%hSize)*w->screen->width;
+ //float screenW = w->screen->width;
+
+ //printf ("%i, %i\n", ((int) (winX/screenW)), w->screen->x);
+ //if (((int) (winX/screenW))!=square->side)
+
+ if (windowOnAllViewports (w) && rubikGetDesktopCaps(s) && square->side>=4) {
+ if (viewport!=screenX)
+ continue;
+ }
+ else if (viewport != square->side)
continue;
}
@@ -456,6 +495,7 @@ static void rubikPaintInside (CompScreen *s,
if (i==3)
glRotatef (face->side[index]*90, 0, 1, 0);
*/
+ //glTranslatef (0,0,0.5-0.00005*(numWindows+1-winCounter)); //allow for layers
glTranslatef (0,0,0.5-0.00005*(numWindows+1-winCounter)); //allow for layers
@@ -511,21 +551,33 @@ static void rubikPaintInside (CompScreen *s,
if (wh1<wh2 && wv1<wv2) {
- h1 -= y;
- h2 = (h2-y)/height;
wh1-= y;
wh2-= y;
-
-
+
+ h1 = wh1/height;
+ h2 = wh2/height;
wh1+=((float) hs-square->y )/((float) hStrips);
wh2+=((float) hs-square->y )/((float) hStrips);
- v1 -= x;
- v2 = (v2-x)/width;
+ //h2 = (h2-y)/height;
+ //h2 += y;
+
+
+
+
+
+ //v1 = x;
+ //v2 = (v2-x)/width;
+ //v2 -= x/width;
+
+ v1 = (wv1-x)/width;
+ v2 = (wv2-x)/width;
+
wv1+= x;
wv2+= x;
+
wv1+=((float) vs-square->x )/((float) vStrips);
wv2+=((float) vs-square->x )/((float) vStrips);
@@ -559,6 +611,7 @@ static void rubikPaintInside (CompScreen *s,
}
else {
if (i>=4) continue;
+ if (!w->desktop) continue;
for (vs=0; vs<vStrips; vs++) {
@@ -619,7 +672,10 @@ static void rubikPaintInside (CompScreen *s,
if (!coloredSides) {
disableTexture (s, w->texture);
}
- }
+ }
+ }
+ if (!coloredSides)
+ moveScreenViewport (s, -screenX-1, 0, FALSE);
}
glPopMatrix();
diff --git a/rubik.xml.in b/rubik.xml.in
index b871d60..98cba1b 100644
--- a/rubik.xml.in
+++ b/rubik.xml.in
@@ -54,11 +54,6 @@
<long>Rotate desktop as well as windows.</long>
<default>true</default>
</option>
- <option name="paint_window_contents" type="bool">
- <short>Paint window contents</short>
- <long>Display the windows when initiated (without frames).</long>
- <default>false</default>
- </option>
<option name="colored_sides" type="bool">
<short>Colored Sides</short>
<long>Replace wallpaper with colored sides.</long>
diff --git a/util.c b/util.c
index 72d906f..025a912 100644
--- a/util.c
+++ b/util.c
@@ -4,109 +4,145 @@
#include <math.h>
#include <float.h>
-
-
-float randf (float x) { //return random number in range [0,x)
- return rand()/(((double)RAND_MAX + 1) / x);
+float
+randf(float x)
+{ //return random number in range [0,x)
+ return rand()/(((double)RAND_MAX + 1) / x);
}
-float minimum (float x, float y) {
- return ((x) < (y) ? (x) : (y));
+float
+minimum(float x, float y)
+{
+ return ((x) < (y) ? (x) : (y));
}
-float maximum (float x, float y) {
- return ((x) > (y) ? (x) : (y));
+float
+maximum(float x, float y)
+{
+ return ((x) > (y) ? (x) : (y));
}
-float symmDistr() { //returns number in range [-1, 1] with bias towards 0, symmetric about 0.
- float x = 2*randf(1)-1;
- return x*(1-cbrt(1-fabsf(x)));
+float
+symmDistr()
+{ //returns number in range [-1, 1] with bias towards 0, symmetric about 0.
+ float x = 2*randf(1)-1;
+ return x*(1-cbrt(1-fabsf(x)));
}
-void setColor(float* color, float r, float g, float b, float a, float randomOffset, float randomness) {
- float ro = randf(randomOffset);
- color[0]=r+ro+randf(randomness);
- color[1]=g+ro+randf(randomness);
- color[2]=b+ro+randf(randomness);
- color[3]=a;
-
- int i;
- for (i=0; i<4; i++) {
- if (color[i]<0) color[i]=0;
- else if (color[i]>1) color[i]=1;
- }
+void
+setColor(float* color, float r, float g, float b, float a,
+ float randomOffset, float randomness)
+{
+ int i;
+ float ro = randf(randomOffset);
+
+ color[0]=r+ro+randf(randomness);
+ color[1]=g+ro+randf(randomness);
+ color[2]=b+ro+randf(randomness);
+ color[3]=a;
+
+ for (i=0; i<4; i++)
+ {
+ if (color[i]<0)
+ color[i]=0;
+ else if (color[i]>1)
+ color[i]=1;
+ }
}
-void setSpecifiedColor (float* color, int c) {
- switch (c) {
- case RANDOMCOLOR: setColor(color, 0,0,0,1,0,1); break;
- case BLACK: setColor(color, 0,0,0,1,0,0); break;
- case BLUE: setColor(color, 0,0,1,1,0,0); break;
- case BROWN: setColor(color, 0.5,0.25,0.05,1,0,0); break;
- case CYAN: setColor(color, 0,1,1,1,0,0); break;
- case GREEN: setColor(color, 0,1,0,1,0,0); break;
- case GREY: setColor(color, 0.5,0.5,0.5,1,0,0); break;
- case ORANGE: setColor(color, 1,0.5,0,1,0,0); break;
- case PINK: setColor(color, 1,0,1,1,0,0); break;
- case PURPLE: setColor(color, 0.5,0,1,1,0,0); break;
- case RED: setColor(color, 1,0,0,1,0,0); break;
- case YELLOW: setColor(color, 1,1,0,1,0,0); break;
- case WHITE: setColor(color, 1,1,1,1,0,0); break;
- }
+void
+setSpecifiedColor(float* color, int c)
+{
+ switch (c)
+ {
+ case RANDOMCOLOR:
+ setColor(color, 0, 0, 0, 1, 0, 1);
+ break;
+ case BLACK:
+ setColor(color, 0, 0, 0, 1, 0, 0);
+ break;
+ case BLUE:
+ setColor(color, 0, 0, 1, 1, 0, 0);
+ break;
+ case BROWN:
+ setColor(color, 0.5, 0.25, 0.05, 1, 0, 0);
+ break;
+ case CYAN:
+ setColor(color, 0, 1, 1, 1, 0, 0);
+ break;
+ case GREEN:
+ setColor(color, 0, 1, 0, 1, 0, 0);
+ break;
+ case GREY:
+ setColor(color, 0.5, 0.5, 0.5, 1, 0, 0);
+ break;
+ case ORANGE:
+ setColor(color, 1, 0.5, 0, 1, 0, 0);
+ break;
+ case PINK:
+ setColor(color, 1, 0, 1, 1, 0, 0);
+ break;
+ case PURPLE:
+ setColor(color, 0.5, 0, 1, 1, 0, 0);
+ break;
+ case RED:
+ setColor(color, 1, 0, 0, 1, 0, 0);
+ break;
+ case YELLOW:
+ setColor(color, 1, 1, 0, 1, 0, 0);
+ break;
+ case WHITE:
+ setColor(color, 1, 1, 1, 1, 0, 0);
+ break;
+ }
}
-void rotateClockwise (squareRec * square) {
+void
+rotateClockwise(squareRec * square)
+{
- int m,j,k;
-
- for (m=0; m<hStrips/2; m++) {
- for (j=0; j<hStrips-1-2*m; j++) {
- int pos1 = (vStrips-1-j-m);
- int pos2 = j+m;
- squareRec tempSquare2 = square[pos2*hStrips+m];
- square[pos2*hStrips+m] = square[m*hStrips+pos1];
- square[m*hStrips+pos1] = square[pos1*hStrips+(vStrips-1-m)];
- square[pos1*hStrips+(vStrips-1-m)] = square[(vStrips-1-m)*hStrips+pos2];
- square[(vStrips-1-m)*hStrips+pos2] = tempSquare2;
- }
- }
-
- for (k=0; k<vStrips; k++) {
- for (j=0; j<hStrips; j++) {
- square[j*hStrips+k].psi = (square[j*hStrips+k].psi+1)%4;
- }
+ int m, j, k;
+
+ for (m=0; m<hStrips/2; m++)
+ {
+ for (j=0; j<hStrips-1-2*m; j++)
+ {
+ int pos1 = (vStrips-1-j-m);
+ int pos2 = j+m;
+ squareRec tempSquare2 = square[pos2*hStrips+m];
+ square[pos2*hStrips+m] = square[m*hStrips+pos1];
+ square[m*hStrips+pos1] = square[pos1*hStrips+(vStrips-1-m)];
+ square[pos1*hStrips+(vStrips-1-m)] = square[(vStrips-1-m)*hStrips+pos2];
+ square[(vStrips-1-m)*hStrips+pos2] = tempSquare2;
}
-
-/*
- int m;
- for (m=0; m<hStrips/2; m++) {
- for (j=0; j<hStrips-1-2*m; j++) {
- int pos1 = (vStrips-1-j-m);
- int pos2 = j+m;
- squareRec tempSquare2 = (rs->faces[4].square[pos2*hStrips+m]);
- rs->faces[4].square[pos2*hStrips+m] = rs->faces[4].square[m*hStrips+pos1];
- rs->faces[4].square[m*hStrips+pos1] = rs->faces[4].square[pos1*hStrips+(vStrips-1-m)];
- rs->faces[4].square[pos1*hStrips+(vStrips-1-m)] = rs->faces[4].square[(vStrips-1-m)*hStrips+pos2];
- rs->faces[4].square[(vStrips-1-m)*hStrips+pos2] = tempSquare2;
- }
+ }
+
+ for (k=0; k<vStrips; k++)
+ {
+ for (j=0; j<hStrips; j++)
+ {
+ square[j*hStrips+k].psi = (square[j*hStrips+k].psi+1)%4;
}
-*/
-
+ }
}
-void rotateAnticlockwise (squareRec * square) {
+void rotateAnticlockwise(squareRec * square)
+{
+ int m, j, k;
- int m,j,k;
-
- for (m=0; m<hStrips/2; m++) {
- for (j=0; j<hStrips-1-2*m; j++) {
- int pos1 = (vStrips-1-j-m);
- int pos2 = j+m;
- squareRec tempSquare2 = square[pos2*hStrips+m];
- square[pos2*hStrips+m] = square[(vStrips-1-m)*hStrips+pos2];
- square[(vStrips-1-m)*hStrips+pos2] = square[pos1*hStrips+(vStrips-1-m)];
- square[pos1*hStrips+(vStrips-1-m)] = square[m*hStrips+pos1];
- square[m*hStrips+pos1] = tempSquare2;
- }
+ for (m=0; m<hStrips/2; m++)
+ {
+ for (j=0; j<hStrips-1-2*m; j++)
+ {
+ int pos1 = (vStrips-1-j-m);
+ int pos2 = j+m;
+ squareRec tempSquare2 = square[pos2*hStrips+m];
+ square[pos2*hStrips+m] = square[(vStrips-1-m)*hStrips+pos2];
+ square[(vStrips-1-m)*hStrips+pos2] = square[pos1*hStrips+(vStrips-1-m)];
+ square[pos1*hStrips+(vStrips-1-m)] = square[m*hStrips+pos1];
+ square[m*hStrips+pos1] = tempSquare2;
}
-
- for (k=0; k<vStrips; k++) {
- for (j=0; j<hStrips; j++) {
- square[j*hStrips+k].psi = (square[j*hStrips+k].psi+4-1)%4;
- }
+ }
+
+ for (k=0; k<vStrips; k++)
+ {
+ for (j=0; j<hStrips; j++)
+ {
+ square[j*hStrips+k].psi = (square[j*hStrips+k].psi+4-1)%4;
}
+ }
}