A low-level wrapper to the AntTweakBar API.
Exemplo n.º 1
0
 /// <summary>
 /// This function checks if a key event would be processed but without processing it. This could be helpful to prevent bad handling report.
 /// </summary>
 /// <param name="key">One of the <see cref="AntTweakBar.Tw.Key"/> codes.</param>
 /// <param name="modifiers">One or a combination of the <see cref="AntTweakBar.Tw.KeyModifiers"/> constants.</param>
 /// <returns>Whether the key event would have been handled by AntTweakBar.</returns>
 public static bool KeyTest(Tw.Key key, KeyModifiers modifiers)
 {
     return KeyTest((char)key, modifiers);
 }
Exemplo n.º 2
0
 public StructMember(IntPtr name, Tw.VariableType type, UIntPtr offset, IntPtr defString) : this()
 {
     Name = name;
     Type = type;
     Offset = offset;
     DefString = defString;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Call this function to inform AntTweakBar when a keyboard event occurs.
 /// </summary>
 /// <param name="key">One of the <see cref="AntTweakBar.Tw.Key"/> codes.</param>
 /// <param name="modifiers">One or a combination of the <see cref="AntTweakBar.Tw.KeyModifiers"/> constants.</param>
 /// <returns>Whether the key event has been handled by AntTweakBar.</returns>
 public static bool KeyPressed(Tw.Key key, KeyModifiers modifiers)
 {
     return KeyPressed((char)key, modifiers);
 }
Exemplo n.º 4
0
        /// <summary>
        /// This function creates a new <see cref="AntTweakBar.Tw.VariableType"/> corresponding to a structure.
        /// </summary>
        public static VariableType DefineStruct(String name, IDictionary<String, StructMemberInfo> structMembers, int structSize, Tw.SummaryCallback callback, IntPtr clientData)
        {
            if (name == null) {
                throw new ArgumentNullException("name");
            } else if (structMembers == null) {
                throw new ArgumentNullException("structMembers");
            } else if (structSize == 0) {
                throw new ArgumentOutOfRangeException("structSize");
            }

            var structData = new List<NativeMethods.StructMember>();

            try
            {
                foreach (var kv in structMembers) {
                    IntPtr namePtr = IntPtr.Zero;
                    IntPtr defPtr = IntPtr.Zero;

                    if (kv.Key == null) {
                        throw new ArgumentNullException("", "Member name cannot be null.");
                    }

                    if (kv.Value.Def == null) {
                        throw new ArgumentNullException("", "Member definition string cannot be null.");
                    }

                    try
                    {
                        namePtr = Helpers.PtrFromStr(kv.Key);
                        defPtr = Helpers.PtrFromStr(kv.Value.Def);

                        structData.Add(new NativeMethods.StructMember(
                            namePtr,
                            kv.Value.Type,
                            new UIntPtr((uint)kv.Value.Offset),
                            defPtr
                            ));
                    }
                    catch (Exception)
                    {
                        if (namePtr != IntPtr.Zero) {
                            Marshal.FreeCoTaskMem(namePtr);
                        }

                        if (defPtr != IntPtr.Zero) {
                            Marshal.FreeCoTaskMem(defPtr);
                        }

                        throw;
                    }
                }

                Tw.VariableType structType = NativeMethods.TwDefineStruct(name, structData.ToArray(),
                                                                          (uint)structData.Count,
                                                                          new UIntPtr((uint)structSize),
                                                                          callback, clientData);

                if (structType == VariableType.Undefined) {
                    throw new AntTweakBarException("TwDefineStruct failed.");
                }

                return structType;
            }
            finally
            {
                foreach (var member in structData) {
                    Marshal.FreeCoTaskMem(member.Name);
                    Marshal.FreeCoTaskMem(member.DefString);
                }
            }
        }