* Center fonttags/v0.99.beta18
@@ -33,6 +33,7 @@ | |||||
E64A331D10DA447500325A66 /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = config.h; path = ../config.h; sourceTree = SOURCE_ROOT; }; | E64A331D10DA447500325A66 /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = config.h; path = ../config.h; sourceTree = SOURCE_ROOT; }; | ||||
E64A33E410DA861600325A66 /* klibc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = klibc.c; sourceTree = "<group>"; }; | E64A33E410DA861600325A66 /* klibc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = klibc.c; sourceTree = "<group>"; }; | ||||
E68A871110CD1F040047EB17 /* mouse.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = mouse.c; path = ../examples/mouse.c; sourceTree = SOURCE_ROOT; }; | E68A871110CD1F040047EB17 /* mouse.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = mouse.c; path = ../examples/mouse.c; sourceTree = SOURCE_ROOT; }; | ||||
E68B916D13237280006B282B /* cacaclock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cacaclock.c; path = ../src/cacaclock.c; sourceTree = SOURCE_ROOT; }; | |||||
E6A7681710B560BB008B6DEC /* caca++.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "caca++.cpp"; path = "../cxx/caca++.cpp"; sourceTree = SOURCE_ROOT; }; | E6A7681710B560BB008B6DEC /* caca++.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "caca++.cpp"; path = "../cxx/caca++.cpp"; sourceTree = SOURCE_ROOT; }; | ||||
E6A7681810B560BB008B6DEC /* caca++.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "caca++.h"; path = "../cxx/caca++.h"; sourceTree = SOURCE_ROOT; }; | E6A7681810B560BB008B6DEC /* caca++.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "caca++.h"; path = "../cxx/caca++.h"; sourceTree = SOURCE_ROOT; }; | ||||
E6A7681910B560BB008B6DEC /* cxxtest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = cxxtest.cpp; path = ../cxx/cxxtest.cpp; sourceTree = SOURCE_ROOT; }; | E6A7681910B560BB008B6DEC /* cxxtest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = cxxtest.cpp; path = ../cxx/cxxtest.cpp; sourceTree = SOURCE_ROOT; }; | ||||
@@ -99,8 +100,6 @@ | |||||
E6DB663210AECCD700B6F924 /* common-image.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "common-image.c"; path = "../src/common-image.c"; sourceTree = SOURCE_ROOT; }; | E6DB663210AECCD700B6F924 /* common-image.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "common-image.c"; path = "../src/common-image.c"; sourceTree = SOURCE_ROOT; }; | ||||
E6DB663310AECCD700B6F924 /* common-image.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "common-image.h"; path = "../src/common-image.h"; sourceTree = SOURCE_ROOT; }; | E6DB663310AECCD700B6F924 /* common-image.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "common-image.h"; path = "../src/common-image.h"; sourceTree = SOURCE_ROOT; }; | ||||
E6DB663410AECCD700B6F924 /* img2txt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = img2txt.c; path = ../src/img2txt.c; sourceTree = SOURCE_ROOT; }; | E6DB663410AECCD700B6F924 /* img2txt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = img2txt.c; path = ../src/img2txt.c; sourceTree = SOURCE_ROOT; }; | ||||
E6DB663510AECCD700B6F924 /* mygetopt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = mygetopt.c; path = ../src/mygetopt.c; sourceTree = SOURCE_ROOT; }; | |||||
E6DB663610AECCD700B6F924 /* mygetopt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = mygetopt.h; path = ../src/mygetopt.h; sourceTree = SOURCE_ROOT; }; | |||||
E6DB663710AECCD700B6F924 /* texture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = texture.h; path = ../src/texture.h; sourceTree = SOURCE_ROOT; }; | E6DB663710AECCD700B6F924 /* texture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = texture.h; path = ../src/texture.h; sourceTree = SOURCE_ROOT; }; | ||||
E6DB663910AECD1F00B6F924 /* trifiller.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = trifiller.c; path = ../examples/trifiller.c; sourceTree = SOURCE_ROOT; wrapsLines = 0; }; | E6DB663910AECD1F00B6F924 /* trifiller.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = trifiller.c; path = ../examples/trifiller.c; sourceTree = SOURCE_ROOT; wrapsLines = 0; }; | ||||
E6DB663B10AECDF500B6F924 /* blit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = blit.c; path = ../examples/blit.c; sourceTree = SOURCE_ROOT; }; | E6DB663B10AECDF500B6F924 /* blit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = blit.c; path = ../examples/blit.c; sourceTree = SOURCE_ROOT; }; | ||||
@@ -299,6 +298,7 @@ | |||||
E6DB662B10AECCBF00B6F924 /* src */ = { | E6DB662B10AECCBF00B6F924 /* src */ = { | ||||
isa = PBXGroup; | isa = PBXGroup; | ||||
children = ( | children = ( | ||||
E68B916D13237280006B282B /* cacaclock.c */, | |||||
E6DB66FF10B17BEA00B6F924 /* Makefile.am */, | E6DB66FF10B17BEA00B6F924 /* Makefile.am */, | ||||
E6DB662C10AECCD700B6F924 /* aafire.c */, | E6DB662C10AECCD700B6F924 /* aafire.c */, | ||||
E6DB662D10AECCD700B6F924 /* cacademo.c */, | E6DB662D10AECCD700B6F924 /* cacademo.c */, | ||||
@@ -309,8 +309,6 @@ | |||||
E6DB663210AECCD700B6F924 /* common-image.c */, | E6DB663210AECCD700B6F924 /* common-image.c */, | ||||
E6DB663310AECCD700B6F924 /* common-image.h */, | E6DB663310AECCD700B6F924 /* common-image.h */, | ||||
E6DB663410AECCD700B6F924 /* img2txt.c */, | E6DB663410AECCD700B6F924 /* img2txt.c */, | ||||
E6DB663510AECCD700B6F924 /* mygetopt.c */, | |||||
E6DB663610AECCD700B6F924 /* mygetopt.h */, | |||||
E6DB663710AECCD700B6F924 /* texture.h */, | E6DB663710AECCD700B6F924 /* texture.h */, | ||||
); | ); | ||||
name = src; | name = src; | ||||
@@ -268,14 +268,14 @@ if test "${enable_cocoa}" != "no"; then | |||||
x*86_64*darwin*) | x*86_64*darwin*) | ||||
MACOSX_SDK="${MACOSX_SDK:-/Developer/SDKs/MacOSX10.5.sdk}" | MACOSX_SDK="${MACOSX_SDK:-/Developer/SDKs/MacOSX10.5.sdk}" | ||||
GCC_VERSION="${GCC_VERSION:-4.0}" | GCC_VERSION="${GCC_VERSION:-4.0}" | ||||
ARCH="${ARCH:--arch i386}" | |||||
ARCH="${ARCH:--arch x86_64}" | |||||
MACOSX_SDK_CFLAGS="${MACOSX_SDK_CFLAGS:--isysroot ${MACOSX_SDK}}" | MACOSX_SDK_CFLAGS="${MACOSX_SDK_CFLAGS:--isysroot ${MACOSX_SDK}}" | ||||
MACOSX_SDK_CXXFLAGS="${MACOSX_SDK_CXXFLAGS:-${MACOSX_SDK_CFLAGS}}" | MACOSX_SDK_CXXFLAGS="${MACOSX_SDK_CXXFLAGS:-${MACOSX_SDK_CFLAGS}}" | ||||
;; | ;; | ||||
x*86*darwin*) | x*86*darwin*) | ||||
MACOSX_SDK="${MACOSX_SDK:-/Developer/SDKs/MacOSX10.6.sdk}" | MACOSX_SDK="${MACOSX_SDK:-/Developer/SDKs/MacOSX10.6.sdk}" | ||||
GCC_VERSION="${GCC_VERSION:-4.0}" | GCC_VERSION="${GCC_VERSION:-4.0}" | ||||
ARCH="${ARCH:--arch i386}" | |||||
ARCH="${ARCH:--arch x86_64}" | |||||
MACOSX_SDK_CFLAGS="${MACOSX_SDK_CFLAGS:--isysroot ${MACOSX_SDK}}" | MACOSX_SDK_CFLAGS="${MACOSX_SDK_CFLAGS:--isysroot ${MACOSX_SDK}}" | ||||
MACOSX_SDK_CXXFLAGS="${MACOSX_SDK_CXXFLAGS:-${MACOSX_SDK_CFLAGS}}" | MACOSX_SDK_CXXFLAGS="${MACOSX_SDK_CXXFLAGS:-${MACOSX_SDK_CFLAGS}}" | ||||
;; | ;; | ||||
@@ -284,9 +284,9 @@ if test "${enable_cocoa}" != "no"; then | |||||
CXX="${CXX:-g++-${GCC_VERSION}}" | CXX="${CXX:-g++-${GCC_VERSION}}" | ||||
MACOSX_SDK_FRAMEWORKS="${MACOSX_SDK_FRAMEWORKS:--F${MACOSX_SDK}/System/Library/Frameworks}" | MACOSX_SDK_FRAMEWORKS="${MACOSX_SDK_FRAMEWORKS:--F${MACOSX_SDK}/System/Library/Frameworks}" | ||||
CPPFLAGS="${CPPFLAGS} ${ARCH} ${MACOSX_SDK_FRAMEWORKS}" | CPPFLAGS="${CPPFLAGS} ${ARCH} ${MACOSX_SDK_FRAMEWORKS}" | ||||
CFLAGS="${CFLAGS} ${MACOSX_SDK_CFLAGS}" | |||||
CXXFLAGS="${CXXFLAGS} ${MACOSX_SDK_CXXFLAGS}" | |||||
OBJCFLAGS="${OBJCFLAGS} ${MACOSX_SDK_CFLAGS}" | |||||
CFLAGS="${CFLAGS} ${MACOSX_SDK_CFLAGS} -mmacosx-version-min=10.5" | |||||
CXXFLAGS="${CXXFLAGS} ${MACOSX_SDK_CXXFLAGS} -mmacosx-version-min=10.5" | |||||
OBJCFLAGS="${OBJCFLAGS} ${MACOSX_SDK_CFLAGS} -mmacosx-version-min=10.5" | |||||
LDFLAGS="${ARCH} ${MACOSX_SDK_LDFLAGS} ${LDFLAGS}" | LDFLAGS="${ARCH} ${MACOSX_SDK_LDFLAGS} ${LDFLAGS}" | ||||
AC_DEFINE(USE_COCOA, 1, Define to 1 to activate the Cocoa backend driver) | AC_DEFINE(USE_COCOA, 1, Define to 1 to activate the Cocoa backend driver) | ||||
CACA_LIBS="${CACA_LIBS} -Wl,-syslibroot,${MACOSX_SDK},-framework,Cocoa" | CACA_LIBS="${CACA_LIBS} -Wl,-syslibroot,${MACOSX_SDK},-framework,Cocoa" | ||||
@@ -23,13 +23,43 @@ | |||||
#define CACACLOCKVERSION "0.1" | #define CACACLOCKVERSION "0.1" | ||||
static void usage(int argc, char **argv) | |||||
{ | |||||
char const * const * list; | |||||
fprintf(stderr, "Usage: %s [OPTIONS]... <IMAGE>\n", argv[0]); | |||||
fprintf(stderr, "Convert IMAGE to any text based available format.\n"); | |||||
fprintf(stderr, "Example : %s -w 80 -f ansi ./caca.png\n\n", argv[0]); | |||||
fprintf(stderr, "Options:\n"); | |||||
fprintf(stderr, " -h, --help\t\t\tThis help\n"); | |||||
fprintf(stderr, " -v, --version\t\t\tVersion of the program\n"); | |||||
fprintf(stderr, " -f, --font=FONT\t\tUse FONT for time display\n"); | |||||
fprintf(stderr, " -d, --dateformat=FORMAT\tUse FORMAT as strftime argument (default %%R:%%S)\n"); | |||||
} | |||||
static void version(void) | |||||
{ | |||||
printf( | |||||
"cacaclock Copyright 2011 Jean-Yves Lamoureux\n" | |||||
"Internet: <jylam@lnxscene.org> Version: %s (libcaca %s), date: %s\n" | |||||
"\n" | |||||
"cacaclock, along with its documentation, may be freely copied and distributed.\n" | |||||
"\n" | |||||
"The latest version of cacaclock is available from the web site,\n" | |||||
" http://caca.zoy.org/wiki/libcaca in the libcaca package.\n" | |||||
"\n", | |||||
CACACLOCKVERSION, caca_get_version(), __DATE__); | |||||
} | |||||
static char* get_date(void) { | |||||
static char* get_date(char *format) { | |||||
time_t currtime; | time_t currtime; | ||||
char *charTime = malloc(101); | char *charTime = malloc(101); | ||||
time(&currtime); | time(&currtime); | ||||
strftime(charTime, 100,"%R:%S",localtime(&currtime)); | |||||
strftime(charTime, 100,format,localtime(&currtime)); | |||||
return charTime; | return charTime; | ||||
} | } | ||||
@@ -39,11 +69,49 @@ int main(int argc, char *argv[]) { | |||||
caca_canvas_t *cv; | caca_canvas_t *cv; | ||||
caca_canvas_t *figcv; | caca_canvas_t *figcv; | ||||
caca_display_t *dp; | caca_display_t *dp; | ||||
uint32_t w, h; | |||||
uint32_t w, h, fw, fh; | |||||
char *format = "%R:%S"; | |||||
char *font = "/usr/share/figlet/mono12.tlf"; | |||||
for(;;) | |||||
{ | |||||
int option_index = 0; | |||||
static struct caca_option long_options[] = | |||||
{ | |||||
{ "font", 1, NULL, 'f' }, | |||||
{ "dateformat", 1, NULL, 'd' }, | |||||
{ "help", 0, NULL, 'h' }, | |||||
{ "version", 0, NULL, 'v' }, | |||||
}; | |||||
int c = caca_getopt(argc, argv, "f:d:hv", | |||||
long_options, &option_index); | |||||
if(c == -1) | |||||
break; | |||||
switch(c) | |||||
{ | |||||
case 'h': /* --help */ | |||||
usage(argc, argv); | |||||
return 0; | |||||
break; | |||||
case 'v': /* --version */ | |||||
version(); | |||||
return 0; | |||||
break; | |||||
case 'f': /* --font */ | |||||
font = caca_optarg; | |||||
break; | |||||
case 'd': /* --dateformat */ | |||||
format = caca_optarg; | |||||
break; | |||||
default: | |||||
return 1; | |||||
break; | |||||
} | |||||
} | |||||
char *font = "/usr/share/figlet/mono12.tlf"; | |||||
if(argc==2) font = argv[1]; | |||||
cv = caca_create_canvas(0, 0); | cv = caca_create_canvas(0, 0); | ||||
@@ -67,9 +135,8 @@ int main(int argc, char *argv[]) { | |||||
return -1; | return -1; | ||||
} | } | ||||
w = caca_get_canvas_width (cv); | |||||
h = caca_get_canvas_height(cv); | |||||
caca_set_color_ansi(figcv, CACA_DEFAULT, CACA_DEFAULT); | |||||
caca_clear_canvas(cv); | |||||
for(;;) { | for(;;) { | ||||
caca_event_t ev; | caca_event_t ev; | ||||
@@ -79,7 +146,7 @@ int main(int argc, char *argv[]) { | |||||
if(caca_get_event_type(&ev)) | if(caca_get_event_type(&ev)) | ||||
goto end; | goto end; | ||||
} | } | ||||
char *d = get_date(); | |||||
char *d = get_date(format); | |||||
uint32_t o = 0; | uint32_t o = 0; | ||||
// figfont API is not complete, and does not alloq us to put a string | // figfont API is not complete, and does not alloq us to put a string | ||||
@@ -90,13 +157,20 @@ int main(int argc, char *argv[]) { | |||||
caca_clear_canvas(figcv); | caca_clear_canvas(figcv); | ||||
while(d[o]) | while(d[o]) | ||||
{ | { | ||||
caca_set_color_ansi(figcv, CACA_WHITE, CACA_TRANSPARENT); | |||||
caca_put_figchar(figcv, d[o++]); | caca_put_figchar(figcv, d[o++]); | ||||
} | } | ||||
caca_flush_figlet (figcv); | caca_flush_figlet (figcv); | ||||
fw = caca_get_canvas_width (figcv); | |||||
fh = caca_get_canvas_height(figcv); | |||||
free(d); | free(d); | ||||
//TODO center etc. | |||||
caca_blit(cv, 0, 0, figcv, NULL); | |||||
w = caca_get_canvas_width (cv); | |||||
h = caca_get_canvas_height(cv); | |||||
uint32_t x = (w/2) - (fw/2); | |||||
uint32_t y = (h/2) - (fh/2); | |||||
caca_blit(cv, x, y, figcv, NULL); | |||||
caca_refresh_display(dp); | caca_refresh_display(dp); | ||||
usleep(250000); | usleep(250000); | ||||
} | } | ||||