Pinta.ColorPaletteWidget.OnButtonPressEvent C# (CSharp) Method

OnButtonPressEvent() protected method

protected OnButtonPressEvent ( Gdk ev ) : bool
ev Gdk
return bool
        protected override bool OnButtonPressEvent(Gdk.EventButton ev)
        {
            if (swap_rect.ContainsPoint (ev.X, ev.Y)) {
                Color temp = PintaCore.Palette.PrimaryColor;
                PintaCore.Palette.PrimaryColor = PintaCore.Palette.SecondaryColor;
                PintaCore.Palette.SecondaryColor = temp;
                GdkWindow.Invalidate ();
            }

            if (primary_rect.ContainsPoint (ev.X, ev.Y)) {
                Gtk.ColorSelectionDialog csd = new Gtk.ColorSelectionDialog ("Choose Primary Color");
                csd.ColorSelection.PreviousColor = PintaCore.Palette.PrimaryColor.ToGdkColor ();
                csd.ColorSelection.CurrentColor = PintaCore.Palette.PrimaryColor.ToGdkColor ();
                csd.ColorSelection.CurrentAlpha = PintaCore.Palette.PrimaryColor.GdkColorAlpha ();
                csd.ColorSelection.HasOpacityControl = true;

                int response = csd.Run ();

                if (response == (int)Gtk.ResponseType.Ok) {
                    PintaCore.Palette.PrimaryColor = csd.ColorSelection.GetCairoColor ();
                }

                csd.Destroy ();
            } else if (secondary_rect.ContainsPoint (ev.X, ev.Y)) {
                Gtk.ColorSelectionDialog csd = new Gtk.ColorSelectionDialog ("Choose Secondary Color");
                csd.ColorSelection.PreviousColor = PintaCore.Palette.SecondaryColor.ToGdkColor ();
                csd.ColorSelection.CurrentColor = PintaCore.Palette.SecondaryColor.ToGdkColor ();
                csd.ColorSelection.CurrentAlpha = PintaCore.Palette.SecondaryColor.GdkColorAlpha ();
                csd.ColorSelection.HasOpacityControl = true;

                int response = csd.Run ();

                if (response == (int)Gtk.ResponseType.Ok) {
                    PintaCore.Palette.SecondaryColor = csd.ColorSelection.GetCairoColor ();
                }

                csd.Destroy ();
            }

            int pal = PointToPalette ((int)ev.X, (int)ev.Y);

            if (pal >= 0) {
                if (ev.Button == 3)
                    PintaCore.Palette.SecondaryColor = palette[pal];
                else
                    PintaCore.Palette.PrimaryColor = palette[pal];

                GdkWindow.Invalidate ();
            }

            // Insert button press handling code here.
            return base.OnButtonPressEvent (ev);
        }