anttweakbar.d 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. module three.anttweakbar.anttweakbar;
  2. import derelict.anttweakbar.anttweakbar;
  3. import std.string;
  4. import std.stdio;
  5. import three.primitives;
  6. template toAntTweakBarType(T) {
  7. static if(is(T == bool)) {
  8. alias toAntTweakBarType = TW_TYPE_BOOLCPP;
  9. }
  10. else static if(is(T == byte)) {
  11. alias toAntTweakBarType = TW_TYPE_INT8;
  12. }
  13. else static if(is(T == short)) {
  14. alias toAntTweakBarType = TW_TYPE_INT16;
  15. }
  16. else static if(is(T == int)) {
  17. alias toAntTweakBarType = TW_TYPE_INT32;
  18. }
  19. else static if(is(T == ubyte)) {
  20. alias toAntTweakBarType = TW_TYPE_UINT8;
  21. }
  22. else static if(is(T == ushort)) {
  23. alias toAntTweakBarType = TW_TYPE_UINT16;
  24. }
  25. else static if(is(T == uint)) {
  26. alias toAntTweakBarType = TW_TYPE_UINT32;
  27. }
  28. else static if(is(T == float)) {
  29. alias toAntTweakBarType = TW_TYPE_FLOAT;
  30. }
  31. else static if(is(T == double)) {
  32. alias toAntTweakBarType = TW_TYPE_DOUBLE;
  33. }
  34. else static if(is(T == Vector3f)) {
  35. alias toAntTweakBarType = TW_TYPE_DIR3D;
  36. }
  37. else static if(is(T == Quaternionf)) {
  38. alias toAntTweakBarType = TW_TYPE_QUAT4F;
  39. }
  40. else static assert(false, "no type convertion possible");
  41. }
  42. final class TweakBar {
  43. private:
  44. TwBar* _handle;
  45. public:
  46. ///
  47. this(string name) {
  48. this._handle = TwNewBar(name.toStringz());
  49. writeln("TweakBar created: ", this._handle);
  50. }
  51. ///
  52. ~this() {
  53. TwDeleteBar(this._handle);
  54. writeln("TweakBar destroyed: ", this._handle);
  55. }
  56. public:
  57. void addVarRW(T)(string name, string def, ref T t) {
  58. TwAddVarRW(this._handle, name.toStringz(), toAntTweakBarType!T, &t, def.toStringz());
  59. }
  60. public:
  61. ///
  62. @property bool isValid() const @safe nothrow {
  63. return (this._handle != null);
  64. }
  65. }