예제 #1
0
static void play_animation(int i) {

	struct timeval start;
	gettimeofday(&start, NULL);

	sprite_t * sprite = applications[i].icon_sprite;

	int x = ICON_X;
	int y = ICON_TOP_Y + ICON_SPACING_Y * i;

	while (1) {
		uint32_t tick;
		struct timeval t;
		gettimeofday(&t, NULL);

		uint32_t sec_diff = t.tv_sec - start.tv_sec;
		uint32_t usec_diff = t.tv_usec - start.tv_usec;

		if (t.tv_usec < start.tv_usec) {
			sec_diff -= 1;
			usec_diff = (1000000 + t.tv_usec) - start.tv_usec;
		}

		tick = (uint32_t)(sec_diff * 1000 + usec_diff / 1000);
		if (tick > ANIMATION_TICKS) break;

		float percent = (float)tick / (float)ANIMATION_TICKS;
		float scale = 1.0f + (SCALE_MAX - 1.0f) * percent;
		float opacity = 1.0f - 1.0f * percent;

		int offset_x = sprite->width / 2 - scale * (sprite->width / 2);
		int offset_y = sprite->height / 2 - scale * (sprite->height / 2);

		redraw_apps(0);
		draw_sprite_scaled_alpha(ctx, sprite, x + offset_x, y + offset_y, sprite->width * scale, sprite->height * scale, opacity);
		flip(ctx);
		yutani_flip_region(yctx, wina, 0, y - sprite->height, x + sprite->width * 2, y + sprite->height * 2);

	}

	redraw_apps(1);
	yutani_flip_region(yctx, wina, 0, y - sprite->height, x + sprite->width * 2, y + sprite->height * 2);
}
예제 #2
0
파일: wallpaper.c 프로젝트: etel/ponyos
static void set_focused(int i) {
	if (focused_app != i) {
		int old_focused = focused_app;
		focused_app = i;
		redraw_apps();
		if (old_focused >= 0) {
			yutani_flip_region(yctx, wina, 0, ICON_TOP_Y + ICON_SPACING_Y * old_focused, ICON_WIDTH + 2 * EXTRA_WIDTH, ICON_SPACING_Y);
		}
		if (focused_app >= 0) {
			yutani_flip_region(yctx, wina, 0, ICON_TOP_Y + ICON_SPACING_Y * focused_app, ICON_WIDTH + 2 * EXTRA_WIDTH, ICON_SPACING_Y);
		}
	}
}
예제 #3
0
파일: wallpaper.c 프로젝트: etel/ponyos
int main (int argc, char ** argv) {
	yctx = yutani_init();

	int width  = yctx->display_width;
	int height = yctx->display_height;

	sprite_t * wallpaper_tmp = malloc(sizeof(sprite_t));

	char f_name[512];
	sprintf(f_name, "%s/.wallpaper.png", getenv("HOME"));
	FILE * f = fopen(f_name, "r");
	if (f) {
		fclose(f);
		load_sprite_png(wallpaper_tmp, f_name);
	} else {
		load_sprite_png(wallpaper_tmp, "/usr/share/wallpaper.png");
	}

	/* Initialize hashmap for icon cache */
	icon_cache = hashmap_create(10);

	{ /* Generic fallback icon */
		sprite_t * app_icon = malloc(sizeof(sprite_t));
		load_sprite_png(app_icon, "/usr/share/icons/48/applications-generic.png");
		hashmap_set(icon_cache, "generic", app_icon);
	}

	sprintf(f_name, "%s/.desktop", getenv("HOME"));
	f = fopen(f_name, "r");
	if (!f) {
		f = fopen("/etc/default.desktop", "r");
	}
	read_applications(f);

	/* Load applications */
	uint32_t i = 0;
	while (applications[i].icon) {
		applications[i].icon_sprite = icon_get(applications[i].icon);
		++i;
	}

	float x = (float)width  / (float)wallpaper_tmp->width;
	float y = (float)height / (float)wallpaper_tmp->height;

	int nh = (int)(x * (float)wallpaper_tmp->height);
	int nw = (int)(y * (float)wallpaper_tmp->width);;

	wallpaper = create_sprite(width, height, ALPHA_OPAQUE);
	gfx_context_t * tmp = init_graphics_sprite(wallpaper);

	if (nw > width) {
		draw_sprite_scaled(tmp, wallpaper_tmp, (width - nw) / 2, 0, nw, height);
	} else {
		draw_sprite_scaled(tmp, wallpaper_tmp, 0, (height - nh) / 2, width, nh);
	}

	free(tmp);

	win_width = width;
	win_height = height;

	wina = yutani_window_create(yctx, width, height);
	assert(wina);
	yutani_set_stack(yctx, wina, YUTANI_ZORDER_BOTTOM);
	ctx = init_graphics_yutani_double_buffer(wina);
	init_shmemfonts();

	redraw_apps();
	yutani_flip(yctx, wina);

	while (_continue) {
		yutani_msg_t * m = yutani_poll(yctx);
		waitpid(-1, NULL, WNOHANG);
		if (m) {
			switch (m->type) {
				case YUTANI_MSG_WINDOW_MOUSE_EVENT:
					wallpaper_check_click((struct yutani_msg_window_mouse_event *)m->data);
					break;
				case YUTANI_MSG_SESSION_END:
					_continue = 0;
					break;
			}
			free(m);
		}
	}

	yutani_close(yctx, wina);

	return 0;
}