コード例 #1
0
 /// <summary>
 /// Add a tooltip for a widget if a PropertyPropertiesAttribute is set.
 /// </summary>
 /// <param name="propertyProperties">Attribute with tooltip</param>
 /// <param name="widget">Widget to add tooltip to.</param>
 private void AddTooltip(PropertyPropertiesAttribute propertyProperties, Gtk.Widget widget)
 {
     if ((propertyProperties != null) && (propertyProperties.Tooltip.Length != 0))
     {
         widget.TooltipText = propertyProperties.Tooltip;
     }
 }
コード例 #2
0
 /// <summary>
 /// Add a tooltip for a widget if a PropertyPropertiesAttribute is set.
 /// </summary>
 /// <param name="propertyProperties">Attribute with tooltip</param>
 /// <param name="widget">Widget to add tooltip to.</param>
 private void AddTooltip(PropertyPropertiesAttribute propertyProperties, Widget widget)
 {
     if ((propertyProperties != null) && (propertyProperties.Tooltip.Length != 0))
     {
         tooltips.SetTip(widget, propertyProperties.Tooltip, propertyProperties.Tooltip);
     }
 }
コード例 #3
0
    /// <summary> Moves any ILayer from layer to layer when ZPos is changed. </summary>
    private void OnFieldChanged(object Object, FieldOrProperty field, object oldValue)
    {
        if (!(Object is IGameObject && sector.Contains((IGameObject)Object)))           //return, if it's not (GameObject in our sector)
        {
            return;
        }

        if (Object is IDrawableLayer && field.Name == "Layer")           //filter for ILayer.Layer
        {
            Layer     layer    = (Layer)SceneGraphRoot;
            ILayer    ILayer   = (ILayer)Object;
            ColorNode color    = colors[ILayer];
            int       oldLayer = (int)oldValue;

            layer.Remove(oldLayer, color);
            layer.Add(ILayer.Layer, color);

            QueueDraw();
        }

        PropertyPropertiesAttribute propertyProperties = (PropertyPropertiesAttribute)
                                                         field.GetCustomAttribute(typeof(PropertyPropertiesAttribute));

        if (propertyProperties != null && propertyProperties.RedrawOnChange)            //Every property that affects appearance is marked using this attribute
        {
            QueueDraw();
        }
    }
コード例 #4
0
    /// <summary> Static member accesible for other ICustomSettingsWidgets. </summary>
    public static void CreateToolTip(object caller, Widget widget, FieldOrProperty field)
    {
        // Create a tooltip if we can.
        PropertyPropertiesAttribute propertyProperties = (PropertyPropertiesAttribute)
                                                         field.GetCustomAttribute(typeof(PropertyPropertiesAttribute));

        if ((propertyProperties != null) && (caller.GetType() == typeof(PropertiesView)))
        {
            PropertiesView propview = (PropertiesView)caller;
            propview.tooltips.SetTip(widget, propertyProperties.Tooltip, propertyProperties.Tooltip);
        }
    }
コード例 #5
0
    private void CreatePropertyWidgets(string title, object NewObject)
    {
        //NOTE: we need to remove all the old widgets before we empty the widget and field tables, because the
        //      focus out event handlers which may be called during this step need them.
        Foreach(Remove);

        Gtk.VBox box = new Gtk.VBox();

        titleLabel        = new Gtk.Label();
        titleLabel.Xalign = 0;
        titleLabel.Xpad   = 12;
        titleLabel.Ypad   = 6;
        titleLabel.Markup = "<b>" + title + "</b>";
        box.PackStart(titleLabel, true, false, 0);

        Type type = NewObject.GetType();

        // Dispose all former custom editor widgets
        foreach (IDisposable disposable in customWidgets)
        {
            disposable.Dispose();
        }

        // Unregister our event handler from self-managed fields
        foreach (FieldOrProperty field in fieldTable)
        {
            field.Changed -= OnFieldChanged;
        }

        widgetTable.Clear();
        fieldTable.Clear();
        editWidgets.Clear();
        customWidgets.Clear();

        // iterate over all fields and properties
        foreach (FieldOrProperty field in FieldOrProperty.GetFieldsAndProperties(type))
        {
            CustomSettingsWidgetAttribute customSettings = (CustomSettingsWidgetAttribute)
                                                           field.GetCustomAttribute(typeof(CustomSettingsWidgetAttribute));
            if (customSettings != null)
            {
                Type customType = customSettings.Type;
                ICustomSettingsWidget customWidget = (ICustomSettingsWidget)CreateObject(customType);
                customWidgets.Add(customWidget);
                editWidgets.Add(customWidget.Create(this, NewObject, field));
                continue;
            }

            LispChildAttribute ChildAttrib = (LispChildAttribute)
                                             field.GetCustomAttribute(typeof(LispChildAttribute));
            if (ChildAttrib == null)
            {
                continue;
            }

            PropertyPropertiesAttribute propertyProperties = (PropertyPropertiesAttribute)
                                                             field.GetCustomAttribute(typeof(PropertyPropertiesAttribute));

            if ((propertyProperties != null) && (propertyProperties.Hidden))
            {
                continue;
            }

            if (field.Type == typeof(string) || field.Type == typeof(float) ||
                field.Type == typeof(int))
            {
                Gtk.Entry entry = new Gtk.Entry();
                entry.Name = field.Name;
                object val = field.GetValue(NewObject);
                if (val != null)
                {
                    entry.Text = val.ToString();
                }
                widgetTable.Add(entry);
                fieldTable.Add(field);
                entry.Changed       += OnEntryChanged;
                entry.FocusOutEvent += OnEntryChangeDone;
                editWidgets.Add(entry);
                AddTooltip(propertyProperties, entry);
            }
            else if (field.Type == typeof(bool))
            {
                Gtk.CheckButton checkButton = new Gtk.CheckButton(field.Name);
                checkButton.Name   = field.Name;
                checkButton.Active = (bool)field.GetValue(NewObject);
                widgetTable.Add(checkButton);
                fieldTable.Add(field);
                checkButton.Toggled += OnCheckButtonToggled;
                editWidgets.Add(checkButton);
                AddTooltip(propertyProperties, checkButton);
            }
            else if (field.Type.IsEnum)
            {
                // Create a combobox containing all the names of enum values.
                Gtk.ComboBox comboBox = new Gtk.ComboBox(Enum.GetNames(field.Type));
                // Set the name of the box.
                comboBox.Name = field.Name;
                // FIXME: This will break if:
                //        1) the first enum isn't 0 and/or
                //        2) the vaules are not sequential (0, 1, 3, 4 wouldn't work)
                object val = field.GetValue(NewObject);
                if (val != null)
                {
                    comboBox.Active = (int)val;
                }
                widgetTable.Add(comboBox);
                fieldTable.Add(field);
                comboBox.Changed += OnComboBoxChanged;
                editWidgets.Add(comboBox);
                AddTooltip(propertyProperties, comboBox);
            }
        }

        // Register our event handler for self-managed fields
        foreach (FieldOrProperty field in fieldTable)
        {
            field.Changed += OnFieldChanged;
        }

        Gtk.Table table = new Gtk.Table((uint)editWidgets.Count, 2, false);
        table.ColumnSpacing = 6;
        table.RowSpacing    = 6;
        table.BorderWidth   = 12;
        for (uint i = 0; i < editWidgets.Count; ++i)
        {
            Gtk.Widget widget = editWidgets[(int)i];
            if (widget is Gtk.CheckButton)
            {
                table.Attach(widget, 0, 2, i, i + 1,
                             Gtk.AttachOptions.Fill | Gtk.AttachOptions.Expand, Gtk.AttachOptions.Shrink, 0, 0);
            }
            else
            {
                Gtk.Label label = new Gtk.Label(widget.Name + ":");
                label.SetAlignment(0, 1);
                table.Attach(label, 0, 1, i, i + 1,
                             Gtk.AttachOptions.Fill, Gtk.AttachOptions.Shrink, 0, 0);
                table.Attach(widget, 1, 2, i, i + 1,
                             Gtk.AttachOptions.Fill | Gtk.AttachOptions.Expand, Gtk.AttachOptions.Shrink, 0, 0);
            }
        }
        box.PackStart(table, true, true, 0);

        // TODO add a (!) image in front of the label (and hide/show it depending
        // if there was an error)
        errorLabel        = new Gtk.Label(String.Empty);
        errorLabel.Xalign = 0;
        errorLabel.Xpad   = 12;
        box.PackStart(errorLabel, true, false, 0);

        box.ShowAll();

        AddWithViewport(box);
    }
コード例 #6
0
 /// <summary>
 /// Add a tooltip for a widget if a PropertyPropertiesAttribute is set.
 /// </summary>
 /// <param name="propertyProperties">Attribute with tooltip</param>
 /// <param name="widget">Widget to add tooltip to.</param>
 private void AddTooltip(PropertyPropertiesAttribute propertyProperties, Widget widget)
 {
     if ((propertyProperties != null) && (propertyProperties.Tooltip.Length != 0))
         tooltips.SetTip(widget, propertyProperties.Tooltip, propertyProperties.Tooltip);
 }