diff options
author | Alex Auvolat <alex@adnab.me> | 2017-04-25 18:04:01 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2017-04-25 18:04:01 +0200 |
commit | a959c94c1d67e234adbbb96d0d290eaf3bc26ac1 (patch) | |
tree | 7056780f8cc1398fccf870991f2a155b963acfb8 /src | |
parent | 978b3234a04f11f959f603db4756253278ca65df (diff) | |
download | kogata-a959c94c1d67e234adbbb96d0d290eaf3bc26ac1.tar.gz kogata-a959c94c1d67e234adbbb96d0d290eaf3bc26ac1.zip |
Gui start
Diffstat (limited to 'src')
-rw-r--r-- | src/sysapp/login/main.lua | 13 | ||||
-rw-r--r-- | src/sysbin/lx/lxdrawlib.c | 4 | ||||
-rw-r--r-- | src/syslua/lx/gui.lua | 76 |
3 files changed, 89 insertions, 4 deletions
diff --git a/src/sysapp/login/main.lua b/src/sysapp/login/main.lua index 0c54769..0ef8727 100644 --- a/src/sysapp/login/main.lua +++ b/src/sysapp/login/main.lua @@ -11,7 +11,7 @@ print("vesa_fd = " .. vesa_fd) local vesa_info = ioctl.fb_get_info(vesa_fd) print("vesa_info = ", vesa_info) -local surface = draw.from_fd(vesa_fd, vesa_info) +local surface = draw.surface_from_fd(vesa_fd, vesa_info) for x = 0, 255 do for y = 0, 255 do surface:plot(x, y, surface:rgb(x, y, 0)) @@ -20,8 +20,17 @@ end local fnt = draw.load_font('default') +local mouse_fd = sys.open("io:/input/pcmouse", sysdef.FM_READ) +print("mouse_fd = " .. mouse_fd) + local i = 1 while true do + local mouse_data, mouse_l = sys.read(mouse_fd, 0, 8) + if mouse_l > 0 then + print("mouse_l = ", mouse_l) + print("mouse_data = ", string.unpack("hhbBBB", mouse_data)) + end + surface:rect((i*3) % (vesa_info.width-3), (i*3) % (vesa_info.height-5), 3, 3, @@ -40,7 +49,7 @@ while true do surface:fillrect(x0, y0, x1-x0, y1-y0, c) end if i % 10000 == 0 then - print(i) + -- print(i) local txt = tostring(i) surface:fillrect(0, 0, fnt:text_width(txt), fnt:text_height(txt), diff --git a/src/sysbin/lx/lxdrawlib.c b/src/sysbin/lx/lxdrawlib.c index 91bf07f..001d378 100644 --- a/src/sysbin/lx/lxdrawlib.c +++ b/src/sysbin/lx/lxdrawlib.c @@ -89,7 +89,7 @@ static int font_text_height(lua_State *L) { // ==================================================================== // SURFACES -static int draw_from_fd(lua_State *L) { +static int draw_surface_from_fd(lua_State *L) { int fd = luaL_checkinteger(L, 1); luaL_checktype(L, 2, LUA_TTABLE); @@ -267,7 +267,7 @@ static int surface_write(lua_State *L) { /* }====================================================== */ static const luaL_Reg drawlib[] = { - {"from_fd", draw_from_fd}, + {"surface_from_fd",draw_surface_from_fd}, {"load_font", draw_loadfont}, {NULL, NULL} }; diff --git a/src/syslua/lx/gui.lua b/src/syslua/lx/gui.lua new file mode 100644 index 0000000..beb382e --- /dev/null +++ b/src/syslua/lx/gui.lua @@ -0,0 +1,76 @@ +local sys = require 'lx.sys' +local sysdef= require 'lx.sysdef' +local ioctl = require 'lx.ioctl' +local draw = require 'lx.draw' + +local mainloop = require 'lx.mainloop' + +local gui = { + -- Keyboard info + -- TODO + -- Mouse info + mouse_x = 0, + mouse_y = 0, + mouse_lbtn = false, + mouse_rbtn = false, + mouse_midbtn = false, +} + +function gui.open() + if sys.stat('io:/display/vesa') and sys.stat('io:/input/pckbd') and sys.stat('io:/input/pcmouse') then + gui.open_io() + elseif sys.stat_open(sysdef.STD_FD_GIP) then + gui.open_gip() + else + error("Could not open GUI!") + end +end + +function gui.open_io() + -- Open display + gui.vesa_fd = sys.open("io:/display/vesa", sysdef.FM_IOCTL | sysdef.FM_READ | sysdef.FM_WRITE | sysdef.FM_MMAP) + assert(gui.vesa_fd ~= 0) + + gui.vesa_info = ioctl.fb_get_info(gui.vesa_fd) + gui.surface = draw.surface_from_fd(gui.vesa_fd, gui.vesa_info) + + -- Open keyboard + gui.pckbd_fd = sys.open("io:/input/pckbd", sysdef.FM_READ) + assert(gui.pckbd_fd ~= 0) + + gui.pckbd_mainloop_fd = mainloop.add_fd(gui.pckbd_fd, function() error('pckbd fd error') end) + local function pckbd_handler(ev) + local scancode, ty = string.unpack("HH", ev) + gui.on_keyboard(scancode, ty) + + gui.pckbd_mainloop_fd:expect(4, pckbd_handler) + end + gui.pckbd_mainloop_fd:expect(4, pckbd_handler) + + -- Open mouse + gui.pcmouse_fd = sys.open("io:/input/pcmouse", sysdef.FM_READ) + assert(gui.pcmouse_fd ~= 0) + + gui.pcmouse_mainloop_fd = mainloop.add_fd(gui.pcmouse_fd, function() error("pcmouse fd error") end) + local function pcmouse_handler(ev) + local dx, dy, dw, lb, rb, mb = string.unpack("hhbBBB", ev) + gui.on_mouse(dx, dy, dw, lb, rb, mb) + + gui.pcmouse_mainloop_fd:expect(8, pcmouse_handler) + end + gui.pcmouse_mainloop_fd:expect(8, pcmouse_handler) +end + +function gui.open_gip() + -- TODO +end + +function gui.on_keyboard(scancode, ty) + -- TODO +end + +function gui.on_mouse(dx, dy, dw, lb, rb, mb) + -- TODO +end + +return gui |