Exemple #1
0
/**
 * Can be used to cycle through the colors of a VisPalette and blend between elements. The rate is from 0.0 to number of
 * VisColors in the VisPalette. The VisColor is newly allocated so you have to unref it. The last VisColor in the VisPalette is
 * morphed with the first.
 *
 * @param pal Pointer to the VisPalette in which the VisColors are cycled.
 * @param rate Selection of the VisColor from the VisPalette, goes from 0.0 to number of VisColors in the VisPalette
 * 	and morphs between colors if needed.
 *
 * @return A new VisColor, possibly a morph between two VisColors, NULL on failure.
 */
VisColor *visual_palette_color_cycle (VisPalette *pal, float rate)
{
	VisColor *color, *tmp1, *tmp2;
	int irate = (int) rate;
	unsigned char alpha;
	float rdiff = rate - irate;

	visual_log_return_val_if_fail (pal != NULL, NULL);

	irate = irate % pal->ncolors;
	alpha = rdiff * 255;

	color = visual_color_new ();

	/* If rate is exactly an item, return that item */
	if (rdiff == 0) {
		visual_color_copy (color, &pal->colors[irate]);

		return color;
	}

	tmp1 = &pal->colors[irate];

	if (irate == pal->ncolors - 1)
		tmp2 = &pal->colors[0];
	else
		tmp2 = &pal->colors[irate + 1];

	color->r = ((alpha * (tmp1->r - tmp2->r) >> 8) + tmp2->r);
	color->g = ((alpha * (tmp1->g - tmp2->g) >> 8) + tmp2->g);
	color->b = ((alpha * (tmp1->b - tmp2->b) >> 8) + tmp2->b);

	return color;
}
static int act_bumpscope_events (VisPluginData *plugin, VisEventQueue *events)
{
	BumpscopePrivate *priv = visual_plugin_get_private (plugin);
	VisEvent ev;
	VisParam *param;
	VisColor *tmp;

	while (visual_event_queue_poll (events, &ev)) {
		switch (ev.type) {
			case VISUAL_EVENT_RESIZE:
				act_bumpscope_resize (plugin, ev.event.resize.width, ev.event.resize.height);
				break;

			case VISUAL_EVENT_MOUSEMOTION:
				if (ev.event.mousemotion.state == VISUAL_MOUSE_DOWN) {
					priv->light_x = ev.event.mousemotion.x;
					priv->light_y = ev.event.mousemotion.y;
				}

				break;

			case VISUAL_EVENT_PARAM:
				param = ev.event.param.param;

				if (visual_param_has_name (param, "color")) {
					tmp = visual_param_get_value_color (param);
					visual_color_copy (&priv->color, tmp);

					__bumpscope_generate_palette (priv, &priv->color);

				} else if (visual_param_has_name (param, "light size")) {
					priv->phongres = visual_param_get_value_integer (param);

					__bumpscope_cleanup (priv);
					__bumpscope_init (priv);

				} else if (visual_param_has_name (param, "color_cycle")) {
					priv->color_cycle = visual_param_get_value_bool (param);

				} else if (visual_param_has_name (param, "moving_light")) {
					priv->moving_light = visual_param_get_value_bool (param);

				} else if (visual_param_has_name (param, "diamond")) {
					priv->diamond = visual_param_get_value_bool (param);

					__bumpscope_generate_phongdat (priv);
				}

				break;

			default: /* to avoid warnings */
				break;
		}
	}

	return TRUE;
}
Exemple #3
0
/**
 * Sets the VisParamEntry to VISUAL_PARAM_ENTRY_TYPE_COLOR and assigns the rgb values from the given VisColor as argument to it.
 *
 * @param param Pointer to the VisParamEntry to which a parameter is set.
 * @param color Pointer to the VisColor from which the rgb values are copied into the parameter.
 *
 * @return VISUAL_OK on succes, -VISUAL_ERROR_PARAM_NULL on failure.
 */
int visual_param_entry_set_color_by_color (VisParamEntry *param, VisColor *color)
{
	visual_log_return_val_if_fail (param != NULL, -VISUAL_ERROR_PARAM_NULL);

	param->type = VISUAL_PARAM_ENTRY_TYPE_COLOR;

	if (visual_color_compare (&param->color, color) == FALSE) {
		visual_color_copy (&param->color, color);

		visual_param_entry_changed (param);
	}

	return VISUAL_OK;
}