Changeset 4800
- Timestamp:
- 01/11/12 16:44:37 (18 months ago)
- Location:
- libcaca/trunk
- Files:
-
- 2 edited
-
python/caca/canvas.py (modified) (1 diff)
-
src/cacaclock.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/python/caca/canvas.py
r4776 r4800 1546 1546 1547 1547 def set_figfont(self, filename): 1548 """ Load a figfont and attach it to a canvas.1548 """ Load a figfont and attach it to a canvas. 1549 1549 1550 1550 filename -- the figfont file to load. -
libcaca/trunk/src/cacaclock.c
r4787 r4800 26 26 static void usage(int argc, char **argv) 27 27 { 28 fprintf(stderr, "Usage: %s [OPTIONS]...\n", argv[0]);29 fprintf(stderr, "Display current time in text mode (q to quit)\n");30 fprintf(stderr, "Example : %s -d '%%R'\n\n", argv[0]);31 fprintf(stderr, "Options:\n");32 fprintf(stderr, " -h, --help\t\t\tThis help\n");33 fprintf(stderr, " -v, --version\t\t\tVersion of the program\n");34 fprintf(stderr, " -f, --font=FONT\t\tUse FONT for time display\n");35 fprintf(stderr, " -d, --dateformat=FORMAT\tUse FORMAT as strftime argument (default %%R:%%S)\n");28 fprintf(stderr, "Usage: %s [OPTIONS]...\n", argv[0]); 29 fprintf(stderr, "Display current time in text mode (q to quit)\n"); 30 fprintf(stderr, "Example : %s -d '%%R'\n\n", argv[0]); 31 fprintf(stderr, "Options:\n"); 32 fprintf(stderr, " -h, --help\t\t\tThis help\n"); 33 fprintf(stderr, " -v, --version\t\t\tVersion of the program\n"); 34 fprintf(stderr, " -f, --font=FONT\t\tUse FONT for time display\n"); 35 fprintf(stderr, " -d, --dateformat=FORMAT\tUse FORMAT as strftime argument (default %%R:%%S)\n"); 36 36 } 37 37 … … 39 39 static void version(void) 40 40 { 41 printf(42 "cacaclock Copyright 2011 Jean-Yves Lamoureux\n"43 "Internet: <jylam@lnxscene.org> Version: %s (libcaca %s), date: %s\n"44 "\n"45 "cacaclock, along with its documentation, may be freely copied and distributed.\n"46 "\n"47 "The latest version of cacaclock is available from the web site,\n"48 " http://caca.zoy.org/wiki/libcaca in the libcaca package.\n"49 "\n",50 CACACLOCKVERSION, caca_get_version(), __DATE__);41 printf( 42 "cacaclock Copyright 2011 Jean-Yves Lamoureux\n" 43 "Internet: <jylam@lnxscene.org> Version: %s (libcaca %s), date: %s\n" 44 "\n" 45 "cacaclock, along with its documentation, may be freely copied and distributed.\n" 46 "\n" 47 "The latest version of cacaclock is available from the web site,\n" 48 " http://caca.zoy.org/wiki/libcaca in the libcaca package.\n" 49 "\n", 50 CACACLOCKVERSION, caca_get_version(), __DATE__); 51 51 } 52 52 53 53 54 54 static char* get_date(char *format) { 55 time_t currtime;56 char *charTime = malloc(101);55 time_t currtime; 56 char *charTime = malloc(101); 57 57 58 time(&currtime);59 strftime(charTime, 100,format,localtime(&currtime));58 time(&currtime); 59 strftime(charTime, 100,format,localtime(&currtime)); 60 60 61 return charTime;61 return charTime; 62 62 } 63 63 64 64 int main(int argc, char *argv[]) { 65 65 66 caca_canvas_t *cv;67 caca_canvas_t *figcv;68 caca_display_t *dp;69 uint32_t w, h, fw, fh;66 caca_canvas_t *cv; 67 caca_canvas_t *figcv; 68 caca_display_t *dp; 69 uint32_t w, h, fw, fh; 70 70 71 char *format = "%R:%S";72 char *font = "/usr/share/figlet/mono12.tlf";71 char *format = "%R:%S"; 72 char *font = "/usr/share/figlet/mono12.tlf"; 73 73 74 74 75 for(;;)76 {77 int option_index = 0;78 static struct caca_option long_options[] =79 {80 { "font", 1, NULL, 'f' },81 { "dateformat", 1, NULL, 'd' },82 { "help", 0, NULL, 'h' },83 { "version", 0, NULL, 'v' },84 };85 int c = caca_getopt(argc, argv, "f:d:hv",86 long_options, &option_index);87 if(c == -1)88 break;75 for(;;) 76 { 77 int option_index = 0; 78 static struct caca_option long_options[] = 79 { 80 { "font", 1, NULL, 'f' }, 81 { "dateformat", 1, NULL, 'd' }, 82 { "help", 0, NULL, 'h' }, 83 { "version", 0, NULL, 'v' }, 84 }; 85 int c = caca_getopt(argc, argv, "f:d:hv", 86 long_options, &option_index); 87 if(c == -1) 88 break; 89 89 90 switch(c)91 {92 case 'h': /* --help */93 usage(argc, argv);94 return 0;95 break;96 case 'v': /* --version */97 version();98 return 0;99 break;100 case 'f': /* --font */101 font = caca_optarg;102 break;103 case 'd': /* --dateformat */104 format = caca_optarg;105 break;106 default:107 return 1;108 break;109 }110 }90 switch(c) 91 { 92 case 'h': /* --help */ 93 usage(argc, argv); 94 return 0; 95 break; 96 case 'v': /* --version */ 97 version(); 98 return 0; 99 break; 100 case 'f': /* --font */ 101 font = caca_optarg; 102 break; 103 case 'd': /* --dateformat */ 104 format = caca_optarg; 105 break; 106 default: 107 return 1; 108 break; 109 } 110 } 111 111 112 112 113 113 114 cv = caca_create_canvas(0, 0);115 figcv = caca_create_canvas(0, 0);116 if(!cv || !figcv)117 {118 fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]);119 return 1;120 }114 cv = caca_create_canvas(0, 0); 115 figcv = caca_create_canvas(0, 0); 116 if(!cv || !figcv) 117 { 118 fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]); 119 return 1; 120 } 121 121 122 if(caca_canvas_set_figfont(figcv, font))123 {124 fprintf(stderr, "Could not open font\n");125 return -1;126 }122 if(caca_canvas_set_figfont(figcv, font)) 123 { 124 fprintf(stderr, "Could not open font\n"); 125 return -1; 126 } 127 127 128 128 129 dp = caca_create_display(cv);130 if(!dp) {131 printf("Can't open window. CACA_DRIVER problem ?\n");132 return -1;133 }129 dp = caca_create_display(cv); 130 if(!dp) { 131 printf("Can't open window. CACA_DRIVER problem ?\n"); 132 return -1; 133 } 134 134 135 caca_set_color_ansi(figcv, CACA_DEFAULT, CACA_DEFAULT);136 caca_clear_canvas(cv);137 for(;;) {138 caca_event_t ev;135 caca_set_color_ansi(figcv, CACA_DEFAULT, CACA_DEFAULT); 136 caca_clear_canvas(cv); 137 for(;;) { 138 caca_event_t ev; 139 139 140 while(caca_get_event(dp, CACA_EVENT_KEY_PRESS141 | CACA_EVENT_QUIT, &ev, 1))142 {143 if(caca_get_event_type(&ev))144 goto end;145 }146 char *d = get_date(format);147 uint32_t o = 0;140 while(caca_get_event(dp, CACA_EVENT_KEY_PRESS 141 | CACA_EVENT_QUIT, &ev, 1)) 142 { 143 if(caca_get_event_type(&ev)) 144 goto end; 145 } 146 char *d = get_date(format); 147 uint32_t o = 0; 148 148 149 // figfont API is not complete, and does not allow us to put a string150 // at another position than 0,0151 // So, we have to create a canvas which will hold the figfont string,152 // then blit this canvas to the main one at the desired position.153 caca_clear_canvas(cv);154 caca_clear_canvas(figcv);155 while(d[o])156 {157 caca_put_figchar(figcv, d[o++]);158 }159 caca_flush_figlet (figcv);160 free(d);149 // figfont API is not complete, and does not allow us to put a string 150 // at another position than 0,0 151 // So, we have to create a canvas which will hold the figfont string, 152 // then blit this canvas to the main one at the desired position. 153 caca_clear_canvas(cv); 154 caca_clear_canvas(figcv); 155 while(d[o]) 156 { 157 caca_put_figchar(figcv, d[o++]); 158 } 159 caca_flush_figlet (figcv); 160 free(d); 161 161 162 w = caca_get_canvas_width (cv);163 h = caca_get_canvas_height(cv);162 w = caca_get_canvas_width (cv); 163 h = caca_get_canvas_height(cv); 164 164 fw = caca_get_canvas_width (figcv); 165 fh = caca_get_canvas_height(figcv); 165 fh = caca_get_canvas_height(figcv); 166 166 167 uint32_t x = (w/2) - (fw/2);168 uint32_t y = (h/2) - (fh/2);167 uint32_t x = (w/2) - (fw/2); 168 uint32_t y = (h/2) - (fh/2); 169 169 170 caca_blit(cv, x, y, figcv, NULL);171 caca_refresh_display(dp);172 usleep(250000);173 }170 caca_blit(cv, x, y, figcv, NULL); 171 caca_refresh_display(dp); 172 usleep(250000); 173 } 174 174 end: 175 175 176 caca_free_canvas(figcv);177 caca_free_canvas(cv);178 caca_free_display(dp);176 caca_free_canvas(figcv); 177 caca_free_canvas(cv); 178 caca_free_display(dp); 179 179 180 return 0;180 return 0; 181 181 }
Note: See TracChangeset
for help on using the changeset viewer.
