예제 #1
0
        public bool CheckButtonPress(string buttonName, ButtonPressType pressType)
        {
            bool wasPressed;
            bool isPressed;

            _oldButtonsState.TryGetValue(buttonName, out wasPressed);
            _buttonsState.TryGetValue(buttonName, out isPressed);
            switch (pressType)
            {
            case ButtonPressType.OnPress:
                return(!wasPressed && isPressed);

            case ButtonPressType.Hold:
                return(isPressed);

            case ButtonPressType.OnReleased:
                return(wasPressed && !isPressed);

            case ButtonPressType.WhileReleased:
                return(wasPressed);

            default:
                return(!wasPressed && isPressed);
            }
        }
        public GenericKeyboardValueInputCheck(Keys key, float value, ButtonPressType pressType, string commandname = "generic_key")
        {
            IsDebugMode  = false;
            IsDrawable   = false;
            DrawOrder    = 0;
            IsUpdateable = true;

            ButtonPressType = pressType;
            CommandName     = commandname;
            DeviceType      = InputType.Keyboard;
            _triggerKey     = key;
            _triggerValue   = value;
        }
예제 #3
0
        /// <summary>
        /// Sends a custom button press (click) event to a widget.
        /// </summary>
        /// <param name="target">Widget which should receive the button press event.</param>
        /// <param name="eventType">Type of event to be sent.</param>
        /// <param name="state">Modifiers for the click - ie control click, shift click, etc.</param>
        /// <param name="button">Type of click - ie left click, middle click or right click.</param>
        /// <param name="x">x-coordinate of the click, relative to the top-left corner of the widget.</param>
        /// <param name="y">y-coordinate of the click, relative to the top-left corner of the widget.</param>
        /// <param name="wait">Iff true, will wait for gtk to process the event.</param>
        public static void Click(Widget target, EventType eventType, ModifierType state, ButtonPressType button, double x = 0, double y = 0, bool wait = true)
        {
            Gdk.Window win = target.GdkWindow;

            int rx, ry;

            win.GetRootOrigin(out rx, out ry);

            var nativeEvent = new NativeEventButtonStruct
            {
                type       = eventType,
                send_event = 1,
                window     = win.Handle,
                state      = (uint)state,
                button     = (uint)button,
                x          = x,
                y          = y,
                axes       = IntPtr.Zero,
                device     = IntPtr.Zero,
                time       = Gtk.Global.CurrentEventTime,
                x_root     = x + rx,
                y_root     = y + ry
            };

            IntPtr ptr = GLib.Marshaller.StructureToPtrAlloc(nativeEvent);

            try
            {
                EventHelper.Put(new EventButton(ptr));
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }

            if (wait)
            {
                // Clear gtk event loop.
                while (GLib.MainContext.Iteration())
                {
                    ;
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Sends a custom button press (click) event to a particular cell in a GridView.
        /// </summary>
        /// <param name="grid">The GridView which should receive the button press event.</param>
        /// <param name="row">Row index of the cell to be clicked.</param>
        /// <param name="col">Column index of the cell to be clicked.</param>
        /// <param name="eventType">Type of event to be sent.</param>
        /// <param name="state">Modifiers for the click - ie control click, shift click, etc.</param>
        /// <param name="buttonClickType">Type of click - ie left click, middle click or right click.</param>
        /// <param name="wait">Iff true, will wait for gtk to process the event.</param>
        public static void ClickOnGridCell(GridView grid, int row, int col, EventType eventType, ModifierType state, ButtonPressType buttonClickType, bool wait = true)
        {
            // We want to click on a cell, but this requires coordinates.
            GetTreeViewCoordinates(grid.Grid, row, col, out int x, out int y);

            // Double-click on the top-right cell using the coordinates.
            Click(grid.Grid, eventType, state, buttonClickType, x, y, wait);
        }
예제 #5
0
 public static bool HasType(this ButtonPressType flag, ButtonPressType type)
 {
     return((flag & type) == type);
 }
예제 #6
0
        //internal static float GetHeaderAttributeHeight(SerializedProperty serializedProperty)
        //{
        //    Object target = serializedProperty.serializedObject.targetObject;
        //    FieldInfo fieldInfo = target.GetType().GetField(serializedProperty.name);
        //    if (fieldInfo == null)
        //    {
        //        return 0;
        //    }

        //    Type tButtonExAttribute = typeof(HeaderAttribute);
        //    if (Attribute.IsDefined(fieldInfo, tButtonExAttribute, true))
        //    {
        //        return fieldInfo.GetCustomAttributes(tButtonExAttribute, true).Length * 24f;
        //    }

        //    return 0;
        //}

        private static void ListField(SerializedProperty iterator, MonoInspector editor)
        {
            editor.nListId++;
            int dragId = editor.nListId + editor.nObjectId;

            GUILayout.BeginHorizontal();
            GUILayout.Space(10);
            EditorGUILayout.PropertyField(iterator,
                                          new GUIContent(string.Format("[{0}] {1}", iterator.arraySize, iterator.displayName)), false);
            GUILayout.EndHorizontal();
            Rect position = GUILayoutUtility.GetLastRect();

            position.x     = 2;
            position.width = 10;
            float heightDelta = position.height - 16;

            if (heightDelta > 0)
            {
                position.height = 16;
                position.y     += heightDelta;
            }

            //上移16高度绘制“+”、“清空”按钮
            GUILayout.Space(-18);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayoutPressButton(sStyles.iconPlus, sStyles.preButton, GUILayout.Width(16)) ==
                ButtonPressType.Mouse0)
            {
                //添加一个元素
                iterator.isExpanded = true;
                iterator.InsertArrayElementAtIndex(iterator.arraySize);
                Event.current.type = EventType.Used;
                editor.Repaint();
            }

            Color currColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.red;
            if (GUILayoutPressButton(sStyles.iconTrash, sStyles.preButton, GUILayout.Width(16)) ==
                ButtonPressType.Mouse0)
            {
                //清空列表
                iterator.isExpanded = true;
                iterator.ClearArray();
                MonoInspectorDrag.EndDrag(false);
                Event.current.type = EventType.Used;
                editor.Repaint();
            }

            GUI.backgroundColor = currColor;
            GUILayout.EndHorizontal();

            //显示折叠
            if (!iterator.isExpanded || iterator.serializedObject == null || iterator.arraySize == 0)
            {
                return;
            }

            //为拖拽准备一个IList
            IList     iList      = null;
            int       minListLen = int.MaxValue;
            Type      type       = editor.target.GetType();
            FieldInfo fInfo      = type.GetField(iterator.name,
                                                 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            while (fInfo == null && type != typeof(Object))
            {
                type = type.BaseType;
                if (type == null)
                {
                    break;
                }

                fInfo = type.GetField(iterator.name,
                                      BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            }

            for (int index = 0; index < editor.targets.Length; index++)
            {
                Object o  = editor.targets[index];
                IList  li = fInfo.GetValue(o) as IList;
                int    l  = li == null ? 0 : li.Count;
                if (l >= minListLen)
                {
                    continue;
                }

                iList      = li;
                minListLen = l;
            }

            //绘制列表元素
            Undo.RecordObject(iterator.serializedObject.targetObject, iterator.serializedObject.targetObject.name);
            if (Event.current.type == EventType.DragPerform || Event.current.type == EventType.DragExited ||
                Event.current.type == EventType.DragUpdated)
            {
                for (int i = 0; i < iterator.arraySize; i++)
                {
                    SerializedProperty spArrayElement = iterator.GetArrayElementAtIndex(i);
                    EditorGUILayout.PropertyField(spArrayElement, spArrayElement.hasChildren); // Property
                }

                return;
            }

            EditorGUILayout.BeginVertical(sStyles.list);
            for (int i = 0; i < iterator.arraySize; i++)
            {
                SerializedProperty spArrayElement = iterator.GetArrayElementAtIndex(i);
                EditorGUILayout.BeginHorizontal();
                float currLabelW = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth -= 25;
                bool wasEnabled = GUI.enabled;
                if (editor.targets.Length > 1)
                {
                    GUI.enabled = false;
                }

                //按方块开始拖拽
                ButtonPressType bpt = GUILayoutPressButton(GUIContent.none, sStyles.listItem);
                if (bpt == ButtonPressType.Mouse1)
                {
                    MonoInspectorDrag.StartDrag(dragId, editor, iList, i);
                }

                GUI.enabled = wasEnabled;
                if (spArrayElement.hasVisibleChildren)
                {
                    GUILayout.Label(i.ToString(), sStyles.button);
                    GUILayout.Space(10);
                }

                EditorGUILayout.PropertyField(spArrayElement, spArrayElement.hasChildren); // Property
                if (GUILayout.Button(sStyles.iconPlus, sStyles.preButton, GUILayout.Width(16)))
                {
                    iterator.InsertArrayElementAtIndex(i);
                    EditorGUILayout.EndHorizontal();
                    break;
                }

                if (GUILayout.Button(sStyles.iconMinus, sStyles.preButton, GUILayout.Width(16)))
                {
                    if (spArrayElement.propertyType == SerializedPropertyType.ObjectReference &&
                        spArrayElement.objectReferenceValue != null)
                    {
                        iterator.DeleteArrayElementAtIndex(i);
                    }

                    iterator.DeleteArrayElementAtIndex(i);
                    EditorGUILayout.EndHorizontal();
                    break;
                }

                EditorGUIUtility.labelWidth = currLabelW;
                EditorGUILayout.EndHorizontal();
                if (MonoInspectorDrag.Drag(dragId, iList, i).outcome == DragResultType.Accepted)
                {
                    GUI.changed = true;
                }
            }

            EditorGUILayout.EndHorizontal();

            if (iterator.isExpanded)
            {
                GUILayout.Space(3);
                GUILayout.Box(string.Empty, sStyles.endBackground, GUILayout.ExpandWidth(true), GUILayout.Height(2));
            }
        }