示例#1
0
        public static bool ButtonAbsolute(Vector4 recta, string label, Vector4 color, params GUIOption[] option)
        {
            recta = recta.Padding(1);

            GUIOptionAlign optAlign = null;

            if (option != null)
            {
                option.GetOption(out optAlign);
            }

            bool clicked = false;

            var e = GUI.Event;


            if (e.Used)
            {
                GUI.RectAbsolute(recta, color);
            }
            else
            {
                if (GUIUtility.RectContainsCheck(recta, e.Pointer))
                {
                    if (e.EventType == RigelGUIEventType.MouseClick)
                    {
                        GUI.RectAbsolute(recta, GUIStyle.Current.ColorActiveD);

                        GUI.Event.Use();
                        clicked = true;
                    }
                    else
                    {
                        if (e.EventType == RigelGUIEventType.MouseMove)
                        {
                            GUI.RectAbsolute(recta, GUIStyle.Current.ColorActive);
                        }
                        else
                        {
                            GUI.RectAbsolute(recta, color);
                        }
                    }
                }
                else
                {
                    GUI.RectAbsolute(recta, color);
                }
            }

            Vector2 offset = new Vector2(2, (int)(recta.w - GUI.Font.FontPixelSize) / 2);

            if (optAlign == null || optAlign == GUIOption.AlignCenter)
            {
                offset.x = Mathf.FloorToInt((recta.z - GUI.Font.GetTextWidth(label)) / 2);
            }
            else if (optAlign == GUIOption.AlignRight)
            {
                offset.x = recta.z - GUI.Font.GetTextWidth(label) - 2;
            }

            GUI.TextAbsolute(recta, label, RigelColor.White, offset, true);

            return(clicked);
        }
示例#2
0
        /// <summary>
        /// Draw Button
        /// </summary>
        /// <param name="label"></param>
        /// <param name="options">GUIOptionGrid | GUIOptionWidth | GUIOptionHeight | GUIOptionAlign </param>
        /// <returns></returns>
        public static bool Button(string label, Vector4 color, params GUIOption[] options)
        {
            float w = GUI.CurLayout.RemainSize.x;
            float h = LineHeight;

            GUIOptionAlign optAlign = null;

            if (options != null)
            {
                GUIOptionGrid   grid      = null;
                GUIOptionWidth  optWidth  = null;
                GUIOptionHeight optHeight = null;
                options.GetOption(out grid, out optWidth, out optHeight);

                options.GetOption(out optAlign);

                if (optWidth != null)
                {
                    w = optWidth.Value;
                }
                else if (grid != null)
                {
                    w *= grid.Value;
                }
                if (optHeight != null)
                {
                    h = optHeight.Value;
                }
            }

            var rect = new Vector4(GUI.CurLayout.Offset, w, h);

            rect = rect.Padding(1);

            bool clicked = false;

            var recta = rect.Move(GUI.CurArea.Rect);

            if (GUI.Event.Used)
            {
                GUI.RectAbsolute(recta, color);
            }
            else
            {
                if (GUIUtility.RectContainsCheck(recta, GUI.Event.Pointer))
                {
                    if (GUI.Event.EventType == RigelGUIEventType.MouseClick)
                    {
                        GUI.RectAbsolute(recta, GUIStyle.Current.ColorActiveD);
                        GUI.Event.Use();
                        clicked = true;
                    }
                    else
                    {
                        GUI.RectAbsolute(recta, GUIStyle.Current.ColorActive);
                        if (GUI.Event.EventType == RigelGUIEventType.MouseMove)
                        {
                            GUI.Event.Use();
                        }
                    }
                }
                else
                {
                    GUI.RectAbsolute(recta, color);
                }
            }

            //Draw label

            Vector2 offset = new Vector2(4, (rect.w - GUI.Font.FontPixelSize) / 2);

            if (optAlign == null || optAlign == GUIOption.AlignCenter)
            {
                offset.x = (int)((rect.z - GUI.Font.GetTextWidth(label)) / 2);
            }
            else if (optAlign == GUIOption.AlignRight)
            {
                offset.x = rect.z - GUI.Font.GetTextWidth(label) - 2;
            }
            GUI.Text(rect, label, RigelColor.White, offset, true);
            AutoCaculateOffset(w, h);

            return(clicked);
        }