2024-11-03 19:47:04 +08:00
|
|
|
package.path = package.path..";../../../?.lua"
|
|
|
|
|
local dirtools = require("tools.dirtools")
|
|
|
|
|
local base_path = dirtools.get_app_path("sokol%-luajit")
|
|
|
|
|
|
|
|
|
|
package.cpath = package.cpath..";"..base_path.."bin/win64/?.dll"
|
|
|
|
|
package.path = package.path..";"..base_path.."ffi/sokol/?.lua"
|
|
|
|
|
package.path = package.path..";"..base_path.."?.lua"
|
|
|
|
|
|
|
|
|
|
--_G.SOKOL_DLL = "sokol_debug_dll"
|
|
|
|
|
local sapp = require("sokol_app")
|
|
|
|
|
sg = require("sokol_nuklear")
|
|
|
|
|
local nk = sg
|
|
|
|
|
local slib = require("sokol_libs") -- Warn - always after gfx!!
|
|
|
|
|
|
|
|
|
|
local hmm = require("hmm")
|
|
|
|
|
local hutils = require("hmm_utils")
|
|
|
|
|
|
|
|
|
|
local stb = require("stb")
|
|
|
|
|
|
|
|
|
|
local ffi = require("ffi")
|
|
|
|
|
|
2024-11-05 19:02:35 +08:00
|
|
|
-- --------------------------------------------------------------------------------------
|
|
|
|
|
-- For win - sleep so as to not consume all proc cycles for ui
|
|
|
|
|
ffi.cdef[[
|
|
|
|
|
void Sleep(uint32_t ms);
|
|
|
|
|
]]
|
|
|
|
|
|
|
|
|
|
|
2024-11-03 19:47:04 +08:00
|
|
|
-- --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
local config = require("config.settings")
|
2024-11-05 10:29:41 +08:00
|
|
|
local wdgts = require("utils.widgets")
|
2024-11-05 19:02:35 +08:00
|
|
|
local fonts = require("utils.fonts")
|
2024-11-03 19:47:04 +08:00
|
|
|
|
2024-11-05 19:02:35 +08:00
|
|
|
local icons = ffi.new("struct nk_image [?]", 10)
|
2024-11-03 19:47:04 +08:00
|
|
|
|
2024-11-05 19:02:35 +08:00
|
|
|
-- --------------------------------------------------------------------------------------
|
2024-11-03 19:47:04 +08:00
|
|
|
|
2024-11-05 19:02:35 +08:00
|
|
|
local myfonts = nil
|
|
|
|
|
local font_list = {
|
|
|
|
|
{ font_file = "fontawesome-webfont.ttf", font_size = 30.0, range = nk.nk_font_awesome_glyph_ranges() },
|
|
|
|
|
{ font_file = "Rubik-Light.ttf", font_size = 16.0 },
|
|
|
|
|
{ font_file = "Rubik-Regular.ttf", font_size = 20.0 },
|
|
|
|
|
{ font_file = "Rubik-Bold.ttf", font_size = 21.0 },
|
|
|
|
|
}
|
2024-11-05 10:29:41 +08:00
|
|
|
|
2024-11-03 19:47:04 +08:00
|
|
|
-- --------------------------------------------------------------------------------------
|
|
|
|
|
|
2024-11-06 10:47:28 +08:00
|
|
|
local visited = {}
|
|
|
|
|
local function tdump(o, level)
|
|
|
|
|
local level = level or 1
|
|
|
|
|
if(level == 0) then visited = {} end
|
|
|
|
|
if type(o) == 'table' then
|
|
|
|
|
local s = ' {\n'
|
|
|
|
|
for k,v in pairs(o) do
|
|
|
|
|
if type(k) ~= 'number' then k = '"'..tostring(k)..'"' end
|
|
|
|
|
if(visited[v] == nil) then
|
|
|
|
|
visited[v] = true
|
|
|
|
|
s = s .. string.rep(" ", level)..'['..k..'] = ' .. tdump(v, level+1)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return s .. string.rep(" ", level-1)..'}\n'
|
|
|
|
|
else
|
|
|
|
|
return tostring(o).."\n"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2024-11-03 19:47:04 +08:00
|
|
|
-- --------------------------------------------------------------------------------------
|
|
|
|
|
-- Static vars
|
|
|
|
|
--
|
|
|
|
|
-- Note: Many vars are locally set or globals. This was from a direct C conversion.
|
|
|
|
|
-- To make static vars workaround then place them below.
|
|
|
|
|
|
|
|
|
|
local winrect = ffi.new("struct nk_rect[1]", {{10, 25, 1000, 600}})
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
local pix = {}
|
|
|
|
|
|
|
|
|
|
local function init(void)
|
|
|
|
|
-- // setup sokol-gfx, sokol-time and sokol-imgui
|
|
|
|
|
local sg_desc = ffi.new("sg_desc[1]")
|
|
|
|
|
sg_desc[0].environment = slib.sglue_environment()
|
|
|
|
|
sg_desc[0].logger.func = slib.slog_func
|
|
|
|
|
sg.sg_setup( sg_desc )
|
|
|
|
|
|
|
|
|
|
-- // use sokol-nuklear with all default-options (we're not doing
|
|
|
|
|
-- // multi-sampled rendering or using non-default pixel formats)
|
|
|
|
|
local snk = ffi.new("snk_desc_t[1]")
|
|
|
|
|
snk[0].dpi_scale = sapp.sapp_dpi_scale()
|
|
|
|
|
snk[0].logger.func = slib.slog_func
|
|
|
|
|
nk.snk_setup(snk)
|
|
|
|
|
|
|
|
|
|
local base_path = "./"
|
2024-11-05 19:02:35 +08:00
|
|
|
pix["baboon"] = wdgts.icon_load(base_path.."images/baboon.png")
|
2024-11-03 19:47:04 +08:00
|
|
|
-- pix["copy"] = icon_load(base_path.."icon/copy.png")
|
|
|
|
|
-- pix["del"] = icon_load(base_path.."icon/delete.png")
|
|
|
|
|
-- pix["rocket"] = icon_load(base_path.."icon/rocket.png")
|
|
|
|
|
-- pix["edit"] = icon_load(base_path.."icon/edit.png")
|
|
|
|
|
|
|
|
|
|
sapp.sapp_show_mouse(false)
|
|
|
|
|
|
|
|
|
|
winrect[0].x = 0
|
|
|
|
|
winrect[0].y = 0
|
|
|
|
|
winrect[0].w = sapp.sapp_width()
|
|
|
|
|
winrect[0].h = sapp.sapp_height()
|
2024-11-05 10:29:41 +08:00
|
|
|
|
|
|
|
|
icons[0] = wdgts.icon_load("./icon/home.png")
|
|
|
|
|
icons[1] = wdgts.icon_load("./icon/phone.png")
|
|
|
|
|
icons[2] = wdgts.icon_load("./icon/plane.png")
|
|
|
|
|
icons[3] = wdgts.icon_load("./icon/wifi.png")
|
|
|
|
|
icons[4] = wdgts.icon_load("./icon/settings.png")
|
|
|
|
|
icons[5] = wdgts.icon_load("./icon/volume.png")
|
2024-11-03 19:47:04 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
local function cleanup()
|
|
|
|
|
|
|
|
|
|
sg.sg_shutdown()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------
|
2024-11-03 19:54:22 +08:00
|
|
|
local current_ctx = nil
|
2024-11-03 19:47:04 +08:00
|
|
|
local function input(event)
|
2024-11-03 19:54:22 +08:00
|
|
|
if(event.type == sapp.SAPP_EVENTTYPE_RESIZED) then
|
|
|
|
|
nk.snk_handle_event(event)
|
|
|
|
|
elseif(event.type == sapp.SAPP_EVENTTYPE_MOUSE_ENTER) then
|
|
|
|
|
nk.nk_style_show_cursor(current_ctx)
|
|
|
|
|
sapp.sapp_show_mouse(false)
|
|
|
|
|
elseif(event.type == sapp.SAPP_EVENTTYPE_MOUSE_LEAVE) then
|
|
|
|
|
nk.nk_style_hide_cursor(current_ctx)
|
|
|
|
|
sapp.sapp_show_mouse(true)
|
|
|
|
|
else
|
|
|
|
|
nk.snk_handle_event(event)
|
|
|
|
|
end
|
2024-11-03 19:47:04 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------
|
2024-11-07 09:30:16 +08:00
|
|
|
-- Extract config and build ffi objects for them
|
|
|
|
|
-- Each config property shall have a shadow ffi property labeled with _ffi
|
2024-11-07 17:14:49 +08:00
|
|
|
for sectionname, section in pairs(config) do
|
|
|
|
|
|
|
|
|
|
for key, prop in pairs(section) do
|
|
|
|
|
-- If ptype is nill or string its a string
|
|
|
|
|
if(prop.ptype == nil or prop.ptype == "string") then
|
|
|
|
|
prop.ffi = ffi.new("char[?]", prop.slen )
|
|
|
|
|
ffi.fill(prop.ffi, prop.slen, 0)
|
|
|
|
|
ffi.copy(prop.ffi, ffi.string(prop.value))
|
|
|
|
|
prop.len_ffi = ffi.new("int[1]", {string.len(prop.value)})
|
|
|
|
|
elseif(prop.ptype == "combo") then
|
|
|
|
|
prop.ffi = ffi.new("int[1]", prop.value)
|
|
|
|
|
elseif(prop.ptype == "int") then
|
|
|
|
|
prop.ffi = ffi.new("int[1]", prop.value)
|
|
|
|
|
elseif(prop.ptype == "float") then
|
|
|
|
|
prop.ffi = ffi.new("float[1]", prop.value)
|
2024-11-07 09:30:16 +08:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-11-07 17:14:49 +08:00
|
|
|
local group_width = ffi.new("int[1]", {320})
|
|
|
|
|
local group_height = ffi.new("int[1]", {200})
|
2024-11-05 16:47:08 +08:00
|
|
|
|
2024-11-05 19:02:35 +08:00
|
|
|
-- --------------------------------------------------------------------------------------
|
2024-11-07 17:14:49 +08:00
|
|
|
local range_float_value = ffi.new("float[1]")
|
2024-11-03 19:47:04 +08:00
|
|
|
|
2024-11-07 09:30:16 +08:00
|
|
|
local function display_section(ctx, sectionname)
|
2024-11-03 19:47:04 +08:00
|
|
|
|
2024-11-07 09:30:16 +08:00
|
|
|
local section = config[sectionname]
|
2024-11-07 17:14:49 +08:00
|
|
|
-- Collect the number of properties in the section
|
|
|
|
|
local count = 0
|
|
|
|
|
local sorted = {}
|
2024-11-07 09:30:16 +08:00
|
|
|
for k,v in pairs(section) do
|
2024-11-07 17:14:49 +08:00
|
|
|
count = count + 1
|
|
|
|
|
v.key = k
|
|
|
|
|
sorted[v.index] = v
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
nk.nk_layout_row_dynamic(ctx, 28 * count + 60, 1)
|
|
|
|
|
local bounds = nk.nk_window_get_content_region(ctx)
|
|
|
|
|
local prop_col = bounds.w * 0.23
|
|
|
|
|
local value_col = bounds.w * 0.73
|
|
|
|
|
|
|
|
|
|
local flags = bit.bor(nk.NK_WINDOW_BORDER, nk.NK_WINDOW_TITLE)
|
|
|
|
|
flags = bit.bor(flags, nk.NK_WINDOW_NO_SCROLLBAR)
|
|
|
|
|
if (nk.nk_group_begin(ctx, sectionname, flags) == true) then
|
|
|
|
|
|
|
|
|
|
for k,v in ipairs(sorted) do
|
|
|
|
|
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 28, 3)
|
|
|
|
|
nk.nk_layout_row_push(ctx, prop_col)
|
|
|
|
|
nk.nk_label(ctx, v.key..":", nk.NK_TEXT_LEFT)
|
|
|
|
|
nk.nk_layout_row_push(ctx, value_col)
|
|
|
|
|
if(v.ptype == "string" or v.ptype == nil) then
|
|
|
|
|
nk.nk_edit_string(ctx, nk.NK_EDIT_SIMPLE, v.ffi, v.len_ffi, v.slen, nk.nk_filter_default)
|
|
|
|
|
elseif(v.ptype == "combo") then
|
|
|
|
|
v.value = wdgts.widget_combo_box(ctx, v.plist, v.value, 200)
|
|
|
|
|
elseif(v.ptype == "int") then
|
|
|
|
|
nk.nk_property_int(ctx, "", v.vmin, v.ffi, v.vmax, v.vstep, v.vinc)
|
|
|
|
|
elseif(v.ptype == "float") then
|
|
|
|
|
nk.nk_property_float(ctx, "", v.vmin, v.ffi, v.vmax, v.vstep, v.vinc)
|
2024-11-07 09:30:16 +08:00
|
|
|
end
|
2024-11-07 17:14:49 +08:00
|
|
|
nk.nk_layout_row_end(ctx)
|
|
|
|
|
|
2024-11-07 09:30:16 +08:00
|
|
|
end
|
2024-11-07 17:14:49 +08:00
|
|
|
nk.nk_group_end(ctx)
|
2024-11-05 16:47:08 +08:00
|
|
|
end
|
2024-11-07 09:30:16 +08:00
|
|
|
end
|
2024-11-05 10:29:41 +08:00
|
|
|
|
2024-11-07 09:30:16 +08:00
|
|
|
-- --------------------------------------------------------------------------------------
|
2024-11-05 19:02:35 +08:00
|
|
|
|
2024-11-07 17:14:49 +08:00
|
|
|
local project_curr_tab = 1
|
|
|
|
|
local project_tabs = {
|
|
|
|
|
{
|
|
|
|
|
name = "Project",
|
|
|
|
|
func = function(ctx)
|
|
|
|
|
display_section(ctx, "project")
|
|
|
|
|
display_section(ctx, "sokol")
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name = "Build",
|
|
|
|
|
func = function(ctx)
|
|
|
|
|
display_section(ctx, "platform")
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name = "Logs"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------
|
|
|
|
|
|
2024-11-07 09:30:16 +08:00
|
|
|
local function project_panel(ctx)
|
2024-11-05 16:47:08 +08:00
|
|
|
|
2024-11-07 09:30:16 +08:00
|
|
|
nk.nk_style_set_font(ctx, myfonts[3].handle)
|
2024-11-05 16:47:08 +08:00
|
|
|
|
2024-11-07 17:14:49 +08:00
|
|
|
project_curr_tab = wdgts.widget_notebook(ctx, "assets", project_tabs, project_curr_tab, 500, 120)
|
|
|
|
|
-- display_section(ctx, "graphics")
|
|
|
|
|
-- display_section(ctx, "audio")
|
2024-11-05 16:47:08 +08:00
|
|
|
|
2024-11-05 10:29:41 +08:00
|
|
|
-- Awesome little radial popup.
|
2024-11-05 16:47:08 +08:00
|
|
|
local res = wdgts.make_pie_popup(ctx, icons, 100, 6)
|
2024-11-05 10:29:41 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------
|
2024-11-05 19:02:35 +08:00
|
|
|
local curr_tab = 1
|
2024-11-07 17:14:49 +08:00
|
|
|
local tabs = { { name = "Lua Source" }, { name = "Images" }, { name = "Data" } }
|
2024-11-05 19:02:35 +08:00
|
|
|
|
|
|
|
|
local function assets_panel(ctx)
|
2024-11-05 10:29:41 +08:00
|
|
|
|
2024-11-05 19:02:35 +08:00
|
|
|
nk.nk_style_set_font(ctx, myfonts[3].handle)
|
2024-11-05 10:29:41 +08:00
|
|
|
|
2024-11-06 10:47:28 +08:00
|
|
|
curr_tab = wdgts.widget_notebook(ctx, "assets", tabs, curr_tab, 500, 120)
|
2024-11-05 10:29:41 +08:00
|
|
|
|
|
|
|
|
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 22, 3)
|
|
|
|
|
nk.nk_layout_row_push(ctx, 50)
|
|
|
|
|
nk.nk_label(ctx, "size:", nk.NK_TEXT_LEFT)
|
|
|
|
|
nk.nk_layout_row_push(ctx, 130)
|
|
|
|
|
nk.nk_property_int(ctx, "#Width:", 100, group_width, 500, 10, 1)
|
|
|
|
|
nk.nk_layout_row_push(ctx, 130)
|
|
|
|
|
nk.nk_property_int(ctx, "#Height:", 100, group_height, 500, 10, 1)
|
|
|
|
|
nk.nk_layout_row_end(ctx)
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
local function panel_project_function(data, left, top, width, height)
|
|
|
|
|
project_panel(data.ctx)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------
|
|
|
|
|
|
2024-11-05 19:02:35 +08:00
|
|
|
local function panel_assets_function(data, left, top, width, height)
|
|
|
|
|
assets_panel(data.ctx)
|
2024-11-03 19:47:04 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
local function main_ui(ctx)
|
|
|
|
|
|
2024-11-05 19:02:35 +08:00
|
|
|
if(myfonts == nil) then
|
|
|
|
|
myfonts = fonts.setup_font(ctx, font_list)
|
2024-11-03 19:47:04 +08:00
|
|
|
end
|
|
|
|
|
|
2024-11-05 19:02:35 +08:00
|
|
|
nk.nk_style_set_font(ctx, myfonts[4].handle)
|
2024-11-03 19:47:04 +08:00
|
|
|
|
2024-11-07 17:14:49 +08:00
|
|
|
local flags = nk.NK_WINDOW_BORDER
|
2024-11-05 10:29:41 +08:00
|
|
|
local height = sapp.sapp_height() - 20
|
|
|
|
|
local width = sapp.sapp_width() / 2 - 15
|
|
|
|
|
wdgts.widget_panel_fixed(ctx, "Project", 10, 10, width, height, flags, panel_project_function, {ctx=ctx})
|
|
|
|
|
|
2024-11-05 19:02:35 +08:00
|
|
|
nk.nk_style_set_font(ctx, myfonts[4].handle)
|
2024-11-05 10:29:41 +08:00
|
|
|
|
|
|
|
|
local height = sapp.sapp_height() - 20
|
|
|
|
|
local width = sapp.sapp_width() / 2 - 15
|
2024-11-05 19:02:35 +08:00
|
|
|
wdgts.widget_panel_fixed(ctx, "Assets", 10+width+10, 10, width, height, flags, panel_assets_function, {ctx=ctx})
|
2024-11-03 19:47:04 +08:00
|
|
|
return not nk.nk_window_is_closed(ctx, "Overview")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
local function frame(void)
|
|
|
|
|
|
|
|
|
|
local ctx = nk.snk_new_frame()
|
2024-11-03 19:54:22 +08:00
|
|
|
current_ctx = ctx
|
2024-11-03 19:47:04 +08:00
|
|
|
|
|
|
|
|
main_ui(ctx)
|
|
|
|
|
|
|
|
|
|
-- // the sokol_gfx draw pass
|
|
|
|
|
local pass = ffi.new("sg_pass[1]")
|
|
|
|
|
pass[0].action.colors[0].load_action = sg.SG_LOADACTION_CLEAR
|
|
|
|
|
pass[0].action.colors[0].clear_value = { 0.25, 0.5, 0.7, 1.0 }
|
|
|
|
|
pass[0].swapchain = slib.sglue_swapchain()
|
|
|
|
|
sg.sg_begin_pass(pass)
|
|
|
|
|
|
|
|
|
|
nk.snk_render(sapp.sapp_width(), sapp.sapp_height())
|
|
|
|
|
sg.sg_end_pass()
|
|
|
|
|
sg.sg_commit()
|
2024-11-05 19:02:35 +08:00
|
|
|
|
|
|
|
|
ffi.C.Sleep(3)
|
2024-11-03 19:47:04 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
local app_desc = ffi.new("sapp_desc[1]")
|
|
|
|
|
app_desc[0].init_cb = init
|
|
|
|
|
app_desc[0].frame_cb = frame
|
|
|
|
|
app_desc[0].cleanup_cb = cleanup
|
|
|
|
|
app_desc[0].event_cb = input
|
|
|
|
|
app_desc[0].width = 1280
|
|
|
|
|
app_desc[0].height = 800
|
|
|
|
|
app_desc[0].window_title = config.title
|
|
|
|
|
app_desc[0].icon.sokol_default = true
|
|
|
|
|
app_desc[0].logger.func = slib.slog_func
|
|
|
|
|
app_desc[0].enable_clipboard = true
|
|
|
|
|
app_desc[0].ios_keyboard_resizes_canvas = false
|
|
|
|
|
|
|
|
|
|
sapp.sapp_run( app_desc )
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------
|
2024-11-06 10:47:28 +08:00
|
|
|
|
|
|
|
|
local default_libs = {
|
|
|
|
|
["os"] = true,
|
|
|
|
|
["_G"] = true,
|
|
|
|
|
["jit"] = true,
|
|
|
|
|
["table"] = true,
|
|
|
|
|
["jit.opt"] = true,
|
|
|
|
|
["ffi"] = true,
|
|
|
|
|
["string"] = true,
|
|
|
|
|
["io"] = true,
|
|
|
|
|
["coroutine"] = true,
|
|
|
|
|
["package"] = true,
|
|
|
|
|
["math"] = true,
|
|
|
|
|
["debug"] = true,
|
|
|
|
|
["bit"] = true,
|
|
|
|
|
}
|
|
|
|
|
for k,v in pairs(package.loaded) do
|
|
|
|
|
|
|
|
|
|
if(type(v) ~= "userdata" and default_libs[tostring(k)] == nil) then
|
|
|
|
|
print( "["..tostring(k).."] = "..tostring(v))
|
|
|
|
|
end
|
|
|
|
|
end
|