size_t ppm_to_patch(void **lumpdata, const char *filename, int insert_x, int insert_y) { void *data; size_t size = read_or_die(&data, filename); int i, width, height, *column_colours; unsigned char *pixels, **columns, *patch; size_t *columnsizes, totalcolumnsize, offset; pixels = parseppm(data, size, filename, &width, &height); columns = xmalloc(width * sizeof(*columns)); columnsizes = xmalloc(width * sizeof(*columnsizes)); column_colours = xmalloc(height * sizeof(*column_colours)); for (totalcolumnsize = i = 0; i < width; i++) { pixels_to_colours(column_colours, pixels, width, height, i); columnsizes[i] = createcolumn(&columns[i], column_colours, height); totalcolumnsize += columnsizes[i]; } patch = xmalloc(8+4*width+totalcolumnsize); ((short *)patch)[0] = SHORT(width); ((short *)patch)[1] = SHORT(height); ((short *)patch)[2] = SHORT(insert_x); ((short *)patch)[3] = SHORT(insert_y); for (offset = 8+4*width, i = 0; i < width; i++) { ((int *)(patch+8))[i] = LONG(offset); offset += columnsizes[i]; } for (offset = 8+4*width, i = 0; i < width; i++) { memmove(patch + offset, columns[i], columnsizes[i]); offset += columnsizes[i]; free(columns[i]); } free(column_colours); free(columnsizes); free(columns); free(data); *lumpdata = patch; return 8+4*width+totalcolumnsize; }
Wind* windmk(char *label, char *target) { Wind *w; w = mallocz(sizeof(*w), 1); w->cs = newcontrolset(screen, nil, nil, nil); w->column = createcolumn(w->cs, "column"); w->top = createlabel(w->cs, "top"); w->body = createtext(w->cs, "body"); w->input = createentry(w->cs, "input"); w->event = chancreate(sizeof(char*), 0); w->blines = 0; if(target != nil) w->target = strdup(target); ctlprint(w->top, "value %s", label); ctlprint(w->top, "border 1"); ctlprint(w->top, "size %d %d %d %d", 10, font->height+1, 10000, font->height+1); ctlprint(w->body, "border 1"); ctlprint(w->body, "scroll 1"); ctlprint(w->input, "border 1"); ctlprint(w->input, "size %d %d %d %d", 10, font->height+1, 10000, font->height+1); controlwire(w->input, "event", w->event); chanprint(w->cs->ctl, "column add top"); chanprint(w->cs->ctl, "column add body"); chanprint(w->cs->ctl, "column add input"); activate(w->input); return w; }