Example #1
0
int main(int argc, char *argv[])
{
    char const * const *list;
    caca_display_t *dp;
    caca_canvas_t *cv;

    list = caca_get_display_driver_list();

    dp = caca_create_display(NULL);
    if(dp == NULL)
    {
        printf("cannot create display\n");
        return -1;
    }

    cv = caca_get_canvas(dp);
    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);

    while(1)
    {
        char const *driver;
        int i, cur = 0;

        caca_put_str(cv, 1, 0, "Available drivers:");

        driver = caca_get_display_driver(dp);

        for(i = 0; list[i]; i += 2)
        {
            int match = !strcmp(list[i], driver);

            if(match)
                cur = i;
            caca_draw_line(cv, 0, i + 2, 9999, i + 2, ' ');
            caca_printf(cv, 2, i + 2, "%c %s (%s)",
                         match ? '*' : ' ', list[i], list[i + 1]);
        }

        caca_put_str(cv, 1, i + 2, "Switching driver in 5 seconds");

        caca_refresh_display(dp);

        if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, 5000000))
            break;

        do
        {
            cur += 2;
            if(list[cur] && !strcmp(list[cur], "raw"))
                cur += 2;
            if(!list[cur])
                cur = 0;
        }
        while(caca_set_display_driver(dp, list[cur]));
    }

    caca_free_display(dp);

    return 0;
}
static void
_increment_frame (lw6sys_context_t * sys_context, _mod_caca_context_t * caca_context, caca_font_t * fo, caca_dither_t * di, uint8_t * buff)
{
  int wc, hc;
  static caca_font_t *f = NULL;
  static caca_dither_t *d = NULL;
  static uint8_t *buf = NULL;

  if (fo != NULL)
    f = fo;
  if (di != NULL)
    d = di;
  if (buff != NULL)
    buf = buff;
  hc = caca_get_canvas_height (caca_context->canvas);
  wc = caca_get_canvas_width (caca_context->canvas);
  _plasma (sys_context, UPDATE, caca_context->canvas);
  _plasma (sys_context, RENDER, caca_context->canvas);

  caca_set_color_ansi (caca_context->canvas, CACA_WHITE, CACA_BLACK);
  caca_dither_bitmap (caca_context->canvas, (wc - (10 * caca_get_font_width (f))) / 2, (hc - caca_get_font_height (f)) / 2, wc, hc, d, buf);
  caca_put_str (caca_context->canvas, wc - 8, 0, "mod-caca");
  caca_put_str (caca_context->canvas, 0, 0, "PFA Epitech 2012-2013");
  caca_put_str (caca_context->canvas, (wc - 41) / 2, hc - 1, "by france_a, clavel_r, lemonn_k, vougie_c");
  caca_refresh_display (caca_context->display);
  frame++;
}
Example #3
0
File: svv.c Project: engie/robo_gui
void gui_console_update(unsigned char *p, int len)
{
    caca_dither_bitmap(
        c_ui.cv,
        0, 0,
        c_ui.ww, c_ui.wh,
        c_ui.im,
        p);
    caca_refresh_display(c_ui.dp);
}
Example #4
0
static void caca_render_msg(video_frame_info_t *video_info,
      void *data, const char *msg,
      const void *userdata)
{
   float x, y, scale;
   unsigned width, height;
   unsigned newX, newY;
   unsigned align;
   caca_raster_t              *font = (caca_raster_t*)data;
   const struct font_params *params = (const struct font_params*)userdata;

   if (!font || string_is_empty(msg))
      return;

   if (params)
   {
      x = params->x;
      y = params->y;
      scale = params->scale;
      align = params->text_align;
   }
   else
   {
      x = video_info->font_msg_pos_x;
      y = video_info->font_msg_pos_y;
      scale = 1.0f;
      align = TEXT_ALIGN_LEFT;
   }

   if (!font->caca || !font->caca->caca_cv || !font->caca->caca_display ||
       !*font->caca->caca_cv || !*font->caca->caca_display)
      return;

   width    = caca_get_canvas_width(*font->caca->caca_cv);
   height   = caca_get_canvas_height(*font->caca->caca_cv);
   newY     = height - (y * height * scale);

   switch (align)
   {
      case TEXT_ALIGN_RIGHT:
         newX = (x * width * scale) - strlen(msg);
         break;
      case TEXT_ALIGN_CENTER:
         newX = (x * width * scale) - (strlen(msg) / 2);
         break;
      case TEXT_ALIGN_LEFT:
      default:
         newX = x * width * scale;
         break;
   }

   caca_put_str(*font->caca->caca_cv, newX, newY, msg);

   caca_refresh_display(*font->caca->caca_display);
}
Example #5
0
static int refresh_screen(void)
{
    caca_set_color_ansi(cv, CACA_DEFAULT, CACA_DEFAULT);
    caca_clear_canvas(cv);

    caca_blit(cv, - x, - y, image, NULL);

    caca_refresh_display(dp);

    return 0;
}
Example #6
0
int main(void)
{
    //                   R G B A
    uint32_t pattern = 0xFFFF00FF;

#ifdef __APPLE__
    memset_pattern4(gfx, &pattern, sizeof(gfx));
#else
    wmemset(gfx, pattern, (64*32) * sizeof(char));
#endif

    gfx[0] =    0xFF0000FF; // R
    gfx[1] =    0x00FF00FF; // G
    gfx[2] =    0x0000FFFF; // B
    gfx[63] =   0xFF0000FF; // R
    gfx[64*31] =0x00FF00FF; // G
    int x = 64, y = 32;
    gfx[(y-1)*64+(x-1)] = 0x0000FFFF; // B

    caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev;
    dp = caca_create_display(NULL);
    if(!dp)
        return 1;
    /*
    printf("Current driver: %s\n", caca_get_display_driver(dp));
    char **drivers = caca_get_display_driver_list();
    caca_free_display(dp);
    while(*drivers != NULL) {
        printf("%s\n", *drivers);
        drivers++;
    }
    exit(0);*/
    cv = caca_get_canvas(dp);
    caca_dither_t *dither = caca_create_dither(32, 64, 32, 4*64,
        0xFF000000,
        0x00FF0000,
        0x0000FF00,
        0x000000FF);
    int cw = caca_get_canvas_width(cv);
    int ch = caca_get_canvas_height(cv);
    caca_set_display_title(dp, "Hello!");
    //caca_set_color_ansi(cv, CACA_BLUE, CACA_WHITE);
    //caca_put_str(cv, 0, 0, "This is a message");
    caca_dither_bitmap(cv, 0,0,cw,ch, dither, gfx);
    caca_refresh_display(dp);

    caca_free_dither(dither);
    //caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
    caca_free_display(dp);
    return 0;
}
Example #7
0
File: caca.c Project: 0xheart0/vlc
/**
 * Refresh the display and send resize event
 */
static void Refresh(vout_display_t *vd)
{
    vout_display_sys_t *sys = vd->sys;

    /* */
    caca_refresh_display(sys->dp);

    /* */
    const unsigned width  = caca_get_display_width(sys->dp);
    const unsigned height = caca_get_display_height(sys->dp);

    if (width  != vd->cfg->display.width ||
        height != vd->cfg->display.height)
        vout_display_SendEventDisplaySize(vd, width, height);
}
Example #8
0
static void flip_page(struct vo *vo)
{
    if (showosdmessage) {
        if (time(NULL) >= stoposd) {
            showosdmessage = 0;
            if (*posbar)
                posbar[0] = '\0';
        } else {
            caca_put_str(canvas, osdx, osdy, osdmessagetext);
            if (*posbar)
                caca_put_str(canvas, 0, posbary, posbar);
        }
    }

    caca_refresh_display(display);
}
Example #9
0
int main(int argc, char *argv[])
{
    caca_canvas_t *cv;
    caca_display_t *dp;

    int x, y;

    cv = caca_create_canvas(32, 16);
    if(cv == NULL)
    {
        printf("Failed to create canvas\n");
        return 1;
    }

    dp = caca_create_display(cv);
    if(dp == NULL)
    {
        printf("Failed to create display\n");
        return 1;
    }

    for(y = 0; y < 16; y++)
        for(x = 0; x < 16; x++)
    {
        uint16_t bgcolor = 0xff00 | (y << 4) | x;
        uint16_t fgcolor = 0xf000 | ((15 - y) << 4) | ((15 - x) << 8);

        caca_set_color_argb(cv, fgcolor, bgcolor);
        caca_put_str(cv, x * 2, y, "CA");
    }

    caca_set_color_ansi(cv, CACA_WHITE, CACA_LIGHTBLUE);
    caca_put_str(cv, 2, 1, " truecolor libcaca ");

    caca_refresh_display(dp);

    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);

    caca_free_display(dp);
    caca_free_canvas(cv);

    return 0;
}
Example #10
0
int main(int argc, char *argv[])
{
    caca_canvas_t *cv, *sprite;
    caca_display_t *dp;

    cv = caca_create_canvas(80, 24);
    if(cv == NULL)
    {
        printf("Failed to create canvas\n");
        return 1;
    }

    dp = caca_create_display(cv);
    if(dp == NULL)
    {
        printf("Failed to create display\n");
        return 1;
    }

    sprite = caca_create_canvas(0, 0);
    caca_set_color_ansi(sprite, CACA_LIGHTRED, CACA_BLACK);
    caca_import_canvas_from_memory(sprite, pig, strlen(pig), "text");
    caca_set_canvas_handle(sprite, caca_get_canvas_width(sprite) / 2,
                           caca_get_canvas_height(sprite) / 2);

    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
    caca_put_str(cv, 0, 0, "Centered sprite");

    caca_blit(cv, caca_get_canvas_width(cv) / 2,
              caca_get_canvas_height(cv) / 2, sprite, NULL);

    caca_refresh_display(dp);

    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);

    caca_free_display(dp);
    caca_free_canvas(sprite);
    caca_free_canvas(cv);

    return 0;
}
Example #11
0
void processing_terminal() {

    setup();
    while (pt.running) {

        //width = caca_get_canvas_width(pt.cv);
        // height = caca_get_canvas_height(pt.cv);

        if (!pt.PT_USE_DITHERING) {
            width = caca_get_canvas_width(pt.cv) / X_SCALE;
            height = caca_get_canvas_height(pt.cv);
        } else {
            width = pt.PT_bitmap_width;
            height = pt.PT_bitmap_height;

        }
        pt.DITHERED_DRAW = 0;
        pt.textrenderjoblist_items = 0;
        if (!pt.PT_paused) {
            draw();
        }

        if (pt.PT_USE_DITHERING &&  pt.DITHERED_DRAW) {
            caca_dither_bitmap(caca_get_canvas(pt.dp), 0, 0, caca_get_canvas_width(pt.cv),
                               caca_get_canvas_height(pt.cv), pt.PT_dither, pt.PT_buffer);
        }
        render_text_items();

        int duration = caca_get_display_time(pt.dp);
        if (duration > 0) {
            frameRate = (frameRate * 0.9) + ((1000000 / duration) * 0.1); //(1000 / duration);
        }
        caca_printf(pt.cv, 0, caca_get_canvas_height(pt.cv) - 1, "%d/%d  key=%c (%d) fps=%f (%d)", width, height, key, key, frameRate,duration);
        caca_refresh_display(pt.dp);

    }
    if (pt.PT_USE_DITHERING)  caca_free_dither(pt.PT_dither);
    caca_free_display(pt.dp);
    caca_free_canvas(pt.cv);
    closeKeyboard();
}
Example #12
0
int main(int argc, char *argv[])
{
    caca_display_t *dp;
    caca_canvas_t *cv;

    caca_dither_t *dither;
    int x, y;

    dp = caca_create_display(NULL);
    if(dp == NULL)
    {
        printf("Can't create display\n");
        return -1;
    }

    cv = caca_get_canvas(dp);

    for(y = 0; y < 256; y++)
        for(x = 0; x < 256; x++)
    {
        buffer[y * 256 + x] = ((y * x / 256) << 16) | ((y * x / 256) << 8) | (x<< 0);
    }

    dither = caca_create_dither(32, 256, 256, 4 * 256,
                                 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
    caca_dither_bitmap(caca_get_canvas(dp), 0, 0, caca_get_canvas_width(cv),
                        caca_get_canvas_height(cv), dither, buffer);
    caca_free_dither(dither);

    caca_refresh_display(dp);

    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);

    caca_free_display(dp);

    return 0;
}
Example #13
0
/**
 * Control for vout display
 */
static int Control(vout_display_t *vd, int query, va_list args)
{
    vout_display_sys_t *sys = vd->sys;

    switch (query) {
    case VOUT_DISPLAY_HIDE_MOUSE:
        caca_set_mouse(sys->dp, 0);
        return VLC_SUCCESS;

    case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE: {
        const vout_display_cfg_t *cfg = va_arg(args, const vout_display_cfg_t *);

        caca_refresh_display(sys->dp);

        /* Not quite good but not sure how to resize it */
        if (cfg->display.width  != caca_get_display_width(sys->dp) ||
            cfg->display.height != caca_get_display_height(sys->dp))
            return VLC_EGENERIC;
        return VLC_SUCCESS;
    }

    case VOUT_DISPLAY_CHANGE_ZOOM:
    case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED:
    case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
        return VLC_SUCCESS;

    case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
        if (sys->dither)
            cucul_free_dither(sys->dither);
        sys->dither = NULL;
        return VLC_SUCCESS;

    default:
        msg_Err(vd, "Unsupported query in vout display caca");
        return VLC_EGENERIC;
    }
}
Example #14
0
void CacaWrapperGui::render() {
    caca_refresh_display(_dp);
}
Example #15
0
int main(int argc, char **argv)
{
    caca_event_t *events;
    int i, h, quit;

    cv = caca_create_canvas(80, 24);
    if(cv == NULL)
    {
        printf("Failed to create canvas\n");
        return 1;
    }

    dp = caca_create_display(cv);
    if(dp == NULL)
    {
        printf("Failed to create display\n");
        return 1;
    }

    h = caca_get_canvas_height(cv) - 1;

    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
    caca_draw_line(cv, 0, 0, caca_get_canvas_width(cv) - 1, 0, ' ');

    caca_draw_line(cv, 0, h, caca_get_canvas_width(cv) - 1, h, ' ');
    caca_put_str(cv, 0, h, "type \"quit\" to exit");

    caca_refresh_display(dp);

    events = malloc(h * sizeof(caca_event_t));
    memset(events, 0, h * sizeof(caca_event_t));

    for(quit = 0; quit < 4; )
    {
        caca_event_t ev;
        static char const * quit_string[] = { "", "q", "qu", "qui", "quit" };
        int ret = caca_get_event(dp, CACA_EVENT_ANY, &ev, -1);

        if(!ret)
            continue;

        do
        {
            /* "quit" quits */
            if(caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS)
            {
                int key = caca_get_event_key_ch(&ev);
                if((key == 'q' && quit == 0) || (key == 'u' && quit == 1)
                    || (key == 'i' && quit == 2) || (key == 't' && quit == 3))
                    quit++;
                else if(key == 'q')
                    quit = 1;
                else
                    quit = 0;
            }

            memmove(events + 1, events, (h - 1) * sizeof(caca_event_t));
            events[0] = ev;

            ret = caca_get_event(dp, CACA_EVENT_ANY, &ev, 0);
        }
        while(ret);

        caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK);
        caca_clear_canvas(cv);

        /* Print current event */
        caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
        caca_draw_line(cv, 0, 0, caca_get_canvas_width(cv) - 1, 0, ' ');
        print_event(0, 0, events);

        caca_draw_line(cv, 0, h, caca_get_canvas_width(cv) - 1, h, ' ');
        caca_printf(cv, 0, h, "type \"quit\" to exit: %s", quit_string[quit]);

        /* Print previous events */
        caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);
        for(i = 1; i < h && caca_get_event_type(&events[i]); i++)
            print_event(0, i, events + i);

        caca_refresh_display(dp);
    }

    /* Clean up */
    free(events);
    caca_free_display(dp);
    caca_free_canvas(cv);

    return 0;
}
Example #16
0
static VALUE display_refresh(VALUE self)
{
    caca_refresh_display(_SELF);
    return self;
}
Example #17
0
int main(int argc, char *argv[])
{
    caca_canvas_t *cv, *image, *tmp, *sprite;
    caca_display_t *dp;

    cv = caca_create_canvas(0, 0);
    if(cv == NULL)
    {
        printf("Can't created canvas\n");
        return -1;
    }
    dp = caca_create_display(cv);
    if(dp == NULL)
    {
        printf("Can't create display\n");
        return -1;
    }

    image = caca_create_canvas(70, 6);
    tmp = caca_create_canvas(70, 6);
    sprite = caca_create_canvas(0, 0);

    caca_set_color_ansi(sprite, CACA_LIGHTMAGENTA, CACA_BLACK);
    caca_import_canvas_from_memory(sprite, pig, strlen(pig), "text");
    caca_blit(image, 55, 0, sprite, NULL);

    caca_set_color_ansi(sprite, CACA_LIGHTGREEN, CACA_BLACK);
    caca_import_canvas_from_memory(sprite, duck, strlen(duck), "text");
    caca_blit(image, 30, 1, sprite, NULL);

    caca_set_color_ansi(image, CACA_LIGHTCYAN, CACA_BLACK);
    caca_put_str(image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]");
    caca_set_color_ansi(image, CACA_LIGHTRED, CACA_BLACK);
    caca_put_char(image, 38, 1, '|');

    caca_set_color_ansi(image, CACA_YELLOW, CACA_BLACK);
    caca_put_str(image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/");

    caca_set_color_ansi(image, CACA_WHITE, CACA_LIGHTRED);
    caca_put_str(image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌");
    caca_put_str(image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖");
    caca_set_color_ansi(image, CACA_BLACK, CACA_LIGHTRED);
    caca_put_str(image, 4, 3, "▓▒░");
    caca_put_str(image, 4, 4, "▓▒░");
    caca_put_str(image, 24, 3, "░▒▓");
    caca_put_str(image, 24, 4, "░▒▓");

    /* Blit the transformed canvas onto the main canvas */
    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
    caca_put_str(cv, 0, 0, "normal");
    caca_blit(cv, 10, 0, image, NULL);

    caca_put_str(cv, 0, 6, "flip");
    caca_blit(tmp, 0, 0, image, NULL);
    caca_flip(tmp);
    caca_blit(cv, 10, 6, tmp, NULL);

    caca_put_str(cv, 0, 12, "flop");
    caca_blit(tmp, 0, 0, image, NULL);
    caca_flop(tmp);
    caca_blit(cv, 10, 12, tmp, NULL);

    caca_put_str(cv, 0, 18, "rotate");
    caca_blit(tmp, 0, 0, image, NULL);
    caca_rotate_180(tmp);
    caca_blit(cv, 10, 18, tmp, NULL);

    caca_refresh_display(dp);

    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);

    caca_free_display(dp);
    caca_free_canvas(tmp);
    caca_free_canvas(sprite);
    caca_free_canvas(image);
    caca_free_canvas(cv);

    return 0;
}
Example #18
0
int main(int argc, char *argv[])
{
    caca_canvas_t *cv;
    caca_display_t *dp;

    cv = caca_create_canvas(0, 0);
    if(cv == NULL)
    {
        printf("Can't created canvas\n");
        return -1;
    }
    dp = caca_create_display(cv);
    if(dp == NULL)
    {
        printf("Can't create display\n");
        return -1;
    }
    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
    caca_put_str(cv, 1, 1, "Basic Unicode support");

    caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
    caca_put_str(cv, 1, 2, "This is ASCII:    | abc DEF 123 !@# |");
    caca_put_str(cv, 1, 3, "This is Unicode:  | äßç δεφ ☺♥♀ ╞╬╗ |");
    caca_put_str(cv, 1, 4, "And this is, too: | ἀβϛ ΔЗҒ ᚴᛒᛯ ♩♔✈ |");
    caca_put_str(cv, 41, 4, "Size test: 018adxmygWX'_ÍçÕĔŷ ﻙ が本");

    caca_put_str(cv, 1, 5, "If the three lines do not have the same length, there is a bug somewhere.");

    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
    caca_put_str(cv, 1, 7, "Gradient glyphs");

    caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
    caca_put_str(cv, 31,  8, "  0%");
    caca_put_str(cv, 31,  9, " 25%");
    caca_put_str(cv, 31, 10, " 50%");
    caca_put_str(cv, 31, 11, " 75%");
    caca_put_str(cv, 31, 12, "100%");

    caca_set_color_ansi(cv, CACA_LIGHTRED, CACA_LIGHTGREEN);
    caca_put_str(cv, 1,  8, "                             ");
    caca_put_str(cv, 1,  9, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
    caca_put_str(cv, 1, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
    caca_put_str(cv, 1, 11, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
    caca_put_str(cv, 1, 12, "█████████████████████████████");

    caca_set_color_ansi(cv, CACA_LIGHTGREEN, CACA_LIGHTRED);
    caca_put_str(cv, 36,  8, "█████████████████████████████");
    caca_put_str(cv, 36,  9, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
    caca_put_str(cv, 36, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
    caca_put_str(cv, 36, 11, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
    caca_put_str(cv, 36, 12, "                             ");

    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
    caca_put_str(cv, 1, 14, "Double width characters");

    caca_set_color_ansi(cv, CACA_LIGHTRED, CACA_TRANSPARENT);
    caca_put_str(cv, 1, 15, "| ドラゴン ボーレ |");
    caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
    caca_put_str(cv, 1, 16, "| ()()()() ()()() |");
    caca_set_color_ansi(cv, CACA_YELLOW, CACA_TRANSPARENT);
    caca_put_str(cv, 1, 17, "| ドラゴン");
    caca_put_str(cv, 12, 17, "ボーレ |");

    caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
    caca_put_str(cv, 1, 18, "If the three lines do not have the same length, there is a bug somewhere.");

    caca_put_str(cv, 1, 20, "CP437 glyphs: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼");
    caca_put_str(cv, 1, 21, "more CP437: α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩ ≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■");
    caca_put_str(cv, 1, 22, "drawing blocks: ███ ▓▓▓ ▒▒▒ ░░░ ▀ ▄ ▌ ▐ █ ▖ ▗ ▘ ▝ ▚ ▞ ▙ ▛ ▜ ▟ ─ │ ┌ ┐ └ ┘ ├ ┤");
    caca_put_str(cv, 1, 23, "more drawing: ┬ ┴ ┼ ═ ║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟ ╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬");
    caca_put_str(cv, 1, 24, "misc Unicode: ● ☭ ☮ ☯ ♔ ♛ ♙ ♞ ⚒ ⚓ ⚠");

    caca_refresh_display(dp);

    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);

    caca_free_display(dp);
    caca_free_canvas(cv);

    return 0;
}
Example #19
0
int main(int argc, char *argv[])
{
    caca_canvas_t *cv;
    caca_display_t *dp;
    caca_font_t *f;
    caca_dither_t *d;
    uint8_t *buf;
    unsigned int w, h;
    char const * const * fonts;

    /* Create a canvas */
    cv = caca_create_canvas(8, 2);
    if(cv == NULL)
    {
        printf("Can't create canvas\n");
        return -1;
    }


    /* Draw stuff on our canvas */
    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);
    caca_put_str(cv, 0, 0, "ABcde");
    caca_set_color_ansi(cv, CACA_LIGHTRED, CACA_BLACK);
    caca_put_str(cv, 5, 0, "\\o/");
    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
    caca_put_str(cv, 0, 1, "&$âøÿØ?!");

    /* Load a libcaca internal font */
    fonts = caca_get_font_list();
    if(fonts[0] == NULL)
    {
        fprintf(stderr, "error: libcaca was compiled without any fonts\n");
        return -1;
    }
    f = caca_load_font(fonts[0], 0);
    if(f == NULL)
    {
        fprintf(stderr, "error: could not load font \"%s\"\n", fonts[0]);
        return -1;
    }

    /* Create our bitmap buffer (32-bit ARGB) */
    w = caca_get_canvas_width(cv) * caca_get_font_width(f);
    h = caca_get_canvas_height(cv) * caca_get_font_height(f);
    buf = malloc(4 * w * h);

    /* Render the canvas onto our image buffer */
    caca_render_canvas(cv, f, buf, w, h, 4 * w);

    /* Just for fun, render the image using libcaca */
    caca_set_canvas_size(cv, 80, 32);
    dp = caca_create_display(cv);

    {
#if defined(HAVE_ENDIAN_H)
        if(__BYTE_ORDER == __BIG_ENDIAN)
#else
        /* This is compile-time optimised with at least -O1 or -Os */
        uint32_t const tmp = 0x12345678;
        if(*(uint8_t const *)&tmp == 0x12)
#endif
            d = caca_create_dither(32, w, h, 4 * w,
                                    0xff0000, 0xff00, 0xff, 0xff000000);
        else
            d = caca_create_dither(32, w, h, 4 * w,
                                    0xff00, 0xff0000, 0xff000000, 0xff);
    }

    caca_dither_bitmap(cv, 0, 0, caca_get_canvas_width(cv),
                                  caca_get_canvas_height(cv), d, buf);
    caca_refresh_display(dp);

    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);

    /* Free everything */
    caca_free_display(dp);
    free(buf);
    caca_free_dither(d);
    caca_free_font(f);
    caca_free_canvas(cv);

    return 0;
}
Example #20
0
int main(void)
{
  caca_canvas_t *cv;
  caca_display_t *dp;
  caca_event_t ev;

  // Create canvas and display
  cv = caca_create_canvas(100,80);
  if(!cv) return 1;

  dp = caca_create_display_with_driver(cv, "ncurses");
  if(!dp) return 1;

  caca_set_display_title(dp, "WPC 66");
  caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);

  // Tree stump
  caca_fill_box (cv, 47, 50, 6, 4, '|');

  // Tree body
  caca_draw_thin_triangle (cv,50,10,10,50,90,50);

  // Pot
  caca_fill_triangle(cv, 35, 53, 40, 60, 40, 53, '@');
  caca_fill_box(cv, 40, 53, 19, 8, '@');
  caca_fill_triangle(cv, 59, 60, 64, 53, 59, 53, '@');

  // Balls
  int balls[] = {50, 25, 35, 35, 25, 43, 58, 32, 68, 41, 50, 46};
  for (int i = 0; i <= 10; i += 2)
      caca_draw_thin_ellipse(cv, balls[i], balls[i+1], 2, 2);

  // Sparkly stuff
  int sparks[] = {54, 20, 42, 30, 40, 45, 46, 38, 60, 43, 75, 48};
  for (int i = 0; i <= 10; i += 2)
  {
    caca_put_char(cv, sparks[i], sparks[i+1], '*');
    caca_put_char(cv, sparks[i]-1, sparks[i+1], '<');
    caca_put_char(cv, sparks[i]+1, sparks[i+1], '>');
    caca_put_char(cv, sparks[i], sparks[i+1]-1, '^');
    caca_put_char(cv, sparks[i], sparks[i+1]+1, 'v');
  }

  // Guirlandes
  caca_draw_thin_line(cv, 32, 44, 70, 35);
  caca_draw_thin_line(cv, 17, 49, 30, 46);
  caca_draw_thin_line(cv, 60, 47, 80, 43);
  caca_draw_thin_line(cv, 43, 35, 52, 33);
  caca_draw_thin_line(cv, 55, 28, 60, 27);
  caca_draw_thin_line(cv, 40, 25, 45, 24);

  // Star outline
  caca_fill_triangle(cv, 50, 16, 40, 10, 60, 10, ' ');
  int star_x[] = {50, 45, 40, 45, 40, 45, 50, 55, 60, 55, 60, 55, 50};
  int star_y[] = { 4,  7,  7, 10, 13, 13, 16, 13, 13, 10,  7,  7,  4};
  caca_draw_thin_polyline(cv, star_x, star_y, 12);

  // Inside of star
  int star[] = {50,8,50,9,50,10,50,11,50,12,49,9,48,9,51,9,52,9,49,10,51,10,49,11,48,11,51,11,52,11};
  for (int i = 0; i <= 29; i += 2)
      caca_put_char(cv, star[i], star[i+1], '*');

  // Display and wait for key press
  caca_refresh_display(dp);
  caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
  caca_free_display(dp);
  return 0;
}
Example #21
0
int main(int argc, char *argv[])
{
    textentry entries[TEXT_ENTRIES];
    caca_canvas_t *cv;
    caca_display_t *dp;
    unsigned int i, e = 0, running = 1;

    cv = caca_create_canvas(0, 0);
    if(cv == NULL)
    {
        printf("Can't create canvas\n");
        return -1;
    }
    dp = caca_create_display(cv);
    if(dp == NULL)
    {
        printf("Can't create display\n");
        return -1;
    }
    caca_set_cursor(dp, 1);

    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
    caca_put_str(cv, 1, 1, "Text entries - press tab to cycle");

    for(i = 0; i < TEXT_ENTRIES; i++)
    {
        entries[i].buffer[0] = 0;
        entries[i].size = 0;
        entries[i].cursor = 0;
        entries[i].changed = 1;
        caca_printf(cv, 3, 3 * i + 4, "[entry %i]", i + 1);
    }

    /* Put Unicode crap in the last text entry */
    entries[TEXT_ENTRIES - 1].buffer[0] = 'A';
    entries[TEXT_ENTRIES - 1].buffer[1] = 'b';
    entries[TEXT_ENTRIES - 1].buffer[2] = caca_utf8_to_utf32("Ç", NULL);
    entries[TEXT_ENTRIES - 1].buffer[3] = caca_utf8_to_utf32("đ", NULL);
    entries[TEXT_ENTRIES - 1].buffer[4] = caca_utf8_to_utf32("ボ", NULL);
    entries[TEXT_ENTRIES - 1].buffer[5] = CACA_MAGIC_FULLWIDTH;
    entries[TEXT_ENTRIES - 1].buffer[6] = caca_utf8_to_utf32("♥", NULL);
    entries[TEXT_ENTRIES - 1].size = 7;

    while(running)
    {
        caca_event_t ev;

        for(i = 0; i < TEXT_ENTRIES; i++)
        {
            unsigned int j, start, size;

            if(!entries[i].changed)
                continue;

            caca_set_color_ansi(cv, CACA_BLACK, CACA_LIGHTGRAY);
            caca_fill_box(cv, 2, 3 * i + 5, BUFFER_SIZE + 1, 1, ' ');

            start = 0;
            size = entries[i].size;

            for(j = 0; j < size; j++)
            {
                caca_put_char(cv, 2 + j, 3 * i + 5,
                              entries[i].buffer[start + j]);
            }

            entries[i].changed = 0;
        }

        /* Put the cursor on the active textentry */
        caca_gotoxy(cv, 2 + entries[e].cursor, 3 * e + 5);

        caca_refresh_display(dp);

        if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1) == 0)
            continue;

        switch(caca_get_event_key_ch(&ev))
        {
            case CACA_KEY_ESCAPE:
                running = 0;
                break;
            case CACA_KEY_TAB:
            case CACA_KEY_RETURN:
                e = (e + 1) % TEXT_ENTRIES;
                break;
            case CACA_KEY_HOME:
                entries[e].cursor = 0;
                break;
            case CACA_KEY_END:
                entries[e].cursor = entries[e].size;
                break;
            case CACA_KEY_LEFT:
                if(entries[e].cursor)
                    entries[e].cursor--;
                break;
            case CACA_KEY_RIGHT:
                if(entries[e].cursor < entries[e].size)
                    entries[e].cursor++;
                break;
            case CACA_KEY_DELETE:
                if(entries[e].cursor < entries[e].size)
                {
                    memmove(entries[e].buffer + entries[e].cursor,
                            entries[e].buffer + entries[e].cursor + 1,
                            (entries[e].size - entries[e].cursor + 1) * 4);
                    entries[e].size--;
                    entries[e].changed = 1;
                }
                break;
            case CACA_KEY_BACKSPACE:
                if(entries[e].cursor)
                {
                    memmove(entries[e].buffer + entries[e].cursor - 1,
                            entries[e].buffer + entries[e].cursor,
                            (entries[e].size - entries[e].cursor) * 4);
                    entries[e].size--;
                    entries[e].cursor--;
                    entries[e].changed = 1;
                }
                break;
            default:
                if(entries[e].size < BUFFER_SIZE)
                {
                    memmove(entries[e].buffer + entries[e].cursor + 1,
                            entries[e].buffer + entries[e].cursor,
                            (entries[e].size - entries[e].cursor) * 4);
                    entries[e].buffer[entries[e].cursor] =
                                              caca_get_event_key_utf32(&ev);
                    entries[e].size++;
                    entries[e].cursor++;
                    entries[e].changed = 1;
                }
                break;
        }
    }

    caca_free_display(dp);
    caca_free_canvas(cv);

    return 0;
}
Example #22
0
static bool caca_gfx_frame(void *data, const void *frame,
      unsigned frame_width, unsigned frame_height, uint64_t frame_count,
      unsigned pitch, const char *msg)
{
   size_t len = 0;
   void *buffer = NULL;
   const void *frame_to_copy = frame;
   unsigned width = 0;
   unsigned height = 0;
   bool draw = true;

   (void)data;
   (void)frame;
   (void)frame_width;
   (void)frame_height;
   (void)pitch;
   (void)msg;

   if (!frame || !frame_width || !frame_height)
      return true;

   if (caca_video_width != frame_width || caca_video_height != frame_height || caca_video_pitch != pitch)
   {
      if (frame_width > 4 && frame_height > 4)
      {
         caca_video_width = frame_width;
         caca_video_height = frame_height;
         caca_video_pitch = pitch;
         caca_gfx_free(NULL);
         caca_gfx_create();
      }
   }

   if (!caca_cv)
      return true;

   if (caca_menu_frame)
      frame_to_copy = caca_menu_frame;

   width = caca_get_canvas_width(caca_cv);
   height = caca_get_canvas_height(caca_cv);

   if (frame_to_copy == frame && frame_width == 4 && frame_height == 4 && (frame_width < width && frame_height < height))
      draw = false;

   caca_clear_canvas(caca_cv);

#ifdef HAVE_MENU
   menu_driver_ctl(RARCH_MENU_CTL_FRAME, NULL);
#endif

   if (msg)
      font_driver_render_msg(NULL, msg, NULL);

   if (draw)
   {
      caca_dither_bitmap(caca_cv, 0, 0,
                         width,
                         height,
                         caca_dither, frame_to_copy);

      buffer = caca_export_canvas_to_memory(caca_cv, "caca", &len);

      if (buffer)
      {
         if (len)
            caca_refresh_display(caca_display);

         free(buffer);
      }
   }

   return true;
}
Example #23
0
static void check_events(struct vo *vo)
{
    caca_event_t cev;
    while (caca_get_event(display, CACA_EVENT_ANY, &cev, 0)) {

        switch (cev.type) {
        case CACA_EVENT_RESIZE:
            caca_refresh_display(display);
            resize();
            break;
        case CACA_EVENT_QUIT:
            mplayer_put_key(vo->key_fifo, KEY_CLOSE_WIN);
            break;
        case CACA_EVENT_MOUSE_MOTION:
            vo_mouse_movement(vo, cev.data.mouse.x, cev.data.mouse.y);
            break;
        case CACA_EVENT_MOUSE_PRESS:
            if (!vo_nomouse_input)
                mplayer_put_key(vo->key_fifo,
                        (MOUSE_BTN0 + cev.data.mouse.button - 1) | MP_KEY_DOWN);
            break;
        case CACA_EVENT_MOUSE_RELEASE:
            if (!vo_nomouse_input)
                mplayer_put_key(vo->key_fifo,
                                MOUSE_BTN0 + cev.data.mouse.button - 1);
            break;
        case CACA_EVENT_KEY_PRESS:
        {
            int key = cev.data.key.ch;
            int mpkey = lookup_keymap_table(keysym_map, key);
            const char *msg_name;

            if (mpkey)
                mplayer_put_key(vo->key_fifo, mpkey);
            else
            switch (key) {
            case 'd':
            case 'D':
                /* Toggle dithering algorithm */
                set_next_str(caca_get_dither_algorithm_list(dither),
                             &dither_algo, &msg_name);
                caca_set_dither_algorithm(dither, dither_algo);
                osdmessage(MESSAGE_DURATION, "Using %s", msg_name);
                break;

            case 'a':
            case 'A':
                /* Toggle antialiasing method */
                set_next_str(caca_get_dither_antialias_list(dither),
                             &dither_antialias, &msg_name);
                caca_set_dither_antialias(dither, dither_antialias);
                osdmessage(MESSAGE_DURATION, "Using %s", msg_name);
                break;

            case 'h':
            case 'H':
                /* Toggle charset method */
                set_next_str(caca_get_dither_charset_list(dither),
                             &dither_charset, &msg_name);
                caca_set_dither_charset(dither, dither_charset);
                osdmessage(MESSAGE_DURATION, "Using %s", msg_name);
                break;

            case 'c':
            case 'C':
                /* Toggle color method */
                set_next_str(caca_get_dither_color_list(dither),
                             &dither_color, &msg_name);
                caca_set_dither_color(dither, dither_color);
                osdmessage(MESSAGE_DURATION, "Using %s", msg_name);
                break;

            default:
                if (key <= 255)
                    mplayer_put_key(vo->key_fifo, key);
                break;
            }
        }
        }
    }
}
Example #24
0
int main(int argc, char **argv){
	SDL_AudioSpec requested, obtained;

	int quit = 0;
	int xo, yo;
	int i, j, k;
	int meter[4];

	static char chars[10] =
	{
			'+', '-', '*', '#', 'X', '@', '%', '$', 'M', 'W'
	};

	caca_display_t *dp;
	caca_canvas_t *cv;
	caca_canvas_t *pineapple;

	if(SDL_Init( SDL_INIT_AUDIO ) < 0){
		err(1, "Couldnt initialize SDL\n");
		exit(1);
	}

	cv = caca_create_canvas(80, 24);
	pineapple = caca_create_canvas(0, 0);
	if((cv == NULL) || (pineapple == NULL)){
		printf("failed to create canvas\n");
		return 1;
	}
	dp = caca_create_display(cv);
	caca_set_display_time(dp, 20000);
	if(dp == NULL){
		printf("Failed to create display\n");
		return 1;
	}

	caca_import_file(pineapple, "./pineapple", "");

	atexit(SDL_Quit);

	requested.freq = 16000;
	requested.format = AUDIO_U8;
	requested.samples = 256;
	requested.callback = audiocb;
	requested.channels = 1;

	if(SDL_OpenAudio(&requested, &obtained) == -1){
		err(1, "SDL_OpenAudio");
	}

	initchip();

	loadfile(argv[1]);

	SDL_PauseAudio(0);
	silence();
	startplaysong(0);


	while(!quit)
	{
		caca_event_t ev;
		caca_set_color_ansi(cv, CACA_DEFAULT, CACA_DEFAULT);
		caca_clear_canvas(cv);
		xo = caca_get_canvas_width(cv);
		yo = caca_get_canvas_height(cv);
		//caca_blit(cv, 0, 0, pineapple, NULL);
		caca_blit(cv, 55, 0, pineapple, NULL);
		caca_set_color_ansi(cv, caca_rand(0, 16), caca_rand(0, 16));
		caca_put_str(cv, (xo - strlen("pineapple player")) / 2, (yo / 2) - 5, "pineapple player");
		caca_set_color_ansi(cv, caca_rand(0, 16), caca_rand(0, 16));
		caca_printf(cv, (xo - strlen("song pos ->   ")) / 2, (yo / 2) - 3, "song pos -> %x", songpos);
		
		for(i = 0; i < 4; i ++)
			meter[i] = (osc[i].volume*20)/255;
		/* note visualizer */
		i = 0;
		for(j = 0; j < 25; j=j+6){
				for(k = 0; k < 4; k++){
				caca_draw_line(cv, (((xo/2)+10)-j)-k, yo, (((xo/2)+10)-j)-k, yo - meter[i], 
					chars[caca_rand(0, 9)]);
				}
			i++;
		}

		for(i = 0; i < 4; i ++)
			caca_printf(cv, 0, i, "%0x", osc[i].volume);

    while(caca_get_event(dp, CACA_EVENT_ANY, &ev, 0))
    {
    	if(caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS)
    	{
				switch(caca_get_event_key_ch(&ev))
				{
					case 'q':
					case 'Q':
					case CACA_KEY_ESCAPE:
						quit = 1;
						break;
				}
			}
		}
		caca_refresh_display(dp);
	}
	silence();
	caca_free_display(dp);
	caca_free_canvas(cv);
	return 0;
}
Example #25
0
int main(int argc, char **argv)
{
    static caca_display_t *dp;
    static caca_canvas_t *frontcv, *backcv, *mask;

    int demo, next = -1, paused = 0, next_transition = DEMO_FRAMES;
    unsigned int i;
    int tmode = caca_rand(0, TRANSITION_COUNT);

    /* Set up two canvases, a mask, and attach a display to the front one */
    frontcv = caca_create_canvas(0, 0);
    backcv = caca_create_canvas(0, 0);
    mask = caca_create_canvas(0, 0);

    dp = caca_create_display(frontcv);
    if(!dp)
        return 1;

    caca_set_canvas_size(backcv, caca_get_canvas_width(frontcv),
                         caca_get_canvas_height(frontcv));
    caca_set_canvas_size(mask, caca_get_canvas_width(frontcv),
                         caca_get_canvas_height(frontcv));

    caca_set_display_time(dp, 20000);

    /* Initialise all demos' lookup tables */
    for(i = 0; i < DEMOS; i++)
        fn[i](PREPARE, frontcv);

    /* Choose a demo at random */
    demo = caca_rand(0, DEMOS);
    fn[demo](INIT, frontcv);

    for(;;)
    {
        /* Handle events */
        caca_event_t ev;
        while(caca_get_event(dp, CACA_EVENT_KEY_PRESS
                             | CACA_EVENT_QUIT, &ev, 0))
        {
            if(caca_get_event_type(&ev) == CACA_EVENT_QUIT)
                goto end;

            switch(caca_get_event_key_ch(&ev))
            {
            case CACA_KEY_ESCAPE:
            case CACA_KEY_CTRL_C:
            case CACA_KEY_CTRL_Z:
                goto end;
            case ' ':
                paused = !paused;
                break;
            case '\r':
                if(next == -1)
                    next_transition = frame;
                break;
            }
        }

        /* Resize the spare canvas, just in case the main one changed */
        caca_set_canvas_size(backcv, caca_get_canvas_width(frontcv),
                             caca_get_canvas_height(frontcv));
        caca_set_canvas_size(mask, caca_get_canvas_width(frontcv),
                             caca_get_canvas_height(frontcv));

        if(paused)
            goto _paused;

        /* Update demo's data */
        fn[demo](UPDATE, frontcv);

        /* Handle transitions */
        if(frame == next_transition)
        {
            next = caca_rand(0, DEMOS);
            if(next == demo)
                next = (next + 1) % DEMOS;
            fn[next](INIT, backcv);
        }
        else if(frame == next_transition + TRANSITION_FRAMES)
        {
            fn[demo](FREE, frontcv);
            demo = next;
            next = -1;
            next_transition = frame + DEMO_FRAMES;
            tmode = caca_rand(0, TRANSITION_COUNT);
        }

        if(next != -1)
            fn[next](UPDATE, backcv);

        frame++;
_paused:
        /* Render main demo's canvas */
        fn[demo](RENDER, frontcv);

        /* If a transition is on its way, render it */
        if(next != -1)
        {
            fn[next](RENDER, backcv);
            caca_set_color_ansi(mask, CACA_LIGHTGRAY, CACA_BLACK);
            caca_clear_canvas(mask);
            caca_set_color_ansi(mask, CACA_WHITE, CACA_WHITE);
            transition(mask, tmode,
                       100 * (frame - next_transition) / TRANSITION_FRAMES);
            caca_blit(frontcv, 0, 0, backcv, mask);
        }

        caca_set_color_ansi(frontcv, CACA_WHITE, CACA_BLUE);
        if(frame < 100)
            caca_put_str(frontcv, caca_get_canvas_width(frontcv) - 30,
                         caca_get_canvas_height(frontcv) - 2,
                         " -=[ Powered by libcaca ]=- ");
        caca_refresh_display(dp);
    }
end:
    if(next != -1)
        fn[next](FREE, frontcv);
    fn[demo](FREE, frontcv);

    caca_free_display(dp);
    caca_free_canvas(mask);
    caca_free_canvas(backcv);
    caca_free_canvas(frontcv);

    return 0;
}
Example #26
0
/*****************************************************************************
 * Display: displays previously rendered output
 *****************************************************************************/
static void Display( vout_thread_t *p_vout, picture_t *p_pic )
{
    caca_refresh_display( p_vout->p_sys->p_dp );
}
Example #27
0
/*****************************************************************************
 * Manage: handle libcaca events
 *****************************************************************************
 * This function should be called regularly by video output thread. It manages
 * console events. It returns a non null value on error.
 *****************************************************************************/
static int Manage( vout_thread_t *p_vout )
{
#ifdef CACA_API_VERSION_1
    struct caca_event ev;
#else
    int ev;
#endif

    while( caca_get_event(p_vout->p_sys->p_dp, CACA_EVENT_ANY, &ev, 0) )
    {
        playlist_t *p_playlist;
        vlc_value_t val;

#ifdef CACA_API_VERSION_1
        switch( ev.type )
#else
        switch( ev )
#endif
        {
        case CACA_EVENT_KEY_RELEASE:
#ifdef CACA_API_VERSION_1
            switch( ev.data.key.ch )
#else
            switch( ev & 0x00ffffff )
#endif
            {
            case 'q':
                val.i_int = KEY_MODIFIER_CTRL | 'q';
                break;
            case ' ':
                val.i_int = KEY_SPACE;
                break;
            default:
                continue;
            }

            var_Set( p_vout->p_libvlc, "key-pressed", val );
            break;
        case CACA_EVENT_RESIZE:
            /* Acknowledge the resize */
            caca_refresh_display( p_vout->p_sys->p_dp );
            break;
#ifdef CACA_API_VERSION_1
        case  CACA_EVENT_MOUSE_MOTION:
            val.i_int = ev.data.mouse.x * p_vout->render.i_width
                         / cucul_get_canvas_width( p_vout->p_sys->p_cv );
            var_Set( p_vout, "mouse-x", val );
            val.i_int = ev.data.mouse.y * p_vout->render.i_height
                         / cucul_get_canvas_height( p_vout->p_sys->p_cv );
            var_Set( p_vout, "mouse-y", val );
            val.b_bool = VLC_TRUE;
            var_Set( p_vout, "mouse-moved", val );
            break;
        case CACA_EVENT_MOUSE_RELEASE:
            val.b_bool = VLC_TRUE;
            var_Set( p_vout, "mouse-clicked", val );
            break;
        case CACA_EVENT_QUIT:
        {
            p_playlist = vlc_object_find( p_vout,
                                          VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
            if( p_playlist )
            {
                playlist_Stop( p_playlist );
                vlc_object_release( p_playlist );
            }
            p_vout->p_libvlc->b_die = VLC_TRUE;
            break;
        }
#endif
        default:
            break;
        }
    }

    return VLC_SUCCESS;
}
Example #28
0
int main(int argc, char *argv[])
{
    caca_canvas_t *cv, *caca, *line;
    caca_display_t *dp;

    unsigned int i;

    cv = caca_create_canvas(0, 0);
    if(cv == NULL)
    {
        printf("Can't created canvas\n");
        return -1;
    }
    dp = caca_create_display(cv);
    if(dp == NULL)
    {
        printf("Can't create display\n");
        return -1;
    }

    caca = caca_create_canvas(6, 10);
    line = caca_create_canvas(2, 1);

    /* Line of x's */
    for(i = 0; i < 10; i++)
    {
        caca_set_color_ansi(caca, CACA_WHITE, CACA_BLUE);
        caca_put_str(caca, 0, i, CACA);
        caca_set_color_ansi(caca, CACA_WHITE, CACA_RED);
        caca_put_char(caca, i - 2, i, 'x');
    }

    caca_blit(cv, 1, 1, caca, NULL);

    /* Line of ホ's */
    for(i = 0; i < 10; i++)
    {
        caca_set_color_ansi(caca, CACA_WHITE, CACA_BLUE);
        caca_put_str(caca, 0, i, CACA);
        caca_set_color_ansi(caca, CACA_WHITE, CACA_GREEN);
        caca_put_str(caca, i - 2, i, "ホ");
    }

    caca_blit(cv, 15, 1, caca, NULL);

    /* Line of canvas */
    caca_set_color_ansi(line, CACA_WHITE, CACA_MAGENTA);
    caca_put_str(line, 0, 0, "ほ");
    for(i = 0; i < 10; i++)
    {
        caca_set_color_ansi(caca, CACA_WHITE, CACA_BLUE);
        caca_put_str(caca, 0, i, CACA);
        caca_blit(caca, i - 2, i, line, NULL);
    }

    caca_blit(cv, 29, 1, caca, NULL);

    caca_refresh_display(dp);

    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);

    caca_free_display(dp);

    caca_free_canvas(line);
    caca_free_canvas(caca);
    caca_free_canvas(cv);

    return 0;
}
Example #29
0
int main(int argc, char *argv[]) {

	caca_canvas_t *cv;
	caca_canvas_t *figcv;
	caca_display_t *dp;
	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;
		}
	}



	cv = caca_create_canvas(0, 0);
	figcv = caca_create_canvas(0, 0);
	if(!cv || !figcv)
	{  
		fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]);
		return 1;
	}

	if(caca_canvas_set_figfont(figcv, font))
	{  
		fprintf(stderr, "Could not open font\n");
		return -1;
	}


	dp = caca_create_display(cv);
	if(!dp) {
		printf("Can't open window. CACA_DRIVER problem ?\n");
		return -1;
	}

	caca_set_color_ansi(figcv, CACA_DEFAULT, CACA_DEFAULT);
	caca_clear_canvas(cv);
	for(;;) {
		caca_event_t ev;

		while(caca_get_event(dp, CACA_EVENT_KEY_PRESS
					| CACA_EVENT_QUIT, &ev, 1))
		{  
			if(caca_get_event_type(&ev))
				goto end;
		}
		char *d = get_date(format);
		uint32_t o = 0;

		// figfont API is not complete, and does not allow us to put a string
		// at another position than 0,0
		// So, we have to create a canvas which will hold the figfont string,
		// then blit this canvas to the main one at the desired position.
		caca_clear_canvas(cv);
		caca_clear_canvas(figcv);
		while(d[o])
		{  
			caca_put_figchar(figcv, d[o++]);
		}
		caca_flush_figlet (figcv);
		free(d);

		w = caca_get_canvas_width (cv);
		h = caca_get_canvas_height(cv);
        fw = caca_get_canvas_width (figcv);
		fh = caca_get_canvas_height(figcv);	

		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);
		usleep(250000);
	}
end:

	caca_free_canvas(figcv);
	caca_free_canvas(cv);
	caca_free_display(dp);

	return 0;
}
Example #30
0
static void flip_page(struct vo *vo)
{
    caca_refresh_display(display);
}