text.d 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. module scripts.lua.text;
  2. import bindbc.lua;
  3. import raylib;
  4. import variables;
  5. import graphics.effects;
  6. import std.conv;
  7. import system.debugwriteln;
  8. import system.config;
  9. import std.string;
  10. import std.algorithm;
  11. import system.init;
  12. import graphics.playback;
  13. import std.file;
  14. import graphics.collision;
  15. import audio.sfx;
  16. extern (C) nothrow int luaL_drawText(lua_State *L) {
  17. const char* text = luaL_checkstring(L, 1);
  18. int x = cast(int)luaL_checkinteger(L, 2);
  19. int y = cast(int)luaL_checkinteger(L, 3);
  20. int fontSize = cast(int)luaL_optinteger(L, 4, 20);
  21. Color color = Colors.WHITE;
  22. if (lua_istable(L, 5)) {
  23. lua_getfield(L, 5, "r");
  24. color.r = cast(ubyte)lua_tointeger(L, -1);
  25. lua_pop(L, 1);
  26. lua_getfield(L, 5, "g");
  27. color.g = cast(ubyte)lua_tointeger(L, -1);
  28. lua_pop(L, 1);
  29. lua_getfield(L, 5, "b");
  30. color.b = cast(ubyte)lua_tointeger(L, -1);
  31. lua_pop(L, 1);
  32. lua_getfield(L, 5, "a");
  33. color.a = cast(ubyte)lua_tointeger(L, -1);
  34. lua_pop(L, 1);
  35. }
  36. DrawTextEx(textFont, text, Vector2(x, y), fontSize, 1.0f, color);
  37. return 0;
  38. }
  39. extern (C) nothrow int luaL_measureTextX(lua_State *L) {
  40. lua_pushinteger(L, cast(int)MeasureTextEx(textFont, luaL_checkstring(L, 1), cast(int)luaL_checkinteger(L, 2), 1.0f).x);
  41. return 1;
  42. }
  43. extern (C) nothrow int luaL_measureTextY(lua_State *L) {
  44. lua_pushinteger(L, cast(int)MeasureTextEx(textFont, luaL_checkstring(L, 1), cast(int)luaL_checkinteger(L, 2), 1.0f).y);
  45. return 1;
  46. }