a_sprite * compile_sprtext (const a_fontdata *font, const char *text, enum text_option topt, unsigned int maxwidth, int offset) { unsigned int nspaces; unsigned int text_width = 0; check_message_is_drawable (font, text); if (topt & T_FLUSHED_LEFT) { /* FLUSHED_LEFT or JUSTIFIED */ if (topt & T_FLUSHED_RIGHT) { /* JUSTIFIED */ text_width = compute_text_width (font, text, &nspaces); if (nspaces == 0) { /* we cannot justify a text without spaces */ topt &= ~T_JUSTIFIED; topt |= T_FLUSHED_LEFT; } } } else { /* FLUSHED_RIGHT or CENTERED */ text_width = compute_text_width (font, text, 0); if (topt & T_FLUSHED_RIGHT) /* FLUSHED_RIGHT */ offset -= (int) text_width; else /* CENTERED */ offset -= (int) text_width/2; } new_sprprog (); for (; *text; ++text) { if (*text == ' ') { if ((topt & T_JUSTIFIED) == T_JUSTIFIED) { unsigned int off = (maxwidth - text_width) / nspaces; offset += off; text_width += off; --nspaces; } else offset += font->width[' ']; } else { /* ensure that the letter actually exists before drawing it */ if (font->width[UCHAR (*text)]) add_sprprog (compile_sprrle (font->upper_left[UCHAR (*text)], 0, font->height, font->width[UCHAR (*text)], font->line_size, xbuf), offset); offset += font->width[UCHAR (*text)]; } } if (topt & T_WAVING) return end_sprprogwav (); else return end_sprprog (); }
static a_sprite * get_tile_sprite (unsigned int offset) { /* convert an offset-in-image, into a tile-number */ int tile_row = offset / (tile_set_img.width * 20); int tile_col = (offset % (tile_set_img.width * 20)) / 24; int tile_pos = tile_row * (tile_set_img.width / 24) + tile_col; /* don't recompile the sprite if it's already done */ if (!tile_transp[tile_pos]) tile_transp[tile_pos] = compile_sprrle (tile_set_img.buffer + offset, 0, 20, 24, tile_set_img.width, xbuf); return tile_transp[tile_pos]; }