Sign in to follow this  
Bacterius

AntTweakBar for C#

Recommended Posts

Hello, does anyone know of, or has anyone written a - free - wrapper for the AntTweakBar GUI library for C#? Just asking before I start writing my own, can't find one on the internet at all (which is surprising, I'd imagine someone somewhere would have already created one). The API looks straightforward enough to port, but I'd really hate to reinvent the wheel.

 

Thanks!

Share this post


Link to post
Share on other sites

Well I just rolled my own after all. Here's the link if anyone is looking for one as well, it has most - but not all - of the exported methods and types along with a hastily coded high-level wrapper for DirectX/SharpDX (though it can easily be made to use any other graphics interface). Will probably improve it in the future, but for now this should be enough to get you started on using AntTweakBar from C# without spending too much time screwing around with PInvoke.

 

Acx9RAs.png

Share this post


Link to post
Share on other sites

Can I ask why you decided to use pinvoke instead of C++/CLI?

 

Because I knew PInvoke, didn't know C++/CLI, and needed to get it working ASAP. Will probably rewrite it eventually though.

Share this post


Link to post
Share on other sites

The AntTweakBar API is all C functions, so there's nothing to be gained by using C++/CLI over PInvoke. C++/CLI is a dark and terrible place...you don't want  go there unless you really have to.

Share this post


Link to post
Share on other sites

Sometimes even plain C APIs can be nasty enough that it's easier to write a C++/CLI wrapper.  (The Win32 debugging API is one of those cases in my opinion, with the various ugly structs.)

Edited by Nypyren

Share this post


Link to post
Share on other sites
This is great. Effort very much appreciated.

Unfortunately the callbacks from unmanaged code caused serious trouble (e.g. crash in TwEventWin). I use SlimDX but I doubt it's the culprit. Hmmm, I somehow remembered that callbacks across the unmanaged borders aren't that easy. Did you really have no troubles whatsoever ? I'm surprised.

Thanks to StackOverflow and this MSDN entry I could fix it. Also had to change the calling convention for the delegates to StdCall (by the way, this was for the .NET 2 framework and x86 platform).

I changed the Variable design a bit and also added a Button wrapper if you don't mind. Oh, you already refactored. Anyway, I attached the source file below

And some proof. Tweaky sunrise:

165e30283644990.jpg
6018e1283645007.jpg

Thanks again  biggrin.png

Share this post


Link to post
Share on other sites

Unfortunately the callbacks from unmanaged code caused serious trouble (e.g. crash in TwEventWin). I use SlimDX but I doubt it's the culprit. Hmmm, I somehow remembered that callbacks across the unmanaged borders aren't that easy. Did you really have no troubles whatsoever ?

 

No, the only issue I had at first was not holding a strong reference to them (so they would get garbage collected instantly - I just stored a reference in the Variable class and it worked perfectly). I think you may be spot on regarding the calling convention, I am working on .NET 4, x64 processor, so the calling convention would be different. I will have to try out your version! Really nice renders by the way smile.png

 

BTW I see you've changed around the type semantics a bit. I will definitely need to check it out tomorrow - I am not really happy with my current approach, but I wasn't really sure how to make the wrapper work properly for every variable type without resorting to ugly casts to and from Object. So your generic approach looks a lot better..

Edited by Bacterius

Share this post


Link to post
Share on other sites

No, the only issue I had at first was not holding a strong reference to them (so they would get garbage collected instantly - I just stored a reference in the Variable class and it worked perfectly). I think you may be spot on regarding the calling convention, I am working on .NET 4, x64 processor, so the calling convention would be different. I will have to try out your version! Really nice renders by the way smile.png


Thanks. It's the one from Sean O'Neill.

Hmmm, yeah garbage collecting is the problem mentioned throughout the posts I found. Hopefully more people gonna play with this on different runtimes and platforms.
 

BTW I see you've changed around the type semantics a bit. I will definitely need to check it out tomorrow - I am not really happy with my current approach, but I wasn't really sure how to make the wrapper work properly for every variable type without resorting to ugly casts to and from Object. So your generic approach looks a lot better..


I wonder if one could come up with a super clean design for generic attributes at all wink.png. Runtime polymorphism for "all there is" ? Either you have wrappers for every type or functions for every type, and a cast hides always somewhere. But the generic layer makes the subsequent wrappers a bit more concise.

Share this post


Link to post
Share on other sites

Sometimes even plain C APIs can be nasty enough that it's easier to write a C++/CLI wrapper.  (The Win32 debugging API is one of those cases in my opinion, with the various ugly structs.)

Fair enough, but this API is fairly straightforward so I don't think it would fall into that category.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this