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; }
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; }
void gui_console_init(int argc, char *argv[], int w, int h, int bpp) { c_ui.dp = caca_create_display(NULL); c_ui.cv = caca_get_canvas(c_ui.dp); c_ui.ww = caca_get_canvas_width(c_ui.cv); c_ui.wh = caca_get_canvas_height(c_ui.cv); caca_set_display_title(c_ui.dp, PACKAGE_NAME); c_ui.im = caca_create_dither( bpp, w, h, 3 * w /*stride*/, 0xff0000, 0x00ff00, 0x0000ff, 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; }
static void caca_gfx_create() { caca_display = caca_create_display(NULL); caca_cv = caca_get_canvas(caca_display); if(!caca_video_width || !caca_video_height) { caca_video_width = caca_get_canvas_width(caca_cv); caca_video_height = caca_get_canvas_height(caca_cv); } if (caca_rgb32) caca_dither = caca_create_dither(32, caca_video_width, caca_video_height, caca_video_pitch, 0x00ff0000, 0xff00, 0xff, 0x0); else caca_dither = caca_create_dither(16, caca_video_width, caca_video_height, caca_video_pitch, 0xf800, 0x7e0, 0x1f, 0x0); video_driver_set_size(&caca_video_width, &caca_video_height); }
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(); }
CacaWrapperGui::CacaWrapperGui() { _dp = caca_create_display(NULL); _cv = caca_get_canvas(_dp); caca_set_display_title(_dp, "THE GAME!"); initEventType(); }
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; }