void font_puts(font_t* font, graphics_t* graphics, graphics_pos_t x, graphics_pos_t y, const char* s) { if(x >= (graphics_pos_t)graphics_width(graphics) || y >= (graphics_pos_t)graphics_height(graphics)) return; uint8_t tabs_count = 0; graphics_pos_t orig_x = x; while(*s){ switch(*s){ case '\r': x = orig_x; s ++; break; case '\n': x = orig_x; y += font->symbol_height + font->vspace; s ++; break; case '\t': font_putc(font, graphics, x, y, 0x20); x += font->symbol_width + font->hspace; if(++ tabs_count == FONT_TAB_SIZE){ tabs_count = 0; s ++; } break; default: font_putc(font, graphics, x, y, *s); x += font->symbol_width + font->hspace; s ++; break; } if(y >= (graphics_pos_t)graphics_width(graphics)) break; } }
static int l_textbox_putc(lua_State *L) { l_textbox *tb; uint32_t c; SDL_Color fg; uint32_t width; SDL_Rect srect, prect; tb = l_checkTextbox(L, 1); c = luaL_checkint(L, 2); get_color(tb, FG_INDEX, &fg); width = font_putc(tb->font, c, tb->s, tb->x, tb->y, &fg); _update_screen(tb); tb->x += width; lua_pushnumber(L, width); return 1; }