AntTweakBar for C#

Started by
8 comments, last by MJP 10 years, 5 months ago

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!

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Advertisement

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

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

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

if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight

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.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

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.

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.)

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

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..

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

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.

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.

This topic is closed to new replies.

Advertisement