/* * 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; }
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; }
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 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); }