예제 #1
0
        private void HandleColorPanelButtonPressEvent(object sender, ButtonPressEventArgs args)
        {
            if (args.Event.Type != Gdk.EventType.TwoButtonPress)
            {
                return;
            }

            Gtk.ColorSelectionDialog csd = new Gtk.ColorSelectionDialog("Choose Color");

            ColorPanelWidget panel = (ColorPanelWidget)sender;

            csd.ColorSelection.PreviousColor = panel.CairoColor.ToGdkColor();
            csd.ColorSelection.CurrentColor  = panel.CairoColor.ToGdkColor();
            csd.ColorSelection.CurrentAlpha  = panel.CairoColor.GdkColorAlpha();

            int response = csd.Run();

            if (response == (int)Gtk.ResponseType.Ok)
            {
                ColorBgra col = csd.ColorSelection.CurrentColor.ToBgraColor();

                if (panel == colorpanelInLow)
                {
                    Levels.ColorInLow = col;
                }
                else if (panel == colorpanelInHigh)
                {
                    Levels.ColorInHigh = col;
                }
                else if (panel == colorpanelOutLow)
                {
                    Levels.ColorOutLow = col;
//                } else if (panel == colorpanelOutMid) {
//                    ColorBgra lo = Levels.ColorInLow;
//                    ColorBgra md = histogramInput.Histogram.GetMeanColor();
//                    ColorBgra hi = Levels.ColorInHigh;
//                    ColorBgra out_lo = Levels.ColorOutLow;
//                    ColorBgra out_hi = Levels.ColorOutHigh;
//
//                    for (int i = 0; i < 3; i++) {
//                        double logA = (col[i] - out_lo[i]) / (out_hi[i] - out_lo[i]);
//                        double logBase = (md[i] - lo[i]) / (hi[i] - lo[i]);
//                        double logVal = (logBase == 1.0) ? 0.0 : Math.Log (logA, logBase);
//
//                        Levels.SetGamma(i, (float)Utility.Clamp (logVal, 0.1, 10.0));
//                    }
                }
                else if (panel == colorpanelOutHigh)
                {
                    Levels.ColorOutHigh = col;
                }
            }

            csd.Destroy();
            UpdateFromLevelsOp();
            UpdateLevels();
        }
예제 #2
0
        void HandleMenuitem2ButtonPressEvent(object o, ButtonPressEventArgs args)
        {
            //Gdk.Color color=new Gdk.Color();
            Gtk.ColorSelection selection;
            Console.Write("Menu Item 2");
            Gtk.ColorSelectionDialog dlg = new Gtk.ColorSelectionDialog("Select path color");

            Gtk.ResponseType result = (Gtk.ResponseType)dlg.Run();

            if (result == Gtk.ResponseType.Ok)
            {
                selection = dlg.ColorSelection;
                PathColor = selection.CurrentColor;
            }             //else Console.WriteLine("Cancelled");

            dlg.Destroy();
        }
예제 #3
0
        private void HandleColorPanelButtonPressEvent(object sender, ButtonPressEventArgs args)
        {
            if (args.Event.Type != Gdk.EventType.TwoButtonPress)
                return;

            Gtk.ColorSelectionDialog csd = new Gtk.ColorSelectionDialog ("Choose Color");

               		ColorPanelWidget panel = (ColorPanelWidget)sender;
            csd.ColorSelection.PreviousColor = panel.CairoColor.ToGdkColor ();
            csd.ColorSelection.CurrentColor = panel.CairoColor.ToGdkColor ();
            csd.ColorSelection.CurrentAlpha = panel.CairoColor.GdkColorAlpha ();

            int response = csd.Run ();

            if (response == (int)Gtk.ResponseType.Ok) {

                ColorBgra col = csd.ColorSelection.CurrentColor.ToBgraColor ();

                if (panel == colorpanelInLow)	{
                    Levels.ColorInLow = col;
                } else if (panel == colorpanelInHigh) {
                    Levels.ColorInHigh = col;
                } else if (panel == colorpanelOutLow) {
                    Levels.ColorOutLow = col;
            //                } else if (panel == colorpanelOutMid) {
            //                    ColorBgra lo = Levels.ColorInLow;
            //                    ColorBgra md = histogramInput.Histogram.GetMeanColor();
            //                    ColorBgra hi = Levels.ColorInHigh;
            //                    ColorBgra out_lo = Levels.ColorOutLow;
            //                    ColorBgra out_hi = Levels.ColorOutHigh;
            //
            //                    for (int i = 0; i < 3; i++) {
            //                        double logA = (col[i] - out_lo[i]) / (out_hi[i] - out_lo[i]);
            //                        double logBase = (md[i] - lo[i]) / (hi[i] - lo[i]);
            //                        double logVal = (logBase == 1.0) ? 0.0 : Math.Log (logA, logBase);
            //
            //                        Levels.SetGamma(i, (float)Utility.Clamp (logVal, 0.1, 10.0));
            //                    }
                } else if (panel == colorpanelOutHigh) {
                    Levels.ColorOutHigh = col;
                }
            }

            csd.Destroy ();
            UpdateFromLevelsOp ();
            UpdateLevels ();
        }
예제 #4
0
        public override void LaunchDialogue()
        {
            ColorSelectionDialog dialog = new ColorSelectionDialog ("Select a new color");
            dialog.ColorSelection.CurrentColor = GetColor ();
            dialog.Run ();
            dialog.Destroy ();

            int red = (int) (255 * (float) dialog.ColorSelection.CurrentColor.Red / ushort.MaxValue);
            int green = (int) (255 * (float) dialog.ColorSelection.CurrentColor.Green / ushort.MaxValue);
            int blue = (int) (255 * (float) dialog.ColorSelection.CurrentColor.Blue / ushort.MaxValue);

            System.Drawing.Color color = System.Drawing.Color.FromArgb (red, green, blue);
            //TODO: Property.Converter.ConvertFrom() fails: why?
            parentRow.PropertyValue = color;
        }
예제 #5
0
        public PropertyGridTable ()
        {
            Build();

            items = new List<TreeItem> ();
            pitems = new List<TreeItem> ();
            eitems = new List<EventItem> ();
            nulliter = new TreeIter ();
            sortgroup = true;

            var column1 = new TreeViewColumn ();
            column1.Sizing = TreeViewColumnSizing.Fixed;
            column1.FixedWidth = 100;
            column1.Resizable = true;
            column1.Title = "Name";

            var textCell1 = new CellRendererText ();
            textCell1.Underline = Pango.Underline.Single;
            column1.PackStart (textCell1, false);

            var textCell2 = new CellRendererText ();
            column1.PackStart (textCell2, false);

            var idCell = new CellRendererText ();
            idCell.Visible = false;
            column1.PackStart (idCell, false);

            treeview1.AppendColumn (column1);

            var column2 = new TreeViewColumn ();
            column2.Sizing = TreeViewColumnSizing.Fixed;
            column2.Resizable = true;
            column2.Title = "Value";

            var editTextCell = new CellRendererText ();

            editTextCell.Edited += delegate(object o, EditedArgs args) {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected (out model, out iter)) {

                    int id = Convert.ToInt32(model.GetValue(iter, 11));

                    for(int i = 0;i < eitems.Count;i++)
                    {
                        if(eitems[i].id == id)
                        {
                            if(eitems[i].eventHandler != null)
                            {
                                var fwidget = new FalseWidget(args.NewText);
                                eitems[i].eventHandler(fwidget, EventArgs.Empty);
                                model.SetValue(iter, 4, args.NewText);
                                break;
                            }
                        }
                    }
                }
            };

            column2.PackStart (editTextCell, false);

            var editTextCell2 = new CellRendererText ();
            editTextCell2.Editable = true;
            editTextCell2.EditingStarted += delegate {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected (out model, out iter)) {

                    var dialog = new CollectionEditorDialog(window, model.GetValue(iter, 14).ToString());
                    if(dialog.Run() == (int)ResponseType.Ok)
                    {
                        int id = Convert.ToInt32(model.GetValue(iter, 11));

                        for(int i = 0;i < eitems.Count;i++)
                        {
                            if(eitems[i].id == id)
                            {
                                if(eitems[i].eventHandler != null)
                                {
                                    var fwidget = new FalseWidget(dialog.text);
                                    eitems[i].eventHandler(fwidget, EventArgs.Empty);
                                    model.SetValue(iter, 14, dialog.text);
                                    break;
                                }
                            }
                        }
                    }
                }
            };
            column2.PackStart (editTextCell2, false);

            var editTextCell4 = new CellRendererText ();
            editTextCell4.Editable = true;
            editTextCell4.EditingStarted += delegate {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected (out model, out iter)) {
                    
                    var col = new Microsoft.Xna.Framework.Color ();
                    int response = (int)ResponseType.Reject;

                    if(Global.GtkMajorVersion < 3 || (Global.GtkMajorVersion == 3 && Global.GtkMinorVersion < 3))
                    {
                        var dialog = new ColorSelectionDialog("Color Chooser");
                        dialog.TransientFor = window;
                        dialog.ColorSelection.HasPalette = true;
                        dialog.ColorSelection.HasOpacityControl = true;

                        try
                        {
                            string[] cvalues = model.GetValue(iter, 15).ToString().Replace (":", " ").Replace("}", " ").Split (' ');

                            byte red = (byte)Convert.ToInt16 (cvalues [1]);
                            byte green = (byte)Convert.ToInt16 (cvalues [3]);
                            byte blue = (byte)Convert.ToInt16 (cvalues [5]);
                            int alpha = Convert.ToInt32(cvalues [7]);

                            dialog.ColorSelection.CurrentColor = new Gdk.Color (red, green, blue);
                            dialog.ColorSelection.CurrentAlpha = (ushort)(alpha * 257);
                        }
                        catch { }

                        response = dialog.Run();

                        col.R = (byte)Convert.ToInt32(dialog.ColorSelection.CurrentColor.Red);
                        col.G = (byte)Convert.ToInt32(dialog.ColorSelection.CurrentColor.Green);
                        col.B = (byte)Convert.ToInt32(dialog.ColorSelection.CurrentColor.Blue);
                        col.A = (byte)(dialog.ColorSelection.CurrentAlpha / 257);

                        dialog.Destroy();
                    }
                    else
                    {
                        #if LINUX
                        Gdk.RGBA rgba = new Gdk.RGBA();

                        try
                        {
                            string[] cvalues = model.GetValue(iter, 15).ToString().Replace (":", " ").Replace("}", " ").Split (' ');
                            rgba.Parse("rgba(" + cvalues [1] + "," + cvalues [3] + "," + cvalues [5] + "," + cvalues [7] + ")");
                        }
                        catch { }

                        var dialog = new ColorChooserDialog(window, "Color Chooser");
                        dialog.ColorChooser.CurrentRgba = rgba;
                        response = (int)dialog.Run();

                        rgba = dialog.ColorChooser.CurrentRgba;
                        dialog.Destroy();

                        string[] split = rgba.ToString().Split('(', ')')[1].Split(',');

                        col.R = (byte)Convert.ToInt32(split[0]);
                        col.G = (byte)Convert.ToInt32(split[1]);
                        col.B = (byte)Convert.ToInt32(split[2]);

                        if(split.Length == 4)
                            col.A = (byte)Convert.ToInt32(double.Parse(split[3]) * 255);
                        else
                            col.A = 255;
                        #endif
                    }

                    if(response == (int)ResponseType.Ok)
                    {
                        int id = Convert.ToInt32(model.GetValue(iter, 11));

                        for(int i = 0;i < eitems.Count;i++)
                        {
                            if(eitems[i].id == id)
                            {
                                if(eitems[i].eventHandler != null)
                                {
                                    var fwidget = new FalseWidget(col.ToString ());
                                    eitems[i].eventHandler(fwidget, EventArgs.Empty);
                                    model.SetValue(iter, 15, col.ToString ());
                                    break;
                                }
                            }
                        }
                    }
                }
            };
            column2.PackStart (editTextCell4, false);

            var editTextCell3 = new CellRendererText ();
            editTextCell3.Visible = false;
            column2.PackStart (editTextCell3, false);

            var comboCell = new CellRendererCombo ();
            comboCell.TextColumn = 0;
            comboCell.IsExpanded = true;
            comboCell.Editable = true;
            comboCell.HasEntry = false;
            comboCell.Edited += delegate(object o, EditedArgs args) {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected (out model, out iter)) {

                    int id = Convert.ToInt32(model.GetValue(iter, 11));

                    for(int i = 0;i < eitems.Count;i++)
                    {
                        if(eitems[i].id == id)
                        {
                            if(eitems[i].eventHandler != null && args.NewText != null && args.NewText != "")
                            {
                                var fwidget = new FalseWidget(args.NewText);
                                eitems[i].eventHandler(fwidget, EventArgs.Empty);
                                model.SetValue(iter, 8, args.NewText);
                                break;
                            }
                        }
                    }
                }
            };

            column2.PackStart (comboCell , false);

            var editFilePathCell = new CellRendererText();
            editFilePathCell.Editable = true;
            editFilePathCell.EditingStarted += delegate(object o, EditingStartedArgs args) {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected (out model, out iter)) {

                    var dialog = new CustomFolderDialog(window, model.GetValue(iter, 17).ToString());
                    var responseid = dialog.Run();
                    var fileName = dialog.FileName;
                    dialog.Destroy();

                    if(responseid != (int)ResponseType.Ok)
                        return;

                    int id = Convert.ToInt32(model.GetValue(iter, 11));

                    for(int i = 0;i < eitems.Count;i++)
                    {
                        if(eitems[i].id != id || eitems[i].eventHandler == null)
                            continue;

                        var fwidget = new FalseWidget(fileName);
                        eitems[i].eventHandler(fwidget, EventArgs.Empty);
                        model.SetValue(iter, 17, fileName);

                        break;
                    }
                }
            };
            column2.PackStart (editFilePathCell, false);

            treeview1.AppendColumn (column2);

            column1.AddAttribute (textCell1, "text", 0);
            column1.AddAttribute (textCell1, "visible", 1);
            column1.AddAttribute (textCell2, "text", 2);
            column1.AddAttribute (textCell2, "visible", 3);
            column2.AddAttribute (editTextCell, "text", 4);
            column2.AddAttribute (editTextCell, "visible", 5);
            column2.AddAttribute (editTextCell, "editable", 6);
            column2.AddAttribute (comboCell, "model", 7);
            column2.AddAttribute (comboCell, "text", 8);
            column2.AddAttribute (comboCell, "editable", 9);
            column2.AddAttribute (comboCell, "visible", 10);
            column1.AddAttribute (idCell, "text", 11);
            column2.AddAttribute (editTextCell2, "text", 12);
            column2.AddAttribute (editTextCell2, "visible", 13);
            column2.AddAttribute (editTextCell3, "text", 14);
            column2.AddAttribute (editTextCell4, "text", 15);
            column2.AddAttribute (editTextCell4, "visible", 16);
            column2.AddAttribute (editFilePathCell, "text", 17);
            column2.AddAttribute (editFilePathCell, "visible", 18);

            listStore = new TreeStore (typeof (string), typeof(bool), typeof (string), typeof(bool), typeof (string), typeof(bool), typeof(bool), typeof(TreeStore), typeof(string), typeof(bool), typeof(bool), typeof(string), typeof(string), typeof(bool), typeof(string), typeof(string), typeof(bool), typeof(string), typeof(bool));
            treeview1.Model = listStore;
        }