Changeset 204


Ignore:
Timestamp:
Nov 21, 2003, 3:34:07 PM (17 years ago)
Author:
Sam Hocevar
Message:
  • TODO: + A few updates.
  • src/blit.c: + Split blit() into caca_create_bitmap() and caca_draw_bitmap(). + Started removing hardcoded bitmask and pitch values.
  • examples/demo.c: + Do something with mouse clicks.
Location:
libcaca/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/TODO

    r202 r204  
    2222   o  Fix the thin ellipse rendering
    2323
     24   o  Support more colour depths, more bitmask orderings
     25
    2426
    2527Misc
    2628
    2729   o  Draw a nicer logo sprite
     30
     31   o  Text edit widget
    2832
    2933
  • libcaca/trunk/examples/demo.c

    r202 r204  
    184184            caca_refresh();
    185185        }
     186        else if(event & CACA_EVENT_MOUSE_CLICK)
     187        {
     188            display_menu();
     189            caca_set_color(CACA_COLOR_RED);
     190            caca_putstr((event & 0xff00) >> 8, event & 0xff, "|\\");
     191            caca_refresh();
     192        }
    186193
    187194        if(demo)
     
    486493static void demo_blit(void)
    487494{
     495#if 0
    488496    caca_blit(6, 4, caca_get_width() - 6, caca_get_height() - 4,
    489497              pixels, bufx, bufy);
    490 }
    491 
     498#endif
     499}
     500
  • libcaca/trunk/src/blit.c

    r200 r204  
    8484}
    8585
    86 void caca_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h)
    87 {
     86struct caca_bitmap
     87{
     88    int bpp;
     89    int w, h, pitch;
     90    int rmask, gmask, bmask;
     91};
     92
     93struct caca_bitmap *caca_create_bitmap(int bpp, int w, int h, int pitch,
     94                                       int rmask, int gmask, int bmask)
     95{
     96    struct caca_bitmap *bitmap;
     97
     98    /* Currently only this format is supported. Will improve later. */
     99    if(!w || !h || !pitch || bpp != 32 ||
     100       rmask != 0x00ff0000 || gmask != 0x0000ff00 || bmask != 0x000000ff)
     101        return NULL;
     102
     103    bitmap = malloc(sizeof(struct caca_bitmap));
     104    if(!bitmap)
     105        return NULL;
     106
     107    bitmap->bpp = bpp;
     108
     109    bitmap->w = w;
     110    bitmap->h = h;
     111    bitmap->pitch = pitch;
     112
     113    bitmap->rmask = rmask;
     114    bitmap->gmask = gmask;
     115    bitmap->bmask = bmask;
     116
     117    return bitmap;
     118}
     119
     120void caca_free_bitmap(struct caca_bitmap *bitmap)
     121{
     122    if(!bitmap)
     123        return;
     124
     125    free(bitmap);
     126}
     127
     128void caca_draw_bitmap(int x1, int y1, int x2, int y2,
     129                      struct caca_bitmap *bitmap, char *pixels)
     130{
     131    /* FIXME: this code is shite! */
    88132    static int white_colors[] = {CACA_COLOR_DARKGRAY, CACA_COLOR_LIGHTGRAY, CACA_COLOR_WHITE};
    89133    static int light_colors[] = {CACA_COLOR_LIGHTMAGENTA, CACA_COLOR_LIGHTRED, CACA_COLOR_YELLOW, CACA_COLOR_LIGHTGREEN, CACA_COLOR_LIGHTCYAN, CACA_COLOR_LIGHTBLUE, CACA_COLOR_LIGHTMAGENTA};
    90134    static int dark_colors[] = {CACA_COLOR_MAGENTA, CACA_COLOR_RED, CACA_COLOR_BROWN, CACA_COLOR_GREEN, CACA_COLOR_CYAN, CACA_COLOR_BLUE, CACA_COLOR_MAGENTA};
    91135    static char foo[] = { ' ', '.', ':', ';', '=', '%', '$', 'W', '#', '8', '@' };
    92     int x, y, pitch;
     136    int x, y, w, h, pitch;
     137
     138    if(!bitmap || !pixels)
     139        return;
     140
     141    w = bitmap->w;
     142    h = bitmap->h;
     143    pitch = bitmap->pitch;
    93144
    94145    if(x1 > x2)
     
    101152        int tmp = y2; y2 = y1; y1 = tmp;
    102153    }
    103 
    104     //pitch = (3 * w + 3) / 4 * 4;
    105     pitch = 4 * w;
    106154
    107155    for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)caca_get_height(); y++)
     
    115163            int fromx = w * (x - x1) / (x2 - x1 + 1);
    116164            int fromy = h * (y - y1) / (y2 - y1 + 1);
    117             //int r = ((unsigned char *)pixels)[3 * fromx + pitch * fromy];
    118             //int g = ((unsigned char *)pixels)[3 * fromx + 1 + pitch * fromy];
    119             //int b = ((unsigned char *)pixels)[3 * fromx + 2 + pitch * fromy];
     165            /* FIXME: bwahaaa, we don't even respect masks */
    120166            int b = ((unsigned char *)pixels)[4 * fromx + pitch * fromy];
    121167            int g = ((unsigned char *)pixels)[4 * fromx + 1 + pitch * fromy];
  • libcaca/trunk/src/caca.h

    r199 r204  
    102102
    103103/*
    104  * Types
     104 * Internal types
    105105 */
    106106struct caca_sprite;
     107struct caca_bitmap;
    107108
    108109/*
    109  * Prototypes
     110 * Basic functions
    110111 */
    111112int caca_init(void);
     
    119120void caca_end(void);
    120121
     122/*
     123 * Events
     124 */
    121125int caca_get_event(void);
    122126
     127/*
     128 * Character graphics
     129 */
    123130void caca_set_color(enum caca_color);
    124131enum caca_color caca_get_color(void);
     
    128135void caca_clear(void);
    129136
     137/*
     138 * Graphics primitives
     139 */
    130140void caca_draw_line(int, int, int, int, char);
    131141void caca_draw_polyline(const int[], const int[], int, char);
     
    146156void caca_fill_triangle(int, int, int, int, int, int, char);
    147157
     158/*
     159 * Maths
     160 */
    148161int caca_rand(int, int);
    149162unsigned int caca_sqrt(unsigned int);
    150163
     164/*
     165 * Sprite handling
     166 */
    151167struct caca_sprite * caca_load_sprite(const char *);
    152168int caca_get_sprite_frames(struct caca_sprite *);
     
    158174void caca_free_sprite(struct caca_sprite *);
    159175
    160 void caca_blit(int, int, int, int, void *, int, int);
     176/*
     177 * Bitmap handling
     178 */
     179struct caca_bitmap *caca_create_bitmap(int, int, int, int, int, int, int);
     180void caca_draw_bitmap(int, int, int, int, struct caca_bitmap *, char *);
     181void caca_free_bitmap(struct caca_bitmap *);
    161182
    162183#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.