change DrawText func && update manual #1
12
.vscode/settings.json
vendored
12
.vscode/settings.json
vendored
@@ -4,9 +4,14 @@
|
||||
"files.associations": {
|
||||
"stdlib.h": "c",
|
||||
"ksys.h": "c",
|
||||
"socket.h": "c"
|
||||
"socket.h": "c",
|
||||
"graphic.h": "c"
|
||||
},
|
||||
"cSpell.words": [
|
||||
"syscalls",
|
||||
"INET",
|
||||
"IPPROTO",
|
||||
"DGRAM",
|
||||
"ksys",
|
||||
"ksys_oskey_t",
|
||||
"LUALIB_API",
|
||||
@@ -15,17 +20,18 @@
|
||||
"tonumber",
|
||||
"luaL_newmetatable",
|
||||
"luaL_setmetatable",
|
||||
"lua_createtable",
|
||||
"luaL_setfuncs",
|
||||
"luaL_checkinteger",
|
||||
"luaL_checkstring",
|
||||
"luaL_checkudata",
|
||||
"luaL_optinteger",
|
||||
"lua_pushboolean",
|
||||
"lua_pushinteger",
|
||||
"lua_pushnumber",
|
||||
"luaL_optinteger",
|
||||
"lua_pushstring",
|
||||
"lua_pushnil",
|
||||
"lua_createtable",
|
||||
"lua_newtable",
|
||||
"lua_touserdata",
|
||||
"lua_setfield",
|
||||
"lua_getfield",
|
||||
|
2
Makefile
2
Makefile
@@ -15,7 +15,7 @@ else
|
||||
TOOLCHAIN_PATH = /home/autobuild/tools/win32
|
||||
endif
|
||||
|
||||
KOLIBRIOS_REPO = ../kolibrios
|
||||
KOLIBRIOS_REPO = $(abspath ../kolibrios)
|
||||
|
||||
|
||||
|
||||
|
@@ -12,18 +12,77 @@ local syscalls = require("syscalls")
|
||||
syscalls.Event.<EventName>
|
||||
```
|
||||
|
||||
|
||||
+ `Redraw`
|
||||
+ `Button`
|
||||
+ `Key`
|
||||
+ `Desktop`
|
||||
+ `Mouse`
|
||||
+ `Network`
|
||||
+ `IPC`
|
||||
+ `Debug`
|
||||
|
||||
## Graphic
|
||||
|
||||
### Text encoding
|
||||
|
||||
```lua
|
||||
syscalls.Encoding.<value>
|
||||
```
|
||||
|
||||
+ `cp866`
|
||||
+ `cp866_8x16`
|
||||
+ `utf8`
|
||||
+ `utf16`
|
||||
|
||||
### Text sizes
|
||||
|
||||
```lua
|
||||
syscalls.textSize.<value>
|
||||
```
|
||||
|
||||
+ `6x9` (cp866 only)
|
||||
+ `8x16`
|
||||
+ `12x18` (cp866 only)
|
||||
+ `16x32`
|
||||
+ `18x27` (cp866 only)
|
||||
+ `24x36` (cp866 only)
|
||||
+ `24x48`
|
||||
+ `30x45` (cp866 only)
|
||||
+ `32x64`
|
||||
+ `36x54` (cp866 only)
|
||||
+ `40x80`
|
||||
+ `42x63` (cp866 only)
|
||||
+ `48x72` (cp866 only)
|
||||
+ `48x96`
|
||||
+ `56x112`
|
||||
+ `64x128`
|
||||
|
||||
### `DrawText(text, xPos, yPos, textColor, textScale, textLen, backgroundColor, encoding)`
|
||||
|
||||
### `DrawTextFixSize(text, xPos, yPos, textColor, textSize, textLen, backgroundColor, encoding)`
|
||||
|
||||
Draw text.
|
||||
|
||||
textSize, textLen, backgroundColor, encoding are optional.
|
||||
|
||||
### `DrawLine(x1, y1, x2, y2)`
|
||||
|
||||
### `DrawRectangle(x, y, w, h color)`
|
||||
|
||||
### `ReadPoint(x, y)`
|
||||
|
||||
return color
|
||||
|
||||
## Sockets
|
||||
|
||||
### OpenSocket
|
||||
### `OpenSocket(domain, type, protocol)`
|
||||
|
||||
```lua
|
||||
local socket, err = syscalls.OpenSocket()
|
||||
local socket, err = syscalls.OpenSocket(
|
||||
syscalls.SOCK.STREAM,
|
||||
syscalls.AF.INET,
|
||||
syscalls.IPPROTO.IP
|
||||
)
|
||||
|
||||
if err then
|
||||
print("Error", err)
|
||||
@@ -32,9 +91,9 @@ else
|
||||
end
|
||||
```
|
||||
|
||||
### CloseSocket(socket)
|
||||
### `CloseSocket(socket)`
|
||||
|
||||
### PairSocket()
|
||||
### `PairSocket()`
|
||||
|
||||
```lua
|
||||
local first, second = PairSocket()
|
||||
@@ -46,19 +105,19 @@ else
|
||||
end
|
||||
```
|
||||
|
||||
### Bind(socket, address)
|
||||
### `Bind(socket, address)`
|
||||
|
||||
### Listen(socket, backlog)
|
||||
### `Listen(socket, backlog)`
|
||||
|
||||
### Connect()
|
||||
### `Connect(socket, address)`
|
||||
|
||||
### Accept
|
||||
### `Accept(socket, , flags)`
|
||||
|
||||
### Receive
|
||||
### `Receive(socket, , flags)`
|
||||
|
||||
## SetSocketOption
|
||||
### `SetSocketOption(socket, opt)`
|
||||
|
||||
### GetSocketOption
|
||||
### `GetSocketOption(socket, opt)`
|
||||
|
||||
### Socket types
|
||||
|
||||
|
@@ -28,17 +28,38 @@ int syscalls_drawLine(lua_State* L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
static void drawText(char* text, uint32_t x, uint32_t y, ksys_color_t color, size_t len, uint64_t backgroundColor)
|
||||
{
|
||||
enum DrawTextEncoding
|
||||
bool fillBackground = !(backgroundColor << 32);
|
||||
|
||||
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_
|
||||
{
|
||||
cp866_6x9 = 0,
|
||||
cp866_8x16 = 1,
|
||||
utf8 = 3,
|
||||
utf16 = 4
|
||||
cp866_8x16 = 1
|
||||
};
|
||||
|
||||
|
||||
enum scale
|
||||
{
|
||||
scale_x1 = 0,
|
||||
@@ -53,21 +74,19 @@ 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:
|
||||
color |= (cp866_8x16 << 28) | (scale_x1 << 24);
|
||||
color |= (cp866_6x9 << 28) | (scale_x1 << 24);
|
||||
break;
|
||||
case TextScale_SIZE_8x16:
|
||||
color |= (cp866_8x16 << 28);
|
||||
color |= (encoding << 28) | (scale_x1 << 24);
|
||||
break;
|
||||
case TextScale_SIZE_12x18:
|
||||
color |= (cp866_6x9 << 28) | (scale_x2 << 24);
|
||||
break;
|
||||
case TextScale_SIZE_16x32:
|
||||
color |= (cp866_8x16 << 28) | (scale_x2 << 24);
|
||||
color |= (encoding << 28) | (scale_x2 << 24);
|
||||
break;
|
||||
case TextScale_SIZE_18x27:
|
||||
color |= (cp866_6x9 << 28) | (scale_x3 << 24);
|
||||
@@ -76,16 +95,19 @@ static void syscall_drawText(const char* text, uint32_t x, uint32_t y, ksys_colo
|
||||
color |= (cp866_6x9 << 28) | (scale_x4 << 24);
|
||||
break;
|
||||
case TextScale_SIZE_24x48:
|
||||
color |= (cp866_8x16 << 28) | (scale_x3 << 24);
|
||||
color |= (encoding << 28) | (scale_x3 << 24);
|
||||
break;
|
||||
case TextScale_SIZE_30x45:
|
||||
color |= (cp866_6x9 << 28) | (scale_x5 << 24);
|
||||
break;
|
||||
case TextScale_SIZE_32x64:
|
||||
color |= (encoding << 28) | (scale_x4 << 24);
|
||||
break;
|
||||
case TextScale_SIZE_36x54:
|
||||
color |= (cp866_6x9 << 28) | (scale_x6 << 24);
|
||||
break;
|
||||
case TextScale_SIZE_40x80:
|
||||
color |= (cp866_8x16 << 28) | (scale_x5 << 24);
|
||||
color |= (encoding << 28) | (scale_x5 << 24);
|
||||
break;
|
||||
case TextScale_SIZE_42x63:
|
||||
color |= (cp866_6x9 << 28) | (scale_x7 << 24);
|
||||
@@ -94,31 +116,40 @@ static void syscall_drawText(const char* text, uint32_t x, uint32_t y, ksys_colo
|
||||
color |= (cp866_6x9 << 28) | (scale_x8 << 24);
|
||||
break;
|
||||
case TextScale_SIZE_48x96:
|
||||
color |= (cp866_8x16 << 28) | (scale_x6 << 24);
|
||||
color |= (encoding << 28) | (scale_x6 << 24);
|
||||
break;
|
||||
case TextScale_SIZE_56x112:
|
||||
color |= (cp866_8x16 << 28) | (scale_x7 << 24);
|
||||
color |= (encoding << 28) | (scale_x7 << 24);
|
||||
break;
|
||||
case TextScale_SIZE_64x128:
|
||||
color |= (cp866_8x16 << 28) | (scale_x8 << 24);
|
||||
color |= (encoding << 28) | (scale_x8 << 24);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
||||
if (len <= 0)
|
||||
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)
|
||||
{
|
||||
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),
|
||||
@@ -127,8 +158,9 @@ int syscalls_drawText(lua_State* L)
|
||||
luaL_checkinteger(L, 4),
|
||||
luaL_optinteger(L, 5, TextScale_SIZE_8x16),
|
||||
luaL_optinteger(L, 6, 0),
|
||||
luaL_optinteger(L, 7, 0),
|
||||
luaL_optinteger(L, 8, 0));
|
||||
luaL_optinteger(L, 7, 1 << 32),
|
||||
luaL_optinteger(L, 8, DEFAULT_ENCODING)
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -24,8 +24,19 @@ enum TextScale
|
||||
TextScale_SIZE_64x128 // 8x 8x16
|
||||
};
|
||||
|
||||
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);
|
||||
@@ -85,4 +96,25 @@ inline void syscalls_push_textSizes(lua_State* L)
|
||||
lua_setfield(L, -2, "textSize");
|
||||
}
|
||||
|
||||
#endif // __GRAPHIC_H__
|
||||
inline void syscalls_push_Encoding(lua_State* L)
|
||||
{
|
||||
lua_newtable(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");
|
||||
|
||||
lua_pushinteger(L, utf16);
|
||||
lua_setfield(L, -2, "utf16");
|
||||
|
||||
lua_setfield(L, -2, "Encoding");
|
||||
}
|
||||
|
||||
#define syscalls_push_graphic(L) syscalls_push_textSizes(L); syscalls_push_Encoding(L);
|
||||
|
||||
#endif // __GRAPHIC_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_
|
||||
#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 */
|
||||
@@ -1855,7 +1856,7 @@ LUALIB_API int luaopen_syscalls(lua_State* L)
|
||||
syscalls_push_windowStyles(L);
|
||||
syscalls_push_buttons(L);
|
||||
syscalls_push_connectionStatus(L);
|
||||
syscalls_push_textSizes(L);
|
||||
syscalls_push_graphic(L);
|
||||
|
||||
syscalls_register_ARPEntry(L);
|
||||
syscalls_register_SystemColors(L);
|
||||
|
@@ -53,4 +53,4 @@ inline void syscalls_ReturnStringOrNil(LUA_INTEGER cond, const char* value, lua_
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __SYSCALLS_H__
|
||||
#endif // __SYSCALLS_H__
|
||||
|
Reference in New Issue
Block a user