implement our own gui module, drop microui
This commit is contained in:
parent
2555bec8eb
commit
8baf5f06ea
25 changed files with 495 additions and 507 deletions
|
|
@ -8,12 +8,12 @@ local particles = require("pxl8.particles")
|
|||
local tilemap = require("pxl8.tilemap")
|
||||
local gfx3d = require("pxl8.gfx3d")
|
||||
local math3d = require("pxl8.math")
|
||||
local ui = require("pxl8.ui")
|
||||
local gui = require("pxl8.gui")
|
||||
local world = require("pxl8.world")
|
||||
local transition = require("pxl8.transition")
|
||||
local anim = require("pxl8.anim")
|
||||
|
||||
core.init(_pxl8_gfx, _pxl8_input, _pxl8_sys, _pxl8_ui)
|
||||
core.init(_pxl8_gfx, _pxl8_input, _pxl8_sys)
|
||||
|
||||
local pxl8 = {}
|
||||
|
||||
|
|
@ -25,6 +25,7 @@ pxl8.warn = core.warn
|
|||
pxl8.error = core.error
|
||||
pxl8.debug = core.debug
|
||||
pxl8.trace = core.trace
|
||||
pxl8.quit = core.quit
|
||||
|
||||
pxl8.clear = gfx2d.clear
|
||||
pxl8.pixel = gfx2d.pixel
|
||||
|
|
@ -51,6 +52,11 @@ pxl8.mouse_wheel_x = input.mouse_wheel_x
|
|||
pxl8.mouse_wheel_y = input.mouse_wheel_y
|
||||
pxl8.mouse_x = input.mouse_x
|
||||
pxl8.mouse_y = input.mouse_y
|
||||
pxl8.get_mouse_pos = input.get_mouse_pos
|
||||
pxl8.mouse_pressed = input.mouse_pressed
|
||||
pxl8.mouse_released = input.mouse_released
|
||||
pxl8.center_cursor = input.center_cursor
|
||||
pxl8.set_cursor = input.set_cursor
|
||||
pxl8.set_relative_mouse_mode = input.set_relative_mouse_mode
|
||||
|
||||
pxl8.vfx_raster_bars = vfx.raster_bars
|
||||
|
|
@ -116,15 +122,18 @@ pxl8.mat4_perspective = math3d.mat4_perspective
|
|||
pxl8.mat4_lookat = math3d.mat4_lookat
|
||||
pxl8.bounds = math3d.bounds
|
||||
|
||||
pxl8.ui_button = ui.button
|
||||
pxl8.ui_checkbox = ui.checkbox
|
||||
pxl8.ui_has_mouse_focus = ui.has_mouse_focus
|
||||
pxl8.ui_indent = ui.indent
|
||||
pxl8.ui_label = ui.label
|
||||
pxl8.ui_layout_row = ui.layout_row
|
||||
pxl8.ui_window_begin = ui.window_begin
|
||||
pxl8.ui_window_end = ui.window_end
|
||||
pxl8.ui_window_set_open = ui.window_set_open
|
||||
pxl8.gui_state_create = gui.state_create
|
||||
pxl8.gui_state_destroy = gui.state_destroy
|
||||
pxl8.gui_begin_frame = gui.begin_frame
|
||||
pxl8.gui_end_frame = gui.end_frame
|
||||
pxl8.gui_cursor_move = gui.cursor_move
|
||||
pxl8.gui_cursor_down = gui.cursor_down
|
||||
pxl8.gui_cursor_up = gui.cursor_up
|
||||
pxl8.gui_button = gui.button
|
||||
pxl8.gui_window = gui.window
|
||||
pxl8.gui_label = gui.label
|
||||
pxl8.gui_is_hovering = gui.is_hovering
|
||||
pxl8.gui_get_cursor_pos = gui.get_cursor_pos
|
||||
|
||||
pxl8.world_new = world.new
|
||||
pxl8.world_destroy = world.destroy
|
||||
|
|
|
|||
|
|
@ -3,11 +3,10 @@ local C = ffi.C
|
|||
|
||||
local core = {}
|
||||
|
||||
function core.init(gfx_ptr, input_ptr, sys_ptr, ui_ptr)
|
||||
function core.init(gfx_ptr, input_ptr, sys_ptr)
|
||||
core.gfx = gfx_ptr
|
||||
core.input = input_ptr
|
||||
core.sys = sys_ptr
|
||||
core.ui = ui_ptr
|
||||
end
|
||||
|
||||
function core.get_fps()
|
||||
|
|
@ -42,4 +41,8 @@ function core.trace(msg)
|
|||
C.pxl8_lua_trace(msg)
|
||||
end
|
||||
|
||||
function core.quit()
|
||||
C.pxl8_set_running(core.sys, false)
|
||||
end
|
||||
|
||||
return core
|
||||
|
|
|
|||
59
src/lua/pxl8/gui.lua
Normal file
59
src/lua/pxl8/gui.lua
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local core = require("pxl8.core")
|
||||
|
||||
local gui = {}
|
||||
|
||||
local state = nil
|
||||
|
||||
local function gui_state()
|
||||
if not state then
|
||||
state = ffi.gc(C.pxl8_gui_state_create(), C.pxl8_gui_state_destroy)
|
||||
end
|
||||
return state
|
||||
end
|
||||
|
||||
function gui.begin_frame()
|
||||
C.pxl8_gui_begin_frame(gui_state())
|
||||
end
|
||||
|
||||
function gui.end_frame()
|
||||
C.pxl8_gui_end_frame(gui_state())
|
||||
end
|
||||
|
||||
function gui.cursor_move(x, y)
|
||||
C.pxl8_gui_cursor_move(gui_state(), x, y)
|
||||
end
|
||||
|
||||
function gui.cursor_down()
|
||||
C.pxl8_gui_cursor_down(gui_state())
|
||||
end
|
||||
|
||||
function gui.cursor_up()
|
||||
C.pxl8_gui_cursor_up(gui_state())
|
||||
end
|
||||
|
||||
function gui.button(id, x, y, w, h, label)
|
||||
return C.pxl8_gui_button(gui_state(), core.gfx, id, x, y, w, h, label)
|
||||
end
|
||||
|
||||
function gui.window(x, y, w, h, title)
|
||||
C.pxl8_gui_window(core.gfx, x, y, w, h, title)
|
||||
end
|
||||
|
||||
function gui.label(x, y, text, color)
|
||||
C.pxl8_gui_label(core.gfx, x, y, text, color)
|
||||
end
|
||||
|
||||
function gui.is_hovering()
|
||||
return C.pxl8_gui_is_hovering(gui_state())
|
||||
end
|
||||
|
||||
function gui.get_cursor_pos()
|
||||
local x = ffi.new("i32[1]")
|
||||
local y = ffi.new("i32[1]")
|
||||
C.pxl8_gui_get_cursor_pos(gui_state(), x, y)
|
||||
return x[0], y[0]
|
||||
end
|
||||
|
||||
return gui
|
||||
|
|
@ -40,8 +40,36 @@ function input.mouse_dy()
|
|||
return C.pxl8_mouse_dy(core.input)
|
||||
end
|
||||
|
||||
function input.get_mouse_pos()
|
||||
return C.pxl8_mouse_x(core.input), C.pxl8_mouse_y(core.input)
|
||||
end
|
||||
|
||||
function input.mouse_pressed(button)
|
||||
return C.pxl8_mouse_pressed(core.input, button)
|
||||
end
|
||||
|
||||
function input.mouse_released(button)
|
||||
return C.pxl8_mouse_released(core.input, button)
|
||||
end
|
||||
|
||||
function input.set_relative_mouse_mode(enabled)
|
||||
C.pxl8_set_relative_mouse_mode(core.sys, enabled)
|
||||
end
|
||||
|
||||
function input.center_cursor()
|
||||
C.pxl8_center_cursor(core.sys)
|
||||
end
|
||||
|
||||
function input.set_cursor(cursor_type)
|
||||
local cursor_enum
|
||||
if cursor_type == "arrow" then
|
||||
cursor_enum = C.PXL8_CURSOR_ARROW
|
||||
elseif cursor_type == "hand" then
|
||||
cursor_enum = C.PXL8_CURSOR_HAND
|
||||
else
|
||||
cursor_enum = C.PXL8_CURSOR_ARROW
|
||||
end
|
||||
C.pxl8_set_cursor(core.sys, cursor_enum)
|
||||
end
|
||||
|
||||
return input
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local core = require("pxl8.core")
|
||||
|
||||
local ui = {}
|
||||
|
||||
function ui.button(label)
|
||||
return C.pxl8_ui_button(core.ui, label)
|
||||
end
|
||||
|
||||
function ui.checkbox(label, state)
|
||||
local state_ptr = ffi.new("bool[1]", state)
|
||||
local changed = C.pxl8_ui_checkbox(core.ui, label, state_ptr)
|
||||
return changed, state_ptr[0]
|
||||
end
|
||||
|
||||
function ui.has_mouse_focus()
|
||||
return C.pxl8_ui_has_mouse_focus(core.ui)
|
||||
end
|
||||
|
||||
function ui.indent(amount)
|
||||
C.pxl8_ui_indent(core.ui, amount)
|
||||
end
|
||||
|
||||
function ui.label(text)
|
||||
C.pxl8_ui_label(core.ui, text)
|
||||
end
|
||||
|
||||
function ui.layout_row(item_count, widths, height)
|
||||
local widths_array = widths
|
||||
if type(widths) == "table" then
|
||||
widths_array = ffi.new("int[?]", #widths, widths)
|
||||
elseif type(widths) == "number" then
|
||||
widths_array = ffi.new("int[1]", widths)
|
||||
end
|
||||
C.pxl8_ui_layout_row(core.ui, item_count, widths_array, height)
|
||||
end
|
||||
|
||||
function ui.window_begin(title, x, y, w, h, options)
|
||||
local rect = ffi.new("pxl8_bounds", {x = x, y = y, w = w, h = h})
|
||||
return C.pxl8_ui_window_begin(core.ui, title, rect, options or 0)
|
||||
end
|
||||
|
||||
function ui.window_end()
|
||||
C.pxl8_ui_window_end(core.ui)
|
||||
end
|
||||
|
||||
function ui.window_set_open(title, open)
|
||||
C.pxl8_ui_window_set_open(core.ui, title, open)
|
||||
end
|
||||
|
||||
return ui
|
||||
Loading…
Add table
Add a link
Reference in a new issue