Changeset 185 for libcaca/trunk/libcaca
- Timestamp:
- Nov 16, 2003, 1:33:35 AM (19 years ago)
- Location:
- libcaca/trunk/libcaca
- Files:
-
- 10 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/libcaca/Makefile.am
r183 r185 1 1 ############################################################################### 2 # Automake targets and declarations for lib ee2 # Automake targets and declarations for libcaca 3 3 ############################################################################### 4 4 5 lib_LIBRARIES = lib ee.a6 lib ee_a_SOURCES = \7 ee.c \8 ee.h \9 ee_internals.h \5 lib_LIBRARIES = libcaca.a 6 libcaca_a_SOURCES = \ 7 caca.c \ 8 caca.h \ 9 caca_internals.h \ 10 10 graphics.c \ 11 11 io.c \ -
libcaca/trunk/libcaca/blit.c
r183 r185 1 1 /* 2 * lib eeASCII-Art library2 * libcaca ASCII-Art library 3 3 * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> 4 4 * All Rights Reserved … … 31 31 #include <stdlib.h> 32 32 33 #include " ee.h"34 #include " ee_internals.h"33 #include "caca.h" 34 #include "caca_internals.h" 35 35 36 36 #include <stdio.h> 37 void ee_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h)37 void caca_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h) 38 38 { 39 39 char foo[] = { ' ', '.', ':', ';', '=', '$', '%', '@', '#', '8', 'W' }; … … 52 52 pitch = (3 * w + 3) / 4 * 4; 53 53 54 for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= ee_get_height(); y++)55 for(x = x1 > 0 ? x1 : 0; x <= x2 && x <= ee_get_width(); x++)54 for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= caca_get_height(); y++) 55 for(x = x1 > 0 ? x1 : 0; x <= x2 && x <= caca_get_width(); x++) 56 56 { 57 57 int fromx = w * (x - x1) / (x2 - x1 + 1); … … 63 63 if(r == g && g == b) 64 64 { 65 ee_set_color(EE_LIGHTGRAY);65 caca_set_color(EE_LIGHTGRAY); 66 66 } 67 67 else … … 89 89 hue += 360; 90 90 91 ee_set_color(foo_colors[(int)(hue + 30) / 60]);91 caca_set_color(foo_colors[(int)(hue + 30) / 60]); 92 92 } 93 93 else 94 94 { 95 ee_set_color(EE_LIGHTGRAY);95 caca_set_color(EE_LIGHTGRAY); 96 96 } 97 97 } 98 98 99 ee_putchar(x, y, foo[(r + g + b) / 3 / 25]);99 caca_putchar(x, y, foo[(r + g + b) / 3 / 25]); 100 100 } 101 101 } -
libcaca/trunk/libcaca/box.c
r159 r185 1 1 /* 2 * lib eeASCII-Art library2 * libcaca ASCII-Art library 3 3 * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> 4 4 * All Rights Reserved … … 25 25 #include <stdlib.h> 26 26 27 #include " ee.h"28 #include " ee_internals.h"27 #include "caca.h" 28 #include "caca_internals.h" 29 29 30 void ee_draw_box(int x1, int y1, int x2, int y2, char c)30 void caca_draw_box(int x1, int y1, int x2, int y2, char c) 31 31 { 32 ee_draw_line(x1, y1, x1, y2, c);33 ee_draw_line(x1, y2, x2, y2, c);34 ee_draw_line(x2, y2, x2, y1, c);35 ee_draw_line(x2, y1, x1, y1, c);32 caca_draw_line(x1, y1, x1, y2, c); 33 caca_draw_line(x1, y2, x2, y2, c); 34 caca_draw_line(x2, y2, x2, y1, c); 35 caca_draw_line(x2, y1, x1, y1, c); 36 36 } 37 37 38 void ee_draw_thin_box(int x1, int y1, int x2, int y2)38 void caca_draw_thin_box(int x1, int y1, int x2, int y2) 39 39 { 40 40 int x, y, xmax, ymax; … … 52 52 } 53 53 54 xmax = ee_get_width() - 1;55 ymax = ee_get_height() - 1;54 xmax = caca_get_width() - 1; 55 ymax = caca_get_height() - 1; 56 56 57 57 if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) … … 61 61 if(y1 >= 0) 62 62 for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) 63 ee_putchar(x, y1, '-');63 caca_putchar(x, y1, '-'); 64 64 65 65 if(y2 <= ymax) 66 66 for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) 67 ee_putchar(x, y2, '-');67 caca_putchar(x, y2, '-'); 68 68 69 69 if(x1 >= 0) 70 70 for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) 71 ee_putchar(x1, y, '|');71 caca_putchar(x1, y, '|'); 72 72 73 73 if(x2 <= xmax) 74 74 for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) 75 ee_putchar(x2, y, '|');75 caca_putchar(x2, y, '|'); 76 76 77 77 /* Draw corners */ 78 78 if(x1 >= 0 && y1 >= 0) 79 ee_putchar(x1, y1, ',');79 caca_putchar(x1, y1, ','); 80 80 81 81 if(x1 >= 0 && y2 <= ymax) 82 ee_putchar(x1, y2, '`');82 caca_putchar(x1, y2, '`'); 83 83 84 84 if(x2 <= xmax && y1 >= 0) 85 ee_putchar(x2, y1, '.');85 caca_putchar(x2, y1, '.'); 86 86 87 87 if(x2 <= xmax && y2 <= ymax) 88 ee_putchar(x2, y2, '\'');88 caca_putchar(x2, y2, '\''); 89 89 } 90 90 91 void ee_fill_box(int x1, int y1, int x2, int y2, char c)91 void caca_fill_box(int x1, int y1, int x2, int y2, char c) 92 92 { 93 93 int x, y, xmax, ymax; … … 105 105 } 106 106 107 xmax = ee_get_width() - 1;108 ymax = ee_get_height() - 1;107 xmax = caca_get_width() - 1; 108 ymax = caca_get_height() - 1; 109 109 110 110 if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) … … 118 118 for(y = y1; y <= y2; y++) 119 119 for(x = x1; x <= x2; x++) 120 ee_putchar(x, y, c);120 caca_putchar(x, y, c); 121 121 } 122 122 -
libcaca/trunk/libcaca/caca.c
r184 r185 1 1 /* 2 * lib eeASCII-Art library2 * libcaca ASCII-Art library 3 3 * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> 4 4 * All Rights Reserved … … 43 43 #include <time.h> 44 44 45 #include " ee.h"46 #include " ee_internals.h"47 48 static unsigned int _ ee_delay;49 static unsigned int _ ee_rendertime;50 char *_ ee_empty_line;51 char *_ ee_scratch_line;45 #include "caca.h" 46 #include "caca_internals.h" 47 48 static unsigned int _caca_delay; 49 static unsigned int _caca_rendertime; 50 char *_caca_empty_line; 51 char *_caca_scratch_line; 52 52 53 53 #if defined(USE_NCURSES) 54 int _ ee_attr[16];54 int _caca_attr[16]; 55 55 #endif 56 56 57 57 #if defined(USE_CONIO) 58 58 static struct text_info ti; 59 char *_ ee_screen;60 #endif 61 62 int ee_init(void)59 char *_caca_screen; 60 #endif 61 62 int caca_init(void) 63 63 { 64 64 #if defined(USE_SLANG) … … 144 144 for(i = 0; i < 8; i++) 145 145 { 146 _ ee_attr[i] = COLOR_PAIR(1 + i);147 _ ee_attr[i + 8] = A_BOLD | COLOR_PAIR(1 + i);146 _caca_attr[i] = COLOR_PAIR(1 + i); 147 _caca_attr[i + 8] = A_BOLD | COLOR_PAIR(1 + i); 148 148 } 149 149 150 150 #elif defined(USE_CONIO) 151 151 gettextinfo(&ti); 152 _ ee_screen = malloc(2 * ti.screenwidth * ti.screenheight);153 if(_ ee_screen == NULL)152 _caca_screen = malloc(2 * ti.screenwidth * ti.screenheight); 153 if(_caca_screen == NULL) 154 154 return -1; 155 155 _wscroll = 0; … … 157 157 clrscr(); 158 158 # if defined(SCREENUPDATE_IN_PC_H) 159 ScreenRetrieve(_ ee_screen);159 ScreenRetrieve(_caca_screen); 160 160 # else 161 161 /* FIXME */ … … 163 163 164 164 #endif 165 _ ee_empty_line = malloc(ee_get_width() + 1);166 memset(_ ee_empty_line, ' ', ee_get_width());167 _ ee_empty_line[ee_get_width()] = '\0';168 169 _ ee_scratch_line = malloc(ee_get_width() + 1);170 171 _ ee_delay = 0;172 _ ee_rendertime = 0;165 _caca_empty_line = malloc(caca_get_width() + 1); 166 memset(_caca_empty_line, ' ', caca_get_width()); 167 _caca_empty_line[caca_get_width()] = '\0'; 168 169 _caca_scratch_line = malloc(caca_get_width() + 1); 170 171 _caca_delay = 0; 172 _caca_rendertime = 0; 173 173 174 174 return 0; 175 175 } 176 176 177 unsigned int ee_get_width(void)177 unsigned int caca_get_width(void) 178 178 { 179 179 #if defined(USE_SLANG) … … 186 186 } 187 187 188 unsigned int ee_get_height(void)188 unsigned int caca_get_height(void) 189 189 { 190 190 #if defined(USE_SLANG) … … 197 197 } 198 198 199 void ee_set_delay(unsigned int usec)200 { 201 _ ee_delay = usec;202 } 203 204 unsigned int ee_get_rendertime(void)205 { 206 return _ ee_rendertime;207 } 208 209 const char * ee_get_color_name(unsigned int color)199 void caca_set_delay(unsigned int usec) 200 { 201 _caca_delay = usec; 202 } 203 204 unsigned int caca_get_rendertime(void) 205 { 206 return _caca_rendertime; 207 } 208 209 const char *caca_get_color_name(unsigned int color) 210 210 { 211 211 static const char *color_names[16] = … … 235 235 } 236 236 237 static unsigned int _ ee_getticks(void)237 static unsigned int _caca_getticks(void) 238 238 { 239 239 static unsigned int last_sec = 0, last_usec = 0; … … 255 255 } 256 256 257 void ee_refresh(void)257 void caca_refresh(void) 258 258 { 259 259 #define IDLE_USEC 10000 260 260 static unsigned int lastticks = 0; 261 unsigned int ticks = lastticks + _ ee_getticks();261 unsigned int ticks = lastticks + _caca_getticks(); 262 262 263 263 #if defined(USE_SLANG) … … 267 267 #elif defined(USE_CONIO) 268 268 # if defined(SCREENUPDATE_IN_PC_H) 269 ScreenUpdate(_ ee_screen);269 ScreenUpdate(_caca_screen); 270 270 # else 271 271 /* FIXME */ … … 273 273 #endif 274 274 275 /* Wait until _ ee_delay + time of last call */276 ticks += _ ee_getticks();277 for(; ticks < _ ee_delay - IDLE_USEC; ticks += _ee_getticks())275 /* Wait until _caca_delay + time of last call */ 276 ticks += _caca_getticks(); 277 for(; ticks < _caca_delay - IDLE_USEC; ticks += _caca_getticks()) 278 278 usleep(IDLE_USEC); 279 279 280 280 /* Update the sliding mean of the render time */ 281 _ ee_rendertime = (7 * _ee_rendertime + ticks) / 8;282 283 lastticks = ticks - _ ee_delay;281 _caca_rendertime = (7 * _caca_rendertime + ticks) / 8; 282 283 lastticks = ticks - _caca_delay; 284 284 285 285 /* If we drifted too much, it's bad, bad, bad. */ 286 if(lastticks > _ ee_delay)286 if(lastticks > _caca_delay) 287 287 lastticks = 0; 288 288 } 289 289 290 void ee_end(void)290 void caca_end(void) 291 291 { 292 292 #if defined(USE_SLANG) … … 301 301 textcolor((enum COLORS)WHITE); 302 302 textbackground((enum COLORS)BLACK); 303 gotoxy( ee_get_width(), ee_get_height());303 gotoxy(caca_get_width(), caca_get_height()); 304 304 cputs("\r\n"); 305 305 _setcursortype(_NORMALCURSOR); -
libcaca/trunk/libcaca/caca.h
r184 r185 1 1 /* 2 * lib eeASCII-Art library2 * libcaca ASCII-Art library 3 3 * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> 4 4 * All Rights Reserved … … 32 32 * Colors 33 33 */ 34 enum ee_colors34 enum caca_colors 35 35 { 36 36 EE_BLACK = 0, … … 55 55 * Types 56 56 */ 57 struct ee_sprite;57 struct caca_sprite; 58 58 59 59 /* 60 60 * Prototypes 61 61 */ 62 int ee_init(void);63 void ee_set_delay(unsigned int);64 unsigned int ee_get_rendertime(void);65 unsigned int ee_get_width(void);66 unsigned int ee_get_height(void);67 const char * ee_get_color_name(unsigned int);68 void ee_refresh(void);69 void ee_end(void);62 int caca_init(void); 63 void caca_set_delay(unsigned int); 64 unsigned int caca_get_rendertime(void); 65 unsigned int caca_get_width(void); 66 unsigned int caca_get_height(void); 67 const char *caca_get_color_name(unsigned int); 68 void caca_refresh(void); 69 void caca_end(void); 70 70 71 char ee_get_key(void);71 char caca_get_key(void); 72 72 73 void ee_set_color(int);74 int ee_get_color(void);75 void ee_putchar(int, int, char);76 void ee_putstr(int, int, const char *);77 void ee_printf(int, int, const char *, ...);78 void ee_clear(void);73 void caca_set_color(int); 74 int caca_get_color(void); 75 void caca_putchar(int, int, char); 76 void caca_putstr(int, int, const char *); 77 void caca_printf(int, int, const char *, ...); 78 void caca_clear(void); 79 79 80 void ee_draw_line(int, int, int, int, char);81 void ee_draw_polyline(const int[], const int[], int, char);82 void ee_draw_thin_line(int, int, int, int);83 void ee_draw_thin_polyline(const int[], const int[], int);80 void caca_draw_line(int, int, int, int, char); 81 void caca_draw_polyline(const int[], const int[], int, char); 82 void caca_draw_thin_line(int, int, int, int); 83 void caca_draw_thin_polyline(const int[], const int[], int); 84 84 85 void ee_draw_circle(int, int, int, char);86 void ee_draw_ellipse(int, int, int, int, char);87 void ee_draw_thin_ellipse(int, int, int, int);88 void ee_fill_ellipse(int, int, int, int, char);85 void caca_draw_circle(int, int, int, char); 86 void caca_draw_ellipse(int, int, int, int, char); 87 void caca_draw_thin_ellipse(int, int, int, int); 88 void caca_fill_ellipse(int, int, int, int, char); 89 89 90 void ee_draw_box(int, int, int, int, char);91 void ee_draw_thin_box(int, int, int, int);92 void ee_fill_box(int, int, int, int, char);90 void caca_draw_box(int, int, int, int, char); 91 void caca_draw_thin_box(int, int, int, int); 92 void caca_fill_box(int, int, int, int, char); 93 93 94 void ee_draw_triangle(int, int, int, int, int, int, char);95 void ee_draw_thin_triangle(int, int, int, int, int, int);96 void ee_fill_triangle(int, int, int, int, int, int, char);94 void caca_draw_triangle(int, int, int, int, int, int, char); 95 void caca_draw_thin_triangle(int, int, int, int, int, int); 96 void caca_fill_triangle(int, int, int, int, int, int, char); 97 97 98 int ee_rand(int, int);99 unsigned int ee_sqrt(unsigned int);98 int caca_rand(int, int); 99 unsigned int caca_sqrt(unsigned int); 100 100 101 struct ee_sprite * ee_load_sprite(const char *);102 int ee_get_sprite_frames(struct ee_sprite *);103 int ee_get_sprite_width(struct ee_sprite *, int);104 int ee_get_sprite_height(struct ee_sprite *, int);105 int ee_get_sprite_dx(struct ee_sprite *, int);106 int ee_get_sprite_dy(struct ee_sprite *, int);107 void ee_draw_sprite(int, int, struct ee_sprite *, int);108 void ee_free_sprite(struct ee_sprite *);101 struct caca_sprite * caca_load_sprite(const char *); 102 int caca_get_sprite_frames(struct caca_sprite *); 103 int caca_get_sprite_width(struct caca_sprite *, int); 104 int caca_get_sprite_height(struct caca_sprite *, int); 105 int caca_get_sprite_dx(struct caca_sprite *, int); 106 int caca_get_sprite_dy(struct caca_sprite *, int); 107 void caca_draw_sprite(int, int, struct caca_sprite *, int); 108 void caca_free_sprite(struct caca_sprite *); 109 109 110 void ee_blit(int, int, int, int, void *, int, int);110 void caca_blit(int, int, int, int, void *, int, int); 111 111 112 112 #ifdef __cplusplus -
libcaca/trunk/libcaca/caca_internals.h
r184 r185 1 1 /* 2 * lib eeASCII-Art library2 * libcaca ASCII-Art library 3 3 * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> 4 4 * All Rights Reserved … … 25 25 26 26 #if defined(USE_NCURSES) 27 extern int _ ee_attr[];27 extern int _caca_attr[]; 28 28 #endif 29 29 30 30 #if defined(USE_CONIO) 31 extern char *_ ee_screen;31 extern char *_caca_screen; 32 32 #endif 33 33 34 extern char *_ ee_empty_line;35 extern char *_ ee_scratch_line;34 extern char *_caca_empty_line; 35 extern char *_caca_scratch_line; 36 36 37 37 #endif /* __EE_INTERNALS_H__ */ -
libcaca/trunk/libcaca/conic.c
r165 r185 1 1 /* 2 * lib eeASCII-Art library2 * libcaca ASCII-Art library 3 3 * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> 4 4 * All Rights Reserved … … 31 31 #include <stdlib.h> 32 32 33 #include " ee.h"34 #include " ee_internals.h"33 #include "caca.h" 34 #include "caca_internals.h" 35 35 36 36 static void ellipsepoints(int, int, int, int, char); 37 37 38 void ee_draw_circle(int x, int y, int r, char c)38 void caca_draw_circle(int x, int y, int r, char c) 39 39 { 40 40 int test, dx, dy; … … 50 50 } 51 51 52 void ee_fill_ellipse(int xo, int yo, int a, int b, char c)52 void caca_fill_ellipse(int xo, int yo, int a, int b, char c) 53 53 { 54 54 int d2; … … 66 66 { 67 67 d1 += b*b*(2*x*1) + a*a*(-2*y+2); 68 ee_draw_line(xo - x, yo - y, xo + x, yo - y, c);69 ee_draw_line(xo - x, yo + y, xo + x, yo + y, c);68 caca_draw_line(xo - x, yo - y, xo + x, yo - y, c); 69 caca_draw_line(xo - x, yo + y, xo + x, yo + y, c); 70 70 y--; 71 71 } … … 73 73 } 74 74 75 ee_draw_line(xo - x, yo - y, xo + x, yo - y, c);76 ee_draw_line(xo - x, yo + y, xo + x, yo + y, c);75 caca_draw_line(xo - x, yo - y, xo + x, yo - y, c); 76 caca_draw_line(xo - x, yo + y, xo + x, yo + y, c); 77 77 78 78 d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b; … … 90 90 91 91 y--; 92 ee_draw_line(xo - x, yo - y, xo + x, yo - y, c);93 ee_draw_line(xo - x, yo + y, xo + x, yo + y, c);94 } 95 } 96 97 void ee_draw_ellipse(int xo, int yo, int a, int b, char c)92 caca_draw_line(xo - x, yo - y, xo + x, yo - y, c); 93 caca_draw_line(xo - x, yo + y, xo + x, yo + y, c); 94 } 95 } 96 97 void caca_draw_ellipse(int xo, int yo, int a, int b, char c) 98 98 { 99 99 int d2; … … 137 137 } 138 138 139 void ee_draw_thin_ellipse(int xo, int yo, int a, int b)139 void caca_draw_thin_ellipse(int xo, int yo, int a, int b) 140 140 { 141 141 /* FIXME: this is not correct */ … … 184 184 uint8_t b = 0; 185 185 186 if(xo + x >= 0 && xo + x < ee_get_width())186 if(xo + x >= 0 && xo + x < caca_get_width()) 187 187 b |= 0x1; 188 if(xo - x >= 0 && xo - x < ee_get_width())188 if(xo - x >= 0 && xo - x < caca_get_width()) 189 189 b |= 0x2; 190 if(yo + y >= 0 && yo + y < ee_get_height())190 if(yo + y >= 0 && yo + y < caca_get_height()) 191 191 b |= 0x4; 192 if(yo - y >= 0 && yo - y < ee_get_height())192 if(yo - y >= 0 && yo - y < caca_get_height()) 193 193 b |= 0x8; 194 194 195 195 if((b & (0x1|0x4)) == (0x1|0x4)) 196 ee_putchar(xo + x, yo + y, c);196 caca_putchar(xo + x, yo + y, c); 197 197 198 198 if((b & (0x2|0x4)) == (0x2|0x4)) 199 ee_putchar(xo - x, yo + y, c);199 caca_putchar(xo - x, yo + y, c); 200 200 201 201 if((b & (0x1|0x8)) == (0x1|0x8)) 202 ee_putchar(xo + x, yo - y, c);202 caca_putchar(xo + x, yo - y, c); 203 203 204 204 if((b & (0x2|0x8)) == (0x2|0x8)) 205 ee_putchar(xo - x, yo - y, c);206 } 207 205 caca_putchar(xo - x, yo - y, c); 206 } 207 -
libcaca/trunk/libcaca/graphics.c
r181 r185 1 1 /* 2 * lib eeASCII-Art library2 * libcaca ASCII-Art library 3 3 * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> 4 4 * All Rights Reserved … … 37 37 #include <stdarg.h> 38 38 39 #include " ee.h"40 #include " ee_internals.h"39 #include "caca.h" 40 #include "caca_internals.h" 41 41 42 static int _ ee_color = 0;42 static int _caca_color = 0; 43 43 44 void ee_set_color(int color)44 void caca_set_color(int color) 45 45 { 46 46 if(color < 0 || color > 15) 47 47 return; 48 48 49 _ ee_color = color;49 _caca_color = color; 50 50 #if defined(USE_SLANG) 51 51 SLsmg_set_color(color + 1); 52 52 #elif defined(USE_NCURSES) 53 attrset(_ ee_attr[color]);53 attrset(_caca_attr[color]); 54 54 #elif defined(USE_CONIO) 55 55 textcolor(color); … … 57 57 } 58 58 59 int ee_get_color(void)59 int caca_get_color(void) 60 60 { 61 return _ ee_color;61 return _caca_color; 62 62 } 63 63 64 void ee_putchar(int x, int y, char c)64 void caca_putchar(int x, int y, char c) 65 65 { 66 if(x < 0 || x >= ee_get_width() || y < 0 || y >= ee_get_height())66 if(x < 0 || x >= caca_get_width() || y < 0 || y >= caca_get_height()) 67 67 return; 68 68 … … 74 74 addch(c); 75 75 #elif defined(USE_CONIO) 76 _ ee_screen[2 * (x + y * ee_get_width())] = c;77 _ ee_screen[2 * (x + y * ee_get_width()) + 1] = _ee_color;76 _caca_screen[2 * (x + y * caca_get_width())] = c; 77 _caca_screen[2 * (x + y * caca_get_width()) + 1] = _caca_color; 78 78 // gotoxy(x + 1, y + 1); 79 79 // putch(c); … … 81 81 } 82 82 83 void ee_putstr(int x, int y, const char *s)83 void caca_putstr(int x, int y, const char *s) 84 84 { 85 85 int len; 86 86 87 if(y < 0 || y >= ee_get_height() || x >= ee_get_width())87 if(y < 0 || y >= caca_get_height() || x >= caca_get_width()) 88 88 return; 89 89 … … 99 99 } 100 100 101 if(x + len >= ee_get_width())101 if(x + len >= caca_get_width()) 102 102 { 103 memcpy(_ ee_scratch_line, s, ee_get_width() - x);104 _ ee_scratch_line[ee_get_width() - x] = '\0';105 s = _ ee_scratch_line;103 memcpy(_caca_scratch_line, s, caca_get_width() - x); 104 _caca_scratch_line[caca_get_width() - x] = '\0'; 105 s = _caca_scratch_line; 106 106 } 107 107 … … 113 113 addstr(s); 114 114 #elif defined(USE_CONIO) 115 char *buf = _ ee_screen + 2 * (x + y * ee_get_width());115 char *buf = _caca_screen + 2 * (x + y * caca_get_width()); 116 116 while(*s) 117 117 { 118 118 *buf++ = *s++; 119 *buf++ = _ ee_color;119 *buf++ = _caca_color; 120 120 } 121 121 // gotoxy(x + 1, y + 1); … … 124 124 } 125 125 126 void ee_printf(int x, int y, const char *format, ...)126 void caca_printf(int x, int y, const char *format, ...) 127 127 { 128 128 char tmp[BUFSIZ]; … … 130 130 va_list args; 131 131 132 if(y < 0 || y >= ee_get_height() || x >= ee_get_width())132 if(y < 0 || y >= caca_get_height() || x >= caca_get_width()) 133 133 return; 134 134 135 if( ee_get_width() - x + 1 > BUFSIZ)136 buf = malloc( ee_get_width() - x + 1);135 if(caca_get_width() - x + 1 > BUFSIZ) 136 buf = malloc(caca_get_width() - x + 1); 137 137 138 138 va_start(args, format); 139 vsnprintf(buf, ee_get_width() - x + 1, format, args);140 buf[ ee_get_width() - x] = '\0';139 vsnprintf(buf, caca_get_width() - x + 1, format, args); 140 buf[caca_get_width() - x] = '\0'; 141 141 va_end(args); 142 142 143 ee_putstr(x, y, buf);143 caca_putstr(x, y, buf); 144 144 145 145 if(buf != tmp) … … 147 147 } 148 148 149 void ee_clear(void)149 void caca_clear(void) 150 150 { 151 151 /* We could use SLsmg_cls() etc., but drawing empty lines is much faster */ 152 int y = ee_get_height();152 int y = caca_get_height(); 153 153 154 154 while(y--) 155 ee_putstr(0, y, _ee_empty_line);155 caca_putstr(0, y, _caca_empty_line); 156 156 } 157 157 -
libcaca/trunk/libcaca/io.c
r159 r185 1 1 /* 2 * lib eeASCII-Art library2 * libcaca ASCII-Art library 3 3 * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> 4 4 * All Rights Reserved … … 33 33 #endif 34 34 35 #include " ee.h"36 #include " ee_internals.h"35 #include "caca.h" 36 #include "caca_internals.h" 37 37 38 char ee_get_key(void)38 char caca_get_key(void) 39 39 { 40 40 #if defined(USE_SLANG) -
libcaca/trunk/libcaca/line.c
r179 r185 1 1 /* 2 * lib eeASCII-Art library2 * libcaca ASCII-Art library 3 3 * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> 4 4 * All Rights Reserved … … 31 31 #include <stdlib.h> 32 32 33 #include " ee.h"34 #include " ee_internals.h"33 #include "caca.h" 34 #include "caca_internals.h" 35 35 36 36 struct line … … 57 57 * \return nothing 58 58 */ 59 void ee_draw_line(int x1, int y1, int x2, int y2, char c)59 void caca_draw_line(int x1, int y1, int x2, int y2, char c) 60 60 { 61 61 struct line s; … … 69 69 } 70 70 71 void ee_draw_polyline(const int x[], const int y[], int n, char c)71 void caca_draw_polyline(const int x[], const int y[], int n, char c) 72 72 { 73 73 int i; … … 95 95 * \return nothing 96 96 */ 97 void ee_draw_thin_line(int x1, int y1, int x2, int y2)97 void caca_draw_thin_line(int x1, int y1, int x2, int y2) 98 98 { 99 99 struct line s; … … 106 106 } 107 107 108 void ee_draw_thin_polyline(const int x[], const int y[], int n)108 void caca_draw_thin_polyline(const int x[], const int y[], int n) 109 109 { 110 110 int i; … … 164 164 else if(bits1 & (1<<1)) 165 165 { 166 int xmax = ee_get_width() - 1;166 int xmax = caca_get_width() - 1; 167 167 s->y1 = s->y2 - (s->x2 - xmax) * (s->y2 - s->y1) / (s->x2 - s->x1); 168 168 s->x1 = xmax; … … 175 175 else if(bits1 & (1<<3)) 176 176 { 177 int ymax = ee_get_height() - 1;177 int ymax = caca_get_height() - 1; 178 178 s->x1 = s->x2 - (s->y2 - ymax) * (s->x2 - s->x1) / (s->y2 - s->y1); 179 179 s->y1 = ymax; … … 196 196 if(x < 0) 197 197 b |= (1<<0); 198 else if(x >= ee_get_width())198 else if(x >= caca_get_width()) 199 199 b |= (1<<1); 200 200 201 201 if(y < 0) 202 202 b |= (1<<2); 203 else if(y >= ee_get_height())203 else if(y >= caca_get_height()) 204 204 b |= (1<<3); 205 205 … … 236 236 for(; dx>=0; dx--) 237 237 { 238 ee_putchar(x1, y1, s->c);238 caca_putchar(x1, y1, s->c); 239 239 if(delta > 0) 240 240 { … … 258 258 for(; dy >= 0; dy--) 259 259 { 260 ee_putchar(x1, y1, s->c);260 caca_putchar(x1, y1, s->c); 261 261 if(delta > 0) 262 262 { … … 330 330 if(delta > 0) 331 331 { 332 ee_putchar(x1, y1, charmapy[1]);332 caca_putchar(x1, y1, charmapy[1]); 333 333 x1++; 334 334 y1 += yinc; … … 339 339 { 340 340 if(prev) 341 ee_putchar(x1, y1, charmapy[0]);341 caca_putchar(x1, y1, charmapy[0]); 342 342 else 343 ee_putchar(x1, y1, '-');343 caca_putchar(x1, y1, '-'); 344 344 x1++; 345 345 delta += dpr; … … 358 358 if(delta > 0) 359 359 { 360 ee_putchar(x1, y1, charmapx[0]);361 ee_putchar(x1 + 1, y1, charmapx[1]);360 caca_putchar(x1, y1, charmapx[0]); 361 caca_putchar(x1 + 1, y1, charmapx[1]); 362 362 x1++; 363 363 y1 += yinc; … … 366 366 else 367 367 { 368 ee_putchar(x1, y1, '|');368 caca_putchar(x1, y1, '|'); 369 369 y1 += yinc; 370 370 delta += dpr; -
libcaca/trunk/libcaca/math.c
r171 r185 1 1 /* 2 * lib eeASCII-Art library2 * libcaca ASCII-Art library 3 3 * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> 4 4 * All Rights Reserved … … 25 25 #include <stdlib.h> 26 26 27 #include " ee.h"28 #include " ee_internals.h"27 #include "caca.h" 28 #include "caca_internals.h" 29 29 30 int ee_rand(int min, int max)30 int caca_rand(int min, int max) 31 31 { 32 32 return min + (int)((1.0*(max-min+1)) * rand() / (RAND_MAX+1.0)); 33 33 } 34 34 35 unsigned int ee_sqrt(unsigned int a)35 unsigned int caca_sqrt(unsigned int a) 36 36 { 37 37 if(a == 0) … … 55 55 } 56 56 57 return 2 * ee_sqrt(a / 4);57 return 2 * caca_sqrt(a / 4); 58 58 } 59 59 -
libcaca/trunk/libcaca/sprite.c
r167 r185 1 1 /* 2 * lib eeASCII-Art library2 * libcaca ASCII-Art library 3 3 * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> 4 4 * All Rights Reserved … … 27 27 #include <string.h> 28 28 29 #include " ee.h"30 #include " ee_internals.h"31 32 struct ee_frame29 #include "caca.h" 30 #include "caca_internals.h" 31 32 struct caca_frame 33 33 { 34 34 int w, h; … … 38 38 }; 39 39 40 struct ee_sprite40 struct caca_sprite 41 41 { 42 42 int nf; 43 struct ee_frame *frames;43 struct caca_frame *frames; 44 44 }; 45 45 46 struct ee_sprite *ee_load_sprite(const char *file)46 struct caca_sprite *caca_load_sprite(const char *file) 47 47 { 48 48 char buf[BUFSIZ]; 49 struct ee_sprite *sprite;49 struct caca_sprite *sprite; 50 50 FILE *fd; 51 51 … … 54 54 return NULL; 55 55 56 sprite = malloc(sizeof(struct ee_sprite));56 sprite = malloc(sizeof(struct caca_sprite)); 57 57 if(sprite == NULL) 58 58 goto sprite_alloc_failed; … … 65 65 int x, y; 66 66 int w = 0, h = 0, dx = 0, dy = 0; 67 struct ee_frame *frame;67 struct caca_frame *frame; 68 68 69 69 /* Get width and height */ … … 78 78 { 79 79 void *tmp = realloc(sprite->frames, 80 (sprite->nf + 1) * sizeof(struct ee_frame));80 (sprite->nf + 1) * sizeof(struct caca_frame)); 81 81 if(tmp == NULL) 82 82 goto frame_failed; … … 86 86 else 87 87 { 88 sprite->frames = malloc((sprite->nf + 1) * sizeof(struct ee_frame));88 sprite->frames = malloc((sprite->nf + 1) * sizeof(struct caca_frame)); 89 89 if(sprite->frames == NULL) 90 90 goto sprite_failed; … … 159 159 } 160 160 161 int ee_get_sprite_frames(struct ee_sprite *sprite)161 int caca_get_sprite_frames(struct caca_sprite *sprite) 162 162 { 163 163 if(sprite == NULL) … … 167 167 } 168 168 169 int ee_get_sprite_width(struct ee_sprite *sprite, int f)169 int caca_get_sprite_width(struct caca_sprite *sprite, int f) 170 170 { 171 171 if(sprite == NULL) … … 178 178 } 179 179 180 int ee_get_sprite_height(struct ee_sprite *sprite, int f)180 int caca_get_sprite_height(struct caca_sprite *sprite, int f) 181 181 { 182 182 if(sprite == NULL) … … 189 189 } 190 190 191 int ee_get_sprite_dx(struct ee_sprite *sprite, int f)191 int caca_get_sprite_dx(struct caca_sprite *sprite, int f) 192 192 { 193 193 if(sprite == NULL) … … 200 200 } 201 201 202 int ee_get_sprite_dy(struct ee_sprite *sprite, int f)202 int caca_get_sprite_dy(struct caca_sprite *sprite, int f) 203 203 { 204 204 if(sprite == NULL) … … 211 211 } 212 212 213 void ee_draw_sprite(int x, int y, struct ee_sprite *sprite, int f)213 void caca_draw_sprite(int x, int y, struct caca_sprite *sprite, int f) 214 214 { 215 215 int i, j, oldcol; 216 struct ee_frame *frame;216 struct caca_frame *frame; 217 217 218 218 if(sprite == NULL) … … 224 224 frame = &sprite->frames[f]; 225 225 226 oldcol = ee_get_color();226 oldcol = caca_get_color(); 227 227 228 228 for(j = 0; j < frame->h; j++) … … 233 233 if(col >= 0) 234 234 { 235 ee_set_color(col);236 ee_putchar(x + i - frame->dx, y + j - frame->dy,235 caca_set_color(col); 236 caca_putchar(x + i - frame->dx, y + j - frame->dy, 237 237 frame->chars[frame->w * j + i]); 238 238 } … … 240 240 } 241 241 242 ee_set_color(oldcol);243 } 244 245 void ee_free_sprite(struct ee_sprite *sprite)242 caca_set_color(oldcol); 243 } 244 245 void caca_free_sprite(struct caca_sprite *sprite) 246 246 { 247 247 int i; … … 252 252 for(i = sprite->nf; i--;) 253 253 { 254 struct ee_frame *frame = &sprite->frames[i];254 struct caca_frame *frame = &sprite->frames[i]; 255 255 free(frame->chars); 256 256 free(frame->color); -
libcaca/trunk/libcaca/triangle.c
r159 r185 1 1 /* 2 * lib eeASCII-Art library2 * libcaca ASCII-Art library 3 3 * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> 4 4 * All Rights Reserved … … 25 25 #include <stdlib.h> 26 26 27 #include " ee.h"28 #include " ee_internals.h"27 #include "caca.h" 28 #include "caca_internals.h" 29 29 30 void ee_draw_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c)30 void caca_draw_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c) 31 31 { 32 ee_draw_line(x1, y1, x2, y2, c);33 ee_draw_line(x2, y2, x3, y3, c);34 ee_draw_line(x3, y3, x1, y1, c);32 caca_draw_line(x1, y1, x2, y2, c); 33 caca_draw_line(x2, y2, x3, y3, c); 34 caca_draw_line(x3, y3, x1, y1, c); 35 35 } 36 36 37 void ee_draw_thin_triangle(int x1, int y1, int x2, int y2, int x3, int y3)37 void caca_draw_thin_triangle(int x1, int y1, int x2, int y2, int x3, int y3) 38 38 { 39 ee_draw_thin_line(x1, y1, x2, y2);40 ee_draw_thin_line(x2, y2, x3, y3);41 ee_draw_thin_line(x3, y3, x1, y1);39 caca_draw_thin_line(x1, y1, x2, y2); 40 caca_draw_thin_line(x2, y2, x3, y3); 41 caca_draw_thin_line(x3, y3, x1, y1); 42 42 } 43 43 44 void ee_fill_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c)44 void caca_fill_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c) 45 45 { 46 46 int x, y, xa, xb, xmax, ymax; … … 49 49 if(y1 > y2) 50 50 { 51 ee_fill_triangle(x2, y2, x1, y1, x3, y3, c);51 caca_fill_triangle(x2, y2, x1, y1, x3, y3, c); 52 52 return; 53 53 } … … 55 55 if(y2 > y3) 56 56 { 57 ee_fill_triangle(x1, y1, x3, y3, x2, y2, c);57 caca_fill_triangle(x1, y1, x3, y3, x2, y2, c); 58 58 return; 59 59 } … … 64 64 x3 *= 4; 65 65 66 xmax = ee_get_width() - 1;67 ymax = ee_get_height() - 1;66 xmax = caca_get_width() - 1; 67 ymax = caca_get_height() - 1; 68 68 69 69 /* Rasterize our triangle */ … … 97 97 98 98 for(x = xa; x <= xb; x++) 99 ee_putchar(x, y, c);99 caca_putchar(x, y, c); 100 100 } 101 101 }
Note: See TracChangeset
for help on using the changeset viewer.