コード例 #1
0
ファイル: driver.c プロジェクト: gitpan/Term-Caca
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;
}
コード例 #2
0
ファイル: test_caca.c プロジェクト: xspager/Terra_CHIP8
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;
}
コード例 #3
0
ファイル: CacaWrapperGui.cpp プロジェクト: elominp/cpp_arcade
std::list<int>* CacaWrapperGui::getEvents() const{
    std::list<int>* events = new std::list<int>();
    int search;
    int retKey;
    int retok = 0;
    caca_event_t     _ev;

  retok = caca_get_event(_dp, CACA_EVENT_KEY_PRESS, &_ev, 0);
   retKey = caca_get_event_key_ch(&_ev);
    search = this->_eventKeyboard.find(retKey)->second;
    if (search != 0 && retok)
        events->push_back(search);
  return events;

}
コード例 #4
0
ファイル: truecolor.c プロジェクト: gitpan/Term-Caca
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;
}
コード例 #5
0
ファイル: blit.c プロジェクト: zougloub/libcaca
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;
}
コード例 #6
0
ファイル: hsv.c プロジェクト: gitpan/Term-Caca
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;
}
コード例 #7
0
ファイル: testcaca.c プロジェクト: jjo/um-posix-dev
int main(void)
{
	int event;
	int ch;
	struct caca_sprite *carita=NULL;

	if (caca_init()) 
		return 1;
	caca_set_feature(CACA_ANTIALIASING_PREFILTER);
	caca_set_delay(40000);
	caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_RED);
	caca_draw_thin_box(0,0,10,2);
	caca_refresh();
	carita=caca_load_sprite("carita.txt");
	while(1) {
		while((event = caca_get_event(CACA_EVENT_ANY))) {
			caca_set_color(CACA_COLOR_BLACK, CACA_COLOR_WHITE);
			caca_printf(1,1, "%x\n", event);
			if(event & CACA_EVENT_KEY_PRESS)
			{
				ch=event & 0xffff;
				switch(ch)
				{
					case 'q':
					case 'Q':
						goto fin;
					case '0'...'9':  /* extension gcc */
						caca_set_color(caca_rand(2,14), CACA_COLOR_BLACK);
						caca_draw_thin_line(0,3,caca_get_width(),3+(ch-'0')*10);
					default:
						if (carita)
							caca_draw_sprite(caca_rand(4,caca_get_width()), caca_rand(4,caca_get_height()), carita, 0);
				}
			}
			caca_refresh();
		}
	}
コード例 #8
0
ファイル: font.c プロジェクト: Kirkman/libcaca
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;
}
コード例 #9
0
ファイル: transform.c プロジェクト: mwgoldsmith/caca
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;
}
コード例 #10
0
ファイル: wpc66.c プロジェクト: Karikaturist/WPC
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;
}
コード例 #11
0
ファイル: cacadraw.c プロジェクト: gitpan/Term-Caca
int main(int argc, char **argv)
{
    int refresh = 1, file = 1;
    unsigned int iw = 0, ih = 0;

    if(argc < 2)
    {
        fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
        return 1;
    }

    cv = caca_create_canvas(0, 0);
    if(!cv)
        return 1;
    dp = caca_create_display(cv);
    if(!dp)
        return 1;

    for(;;)
    {
        caca_event_t ev;
        unsigned int w, h;
        int dx = 0, dy = 0;

        if(!image)
        {
            image = caca_create_canvas(0, 0);
            if(caca_import_canvas_from_file(image, argv[file], "ansi") < 0)
            {
                fprintf(stderr, "%s: invalid file `%s'.\n", argv[0], argv[1]);
                return 1;
            }

            ih = caca_get_canvas_height(image);
            iw = caca_get_canvas_width(image);
            x = y = 0;

            caca_set_display_title(dp, argv[file]);

            refresh = 1;
        }

        if(refresh)
        {
            refresh_screen();
            refresh = 0;
        }

        while(caca_get_event(dp, CACA_EVENT_ANY, &ev, -1))
        {
            switch(caca_get_event_type(&ev))
            {
                case CACA_EVENT_QUIT:
                    goto quit;
                case CACA_EVENT_KEY_PRESS:
                    switch(caca_get_event_key_ch(&ev))
                    {
                    case CACA_KEY_LEFT: dx -= 2; break;
                    case CACA_KEY_RIGHT: dx += 2; break;
                    case CACA_KEY_UP: dy--; break;
                    case CACA_KEY_DOWN: dy++; break;
                    case CACA_KEY_PAGEUP: dy -= 12; break;
                    case CACA_KEY_PAGEDOWN: dy += 12; break;
                    case CACA_KEY_ESCAPE:
                    case 'q':
                        goto quit;
                    case 'n':
                        file = file + 1 < argc ? file + 1 : 1;
                        caca_free_canvas(image);
                        image = NULL;
                        goto stopevents;
                    case 'p':
                        file = file > 1 ? file - 1 : argc - 1;
                        caca_free_canvas(image);
                        image = NULL;
                        goto stopevents;
                    default:
                        break;
                    }
                case CACA_EVENT_RESIZE:
                    refresh = 1;
                    goto stopevents;
                default:
                    break;
            }
        }
stopevents:

        w = caca_get_canvas_width(cv);
        h = caca_get_canvas_height(cv);

        if(dx | dy)
        {
            refresh = 1;
            x += dx;
            y += dy;

            if(x < 0) x = 0; else if(x + w > iw) x = iw > w ? iw - w : 0;
            if(y < 0) y = 0; else if(y + h > ih) y = ih > h ? ih - h : 0;
        }
    }
quit:

    /* Clean up */
    caca_free_display(dp);
    caca_free_canvas(image);
    caca_free_canvas(cv);

    return 0;
}
コード例 #12
0
ファイル: trifiller.c プロジェクト: gitpan/Term-Caca
int main(int argc, char *argv[])
{

    /* libcaca/libcaca contexts */
    caca_canvas_t *cv;
    caca_display_t *dp;
    caca_canvas_t *tex;

    /* cached canvas size */
    int ww, wh, tw, th;

    /* logic */
    int quit = 0;
    int update = 1;
    int px, py;
    float angle = 0;


    float square[6][2] = {
        {-SQUARE_SIZE, -SQUARE_SIZE},
        {SQUARE_SIZE, -SQUARE_SIZE},
        {SQUARE_SIZE, SQUARE_SIZE},
        {-SQUARE_SIZE, SQUARE_SIZE},
    };
    float uv1[6] = {
        0, 0,
        1, 0,
        1, 1
    };
    float uv2[6] = {
        0, 0,
        1, 1,
        0, 1
    };


    float rotated[4][2];
    int coords1[6], coords2[6];

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

    /* Create texture holding canvas */
    tex = caca_create_canvas(16, 16);
    if (!tex)
    {
        fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]);
        return 1;
    }

    /* Open window */
    dp = caca_create_display(cv);
    if (!dp)
    {
        fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]);
        return 1;
    }



    /* Set the window title */
    caca_set_display_title(dp, "trifiller");

    /* Frame duration */
    caca_set_display_time(dp, 10000);

    /* Get displayed canvas size */
    ww = caca_get_canvas_width(cv);
    wh = caca_get_canvas_height(cv);

    /* Texture size */
    tw = caca_get_canvas_width(tex);
    th = caca_get_canvas_height(tex);

    /* Load texture if any */
    if (argc == 2)
    {
        struct image *im = load_image(argv[1]);
        if (!im)
        {
            fprintf(stderr, "%s: unable to load image '%s'\n", argv[0],
                    argv[1]);
            return 1;
        }

        caca_set_dither_algorithm(im->dither,
                                  caca_get_dither_algorithm_list(NULL)[4]);
        caca_dither_bitmap(tex, 0, 0, tw, th, im->dither, im->pixels);
        unload_image(im);
    }
    /* or generate one */
    else
    {

        int i;
        for (i = 0; i < 16; i++)
        {
            caca_set_color_ansi(tex, (i + 1) % 0xF, i % 0xF);
            caca_put_str(tex, 0, i, "0123456789ABCDEF");
        }
    }


    px = 0;
    py = 0;

    while (!quit)
    {
        caca_event_t ev;
        unsigned int const event_mask = CACA_EVENT_KEY_PRESS
            | CACA_EVENT_RESIZE | CACA_EVENT_QUIT;
        int event;

        if (update)
            event = caca_get_event(dp, event_mask, &ev, 0);
        else
            event = caca_get_event(dp, event_mask, &ev, -1);

        while (event)
        {
            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;
                case CACA_KEY_UP:
                    py--;
                    break;
                case CACA_KEY_DOWN:
                    py++;
                    break;
                case CACA_KEY_LEFT:
                    px--;
                    break;
                case CACA_KEY_RIGHT:
                    px++;
                    break;
                case 'a':
                    angle += 1.0f;
                    break;
                case 's':
                    angle -= 1.0f;
                    break;
                }
            else if (caca_get_event_type(&ev) == CACA_EVENT_RESIZE)
            {
                caca_refresh_display(dp);
                ww = caca_get_event_resize_width(&ev);
                wh = caca_get_event_resize_height(&ev);
                update = 1;
            }
            else if (caca_get_event_type(&ev) & CACA_EVENT_QUIT)
                quit = 1;

            event = caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0);
        }



        /* 2D Rotation around screen center */
        int p;
        for (p = 0; p < 4; p++)
        {
            rotated[p][0] =
                square[p][0] * cos(angle * M_PI / 180.0f) -
                square[p][1] * sin(angle * M_PI / 180.0f);
            rotated[p][1] =
                square[p][0] * sin(angle * M_PI / 180.0f) +
                square[p][1] * cos(angle * M_PI / 180.0f);

            rotated[p][0] += ww / 2 + px;
            rotated[p][1] += wh / 2 + py;
        }

        angle += 1.0f;


        /* Reaarange coordinates to fit libcaca's format */
        coords1[0] = rotated[0][0];
        coords1[1] = rotated[0][1];
        coords1[2] = rotated[1][0];
        coords1[3] = rotated[1][1];
        coords1[4] = rotated[2][0];
        coords1[5] = rotated[2][1];

        coords2[0] = rotated[0][0];
        coords2[1] = rotated[0][1];
        coords2[2] = rotated[2][0];
        coords2[3] = rotated[2][1];
        coords2[4] = rotated[3][0];
        coords2[5] = rotated[3][1];

        /* Display two triangles */
        caca_fill_triangle_textured(cv, /* canvas */
                                    coords1,    /* triangle coordinates */
                                    tex,        /* texture canvas */
                                    uv1);       /* texture coordinates */
        caca_fill_triangle_textured(cv, coords2, tex, uv2);

        /* Refresh display and clear for next frame */
        caca_refresh_display(dp);
        caca_clear_canvas(cv);

    }

    caca_free_display(dp);
    caca_free_canvas(cv);
    caca_free_canvas(tex);

    return 0;
}
コード例 #13
0
ファイル: vo_caca.c プロジェクト: divVerent/mplayer2
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;
            }
        }
        }
    }
}
コード例 #14
0
ファイル: cacaclock.c プロジェクト: gitpan/Term-Caca
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;
}
コード例 #15
0
ファイル: player.c プロジェクト: dinosaurdemon/pineapple
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;
}
コード例 #16
0
ファイル: caca-display.c プロジェクト: Kirkman/libcaca
static VALUE get_event(VALUE self, VALUE event_mask, VALUE timeout)
{
    char utf8[8];
    caca_event_t ev;
    VALUE e;

    event_mask = rb_funcall(event_mask, rb_intern("to_i"), 0);

    if(caca_get_event(_SELF, NUM2UINT(event_mask), &ev, NUM2INT(timeout)) == 0)
    {
        return Qnil;
    }

    switch(caca_get_event_type(&ev))
    {
    case CACA_EVENT_KEY_PRESS:
        caca_get_event_key_utf8(&ev, utf8);
        e = rb_funcall(cEventKeyPress, rb_intern("new"), 3,
                       UINT2NUM(caca_get_event_key_ch(&ev)),
                       ULONG2NUM(caca_get_event_key_utf32(&ev)),
                       rb_str_new(utf8, 8));
        break;
    case CACA_EVENT_KEY_RELEASE:
        caca_get_event_key_utf8(&ev, utf8);
        e = rb_funcall(cEventKeyRelease, rb_intern("new"), 3,
                       UINT2NUM(caca_get_event_key_ch(&ev)),
                       ULONG2NUM(caca_get_event_key_utf32(&ev)),
                       rb_str_new(utf8, 8));
        break;
    case CACA_EVENT_MOUSE_PRESS:
        e = rb_funcall(cEventMousePress, rb_intern("new"), 3,
                       UINT2NUM(caca_get_event_mouse_x(&ev)),
                       UINT2NUM(caca_get_event_mouse_y(&ev)),
                       UINT2NUM(caca_get_event_mouse_button(&ev)));
        break;
    case CACA_EVENT_MOUSE_RELEASE:
        e = rb_funcall(cEventMouseRelease, rb_intern("new"), 3,
                       UINT2NUM(caca_get_event_mouse_x(&ev)),
                       UINT2NUM(caca_get_event_mouse_y(&ev)),
                       UINT2NUM(caca_get_event_mouse_button(&ev)));
        break;
    case CACA_EVENT_MOUSE_MOTION:
        e = rb_funcall(cEventMouseMotion, rb_intern("new"), 3,
                       UINT2NUM(caca_get_event_mouse_x(&ev)),
                       UINT2NUM(caca_get_event_mouse_y(&ev)),
                       Qnil);
        break;
    case CACA_EVENT_RESIZE:
        e = rb_funcall(cEventResize, rb_intern("new"), 2,
                       UINT2NUM(caca_get_event_resize_width(&ev)),
                       UINT2NUM(caca_get_event_resize_height(&ev)));
        break;
    case CACA_EVENT_QUIT:
        e = rb_funcall(cEventQuit, rb_intern("new"), 0);
        break;
    default:
        rb_raise(rb_eRuntimeError, "Invalid event received !");
    }

    return e;
}
コード例 #17
0
ファイル: unicode.c プロジェクト: gitpan/Term-Caca
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;
}
コード例 #18
0
ファイル: input.c プロジェクト: gitpan/Term-Caca
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;
}
コード例 #19
0
ファイル: event.c プロジェクト: mwgoldsmith/caca
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;
}
コード例 #20
0
ファイル: cacademo.c プロジェクト: zougloub/libcaca
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;
}
コード例 #21
0
ファイル: caca.c プロジェクト: 0xheart0/vlc
/**
 * Proccess pending event
 */
static void Manage(vout_display_t *vd)
{
    vout_display_sys_t *sys = vd->sys;

    struct caca_event ev;
    while (caca_get_event(sys->dp, CACA_EVENT_ANY, &ev, 0) > 0) {
        switch (caca_get_event_type(&ev)) {
        case CACA_EVENT_KEY_PRESS: {
            const int caca = caca_get_event_key_ch(&ev);

            for (int i = 0; keys[i].caca != -1; i++) {
                if (keys[i].caca == caca) {
                    const int vlc = keys[i].vlc;

                    if (vlc >= 0)
                        vout_display_SendEventKey(vd, vlc);
                    return;
                }
            }
            if (caca >= 0x20 && caca <= 0x7f) {
                vout_display_SendEventKey(vd, caca);
                return;
            }
            break;
        }
        case CACA_EVENT_RESIZE:
            vout_display_SendEventDisplaySize(vd, caca_get_event_resize_width(&ev),
                                                  caca_get_event_resize_height(&ev));
            break;
        case CACA_EVENT_MOUSE_MOTION: {
            vout_display_place_t place;
            Place(vd, &place);

            const unsigned x = vd->source.i_x_offset +
                               (int64_t)(caca_get_event_mouse_x(&ev) - place.x) *
                                    vd->source.i_visible_width / place.width;
            const unsigned y = vd->source.i_y_offset +
                               (int64_t)(caca_get_event_mouse_y(&ev) - place.y) *
                                    vd->source.i_visible_height / place.height;

            caca_set_mouse(sys->dp, 1);
            vout_display_SendEventMouseMoved(vd, x, y);
            break;
        }
        case CACA_EVENT_MOUSE_PRESS:
        case CACA_EVENT_MOUSE_RELEASE: {
            caca_set_mouse(sys->dp, 1);
            const int caca = caca_get_event_mouse_button(&ev);
            for (int i = 0; mouses[i].caca != -1; i++) {
                if (mouses[i].caca == caca) {
                    if (caca_get_event_type(&ev) == CACA_EVENT_MOUSE_PRESS)
                        vout_display_SendEventMousePressed(vd, mouses[i].vlc);
                    else
                        vout_display_SendEventMouseReleased(vd, mouses[i].vlc);
                    return;
                }
            }
            break;
        }
        case CACA_EVENT_QUIT:
            vout_display_SendEventClose(vd);
            break;
        default:
            break;
        }
    }
}
コード例 #22
0
ファイル: fullwidth.c プロジェクト: gitpan/Term-Caca
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;
}
コード例 #23
0
ファイル: vo_caca.c プロジェクト: BOTCrusher/sagetv
static void check_events (void)
{
    unsigned int cev;

    if ((cev = caca_get_event(CACA_EVENT_ANY)))
    {
	if (cev & CACA_EVENT_RESIZE)
	{
	    caca_refresh();
	    resize();
	} else if (cev & CACA_EVENT_KEY_RELEASE)
	{
	    int key = (cev & 0x00ffffff);
	    enum caca_feature cf;

	    switch (key) {
	    case 'd':
	    case 'D':
	      /* Toggle dithering method */
	      cf = 1 + caca_get_feature(CACA_DITHERING);
	      if (cf > CACA_DITHERING_MAX)
		  cf = CACA_DITHERING_MIN;
	      caca_set_feature(cf);
	      osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf));
	      break;

	    case 'a':
	    case 'A':
	      /* Toggle antialiasing method */
	      cf = 1 + caca_get_feature(CACA_ANTIALIASING);
	      if (cf > CACA_ANTIALIASING_MAX)
		  cf = CACA_ANTIALIASING_MIN;
	      caca_set_feature(cf);
	      osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf));
	      break;

	    case 'b':
	    case 'B':
	      /* Toggle background method */
	      cf = 1 + caca_get_feature(CACA_BACKGROUND);
	      if (cf > CACA_BACKGROUND_MAX)
		  cf = CACA_BACKGROUND_MIN;
	      caca_set_feature(cf);
	      osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf));
	      break;

	    case CACA_KEY_UP:
	      mplayer_put_key(KEY_UP);
	      break;
	    case CACA_KEY_DOWN:
	      mplayer_put_key(KEY_DOWN);
	      break;
	    case CACA_KEY_LEFT:
	      mplayer_put_key(KEY_LEFT);
	      break;
	    case CACA_KEY_RIGHT:
	      mplayer_put_key(KEY_RIGHT);
	      break;
	    case CACA_KEY_ESCAPE:
	      mplayer_put_key(KEY_ESC);
	      break;
	    case CACA_KEY_PAGEUP:
	      mplayer_put_key(KEY_PAGE_UP);
	      break;
	    case CACA_KEY_PAGEDOWN:
	      mplayer_put_key(KEY_PAGE_DOWN);
	      break;
	    case CACA_KEY_RETURN:
	      mplayer_put_key(KEY_ENTER);
	      break;
	    case CACA_KEY_HOME:
	      mplayer_put_key(KEY_HOME);
	      break;
	    case CACA_KEY_END:
	      mplayer_put_key(KEY_END);
	      break;
	    default:
	      if (key <= 255)
		  mplayer_put_key (key);
	      break;
	    }
	}
    }
}
コード例 #24
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;
}