Merge branch 'docking_inter'

This commit is contained in:
Victor Bombi
2021-02-05 18:12:21 +01:00
4 changed files with 147 additions and 26 deletions

View File

@@ -11,7 +11,13 @@
#include <GL/gl.h>
#include <GL/glu.h>
#ifdef IMGUI_HAS_IMSTR
#define igBegin SigBegin
#define igSliderFloat SigSliderFloat
#define igCheckbox SigCheckbox
#define igColorEdit3 SigColorEdit3
#define igButton SigButton
#endif
SDL_Window *window = NULL;

View File

@@ -165,8 +165,11 @@ local function parse_enum_value(value, allenums,dontpost)
--already in allenums
if allenums[clean(value)] then return allenums[clean(value)] end
--must be several and operators
--precedence order (hope not ())
assert(not value:match("[%(%)]"))
------------precedence order (hope not ())
--first drop outer ()
value = value:gsub("^(%()",""):gsub("(%))$","")
assert(not value:match("[%(%)]"),value)
local several,seps = strsplit(value,"([<>&|~%+]+)")
--M.prtable(value,several,seps)
assert(#seps+1==#several)
@@ -182,6 +185,9 @@ local function parse_enum_value(value, allenums,dontpost)
local val2 = clean(several[i+1])
if allenums[val1] then val1 = allenums[val1] end
if allenums[val2] then val2 = allenums[val2] end
--clean 1u
if type(val1)=="string" then val1 = val1:gsub("(%d)(u)$","%1") end
if type(val2)=="string" then val2 = val2:gsub("(%d)(u)$","%1") end
--for getting numbers from "1ULL"
if type(val1)=="string" then val1 = loadstring("return "..val1)() end
if type(val2)=="string" then val2 = loadstring("return "..val2)() end
@@ -414,14 +420,13 @@ local function parseItems(txt,linenumdict, itparent, dumpit)
end
M.parseItems = parseItems
local function name_overloadsAlgo(v)
local aa = {}
local bb = {}
local done = {}
local maxnum = 0
for i,t in ipairs(v) do
bb[i] = ""
--local signature = t.signature:sub(2,-2) -- without parenthesis
--inside parenthesis
local signature = t.signature:match("%b()")
signature = signature:sub(2,-2)
--add const function
@@ -430,11 +435,7 @@ local function name_overloadsAlgo(v)
end
aa[i] = {}
local num = 1
--for typec in t.signature:gmatch(".-([^,%(%s]+)[,%)]") do
--for typec in t.signature:gmatch(".-([^,%(]+)[,%)]") do
--for typec in signature:gmatch(".-([^,]+),?") do
for typec in signature:gsub("(%(.-%))", function(x) return x:gsub(",","\0") end):gmatch(".-([^,]+),?") do
--typec = typec:gsub
aa[i][num] = typec:gsub("%z+", ",")
num = num + 1
end
@@ -448,7 +449,7 @@ local function name_overloadsAlgo(v)
local equal = true
for i=1,#v do
aa[i][l] = aa[i][l] or "nil"
keys[aa[i][l]] = 1 + (aa[i][l] and keys[aa[i][l]] or 0)
keys[aa[i][l]] = 1 + (keys[aa[i][l]] or 0)
if not done[i] then
for j=i+1,#v do
if not done[j] then
@@ -465,11 +466,20 @@ local function name_overloadsAlgo(v)
for i=1,#v do
if not done[i] then
bb[i] = bb[i]..(aa[i][l]=="nil" and "" or aa[i][l])
if keys[aa[i][l]] == 1 then
done[i] = true
-- if keys[aa[i][l]] == 1 then
-- done[i] = true
-- end
end
end
end
--test done
for i=1,#v do
done[i] = true
for j=1,#v do
if i~=j and bb[i]==bb[j] then
done[i] = false
end
end
end
end
--avoid empty postfix which will be reserved to generic
@@ -493,6 +503,7 @@ local function typetoStr(typ)
typ = typ:gsub("float","Float")
typ = typ:gsub("uInt","Uint")
typ = typ:gsub("ImGui","")
typ = typ:gsub("ImStr","STR")
typ = typ:gsub("Im","")
typ = typ:gsub("[<>]","")
return typ
@@ -769,6 +780,84 @@ local function AdjustArguments(FP)
end
end
end
local function ADDIMSTR_S(FP)
local defsT = FP.defsT
local newcdefs = {}
for numcdef,t in ipairs(FP.funcdefs) do
newcdefs[#newcdefs+1] = t
if t.cimguiname then
local cimf = defsT[t.cimguiname]
local defT = cimf[t.signature]
--if isIMSTR return generate _S version
local isIMSTR = false
for i,arg in ipairs(defT.argsT) do
if arg.type == "ImStr" then isIMSTR=true;break end
end
--if defT.ret=="ImVec2" or defT.ret=="ImVec4" or defT.ret=="ImColor" then
--if isIMSTR then print(t.cimguiname,defT.ov_cimguiname,defT.argsoriginal,"isIMSTR") end
if isIMSTR then
--passing as a pointer arg
local defT2 = {}
--first strings
for k,v in pairs(defT) do
defT2[k] = v
end
--then argsT table
defT2.argsT = {}
for k,v in ipairs(defT.argsT) do
local typ = v.type == "ImStr" and "const char*" or v.type
table.insert(defT2.argsT,{type=typ,name=v.name})
end
--defaults table
defT2.defaults = {}
for k,v in pairs(defT.defaults) do
defT2.defaults[k] = v
end
defT2.args = defT2.args:gsub("ImStr","const char*")
--recreate call_args for wrapping into ImStr
local caar
if #defT.argsT > 0 then
caar = "("
for i,v in ipairs(defT.argsT) do
local name = v.name --v.type == "ImStr" and "ImStr("..v.name..")" or v.name --wrap
if v.ret then --function pointer
caar = caar .. name .. ","
else
local callname = v.reftoptr and "*"..name or name
caar = caar .. callname .. ","
end
end
caar = caar:sub(1,-2)..")"
else
caar = "()"
end
defT2.call_args = caar --:gsub("ImStr%(([^%(%)]+)%)","%1") --unwrap
------------------
defT2.signature = defT.signature:gsub("ImStr","const char*") --.."_S"
defT2.ov_cimguiname = defT2.ov_cimguiname .. "_Strv"
defT2.isIMSTR_S = 1
-- check there is not an equal version in imgui_stname
local doadd = true
for i,dd in ipairs(cimf) do
if dd.signature == defT2.signature then
doadd = false;
print("skip _S addition",defT2.cimguiname)
break
end
end
--add _S version
if doadd then
cimf[#cimf+1] = defT2
cimf[defT2.signature] = defT2
newcdefs[#newcdefs+1] = {stname=t.stname,funcname=t.funcname,args=defT2.args,signature=defT2.signature,cimguiname=defT2.cimguiname,ret =defT2.ret}
end
end
else print("not cimguiname in");M.prtable(t)
end
end
FP.funcdefs = newcdefs
end
local function ADDnonUDT(FP)
local defsT = FP.defsT
--local newcdefs = {}
@@ -1491,6 +1580,7 @@ function M.Parser()
for k,v in pairs(self.alltypes) do print(k, typetoStr(k) ) end
end
function par:compute_overloads()
--ADDIMSTR_S(self)
local strt = {}
local numoverloaded = 0
self.alltypes = {}
@@ -1506,8 +1596,15 @@ function M.Parser()
for i,t in ipairs(v) do
--take overloaded name from manual table or algorythm
t.ov_cimguiname = self.getCname_overload(t.stname,t.funcname,t.signature,t.namespace) or k..typetoStr(post[i])
--check ...
if( t.ov_cimguiname:match"%.%.%.") then
print("... in ov",t.ov_cimguiname)
for i,dd in ipairs(v) do
print(dd.signature,post[i])
end
error"Bad check ..."
end
table.insert(strt,string.format("%d\t%s\t%s %s",i,t.ret,t.ov_cimguiname,t.signature))
--M.prtable(typesc[i],post)
end
--check not two names are equal (produced by bad cimguiname_overload)
for i=1,#v-1 do
@@ -1525,8 +1622,10 @@ function M.Parser()
end)
--print(numoverloaded, "overloaded")
table.insert(strt,string.format("%d overloaded",numoverloaded))
ADDIMSTR_S(self)
AdjustArguments(self)
ADDnonUDT(self)
--ADDdestructors(self)
self.overloadstxt = table.concat(strt,"\n")
end

View File

@@ -313,6 +313,9 @@ local function cimgui_generation(parser)
if gdefines.IMGUI_HAS_DOCK then
cstructsstr = cstructsstr.."\n#define IMGUI_HAS_DOCK 1\n"
end
if gdefines.IMGUI_HAS_IMSTR then
cstructsstr = cstructsstr.."\n#define IMGUI_HAS_IMSTR 1\n"
end
hstrfile = hstrfile:gsub([[#include "imgui_structs%.h"]],cstructsstr)
local cfuncsstr = func_header_generate(parser)
@@ -333,13 +336,13 @@ end
--------------------------------------------------------
--get imgui.h version and IMGUI_HAS_DOCK--------------------------
--get some defines wont work for cl ----------------
gdefines = get_defines{"IMGUI_VERSION","FLT_MAX","FLT_MIN","IMGUI_HAS_DOCK"}
gdefines = get_defines{"IMGUI_VERSION","FLT_MAX","FLT_MIN","IMGUI_HAS_DOCK","IMGUI_HAS_IMSTR"}
--this will work for cl
local pipe,err = io.open("../imgui/imgui.h","r")
if not pipe then
error("could not open file:"..err)
end
local imgui_version,has_dock
local imgui_version,has_dock,has_imstr
while true do
local line = pipe:read"*l"
if not line then break end
@@ -349,11 +352,15 @@ while true do
if not has_dock then
has_dock = line:match([[#define%s+IMGUI_HAS_DOCK]])--%s*(".+")]])
end
if imgui_version and has_dock then break end
if not has_imstr then
has_imstr = line:match([[#define%s+IMGUI_HAS_IMSTR]])--%s*(".+")]])
end
if imgui_version and has_dock and has_imstr then break end
end
pipe:close()
if has_dock then gdefines.IMGUI_HAS_DOCK = true end
if has_imstr then gdefines.IMGUI_HAS_IMSTR = true end
cimgui_header = cimgui_header:gsub("XXX",imgui_version)
if INTERNAL_GENERATION then
@@ -369,6 +376,7 @@ if gdefines.IMGUI_HAS_DOCK then
]]
end
print("IMGUI_HAS_IMSTR",gdefines.IMGUI_HAS_IMSTR)
print("IMGUI_HAS_DOCK",gdefines.IMGUI_HAS_DOCK)
print("IMGUI_VERSION",imgui_version)

View File

@@ -2,6 +2,14 @@
#include <assert.h>
#include "../cimgui.h"
#ifdef IMGUI_HAS_IMSTR
#define igBegin SigBegin
#define igSliderFloat SigSliderFloat
#define igCheckbox SigCheckbox
#define igColorEdit3 SigColorEdit3
#define igButton SigButton
#endif
int main(void)
{
assert(igDebugCheckVersionAndDataLayout(igGetVersion(), sizeof(ImGuiIO), sizeof(ImGuiStyle),