Changeset 1194 for toilet/trunk
- Timestamp:
- Oct 10, 2006, 1:54:40 AM (16 years ago)
- Location:
- toilet/trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
toilet/trunk/src/main.c
r1193 r1194 170 170 } 171 171 172 #if 0173 if(optind >= argc)174 #endif175 176 #if 0177 /* Render string to canvas */178 172 if(!strcasecmp(cx->font, "mono9")) 179 { 180 cv = render_big(string, length); 181 filter_autocrop(cv); 182 } 183 else if(!strcasecmp(cx->font, "term")) 184 cv = render_tiny(string, length); 185 else 186 cv = render_figlet(cx, string, length); 187 #endif 188 189 init_tiny(cx); 173 init_big(cx); 174 else /* if(!strcasecmp(cx->font, "term")) */ 175 init_tiny(cx); 190 176 191 177 if(optind >= argc) … … 230 216 231 217 /* Apply optional effects to our string */ 218 if(!strcasecmp(cx->font, "mono9")) 219 filter_autocrop(cx->cv); 232 220 if(flag_metal) 233 221 filter_metal(cx->cv); -
toilet/trunk/src/render.c
r1193 r1194 30 30 static int end_tiny(context_t *); 31 31 32 static int feed_big(context_t *, uint32_t); 33 static int end_big(context_t *); 34 32 35 int init_tiny(context_t *cx) 33 36 { … … 46 49 static int feed_tiny(context_t *cx, uint32_t ch) 47 50 { 48 if(cx->x >= cx->w) 49 cx->w = cx->x + 1; 51 /* Check whether we reached the end of the screen */ 52 if(cx->x && cx->x + 1 > cx->term_width) 53 { 54 cx->x = 0; 55 cx->y++; 56 } 50 57 51 if(cx->y >= cx->h) 58 /* Check whether the current canvas is large enough */ 59 if(cx->x + 1 > cx->w) 60 { 61 cx->w = cx->x + 1 < cx->term_width ? cx->x + 1 : cx->term_width; 62 if(cx->w > cx->ew) 63 cx->ew = cx->ew + cx->ew / 2; 64 } 65 66 if(cx->y + 1 > cx->h) 67 { 52 68 cx->h = cx->y + 1; 69 if(cx->h > cx->eh) 70 cx->eh = cx->eh + cx->eh / 2; 71 } 72 73 cucul_set_canvas_size(cx->cv, cx->ew, cx->eh); 53 74 54 75 switch(ch) … … 69 90 } 70 91 71 if(cx->x >= cx->term_width)72 {73 cx->x = 0;74 cx->y++;75 }76 77 if(cx->x >= cx->ew)78 cx->ew = cx->ew + cx->ew / 2;79 80 if(cx->y >= cx->eh)81 cx->eh = cx->eh + cx->eh / 2;82 83 cucul_set_canvas_size(cx->cv, cx->ew, cx->eh);84 85 92 return 0; 86 93 } … … 93 100 } 94 101 95 #if 0 96 cucul_canvas_t *render_big(uint32_t const *string, unsigned int length) 102 int init_big(context_t *cx) 97 103 { 98 cucul_canvas_t *cv;99 cucul_font_t *f;100 104 char const * const * fonts; 101 unsigned char *buf;102 unsigned int w, h, x, y, miny, maxy;103 104 cv = cucul_create_canvas(length, 1);105 cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);106 for(x = 0; x < length; x++)107 cucul_putchar(cv, x, 0, string[x]);108 105 109 106 fonts = cucul_get_font_list(); 110 f = cucul_load_font(fonts[0], 0); 107 cx->f = cucul_load_font(fonts[0], 0); 108 cx->buf = malloc(4 * cucul_get_font_width(cx->f) 109 * cucul_get_font_height(cx->f)); 110 cx->onechar = cucul_create_canvas(1, 1); 111 cucul_set_color(cx->onechar, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); 111 112 112 /* Create our bitmap buffer (32-bit ARGB) */ 113 w = cucul_get_canvas_width(cv) * cucul_get_font_width(f); 114 h = cucul_get_canvas_height(cv) * cucul_get_font_height(f); 115 buf = malloc(4 * w * h); 113 cx->x = cx->y = 0; 114 cx->w = cx->h = 0; 115 cx->cv = cucul_create_canvas(1, 1); 116 116 117 /* Render the canvas onto our image buffer */118 c ucul_render_canvas(cv, f, buf, w, h, 4 * w);117 cx->feed = feed_big; 118 cx->end = end_big; 119 119 120 /* Free our canvas, and allocate a bigger one */ 121 cucul_free_font(f); 122 cucul_free_canvas(cv); 123 cv = cucul_create_canvas(w, h); 120 return 0; 121 } 124 122 125 /* Render the image buffer on the canvas */ 126 cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_TRANSPARENT); 127 cucul_clear_canvas(cv); 123 static int feed_big(context_t *cx, uint32_t ch) 124 { 125 unsigned int w = cucul_get_font_width(cx->f); 126 unsigned int h = cucul_get_font_height(cx->f); 127 unsigned int x, y; 128 128 129 miny = h; maxy = 0; 129 /* Check whether we reached the end of the screen */ 130 if(cx->x && cx->x + w > cx->term_width) 131 { 132 cx->x = 0; 133 cx->y += h; 134 } 135 136 /* Check whether the current canvas is large enough */ 137 if(cx->x + w > cx->w) 138 cx->w = cx->x + w < cx->term_width ? cx->x + w : cx->term_width; 139 140 if(cx->y + h > cx->h) 141 cx->h = cx->y + h; 142 143 cucul_set_canvas_size(cx->cv, cx->w, cx->h); 144 145 /* Render our char */ 146 cucul_putchar(cx->onechar, 0, 0, ch); 147 cucul_render_canvas(cx->onechar, cx->f, cx->buf, w, h, 4 * w); 130 148 131 149 for(y = 0; y < h; y++) 132 150 for(x = 0; x < w; x++) 133 151 { 134 unsigned char c = buf[4 * (x + y * w) + 2];152 unsigned char c = cx->buf[4 * (x + y * w) + 2]; 135 153 136 154 if(c >= 0xa0) 137 cucul_putstr(c v, x,y, "█");155 cucul_putstr(cx->cv, cx->x + x, cx->y + y, "█"); 138 156 else if(c >= 0x80) 139 cucul_putstr(c v, x,y, "▓");157 cucul_putstr(cx->cv, cx->x + x, cx->y + y, "▓"); 140 158 else if(c >= 0x40) 141 cucul_putstr(c v, x,y, "▒");159 cucul_putstr(cx->cv, cx->x + x, cx->y + y, "▒"); 142 160 else if(c >= 0x20) 143 cucul_putstr(c v, x,y, "░");161 cucul_putstr(cx->cv, cx->x + x, cx->y + y, "░"); 144 162 } 145 163 146 free(buf); 164 /* Advance cursor */ 165 cx->x += w; 147 166 148 return cv;167 return 0; 149 168 } 150 #endif151 169 170 static int end_big(context_t *cx) 171 { 172 cucul_free_canvas(cx->onechar); 173 free(cx->buf); 174 cucul_free_font(cx->f); 175 176 return 0; 177 } 178 -
toilet/trunk/src/render.h
r1193 r1194 17 17 18 18 extern int init_tiny(context_t *); 19 extern int init_big(context_t *); 19 20 -
toilet/trunk/src/toilet.h
r1193 r1194 27 27 unsigned int w, h, ew, eh, x, y; 28 28 29 /* Methods */ 29 30 int (*feed)(struct toilet_context *, uint32_t); 30 31 int (*end)(struct toilet_context *); 32 33 /* Used by the big driver */ 34 cucul_font_t *f; 35 cucul_canvas_t *onechar; 36 unsigned char *buf; 31 37 }; 32 38
Note: See TracChangeset
for help on using the changeset viewer.