コード例 #1
0
        private void MainEditor_EditorAdded(object sender, PropertyEditorEventArgs e)
        {
            // Make sure new editors start in the correct expand state
            GroupedPropertyEditor groupedEditor = e.Editor as GroupedPropertyEditor;

            if (groupedEditor != null)
            {
                groupedEditor.Expanded = this.gridExpandState.IsEditorExpanded(groupedEditor);
            }
        }
コード例 #2
0
        private void UpdateSelection(ObjectSelection sel, ObjectSelection.Category showCat)
        {
            this.selSchedMouse    = null;
            this.selSchedMouseCat = ObjectSelection.Category.None;
            this.displaySel       = sel;
            this.displayCat       = showCat;

            if (showCat == ObjectSelection.Category.None)
            {
                return;
            }
            this.gridExpandState.UpdateFrom(this.propertyGrid.MainEditor);

            // Selection update may change MainEditor, unsubscribe from events
            if (this.propertyGrid.MainEditor is GroupedPropertyEditor)
            {
                GroupedPropertyEditor groupedMainEditor = this.propertyGrid.MainEditor as GroupedPropertyEditor;
                groupedMainEditor.EditorAdded -= this.MainEditor_EditorAdded;
            }

            if ((showCat & ObjectSelection.Category.GameObjCmp) != ObjectSelection.Category.None)
            {
                this.displaySel = new ObjectSelection(sel.GameObjects.Union(sel.Components.GameObject()));
                this.displayCat = ObjectSelection.Category.GameObjCmp;
                this.propertyGrid.SelectObjects(this.displaySel, false);
            }
            else if ((showCat & ObjectSelection.Category.Resource) != ObjectSelection.Category.None)
            {
                this.displaySel = new ObjectSelection(sel.Resources);
                this.displayCat = ObjectSelection.Category.Resource;
                this.propertyGrid.SelectObjects(this.displaySel, this.displaySel.Resources.Any(r => r.IsDefaultContent));
            }
            else if ((showCat & ObjectSelection.Category.Other) != ObjectSelection.Category.None)
            {
                this.displaySel = new ObjectSelection(sel.OtherObjects);
                this.displayCat = ObjectSelection.Category.Other;
                this.propertyGrid.SelectObjects(this.displaySel, false);
            }

            if (this.propertyGrid.MainEditor is GroupedPropertyEditor)
            {
                GroupedPropertyEditor groupedMainEditor = this.propertyGrid.MainEditor as GroupedPropertyEditor;
                groupedMainEditor.EditorAdded += this.MainEditor_EditorAdded;
            }

            this.gridExpandState.ApplyTo(this.propertyGrid.MainEditor);
            this.buttonClone.Enabled = this.propertyGrid.Selection.Any();
        }
コード例 #3
0
        private void SetupChildEditors()
        {
            this.BeginUpdate();

            // Remove the old Resource editor if it doesn't match
            if (this.resourceEditor != null && this.resourceType != this.EditedType)
            {
                this.DisposeResourceEditor();
            }

            // Add a new Resource editor if we don't have one yet
            if (this.resourceEditor == null)
            {
                this.resourceType          = this.EditedType;
                this.resourceEditor        = this.ParentGrid.CreateEditor(this.EditedType, this);
                this.resourceEditor.Getter = this.GetValue;
                this.resourceEditor.Setter = v => {};
                this.ParentGrid.ConfigureEditor(this.resourceEditor);
                this.AddPropertyEditor(this.resourceEditor);

                // If the child editor is a grouped one, expand it immediately after adding
                // and hide the expand / collapse checkbox. We don't want to expose our wrapper
                // structure after all.
                GroupedPropertyEditor group = this.resourceEditor as GroupedPropertyEditor;
                if (group != null)
                {
                    group.Expanded = true;
                    group.Hints   &= ~HintFlags.HasExpandCheck;
                }
            }

            // Set up a shared Asset editor that will be added or removed on demand
            if (this.assetEditor == null)
            {
                this.assetEditor            = new ResourceAssetPropertyEditor();
                this.assetEditor.EditedType = this.EditedType;                 // Needs to match so the forwarded getter's safety check passes
                this.assetEditor.Getter     = this.GetValue;
                this.assetEditor.Setter     = v => {};
                this.ParentGrid.ConfigureEditor(this.assetEditor);
            }

            this.EndUpdate();
        }
コード例 #4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Color headerBgColorUpper = ControlRenderer.ColorBackground;
            Color headerBgColorLower = headerBgColorUpper.ScaleBrightness(0.95f);

            GroupedPropertyEditor.DrawGroupHeaderBackground(e.Graphics, this.rectHeader, headerBgColorUpper, GroupedPropertyEditor.GroupHeaderStyle.Emboss);
            GroupedPropertyEditor.DrawGroupHeaderBackground(e.Graphics, this.rectPrefab, headerBgColorLower, GroupedPropertyEditor.GroupHeaderStyle.SmoothSunken);
            if (this.Focused)
            {
                ControlRenderer.DrawBorder(e.Graphics, this.ClientRectangle, AdamsLair.WinForms.Drawing.BorderStyle.Simple, BorderState.Normal);
            }

            CheckBoxState activeState = CheckBoxState.UncheckedDisabled;

            if (!this.ReadOnly && this.Enabled)
            {
                if (!this.active.HasValue)
                {
                    if (this.activeCheckPressed)
                    {
                        activeState = CheckBoxState.MixedPressed;
                    }
                    else if (this.activeCheckHovered)
                    {
                        activeState = CheckBoxState.MixedHot;
                    }
                    else
                    {
                        activeState = CheckBoxState.MixedNormal;
                    }
                }
                else if (this.active.Value)
                {
                    if (this.activeCheckPressed)
                    {
                        activeState = CheckBoxState.CheckedPressed;
                    }
                    else if (this.activeCheckHovered)
                    {
                        activeState = CheckBoxState.CheckedHot;
                    }
                    else
                    {
                        activeState = CheckBoxState.CheckedNormal;
                    }
                }
                else
                {
                    if (this.activeCheckPressed)
                    {
                        activeState = CheckBoxState.UncheckedPressed;
                    }
                    else if (this.activeCheckHovered)
                    {
                        activeState = CheckBoxState.UncheckedHot;
                    }
                    else
                    {
                        activeState = CheckBoxState.UncheckedNormal;
                    }
                }
            }
            else
            {
                if (!this.active.HasValue)
                {
                    activeState = CheckBoxState.MixedDisabled;
                }
                else if (this.active.Value)
                {
                    activeState = CheckBoxState.CheckedDisabled;
                }
                else
                {
                    activeState = CheckBoxState.UncheckedDisabled;
                }
            }
            ControlRenderer.DrawCheckBox(e.Graphics, this.rectCheckActive.Location, activeState);

            Region[] nameLabelRegion = ControlRenderer.MeasureStringLine(e.Graphics, this.displayedName, new[] { new CharacterRange(0, this.displayedName.Length) }, headerNameFont, this.rectLabelName);
            ControlRenderer.DrawStringLine(e.Graphics, this.displayedName, headerNameFont, this.rectLabelName, SystemColors.ControlText);

            if (nameLabelRegion.Length > 0)
            {
                SizeF     nameLabelSize = nameLabelRegion[0].GetBounds(e.Graphics).Size;
                Rectangle extLabelRect  = new Rectangle(
                    this.rectLabelName.X + (int)nameLabelSize.Width,
                    this.rectLabelName.Y,
                    this.rectLabelName.Width - (int)nameLabelSize.Width,
                    this.rectLabelName.Height);
                ControlRenderer.DrawStringLine(e.Graphics, this.displayedNameExt, headerNameExtFont, extLabelRect, SystemColors.ControlText);
            }

            ButtonState buttonStateAdd        = ButtonState.Normal;
            ButtonState buttonStateDefaultAdd = ButtonState.Normal;

            if (this.curButtonPressed)
            {
                buttonStateAdd = ButtonState.Pressed;
            }
            else if (this.curButtonHovered)
            {
                buttonStateAdd = ButtonState.Hot;
            }
            ControlRenderer.DrawButton(e.Graphics, this.rectButtonAddComponent, this.curButton == 4 ? buttonStateAdd : buttonStateDefaultAdd, "+");

            ControlRenderer.DrawStringLine(e.Graphics, "PrefabLink", headerPrefabFont, this.rectLabelPrefab, !this.prefabLinked ? SystemColors.GrayText : (this.prefabLinkAvailable ? Color.Blue : Color.DarkRed));

            ButtonState buttonState             = ButtonState.Disabled;
            ButtonState buttonStateDefault      = ButtonState.Disabled;
            ButtonState buttonStateDefaultBreak = ButtonState.Disabled;

            if (!this.ReadOnly && this.Enabled && this.prefabLinked)
            {
                if (this.prefabLinkAvailable)
                {
                    buttonState        = ButtonState.Normal;
                    buttonStateDefault = ButtonState.Normal;
                }
                buttonStateDefaultBreak = ButtonState.Normal;
            }

            if (this.curButtonPressed)
            {
                buttonState = ButtonState.Pressed;
            }
            else if (this.curButtonHovered)
            {
                buttonState = ButtonState.Hot;
            }

            ControlRenderer.DrawButton(e.Graphics, this.rectButtonPrefabShow, this.curButton == 0 ? buttonState : buttonStateDefault, "Show");
            ControlRenderer.DrawButton(e.Graphics, this.rectButtonPrefabRevert, this.curButton == 1 ? buttonState : buttonStateDefault, "Revert");
            ControlRenderer.DrawButton(e.Graphics, this.rectButtonPrefabApply, this.curButton == 2 ? buttonState : buttonStateDefault, "Apply");
            ControlRenderer.DrawButton(e.Graphics, this.rectButtonPrefabBreak, this.curButton == 3 ? buttonState : buttonStateDefaultBreak, "Break");
        }
コード例 #5
0
        protected PropertyEditor CreateUniformEditor(ShaderFieldInfo field)
        {
            PropertyEditor editor            = null;
            bool           mainEditorIsArray = false;

            if (field.ArrayLength == 1)
            {
                if (field.EditorTypeTag == "ColorRgba")
                {
                    editor        = this.ParentGrid.CreateEditor(typeof(ColorRgba), this);
                    editor.Getter = this.CreateUniformValueGetter <ColorRgba>(field.Name);
                    editor.Setter = !this.ReadOnly ? this.CreateUniformValueSetter <ColorRgba>(field.Name) : null;
                }
                else if (field.EditorTypeTag == "ColorHsva")
                {
                    editor        = this.ParentGrid.CreateEditor(typeof(ColorHsva), this);
                    editor.Getter = this.CreateUniformValueGetter <ColorHsva>(field.Name);
                    editor.Setter = !this.ReadOnly ? this.CreateUniformValueSetter <ColorHsva>(field.Name) : null;
                }
                else if (field.Type == ShaderFieldType.Float || field.Type == ShaderFieldType.Int)
                {
                    Type editType = typeof(float);
                    if (field.Type == ShaderFieldType.Int)
                    {
                        editType = typeof(int);
                    }

                    editor = this.ParentGrid.CreateEditor(editType, this);
                    if (field.Type == ShaderFieldType.Int)
                    {
                        editor.Getter = this.CreateUniformValueGetter <int>(field.Name);
                        editor.Setter = !this.ReadOnly ? this.CreateUniformValueSetter <int>(field.Name) : null;
                    }
                    else
                    {
                        editor.Getter = this.CreateUniformValueGetter <float>(field.Name);
                        editor.Setter = !this.ReadOnly ? this.CreateUniformValueSetter <float>(field.Name) : null;
                    }
                }
                else if (field.Type == ShaderFieldType.Vec2)
                {
                    editor        = this.ParentGrid.CreateEditor(typeof(Vector2), this);
                    editor.Getter = this.CreateUniformValueGetter <Vector2>(field.Name);
                    editor.Setter = !this.ReadOnly ? this.CreateUniformValueSetter <Vector2>(field.Name) : null;
                }
                else if (field.Type == ShaderFieldType.Vec3)
                {
                    editor        = this.ParentGrid.CreateEditor(typeof(Vector3), this);
                    editor.Getter = this.CreateUniformValueGetter <Vector3>(field.Name);
                    editor.Setter = !this.ReadOnly ? this.CreateUniformValueSetter <Vector3>(field.Name) : null;
                }
                else if (field.Type == ShaderFieldType.Vec4)
                {
                    editor        = this.ParentGrid.CreateEditor(typeof(Vector4), this);
                    editor.Getter = this.CreateUniformValueGetter <Vector4>(field.Name);
                    editor.Setter = !this.ReadOnly ? this.CreateUniformValueSetter <Vector4>(field.Name) : null;
                }
                else
                {
                    editor            = this.ParentGrid.CreateEditor(typeof(float[]), this);
                    editor.Getter     = this.CreateUniformArrayValueGetter <float>(field.Name);
                    editor.Setter     = !this.ReadOnly ? this.CreateUniformArrayValueSetter <float>(field.Name) : null;
                    mainEditorIsArray = true;
                }
            }
            else
            {
                mainEditorIsArray = true;
                if (field.EditorTypeTag == "ColorRgba")
                {
                    editor                = this.ParentGrid.CreateEditor(typeof(ColorRgba[]), this);
                    editor.Getter         = this.CreateUniformArrayValueGetter <ColorRgba>(field.Name);
                    editor.Setter         = !this.ReadOnly ? this.CreateUniformArrayValueSetter <ColorRgba>(field.Name) : null;
                    editor.ForceWriteBack = true;
                }
                else if (field.EditorTypeTag == "ColorHsva")
                {
                    editor                = this.ParentGrid.CreateEditor(typeof(ColorHsva[]), this);
                    editor.Getter         = this.CreateUniformArrayValueGetter <ColorHsva>(field.Name);
                    editor.Setter         = !this.ReadOnly ? this.CreateUniformArrayValueSetter <ColorHsva>(field.Name) : null;
                    editor.ForceWriteBack = true;
                }
                else if (field.Type == ShaderFieldType.Float || field.Type == ShaderFieldType.Int)
                {
                    Type editType = typeof(float);
                    if (field.Type == ShaderFieldType.Int)
                    {
                        editType = typeof(int);
                    }

                    editor                = this.ParentGrid.CreateEditor(editType.MakeArrayType(), this);
                    editor.Getter         = this.CreateUniformArrayValueGetter <float>(field.Name);
                    editor.Setter         = !this.ReadOnly ? this.CreateUniformArrayValueSetter <float>(field.Name) : null;
                    editor.ForceWriteBack = true;
                }
                else if (field.Type == ShaderFieldType.Vec2)
                {
                    editor                = this.ParentGrid.CreateEditor(typeof(Vector2[]), this);
                    editor.Getter         = this.CreateUniformArrayValueGetter <Vector2>(field.Name);
                    editor.Setter         = !this.ReadOnly ? this.CreateUniformArrayValueSetter <Vector2>(field.Name) : null;
                    editor.ForceWriteBack = true;
                }
                else if (field.Type == ShaderFieldType.Vec3)
                {
                    editor                = this.ParentGrid.CreateEditor(typeof(Vector3[]), this);
                    editor.Getter         = this.CreateUniformArrayValueGetter <Vector3>(field.Name);
                    editor.Setter         = !this.ReadOnly ? this.CreateUniformArrayValueSetter <Vector3>(field.Name) : null;
                    editor.ForceWriteBack = true;
                }
                else if (field.Type == ShaderFieldType.Vec4)
                {
                    editor                = this.ParentGrid.CreateEditor(typeof(Vector4[]), this);
                    editor.Getter         = this.CreateUniformArrayValueGetter <Vector4>(field.Name);
                    editor.Setter         = !this.ReadOnly ? this.CreateUniformArrayValueSetter <Vector4>(field.Name) : null;
                    editor.ForceWriteBack = true;
                }
                else
                {
                    editor        = this.ParentGrid.CreateEditor(typeof(float[]), this);
                    editor.Getter = this.CreateUniformArrayValueGetter <float>(field.Name);
                    editor.Setter = !this.ReadOnly ? this.CreateUniformArrayValueSetter <float>(field.Name) : null;
                }
            }

            List <EditorHintAttribute> configData = new List <EditorHintAttribute>();

            if (mainEditorIsArray)
            {
                GroupedPropertyEditor groupedMainEditor = editor as GroupedPropertyEditor;
                if (groupedMainEditor != null)
                {
                    groupedMainEditor.EditorAdded += this.UniformList_EditorAdded;
                }
            }
            else
            {
                this.PrepareEditorConfigData(field, configData);
            }

            editor.PropertyName = field.Name;
            editor.PropertyDesc = field.Description;
            this.ParentGrid.ConfigureEditor(editor, configData);
            return(editor);
        }
コード例 #6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Rectangle rectImage     = new Rectangle(this.rectPreview.X + 1, this.rectPreview.Y + 1, this.rectPreview.Width - 2, this.rectPreview.Height - 2);
            Color     brightChecker = this.prevImageLum > 0.5f ? Color.FromArgb(48, 48, 48) : Color.FromArgb(224, 224, 224);
            Color     darkChecker   = this.prevImageLum > 0.5f ? Color.FromArgb(32, 32, 32) : Color.FromArgb(192, 192, 192);
            Bitmap    img           = this.GetPreviewFrame((int)this.subImageSelector.Value);

            e.Graphics.FillRectangle(new HatchBrush(HatchStyle.LargeCheckerBoard, brightChecker, darkChecker), rectImage);
            if (img != null)
            {
                Size  imgSize        = img.Size;
                float widthForHeight = (float)imgSize.Width / (float)imgSize.Height;
                if (widthForHeight * (imgSize.Height - rectImage.Height) > imgSize.Width - rectImage.Width)
                {
                    imgSize.Height = Math.Min(rectImage.Height, imgSize.Height);
                    imgSize.Width  = MathF.RoundToInt(widthForHeight * imgSize.Height);
                }
                else
                {
                    imgSize.Width  = Math.Min(rectImage.Width, imgSize.Width);
                    imgSize.Height = MathF.RoundToInt(imgSize.Width / widthForHeight);
                }
                e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                e.Graphics.DrawImage(img,
                                     rectImage.X + rectImage.Width / 2 - imgSize.Width / 2,
                                     rectImage.Y + rectImage.Height / 2 - imgSize.Height / 2,
                                     imgSize.Width,
                                     imgSize.Height);
                e.Graphics.InterpolationMode = InterpolationMode.Default;
            }

            ControlRenderer.DrawBorder(e.Graphics,
                                       this.rectPreview,
                                       BorderStyle.Simple,
                                       !this.Enabled ? BorderState.Disabled : BorderState.Normal);

            bool  focusBg       = this.Focused || (this is IPopupControlHost && (this as IPopupControlHost).IsDropDownOpened);
            Color headerBgColor = this.ControlRenderer.ColorBackground;

            if (focusBg)
            {
                headerBgColor = headerBgColor.ScaleBrightness(this.ControlRenderer.FocusBrightnessScale);
            }
            GroupedPropertyEditor.DrawGroupHeaderBackground(
                e.Graphics,
                this.rectHeader,
                headerBgColor,
                GroupedPropertyEditor.GroupHeaderStyle.SmoothSunken);

            if (this.subImageSelector.Rect.Width > 0)
            {
                this.ControlRenderer.DrawStringLine(e.Graphics,
                                                    "Frame Index",
                                                    SystemFonts.DefaultFont,
                                                    this.rectLabelName,
                                                    !this.Enabled ? this.ControlRenderer.ColorGrayText : this.ControlRenderer.ColorText,
                                                    StringAlignment.Far);
                this.subImageSelector.OnPaint(e, this.Enabled && !this.subImageSelector.ReadOnly, false);
            }
        }