add sdl implementation

This commit is contained in:
sonoro1234
2018-06-25 15:52:55 +02:00
parent 532feb55ff
commit 213eb53557
5 changed files with 161 additions and 128 deletions

View File

@@ -2,24 +2,24 @@
#include <stdio.h>
#if defined _WIN32 || defined __CYGWIN__
#ifdef CIMGUI_NO_EXPORT
#define API
#ifdef CIMGUI_NO_EXPORT
#define API
#else
#define API __declspec(dllexport)
#endif
#ifndef __GNUC__
#define snprintf sprintf_s
#endif
#else
#define API __declspec(dllexport)
#endif
#ifndef __GNUC__
#define snprintf sprintf_s
#endif
#else
#define API
#define API
#endif
#if defined __cplusplus
#define EXTERN extern "C"
#define EXTERN extern "C"
#else
#include <stdarg.h>
#include <stdbool.h>
#define EXTERN extern
#include <stdarg.h>
#include <stdbool.h>
#define EXTERN extern
#endif
#define CIMGUI_API EXTERN API
@@ -32,11 +32,11 @@ typedef unsigned __int64 ImU64;
typedef unsigned long long ImU64;
#endif
struct GLFWwindow;
//struct GLFWwindow;
//struct SDL_Window;
#ifdef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
/////////////// BEGIN AUTOGENERATED SEGMENT
typedef struct GLFWwindow GLFWwindow;
typedef struct ImFont ImFont;
typedef struct ImFontAtlas ImFontAtlas;
typedef struct CustomRect CustomRect;
@@ -1012,45 +1012,6 @@ struct ImFont
// [Internal]
};
// Include imgui_user.h at the end of imgui.h (convenient for user to only explicitly include vanilla imgui.h)
// ImGui Platform Binding for: GLFW
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan..)
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
// Implemented features:
// [X] Platform: Clipboard support.
// [X] Platform: Gamepad navigation mapping. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
// [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: 3 cursors types are missing from GLFW.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
// https://github.com/ocornut/imgui
// About GLSL version:
// The 'glsl_version' initialization parameter defaults to "#version 150" if NULL.
// Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure!
struct GLFWwindow;
// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization)
// Provided here if you want to chain callbacks.
// You can also handle inputs yourself and use those as a reference.
// ImGui Renderer for: OpenGL3 (modern OpenGL with shaders / programmatic pipeline)
// This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..)
// (Note: We are using GL3W as a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc..)
// Implemented features:
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// About GLSL version:
// The 'glsl_version' initialization parameter defaults to "#version 150" if NULL.
// Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure!
// Called by Init/NewFrame/Shutdown
// ImGui Renderer for: OpenGL2 (legacy OpenGL, fixed pipeline)
// This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..)
// Implemented features:
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)**
// **Prefer using the code in imgui_impl_opengl3.cpp**
// This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read.
// If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more
// complicated, will require your code to reset every single OpenGL attributes to their initial state, and might
// confuse your GPU driver.
// The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API.
// Called by Init/NewFrame/Shutdown
struct GlyphRangesBuilder
{
ImVector/*<unsigned char>*/ UsedChars;
@@ -1076,6 +1037,10 @@ struct GLFWwindow;
};
//////////////// END AUTOGENERATED SEGMENT
#else
struct GLFWwindow;
struct SDL_Window;
typedef union SDL_Event SDL_Event;
#endif // CIMGUI_DEFINE_ENUMS_AND_STRUCTS
#ifndef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
@@ -1722,30 +1687,6 @@ CIMGUI_API void ImFont_RenderText(ImFont* self,ImDrawList* draw_list,float size
CIMGUI_API void ImFont_GrowIndex(ImFont* self,int new_size);
CIMGUI_API void ImFont_AddGlyph(ImFont* self,ImWchar c,float x0,float y0,float x1,float y1,float u0,float v0,float u1,float v1,float advance_x);
CIMGUI_API void ImFont_AddRemapChar(ImFont* self,ImWchar dst,ImWchar src,bool overwrite_dst); // Makes 'dst' character/glyph points to 'src' character/glyph. Currently needs to be called AFTER fonts have been built.
CIMGUI_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window,bool install_callbacks);
CIMGUI_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window,bool install_callbacks);
CIMGUI_API void ImGui_ImplGlfw_Shutdown();
CIMGUI_API void ImGui_ImplGlfw_NewFrame();
CIMGUI_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window,int button,int action,int mods);
CIMGUI_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window,double xoffset,double yoffset);
CIMGUI_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window,int key,int scancode,int action,int mods);
CIMGUI_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window,unsigned int c);
CIMGUI_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version);
CIMGUI_API void ImGui_ImplOpenGL3_Shutdown();
CIMGUI_API void ImGui_ImplOpenGL3_NewFrame();
CIMGUI_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data);
CIMGUI_API bool ImGui_ImplOpenGL3_CreateFontsTexture();
CIMGUI_API void ImGui_ImplOpenGL3_DestroyFontsTexture();
CIMGUI_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
CIMGUI_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
CIMGUI_API bool ImGui_ImplOpenGL2_Init();
CIMGUI_API void ImGui_ImplOpenGL2_Shutdown();
CIMGUI_API void ImGui_ImplOpenGL2_NewFrame();
CIMGUI_API void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data);
CIMGUI_API bool ImGui_ImplOpenGL2_CreateFontsTexture();
CIMGUI_API void ImGui_ImplOpenGL2_DestroyFontsTexture();
CIMGUI_API bool ImGui_ImplOpenGL2_CreateDeviceObjects();
CIMGUI_API void ImGui_ImplOpenGL2_DestroyDeviceObjects();
/////////////////////////hand written functions

View File

@@ -2,24 +2,24 @@
#include <stdio.h>
#if defined _WIN32 || defined __CYGWIN__
#ifdef CIMGUI_NO_EXPORT
#define API
#ifdef CIMGUI_NO_EXPORT
#define API
#else
#define API __declspec(dllexport)
#endif
#ifndef __GNUC__
#define snprintf sprintf_s
#endif
#else
#define API __declspec(dllexport)
#endif
#ifndef __GNUC__
#define snprintf sprintf_s
#endif
#else
#define API
#define API
#endif
#if defined __cplusplus
#define EXTERN extern "C"
#define EXTERN extern "C"
#else
#include <stdarg.h>
#include <stdbool.h>
#define EXTERN extern
#include <stdarg.h>
#include <stdbool.h>
#define EXTERN extern
#endif
#define CIMGUI_API EXTERN API
@@ -32,10 +32,15 @@ typedef unsigned __int64 ImU64;
typedef unsigned long long ImU64;
#endif
struct GLFWwindow;
//struct GLFWwindow;
//struct SDL_Window;
#ifdef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
#include "imgui_structs.h"
#else
struct GLFWwindow;
struct SDL_Window;
typedef union SDL_Event SDL_Event;
#endif // CIMGUI_DEFINE_ENUMS_AND_STRUCTS
#include "auto_funcs.h"

View File

@@ -1,21 +1,16 @@
:: this is used to rebuild cimgui.h and cimgui.cpp and must be executed in this directory
:: also provides definitions.lua for function definitions
:: and structs_and_enums.lua with struct and enum information-definitions
:: definitions.lua for function definitions
:: structs_and_enums.lua with struct and enum information-definitions
:: impl_definitions.lua for implementation function definitions
:: cimgui_impl.h with implementation function cdefs
:: set your PATH if necessary for gcc and lua 5.1 or luajit with:
set PATH=%PATH%;C:\mingw32\bin;C:\luaGL;
:: gcc -E preprocesor striped comments
:: gcc -E -C //comments but not /* and multiple spaces to one
:: gcc -E -CC // and /* comments
:: gcc -E -C -traditional-cpp // coments and respects multiple spaces
:: gcc -E -P no #pragma location information
::generate preprocessed file
gcc -E -C -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ../../imgui/imgui.h ../../imgui/examples/imgui_impl_glfw.h ../../imgui/examples/imgui_impl_opengl3.h ../../imgui/examples/imgui_impl_opengl2.h > 1.txt
::process preprocessed file
type 1.txt | luajit.exe ./generator.lua true imgui imgui_impl_glfw imgui_impl_opengl3 imgui_impl_opengl2 > out.txt
::process files
:: arg[1] true=use gcc false=dont use gcc
:: arg[2..] name of implementation to generate
luajit.exe ./generator.lua true glfw opengl3 opengl2 sdl
::copy cimgui.h and cimgui.cpp
copy .\cimgui.h ..\cimgui.h

View File

@@ -3,11 +3,10 @@
--expects Lua 5.1 or luajit
--------------------------------------------------------------------------
local script_args = {...}
local locations = {}
for i=2,#script_args do table.insert(locations,script_args[i]) end
local implementations = {}
for i=2,#script_args do table.insert(implementations,script_args[i]) end
-- first script argument to use gcc or not
local USEGCC = script_args[1] == "true"
print("USEGCC",USEGCC)
--------------------------------------------------------------------------
--this table has the functions to be skipped in generation
--------------------------------------------------------------------------
@@ -56,7 +55,7 @@ local cimgui_overloads = {
--helper functions
--------------------------------------------------------------------------
--iterates lines from a .h file and discards between #if.. and #endif
local function imguilines(file)
local function filelines(file)
local iflevels = {}
local function location_it()
repeat
@@ -88,6 +87,7 @@ local function location(file,locpathT)
table.insert(path_reT,'^(.*[\\/])('..locpath..')%.h$')
end
local in_location = false
local which_location = ""
local function location_it()
repeat
local line = file:read"*l"
@@ -98,11 +98,15 @@ local function location(file,locpathT)
if location_match then
in_location = false
for i,path_re in ipairs(path_reT) do
if location_match:match(path_re) then in_location = true; break end
if location_match:match(path_re) then
in_location = true;
which_location = locpathT[i]
break
end
end
end
elseif in_location then
return line
return line, which_location
end
until false
end
@@ -334,7 +338,8 @@ local function func_parser()
FP.embeded_structs = embeded_structs
FP.defsT = defsT
FP.ImVector_templates = ImVector_templates
function FP.insert(line,comment)
function FP.insert(line,comment,locat)
line = clean_spaces(line)
if line:match"template" then return end
line = line:gsub("%S+",{class="struct",mutable=""}) --class -> struct
@@ -439,6 +444,7 @@ local function func_parser()
defT.signature = signature
defT.call_args = call_args
defT.isvararg = signature:match("%.%.%.%)$")
defT.location = locat
defT.comment = comment
if ret then
defT.ret = ret:gsub("&","*")
@@ -693,6 +699,29 @@ typedef struct ImVector ImVector;]])
return outtab
end
local function func_header_impl_generate(FP)
--local hfile = io.open("./auto_funcs2.h","w")
local outtab = {}
for _,t in ipairs(FP.cdefs) do
if t.cimguiname then
local cimf = FP.defsT[t.cimguiname]
local def = cimf[t.signature]
if def.ret then --not constructor
local addcoment = def.comment or ""
if def.stname == "" then --ImGui namespace or top level
table.insert(outtab,"CIMGUI_API".." "..def.ret.." "..(def.ov_cimguiname or def.cimguiname)..def.args..";"..addcoment.."\n")
else
error("class function in implementations")
end
end
else --not cimguiname
table.insert(outtab,t.comment:gsub("%%","%%%%").."\n")-- %% substitution for gsub
end
end
--hfile:close()
return outtab
end
local function func_header_generate(FP)
--local hfile = io.open("./auto_funcs2.h","w")
local outtab = {}
@@ -798,19 +827,33 @@ end
--------------------------------------------------------
-----------------------------do it----------------------
--------------------------------------------------------
print("USEGCC",USEGCC)
local pipe,err
if USEGCC then
pipe,err = io.popen([[gcc -E -C -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ../../imgui/imgui.h]],"r")
if not pipe then
error("could not execute gcc "..err)
end
else
pipe,err = io.open("../../imgui/imgui.h","r")
if not pipe then
error("could not execute gcc "..err)
end
end
print"goint to iterate"
local STP = struct_parser()
local FP = func_parser()
print("USEGCC",USEGCC)
local iterator = (USEGCC and location) or imguilines
print("iterator",iterator)
print(location, imguilines)
for line in iterator(io.input(),locations) do
local iterator = (USEGCC and location) or filelines
for line in iterator(pipe,{"imgui"}) do
local line, comment = split_comment(line)
STP.insert(line,comment)
FP.insert(line,comment)
end
pipe:close()
--output after insert
-- local hfile = io.open("./outstructs.h","w")
@@ -822,7 +865,6 @@ FP:compute_overloads()
local cstructs = gen_structs_and_enums(STP.lines)
local cfuncs = func_header_generate(FP)
local cstructs_table = gen_structs_and_enums_table(STP.lines)
--merge it in cimgui_template.h to cimgui.h
local hfile = io.open("./cimgui_template.h","r")
@@ -857,12 +899,64 @@ hfile:close()
----------save struct and enums lua table in structs_and_enums.lua for using in bindings
local hfile = io.open("./structs_and_enums.lua","w")
local ser = serializeTable("defs",cstructs_table)
local ser = serializeTable("defs",gen_structs_and_enums_table(STP.lines))
hfile:write(ser.."\nreturn defs")
hfile:close()
--=================================Now implementations
local sources = {}
local impl_locs = {}
for i,impl in ipairs(implementations) do
table.insert(sources,[[../../imgui/examples/imgui_impl_]].. impl .. ".h ")
table.insert(impl_locs,[[imgui_impl_]].. impl )
end
if #sources > 0 then
local pipe = nil
if USEGCC then
pipe,err = io.popen([[gcc -E -C -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ]] ..table.concat(sources),"r")
if not pipe then
error("could not execute gcc "..err)
end
end
local iFP = func_parser()
local iSTP = struct_parser()
for line,locat in iterator(pipe,impl_locs) do
local line, comment = split_comment(line)
iSTP.insert(line,comment)
iFP.insert(line,comment,locat)
end
pipe:close()
---[[
local impl_cfuncs = func_header_impl_generate(iFP)
local impl_cstructs = gen_structs_and_enums(iSTP.lines)
---require"anima.utils"
---prtable("impl_funcs",impl_cfuncs)
--save to cimgui_impl.h
local cstructstr = table.concat(impl_cstructs)
cstructstr = cstructstr:gsub("\n+","\n") --several empty lines to one empty line
local cfuncsstr = table.concat(impl_cfuncs)
cfuncsstr = cfuncsstr:gsub("\n+","\n") --several empty lines to one empty line
local outfile = io.open("./cimgui_impl.h","w")
outfile:write(cstructstr)
outfile:write(cfuncsstr)
outfile:close()
--]]
----------save fundefs in impl_definitions.lua for using in bindings
local hfile = io.open("./impl_definitions.lua","w")
local ser = serializeTable("defs",iFP.defsT)
hfile:write(ser.."\nreturn defs")
hfile:close()
end -- #sources > 0 then
--[[
---dump some infos-----------------------------------------------------------------------
------------------------------------------------------------------------------------
print"//-------alltypes--------------------------------------------------------------------"
@@ -880,7 +974,7 @@ end
print"//constructors------------------------------------------------------------------"
for i,t in ipairs(FP.cdefs) do
if not t.ret then
if t.cimguiname and not t.ret then
print(t.cimguiname,"\t",t.signature,"\t",t.args,"\t",t.argsc,"\t",t.call_args,"\t",t.ret)
end
end
@@ -889,6 +983,4 @@ for i,t in ipairs(FP.cdefs) do
--print(t.cimguiname," ",t.funcname,"\t",t.signature,"\t",t.args,"\t",t.argsc,"\t",t.call_args,"\t",t.ret)
end
---------------------------------------------------------------------------------------------
--]]

View File

@@ -2,12 +2,12 @@ rem this is used to rebuild imgui_structs.h
rem set your PATH if necessary for gcc and lua with:
set PATH=%PATH%;C:\luaGL;
rem type ..\..\imgui\imgui.h | luajit.exe ./generator.lua false > out.txt
type ..\..\imgui\imgui.h ..\..\imgui\examples\imgui_impl_glfw.h ..\..\imgui\examples\imgui_impl_opengl3.h | luajit.exe ./generator.lua false > out.txt
luajit.exe ./generator.lua false
::copy cimgui.h and cimgui.cpp
copy .\cimgui.h ..\cimgui.h
copy .\cimgui.cpp ..\cimgui.cpp
::copy .\cimgui.h ..\cimgui.h
::copy .\cimgui.cpp ..\cimgui.cpp
cmd /k