Esempio n. 1
0
    protected override void RenderBody(SerializedPropertyX considerationProperty, RenderData _data, int index)
    {
        ConsiderationRenderData data          = _data as ConsiderationRenderData;
        Consideration           consideration = considerationProperty.GetValue <Consideration>();

        //manually render description and curve to make sure they come first
        DrawerUtil.PushLabelWidth(125);
        DrawerUtil.PushIndentLevel(1);
        consideration.description = EditorGUILayout.TextField(new GUIContent("Description"),
                                                              consideration.description);
        GUIContent content = new GUIContent();

        content.text = Util.SplitAndTitlize(consideration.GetType().Name);
        EditorGUILayout.BeginHorizontal();
        data.isInputDisplayed = EditorGUILayout.Foldout(data.isInputDisplayed, content);
        EditorGUILayout.EndHorizontal();
        if (data.isInputDisplayed)
        {
            EditorGUI.indentLevel++;
            for (int i = 0; i < considerationProperty.ChildCount; i++)
            {
                SerializedPropertyX child = considerationProperty.GetChildAt(i);
                if (skipRenderingFields.IndexOf(child.name) != -1)
                {
                    continue;
                }
                EditorGUILayoutX.PropertyField(child, child.label, child.isExpanded);
            }
            EditorGUI.indentLevel--;
        }
        RenderCurve(considerationProperty.FindProperty("curve"), data);
        DrawerUtil.PopLabelWidth();
        DrawerUtil.PopIndentLevel();
    }
Esempio n. 2
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        WritableAttribute attr = attribute as WritableAttribute;

        GUI.enabled = attr.Result(DrawerUtil.GetTarget(property));
        DrawerUtil.OnGUI(position, property, label);
        GUI.enabled = true;
    }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        VisibleAttribute attr = attribute as VisibleAttribute;

        if (attr == null || attr.Result(DrawerUtil.GetTarget(property)))
        {
            DrawerUtil.OnGUI(position, property, label);
        }
    }
 private void Init(SerializedProperty property)
 {
     if (visible == null)
     {
         visible       = new AnimBool();
         visible.speed = DrawerUtil.AnimSpeed;
         visible.valueChanged.AddListener(() => { DrawerUtil.RepaintInspector(property.serializedObject); });
     }
 }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // EditorGUI.BeginProperty(position, label, property);
            Init(property);

            EditorGUI.indentLevel++;

            var attr = this.attribute as CollapsedEventAttribute;

            position.height = EditorGUIUtility.singleLineHeight;
            var temp = new GUIContent(label);

            SerializedProperty persistentCalls = property.FindPropertyRelative("m_PersistentCalls.m_Calls");

            if (persistentCalls != null)
            {
                temp.text += " (" + persistentCalls.arraySize + ")";
            }

            EditorGUI.BeginChangeCheck();

            if (string.IsNullOrEmpty(temp.tooltip))
            {
                // var tooltipAttribute = fieldInfo.GetCustomAttributes(typeof(TooltipAttribute), true).FirstOrDefault() as TooltipAttribute;
                // var tooltip = tooltipAttribute != null ? tooltipAttribute.tooltip : null;
                temp.tooltip = attr.tooltip;
            }

#if UNITY_2019_1_OR_NEWER
            attr.visible = EditorGUI.BeginFoldoutHeaderGroup(position, attr.visible, temp);
#else
            attr.visible = EditorGUI.Foldout(position, attr.visible, temp, true);
#endif
            if (EditorGUI.EndChangeCheck())
            {
                visible.target = attr.visible;
            }

            position.height = base.GetPropertyHeight(property, label) * visible.faded;
            position.y     += EditorGUIUtility.singleLineHeight;
            if (DrawerUtil.BeginFade(visible, ref position))
            {
                var text = label.text;
                label.text = null;
                base.OnGUI(position, property, label);
                label.text = text;
            }
            DrawerUtil.EndFade();
#if UNITY_2019_1_OR_NEWER
            EditorGUI.EndFoldoutHeaderGroup();
#endif
            EditorGUI.indentLevel--;
        }
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        VisibleAttribute attr = attribute as VisibleAttribute;

        if (attr == null || attr.Result(DrawerUtil.GetTarget(property)))
        {
            return(DrawerUtil.GetPropertyHeight(property, label));
        }
        else
        {
            return(0f);
        }
    }
Esempio n. 7
0
        /// <summary>
        /// 打印指定页面
        /// </summary>
        /// <param name="myPage">页面对象</param>
        /// <param name="g">绘图操作对象</param>
        /// <param name="MainClipRect">主剪切矩形</param>
        /// <param name="UseMargin">是否启用页边距</param>
        public override void DrawPage(
            PrintPage myPage,
            System.Drawing.Graphics g,
            System.Drawing.Rectangle MainClipRect,
            bool UseMargin)
        {
            //XPageSettings pageSettings = myPage.PageSettings;
            int LeftMargin   = 0;
            int TopMargin    = 0;
            int RightMargin  = 0;
            int BottomMargin = 0;

            if (UseMargin)
            {
                LeftMargin   = (int)myPage.ViewLeftMargin;
                TopMargin    = (int)myPage.ViewTopMargin;
                RightMargin  = (int)myPage.ViewRightMargin;
                BottomMargin = (int)myPage.ViewBottomMargin;
            }

            this.OnBeforeDrawPage(myPage, g);
            IntPtr          hdc = g.GetHdc();
            DeviceCapsClass dcc = new DeviceCapsClass(hdc);

            g.ReleaseHdc();

            DomDocument   document = (DomDocument)this.Document;
            XPageSettings ps       = myPage.PageSettings;

            if (ps == null)
            {
                ps = document.PageSettings;
            }
            g.PageUnit = document.DocumentGraphicsUnit;
            System.Drawing.Rectangle ClipRect = System.Drawing.Rectangle.Empty;
            if (this.PageHeadText != null)
            {
                // 绘制标题文本
                g.DrawString(
                    this.PageHeadText,
                    System.Windows.Forms.Control.DefaultFont,
                    System.Drawing.Brushes.Red,
                    20,
                    20,
                    System.Drawing.StringFormat.GenericDefault);
            }
            float printableAreaOffsetX = (float)GraphicsUnitConvert.Convert(
                this.PrintableAreaOffset.X / 100.0,
                System.Drawing.GraphicsUnit.Inch,
                document.DocumentGraphicsUnit);
            float printableAreaOffsetY = (float)GraphicsUnitConvert.Convert(
                this.PrintableAreaOffset.Y / 100.0,
                System.Drawing.GraphicsUnit.Inch,
                document.DocumentGraphicsUnit);

            float headerHeight    = Math.Max(ps.ViewHeaderHeight, document.Header.Height);
            int   headerHeightFix = 0;

            if (document.Header.Height > ps.ViewHeaderHeight - 10)
            {
                headerHeightFix = ( int )(document.Header.Height - (ps.ViewHeaderHeight - 10));
            }
            if (this.DrawHead)
            {
                // 绘制页眉
                g.ResetTransform();
                g.ResetClip();
                ClipRect = new System.Drawing.Rectangle(
                    0,
                    0,
                    myPage.Width,
                    (int)headerHeight);

                g.ScaleTransform(this.XZoomRate, this.YZoomRate);
                g.TranslateTransform(
                    LeftMargin - printableAreaOffsetX,
                    ps.ViewHeaderDistance - printableAreaOffsetY);

                g.SetClip(new System.Drawing.Rectangle(
                              ClipRect.Left,
                              ClipRect.Top,
                              ClipRect.Width + 1,
                              ClipRect.Height + 1));

                PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs(
                    g,
                    ClipRect,
                    document,
                    myPage,
                    PageContentPartyStyle.Header);
                args.RenderMode    = ContentRenderMode.Print;
                args.ContentBounds = ClipRect;
                document.DrawContent(args);
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
                g.ResetClip();
                g.ResetTransform();
            }

            // 绘制页面正文
            ClipRect = new System.Drawing.Rectangle(
                0,
                myPage.Top,
                myPage.Width,
                myPage.Height);

            if (!MainClipRect.IsEmpty)
            {
                ClipRect = System.Drawing.Rectangle.Intersect(ClipRect, MainClipRect);
            }
            if (!ClipRect.IsEmpty)
            {
                g.ScaleTransform(this.XZoomRate, this.YZoomRate);
                g.TranslateTransform(
                    LeftMargin - printableAreaOffsetX,
                    TopMargin - myPage.Top + headerHeightFix - printableAreaOffsetY);

                //System.Drawing.Drawing2D.GraphicsPath clipPath = new System.Drawing.Drawing2D.GraphicsPath();
                //clipPath.AddRectangle( ClipRect );
                //g.SetClip( clipPath );

                //g.TranslateTransform( myPages.LeftMargin , myPages.TopMargin - myPage.Top + myPages.HeadHeight );

                System.Drawing.RectangleF rect = DrawerUtil.FixClipBounds(
                    g,
                    ClipRect.Left,
                    ClipRect.Top,
                    ClipRect.Width,
                    ClipRect.Height);

                rect.Offset(-4, -4);
                rect.Width  = rect.Width + 8;
                rect.Height = rect.Height + 8;
                g.SetClip(rect);

                //				System.Drawing.RectangleF rect2 = g.ClipBounds ;
                //				if( rect.Top < rect2.Top )
                //				{
                //					float dy = rect2.Top - rect.Top ;
                //					rect.Y = rect.Y - dy * 2 ;
                //					rect.Height = rect.Height + dy * 4 ;
                //				}
                //				g.SetClip( rect );

                PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs(
                    g,
                    ClipRect,
                    document,
                    myPage,
                    PageContentPartyStyle.Body);
                args.RenderMode    = ContentRenderMode.Print;
                args.ContentBounds = ClipRect;
                document.DrawContent(args);

                //myDocument.DrawDocument( g , ClipRect );
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
            }

            if (this.DrawFooter)
            {
                // 绘制页脚
                g.ResetClip();
                g.ResetTransform();
                int   documentHeight = myPage.DocumentHeight;
                float footerHeight   = Math.Max(document.Footer.Height, ps.ViewFooterHeight);
                ClipRect = new System.Drawing.Rectangle(
                    0,
                    0,
                    myPage.Width,
                    (int)footerHeight);
                int dy = 0;

                dy = (int)(myPage.ViewPaperHeight
                           - ps.ViewFooterDistance - document.Footer.Height);

                g.ScaleTransform(this.XZoomRate, this.YZoomRate);
                g.TranslateTransform(
                    LeftMargin - printableAreaOffsetX,
                    dy - printableAreaOffsetY);

                g.SetClip(new System.Drawing.Rectangle(
                              ClipRect.Left,
                              ClipRect.Top,
                              ClipRect.Width + 1,
                              ClipRect.Height + 1));

                PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs(
                    g,
                    ClipRect,
                    document,
                    myPage,
                    PageContentPartyStyle.Footer);
                args.RenderMode    = ContentRenderMode.Print;
                args.ContentBounds = ClipRect;
                document.DrawContent(args);
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
            } //if( this.bolDrawFooter )
        }     //public void DrawPage()
Esempio n. 8
0
    private void RenderCurve(SerializedPropertyX curveProperty, ConsiderationRenderData data)
    {
        ResponseCurve curve         = curveProperty.GetValue <ResponseCurve>();
        bool          updateTexture = false;
        Texture2D     graphTexture  = data.graphTexture;

        if (graphTexture == null)
        {
            data.graphTexture = new Texture2D(1, 1, TextureFormat.RGBA32, true);
        }
        EditorGUILayout.BeginHorizontal();
        data.isCurveShown = EditorGUILayout.Foldout(data.isCurveShown, "Curve(" + curve.curveType.ToString() + ")");
        if (!data.isCurveShown)
        {
            if (graphTexture.width != 64)
            {
                graphTexture.Resize(64, 32);

                Rect rect = new Rect()
                {
                    x      = 0,
                    y      = 0,
                    width  = graphTexture.width,
                    height = graphTexture.height
                };
                GraphHelper.DrawGraphLines(rect, graphTexture, (float input) => {
                    return(curve.Evaluate(input));
                });
                graphTexture.FlipVertically();
                graphTexture.Apply(true);
            }
            GUILayout.FlexibleSpace();
            GUIContent content = new GUIContent();
            content.text  = curve.DisplayString;
            content.image = graphTexture;
            GUIStyle style = new GUIStyle(GUI.skin.box);
            style.alignment = TextAnchor.MiddleLeft;
            GUILayout.Box(content, style);
        }

        EditorGUILayout.EndHorizontal();

        if (!data.isCurveShown)
        {
            return;
        }

        DrawerUtil.PushIndentLevel(1);

        EditorGUILayout.BeginHorizontal();
        {
            EditorGUI.BeginChangeCheck();
            GUILayout.BeginVertical(GUILayout.MaxWidth(400f));
            curve.curveType = (ResponseCurveType)EditorGUILayout.EnumPopup("Curve Type", curve.curveType);
            curve.slope     = EditorGUILayout.FloatField("Slope", curve.slope);
            curve.exp       = EditorGUILayout.FloatField("Exp", curve.exp);
            curve.vShift    = EditorGUILayout.FloatField("Vertical Shift", curve.vShift);
            curve.hShift    = EditorGUILayout.FloatField("Horizontal Shift", curve.hShift);
            curve.threshold = EditorGUILayout.FloatField("Threshold", curve.threshold);
            curve.invert    = EditorGUILayout.Toggle(new GUIContent("Inverted"), curve.invert);
            GUILayout.BeginHorizontal();
            GUILayout.Space(EditorGUIUtility.labelWidth);
            if (GUILayout.Button("Reset"))
            {
                curve.Reset();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            updateTexture = EditorGUI.EndChangeCheck();
        }
        //draw the graph
        {
            if (updateTexture || graphTexture.width != 512)
            {
                curveProperty.Update();
                graphTexture.Resize(512, (int)(8.75f * EditorGUIUtility.singleLineHeight));
                Rect rect = new Rect()
                {
                    x      = 0,
                    y      = 0,
                    width  = graphTexture.width,
                    height = graphTexture.height
                };
                GraphHelper.DrawGraphLines(rect, graphTexture, (float input) => {
                    return(curve.Evaluate(input));
                });
                graphTexture.FlipVertically();
                graphTexture.Apply(true);
            }
            DrawerUtil.DrawLayoutTexture(graphTexture);
        }

        EditorGUILayout.EndHorizontal();
        DrawerUtil.PopIndentLevel();
    }
Esempio n. 9
0
        /// <summary>
        /// 打印指定页面
        /// </summary>
        /// <param name="myPage">页面对象</param>
        /// <param name="g">绘图操作对象</param>
        /// <param name="MainClipRect">主剪切矩形</param>
        /// <param name="PrintHead">是否打印页眉</param>
        /// <param name="PrintTail">是否打印页脚</param>
        public virtual void DrawPage(
            PrintPage myPage,
            System.Drawing.Graphics g,
            System.Drawing.Rectangle MainClipRect,
            bool UseMargin)
        {
            int LeftMargin   = 0;
            int TopMargin    = 0;
            int RightMargin  = 0;
            int BottomMargin = 0;

            if (UseMargin)
            {
                LeftMargin   = myPages.LeftMargin;
                TopMargin    = myPages.TopMargin;
                RightMargin  = myPages.RightMargin;
                BottomMargin = myPages.BottomMargin;
            }

            this.OnBeforeDrawPage(myPage, g);

            g.PageUnit = myDocument.DocumentGraphicsUnit;
            System.Drawing.Rectangle ClipRect = System.Drawing.Rectangle.Empty;
            if (this.bolDrawHead)
            {
                if (myPages.HeadHeight > 0)
                {
                    g.ResetTransform();
                    g.ResetClip();

                    ClipRect = new System.Drawing.Rectangle(0, 0, myPage.Width, myPages.HeadHeight);
                    g.TranslateTransform(LeftMargin, TopMargin);

                    g.SetClip(new System.Drawing.Rectangle(
                                  ClipRect.Left,
                                  ClipRect.Top,
                                  ClipRect.Width + 1,
                                  ClipRect.Height + 1));

                    myDocument.DrawHead(g, ClipRect);
                    //DesignPaintEventArgs e = new DesignPaintEventArgs(g, ClipRect);
                    //myDocument.RefreshView(e);
                }
                g.ResetClip();
                g.ResetTransform();
            }

            ClipRect = new System.Drawing.Rectangle(
                0,
                myPages.Top,
                myPage.Width,
                myPages.Height);

            if (!MainClipRect.IsEmpty)
            {
                ClipRect = System.Drawing.Rectangle.Intersect(ClipRect, MainClipRect);
            }
            if (!ClipRect.IsEmpty)
            {
                g.TranslateTransform(
                    LeftMargin,
                    TopMargin - myPage.Top + myPages.HeadHeight);

                //System.Drawing.Drawing2D.GraphicsPath clipPath = new System.Drawing.Drawing2D.GraphicsPath();
                //clipPath.AddRectangle( ClipRect );
                //g.SetClip( clipPath );

                //g.TranslateTransform( myPages.LeftMargin , myPages.TopMargin - myPage.Top + myPages.HeadHeight );

                System.Drawing.RectangleF rect = DrawerUtil.FixClipBounds(
                    g,
                    ClipRect.Left,
                    ClipRect.Top,
                    ClipRect.Width,
                    ClipRect.Height);

                rect.Offset(-4, -4);
                //rect.Offset(-4, -100);
                rect.Width  = rect.Width + 8;
                rect.Height = rect.Height + 8;
                g.SetClip(rect);

//				System.Drawing.RectangleF rect2 = g.ClipBounds ;
//				if( rect.Top < rect2.Top )
//				{
//					float dy = rect2.Top - rect.Top ;
//					rect.Y = rect.Y - dy * 2 ;
//					rect.Height = rect.Height + dy * 4 ;
//				}
//				g.SetClip( rect );

                myDocument.DrawDocument(g, ClipRect);
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
            }

            if (this.bolDrawFooter)
            {
                if (myPages.FooterHeight > 0)
                {
                    g.ResetClip();
                    g.ResetTransform();

                    ClipRect = new System.Drawing.Rectangle(
                        0,
                        myPages.DocumentHeight - myPages.FooterHeight,
                        myPage.Width,
                        myPages.FooterHeight);

                    int dy = 0;
                    if (UseMargin)
                    {
                        dy = myPages.PaperHeight - myPages.BottomMargin - myPages.DocumentHeight;
                    }
                    else
                    {
                        dy = myPages.PaperHeight - myPages.BottomMargin - myPages.DocumentHeight - myPages.TopMargin;
                    }
                    g.TranslateTransform(
                        LeftMargin,
                        dy);

                    g.SetClip(new System.Drawing.Rectangle(
                                  ClipRect.Left,
                                  ClipRect.Top,
                                  ClipRect.Width + 1,
                                  ClipRect.Height + 1));

                    myDocument.DrawFooter(g, ClipRect);
                    //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                    //myDocument.RefreshView( e );
                }
            } //if( this.bolDrawFooter )
        }     //public void DrawPage()
Esempio n. 10
0
 public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
 {
     return(DrawerUtil.GetPropertyHeight(property, label));
 }
Esempio n. 11
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (graphTexture == null)
            {
                graphTexture = new Texture2D(1, 1, TextureFormat.RGBA32, true);
            }

            curve = SerializedPropertyUtil.GetTargetObjectOfProperty(property) as ResponseCurve ?? new ResponseCurve();
            GUIRect rect = new GUIRect(position);

            isCurveShown = curve.__editorOnlyFoldout__ = EditorGUI.Foldout(rect.GetFieldRect(), curve.__editorOnlyFoldout__, label.text);

            GUIStyle style = new GUIStyle(GUI.skin.box);

            if (!isCurveShown)
            {
                DrawGraph(64, 32);
                GUIContent content = new GUIContent();
                content.text    = curve.DisplayString;
                content.image   = graphTexture;
                style.alignment = TextAnchor.MiddleLeft;
                GUI.Box(rect.GetFieldRect(2), content, style);
                return;
            }

            GUIRect[] splits = rect.SplitHorizontal(0.5f);
            GUIRect   left   = splits[0];
            GUIRect   right  = splits[1];

            DrawGraph(right.GetRect().width, right.GetRect().height);

            GUIContent graphContent = new GUIContent();

            graphContent.image = graphTexture;
            GUI.Box(right.GetRect(), graphContent, style);
            float oldWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 100;

            DrawerUtil.PushIndentLevel(1);
            EditorGUI.BeginChangeCheck();
            {
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("curveType"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("slope"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("exp"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("vShift"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("hShift"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("threshold"));
                GUIRect   lineRect      = new GUIRect(left.GetFieldRect());
                GUIRect[] lineRectParts = lineRect.SplitHorizontal(0.5f);
                EditorGUI.PropertyField(lineRectParts[0].GetRect(), property.FindPropertyRelative("invert"));


                if (GUI.Button(lineRectParts[1].GetRect(), "Reset Curve"))
                {
                    property.FindPropertyRelative("curveType").intValue   = (int)ResponseCurveType.Polynomial;
                    property.FindPropertyRelative("slope").floatValue     = 1f;
                    property.FindPropertyRelative("exp").floatValue       = 1f;
                    property.FindPropertyRelative("vShift").floatValue    = 0f;
                    property.FindPropertyRelative("hShift").floatValue    = 0f;
                    property.FindPropertyRelative("threshold").floatValue = 0f;
                    property.FindPropertyRelative("invert").boolValue     = false;
                }
            }
            DrawerUtil.PopIndentLevel();
            EditorGUIUtility.labelWidth = oldWidth;
            if (EditorGUI.EndChangeCheck())
            {
                property.serializedObject.ApplyModifiedProperties();
            }
        }