static Bool
snowInitScreen (CompPlugin *p,
		CompScreen *s)
{
    SnowScreen *ss;
    int        i, numFlakes = starGetNumSnowflakes (s->display);
    SnowFlake  *snowFlake;

    SNOW_DISPLAY (s->display);

    ss = calloc (1, sizeof(SnowScreen));

    s->base.privates[sd->screenPrivateIndex].ptr = ss;

    ss->s = s;
    ss->snowTexturesLoaded = 0;
    ss->snowTex = NULL;
    ss->active = FALSE;
    ss->displayListNeedsUpdate = FALSE;

    ss->allSnowFlakes = snowFlake = malloc (numFlakes * sizeof (SnowFlake));

    for (i = 0; i < numFlakes; i++)
    {
	initiateSnowFlake (ss, snowFlake);
	setSnowflakeTexture (ss, snowFlake);
	snowFlake++;
    }

    updateSnowTextures (s);
    setupDisplayList (ss);

    WRAP (ss, s, paintOutput, snowPaintOutput);
    WRAP (ss, s, drawWindow, snowDrawWindow);

    ss->timeoutHandle = compAddTimeout (starGetSnowUpdateDelay (s->display),
					starGetSnowUpdateDelay (s->display) * 1.2, stepSnowPositions, s);

    return TRUE;
}
static void
snowDisplayOptionChanged (CompDisplay        *d,
			  CompOption         *opt,
			  StarDisplayOptions num)
{
    SNOW_DISPLAY (d);

    switch (num)
    {
    case StarDisplayOptionSnowSize:
	{
	    CompScreen *s;

	    for (s = d->screens; s; s = s->next)
	    {
		SNOW_SCREEN (s);
		ss->displayListNeedsUpdate = TRUE;
		updateSnowTextures (s);
	    }
	}
	break;
    case StarDisplayOptionSnowUpdateDelay:
	{
	    CompScreen *s;

	    for (s = d->screens; s; s = s->next)
	    {
		SNOW_SCREEN (s);

		if (ss->timeoutHandle)
		    compRemoveTimeout (ss->timeoutHandle);
		ss->timeoutHandle =
		    compAddTimeout (starGetSnowUpdateDelay (d),
									   starGetSnowUpdateDelay (d) *1.2,  stepSnowPositions, s);
	    }
	}
	break;
    case StarDisplayOptionNumSnowflakes:
	{
	    CompScreen *s;
	    int        i, numFlakes;
	    SnowFlake  *snowFlake;

	    numFlakes = starGetNumSnowflakes (d);
	    for (s = d->screens; s; s = s->next)
	    {
		SNOW_SCREEN (s);
		ss->allSnowFlakes = realloc (ss->allSnowFlakes,
					     numFlakes * sizeof (SnowFlake));
		snowFlake = ss->allSnowFlakes;

		for (i = 0; i < numFlakes; i++)
		{
		    initiateSnowFlake (ss, snowFlake);
		    setSnowflakeTexture (ss, snowFlake);
		    snowFlake++;
		}
	    }
	}
	break;
    case StarDisplayOptionSnowTextures:
	{
	    CompScreen *s;
	    CompOption *texOpt;

	    texOpt = starGetSnowTexturesOption (d);

	    sd->snowTexFiles = texOpt->value.list.value;
	    sd->snowTexNFiles = texOpt->value.list.nValue;

	    for (s = d->screens; s; s = s->next)
		updateSnowTextures (s);
	}
	break;
    default:
	break;
    }
}
static void
updateSnowTextures (CompScreen *s)
{
    int       i, count = 0;
    float     snowSize = starGetSnowSize(s->display);
    int       numFlakes = starGetNumSnowflakes(s->display);
    SnowFlake *snowFlake;

    SNOW_SCREEN (s);
    SNOW_DISPLAY (s->display);

    snowFlake = ss->allSnowFlakes;

    for (i = 0; i < ss->snowTexturesLoaded; i++)
    {
	finiTexture (s, &ss->snowTex[i].tex);
	glDeleteLists (ss->snowTex[i].dList, 1);
    }

    if (ss->snowTex)
	free (ss->snowTex);
    ss->snowTexturesLoaded = 0;

    ss->snowTex = calloc (1, sizeof (SnowTexture) * sd->snowTexNFiles);

    for (i = 0; i < sd->snowTexNFiles; i++)
    {
	CompMatrix  *mat;
	SnowTexture *sTex;

	ss->snowTex[count].loaded =
	    readImageToTexture (s, &ss->snowTex[count].tex,
				sd->snowTexFiles[i].s,
				&ss->snowTex[count].width,
				&ss->snowTex[count].height);
	if (!ss->snowTex[count].loaded)
	{
	    compLogMessage ("snow", CompLogLevelWarn,
			    "Texture not found : %s", sd->snowTexFiles[i].s);
	    continue;
	}
	compLogMessage ("snow", CompLogLevelInfo,
			"Loaded Texture %s", sd->snowTexFiles[i].s);

	mat = &ss->snowTex[count].tex.matrix;
	sTex = &ss->snowTex[count];

	sTex->dList = glGenLists (1);
	glNewList (sTex->dList, GL_COMPILE);

	glBegin (GL_QUADS);

	glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0));
	glVertex2f (0, 0);
	glTexCoord2f (COMP_TEX_COORD_X (mat, 0),
		      COMP_TEX_COORD_Y (mat, sTex->height));
	glVertex2f (0, snowSize * sTex->height / sTex->width);
	glTexCoord2f (COMP_TEX_COORD_X (mat, sTex->width),
		      COMP_TEX_COORD_Y (mat, sTex->height));
	glVertex2f (snowSize, snowSize * sTex->height / sTex->width);
	glTexCoord2f (COMP_TEX_COORD_X (mat, sTex->width),
		      COMP_TEX_COORD_Y (mat, 0));
	glVertex2f (snowSize, 0);

	glEnd ();
	glEndList ();

	count++;
    }

    ss->snowTexturesLoaded = count;
    if (count < sd->snowTexNFiles)
	ss->snowTex = realloc (ss->snowTex, sizeof (SnowTexture) * count);

    for (i = 0; i < numFlakes; i++)
	setSnowflakeTexture (ss, snowFlake++);
}
示例#4
0
文件: snow.c 项目: jordigh/fusilli
static void
snowChangeNotify (const char        *optionName,
                  BananaType        optionType,
                  const BananaValue *optionValue,
                  int               screenNum)
{
	SNOW_DISPLAY (&display);

	if (strcasecmp (optionName, "snow_size") == 0)
	{
		CompScreen *s;

		for (s = display.screens; s; s = s->next)
		{
			SNOW_SCREEN (s);
			ss->displayListNeedsUpdate = TRUE;
			updateSnowTextures (s);
		}
	}
	else if (strcasecmp (optionName, "snow_update_delay") == 0)
	{
		CompScreen *s;

		for (s = display.screens; s; s = s->next)
		{
			SNOW_SCREEN (s);

			if (ss->timeoutHandle)
				compRemoveTimeout (ss->timeoutHandle);
			ss->timeoutHandle =
			    compAddTimeout (optionValue->i,
			            (float) optionValue->i * 1.2,
			            stepSnowPositions, s);
		}
	}
	else if (strcasecmp (optionName, "num_snowflakes") == 0)
	{
		CompScreen *s;
		int        i, numFlakes;
		SnowFlake  *snowFlake;

		numFlakes = optionValue->i;
		for (s = display.screens; s; s = s->next)
		{
			SNOW_SCREEN (s);
			ss->allSnowFlakes = realloc (ss->allSnowFlakes,
			                             numFlakes * sizeof (SnowFlake));
			snowFlake = ss->allSnowFlakes;

			for (i = 0; i < numFlakes; i++)
			{
				initiateSnowFlake (ss, snowFlake);
				setSnowflakeTexture (ss, snowFlake);
				snowFlake++;
			}
		}
	}
	else if (strcasecmp (optionName, "snow_textures") == 0)
	{
		CompScreen *s;

		for (s = display.screens; s; s = s->next)
			updateSnowTextures (s);
	}
	else if (strcasecmp (optionName, "toggle_key") == 0)
		updateKey (optionValue->s, &sd->toggle_key);

}
示例#5
0
文件: snow.c 项目: jordigh/fusilli
static Bool
snowInitScreen (CompPlugin *p,
                CompScreen *s)
{
	SnowScreen *ss;

	const BananaValue *
	option_num_snowflakes = bananaGetOption (bananaIndex,
	                                         "num_snowflakes",
	                                         -1);

	const BananaValue *
	option_snow_update_delay = bananaGetOption (bananaIndex,
	                                            "snow_update_delay",
	                                            -1);

	int        i, numFlakes = option_num_snowflakes->i;
	SnowFlake  *snowFlake;

	SNOW_DISPLAY (&display);

	ss = calloc (1, sizeof(SnowScreen));
	if (!ss)
		return FALSE;

	s->privates[sd->screenPrivateIndex].ptr = ss;

	ss->s = s;
	ss->snowTexturesLoaded = 0;
	ss->snowTex = NULL;
	ss->active = FALSE;
	ss->displayListNeedsUpdate = FALSE;

	ss->allSnowFlakes = snowFlake = malloc (numFlakes * sizeof (SnowFlake));
	if (!snowFlake)
	{
		free (ss);
		return FALSE;
	}

	for (i = 0; i < numFlakes; i++)
	{
		initiateSnowFlake (ss, snowFlake);
		setSnowflakeTexture (ss, snowFlake);
		snowFlake++;
	}

	updateSnowTextures (s);
	setupDisplayList (ss);

	WRAP (ss, s, paintOutput, snowPaintOutput);
	WRAP (ss, s, drawWindow, snowDrawWindow);

	ss->timeoutHandle = compAddTimeout (option_snow_update_delay->i,
	                (float)
	                option_snow_update_delay->i *
	                1.2,
	                stepSnowPositions, s);

	return TRUE;
}
示例#6
0
文件: snow.c 项目: jordigh/fusilli
static void
updateSnowTextures (CompScreen *s)
{
	const BananaValue *
	option_snow_size = bananaGetOption (bananaIndex,
	                                    "snow_size",
	                                    -1);

	const BananaValue *
	option_num_snowflakes = bananaGetOption (bananaIndex,
	                                         "num_snowflakes",
	                                         -1);

	const BananaValue *
	option_snow_textures = bananaGetOption (bananaIndex,
	                                        "snow_textures",
	                                        -1);

	int       i, count = 0;
	float     snowSize = option_snow_size->f;
	int       numFlakes = option_num_snowflakes->i;
	SnowFlake *snowFlake;

	SNOW_SCREEN (s);

	snowFlake = ss->allSnowFlakes;

	for (i = 0; i < ss->snowTexturesLoaded; i++)
	{
		finiTexture (s, &ss->snowTex[i].tex);
		glDeleteLists (ss->snowTex[i].dList, 1);
	}

	if (ss->snowTex)
		free (ss->snowTex);

	ss->snowTexturesLoaded = 0;

	ss->snowTex = calloc (1,
	                 sizeof (SnowTexture) * option_snow_textures->list.nItem);

	for (i = 0; i < option_snow_textures->list.nItem; i++)
	{
		CompMatrix  *mat;
		SnowTexture *sTex;

		ss->snowTex[count].loaded =
		    readImageToTexture (s, &ss->snowTex[count].tex,
		        option_snow_textures->list.item[i].s,
		        &ss->snowTex[count].width,
		        &ss->snowTex[count].height);

		if (!ss->snowTex[count].loaded)
		{
			compLogMessage ("snow", CompLogLevelWarn,
			                "Texture not found : %s",
			                option_snow_textures->list.item[i].s);
			continue;
		}

		compLogMessage ("snow", CompLogLevelInfo,
		                "Loaded Texture %s",
		                option_snow_textures->list.item[i].s);

		mat = &ss->snowTex[count].tex.matrix;
		sTex = &ss->snowTex[count];

		sTex->dList = glGenLists (1);
		glNewList (sTex->dList, GL_COMPILE);

		glBegin (GL_QUADS);

		glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0));
		glVertex2f (0, 0);
		glTexCoord2f (COMP_TEX_COORD_X (mat, 0),
		              COMP_TEX_COORD_Y (mat, sTex->height));
		glVertex2f (0, snowSize * sTex->height / sTex->width);
		glTexCoord2f (COMP_TEX_COORD_X (mat, sTex->width),
		              COMP_TEX_COORD_Y (mat, sTex->height));
		glVertex2f (snowSize, snowSize * sTex->height / sTex->width);
		glTexCoord2f (COMP_TEX_COORD_X (mat, sTex->width),
		              COMP_TEX_COORD_Y (mat, 0));
		glVertex2f (snowSize, 0);

		glEnd ();
		glEndList ();

		count++;
	}

	ss->snowTexturesLoaded = count;
	if (count < option_snow_textures->list.nItem)
		ss->snowTex = realloc (ss->snowTex, sizeof (SnowTexture) * count);

	for (i = 0; i < numFlakes; i++)
		setSnowflakeTexture (ss, snowFlake++);
}