public static Gtk.Window Create ()
		{
			HBox options = new HBox (false, 0);
			CheckButton check_button = null;

			window = new ColorSelectionDialog ("Color selection dialog");
			window.ColorSelection.HasOpacityControl = true;
			window.ColorSelection.HasPalette = true;

			window.SetDefaultSize (250, 200);
			window.VBox.PackStart (options, false, false, 0);
			window.VBox.BorderWidth = 10;

			check_button = new CheckButton("Show Opacity");
			check_button.Active = true;
			options.PackStart (check_button, false, false, 0);
			check_button.Toggled += new EventHandler (Opacity_Callback);

			check_button = new CheckButton("Show Palette");
			check_button.Active = true;
			options.PackEnd (check_button, false, false, 0);
			check_button.Toggled += new EventHandler (Palette_Callback);

			window.ColorSelection.ColorChanged += new EventHandler (Color_Changed);
			window.OkButton.Clicked += new EventHandler (Color_Selection_OK);
			window.CancelButton.Clicked += new EventHandler (Color_Selection_Cancel); 

			options.ShowAll ();

			return window;
		}
Exemple #2
0
    public static OSMP.Color GetColor()
    {
        ColorSelectionDialog colorselectiondialog = new ColorSelectionDialog( "Choose color:" );
            ResponseType response = (ResponseType)colorselectiondialog.Run();
            //colorselectiondialog.

            OSMP.Color newcolor = null;
            if (response == ResponseType.Ok)
            {
                LogFile.WriteLine( colorselectiondialog );
                LogFile.WriteLine( colorselectiondialog.ColorSelection );
                LogFile.WriteLine( colorselectiondialog.ColorSelection.CurrentColor.Red.ToString() + " " +
                colorselectiondialog.ColorSelection.CurrentColor.Green.ToString() + " " +
                    colorselectiondialog.ColorSelection.CurrentColor.Blue.ToString() );
                Gdk.Color newgtkcolor = colorselectiondialog.ColorSelection.CurrentColor;
                newcolor = new OSMP.Color( newgtkcolor.Red / (double)65536,
                    newgtkcolor.Green / (double)65536,
                    newgtkcolor.Blue / (double)65536 );
            }
            else
            {
                LogFile.WriteLine( "cancel pressed" );
            }

            colorselectiondialog.Hide();
            return newcolor;
    }
Exemple #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();
        }
        public void OpenDialog(Color color)
        {
            selectedColor = color;

            dialog = new ColorSelectionDialog("Choose Color");
            dialog.ColorSelection.CurrentColor = Utils.ToColor(color);
            dialog.Response += DialogResponse;
            dialog.Run();
        }
		private void ChangeColorCallback (object o, EventArgs args)
		{
			using (ColorSelectionDialog colorSelectionDialog = new ColorSelectionDialog ("Changing color")) {
				colorSelectionDialog.TransientFor = this;
				colorSelectionDialog.ColorSelection.PreviousColor = color;
				colorSelectionDialog.ColorSelection.CurrentColor = color;
				colorSelectionDialog.ColorSelection.HasPalette = true;

				if (colorSelectionDialog.Run () == (int) ResponseType.Ok) {
					Gdk.Color selected = colorSelectionDialog.ColorSelection.CurrentColor;
					drawingArea.ModifyBg (StateType.Normal, selected);
				}

				colorSelectionDialog.Hide ();
			}
		}
		private void ChangeColorCallback (object o, EventArgs args)
		{
			using (ColorSelectionDialog colorSelectionDialog = new ColorSelectionDialog ("Changing color")) {
				colorSelectionDialog.TransientFor = this;
				colorSelectionDialog.ColorSelection.SetPreviousRgba (color);
				colorSelectionDialog.ColorSelection.CurrentRgba = color;
				colorSelectionDialog.ColorSelection.HasPalette = true;

				if (colorSelectionDialog.Run () == (int) ResponseType.Ok) {
					color = colorSelectionDialog.ColorSelection.CurrentRgba;
					drawingArea.OverrideBackgroundColor (StateFlags.Normal, color);
				}

				colorSelectionDialog.Hide ();
			}
		}
        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();
        }
        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 ();
        }
Exemple #9
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;
        }
    public void MoreColorsActivated(object o, EventArgs ev)
    {
        ColorSelectionDialog colorSel =
            new ColorSelectionDialog("Select Color");

        if(IconWidget is ColorBlockWidget) {
            colorSel.ColorSelection.CurrentColor =
                (IconWidget as ColorBlockWidget).Color;
        }

        // TODO: Add support for opacity as Handwriting supports this
        colorSel.ColorSelection.HasOpacityControl = false;
        colorSel.Response += CustomColorResponded;
        colorSel.Run();
    }
        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;
        }