Bladeren bron

* Added preliminary cacaclock, a continuous clock

tags/v0.99.beta18
Jean-Yves Lamoureux jylam 13 jaren geleden
bovenliggende
commit
41f434f05b
2 gewijzigde bestanden met toevoegingen van 110 en 1 verwijderingen
  1. +5
    -1
      src/Makefile.am
  2. +105
    -0
      src/cacaclock.c

+ 5
- 1
src/Makefile.am Bestand weergeven

@@ -5,7 +5,7 @@ EXTRA_DIST = caca.txt cacademo.vcproj cacafire.vcproj cacaview.vcproj
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/caca -I../caca \
-DLIBCACA=1 -DX_DISPLAY_MISSING=1

bin_PROGRAMS = cacademo cacafire cacaplay cacaview img2txt $(fcntl_programs)
bin_PROGRAMS = cacademo cacafire cacaplay cacaview img2txt cacaclock $(fcntl_programs)
noinst_PROGRAMS = cacadraw

cacademo_SOURCES = cacademo.c texture.h
@@ -29,6 +29,10 @@ cacaplay_LDADD = ../caca/libcaca.la ../caca/libcaca.la
cacaserver_SOURCES = cacaserver.c
cacaserver_LDADD = ../caca/libcaca.la

cacaclock_SOURCES = cacaclock.c
cacaclock_LDADD = ../caca/libcaca.la


img2txt_SOURCES = img2txt.c $(GETOPT) common-image.c common-image.h
img2txt_LDADD = ../caca/libcaca.la
img2txt_CFLAGS = $(IMLIB2_CFLAGS)


+ 105
- 0
src/cacaclock.c Bestand weergeven

@@ -0,0 +1,105 @@
/*
* cacaclock Text-mode clock display
* Copyright (c) 2011 Jean-Yves Lamoureux <jylam@lnxscene.org>
* All Rights Reserved
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/

#include "config.h"

#if !defined(__KERNEL__)
# include <time.h>
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
#endif

#include "caca.h"

#define CACACLOCKVERSION "0.1"


static char* get_date(void) {
time_t currtime;
char *charTime = malloc(101);

time(&currtime);
strftime(charTime, 100,"%R:%S",localtime(&currtime));

return charTime;
}

int main(int argc, char *argv[]) {

caca_canvas_t *cv;
caca_canvas_t *figcv;
caca_display_t *dp;

char *font = "/usr/share/figlet/mono12.tlf";
if(argc==2) font = argv[1];


cv = caca_create_canvas(0, 0);
figcv = caca_create_canvas(0, 0);
if(!cv || !figcv)
{
fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]);
return 1;
}

if(caca_canvas_set_figfont(figcv, font))
{
fprintf(stderr, "Could not open font\n");
return -1;
}


dp = caca_create_display(cv);
if(!dp) {
printf("Can't open window. CACA_DRIVER problem ?\n");
return -1;
}

for(;;) {
caca_event_t ev;

while(caca_get_event(dp, CACA_EVENT_KEY_PRESS
| CACA_EVENT_QUIT, &ev, 1))
{
if(caca_get_event_type(&ev))
goto end;
}
char *d = get_date();
uint32_t o = 0;

// figfont API is not complete, and does not alloq us to put a string
// at another position than 0,0
// So, we have to create a canvas which will hold the figfont string,
// then blit this canvas to the main one at the desired position.
caca_clear_canvas(cv);
caca_clear_canvas(figcv);
while(d[o])
{
caca_set_color_ansi(figcv, CACA_WHITE, CACA_TRANSPARENT);
caca_put_figchar(figcv, d[o++]);
}
caca_flush_figlet (figcv);
free(d);
//TODO center etc.
caca_blit(cv, 0, 0, figcv, NULL);
caca_refresh_display(dp);
usleep(250000);
}
end:

caca_free_canvas(figcv);
caca_free_canvas(cv);
caca_free_display(dp);

return 0;
}

Laden…
Annuleren
Opslaan