/* * 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; }
int second_window_loop() { int ret, dir = 2; time_t now, prev=0; SDL_FreeSurface(window_label.surface); picframe_load_font("fonts/Ubuntu-L.ttf", 30); picframe_gen_text(&window_label.surface, fg, bg, window_labels[1]); 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) { progress += dir; if (progress > 100) { progress = 100; dir = -2; } if (progress < 0) { progress = 0; dir = 2; } prev = now; picframe_update_progress_bar(&progress_bar, progress); } picframe_update(curr_window); SDL_Delay(1); } return 0; }
/* * Execution of the clock window */ int clock_loop() { time_t now, prev = 0; struct tm* tm; char buff[100]; int ret; int clockDeli = 1; Window *w = window[curr_window_idx]; while (1) { if ((ret = handle_input())) return ret; now = time(0); if (now > prev) { tm = localtime(&now); prev = now; clockDeli = clockDeli == 1 ? 0 : 1; if (clockDeli) { sprintf(buff, "%02d:%02d", tm->tm_hour, tm->tm_min); } else { sprintf(buff, "%02d %02d", tm->tm_hour, tm->tm_min); } picframe_load_font("/usr/share/fonts/UbuntuMono-R.ttf", 115); Element_t *time_disp = window_get_element_byName(w, "time"); time_disp->surface = TTF_RenderText_Shaded(_font, buff, fg, bg); strftime(buff, sizeof(buff), "%a, %d %b %Y %Z", tm); picframe_load_font("/usr/share/fonts/Ubuntu-L.ttf", 29); Element_t *info_disp = window_get_element_byName(w, "info"); info_disp->surface = TTF_RenderText_Shaded(_font, buff, fg, bg); window_update(window[curr_window_idx]); } SDL_Delay(1); } return 0; }
int picframe_add_button_text(Element_t *b, SDL_Rect *rect, int textsize, char *text) { SDL_Color fg = {0,0,0,0}; SDL_Color bg = {255,255,255,0}; SDL_Surface *tmp = NULL; SDL_Rect nr; tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, rect->w, rect->h, _screen->format->BitsPerPixel, _screen->format->Rmask, _screen->format->Gmask, _screen->format->Bmask, _screen->format->Amask); SDL_FillRect(tmp, &tmp->clip_rect, SDL_MapRGB(tmp->format, 0, 0,0)); nr.x = 2; nr.y = 2; nr.w = rect->w - 4; nr.h = rect->h - 4; SDL_FillRect(tmp, &nr, SDL_MapRGB(tmp->format, 255, 255, 255)); SDL_Surface *tmp_sel = NULL; tmp_sel = SDL_CreateRGBSurface(SDL_SWSURFACE, rect->w, rect->h, _screen->format->BitsPerPixel, _screen->format->Rmask, _screen->format->Gmask, _screen->format->Bmask, _screen->format->Amask); SDL_FillRect(tmp_sel, &tmp_sel->clip_rect, SDL_MapRGB(tmp_sel->format, 0, 0,0)); nr.x = 4; nr.y = 4; nr.w = rect->w - 8; nr.h = rect->h - 8; SDL_FillRect(tmp_sel, &nr, SDL_MapRGB(tmp_sel->format, 255, 255, 255)); SDL_Surface *tmp_text = NULL; picframe_load_font("/usr/share/fonts/Ubuntu-L.ttf", textsize); picframe_gen_text(&tmp_text, fg, bg, text); nr.x = (rect->w/2) - (tmp_text->clip_rect.w/2); nr.y = (rect->h/2) - (tmp_text->clip_rect.h/2); nr.w = rect->w; nr.h = rect->h; SDL_BlitSurface(tmp_text, NULL, tmp, &nr); SDL_BlitSurface(tmp_text, NULL, tmp_sel, &nr); SDL_FreeSurface(tmp_text); b->surface = tmp; b->surface_selected = tmp_sel; memcpy(&(b->rect), rect, sizeof(SDL_Rect)); b->selected = 0; b->dynamic = 0; return 0; }
int fourth_window_loop() { int ret; SDL_FreeSurface(window_label.surface); picframe_load_font("fonts/Ubuntu-L.ttf", 30); picframe_gen_text(&window_label.surface, fg, bg, window_labels[3]); window_label.rect.x = (WIDTH/2) - (window_label.surface->clip_rect.w/2); while (1) { ret = handle_input(); if (ret) return ret; picframe_update(curr_window); SDL_Delay(1); } return 0; }
/* * Setup routine for the first window */ void first_window_setup() { struct LList_t *first_window = NULL; first_window = picframe_get_window(1); SDL_Rect tmp; /* Left arrow */ tmp.x = 20; tmp.y = 15; picframe_add_button(&left_arrow_icon, &tmp, "data/glyphicons_210_left_arrow.png", "data/glyphicons_210_left_arrow_selected.png"); picframe_add_element_to_window(first_window, &left_arrow_icon); /* Right arrow */ tmp.x = 320-40; tmp.y = 15; right_arrow_icon.selected = 1; picframe_add_button(&right_arrow_icon, &tmp, "data/glyphicons_211_right_arrow.png", "data/glyphicons_211_right_arrow_selected.png"); picframe_add_element_to_window(first_window, &right_arrow_icon); window_label.surface = NULL; window_label.rect.x = 110; window_label.rect.y = 5; window_label.selected =0; window_label.dynamic = 0; picframe_add_element_to_window(first_window, &window_label); picframe_load_font("fonts/Ubuntu-L.ttf", 80); /* Dynamic watch label */ time_disp.surface = NULL; //sometext; time_disp.rect.x = 5; time_disp.rect.y = 50; time_disp.selected = 0; time_disp.dynamic = 1; /* Free up the surface after use, otherwise memory leak! */ picframe_add_element_to_window(first_window, &time_disp); /* Dynamic info label */ info_disp.surface = NULL; info_disp.rect.x = 10; info_disp.rect.y = 200; info_disp.selected = 0; info_disp.dynamic = 1; picframe_add_element_to_window(first_window, &info_disp); }
int fifth_window_loop() { int ret; SDL_FreeSurface(window_label.surface); picframe_load_font("fonts/Ubuntu-L.ttf", 30); picframe_gen_text(&window_label.surface, fg, bg, window_labels[4]); window_label.rect.x = (WIDTH/2) - (window_label.surface->clip_rect.w/2); picframe_load_image(&security_cam.surface, "data/camera.png"); while (1) { ret = handle_input(); if (ret) return ret; picframe_update(curr_window); SDL_Delay(1); } return 0; // TODO: Free up all the images when the window is closed SDL_FreeSurface(security_cam.surface); }
int picframe_init() { _font = NULL; /* SDL Setup */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); /* Initialize our screen */ _screen = SDL_SetVideoMode(WIDTH, HEIGHT, 32, SDL_HWSURFACE ); if ( _screen == NULL ) { fprintf(stderr, "Could not setup screen to resolution %dx%d : %s\n", WIDTH, HEIGHT, SDL_GetError()); exit(1); } /* Hide the mouse */ SDL_ShowCursor(0); /* Solid white background */ picframe_clear_screen(); /* Initialize the fonts */ if ( TTF_Init() == -1 ) { fprintf(stderr, "Could not initalize SDL_ttf!\n"); exit(1); } /* Load a default font */ picframe_load_font("fonts/Ubuntu-L.ttf", 20); /* Aight, lets make our first default window */ _num_windows = 0; struct LList_t *node = picframe_add_window(); picframe_gpio_init(); return 0; }
/* * Setup routine for the clock window */ void clock_setup() { struct LList_t *first_window = NULL; first_window = picframe_get_window(1); SDL_Rect tmp; picframe_add_element_to_window(first_window, &leftArrow); picframe_add_element_to_window(first_window, &rightArrow); /////// Arrows are HERE ////// window_label.surface = NULL; window_label.rect.x = 110; window_label.rect.y = 5; window_label.selected = 0; window_label.dynamic = 0; picframe_add_element_to_window(first_window, &window_label); picframe_load_font("/usr/share/fonts/Ubuntu-L.ttf", 80); /* Dynamic watch label */ time_disp.surface = NULL; //sometext; time_disp.rect.x = 5; time_disp.rect.y = 50; time_disp.selected = 0; time_disp.dynamic = 1; /* Free up the surface after use, otherwise memory leak! */ picframe_add_element_to_window(first_window, &time_disp); /* Dynamic info label */ info_disp.surface = NULL; info_disp.rect.x = 10; info_disp.rect.y = 200; info_disp.selected = 0; info_disp.dynamic = 1; picframe_add_element_to_window(first_window, &info_disp); }
int third_window_loop() { int ret; SDL_FreeSurface(window_label.surface); picframe_load_font("fonts/Ubuntu-L.ttf", 30); picframe_gen_text(&window_label.surface, fg, bg, window_labels[2]); window_label.rect.x = (WIDTH/2) - (window_label.surface->clip_rect.w/2); picframe_load_image(&today_pic.surface, weather_pics[WEATHER_SUNNY]); picframe_load_image(&tomorrow_pic.surface, weather_pics[WEATHER_CLOUDY]); picframe_load_image(&twodays_pic.surface, weather_pics[WEATHER_MIXED]); picframe_load_image(&threedays_pic.surface, weather_pics[WEATHER_SNOWY]); SDL_Rect sep; sep.x = (WIDTH / 3); sep.y = (HEIGHT * 0.5); sep.w = 1; sep.h = (HEIGHT * 0.5); picframe_draw_line(sep); sep.x = (WIDTH / 3)*2; picframe_draw_line(sep); while (1) { ret = handle_input(); if (ret) return ret; picframe_update(curr_window); SDL_Delay(1); } return 0; // TODO: Free up all the images when the window is closed SDL_FreeSurface(today_pic.surface); SDL_FreeSurface(tomorrow_pic.surface); SDL_FreeSurface(twodays_pic.surface); SDL_FreeSurface(threedays_pic.surface); }