Пример #1
0
int init() {
    initMillis () ;
    initKeyboard();

    pthread_t k_t;
    pthread_create(&k_t, NULL, &keyboard_thread, NULL);

    printf("init ");
    sprintf(pt.density, " .',-+:;=o&%%/$*W@#");

    pt.C_stroke_r = 255;
    pt.C_stroke_g = 255;
    pt.C_stroke_b = 255;

    pt.C_color = 0;
    pt.C_pixel = '.';
    pt.running = 1;
    pt.PT_paused = 0;
    pt.PT_keyblocked = 0;

 

    pt.PT_bitmap_width  = 120;
    pt.PT_bitmap_height = 80;

    ellipseMode(CENTER);
    pt.cv = caca_create_canvas(0, 0);
    if (!pt.cv) {
        fprintf(stderr, "unable to initialise libcaca\n");
        return 1;
    }

    pt.dp = caca_create_display_with_driver(pt.cv, "ncurses"); // x11, raw..
    if (pt.dp == NULL ) {
        printf("Failed to create display\n");
        return 1;
    }
    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;

    }
   // caca_set_display_time(pt.dp,40000);
    useDithering();
    stroke(255);
    setDitherResolution(caca_get_canvas_width(pt.cv), caca_get_canvas_height(pt.cv));
    background(0);
    printf("done ");

    return 0;
}
Пример #2
0
/**
 * This function initializes libcaca vout method.
 */
static int Open(vlc_object_t *object)
{
    vout_display_t *vd = (vout_display_t *)object;
    vout_display_sys_t *sys;

    if (vout_display_IsWindowed(vd))
        return VLC_EGENERIC;
#if !defined(__APPLE__) && !defined(_WIN32)
# ifndef X_DISPLAY_MISSING
    if (!vlc_xlib_init(object))
        return VLC_EGENERIC;
# endif
#endif

#if defined(_WIN32)
    CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
    SMALL_RECT rect;
    COORD coord;
    HANDLE hstdout;

    if (!AllocConsole()) {
        msg_Err(vd, "cannot create console");
        return VLC_EGENERIC;
    }

    hstdout =
        CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
                                  FILE_SHARE_READ | FILE_SHARE_WRITE,
                                  NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
    if (!hstdout || hstdout == INVALID_HANDLE_VALUE) {
        msg_Err(vd, "cannot create screen buffer");
        FreeConsole();
        return VLC_EGENERIC;
    }

    if (!SetConsoleActiveScreenBuffer(hstdout)) {
        msg_Err(vd, "cannot set active screen buffer");
        FreeConsole();
        return VLC_EGENERIC;
    }

    coord = GetLargestConsoleWindowSize(hstdout);
    msg_Dbg(vd, "SetConsoleWindowInfo: %ix%i", coord.X, coord.Y);

    /* Force size for now */
    coord.X = 100;
    coord.Y = 40;

    if (!SetConsoleScreenBufferSize(hstdout, coord))
        msg_Warn(vd, "SetConsoleScreenBufferSize %i %i",
                  coord.X, coord.Y);

    /* Get the current screen buffer size and window position. */
    if (GetConsoleScreenBufferInfo(hstdout, &csbiInfo)) {
        rect.Top = 0; rect.Left = 0;
        rect.Right = csbiInfo.dwMaximumWindowSize.X - 1;
        rect.Bottom = csbiInfo.dwMaximumWindowSize.Y - 1;
        if (!SetConsoleWindowInfo(hstdout, TRUE, &rect))
            msg_Dbg(vd, "SetConsoleWindowInfo failed: %ix%i",
                     rect.Right, rect.Bottom);
    }
#endif

    /* Allocate structure */
    vd->sys = sys = calloc(1, sizeof(*sys));
    if (!sys)
        goto error;

    sys->cv = cucul_create_canvas(0, 0);
    if (!sys->cv) {
        msg_Err(vd, "cannot initialize libcucul");
        goto error;
    }

    const char *driver = NULL;
#ifdef __APPLE__
    // Make sure we don't try to open a window.
    driver = "ncurses";
#endif

    sys->dp = caca_create_display_with_driver(sys->cv, driver);
    if (!sys->dp) {
        msg_Err(vd, "cannot initialize libcaca");
        goto error;
    }

    if (vd->cfg->display.title)
        caca_set_display_title(sys->dp,
                               vd->cfg->display.title);
    else
        caca_set_display_title(sys->dp,
                               VOUT_TITLE "(Colour AsCii Art)");

    /* Fix format */
    video_format_t fmt = vd->fmt;
    if (fmt.i_chroma != VLC_CODEC_RGB32) {
        fmt.i_chroma = VLC_CODEC_RGB32;
        fmt.i_rmask = 0x00ff0000;
        fmt.i_gmask = 0x0000ff00;
        fmt.i_bmask = 0x000000ff;
    }

    /* TODO */
    vout_display_info_t info = vd->info;

    /* Setup vout_display now that everything is fine */
    vd->fmt = fmt;
    vd->info = info;

    vd->pool    = Pool;
    vd->prepare = Prepare;
    vd->display = PictureDisplay;
    vd->control = Control;
    vd->manage  = Manage;

    /* Fix initial state */
    vout_display_SendEventFullscreen(vd, false);
    Refresh(vd);

    return VLC_SUCCESS;

error:
    if (sys) {
        if (sys->pool)
            picture_pool_Release(sys->pool);
        if (sys->dither)
            cucul_free_dither(sys->dither);
        if (sys->dp)
            caca_free_display(sys->dp);
        if (sys->cv)
            cucul_free_canvas(sys->cv);

        free(sys);
    }
#if defined(_WIN32)
    FreeConsole();
#endif
    return VLC_EGENERIC;
}
Пример #3
0
/** \brief Attach a caca graphical context to a caca canvas.
 *
 *  Create a graphical context using device-dependent features (ncurses for
 *  terminals, an X11 window, a DOS command window...) that attaches to a
 *  libcaca canvas. Everything that gets drawn in the libcaca canvas can
 *  then be displayed by the libcaca driver.
 *
 *  If no caca canvas is provided, a new one is created. Its handle can be
 *  retrieved using caca_get_canvas() and it is automatically destroyed when
 *  caca_free_display() is called.
 *
 *  See also caca_create_display_with_driver().
 *
 *  If an error occurs, NULL is returned and \b errno is set accordingly:
 *  - \c ENOMEM Not enough memory.
 *  - \c ENODEV Graphical device could not be initialised.
 *
 *  \param cv The caca canvas or NULL to create a canvas automatically.
 *  \return The caca graphical context or NULL if an error occurred.
 */
caca_display_t * caca_create_display(caca_canvas_t *cv)
{
    return caca_create_display_with_driver(cv, NULL);
}
Пример #4
0
static VALUE display_initialize(int argc, VALUE* argv, VALUE self)
{
    caca_display_t *display;
    caca_canvas_t *canvas = NULL;
    const char *driver = NULL;
    VALUE cv = Qnil;
    VALUE arg1, arg2;

    rb_scan_args(argc, argv, "02", &arg1, &arg2);

    if(CLASS_OF(arg1) == cCanvas)
    {
        cv = arg1;
        if(CLASS_OF(arg2) == cCanvas)
        {
            rb_raise(rb_eArgError, "Only one argument can be a Caca::Canvas");
        }
    }
    else if(CLASS_OF(arg2) == cCanvas)
    {
        cv = arg2;
    }

    if(TYPE(arg1) == T_STRING)
    {
        driver = StringValuePtr(arg1);
        if(TYPE(arg2) == T_STRING)
        {
            rb_raise(rb_eArgError, "Only one argument can be a string");
        }
    }
    else if(TYPE(arg2) == T_STRING)
    {
        driver = StringValuePtr(arg2);
    }

    if(cv !=  Qnil)
        canvas = DATA_PTR(cv);

    if(driver == NULL)
    {
        display = caca_create_display(canvas);
        if(display && NIL_P(cv))
        {
            cv = canvas_create(caca_get_canvas(display));
        }
    }
    else
    {
        display = caca_create_display_with_driver(canvas, driver);
    }

    if(display == NULL)
    {
        rb_raise(rb_eRuntimeError, "%s", strerror(errno));
    }

    _SELF = display;

    rb_iv_set(self, "@canvas", cv);

    return self;
}
Пример #5
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;
}