@@ -24,17 +24,55 @@ static void Main(string[] args)
2424 {
2525 outputPath = AppContext . BaseDirectory ;
2626 }
27+
28+ string libraryName ;
29+ if ( args . Length > 1 )
30+ {
31+ libraryName = args [ 1 ] ;
32+ }
33+ else
34+ {
35+ libraryName = "cimgui" ;
36+ }
37+
38+ string projectNamespace = libraryName switch
39+ {
40+ "cimgui" => "ImGuiNET" ,
41+ "cimplot" => "ImGuiNET" ,
42+ "cimnodes" => "ImGuiNET" ,
43+ "cimguizmo" => "ImGuiNET" ,
44+ _ => throw new NotImplementedException ( )
45+ } ;
46+
47+ string classPrefix = libraryName switch
48+ {
49+ "cimgui" => "ImGui" ,
50+ "cimplot" => "ImPlot" ,
51+ "cimnodes" => "ImNodes" ,
52+ "cimguizmo" => "ImGuizmo" ,
53+ _ => throw new NotImplementedException ( )
54+ } ;
55+
56+ string dllName = libraryName switch
57+ {
58+ "cimgui" => "cimgui" ,
59+ "cimplot" => "cimgui" ,
60+ "cimnodes" => "cimgui" ,
61+ "cimguizmo" => "cimgui" ,
62+ _ => throw new NotImplementedException ( )
63+ } ;
2764
65+ string definitionsPath = Path . Combine ( AppContext . BaseDirectory , "definitions" , libraryName ) ;
2866 var defs = new ImguiDefinitions ( ) ;
29- defs . LoadFrom ( AppContext . BaseDirectory ) ;
30-
67+ defs . LoadFrom ( definitionsPath ) ;
68+
3169 Console . WriteLine ( $ "Outputting generated code files to { outputPath } .") ;
3270
3371 foreach ( EnumDefinition ed in defs . Enums )
3472 {
3573 using ( CSharpCodeWriter writer = new CSharpCodeWriter ( Path . Combine ( outputPath , ed . FriendlyName + ".gen.cs" ) ) )
3674 {
37- writer . PushBlock ( "namespace ImGuiNET " ) ;
75+ writer . PushBlock ( $ "namespace { projectNamespace } ") ;
3876 if ( ed . FriendlyName . Contains ( "Flags" ) )
3977 {
4078 writer . WriteLine ( "[System.Flags]" ) ;
@@ -62,7 +100,7 @@ static void Main(string[] args)
62100 writer . Using ( "System.Runtime.CompilerServices" ) ;
63101 writer . Using ( "System.Text" ) ;
64102 writer . WriteLine ( string . Empty ) ;
65- writer . PushBlock ( "namespace ImGuiNET " ) ;
103+ writer . PushBlock ( $ "namespace { projectNamespace } ") ;
66104
67105 writer . PushBlock ( $ "public unsafe partial struct { td . Name } ") ;
68106 foreach ( TypeReference field in td . Fields )
@@ -209,7 +247,7 @@ static void Main(string[] args)
209247 {
210248 defaults . Add ( orderedDefaults [ j ] . Key , orderedDefaults [ j ] . Value ) ;
211249 }
212- EmitOverload ( writer , overload , defaults , "NativePtr" ) ;
250+ EmitOverload ( writer , overload , defaults , "NativePtr" , classPrefix ) ;
213251 }
214252 }
215253 }
@@ -219,14 +257,14 @@ static void Main(string[] args)
219257 }
220258 }
221259
222- using ( CSharpCodeWriter writer = new CSharpCodeWriter ( Path . Combine ( outputPath , "ImGuiNative .gen.cs") ) )
260+ using ( CSharpCodeWriter writer = new CSharpCodeWriter ( Path . Combine ( outputPath , $ " { classPrefix } Native .gen.cs") ) )
223261 {
224262 writer . Using ( "System" ) ;
225263 writer . Using ( "System.Numerics" ) ;
226264 writer . Using ( "System.Runtime.InteropServices" ) ;
227265 writer . WriteLine ( string . Empty ) ;
228- writer . PushBlock ( "namespace ImGuiNET " ) ;
229- writer . PushBlock ( "public static unsafe partial class ImGuiNative " ) ;
266+ writer . PushBlock ( $ "namespace { projectNamespace } ") ;
267+ writer . PushBlock ( $ "public static unsafe partial class { classPrefix } Native ") ;
230268 foreach ( FunctionDefinition fd in defs . Functions )
231269 {
232270 foreach ( OverloadDefinition overload in fd . Overloads )
@@ -273,12 +311,12 @@ static void Main(string[] args)
273311
274312 if ( isUdtVariant )
275313 {
276- writer . WriteLine ( $ "[DllImport(\" cimgui \" , CallingConvention = CallingConvention.Cdecl, EntryPoint = \" { exportedName } \" )]") ;
314+ writer . WriteLine ( $ "[DllImport(\" { dllName } \" , CallingConvention = CallingConvention.Cdecl, EntryPoint = \" { exportedName } \" )]") ;
277315
278316 }
279317 else
280318 {
281- writer . WriteLine ( "[DllImport(\" cimgui \" , CallingConvention = CallingConvention.Cdecl)]" ) ;
319+ writer . WriteLine ( $ "[DllImport(\" { dllName } \" , CallingConvention = CallingConvention.Cdecl)]") ;
282320 }
283321 writer . WriteLine ( $ "public static extern { ret } { methodName } ({ parameters } );") ;
284322 }
@@ -287,15 +325,15 @@ static void Main(string[] args)
287325 writer . PopBlock ( ) ;
288326 }
289327
290- using ( CSharpCodeWriter writer = new CSharpCodeWriter ( Path . Combine ( outputPath , "ImGui .gen.cs") ) )
328+ using ( CSharpCodeWriter writer = new CSharpCodeWriter ( Path . Combine ( outputPath , $ " { classPrefix } .gen.cs") ) )
291329 {
292330 writer . Using ( "System" ) ;
293331 writer . Using ( "System.Numerics" ) ;
294332 writer . Using ( "System.Runtime.InteropServices" ) ;
295333 writer . Using ( "System.Text" ) ;
296334 writer . WriteLine ( string . Empty ) ;
297- writer . PushBlock ( "namespace ImGuiNET " ) ;
298- writer . PushBlock ( "public static unsafe partial class ImGui " ) ;
335+ writer . PushBlock ( $ "namespace { projectNamespace } ") ;
336+ writer . PushBlock ( $ "public static unsafe partial class { classPrefix } ") ;
299337 foreach ( FunctionDefinition fd in defs . Functions )
300338 {
301339 if ( TypeInfo . SkippedFunctions . Contains ( fd . Name ) ) { continue ; }
@@ -336,7 +374,7 @@ static void Main(string[] args)
336374 {
337375 defaults . Add ( orderedDefaults [ j ] . Key , orderedDefaults [ j ] . Value ) ;
338376 }
339- EmitOverload ( writer , overload , defaults , null ) ;
377+ EmitOverload ( writer , overload , defaults , null , classPrefix ) ;
340378 }
341379 }
342380 }
@@ -381,7 +419,8 @@ private static void EmitOverload(
381419 CSharpCodeWriter writer ,
382420 OverloadDefinition overload ,
383421 Dictionary < string , string > defaultValues ,
384- string selfName )
422+ string selfName ,
423+ string classPrefix )
385424 {
386425 if ( overload . Parameters . Where ( tr => tr . Name . EndsWith ( "_begin" ) || tr . Name . EndsWith ( "_end" ) )
387426 . Any ( tr => ! defaultValues . ContainsKey ( tr . Name ) ) )
@@ -481,6 +520,15 @@ private static void EmitOverload(
481520 postCallLines . Add ( $ "}}") ;
482521 }
483522 }
523+ else if ( defaultValues . TryGetValue ( tr . Name , out string defaultVal ) )
524+ {
525+ if ( ! CorrectDefaultValue ( defaultVal , tr , out string correctedDefault ) )
526+ {
527+ correctedDefault = defaultVal ;
528+ }
529+ marshalledParameters [ i ] = new MarshalledParameter ( nativeTypeName , false , correctedIdentifier , true ) ;
530+ preCallLines . Add ( $ "{ nativeTypeName } { correctedIdentifier } = { correctedDefault } ;") ;
531+ }
484532 else if ( tr . Type == "char* []" )
485533 {
486534 string nativeArgName = "native_" + tr . Name ;
@@ -518,15 +566,6 @@ private static void EmitOverload(
518566 preCallLines . Add ( $ " offset += { correctedIdentifier } _byteCounts[i] + 1;") ;
519567 preCallLines . Add ( "}" ) ;
520568 }
521- else if ( defaultValues . TryGetValue ( tr . Name , out string defaultVal ) )
522- {
523- if ( ! CorrectDefaultValue ( defaultVal , tr , out string correctedDefault ) )
524- {
525- correctedDefault = defaultVal ;
526- }
527- marshalledParameters [ i ] = new MarshalledParameter ( nativeTypeName , false , correctedIdentifier , true ) ;
528- preCallLines . Add ( $ "{ nativeTypeName } { correctedIdentifier } = { correctedDefault } ;") ;
529- }
530569 else if ( tr . Type == "bool" )
531570 {
532571 string nativeArgName = "native_" + tr . Name ;
@@ -557,7 +596,7 @@ private static void EmitOverload(
557596 marshalledParameters [ i ] = new MarshalledParameter ( wrappedParamType , false , nativeArgName , false ) ;
558597 preCallLines . Add ( $ "{ tr . Type } { nativeArgName } = { correctedIdentifier } .NativePtr;") ;
559598 }
560- else if ( ( tr . Type . EndsWith ( "*" ) || tr . Type . Contains ( "[" ) || tr . Type . EndsWith ( "&" ) ) && tr . Type != "void*" && tr . Type != "ImGuiContext*" )
599+ else if ( ( tr . Type . EndsWith ( "*" ) || tr . Type . Contains ( "[" ) || tr . Type . EndsWith ( "&" ) ) && tr . Type != "void*" && tr . Type != "ImGuiContext*" && tr . Type != "ImPlotContext*" && tr . Type != "EditorContext*" )
561600 {
562601 string nonPtrType ;
563602 if ( tr . Type . Contains ( "[" ) )
@@ -634,7 +673,7 @@ private static void EmitOverload(
634673 targetName = targetName . Substring ( 0 , targetName . IndexOf ( "_nonUDT" ) ) ;
635674 }
636675
637- writer . WriteLine ( $ "{ ret } ImGuiNative .{ targetName } ({ nativeInvocationStr } );") ;
676+ writer . WriteLine ( $ "{ ret } { classPrefix } Native .{ targetName } ({ nativeInvocationStr } );") ;
638677
639678 foreach ( string line in postCallLines )
640679 {
@@ -736,7 +775,7 @@ private static bool GetWrappedType(string nativeType, out string wrappedType)
736775
737776 private static bool CorrectDefaultValue ( string defaultVal , TypeReference tr , out string correctedDefault )
738777 {
739- if ( tr . Type == "ImGuiContext*" )
778+ if ( tr . Type == "ImGuiContext*" || tr . Type == "ImPlotContext*" || tr . Type == "EditorContext*" )
740779 {
741780 correctedDefault = "IntPtr.Zero" ;
742781 return true ;
@@ -754,7 +793,10 @@ private static bool CorrectDefaultValue(string defaultVal, TypeReference tr, out
754793
755794 if ( tr . IsEnum )
756795 {
757- correctedDefault = $ "({ tr . Type } ){ defaultVal } ";
796+ if ( defaultVal . StartsWith ( "-" ) )
797+ correctedDefault = $ "({ tr . Type } )({ defaultVal } )";
798+ else
799+ correctedDefault = $ "({ tr . Type } ){ defaultVal } ";
758800 return true ;
759801 }
760802
0 commit comments