Changeset 179


Ignore:
Timestamp:
Nov 15, 2003, 10:58:20 AM (20 years ago)
Author:
Sam Hocevar
Message:
  • libee/graphics.c: + Correct clipping in ee_putstr() for long strings.
  • libee/ee.c: + New ee_get_rendertime() call to provide framerate information.
  • libee/ee.h: + Added const keywords where it was meaningful, despite Slang's blatant

omission of such keywords in its prototypes.

Location:
libcaca/trunk/libee
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/libee/ee.c

    r177 r179  
    4747
    4848/* Global array with color names */
    49 char *ee_color_names[16] =
     49const char *ee_color_names[16] =
    5050{
    5151    "black",
     
    6767};
    6868
    69 static int _ee_delay;
     69static unsigned int _ee_delay;
     70static unsigned int _ee_rendertime;
    7071char *_ee_empty_line;
     72char *_ee_scratch_line;
    7173
    7274#if defined(USE_NCURSES)
     
    186188    _ee_empty_line[ee_get_width()] = '\0';
    187189
     190    _ee_scratch_line = malloc(ee_get_width() + 1);
     191
    188192    _ee_delay = 0;
     193    _ee_rendertime = 0;
    189194
    190195    return 0;
    191196}
    192197
    193 int ee_get_width(void)
     198unsigned int ee_get_width(void)
    194199{
    195200#if defined(USE_SLANG)
     
    202207}
    203208
    204 int ee_get_height(void)
     209unsigned int ee_get_height(void)
    205210{
    206211#if defined(USE_SLANG)
     
    213218}
    214219
    215 void ee_set_delay(int usec)
     220void ee_set_delay(unsigned int usec)
    216221{
    217222    _ee_delay = usec;
     223}
     224
     225unsigned int ee_get_rendertime(void)
     226{
     227    return _ee_rendertime;
    218228}
    219229
     
    240250void ee_refresh(void)
    241251{
    242     static int lastticks = 0;
     252    static unsigned int lastticks = 0;
    243253    unsigned int ticks = lastticks + _ee_getticks();
    244254
     
    258268    for(ticks += _ee_getticks(); ticks < _ee_delay; ticks += _ee_getticks())
    259269        usleep(10000);
     270
     271    /* Update the sliding mean of the render time */
     272    _ee_rendertime = (7 * _ee_rendertime + ticks) / 8;
    260273
    261274    lastticks = ticks - _ee_delay;
  • libcaca/trunk/libee/ee.h

    r171 r179  
    5252};
    5353
    54 extern char *ee_color_names[16];
     54extern const char *ee_color_names[16];
    5555
    5656/*
     
    6363 */
    6464int ee_init(void);
    65 void ee_set_delay(int);
    66 int ee_get_width(void);
    67 int ee_get_height(void);
     65void ee_set_delay(unsigned int);
     66unsigned int ee_get_rendertime(void);
     67unsigned int ee_get_width(void);
     68unsigned int ee_get_height(void);
    6869void ee_refresh(void);
    6970void ee_end(void);
     
    7475int ee_get_color(void);
    7576void ee_putchar(int, int, char);
    76 void ee_putstr(int, int, char *);
     77void ee_putstr(int, int, const char *);
    7778void ee_clear(void);
    7879
    7980void ee_draw_line(int, int, int, int, char);
    80 void ee_draw_polyline(int[], int[], int, char);
     81void ee_draw_polyline(const int[], const int[], int, char);
    8182void ee_draw_thin_line(int, int, int, int);
    82 void ee_draw_thin_polyline(int[], int[], int);
     83void ee_draw_thin_polyline(const int[], const int[], int);
    8384
    8485void ee_draw_circle(int, int, int, char);
  • libcaca/trunk/libee/ee_internals.h

    r167 r179  
    3333
    3434extern char *_ee_empty_line;
     35extern char *_ee_scratch_line;
    3536
    3637#endif /* __EE_INTERNALS_H__ */
  • libcaca/trunk/libee/graphics.c

    r167 r179  
    8080}
    8181
    82 void ee_putstr(int x, int y, char *s)
     82void ee_putstr(int x, int y, const char *s)
    8383{
    8484    int len;
    8585
    86     if(y < 0 || y >= ee_get_height())
     86    if(y < 0 || y >= ee_get_height() || x >= ee_get_width())
    8787        return;
    8888
     
    9696        s += -x;
    9797        x = 0;
     98    }
     99
     100    if(x + len >= ee_get_width())
     101    {
     102        memcpy(_ee_scratch_line, s, ee_get_width() - x);
     103        _ee_scratch_line[ee_get_width() - x] = '\0';
     104        s = _ee_scratch_line;
    98105    }
    99106
  • libcaca/trunk/libee/line.c

    r165 r179  
    6969}
    7070
    71 void ee_draw_polyline(int x[], int y[], int n, char c)
     71void ee_draw_polyline(const int x[], const int y[], int n, char c)
    7272{
    7373    int i;
     
    106106}
    107107
    108 void ee_draw_thin_polyline(int x[], int y[], int n)
     108void ee_draw_thin_polyline(const int x[], const int y[], int n)
    109109{
    110110    int i;
Note: See TracChangeset for help on using the changeset viewer.