Rename DrawText to DrawTextFixSize and create DrawText
This commit is contained in:
@@ -25,7 +25,12 @@ syscalls.Event.<EventName>
|
||||
|
||||
### Text encoding
|
||||
|
||||
```lua
|
||||
syscalls.Encoding.<value>
|
||||
```
|
||||
|
||||
+ `cp866`
|
||||
+ `cp866_8x16`
|
||||
+ `utf8`
|
||||
+ `utf16`
|
||||
|
||||
@@ -52,7 +57,9 @@ syscalls.textSize.<value>
|
||||
+ `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.
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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");
|
||||
|
||||
|
@@ -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_
|
||||
#endif //_SOCKET_H_
|
||||
|
@@ -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 */
|
||||
|
Reference in New Issue
Block a user