diff --git a/doc/manual.md b/doc/manual.md index 485c944..3ee2a47 100644 --- a/doc/manual.md +++ b/doc/manual.md @@ -25,7 +25,12 @@ syscalls.Event. ### Text encoding +```lua +syscalls.Encoding. +``` + + `cp866` ++ `cp866_8x16` + `utf8` + `utf16` @@ -52,7 +57,9 @@ syscalls.textSize. + `56x112` + `64x128` -### `DrawText(text, xPos, yPos, textColor, textSize, textLen, backgroundColor, encoding)` +### `DrawText(text, xPos, yPos, textColor, textScale, textLen, backgroundColor, encoding)` + +### `DrawTextFixSize(text, xPos, yPos, textColor, textSize, textLen, backgroundColor, encoding)` Draw text. diff --git a/src/graphic.c b/src/graphic.c index 0b4ff89..220c93c 100644 --- a/src/graphic.c +++ b/src/graphic.c @@ -28,8 +28,29 @@ int syscalls_drawLine(lua_State* L) return 0; } +static void drawText(char* text, uint32_t x, uint32_t y, ksys_color_t color, size_t len, uint64_t backgroundColor) +{ + bool fillBackground = !(backgroundColor << 32); -static void syscall_drawText(const char* text, uint32_t x, uint32_t y, ksys_color_t color, enum TextScale size, uint32_t len, bool fillBackground, ksys_color_t backgroundColor, enum DrawTextEncoding encoding) + color |= (fillBackground << 30); + + if (len == 0) + { + color |= (1 << 31); + } + + asm_inline( + "int $0x40" + ::"a"(4), + "b"((x << 16) | y), + "c"(color), + "d"(text), + "S"(len), + "D"((uint32_t)backgroundColor)); +} + + +static void syscall_drawText(const char* text, uint32_t x, uint32_t y, ksys_color_t color, enum TextScale size, uint32_t len, uint64_t backgroundColor, enum DrawTextEncoding encoding) { enum DrawTextEncoding_ @@ -53,9 +74,6 @@ static void syscall_drawText(const char* text, uint32_t x, uint32_t y, ksys_colo color &= 0x00FFFFFF; - color |= (fillBackground << 30); - - switch (size) { case TextScale_SIZE_6x9: @@ -110,32 +128,38 @@ static void syscall_drawText(const char* text, uint32_t x, uint32_t y, ksys_colo break; }; - if (len == NULL) - color |= (1 << 31); - - asm_inline( - "int $0x40" ::"a"(4), - "b"((x << 16) | y), - "c"(color), - "d"(text), - "S"(len), - "D"(backgroundColor)); + drawText(text, x, y, color, len, backgroundColor); } int syscalls_drawText(lua_State* L) { - LUA_INTEGER backgroundColor = luaL_optinteger(L, 7, 0); + const char text = luaL_checkstring(L, 1); + uint32_t x = luaL_checkinteger(L, 2); + uint32_t y = luaL_checkinteger(L, 3); + ksys_color_t color = luaL_checkinteger(L, 4); + uint8_t scale = luaL_optinteger(L, 5, 1); + uint32_t len = luaL_optinteger(L, 6, 0); + LUA_INTEGER backgroundColor = luaL_optinteger(L, 7, 1 << 32); + enum DrawTextEncoding encoding = luaL_optinteger(L, 8, DEFAULT_ENCODING); + color |= (encoding << 28) | (scale << 24); + + drawText(text, x, y, color, len, backgroundColor); + + return 0; +} + +int syscalls_drawTextFixSize(lua_State* L) +{ syscall_drawText( luaL_checkstring(L, 1), luaL_checkinteger(L, 2), luaL_checkinteger(L, 3), luaL_checkinteger(L, 4), luaL_optinteger(L, 5, TextScale_SIZE_8x16), - luaL_optinteger(L, 6, NULL), - backgroundColor << 32, - backgroundColor, - luaL_optinteger(L, 8, cp866) + luaL_optinteger(L, 6, 0), + luaL_optinteger(L, 7, 1 << 32), + luaL_optinteger(L, 8, DEFAULT_ENCODING) ); return 0; diff --git a/src/graphic.h b/src/graphic.h index 1194a6d..84574a2 100644 --- a/src/graphic.h +++ b/src/graphic.h @@ -27,12 +27,16 @@ enum TextScale enum DrawTextEncoding { cp866 = 1, + cp866_8x16 = 2, utf8 = 3, utf16 = 4 }; +#define DEFAULT_ENCODING cp866 + int syscalls_drawLine(lua_State* L); int syscalls_drawText(lua_State* L); +int syscalls_drawTextFixSize(lua_State* L); int syscalls_drawRectangle(lua_State* L); int syscalls_ReadPoint(lua_State* L); int syscalls_screenSize(lua_State* L); @@ -99,6 +103,9 @@ inline void syscalls_push_Encoding(lua_State* L) lua_pushinteger(L, cp866); lua_setfield(L, -2, "cp866"); + lua_pushinteger(L, cp866_8x16); + lua_setfield(L, -2, "cp866_8x16"); + lua_pushinteger(L, utf8); lua_setfield(L, -2, "utf8"); diff --git a/src/sockets/socket.h b/src/sockets/socket.h index c3f396c..12cfe3b 100644 --- a/src/sockets/socket.h +++ b/src/sockets/socket.h @@ -88,4 +88,4 @@ int setsockopt(int socket, const optstruct* opt); int getsockopt(int socket, optstruct* opt); int socketpair(int* socket1, int* socket2); -#endif //_SOCKET_H_ \ No newline at end of file +#endif //_SOCKET_H_ diff --git a/src/syscalls.c b/src/syscalls.c index 002b4fa..717a367 100644 --- a/src/syscalls.c +++ b/src/syscalls.c @@ -1565,6 +1565,7 @@ static const luaL_Reg syscallsLib[] = { {"DrawLine", syscalls_drawLine}, {"DrawPixel", syscalls_drawPixel}, {"DrawText", syscalls_drawText}, + {"DrawTextFixSize", syscalls_drawTextFixSize}, {"DrawRectangle", syscalls_drawRectangle}, {"ReadPoint", syscalls_ReadPoint}, /* keyboard funcs */