Ignore:
Timestamp:
Nov 12, 2003, 10:18:50 PM (16 years ago)
Author:
Sam Hocevar
Message:
  • libee/ee.h: + Added ee_color_names[] containing our 16 color names.
  • libee/ee.c: + Extended our color set to the full 16 instead of 10. + Precalculate ncurses attributes.
  • libee/graphics.c: + Clip color value in ee_set_color(). + Clip characters in ee_putchar(). + Partially clip characters in ee_putstr(), overflows aren't checked yet.
  • libee/ee_internals.h: + New file to share extern variables within libee.
  • test/demo.c: + Added a simple demo_color() to output all colors. + Replaced four ee_draw_line() with ee_draw_thin_box(). + Replaced x1, y1, x2 etc. with xa, ya, xb etc. because <math.h> already

defines y1.

+ Randomized colours from 0 to 15 instead of 1 to 10.

  • src/Makefiles.am: + Added -lm to the ttyvaders linking flags because of the intro.
  • README BUGS TODO: + Updated.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ttyvaders/trunk/libee/graphics.c

    r158 r160  
    3737
    3838#include "ee.h"
     39#include "ee_internals.h"
    3940
    4041static int ee_color = 0;
    41 #if defined(USE_CONIO)
    42 static enum COLORS dos_colors[] = {
    43     0,
    44     BLACK,
    45     GREEN,
    46     YELLOW,
    47     WHITE,
    48     RED,
    49     DARKGRAY,
    50     LIGHTGRAY,
    51     BLUE,
    52     CYAN,
    53     MAGENTA
    54 };
    55 #endif
    5642
    5743void ee_set_color(int color)
    5844{
     45    if(color < 0 || color > 15)
     46        return;
     47
    5948    ee_color = color;
    6049#if defined(USE_SLANG)
    61     SLsmg_set_color(color);
     50    SLsmg_set_color(color + 1);
    6251#elif defined(USE_NCURSES)
    63     attrset(COLOR_PAIR(color));
     52    attrset(_ee_attr[color]);
    6453#elif defined(USE_CONIO)
    65     if(color >= 1 && color <= 10)
    66         textcolor(dos_colors[color]);
     54    textcolor(color);
    6755#endif
    6856}
     
    7361}
    7462
    75 extern char *_screen_buffer;
    76 
    7763void ee_putchar(int x, int y, char c)
    7864{
     65    if(x < 0 || x >= ee_get_width() || y < 0 || y >= ee_get_height())
     66        return;
     67
    7968#if defined(USE_SLANG)
    80     SLsmg_gotorc(y,x);
     69    SLsmg_gotorc(y, x);
    8170    SLsmg_write_char(c);
    8271#elif defined(USE_NCURSES)
    83     move(y,x);
     72    move(y, x);
    8473    addch(c);
    8574#elif defined(USE_CONIO)
    86     if(x<0 || x>=ee_get_width() || y<0 || y>=ee_get_height())
    87         return;
    88     _screen_buffer[2 * (x + y * ee_get_width())] = c;
    89     _screen_buffer[2 * (x + y * ee_get_width()) + 1] = dos_colors[ee_color];
    90 //    gotoxy(x+1,y+1);
     75    _ee_screen[2 * (x + y * ee_get_width())] = c;
     76    _ee_screen[2 * (x + y * ee_get_width()) + 1] = ee_color;
     77//    gotoxy(x + 1, y + 1);
    9178//    putch(c);
    9279#endif
     
    9582void ee_putstr(int x, int y, char *s)
    9683{
    97     if(y<0 || y>=ee_get_height())
     84    int len;
     85
     86    if(y < 0 || y >= ee_get_height())
    9887        return;
     88
     89    len = strlen(s);
     90
     91    if(x < 0)
     92    {
     93        len -= -x;
     94        if(len < 0)
     95            return;
     96        s += -x;
     97        x = 0;
     98    }
     99
    99100#if defined(USE_SLANG)
    100     SLsmg_gotorc(y,x);
     101    SLsmg_gotorc(y, x);
    101102    SLsmg_write_string(s);
    102103#elif defined(USE_NCURSES)
    103     move(y,x);
     104    move(y, x);
    104105    addstr(s);
    105106#elif defined(USE_CONIO)
    106     char *buf = _screen_buffer + 2 * (x + y * ee_get_width());
     107    char *buf = _ee_screen + 2 * (x + y * ee_get_width());
    107108    while(*s)
    108109    {
    109110        *buf++ = *s++;
    110         *buf++ = dos_colors[ee_color];
     111        *buf++ = ee_color;
    111112    }
    112 //    gotoxy(x+1,y+1);
     113//    gotoxy(x + 1, y + 1);
    113114//    cputs(s);
    114115#endif
     
    118119{
    119120    /* We could use SLsmg_cls() etc., but drawing empty lines is much faster */
    120     int x = ee_get_width(), y = ee_get_height();
     121    int x = ee_get_width();
     122    int y = ee_get_height();
    121123    char *empty_line = malloc((x + 1) * sizeof(char));
    122124
Note: See TracChangeset for help on using the changeset viewer.