void show_osd(int played, int duration, char* title) { if (MAIN_OSD == NULL) { // Calling ``init_osd`` everytime seems wasteful, but it is needed to // ensure that the OSD is visible. The main issue is that if the player // is stopped and then restarted, the graphics library needs to be // reinitalized, otherwise the OSD is not drawn ontop of the video. init_osd(); } OSD* osd = MAIN_OSD; if (played > duration) { played = duration; } osd->duration = duration; osd->played = played; osd->title = title; Start(osd->width, osd->height); Fill(255,255,255,1); Text(32, 120+82+20, "PAUSED", OpenSansBold, 16); // Main OSD background Fill(0, 0, 0, 0.5); Roundrect(22, 82, osd->width-44, 120, 15, 15); /////////////////////////////////////////////////////////////////////// // Header /////////////////////////////////////////////////////////////////////// Fill(0, 0, 0, 1); Roundrect(22, 120+82-20, osd->width-44, 20, 15, 15); // Top of the header Rect(22, 120+82-(54+10), osd->width-44, 54); // Bottom of header // Current time get_time(osd->time_now, 0); Fill(102, 102, 102, 1); Text(46, 162, osd->time_now, OpenSansSemiBold, 14); // End time if (duration > 0) { get_time(osd->time_end, osd->duration-osd->played); TextEnd(osd->width-46, 162, osd->time_end, OpenSansSemiBold, 14); } // Title text Fill(255, 255, 255, 1); int title_width = TextWidth(osd->title, OpenSansSemiBold, 20); Text((osd->width/2)-(title_width/2), 162, osd->title, OpenSansSemiBold, 20); /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // Progress Bar /////////////////////////////////////////////////////////////////////////// if (duration > 0) { int pbar_width = osd->width-288; float pct_player = (float)played/duration; Fill(255, 255, 255, 0.2); // Transparent bg Roundrect(142, 102, pbar_width, 12, 10, 10); // Centered Fill(209, 125, 30, 1); // Orange bar (progress) Roundrect(142, 102, pbar_width*pct_player, 12, 10, 10); // Left justified // Progress text seconds_to_str(osd->pos_now, osd->played); seconds_to_str(osd->pos_end, osd->duration-osd->played); // Text shadow Fill(0, 0, 0, 1); Text(46-1, 102-1, osd->pos_now, OpenSansSemiBold, 12); TextEnd(osd->width-46-1, 102-1, osd->pos_end, OpenSansSemiBold, 12); // Actual text Fill(255,255,255,1); Text(46, 102, osd->pos_now, OpenSansSemiBold, 12); TextEnd(osd->width-46, 102, osd->pos_end, OpenSansSemiBold, 12); } ////////////////////////////////////////////////////////////////////// End(); }
int main(int argc, char **argv) { time_t start, end; time(&start); ctx_msg_out = stderr; cortex_init(); cmd_init(argc, argv); if(argc == 1) print_help(stderr, NULL); const CtxCmd *cmd = ctx_get_command(argv[1]); if(cmd == NULL) print_help(stderr, "Unrecognised command: %s", argv[1]); // Once we have set cmd_usage, we can call cmd_print_usage() from anywhere cmd_set_usage(cmd->usage); // If no arguments after command, print help if(argc == 2) cmd_print_usage(NULL); // Look for -q, --quiet argument, if given silence output int argi = 1; while(argi < argc && !(!strcmp(argv[argi],"-q") || !strcmp(argv[argi],"--quiet"))) argi++; if(argi < argc) { // Found -q, --quiet argument ctx_msg_out = NULL; // Remove argument for(--argc; argi < argc; argi++) argv[argi] = argv[argi+1]; } // Print status header cmd_print_status_header(); SWAP(argv[1],argv[0]); int ret = cmd->func(argc-1, argv+1); time(&end); cmd_destroy(); // Warn if more allocations than deallocations size_t still_alloced = alloc_get_num_allocs() - alloc_get_num_frees(); if(still_alloced) warn("%zu allocates not free'd.", still_alloced); char nallocs_str[50]; ulong_to_str(alloc_get_num_allocs(), nallocs_str); status("[memory] We made %s allocs", nallocs_str); status(ret == 0 ? "Done." : "Fail."); // Print time taken double diff = difftime(end,start); if(diff < 60) status("[time] %.2lf seconds\n", diff); else { char timestr[100]; seconds_to_str((size_t)diff, timestr); status("[time] %.2lf seconds (%s)\n", diff, timestr); } cortex_destroy(); return ret; }