static void add_clock_to_frame( mlt_producer producer, mlt_frame frame, time_info* info ) { mlt_profile profile = mlt_service_profile( MLT_PRODUCER_SERVICE( producer ) ); mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES( producer ); uint8_t* image = NULL; mlt_image_format format = mlt_image_rgb24a; int size = 0; int width = profile->width; int height = profile->height; int line_width = LINE_WIDTH_RATIO * (width > height ? height : width) / 100; int radius = (width > height ? height : width) / 2; char* direction = mlt_properties_get( producer_properties, "direction" ); int clock_angle = 0; mlt_frame_get_image( frame, &image, &format, &width, &height, 1 ); // Calculate the angle for the clock. int frames = info->frames; if( !strcmp( direction, "down" ) ) { frames = info->fps - info->frames - 1; } clock_angle = (frames + 1) * 360 / info->fps; draw_clock( image, profile, clock_angle, line_width ); draw_cross( image, profile, line_width ); draw_ring( image, profile, ( radius * OUTER_RING_RATIO ) / 100, line_width ); draw_ring( image, profile, ( radius * INNER_RING_RATIO ) / 100, line_width ); size = mlt_image_format_size( format, width, height, NULL ); mlt_frame_set_image( frame, image, size, mlt_pool_release ); }
int main(int ac, char **av) { GR_EVENT event; GR_GC_ID gc; GR_WINDOW_ID pmap; GR_WINDOW_ID window; GR_WINDOW_INFO info; if (GrOpen() < 0) { fprintf(stderr, "cannot open graphics\n"); exit(1); } window = nxCreateAppWindow(&ac, &av, args); gc = GrNewGC(); GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_WINDOW)); GrSetGCBackground(gc, GrGetSysColor(GR_COLOR_WINDOWTEXT)); GrSelectEvents(window, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_UPDATE | GR_EVENT_MASK_CLOSE_REQ); GrGetWindowInfo(window, &info); pmap = resize(info.width, info.height, 0); GrMapWindow(window); while (1) { GrGetNextEventTimeout(&event, 500L); switch (event.type) { case GR_EVENT_TYPE_EXPOSURE: case GR_EVENT_TYPE_TIMEOUT: draw_clock(0, 0, width, height, pmap, gc, window); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); exit(0); case GR_EVENT_TYPE_UPDATE: switch (event.update.utype) { case GR_UPDATE_SIZE: pmap = resize(event.update.width, event.update.height, pmap); break; } } } return 0; }
int main(void) { PixelBone_Matrix* matrix = new PixelBone_Matrix(WIDTH,HEIGHT, MATRIX_TOP + MATRIX_LEFT + MATRIX_ROWS + MATRIX_ZIGZAG); struct tm *now; time_t t_curr; while (true) { /* Update time and draw clock here. */ t_curr = time(NULL); now = localtime(&(t_curr)); draw_clock(matrix, now); matrix->wait(); matrix->show(); matrix->moveToNextBuffer(); } return 0; }
/*######################## draw_mon_button_line() #######################*/ void draw_mon_button_line(void) { XFillRectangle(display, button_window, button_bg_gc, 0, 0, window_width, line_height + 1); XFillRectangle(display, button_pixmap, button_bg_gc, 0, 0, window_width, line_height + 1); /* Draw status LED for AFDMON. */ draw_mon_proc_led(AFDMON_LED, prev_afd_mon_status.afd_mon, -1, -1); /* Draw log status indicators. */ draw_mon_log_status(MON_SYS_LOG_INDICATOR, prev_afd_mon_status.mon_sys_log_ec % LOG_FIFO_SIZE); draw_mon_log_status(MON_LOG_INDICATOR, prev_afd_mon_status.mon_log_ec % LOG_FIFO_SIZE); /* Draw clock. */ draw_clock(time(NULL)); return; }
int main(int argc, char **argv) { int c; /* Alloc ttyclock */ ttyclock = malloc(sizeof(ttyclock_t)); ttyclock->option.date = True; /* Date format */ ttyclock->option.format = malloc(sizeof(char) * 100); /* Default date format */ strncpy(ttyclock->option.format, "%a %d %b %Y", 100); /* Default color */ ttyclock->option.color = COLOR_GREEN; /* COLOR_GREEN = 2 */ /* Default bottom pos */ ttyclock->option.bottom = False; /* Default delay */ ttyclock->option.delay = 40000000; /* 25FPS */ /* Default blink */ ttyclock->option.blink = False; while ((c = getopt(argc, argv, "tvsrcbihf:DBd:C:")) != -1) { switch(c) { case 'h': default: printf("usage : tty-clock [-scbtrvihDB] [-C [0-7]] [-f format] \n" " -s Show seconds \n" " -c Set the clock at the center of the terminal \n" " -b Set the clock at the bottom of the terminal \n" " -C [0-7] Set the clock color \n" " -t Set the hour in 12h format \n" " -r Do rebound the clock \n" " -f format Set the date format \n" " -v Show tty-clock version \n" " -i Show some info about tty-clock \n" " -h Show this page \n" " -d delay Set the delay between two redraws of the clock \n" " -D Hide date \n" " -B Enable blinking colon \n"); free(ttyclock); exit(EXIT_SUCCESS); break; case 'i': puts("TTY-Clock 2 © by Martin Duquesnoy ([email protected])"); free(ttyclock); free(ttyclock->option.format); exit(EXIT_SUCCESS); break; case 'v': puts("TTY-Clock 2 © devel version"); free(ttyclock); free(ttyclock->option.format); exit(EXIT_SUCCESS); break; case 's': ttyclock->option.second = True; break; case 'c': ttyclock->option.center = True; break; case 'b': ttyclock->option.bottom = True; break; case 'C': if(atoi(optarg) >= 0 && atoi(optarg) < 8) ttyclock->option.color = atoi(optarg); break; case 't': ttyclock->option.twelve = True; break; case 'r': ttyclock->option.rebound = True; break; case 'f': strncpy(ttyclock->option.format, optarg, 100); break; case 'd': if(atol(optarg) >= 0 && atol(optarg) < 1000000000) ttyclock->option.delay = atol(optarg); break; case 'D': ttyclock->option.date = False; break; case 'B': ttyclock->option.blink = True; break; } } init(); while(ttyclock->running) { clock_rebound(); update_hour(); draw_clock(); key_event(); } free(ttyclock); free(ttyclock->option.format); endwin(); return 0; }
int main(int argc, char **argv){ int c; /* Alloc ttyclock */ ttyclock = malloc(sizeof(ttyclock_t)); assert(ttyclock != NULL); memset(ttyclock, 0, sizeof(ttyclock_t)); ttyclock->option.date = True; /* Date format */ ttyclock->option.format = malloc(sizeof(char) * 100); /* Default date format */ strncpy(ttyclock->option.format, "%F", 100); /* Default color */ ttyclock->option.color = COLOR_RED; /* Default delay */ ttyclock->option.delay = 1; /* 1FPS */ ttyclock->option.nsdelay = 0; /* -0FPS */ ttyclock->option.blink = False; /* Never show seconds */ ttyclock->option.second = False; /* Hide the date */ ttyclock->option.date = False; atexit(cleanup); while ((c = getopt(argc, argv, "ivcbrhBxnC:d:T:a:")) != -1){ switch(c) { case 'h': default: print_usage(); exit(EXIT_SUCCESS); break; case 'i': puts("TTY-Clock 2 © by Martin Duquesnoy ([email protected]), Grey ([email protected])"); exit(EXIT_SUCCESS); break; case 'v': puts("TTY-Clock 2 © devel version"); exit(EXIT_SUCCESS); break; case 'c': ttyclock->option.center = True; break; case 'b': ttyclock->option.bold = True; break; case 'C': if(atoi(optarg) >= 0 && atoi(optarg) < 8) ttyclock->option.color = atoi(optarg); break; case 'r': ttyclock->option.rebound = True; break; case 'd': if(atol(optarg) >= 0 && atol(optarg) < 100) ttyclock->option.delay = atol(optarg); break; case 'B': ttyclock->option.blink = True; break; case 'a': if(atol(optarg) >= 0 && atol(optarg) < 1000000000) ttyclock->option.nsdelay = atol(optarg); break; case 'x': ttyclock->option.box = True; break; case 'T': { struct stat sbuf; if (stat(optarg, &sbuf) == -1) { fprintf(stderr, "tty-clock: error: couldn't stat '%s': %s.\n", optarg, strerror(errno)); exit(EXIT_FAILURE); } else if (!S_ISCHR(sbuf.st_mode)) { fprintf(stderr, "tty-clock: error: '%s' doesn't appear to be a character device.\n", optarg); exit(EXIT_FAILURE); } else { if (ttyclock->tty) free(ttyclock->tty); ttyclock->tty = strdup(optarg); }} break; case 'n': ttyclock->option.noquit = True; break; } } /* Set the default minutes to 25 */ start_minutes = DEFAULT_TIME; /* Check if short or long break */ if (optind < argc){ char *argument = argv[optind]; if (!strcmp(argument, "short")){ start_minutes = SHORT_BREAK; }else if (!strcmp(argument, "long")){ start_minutes = LONG_BREAK; }else{ printf("Command not recognized\n"); print_usage(); exit(EXIT_FAILURE); } } init(); attron(A_BLINK); while(ttyclock->running){ clock_rebound(); update_hour(); draw_clock(); key_event(); } endwin(); return 0; }
/*######################### check_mon_status() ##########################*/ void check_mon_status(Widget w) { static int loop_timer = 0; static char blink = TR_BAR; static time_t next_minute = 0L; signed char flush = NO; time_t current_time; /* * Check if afd_mon process is still running. */ if (prev_afd_mon_status.afd_mon != p_afd_mon_status->afd_mon) { if (p_afd_mon_status->afd_mon == OFF) { blink_flag = ON; } prev_afd_mon_status.afd_mon = p_afd_mon_status->afd_mon; draw_mon_proc_led(AFDMON_LED, prev_afd_mon_status.afd_mon, -1, -1); flush = YES; } loop_timer += redraw_time_status; if (loop_timer > 20000) { struct stat stat_buf; if (stat(mon_active_file, &stat_buf) == 0) { if (stat_buf.st_mtime != afd_mon_active_time) { int fd; if (pid_list != NULL) { #ifdef HAVE_MMAP (void)munmap((void *)pid_list, afd_mon_active_size); #else (void)munmap_emu((void *)pid_list); #endif } afd_mon_active_time = stat_buf.st_mtime; if ((fd = open(mon_active_file, O_RDWR)) < 0) { pid_list = NULL; } else { #ifdef HAVE_MMAP if ((pid_list = mmap(NULL, stat_buf.st_size, (PROT_READ | PROT_WRITE), MAP_SHARED, fd, 0)) == (caddr_t) -1) #else if ((pid_list = mmap_emu(NULL, stat_buf.st_size, (PROT_READ | PROT_WRITE), MAP_SHARED, mon_active_file, 0)) == (caddr_t) -1) #endif { (void)xrec(ERROR_DIALOG, "mmap() error : %s (%s %d)", strerror(errno), __FILE__, __LINE__); pid_list = NULL; } #ifdef HAVE_MMAP afd_mon_active_size = stat_buf.st_size; #endif if (close(fd) == -1) { system_log(DEBUG_SIGN, __FILE__, __LINE__, "close() error : %s", strerror(errno)); } } } if (pid_list != NULL) { if (*(pid_t *)(pid_list) > 0) { if ((kill(*(pid_t *)(pid_list), 0) == -1) && (p_afd_mon_status->afd_mon == ON)) { /* Process is not alive, but it is in the AFD_ACTIVE file?! */ blink_flag = ON; p_afd_mon_status->afd_mon = OFF; prev_afd_mon_status.afd_mon = p_afd_mon_status->afd_mon; draw_mon_proc_led(AFDMON_LED, prev_afd_mon_status.afd_mon, -1, -1); flush = YES; } } } } } if (blink_flag == ON) { if (prev_afd_mon_status.afd_mon == OFF) { draw_mon_proc_led(AFDMON_LED, blink, -1, -1); flush = YES; } if (blink == TR_BAR) { blink = OFF; } else { blink = TR_BAR; } } /* * See if there is any activity in the log files. */ if (prev_afd_mon_status.mon_sys_log_ec != p_afd_mon_status->mon_sys_log_ec) { prev_afd_mon_status.mon_sys_log_ec = p_afd_mon_status->mon_sys_log_ec; (void)memcpy(prev_afd_mon_status.mon_sys_log_fifo, p_afd_mon_status->mon_sys_log_fifo, LOG_FIFO_SIZE + 1); draw_mon_log_status(MON_SYS_LOG_INDICATOR, prev_afd_mon_status.mon_sys_log_ec % LOG_FIFO_SIZE); flush = YES; } if (prev_afd_mon_status.mon_log_ec != p_afd_mon_status->mon_log_ec) { prev_afd_mon_status.mon_log_ec = p_afd_mon_status->mon_log_ec; (void)memcpy(prev_afd_mon_status.mon_log_fifo, p_afd_mon_status->mon_log_fifo, LOG_FIFO_SIZE + 1); draw_mon_log_status(MON_LOG_INDICATOR, prev_afd_mon_status.mon_log_ec % LOG_FIFO_SIZE); flush = YES; } current_time = time(NULL); if (current_time >= next_minute) { draw_clock(current_time); next_minute = ((current_time / 60) + 1) * 60; } if (flush == YES) { XFlush(display); redraw_time_status = MIN_REDRAW_TIME; } else { if (redraw_time_status < 2000) { redraw_time_status += REDRAW_STEP_TIME; } } /* Redraw every redraw_time ms. */ (void)XtAppAddTimeOut(app, redraw_time_status, (XtTimerCallbackProc)check_mon_status, w); return; }
int main(int argc, char **argv) { int c; /* Alloc ttyclock */ ttyclock = malloc(sizeof(ttyclock_t)); assert(ttyclock != NULL); memset(ttyclock, 0, sizeof(ttyclock_t)); /* Date format */ ttyclock->option.format = malloc(sizeof(char) * 100); /* Default date format */ strncpy(ttyclock->option.format, "%F", 100); /* Default color */ ttyclock->option.color = COLOR_GREEN; /* COLOR_GREEN = 2 */ /* Default delay */ ttyclock->option.delay = 40000000; /* 25FPS */ atexit(cleanup); while ((c = getopt(argc, argv, "tT:nvsSrcihbf:d:C:")) != -1) { switch(c) { case 'h': default: printf("usage : tty-clock [-sSbctrnvih] [-C [0-7]] [-f format] [-d delay] [-T tty] \n" " -s Show seconds \n" " -S Screensaver mode \n" " -b Show box \n" " -c Set the clock at the center of the terminal \n" " -C [0-7] Set the clock color \n" " -t Set the hour in 12h format \n" " -T tty Display the clock on the specified terminal \n" " -r Do rebound the clock \n" " -f format Set the date format \n" " -n Don't quit on keypress \n" " -v Show tty-clock version \n" " -i Show some info about tty-clock \n" " -h Show this page \n" " -d delay Set the delay between two redraws of the clock \n"); exit(EXIT_SUCCESS); break; case 'i': puts("TTY-Clock 2 © by Martin Duquesnoy ([email protected])"); exit(EXIT_SUCCESS); break; case 'v': puts("TTY-Clock 2 © devel version"); exit(EXIT_SUCCESS); break; case 's': ttyclock->option.second = True; break; case 'S': ttyclock->option.screensaver = True; break; case 'c': ttyclock->option.center = True; break; case 'C': if(atoi(optarg) >= 0 && atoi(optarg) < 8) ttyclock->option.color = atoi(optarg); break; case 't': ttyclock->option.twelve = True; break; case 'r': ttyclock->option.rebound = True; break; case 'f': strncpy(ttyclock->option.format, optarg, 100); break; case 'd': if(atol(optarg) >= 0 && atol(optarg) < 1000000000) ttyclock->option.delay = atol(optarg); break; case 'b': ttyclock->option.box = True; break; case 'T': { struct stat sbuf; if (stat(optarg, &sbuf) == -1) { fprintf(stderr, "tty-clock: error: couldn't stat '%s': %s.\n", optarg, strerror(errno)); exit(EXIT_FAILURE); } else if (!S_ISCHR(sbuf.st_mode)) { fprintf(stderr, "tty-clock: error: '%s' doesn't appear to be a character device.\n", optarg); exit(EXIT_FAILURE); } else { if (ttyclock->tty) free(ttyclock->tty); ttyclock->tty = strdup(optarg); } } break; case 'n': ttyclock->option.noquit = True; break; } } init(); while(ttyclock->running) { clock_rebound(); update_hour(); draw_clock(); key_event(); } endwin(); return 0; }