diff options
-rw-r--r-- | serenity.c | 91 | ||||
-rw-r--r-- | serenity.options | 2 |
2 files changed, 77 insertions, 16 deletions
@@ -79,11 +79,13 @@ typedef struct _SerenityScreen PreparePaintScreenProc preparePaintScreen; PaintScreenProc paintScreen; - SerenityTexture *currentTex; // What we're drawing right now. - int object_x; //Top-left corner of the current position of our image - int object_y; // + SerenityTexture *currentTex; // What we're drawing right now. + int object_x; // + int object_y; // Current position of our image + int object_z; // unsigned int numTextures; + unsigned int numActiveTextures; SerenityTexture *textures; } SerenityScreen; @@ -103,6 +105,7 @@ static void serenityCreateList(SerenityTexture *tex); static void serenityDoTextures(SerenityScreen *ss); // Assigns SerenityScreen->currentTex to a random SerenityScreen->textures. Only selects between loaded textures static Bool serenitySelectRandomTexture(SerenityScreen *ss); + // Reloads all textures for the screen whenever the stringlist changes static void serenityScreenOptionChanged(CompScreen *s, CompOption *opt, SerenityScreenOptions num); @@ -110,11 +113,25 @@ static void serenityScreenOptionChanged(CompScreen *s, CompOption *opt, Serenity static void serenityPreparePaintScreen(CompScreen * s, int msSinceLastPaint) { SERENITY_SCREEN(s); + + UNWRAP(ss, s, preparePaintScreen); + (*s->preparePaintScreen) (s, msSinceLastPaint); + WRAP(ss, s, preparePaintScreen, serenityPreparePaintScreen); + if (ss->numTextures == 0) return; if (ss->currentTex == NULL) serenitySelectRandomTexture(ss); + + /* stuff that needs doing once the texture has floated all the way down the screen + if (ss->numActiveTextures > 1) + { + disableTexture(ss->currentTex); + serenitySelectRandomTexture(ss); + enableTexture(ss->s, &ss->currentTex->tex, COMP_TEXTURE_FILTER_GOOD); // FIXME: Does this have to be here? + } */ + } // TODO: Draw the texture here @@ -123,8 +140,24 @@ static Bool serenityPaintScreen(CompScreen * s, const CompTransform *transform, Region region, int output, unsigned int mask) { -// SERENITY_SCREEN(s); - return FALSE; + Bool status; + SERENITY_SCREEN(s); + + UNWRAP(ss, s, paintScreen); + status = (*s->paintScreen) (s, sAttrib, transform, region, output, mask); + WRAP(ss, s, paintScreen, serenityPaintScreen); + + CompTransform sTransform = *transform; + transformToScreenSpace (s, output, -DEFAULT_Z_CAMERA, &sTransform); + + glPushMatrix(); + glLoadMatrixf (sTransform.m); + glTranslatef(ss->object_x, ss->object_y, ss->object_z); + glCallList(ss->currentTex->list); + glTranslatef(-ss->object_x, -ss->object_y, -ss->object_z); + glPopMatrix(); + + return status; } static Bool serenityInitTextures(SerenityScreen *ss, unsigned int numTextures) @@ -163,9 +196,10 @@ static void serenityFiniTextures(SerenityScreen *ss) ss->textures[n].height = 0; ss->textures[n].width = 0; }; + ss->numTextures = 0; + if (ss->textures != NULL) free(ss->textures); - ss->numTextures = 0; } // TODO: Check I don't fail at making lists. @@ -235,6 +269,7 @@ static Bool serenitySelectRandomTexture(SerenityScreen *ss) }; ss->currentTex = activeTextures[(int)(rand() / (((double)RAND_MAX + 1) / numActiveTextures))]; + ss->numActiveTextures = numActiveTextures; return TRUE; } @@ -244,10 +279,19 @@ static void serenityScreenOptionChanged(CompScreen *s, CompOption *opt, Serenity switch (num) { case SerenityScreenOptionSerenityTextures: + { + unsigned int temp = ss->numActiveTextures; serenityDoTextures(ss); - break; - default: - break; + + // WRAP our painting functions if necessary + if (temp < 1 && ss->numActiveTextures > 0) + { + WRAP(ss, s, preparePaintScreen, serenityPreparePaintScreen); + WRAP(ss, s, paintScreen, serenityPaintScreen); + }; + } + break; + default: break; } } @@ -302,21 +346,38 @@ static Bool serenityInitScreen(CompPlugin * p, CompScreen * s) ss->s = s; s->privates[sd->screenPrivateIndex].ptr = ss; - WRAP(ss, s, preparePaintScreen, serenityPreparePaintScreen); - WRAP(ss, s, paintScreen, serenityPaintScreen); - - serenitySetSerenityTexturesNotify(s, serenityScreenOptionChanged); ss->object_x = 0; ss->object_y = 0; + ss->object_z = 0; + + ss->currentTex = NULL; + ss->numTextures = 0; + ss->numActiveTextures = 0; + + serenitySetSerenityTexturesNotify(s, serenityScreenOptionChanged); + serenityDoTextures(ss); + + if (ss->numActiveTextures > 0) + { + WRAP(ss, s, preparePaintScreen, serenityPreparePaintScreen); + WRAP(ss, s, paintScreen, serenityPaintScreen); + }; + return TRUE; } static void serenityFiniScreen(CompPlugin * p, CompScreen * s) { SERENITY_SCREEN(s); - UNWRAP(ss, s, preparePaintScreen); - UNWRAP(ss, s, paintScreen); + + if (ss->numActiveTextures > 0) + { + UNWRAP(ss, s, preparePaintScreen); + UNWRAP(ss, s, paintScreen); + }; + + disableTexture(s, ss->currentTex->t); serenityFiniTextures(ss); free(ss); } diff --git a/serenity.options b/serenity.options index ddb66c8..e0913c1 100644 --- a/serenity.options +++ b/serenity.options @@ -1,7 +1,7 @@ <plugin name="serenity"> <screen> <option name="serenity_textures" type="stringlist"> - <short>Texture</short> + <short>Textures</short> <long>The images you want to be used as textures</long> <hints>file;image</hints> </option> |