Пример #1
0
void render_text_items() {
    for (int i = 0; i < pt.textrenderjoblist_items; i++) {
        if (pt.textrenderjoblist[i].type == TEXT_INT) {
            caca_printf(pt.cv, pt.textrenderjoblist[i].x * X_SCALE, pt.textrenderjoblist[i].y, "%d", pt.textrenderjoblist[i].value_int);
        }
        if (pt.textrenderjoblist[i].type == TEXT_FLOAT) {
            caca_printf(pt.cv, pt.textrenderjoblist[i].x * X_SCALE, pt.textrenderjoblist[i].y, "%f", pt.textrenderjoblist[i].value_float);
        }
        if (pt.textrenderjoblist[i].type == TEXT_U_INT) {
            caca_printf(pt.cv, pt.textrenderjoblist[i].x * X_SCALE, pt.textrenderjoblist[i].y, "%d", pt.textrenderjoblist[i].value_u_int);
        }
    }
}
Пример #2
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;
}
Пример #3
0
void point(int x, int y) {
    if (!pt.PT_USE_DITHERING) {
        caca_printf(pt.cv, x * X_SCALE, y, "%c", pt.C_pixel);
    } else {

        set_pixel_in_bitmap(x, y, pt.C_color);
    }
}
Пример #4
0
void list_driver() {
    pt.list = caca_get_display_driver_list();

    int i, cur = 0;
    caca_printf(pt.cv, 2, 1, "Available drivers:");
    char const *driver;
    driver = caca_get_display_driver(pt.dp);
    caca_set_color_ansi(pt.cv, CACA_WHITE, CACA_RED);
    for (i = 0; pt.list[i]; i += 2) {
        int match = !strcmp(pt.list[i], driver);

        if (match) {
            cur = i;
        }
        caca_printf(pt.cv, 2, i + 2, "%c %s (%s)",  match ? '*' : ' ', pt.list[i], pt.list[i + 1]);
    }
}
Пример #5
0
static void print_event(int x, int y, caca_event_t *ev)
{
    int character;

    switch(caca_get_event_type(ev))
    {
    case CACA_EVENT_NONE:
        caca_printf(cv, x, y, "CACA_EVENT_NONE");
        break;
    case CACA_EVENT_KEY_PRESS:
        character = caca_get_event_key_ch(ev);
        caca_printf(cv, x, y, "CACA_EVENT_KEY_PRESS 0x%02x (%c)", character,
                     (character > 0x1f && character < 0x80) ? character : '?');
        break;
    case CACA_EVENT_KEY_RELEASE:
        character = caca_get_event_key_ch(ev);
        caca_printf(cv, x, y, "CACA_EVENT_KEY_RELEASE 0x%02x (%c)", character,
                     (character > 0x1f && character < 0x80) ? character : '?');
        break;
    case CACA_EVENT_MOUSE_MOTION:
        caca_printf(cv, x, y, "CACA_EVENT_MOUSE_MOTION %u %u",
                     caca_get_event_mouse_x(ev), caca_get_event_mouse_y(ev));
        break;
    case CACA_EVENT_MOUSE_PRESS:
        caca_printf(cv, x, y, "CACA_EVENT_MOUSE_PRESS %u",
                     caca_get_event_mouse_button(ev));
        break;
    case CACA_EVENT_MOUSE_RELEASE:
        caca_printf(cv, x, y, "CACA_EVENT_MOUSE_RELEASE %u",
                     caca_get_event_mouse_button(ev));
        break;
    case CACA_EVENT_RESIZE:
        caca_printf(cv, x, y, "CACA_EVENT_RESIZE %u %u",
                     caca_get_event_resize_width(ev),
                     caca_get_event_resize_height(ev));
        break;
    case CACA_EVENT_QUIT:
        caca_printf(cv, x, y, "CACA_EVENT_QUIT");
        break;
    default:
        caca_printf(cv, x, y, "CACA_EVENT_UNKNOWN");
    }
}
Пример #6
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();
}
Пример #7
0
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
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;
}
Пример #9
0
int process_menu(uint8_t scancode)
{
  static union _modifier_state modifier_state;
  static uint8_t last_scancode;
  uint8_t ret=0;

  //Nur Flanke auswerten
  if(last_scancode==0xff && scancode!=0xff)
  {
    //Taste gedrückt?
    if(scancode!=0xff)
    {
#ifndef AVR
      caca_printf(cv,1,4,"8x8 scancode(0..63) = %i  ",scancode);
#endif
      //Wandlung von 8x8 Keycode auf ASCII oder Modifier
      uint8_t c=characters[scancode];
      uint8_t printable_char=0;
      //Prüfen ob ASCII Zeichen
      if(c)
      {
        //printf("%c %i\n",c,c);
        if(modifier_state.SHIFT || modifier_state.CAPS)
        { //alternative Belegung
          switch(c)
          {
            case '1': c='!'; break;
            case '2': c='"'; break;
            case '3': c='^'; break;
            case '4': c='$'; break;
            case '5': c='%'; break;
            case '6': c='&'; break;
            case '7': c='/'; break;
            case '8': c='('; break;
            case '9': c=')'; break;
            case '0': c='='; break;
            case '\\': c='?'; break;
            case '+': c='*'; break;
            case '#': c='\''; break;
            case '<': c='>'; break;
            case ',': c=';'; break;
            case '.': c=':'; break;
            case '@': c='|'; break;
            default:
             c = toupper(c);
             break;
          }
        }
        //Ist es auf dem LCD anzeigbar?
        if(isprint(c))
        {
          //Shift zurücksetzen
          modifier_state.SHIFT=0;
          printable_char=c;
        }
        else
        {
          //Andere Funktion mit ASCII Zeichen wie \b, \r, \t
          if(c=='\b')
          {
            if(cursor_x>0)
            {
              cursor_viewport_calc(_LEFT, &cursor_x,&cursor_y,&viewport_x,&viewport_y, 0);
              delete_ch(cursor_x, cursor_y);
            }
          }
          else if(c=='\r')
          {
            cursor_viewport_calc(_DOWN, &cursor_x,&cursor_y,&viewport_x,&viewport_y, 0);
            cursor_x=get_line_end(cursor_y);
            cursor_viewport_calc(0, &cursor_x,&cursor_y,&viewport_x,&viewport_y, 0);
          }
          //else if(c=='\t')
          // TODO? ;
        }
      }
      else /*muss ein Modifier, Cursor, Funktionstaste oder ähnlich sein*/
      {
        //printf("Not an ASCII char. scancode=%i\n",scancode);
        switch(scancode)
        {
          case _SHIFT: modifier_state.SHIFT=1; break;
          case _CAPS : modifier_state.CAPS=!modifier_state.CAPS; break;
          case _ALT  : modifier_state.ALT=!modifier_state.ALT; break;
          case _STRG : modifier_state.STRG=1; break;
          case _ENTF :if(modifier_state.SHIFT)
                        modifier_state.OVERWRITE=!modifier_state.OVERWRITE;
                      else
                        delete_ch(cursor_x, cursor_y);
                      break;
          case _ENDE :  cursor_x=(modifier_state.SHIFT)?0:get_line_end(cursor_y);
                        modifier_state.SHIFT=0;
                        break;
          case _ESC  :  clr_text_buffer(); cursor_x=0; cursor_y=0; break;
          default:
            break;
        }

        //Nur wenn nicht SHIFT, sonst könnten es
        //Cursortasten -_{} oder F3, F4 [] sein
        if(!modifier_state.SHIFT)
        {
          switch(scancode)
          {
            case _F1: if(font_size>3) font_size--; updated_settings=1; break;
            case _F2: if(font_size<9) font_size++; updated_settings=1; break;
            case _F4: strncpy(font_name,strcmp(font_name,"rowmans")? "rowmans": "scripts", 10); updated_settings=1; break;
            default:
              break;
          }
          cursor_viewport_calc(scancode, &cursor_x,&cursor_y,&viewport_x,&viewport_y, modifier_state.ALT);
        }
        else
          switch(scancode)
          {
            case _DOWN:  printable_char='-'; break;
            case _LEFT:  printable_char='_'; break;
            case _UP:    printable_char='{'; break;
            case _RIGHT: printable_char='}'; break;
            case _F3:    printable_char='['; break;
            case _F4:    printable_char=']'; break;
            default:
              break;
          }
          if(printable_char) //Shift zurücksetzen
            modifier_state.SHIFT=0;
      }
      if(isprint(printable_char))
      {
        //Einfügen oder Überschreiben?
        if(modifier_state.OVERWRITE)
          text_buffer[cursor_y][cursor_x]=printable_char;
        else
          insert_ch(cursor_x, cursor_y, printable_char);

        //Ein Zeichen weiter rechts
        cursor_viewport_calc(_RIGHT, &cursor_x,&cursor_y,&viewport_x,&viewport_y, 0);
      }
      ret=1;
    }
  }
  last_scancode=scancode;

#ifndef AVR
  if(scancode!=0xff)
  {
    char line0[LCD_WIDTH+1];
    char line1[LCD_WIDTH+1];

    strncpy(line0,text_buffer[viewport_y]+viewport_x,LCD_WIDTH);
    strncpy(line1,text_buffer[viewport_y+1]+viewport_x,LCD_WIDTH);
    line0[LCD_WIDTH]=0;
    line1[LCD_WIDTH]=0;

    draw_lcd(line0, line1, viewport_x, viewport_y, cursor_x, cursor_y);
  }
#endif

  return ret;
}
Пример #10
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;
}
Пример #11
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;
}