Ejemplo n.º 1
0
/*
 * Generic Input handling
 */
int handle_input() {
	int i = 0;
	SDL_Event event;

	while (picframe_get_event(&event)) {

		switch (event.type) {
		case SDL_QUIT:
			printf("Quitting\n");
			return 1;
			break;
		case SDL_KEYDOWN:
			if (event.key.keysym.sym == SDLK_LEFT) {
				leftArrow->selected = 1;
				curr_window_idx--;
				if (curr_window_idx < 0)
					curr_window_idx = 0;
				printf("Current window: %d\n", curr_window_idx);

			}

			if (event.key.keysym.sym == SDLK_RIGHT) {
				rightArrow->selected = 1;
				curr_window_idx++;
				if (curr_window_idx > NUM_WINDOWS - 1)
					curr_window_idx = NUM_WINDOWS - 1;

				printf("Current window: %d\n", curr_window_idx);
			}

			if (event.key.keysym.sym == SDLK_RETURN) {
				i = picframe_get_lightsensor();
				printf("Light sensor: %d\n", i);
			}

			break;

		case SDL_KEYUP:
			if (event.key.keysym.sym == SDLK_LEFT) {
				leftArrow->selected = 0;
			}

			if (event.key.keysym.sym == SDLK_RIGHT) {
				rightArrow->selected = 0;
			}

			break;
		default:
			break;
		}
		if (prev_window_idx != curr_window_idx) {
			prev_window_idx = curr_window_idx;
			return 2;
		}
		prev_window_idx = curr_window_idx;
	}
	return 0;
}
Ejemplo n.º 2
0
/*
 *  Execution of the clock window
 */
int clock_loop() {
	time_t now, prev = 0;
	struct tm* tm;
	char buff[50];
	int ret, lightlevel, brightness;

	SDL_FreeSurface(window_label.surface);
	picframe_load_font("/usr/share/fonts/Ubuntu-L.ttf", 30);

//	picframe_gen_text(&window_label.surface, fg, bg, window_labels[0]);
	window_label.rect.x = (WIDTH / 2) - (window_label.surface->clip_rect.w / 2);

	while (1) {
		ret = handle_input();
		if (ret)
			return ret;

		now = time(0);
		if (now > prev) {
			tm = localtime(&now);
			sprintf(buff, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
					tm->tm_sec);
			picframe_load_font("/usr/share/fonts/Ubuntu-L.ttf", 80);

			picframe_gen_text(&time_disp.surface, fg, bg, buff);

			// FREE_FONT
			/*
			debug_printf("Setting time_disp surface to: %p\n",
					time_disp.surface);
			*/
			prev = now;

			lightlevel = picframe_get_lightsensor();
			brightness = picframe_get_backlight();

			sprintf(buff, "Light level: %d\tBrightness: %d", lightlevel,
					brightness);
			picframe_load_font("/usr/share/fonts/Ubuntu-L.ttf", 20);
			picframe_gen_text(&info_disp.surface, fg, bg, buff);
			/*
			debug_printf("Setting info_disp surface to: %p\n",
					info_disp.surface);
			*/
		}

		picframe_update(curr_window);
		SDL_Delay(1);
	}
	return 0;
}
Ejemplo n.º 3
0
/*
 * Generic Input handling
 */
int handle_input() {
	int i = 0;
	struct LList_t *tmp_window = NULL;

//	while (picframe_get_event(&event)) {
	while (SDL_PollEvent(&event)) {
		switch (event.type) {
		case SDL_QUIT:
			printf("Quitting\n");
			return 1;
			break;
		case SDL_KEYDOWN:
			if (event.key.keysym.sym == SDLK_LEFT) {
				leftArrow.selected = 1;
				curr_window_idx--;
				if (curr_window_idx < 1)
					curr_window_idx = 1;
				tmp_window = picframe_get_window(curr_window_idx);
				if (tmp_window)
					curr_window = tmp_window;
				else
					curr_window_idx++;

				printf("Current window: %d\n", curr_window_idx);
			}

			if (event.key.keysym.sym == SDLK_RIGHT) {
				rightArrow.selected = 1;
				curr_window_idx++;
				if (curr_window_idx > NUM_WINDOWS)
					curr_window_idx = NUM_WINDOWS;
				tmp_window = picframe_get_window(curr_window_idx);
				if (tmp_window)
					curr_window = tmp_window;
				else
					curr_window_idx--;

				printf("Current window: %d\n", curr_window_idx);
			}

			if (event.key.keysym.sym == SDLK_RETURN) {
				i = picframe_get_lightsensor();
				printf("Light sensor: %d\n", i);
			}

			if (event.key.keysym.sym == '1') {
				appls[0].selected = 1;
			}
			if (event.key.keysym.sym == '2') {
				appls[1].selected = 1;
			}
			if (event.key.keysym.sym == '3') {
				appls[2].selected = 1;
			}
			if (event.key.keysym.sym == '4') {
				appls[3].selected = 1;
			}

			break;

		case SDL_KEYUP:
			if (event.key.keysym.sym == SDLK_LEFT) {
				leftArrow.selected = 0;
			}

			if (event.key.keysym.sym == SDLK_RIGHT) {
				rightArrow.selected = 0;
			}

			if (event.key.keysym.sym == '1') {
				appls[0].selected = 0;
			}
			if (event.key.keysym.sym == '2') {
				appls[1].selected = 0;
			}
			if (event.key.keysym.sym == '3') {
				appls[2].selected = 0;
			}
			if (event.key.keysym.sym == '4') {
				appls[3].selected = 0;
			}

			break;
		default:
			break;
		}
		if (prev_window_idx != curr_window_idx) {
			prev_window_idx = curr_window_idx;
			return 2;
		}
		prev_window_idx = curr_window_idx;
	}
	return 0;
}